Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp650870pxb; Tue, 5 Apr 2022 17:20:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkSvdALbA0n/CNjci8Gkfh4DxYIe3Sb+4NWLVIKdcz5qNE+avN48Bx4OgoYOKmcFgWAqZJ X-Received: by 2002:a17:906:16cc:b0:6ce:e607:ff02 with SMTP id t12-20020a17090616cc00b006cee607ff02mr5850679ejd.418.1649204292009; Tue, 05 Apr 2022 17:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649204292; cv=none; d=google.com; s=arc-20160816; b=XmXPzwg5BZUi5nJWN1oFLWUctlBhejaxMJs4kb527fEZ5Dv5Hze0f1mRD242hG/dDW MeTFEw8GZvSe26rp2YwMmIS2LEQeqjdiOGMtWv5cJlQcByeWOAdR5yRHKGDfBVRBCDZw PQCElH1tHp070q/frBTQqNIcnzEhv40V39HLiavNQjhk2ELp/f+jbhm4Sjx5V6XB6lhr 4DfBFRxbGJoDWi4Or1lriAjomic2oVOwob8GytqqAsFumjGt6kBMdgS2Wwk8MomPTAuc ZVMrY3+gWG0gTYhWd4KXwPvDOE+x6wdf1CWP5S9pJudRoHhr+UvktbnCa7kRzlMF63B9 Hqug== 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=mexKzF29eNLR+ghsWSAzM6casUbuM0nMin94v5mVfvs=; b=m63xz467YdGHbNO5gqUz5jmh8l5r1C7HX/SnHhuoh39jK9xnP6NQZd7VU+gBaCNNk4 +ThdtkXagUAqJSfH+oHXFSXHVjBIF23mvfOZj1JcS0JudE4wElBVn5KaN9mSSOHM45Bi zqLxjEepG0pqsTLZaxMBhZ/F+LLyW4tS9zlKL36CNPS/630qIWRSxvc/PCujdtVB3Urf csh/7eUE7eitjHJ7Wp67dNks7/ve0MtUBjrSn84phkowmgLC0wKytI7UhG342OGBOu0B eUOIFeA0g+2ZeDKYt3CnBhdjSCQaTF1W79+6Z4+ozxf2DmK+8yZ6qO2pUYMaAZLYqBQ7 +npg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TzJB8xI0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jx18-20020a170906ca5200b006dfaf4466e5si9974836ejb.223.2022.04.05.17.17.47; Tue, 05 Apr 2022 17:18:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TzJB8xI0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1386421AbiDEMnU (ORCPT + 99 others); Tue, 5 Apr 2022 08:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242444AbiDEJH7 (ORCPT ); Tue, 5 Apr 2022 05:07:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A211769284; Tue, 5 Apr 2022 01:56:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A79C1B81BAE; Tue, 5 Apr 2022 08:56:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED688C385A0; Tue, 5 Apr 2022 08:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149004; bh=d4plXabZ/0GHQZP3pqI9AgA3gJA7Dn4AgKEq+HZi9B8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TzJB8xI0uJstUcJW8wTZNVOoBsaujc30X+pM23f8RrBk3zl5CveEmYS/mE2cPsizU ebZ/QV9XrjBeNsptFJdCn0ELbfpWcmL7+0UEdFR7yOCzo56h0yoXcQWcEmqJfFzXjz NCK32ls3mqFcZqz0Kbjt701kRsjIKI4LuGvtzeRE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xu Kuohai , Daniel Borkmann , Song Liu , Sasha Levin Subject: [PATCH 5.16 0560/1017] libbpf: Skip forward declaration when counting duplicated type names Date: Tue, 5 Apr 2022 09:24:33 +0200 Message-Id: <20220405070410.903621803@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xu Kuohai [ Upstream commit 4226961b0019b2e1612029e8950a9e911affc995 ] Currently if a declaration appears in the BTF before the definition, the definition is dumped as a conflicting name, e.g.: $ bpftool btf dump file vmlinux format raw | grep "'unix_sock'" [81287] FWD 'unix_sock' fwd_kind=struct [89336] STRUCT 'unix_sock' size=1024 vlen=14 $ bpftool btf dump file vmlinux format c | grep "struct unix_sock" struct unix_sock; struct unix_sock___2 { <--- conflict, the "___2" is unexpected struct unix_sock___2 *unix_sk; This causes a compilation error if the dump output is used as a header file. Fix it by skipping declaration when counting duplicated type names. Fixes: 351131b51c7a ("libbpf: add btf_dump API for BTF-to-C conversion") Signed-off-by: Xu Kuohai Signed-off-by: Daniel Borkmann Acked-by: Song Liu Link: https://lore.kernel.org/bpf/20220301053250.1464204-2-xukuohai@huawei.com Signed-off-by: Sasha Levin --- tools/lib/bpf/btf_dump.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c index f2ab392a0e34..96af8c4ecf78 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -1483,6 +1483,11 @@ static const char *btf_dump_resolve_name(struct btf_dump *d, __u32 id, if (s->name_resolved) return *cached_name ? *cached_name : orig_name; + if (btf_is_fwd(t) || (btf_is_enum(t) && btf_vlen(t) == 0)) { + s->name_resolved = 1; + return orig_name; + } + dup_cnt = btf_dump_name_dups(d, name_map, orig_name); if (dup_cnt > 1) { const size_t max_len = 256; -- 2.34.1