Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3425696pxf; Mon, 29 Mar 2021 01:44:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLtolQvvtX3Q7dSGAMUQj95gvWS89cbmNQO+ohzKHP6djkW4y5npMhqdf5Yo+9NJz2O+K6 X-Received: by 2002:aa7:d1d0:: with SMTP id g16mr27289499edp.358.1617007442956; Mon, 29 Mar 2021 01:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617007442; cv=none; d=google.com; s=arc-20160816; b=zzLEFlV+GNQ0XV4GaasIQKQ0mdrsssm6NhSOHjdwvDS1qEyK1p7EJybRPSijx8plHO CI/6sptefMLeuk4lZi4lgQCXbCWR0MJyfs2UJVWDeg3WBvBvw6k4476/aavim+Qx18rj KWOSfG+Zq91luT0USaMUNJZCm6rkoRII3nDIwxB36eP66wkp06Qs+tGVMD2Mg/B8NlUn FWLWayOqqJJQkaXXAIjx+XkGnofwBfOJSAkiACX7SUdnEwIDSePcZFX1TrY8Gfey3Ij8 KsEsqw2xf+4lI5ZPbRaX/PuAYQzN1RrNWJ+HMIWKFZDP5KIl0IpLjTPtWyfML4QSXtYx sxDA== 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=CqYOd2BKfs774M//TJGjS4CF2BDpP7b4714dSRAyqTfZgmaahU8eyc8Mq5PpxAiCOQ Q/rrjqJ1lDbWIDbwqOVj4GZUmmSCWfcb0cncEhD55W0VyuiZTBxf65RtM8KopVOsTOx7 6C/xwyAKmaVfOi2zJdoUKvKxhNVvVN+VwtqfwaZXsJlksJTzh6LT0LkZaSS7vLgeQCqc M4tZHe5bX8zH139mo+rtOPJc+mCxzeoWKe/36kCD6vXAYGjD8XLtM7+mpWfvZIJCA4Af +oHp0x//eRq8uYVwz63JfYvlSfVS2bbtzQBgKp/BmOu1bcHipDYiqqGQXpdux6jaktAv J9nw== 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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 jz16si12427663ejb.586.2021.03.29.01.43.40; Mon, 29 Mar 2021 01:44:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S235016AbhC2Ilp (ORCPT + 99 others); Mon, 29 Mar 2021 04:41:45 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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: { -- 2.30.1