From patchwork Mon Mar 29 07:58:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 410808 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3427213jai; Mon, 29 Mar 2021 01:25:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxx3Zi+G4ZCyj4BOLWy4gCVFGZmmVttSGffAt5q5hzj+SkwCSL21LWE69k6PZJ/V4zlc7vf X-Received: by 2002:a17:907:33c6:: with SMTP id zk6mr26714261ejb.228.1617006318401; Mon, 29 Mar 2021 01:25:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617006318; cv=none; d=google.com; s=arc-20160816; b=LFDv8zHYsqycM9sPZdxUzx0qonCE3aT86LC06k2/jCH7VHkBJUJTrp3yiRWUkzpOL7 P3JhhAqw+YwJ0lZNjjNuhdT/OcPztelvImwan4cYSTmvg7hTX6Js8iyZGAhG7mzSDXVu ap1tnx7LQ/sh0o0Y9DV0XuywIfQdF9jt9z5HUliglk5ir9YUxbROc43xCB1h2WlXdSP2 00Y6Df5BTNWgfYCAfnmakgotnwwK2020e9aMdAZygrj4AK9toVxSJxRH5ERfyZoesckx mNgE9CUaXCdOErg5gPV63Ae1DWnUVlmMJ1SKPwrVa8cz9is8cpnhLaYRQn39jtVSebCn 9Ghw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vV8Ud/oQDMqTHmpv/iiIBYQWASotlLGnmzDCDC7G8vI=; b=YVXcQHqpYMdV+LZAgeKAVBuUiTQYSJ13zyde+84Z+sZ615qA1eDL7z3nLi/J7f4QDR mfsEPH4fIOHxNyfHT6jOc2HeUdjAR+kYn/Y/OO6JGK8vGdSBjsXqKAQufeM2A9tyAIDP /oeH43chRKYDxOKQg3lWq6FmO+Vg2B7L+/J0pPwYDGyZfTuKKRshdyT1CMNfEcoK++OY VjEIsfVTYk8dt2SF4TpgUw9AHPeldmmlhezUk3HAwdNK2ypbISI+DDY3/LFZddQVgsNb DRO3qCVgqXi8n8oG/cpF4WKPp7MVSeKmjlnDLpK+Hl9u60aCewOdO7N/1BivZRSnoY4k pfPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rp3sHTHv; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a3si10905631edr.505.2021.03.29.01.25.18; Mon, 29 Mar 2021 01:25:18 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rp3sHTHv; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232692AbhC2IYq (ORCPT + 12 others); Mon, 29 Mar 2021 04:24:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:41084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233697AbhC2IXq (ORCPT ); Mon, 29 Mar 2021 04:23:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 51EB961580; Mon, 29 Mar 2021 08:23:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006224; bh=yKav0Il29ZRjd7L2vycF4NIWmmq44ae3g5LHM4WhjrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rp3sHTHv5QzZRofzzEAsN4Ajj4IADDBAwWpgHTF10QcS0S8j0vwMX4TCKJZPsKW/I t6sopD8J4LhR1iePSjesSkghABRhCESaRdAV4dC6yiP5Ex35hLrxnyLpEdUo1PmPZK w5z8Ok8dtTF+vpVTpbmNkg+Fn7C0KxqrXvQ3dN28= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jean-Philippe Brucker , Andrii Nakryiko , Sasha Levin Subject: [PATCH 5.10 163/221] libbpf: Fix BTF dump of pointer-to-array-of-struct Date: Mon, 29 Mar 2021 09:58:14 +0200 Message-Id: <20210329075634.586217410@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jean-Philippe Brucker [ Upstream commit 901ee1d750f29a335423eeb9463c3ca461ca18c2 ] The vmlinux.h generated from BTF is invalid when building drivers/phy/ti/phy-gmii-sel.c with clang: vmlinux.h:61702:27: error: array type has incomplete element type ‘struct reg_field’ 61702 | const struct reg_field (*regfields)[3]; | ^~~~~~~~~ bpftool generates a forward declaration for this struct regfield, which compilers aren't happy about. Here's a simplified reproducer: struct inner { int val; }; struct outer { struct inner (*ptr_to_array)[2]; } A; After build with clang -> bpftool btf dump c -> clang/gcc: ./def-clang.h:11:23: error: array has incomplete element type 'struct inner' struct inner (*ptr_to_array)[2]; Member ptr_to_array of struct outer is a pointer to an array of struct inner. In the DWARF generated by clang, struct outer appears before struct inner, so when converting BTF of struct outer into C, bpftool issues a forward declaration to struct inner. With GCC the DWARF info is reversed so struct inner gets fully defined. That forward declaration is not sufficient when compilers handle an array of the struct, even when it's only used through a pointer. Note that we can trigger the same issue with an intermediate typedef: struct inner { int val; }; typedef struct inner inner2_t[2]; struct outer { inner2_t *ptr_to_array; } A; Becomes: struct inner; typedef struct inner inner2_t[2]; And causes: ./def-clang.h:10:30: error: array has incomplete element type 'struct inner' typedef struct inner inner2_t[2]; To fix this, clear through_ptr whenever we encounter an intermediate array, to make the inner struct part of a strong link and force full declaration. Fixes: 351131b51c7a ("libbpf: add btf_dump API for BTF-to-C conversion") Signed-off-by: Jean-Philippe Brucker Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20210319112554.794552-2-jean-philippe@linaro.org Signed-off-by: Sasha Levin --- tools/lib/bpf/btf_dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.30.1 diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c index 2f9d685bd522..0911aea4cdbe 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -462,7 +462,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) return err; case BTF_KIND_ARRAY: - return btf_dump_order_type(d, btf_array(t)->type, through_ptr); + return btf_dump_order_type(d, btf_array(t)->type, false); case BTF_KIND_STRUCT: case BTF_KIND_UNION: {