Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp887042pxb; Wed, 6 Apr 2022 03:15:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfZvQtd8jLb7H5wg5NHYi2ZvSglsug15Ynje6g0VnfZMQMttwhGVFRZRpRt7Nqb9GJpC0z X-Received: by 2002:a17:90b:4b89:b0:1c8:105a:2262 with SMTP id lr9-20020a17090b4b8900b001c8105a2262mr9040778pjb.225.1649240144718; Wed, 06 Apr 2022 03:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649240144; cv=none; d=google.com; s=arc-20160816; b=wGuR7TxfOZbEXV70zDSfPc7VlMKSinbpiOAWF5XtBkhosuYzYpgJy2oEV0XMxFI5Oz 2AWX3liWF6WV+zCTAbNRfFscSKmgR1gNIEEyFQsQUUthYclYFWIC0cc4dU9Am3iJFEpw RVhe9bEZxHKBjeQ/DLyCwK/v3SKflM6qhsfBd/58dWBOtHMOL9o5MxZ3U0akQ0Rp8X5Y AQUrP0nO1WfliMOnuqDVobks05Po8HHZYvjO7QU39uygJHBGF+lMnpGnsnxXbFArp81Y iPcNebm1DIuGGqw9Aw23uwnOTiOfDWJNDN3f/fajr8tkdlVHxWUlwCvzEJb/xvVQTYHn 3qlA== 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=c6wBXzWxvaSbAkSvkl8QjmPL1wNxmG1SN/hXye/gZ4Q=; b=Pjw9E9bmKFY+Dr50nbIpCYaMC1vRPJljdIcyS4dH1z0dRJMhByg6LFJyq4LSqsIpui 5wC2bn5OuNxZmUj2MBNCXodsEZy5etLdr+wU2gkOkNL+IaDcNQFaB3VzFPBXkkCADLTm 7m3zYQFHfi8Asw1cEuVMLYfXakD/h84Ub6ST78uHavbehwcVmeNKOsWCfwa1/MjUwYuc Hnob/cCItMGUCkuee7FJ2B8W9wNydEkFMs+UdKqBkVnUwAJAq3PuZDB31A7f5+TOFVMX W1TqJhbHz9emRLmszgP/evqp+joOSELFYN+e1CoC8jnyEASdWMH3QxvGd4fpgaH6kcWI 9Mkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="M/c19MiU"; 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 y16-20020a1709027c9000b001567f569926si8927621pll.186.2022.04.06.03.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 03:15:44 -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="M/c19MiU"; 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 89BFC581B30; Wed, 6 Apr 2022 01:45:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355751AbiDEKVu (ORCPT + 99 others); Tue, 5 Apr 2022 06:21:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241267AbiDEIdD (ORCPT ); Tue, 5 Apr 2022 04:33:03 -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 B7064B8E; Tue, 5 Apr 2022 01:31:04 -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 77B71B81BC0; Tue, 5 Apr 2022 08:31:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA58CC385A1; Tue, 5 Apr 2022 08:31:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147462; bh=xP6Tr2F4niH5CmG/43FEijRnvWU8Se3NAUyhudXwZWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M/c19MiUL0jaah/o582wXff29jDzWOBG+sVaBABUai/zgB6+PSk0bA7nuHs0J0Ie+ KvsIQ1K7eVDUiuEpTHx/2gW+sUq2pjaFY1y+MNX/tTa3zqVeZtTfnKXKAQtFIz6thD lNXiLpQxMuriUlis2YIpk6y2Z24HxGJ50tP7tlNM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Andrii Nakryiko , Arnaldo Carvalho de Melo Subject: [PATCH 5.17 1084/1126] libbpf: Define BTF_KIND_* constants in btf.h to avoid compilation errors Date: Tue, 5 Apr 2022 09:30:31 +0200 Message-Id: <20220405070439.269923427@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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: Toke Høiland-Jørgensen commit eaa266d83a3730a15de2ceebcc89e8f6290e8cf6 upstream. The btf.h header included with libbpf contains inline helper functions to check for various BTF kinds. These helpers directly reference the BTF_KIND_* constants defined in the kernel header, and because the header file is included in user applications, this happens in the user application compile units. This presents a problem if a user application is compiled on a system with older kernel headers because the constants are not available. To avoid this, add #defines of the constants directly in btf.h before using them. Since the kernel header moved to an enum for BTF_KIND_*, the #defines can shadow the enum values without any errors, so we only need #ifndef guards for the constants that predates the conversion to enum. We group these so there's only one guard for groups of values that were added together. [0] Closes: https://github.com/libbpf/libbpf/issues/436 Fixes: 223f903e9c83 ("bpf: Rename BTF_KIND_TAG to BTF_KIND_DECL_TAG") Fixes: 5b84bd10363e ("libbpf: Add support for BTF_KIND_TAG") Signed-off-by: Toke Høiland-Jørgensen Signed-off-by: Andrii Nakryiko Acked-by: Arnaldo Carvalho de Melo Link: https://lore.kernel.org/bpf/20220118141327.34231-1-toke@redhat.com Signed-off-by: Greg Kroah-Hartman --- tools/lib/bpf/btf.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -375,8 +375,28 @@ btf_dump__dump_type_data(struct btf_dump const struct btf_dump_type_data_opts *opts); /* - * A set of helpers for easier BTF types handling + * A set of helpers for easier BTF types handling. + * + * The inline functions below rely on constants from the kernel headers which + * may not be available for applications including this header file. To avoid + * compilation errors, we define all the constants here that were added after + * the initial introduction of the BTF_KIND* constants. */ +#ifndef BTF_KIND_FUNC +#define BTF_KIND_FUNC 12 /* Function */ +#define BTF_KIND_FUNC_PROTO 13 /* Function Proto */ +#endif +#ifndef BTF_KIND_VAR +#define BTF_KIND_VAR 14 /* Variable */ +#define BTF_KIND_DATASEC 15 /* Section */ +#endif +#ifndef BTF_KIND_FLOAT +#define BTF_KIND_FLOAT 16 /* Floating point */ +#endif +/* The kernel header switched to enums, so these two were never #defined */ +#define BTF_KIND_DECL_TAG 17 /* Decl Tag */ +#define BTF_KIND_TYPE_TAG 18 /* Type Tag */ + static inline __u16 btf_kind(const struct btf_type *t) { return BTF_INFO_KIND(t->info);