From patchwork Mon Mar 29 07:58:34 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: 410800 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3423390jai; Mon, 29 Mar 2021 01:17:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9GCW0N4rbqDaRXTeMw9VQCa3kRcJE9tZW3j8CreaegeoyUaNc2IxbqcyE+BFkYJmI5PIB X-Received: by 2002:a17:906:aac5:: with SMTP id kt5mr27929059ejb.548.1617005874797; Mon, 29 Mar 2021 01:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617005874; cv=none; d=google.com; s=arc-20160816; b=alJkMtieZMQH8D4R4Wf5lwYLm+qbvXszSqu6KV3rpc7I0EfGPKla1dTDXQ2OYsEv7E JkHGg5H2vh5yWpYiHUt/mjui9qxAeVe/yfLw8FzeJzfy5QT6krkqLlkYI0jHPqIpkJnb 9FVKZelMdtthYYYt27nuqDJp70AsU62xeA1w89eToFcvfclQg2jok5iL6EpOFnvMjp/Z RajgUW+Og5mY6wXkJqvhVCt670xsC1FCY9xkz9XeGhalAnjlVk1/SV2O2X62IGPBgisL f8WtSxXwpeAGhRoeOWSOIBn00Hvo/o1kfDM43fzlZqpFavSQGXWcaROFMoeqYcC4VtWe ImhQ== 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=bptFY9UZ0cKkqIMUTrA2sj91wBFOeGjsSUQCRVOC4ts=; b=kfuP2oq3sd0CSP65hUHv4MNfmndnphwBWfxNajxpqgS6atOz8mGFFL7V3qTxmZ23rg Edfj4YykS4vEUtTwS6+vXZjA9ar5LC5V811dUqCrKNplACDQCN8d+ejJ3unzhzD7PO+0 KOv2xern9yA/+53MwXa79+rcbBFcIRzDHmNOX1X/DyvsB0MqR9y/daqBHlgsJ13ggZZ+ rztlPw8YpvPbxmpxHf+WAnRV4EU2Nz+jmYEB1D4IOms7DnxVXjrmBKTxq+KXJGlefhl6 o8SEsb3DWN6YPQKyFCPczvZNjg5fLR4aEPBt69Xl2puENz0VLMiCzZ+PZHWArbiz+Fnf KBCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IMLuaf71; 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 s19si12223139ejd.449.2021.03.29.01.17.54; Mon, 29 Mar 2021 01:17:54 -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=IMLuaf71; 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 S231451AbhC2IQo (ORCPT + 12 others); Mon, 29 Mar 2021 04:16:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:57602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232834AbhC2IPR (ORCPT ); Mon, 29 Mar 2021 04:15:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BD0D961932; Mon, 29 Mar 2021 08:14:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617005699; bh=I1nB1dUJTXBLHZnL1Z1EPAblbIjU8WdkGdF3tZuTcnM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IMLuaf71cF1wcekgqiBUW2AHHxP5s81omLUkZYmLRJXok3OdIwuf9ws0iGPYWvHI3 m2/tnAdLGQVhxIVVDA+cxTMil3bblFEHbOuhwfbuNWRc8u5MdZQbaTUkFkC/dwsDvR U/W506+VLwD/NRMOf4Vkast0nvgp91x5I80QJtig= 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.4 086/111] libbpf: Fix BTF dump of pointer-to-array-of-struct Date: Mon, 29 Mar 2021 09:58:34 +0200 Message-Id: <20210329075618.077866706@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075615.186199980@linuxfoundation.org> References: <20210329075615.186199980@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 d9e386b8f47e..b2fc45250450 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -443,7 +443,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: {