Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp933886pxb; Wed, 6 Apr 2022 04:43:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuUK/OwNEe29Ucev2bkgTulK7g7SSwvDVNYsSyIViOqyjUMZidF0pYdOL0KaJOrubQ4nKD X-Received: by 2002:a17:902:f1ca:b0:156:9dae:4cfe with SMTP id e10-20020a170902f1ca00b001569dae4cfemr8042994plc.6.1649245408641; Wed, 06 Apr 2022 04:43:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649245408; cv=none; d=google.com; s=arc-20160816; b=IV6FjAuP8B7XFAlia8o695Bq5LhOtyxNfWDp6h9g7aqQDKlxcVPpA+4bmQHV3+xzhW +idlYFFh/ccOeAVor4Y1AY44XM/tsGNeARLpZorYd56x12b8kORt48u7Q5tLpmmN+sw9 FgC6nrN4YogW+OmXFYsW2TwDBoysH5312WwTwlRlusiu3LVCfErKu3JLnOpR6mzR7q52 Nvd+c2llVwpeenBAXEIUVi13tb4qr2rbAVaVLZg8EuE4GY2hy4fc2B9iWnYHP5juH6US nS7FpHPaWiR3/olF79B4K4micAmbo/bRVo+NkjjOXjnIKD4zB5qXY1IJ0UIg9NZrP4yW mDvA== 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=87P7zmrT5oWvBXWoXPe5hLuttXsNIbJab5hKjFehY1M=; b=E1FNEWAWFx85kxCSlpUpjo+dxcAwXHvMlhCjPsic02rgk1FwDvfh+LO5qIPYJZ34IF v7s4LTg/CpVSB5UgK1pxHLAZcsCjAAfAwfgKTYFhzvLahP7CSE/Ura1pCOTD8RQxs4jN 1rDIgNbxQlZxrmEuIps5n38Ub0PbREpTzezFur2uURnNtfLr9C8PJRb8lwiZX5GxxGoY Y1FwJ6TkYsWs1maBG24JAi7nj7fQEFKiereYUThUqcCY9OmJRkMpiFbHRUq0RdmJdz3Z K+FMXeCqjc1ZposWa11+cv3JOf9dU0sb5LIu86ljTKcDYlxVZFum2CIQ9SRkPViPpLQs c0ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UBpweW7t; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d10-20020a170903230a00b00156ae419651si7659824plh.401.2022.04.06.04.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:43:28 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UBpweW7t; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 41BE461C702; Wed, 6 Apr 2022 03:00:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1588553AbiDFAQa (ORCPT + 99 others); Tue, 5 Apr 2022 20:16:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349146AbiDEJtO (ORCPT ); Tue, 5 Apr 2022 05:49:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D64B7B6C; Tue, 5 Apr 2022 02:41:29 -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 87163B818F3; Tue, 5 Apr 2022 09:41:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D65B6C385A4; Tue, 5 Apr 2022 09:41:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151687; bh=JvznGMqy9yBRzBasrr1B9K2SVFNqRhWE7YuqdTM5RvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UBpweW7t5J2e18vnwyERhoKFIYhH+OtP16gYb219zbyV5xzb3c+5IHoV7rISxcfJM jwq62zqMefA0gv3+b1iRWfrMUmIfj0KBalx3aaJBbCGsMyFv4jTZ6tLrz7ehZjYXGx gWjVBa/qCsSdFbTzX4J+69CLCdFjNk/W/ZdJQbOs= 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.15 506/913] libbpf: Skip forward declaration when counting duplicated type names Date: Tue, 5 Apr 2022 09:26:08 +0200 Message-Id: <20220405070355.024455714@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 463447a071d6..841cc68e3f42 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -1481,6 +1481,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