From nobody Fri Dec 19 13:24:04 2025 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAEA4283FD6 for ; Fri, 19 Dec 2025 02:00:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109639; cv=none; b=C/UsQykX3HRno4Ksr3d4pmSb2+e6+ygzoh+6opl7p1yJbMM6OaT8J4YyOaxiTteqvO2BAyzCO5IFoERT5t8yabwn9xJ4eHjnbBFCMncy3HljxWAB6sztJJLpR6szCv4KGovX6Nl2JpRs9+GjyEqcHaOvjC2a0WfqDOHF5XWoWHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109639; c=relaxed/simple; bh=/9EOX2T4PsSLKlslCku6owIx615Wd85jFXGLADC8i+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gxU7WAoZ+/fI71r2HxL7SnNkqul1PTdHdryQpv9Ca4AusAOxHoUt3MWrVI3K5LFOhISBubSd1UvSouY3ug1ofCW+Cz4gGbxeLyHfmqrZhH3QJ/P0wRWZhriIetfkTBG89qYOjl669hqmoWFuKDjA6CNkCXNMn9O36bR7B1om/hU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=bEqqbtZA; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="bEqqbtZA" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766109631; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eMrhGEo8g6IdHWJcU5PThGSVr6JdXvAM3OyddrEgcdU=; b=bEqqbtZArRLeH/CREI40YEM7Gaxl9jaOOjS2M4aDKsW7976JDF2Q3ZjwpH7gbciIJRNopb G0uGhUWUPt+r01Kb9bPCMSaDI+9kTLA+rI0DcDMDsye5Nrhtirgxhu43U5Peh38MxXc6RC 1nXiz3fe2mh/rpFnjkWnrSMgOEaiFE4= From: Ihor Solodrai To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrew Morton , Nathan Chancellor , Nicolas Schier , Jonathan Corbet , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Shuah Khan , Nick Desaulniers , Bill Wendling , Justin Stitt , Alan Maguire , Donglin Peng Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, sched-ext@lists.linux.dev Subject: [PATCH bpf-next v6 1/8] resolve_btfids: Rename object btf field to btf_path Date: Thu, 18 Dec 2025 17:59:59 -0800 Message-ID: <20251219020006.785065-2-ihor.solodrai@linux.dev> In-Reply-To: <20251219020006.785065-1-ihor.solodrai@linux.dev> References: <20251219020006.785065-1-ihor.solodrai@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Rename the member of `struct object` holding the path to BTF data if provided via --btf arg. `btf_path` is less ambiguous. Acked-by: Eduard Zingerman Signed-off-by: Ihor Solodrai Tested-by: Alan Maguire --- tools/bpf/resolve_btfids/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/mai= n.c index d47191c6e55e..164f0c941f04 100644 --- a/tools/bpf/resolve_btfids/main.c +++ b/tools/bpf/resolve_btfids/main.c @@ -113,7 +113,7 @@ struct btf_id { =20 struct object { const char *path; - const char *btf; + const char *btf_path; const char *base_btf_path; =20 struct { @@ -550,11 +550,11 @@ static int symbols_resolve(struct object *obj) } } =20 - btf =3D btf__parse_split(obj->btf ?: obj->path, base_btf); + btf =3D btf__parse_split(obj->btf_path ?: obj->path, base_btf); err =3D libbpf_get_error(btf); if (err) { pr_err("FAILED: load BTF from %s: %s\n", - obj->btf ?: obj->path, strerror(-err)); + obj->btf_path ?: obj->path, strerror(-err)); goto out; } =20 @@ -790,8 +790,8 @@ int main(int argc, const char **argv) struct option btfid_options[] =3D { OPT_INCR('v', "verbose", &verbose, "be more verbose (show errors, etc)"), - OPT_STRING(0, "btf", &obj.btf, "BTF data", - "BTF data"), + OPT_STRING(0, "btf", &obj.btf_path, "file", + "path to a file with input BTF data"), OPT_STRING('b', "btf_base", &obj.base_btf_path, "file", "path of file providing base BTF"), OPT_BOOLEAN(0, "fatal_warnings", &fatal_warnings, --=20 2.52.0 From nobody Fri Dec 19 13:24:04 2025 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C9C1283FC8 for ; Fri, 19 Dec 2025 02:00:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109653; cv=none; b=a4r5EMib6nUv2kBb/d6eg4i6Z6RK08Y5yU49eX4FUg29NM5Y16biVROKMBu9Wd3O8qbgiQn53q46eJr/RyXCzVHU9KotyTHgQbLsLj52zTMjkYAyx6OcpnHN21qDI3iFXDrR8vVVkwHqguIY2C0CSO07SbQ7wXauQw8bl//reqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109653; c=relaxed/simple; bh=314A5Tj3+5f5HtyrFVZSBb6TJbogsocJkhmlAGdVqtA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GtVCZUOl31rL0DRq5dtmCpsIU8H0G8X29abxTsl0ZvzF4OSQN/jGecFTGVxFuASy7lE1GFB9x0MwrikmIBVIOdTLO1BTX0fbbqoKD0W6UockFZ3nETrNQL2KV/f3b1ZxZasjZXDgTDWwxNc9ehEDw532Tk5S8aawfPUtrlTcnBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=xi5Om+Ep; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xi5Om+Ep" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766109642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KntbnHhIoFklWUgq4SsR9FNc6jQvPv1wzXNXP/Xkbr8=; b=xi5Om+EpGDAxYcxmRRL8z7nxQ+sulnV36jexeMhy7kpKiSACdk89fLP5KcntGmf1i6HBNs IMowr1yJEwNreMKvX4MtiuqOa2uBYENFuSSfOrw0um5+jh8kgpfMEnnGp0cQei+6YTnjVT sprAJ/ELlFob7iIP9xI6aa8YIksYSrc= From: Ihor Solodrai To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrew Morton , Nathan Chancellor , Nicolas Schier , Jonathan Corbet , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Shuah Khan , Nick Desaulniers , Bill Wendling , Justin Stitt , Alan Maguire , Donglin Peng Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, sched-ext@lists.linux.dev Subject: [PATCH bpf-next v6 2/8] resolve_btfids: Factor out load_btf() Date: Thu, 18 Dec 2025 18:00:00 -0800 Message-ID: <20251219020006.785065-3-ihor.solodrai@linux.dev> In-Reply-To: <20251219020006.785065-1-ihor.solodrai@linux.dev> References: <20251219020006.785065-1-ihor.solodrai@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Increase the lifetime of parsed BTF in resolve_btfids by factoring load_btf() routine out of symbols_resolve() and storing the base_btf and btf pointers in the struct object. Acked-by: Eduard Zingerman Signed-off-by: Ihor Solodrai Tested-by: Alan Maguire --- tools/bpf/resolve_btfids/main.c | 47 ++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/mai= n.c index 164f0c941f04..b4caae1170dd 100644 --- a/tools/bpf/resolve_btfids/main.c +++ b/tools/bpf/resolve_btfids/main.c @@ -116,6 +116,9 @@ struct object { const char *btf_path; const char *base_btf_path; =20 + struct btf *btf; + struct btf *base_btf; + struct { int fd; Elf *elf; @@ -529,16 +532,10 @@ static int symbols_collect(struct object *obj) return 0; } =20 -static int symbols_resolve(struct object *obj) +static int load_btf(struct object *obj) { - int nr_typedefs =3D obj->nr_typedefs; - int nr_structs =3D obj->nr_structs; - int nr_unions =3D obj->nr_unions; - int nr_funcs =3D obj->nr_funcs; - struct btf *base_btf =3D NULL; - int err, type_id; - struct btf *btf; - __u32 nr_types; + struct btf *base_btf =3D NULL, *btf =3D NULL; + int err; =20 if (obj->base_btf_path) { base_btf =3D btf__parse(obj->base_btf_path, NULL); @@ -546,7 +543,7 @@ static int symbols_resolve(struct object *obj) if (err) { pr_err("FAILED: load base BTF from %s: %s\n", obj->base_btf_path, strerror(-err)); - return -1; + goto out_err; } } =20 @@ -555,9 +552,30 @@ static int symbols_resolve(struct object *obj) if (err) { pr_err("FAILED: load BTF from %s: %s\n", obj->btf_path ?: obj->path, strerror(-err)); - goto out; + goto out_err; } =20 + obj->base_btf =3D base_btf; + obj->btf =3D btf; + + return 0; + +out_err: + btf__free(base_btf); + btf__free(btf); + return err; +} + +static int symbols_resolve(struct object *obj) +{ + int nr_typedefs =3D obj->nr_typedefs; + int nr_structs =3D obj->nr_structs; + int nr_unions =3D obj->nr_unions; + int nr_funcs =3D obj->nr_funcs; + struct btf *btf =3D obj->btf; + int err, type_id; + __u32 nr_types; + err =3D -1; nr_types =3D btf__type_cnt(btf); =20 @@ -615,8 +633,6 @@ static int symbols_resolve(struct object *obj) =20 err =3D 0; out: - btf__free(base_btf); - btf__free(btf); return err; } =20 @@ -824,6 +840,9 @@ int main(int argc, const char **argv) if (symbols_collect(&obj)) goto out; =20 + if (load_btf(&obj)) + goto out; + if (symbols_resolve(&obj)) goto out; =20 @@ -833,6 +852,8 @@ int main(int argc, const char **argv) if (!(fatal_warnings && warnings)) err =3D 0; out: + btf__free(obj.base_btf); + btf__free(obj.btf); if (obj.efile.elf) { elf_end(obj.efile.elf); close(obj.efile.fd); --=20 2.52.0 From nobody Fri Dec 19 13:24:04 2025 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B80CB23A984 for ; Fri, 19 Dec 2025 02:00:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109659; cv=none; b=Z3hYHdUD931cTIIULkRDJp+R2pIUP1MttamVfATXuVdMLWXZGV0pGlqdRRZMLtMq00mU7RWhMDXeY6n9yNjG1BjjoCmCVrIqjaQk7rGh9Vz9d6knbj3q8hMABG6zNL12pzHs9LMNPh8RiNQxynIesNHqK4jJ3d9vvZ88tx7BHBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109659; c=relaxed/simple; bh=3FEIiRUylmj0GITPIIkPwx+DdvKez+ddqxbv/x6D4l0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WrCfLhb2aQA6ZYfEtQvBPpjV5gRnucDShXlCLts8jtaeUxbf4xoPjw3LqeY7+DqnSMo43qL454HA6sjluwF99LPFTh+EBta24PshxND6EI+JUKsOGHgOpv7fSB/EB1XClsBUNNQf0wRrbRk27r88Gvz1WP32D71uFbDzzYPTKj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ITYaVzMl; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ITYaVzMl" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766109653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sF5NRKZEGl/G+udktejbKoJb2K4tJj9XzuRyl23IiwY=; b=ITYaVzMldxMC67QL1N+DuRvm7Tups3VodTT8+eawC+XURqAU/13IDKQ3yOZ1hIxkBoF4fj /D1rbaOc5LLbmx7f9Jl/FtNOvcAx6jHn21cng24NliS1fGS/J/71DnEecsoB5HTvc7IXao dctxpeBEH3aQPSm8o0cUR8BPmJHKrpg= From: Ihor Solodrai To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrew Morton , Nathan Chancellor , Nicolas Schier , Jonathan Corbet , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Shuah Khan , Nick Desaulniers , Bill Wendling , Justin Stitt , Alan Maguire , Donglin Peng Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, sched-ext@lists.linux.dev Subject: [PATCH bpf-next v6 3/8] resolve_btfids: Introduce enum btf_id_kind Date: Thu, 18 Dec 2025 18:00:01 -0800 Message-ID: <20251219020006.785065-4-ihor.solodrai@linux.dev> In-Reply-To: <20251219020006.785065-1-ihor.solodrai@linux.dev> References: <20251219020006.785065-1-ihor.solodrai@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Instead of using multiple flags, make struct btf_id tagged with an enum value indicating its kind in the context of resolve_btfids. Acked-by: Eduard Zingerman Signed-off-by: Ihor Solodrai Tested-by: Alan Maguire --- tools/bpf/resolve_btfids/main.c | 83 ++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 23 deletions(-) diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/mai= n.c index b4caae1170dd..e721e20a2bbd 100644 --- a/tools/bpf/resolve_btfids/main.c +++ b/tools/bpf/resolve_btfids/main.c @@ -98,6 +98,13 @@ # error "Unknown machine endianness!" #endif =20 +enum btf_id_kind { + BTF_ID_KIND_NONE, + BTF_ID_KIND_SYM, + BTF_ID_KIND_SET, + BTF_ID_KIND_SET8 +}; + struct btf_id { struct rb_node rb_node; char *name; @@ -105,9 +112,8 @@ struct btf_id { int id; int cnt; }; + enum btf_id_kind kind; int addr_cnt; - bool is_set; - bool is_set8; Elf64_Addr addr[ADDR_CNT]; }; =20 @@ -197,8 +203,10 @@ static struct btf_id *btf_id__find(struct rb_root *roo= t, const char *name) return NULL; } =20 -static struct btf_id * -btf_id__add(struct rb_root *root, char *name, bool unique) +static struct btf_id *__btf_id__add(struct rb_root *root, + char *name, + enum btf_id_kind kind, + bool unique) { struct rb_node **p =3D &root->rb_node; struct rb_node *parent =3D NULL; @@ -221,12 +229,23 @@ btf_id__add(struct rb_root *root, char *name, bool un= ique) if (id) { pr_debug("adding symbol %s\n", name); id->name =3D name; + id->kind =3D kind; rb_link_node(&id->rb_node, parent, p); rb_insert_color(&id->rb_node, root); } return id; } =20 +static inline struct btf_id *btf_id__add(struct rb_root *root, char *name,= enum btf_id_kind kind) +{ + return __btf_id__add(root, name, kind, false); +} + +static inline struct btf_id *btf_id__add_unique(struct rb_root *root, char= *name, enum btf_id_kind kind) +{ + return __btf_id__add(root, name, kind, true); +} + static char *get_id(const char *prefix_end) { /* @@ -260,22 +279,36 @@ static char *get_id(const char *prefix_end) return id; } =20 -static struct btf_id *add_set(struct object *obj, char *name, bool is_set8) +static struct btf_id *add_set(struct object *obj, char *name, enum btf_id_= kind kind) { + int len =3D strlen(name); + int prefixlen; + char *id; + /* * __BTF_ID__set__name * name =3D ^ * id =3D ^ */ - char *id =3D name + (is_set8 ? sizeof(BTF_SET8 "__") : sizeof(BTF_SET "__= ")) - 1; - int len =3D strlen(name); + switch (kind) { + case BTF_ID_KIND_SET: + prefixlen =3D sizeof(BTF_SET "__") - 1; + break; + case BTF_ID_KIND_SET8: + prefixlen =3D sizeof(BTF_SET8 "__") - 1; + break; + default: + pr_err("Unexpected kind %d passed to %s() for symbol %s\n", kind, __func= __, name); + return NULL; + } =20 + id =3D name + prefixlen; if (id >=3D name + len) { pr_err("FAILED to parse set name: %s\n", name); return NULL; } =20 - return btf_id__add(&obj->sets, id, true); + return btf_id__add_unique(&obj->sets, id, kind); } =20 static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t = size) @@ -288,7 +321,7 @@ static struct btf_id *add_symbol(struct rb_root *root, = char *name, size_t size) return NULL; } =20 - return btf_id__add(root, id, false); + return btf_id__add(root, id, BTF_ID_KIND_SYM); } =20 /* Older libelf.h and glibc elf.h might not yet define the ELF compression= types. */ @@ -491,35 +524,31 @@ static int symbols_collect(struct object *obj) id =3D add_symbol(&obj->funcs, prefix, sizeof(BTF_FUNC) - 1); /* set8 */ } else if (!strncmp(prefix, BTF_SET8, sizeof(BTF_SET8) - 1)) { - id =3D add_set(obj, prefix, true); + id =3D add_set(obj, prefix, BTF_ID_KIND_SET8); /* * SET8 objects store list's count, which is encoded * in symbol's size, together with 'cnt' field hence * that - 1. */ - if (id) { + if (id) id->cnt =3D sym.st_size / sizeof(uint64_t) - 1; - id->is_set8 =3D true; - } /* set */ } else if (!strncmp(prefix, BTF_SET, sizeof(BTF_SET) - 1)) { - id =3D add_set(obj, prefix, false); + id =3D add_set(obj, prefix, BTF_ID_KIND_SET); /* * SET objects store list's count, which is encoded * in symbol's size, together with 'cnt' field hence * that - 1. */ - if (id) { + if (id) id->cnt =3D sym.st_size / sizeof(int) - 1; - id->is_set =3D true; - } } else { pr_err("FAILED unsupported prefix %s\n", prefix); return -1; } =20 if (!id) - return -ENOMEM; + return -EINVAL; =20 if (id->addr_cnt >=3D ADDR_CNT) { pr_err("FAILED symbol %s crossed the number of allowed lists\n", @@ -643,7 +672,7 @@ static int id_patch(struct object *obj, struct btf_id *= id) int i; =20 /* For set, set8, id->id may be 0 */ - if (!id->id && !id->is_set && !id->is_set8) { + if (!id->id && id->kind !=3D BTF_ID_KIND_SET && id->kind !=3D BTF_ID_KIND= _SET8) { pr_err("WARN: resolve_btfids: unresolved symbol %s\n", id->name); warnings++; } @@ -696,6 +725,7 @@ static int sets_patch(struct object *obj) { Elf_Data *data =3D obj->efile.idlist; struct rb_node *next; + int cnt; =20 next =3D rb_first(&obj->sets); while (next) { @@ -715,11 +745,15 @@ static int sets_patch(struct object *obj) return -1; } =20 - if (id->is_set) { + switch (id->kind) { + case BTF_ID_KIND_SET: set =3D data->d_buf + off; + cnt =3D set->cnt; qsort(set->ids, set->cnt, sizeof(set->ids[0]), cmp_id); - } else { + break; + case BTF_ID_KIND_SET8: set8 =3D data->d_buf + off; + cnt =3D set8->cnt; /* * Make sure id is at the beginning of the pairs * struct, otherwise the below qsort would not work. @@ -744,10 +778,13 @@ static int sets_patch(struct object *obj) bswap_32(set8->pairs[i].flags); } } + break; + default: + pr_err("Unexpected btf_id_kind %d for set '%s'\n", id->kind, id->name); + return -1; } =20 - pr_debug("sorting addr %5lu: cnt %6d [%s]\n", - off, id->is_set ? set->cnt : set8->cnt, id->name); + pr_debug("sorting addr %5lu: cnt %6d [%s]\n", off, cnt, id->name); =20 next =3D rb_next(next); } --=20 2.52.0 From nobody Fri Dec 19 13:24:04 2025 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11E39283FC8 for ; Fri, 19 Dec 2025 02:01:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109670; cv=none; b=BljRrson1XZy2fwesn/87lPW7glxAoSR6/KwWPeC+dw0xHBmJ/yjVGya0fFz/sOZAUVZLuMgkquOhh3pMiL3gcQ/bU4KB5/W9nCa9C89PfEGR4ZIAo53TzxMqPYPPQeQs0yj8yxm9rziMiZe9XuFzHrGhwONme3XDp6gKDObs0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109670; c=relaxed/simple; bh=VuNfMpTBm0CUYXaO+t8aSyvTsMROnkknWppmR/tAKfU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X3RjXJYDGdjFBWr01Dfx0SK+GGqm9romEaF6ZtNj0rqDDVOVjErzfMrkUQQoFYeJdIgr3tzNYMxmm/dy/9+OSx4PTuBzNyUW2RfnSELKxJMjd/9Zul0HiochjofFUAk1pgufQlZXgqqQuNYe/31DTZq48RfRxO1nMwiGkVBIRhA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jfKSWNB5; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jfKSWNB5" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766109662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aayb7iWI2Jbv+ieS21a4aukFU/2uaqV3fIN+m3cIAm4=; b=jfKSWNB5Zw0D8r89UMylhXfa9y5MQeOa4KUtvApvMTBVZXzDaDwcFQgBcWuF9T1xMfts04 6BJRbAGALErdsa3e14+AOnaCZ1a3/9CKGFbdF16PNW4SaJNGZ70ywyXqu5F7yYdnj/OA6c vj93+6taKHijoBdcnfSEvvR/ysA1QJA= From: Ihor Solodrai To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrew Morton , Nathan Chancellor , Nicolas Schier , Jonathan Corbet , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Shuah Khan , Nick Desaulniers , Bill Wendling , Justin Stitt , Alan Maguire , Donglin Peng Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, sched-ext@lists.linux.dev Subject: [PATCH bpf-next v6 4/8] resolve_btfids: Always build with -Wall -Werror Date: Thu, 18 Dec 2025 18:00:02 -0800 Message-ID: <20251219020006.785065-5-ihor.solodrai@linux.dev> In-Reply-To: <20251219020006.785065-1-ihor.solodrai@linux.dev> References: <20251219020006.785065-1-ihor.solodrai@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" resolve_btfids builds without compiler warnings currently, so let's enforce this for future changes with '-Wall -Werror' flags [1]. [1] https://lore.kernel.org/bpf/1957a60b-6c45-42a7-b525-a6e335a735ff@linux.= dev/ Signed-off-by: Ihor Solodrai Tested-by: Alan Maguire --- tools/bpf/resolve_btfids/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/M= akefile index ce1b556dfa90..1733a6e93a07 100644 --- a/tools/bpf/resolve_btfids/Makefile +++ b/tools/bpf/resolve_btfids/Makefile @@ -70,7 +70,8 @@ HOSTCFLAGS_resolve_btfids +=3D -g \ -I$(srctree)/tools/include/uapi \ -I$(LIBBPF_INCLUDE) \ -I$(SUBCMD_INCLUDE) \ - $(LIBELF_FLAGS) + $(LIBELF_FLAGS) \ + -Wall -Werror =20 LIBS =3D $(LIBELF_LIBS) -lz =20 --=20 2.52.0 From nobody Fri Dec 19 13:24:04 2025 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0DF7284670; Fri, 19 Dec 2025 02:01:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109682; cv=none; b=FPQHqeOYQPAVftXt/d43FnRvVCrCjPeFGmTBt+tKlYyUgx+I50rmB4w9zhxBMlQ2n53SqueJTV0E5sfAlxC4ihDY8lMXn9AuU3bA4+ngI7BSixUMSMKCwEoDCAOA7WU+ezmMJwIW0KplnsV9nl2tr8CdRHo8vsz0CmcgDedvoIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109682; c=relaxed/simple; bh=WLjB49Bv+US9iVn92oQnMFPHp8ZyZVv5Qy/cHB0piSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D8pCoojb+5lIpy30Rxt8+euZPjN9GZsfYNKFdPN/8HZeuV33Qvxbd7p3mW1NSFSFaI42lI5FyCIsH6DvLYJXXxbx4YrXTawjBllaI6UPFTyZSY8WyMmNJRjowVkwsDhyLXZayEDdHGmkBhGsZDi77QUykwu2SLGeKQ4+d8dwLxM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=wVjOYG2V; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="wVjOYG2V" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766109672; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3czLYeRjRlvXBbARi9TdvkmM7dkqe9ZURILhRZlVpf8=; b=wVjOYG2VuAkk88imkm+3hxW0Zbr7+cpera3BSDPlMqs0hePlXnJEslrw3eAb1ITPv8YZQK Qz4d8hI2ikKabfv6C7Is8lc8/LQawyfP6uJli3JmdnF486SpuQwo/0xmAPIb0mh00oMLDQ OPExh6t1JhzR75tydE3lTnJZ6UNgIqA= From: Ihor Solodrai To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrew Morton , Nathan Chancellor , Nicolas Schier , Jonathan Corbet , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Shuah Khan , Nick Desaulniers , Bill Wendling , Justin Stitt , Alan Maguire , Donglin Peng Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, sched-ext@lists.linux.dev Subject: [PATCH bpf-next v6 5/8] kbuild: Sync kconfig when PAHOLE_VERSION changes Date: Thu, 18 Dec 2025 18:00:03 -0800 Message-ID: <20251219020006.785065-6-ihor.solodrai@linux.dev> In-Reply-To: <20251219020006.785065-1-ihor.solodrai@linux.dev> References: <20251219020006.785065-1-ihor.solodrai@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch implements kconfig re-sync when the pahole version changes between builds, similar to how it happens for compiler version change via CC_VERSION_TEXT. Define PAHOLE_VERSION in the top-level Makefile and export it for config builds. Set CONFIG_PAHOLE_VERSION default to the exported variable. Kconfig records the PAHOLE_VERSION value in include/config/auto.conf.cmd [1]. The Makefile includes auto.conf.cmd, so if PAHOLE_VERSION changes between builds, make detects a dependency change and triggers syncconfig to update the kconfig [2]. For external module builds, add a warning message in the prepare target, similar to the existing compiler version mismatch warning. Note that if pahole is not installed or available, PAHOLE_VERSION is set to 0 by pahole-version.sh, so the (un)installation of pahole is treated as a version change. See previous discussions for context [3]. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree= /scripts/kconfig/preprocess.c?h=3Dv6.18#n91 [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree= /Makefile?h=3Dv6.18#n815 [3] https://lore.kernel.org/bpf/8f946abf-dd88-4fac-8bb4-84fcd8d81cf0@oracle= .com/ Signed-off-by: Ihor Solodrai Reviewed-by: Nicolas Schier Tested-by: Alan Maguire Tested-by: Nicolas Schier --- Makefile | 9 ++++++++- init/Kconfig | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e404e4767944..9b90a2a2218e 100644 --- a/Makefile +++ b/Makefile @@ -713,6 +713,7 @@ endif # upgrade. CC_VERSION_TEXT =3D $(subst $(pound),,$(shell LC_ALL=3DC $(CC) --version 2= >/dev/null | head -n 1)) RUSTC_VERSION_TEXT =3D $(subst $(pound),,$(shell $(RUSTC) --version 2>/dev= /null)) +PAHOLE_VERSION =3D $(shell $(srctree)/scripts/pahole-version.sh $(PAHOLE)) =20 ifneq ($(findstring clang,$(CC_VERSION_TEXT)),) include $(srctree)/scripts/Makefile.clang @@ -733,7 +734,7 @@ ifdef config-build # KBUILD_DEFCONFIG may point out an alternative default configuration # used for 'make defconfig' include $(srctree)/arch/$(SRCARCH)/Makefile -export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT RUSTC_VERSION_TEXT +export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT RUSTC_VERSION_TEXT = PAHOLE_VERSION =20 config: outputmakefile scripts_basic FORCE $(Q)$(MAKE) $(build)=3Dscripts/kconfig $@ @@ -1921,12 +1922,18 @@ clean: private rm-files :=3D Module.symvers modules= .nsdeps compile_commands.json PHONY +=3D prepare # now expand this into a simple variable to reduce the cost of shell evalu= ations prepare: CC_VERSION_TEXT :=3D $(CC_VERSION_TEXT) +prepare: PAHOLE_VERSION :=3D $(PAHOLE_VERSION) prepare: @if [ "$(CC_VERSION_TEXT)" !=3D "$(CONFIG_CC_VERSION_TEXT)" ]; then \ echo >&2 "warning: the compiler differs from the one used to build the k= ernel"; \ echo >&2 " The kernel was built by: $(CONFIG_CC_VERSION_TEXT)"; \ echo >&2 " You are using: $(CC_VERSION_TEXT)"; \ fi + @if [ "$(PAHOLE_VERSION)" !=3D "$(CONFIG_PAHOLE_VERSION)" ]; then \ + echo >&2 "warning: pahole version differs from the one used to build the= kernel"; \ + echo >&2 " The kernel was built with: $(CONFIG_PAHOLE_VERSION)"; \ + echo >&2 " You are using: $(PAHOLE_VERSION)"; \ + fi =20 PHONY +=3D help help: diff --git a/init/Kconfig b/init/Kconfig index fa79feb8fe57..317f3c0b13ad 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -171,7 +171,7 @@ config RUSTC_HAS_FILE_AS_C_STR =20 config PAHOLE_VERSION int - default $(shell,$(srctree)/scripts/pahole-version.sh $(PAHOLE)) + default "$(PAHOLE_VERSION)" =20 config CONSTRUCTORS bool --=20 2.52.0 From nobody Fri Dec 19 13:24:04 2025 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B646C283FC8 for ; Fri, 19 Dec 2025 02:01:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109692; cv=none; b=m7UZvKYyfezFM8522CLFvftr8RmSGHQfKraFOaXIYHduKtYa0n8Yab4HVVGXdtbvOrKXNEr9ZPDoDa1qS5XR5VTCVM5SrRDVibFY9U2xwFpfxY1MKShyQ0kaYlFAFlas4GDEE5xYoyUVmMnPU954v9oUOGVDVBC9kD95arZ4E2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109692; c=relaxed/simple; bh=gsZpFTi8QIwOAvmn5ydQV0Xi+hYp3QfxBo2eDqJApAM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QAAK4+ojIDrvycjuSAjpcLq0tYyS0hJkLQ0GI+8ghobewN5qksXHJ9DM8AfLg0IOeOO96m7ihZnz79aF2YsuFNuZNxF2S2HYdduNedbxmaTFsFDNzlTwrqf2xIYmKTcTRxxhfZP6I4RA9/x7EcNBsxmoAwYL6KqfmdMr1OgTFCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=nk3aVuHc; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="nk3aVuHc" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766109684; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DExPuYnExZe5P0blUNN50oahe6iegvEMZ5sGMxUQSX4=; b=nk3aVuHco62zS+y22asUKVFtmoMYhwsI2CbBdu48Q2L7RXzXDkYV2Ulo96PnsYZBZ/n1y+ XfkKGOmWfKkyPQmfH+NrX9Ryo+aECkBP96ufmxWgSMqYWfDwWgfDXgP8OQ6rP7vcJQ1ECR TCAfWFvMzXpgw4R/9tEtRvsCMEif7cA= From: Ihor Solodrai To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrew Morton , Nathan Chancellor , Nicolas Schier , Jonathan Corbet , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Shuah Khan , Nick Desaulniers , Bill Wendling , Justin Stitt , Alan Maguire , Donglin Peng Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, sched-ext@lists.linux.dev Subject: [PATCH bpf-next v6 6/8] lib/Kconfig.debug: Set the minimum required pahole version to v1.22 Date: Thu, 18 Dec 2025 18:00:04 -0800 Message-ID: <20251219020006.785065-7-ihor.solodrai@linux.dev> In-Reply-To: <20251219020006.785065-1-ihor.solodrai@linux.dev> References: <20251219020006.785065-1-ihor.solodrai@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Subsequent patches in the series change vmlinux linking scripts to unconditionally pass --btf_encode_detached to pahole, which was introduced in v1.22 [1][2]. This change allows to remove PAHOLE_HAS_SPLIT_BTF Kconfig option and other checks of older pahole versions. [1] https://github.com/acmel/dwarves/releases/tag/v1.22 [2] https://lore.kernel.org/bpf/cbafbf4e-9073-4383-8ee6-1353f9e5869c@oracle= .com/ Acked-by: Eduard Zingerman Signed-off-by: Ihor Solodrai Acked-by: Nicolas Schier Tested-by: Alan Maguire --- Documentation/scheduler/sched-ext.rst | 1 - lib/Kconfig.debug | 13 ++++--------- scripts/Makefile.btf | 9 +-------- tools/sched_ext/README.md | 1 - 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/Documentation/scheduler/sched-ext.rst b/Documentation/schedule= r/sched-ext.rst index 404fe6126a76..9e2882d937b4 100644 --- a/Documentation/scheduler/sched-ext.rst +++ b/Documentation/scheduler/sched-ext.rst @@ -43,7 +43,6 @@ options should be enabled to use sched_ext: CONFIG_DEBUG_INFO_BTF=3Dy CONFIG_BPF_JIT_ALWAYS_ON=3Dy CONFIG_BPF_JIT_DEFAULT_ON=3Dy - CONFIG_PAHOLE_HAS_SPLIT_BTF=3Dy CONFIG_PAHOLE_HAS_BTF_TAG=3Dy =20 sched_ext is used only when the BPF scheduler is loaded and running. diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index ba36939fda79..60281c4f9e99 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -388,18 +388,13 @@ config DEBUG_INFO_BTF depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST depends on BPF_SYSCALL - depends on PAHOLE_VERSION >=3D 116 - depends on DEBUG_INFO_DWARF4 || PAHOLE_VERSION >=3D 121 + depends on PAHOLE_VERSION >=3D 122 # pahole uses elfutils, which does not have support for Hexagon relocatio= ns depends on !HEXAGON help Generate deduplicated BTF type information from DWARF debug info. - Turning this on requires pahole v1.16 or later (v1.21 or later to - support DWARF 5), which will convert DWARF type info into equivalent - deduplicated BTF type info. - -config PAHOLE_HAS_SPLIT_BTF - def_bool PAHOLE_VERSION >=3D 119 + Turning this on requires pahole v1.22 or later, which will convert + DWARF type info into equivalent deduplicated BTF type info. =20 config PAHOLE_HAS_BTF_TAG def_bool PAHOLE_VERSION >=3D 123 @@ -421,7 +416,7 @@ config PAHOLE_HAS_LANG_EXCLUDE config DEBUG_INFO_BTF_MODULES bool "Generate BTF type information for kernel modules" default y - depends on DEBUG_INFO_BTF && MODULES && PAHOLE_HAS_SPLIT_BTF + depends on DEBUG_INFO_BTF && MODULES help Generate compact split BTF type information for kernel modules. =20 diff --git a/scripts/Makefile.btf b/scripts/Makefile.btf index db76335dd917..840a55de42da 100644 --- a/scripts/Makefile.btf +++ b/scripts/Makefile.btf @@ -7,14 +7,7 @@ JOBS :=3D $(patsubst -j%,%,$(filter -j%,$(MAKEFLAGS))) =20 ifeq ($(call test-le, $(pahole-ver), 125),y) =20 -# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars -ifeq ($(call test-le, $(pahole-ver), 121),y) -pahole-flags-$(call test-ge, $(pahole-ver), 118) +=3D --skip_encoding_btf_= vars -endif - -pahole-flags-$(call test-ge, $(pahole-ver), 121) +=3D --btf_gen_floats - -pahole-flags-$(call test-ge, $(pahole-ver), 122) +=3D -j$(JOBS) +pahole-flags-y +=3D --btf_gen_floats -j$= (JOBS) =20 pahole-flags-$(call test-ge, $(pahole-ver), 125) +=3D --skip_encoding_btf_= inconsistent_proto --btf_gen_optimized =20 diff --git a/tools/sched_ext/README.md b/tools/sched_ext/README.md index 16a42e4060f6..56a9d1557ac4 100644 --- a/tools/sched_ext/README.md +++ b/tools/sched_ext/README.md @@ -65,7 +65,6 @@ It's also recommended that you also include the following= Kconfig options: ``` CONFIG_BPF_JIT_ALWAYS_ON=3Dy CONFIG_BPF_JIT_DEFAULT_ON=3Dy -CONFIG_PAHOLE_HAS_SPLIT_BTF=3Dy CONFIG_PAHOLE_HAS_BTF_TAG=3Dy ``` =20 --=20 2.52.0 From nobody Fri Dec 19 13:24:04 2025 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B07629346F for ; Fri, 19 Dec 2025 02:01:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109703; cv=none; b=C/08SzWXcE+PuSjWXxzTtsNQ8ImohlWVQd10hNzOintFwfZRQialMXycvO8SJO6/KZ5pvj3/GsLt6WJ2jqAuK5q7eByJ/DZArvU7X5bKJzIqy8+FExRoyH6+74klqPTkur/dsF9gLcJ5HzD6qKZZGtz+U3ED6IWqH9ClFIHPwmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109703; c=relaxed/simple; bh=5XtEDfZedRFWtJQoT8WqPLnMwqu1EqFypYwbxxsUTGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s0Uv/LsxpwAXieciYkyyJ0Apvins0cIRgI38St6BwquKSfKLNSs+EACIvroUDOCLrDfOjWjuca8hIW7DAt93edqDiuEiav0D6qbX83JZViQZhQFILGzAO0SvQFeLwQDb4kTIp0P22E+uNbccEn8uC2NICpcM3tn5rLc+iqlsLcI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Ecxo0N8T; arc=none smtp.client-ip=91.218.175.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Ecxo0N8T" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766109694; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A1babkEM7oMvkXXUZTjAt8tsiOOvS9LqFpy4/GgvYek=; b=Ecxo0N8TIL6HmgyOI5oXhQAFTcsGt6Y9LXmxT3uibFFd0qD1vnJCUBbwGyKo4ajGkMD50t 9+2Ts7oQhXMjo+Sc8rhtYSjGBhiSXfpFXWWLsdPPdBE9jzTokVn4Lx99ew0GMZsVCDSWOD b/jDaFmicrVcNaAO98LUqb+BGgB27SM= From: Ihor Solodrai To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrew Morton , Nathan Chancellor , Nicolas Schier , Jonathan Corbet , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Shuah Khan , Nick Desaulniers , Bill Wendling , Justin Stitt , Alan Maguire , Donglin Peng Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, sched-ext@lists.linux.dev Subject: [PATCH bpf-next v6 7/8] selftests/bpf: Run resolve_btfids only for relevant .test.o objects Date: Thu, 18 Dec 2025 18:00:05 -0800 Message-ID: <20251219020006.785065-8-ihor.solodrai@linux.dev> In-Reply-To: <20251219020006.785065-1-ihor.solodrai@linux.dev> References: <20251219020006.785065-1-ihor.solodrai@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" A selftest targeting resolve_btfids functionality relies on a resolved .BTF_ids section to be available in the TRUNNER_BINARY. The underlying BTF data is taken from a special BPF program (btf_data.c), and so resolve_btfids is executed as a part of a TRUNNER_BINARY build recipe on the final binary. Subsequent patches in this series allow resolve_btfids to modify BTF before resolving the symbols, which means that the test needs access to that modified BTF [1]. Currently the test simply reads in btf_data.bpf.o on the assumption that BTF hasn't changed. Implement resolve_btfids call only for particular test objects (just resolve_btfids.test.o for now). The test objects are linked into the TRUNNER_BINARY, and so .BTF_ids section will be available there. This will make it trivial for the resolve_btfids test to access BTF modified by resolve_btfids. [1] https://lore.kernel.org/bpf/CAErzpmvsgSDe-QcWH8SFFErL6y3p3zrqNri5-UHJ9i= K2ChyiBw@mail.gmail.com/ Acked-by: Eduard Zingerman Signed-off-by: Ihor Solodrai Tested-by: Alan Maguire --- tools/testing/selftests/bpf/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests= /bpf/Makefile index 4aa60e83ff19..ffd0a4c354c7 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -643,6 +643,9 @@ $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c ) > $$@) endif =20 +$(TRUNNER_OUTPUT)/resolve_btfids.test.o: $(RESOLVE_BTFIDS) $(TRUNNER_OUTPU= T)/btf_data.bpf.o +$(TRUNNER_OUTPUT)/resolve_btfids.test.o: private TEST_NEEDS_BTFIDS =3D 1 + # compile individual test files # Note: we cd into output directory to ensure embedded BPF object is found $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \ @@ -650,6 +653,9 @@ $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \ | $(TRUNNER_OUTPUT)/%.test.d $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@) $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -MMD -MT $$@ -c $(CURDIR)/$$< $$(L= DLIBS) -o $$(@F) + $$(if $$(TEST_NEEDS_BTFIDS), \ + $$(call msg,BTFIDS,$(TRUNNER_BINARY),$$@) \ + $(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.bpf.o $$@) =20 $(TRUNNER_TEST_OBJS:.o=3D.d): $(TRUNNER_OUTPUT)/%.test.d: \ $(TRUNNER_TESTS_DIR)/%.c \ @@ -695,13 +701,11 @@ $(OUTPUT)/$(TRUNNER_BINARY): | $(TRUNNER_BPF_OBJS) $(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \ $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \ $(TRUNNER_LIB_OBJS) \ - $(RESOLVE_BTFIDS) \ $(TRUNNER_BPFTOOL) \ $(OUTPUT)/veristat \ | $(TRUNNER_BINARY)-extras $$(call msg,BINARY,,$$@) $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) $$(LLVM_LDLIBS) $= $(LDFLAGS) $$(LLVM_LDFLAGS) -o $$@ - $(Q)$(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.bpf.o $$@ $(Q)ln -sf $(if $2,..,.)/tools/build/bpftool/$(USE_BOOTSTRAP)bpftool \ $(OUTPUT)/$(if $2,$2/)bpftool =20 --=20 2.52.0 From nobody Fri Dec 19 13:24:04 2025 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB0122BE032; Fri, 19 Dec 2025 02:01:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109712; cv=none; b=X+MghoVvMVBi5DzbOPjghNbxFuhjzZYTQnB4UJlW78tByUMIgZZJ66m2PHptRaVSsRPUfLo6o7m2k1QFbWwM70LdXCdVOEuJ6zlo1rOiDLIDuLMKlwHQMC6fQ6oud2WUxNbRxMN3C3isoahHb6HgjGDA5c89P9FauVXqZZ1s8yE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766109712; c=relaxed/simple; bh=soA8tJD7fTYFPN0wWHKIwy/eKVhZMRV8ZiBG4stFW7w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CqjNQvXN4YggqJttxCMK7JGqlToqTVkS7brPVja5X82GZMzVLadxVHIKa23lD0K4H/QjAYsWf1jBN7Loae2uQdFVQPoMSwl5nLJ700p/W27SOavekYDQFIi69KRuHVNFnZv7GkdkxuVsm6Av8Ekjw109XxXWz43okTakzilWs/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Q9i7ZvI+; arc=none smtp.client-ip=91.218.175.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Q9i7ZvI+" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766109705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yTfTkUDQ1fOGD1fxOWANeNHg9Pe45MJWrztBiRP8mT0=; b=Q9i7ZvI+hv3UYDmyoEgDA8MYK0sqghoAR8D/K37pdIpSNPH+/rJg2wkVJWr3QFGYrJQH1z 1+x3mlIUpgr1fGnAfOsNTGEDr/p1ONS/HCeTJuJAVyiCuIj04WQ20R9ki+oVs7gi1GqQ+E JJX91rGhigWUjAAPHeLW9XVkPnTZBLo= From: Ihor Solodrai To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrew Morton , Nathan Chancellor , Nicolas Schier , Jonathan Corbet , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Shuah Khan , Nick Desaulniers , Bill Wendling , Justin Stitt , Alan Maguire , Donglin Peng Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, sched-ext@lists.linux.dev Subject: [PATCH bpf-next v6 8/8] resolve_btfids: Change in-place update with raw binary output Date: Thu, 18 Dec 2025 18:00:06 -0800 Message-ID: <20251219020006.785065-9-ihor.solodrai@linux.dev> In-Reply-To: <20251219020006.785065-1-ihor.solodrai@linux.dev> References: <20251219020006.785065-1-ihor.solodrai@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Currently resolve_btfids updates .BTF_ids section of an ELF file in-place, based on the contents of provided BTF, usually within the same input file, and optionally a BTF base. Change resolve_btfids behavior to enable BTF transformations as part of its main operation. To achieve this, in-place ELF write in resolve_btfids is replaced with generation of the following binaries: * ${1}.BTF with .BTF section data * ${1}.BTF_ids with .BTF_ids section data if it existed in ${1} * ${1}.BTF.base with .BTF.base section data for out-of-tree modules The execution of resolve_btfids and consumption of its output is orchestrated by scripts/gen-btf.sh introduced in this patch. The motivation for emitting binary data is that it allows simplifying resolve_btfids implementation by delegating ELF update to the $OBJCOPY tool [1], which is already widely used across the codebase. There are two distinct paths for BTF generation and resolve_btfids application in the kernel build: for vmlinux and for kernel modules. For the vmlinux binary a .BTF section is added in a roundabout way to ensure correct linking. The patch doesn't change this approach, only the implementation is a little different. Before this patch it worked as follows: * pahole consumed .tmp_vmlinux1 [2] and added .BTF section with llvm-objcopy [3] to it * then everything except the .BTF section was stripped from .tmp_vmlinux1 into a .tmp_vmlinux1.bpf.o object [2], later linked into vmlinux * resolve_btfids was executed later on vmlinux.unstripped [4], updating it in-place After this patch gen-btf.sh implements the following: * pahole consumes .tmp_vmlinux1 and produces a *detached* file with raw BTF data * resolve_btfids consumes .tmp_vmlinux1 and detached BTF to produce (potentially modified) .BTF, and .BTF_ids sections data * a .tmp_vmlinux1.bpf.o object is then produced with objcopy copying BTF output of resolve_btfids * .BTF_ids data gets embedded into vmlinux.unstripped in link-vmlinux.sh by objcopy --update-section For kernel modules, creating a special .bpf.o file is not necessary, and so embedding of sections data produced by resolve_btfids is straightforward with objcopy. With this patch an ELF file becomes effectively read-only within resolve_btfids, which allows deleting elf_update() call and satellite code (like compressed_section_fix [5]). Endianness handling of .BTF_ids data is also changed. Previously the "flags" part of the section was bswapped in sets_patch() [6], and then Elf_Type was modified before elf_update() to signal to libelf that bswap may be necessary. With this patch we explicitly bswap entire data buffer on load and on dump. [1] https://lore.kernel.org/bpf/131b4190-9c49-4f79-a99d-c00fac97fa44@linux.= dev/ [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree= /scripts/link-vmlinux.sh?h=3Dv6.18#n110 [3] https://git.kernel.org/pub/scm/devel/pahole/pahole.git/tree/btf_encoder= .c?h=3Dv1.31#n1803 [4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree= /scripts/link-vmlinux.sh?h=3Dv6.18#n284 [5] https://lore.kernel.org/bpf/20200819092342.259004-1-jolsa@kernel.org/ [6] https://lore.kernel.org/bpf/cover.1707223196.git.vmalik@redhat.com/ Acked-by: Eduard Zingerman Signed-off-by: Ihor Solodrai Tested-by: Alan Maguire --- MAINTAINERS | 1 + scripts/Makefile.btf | 12 +- scripts/Makefile.modfinal | 5 +- scripts/Makefile.vmlinux | 2 +- scripts/gen-btf.sh | 157 ++++++++++++ scripts/link-vmlinux.sh | 42 +--- tools/bpf/resolve_btfids/main.c | 224 +++++++++++------- tools/testing/selftests/bpf/.gitignore | 3 + tools/testing/selftests/bpf/Makefile | 9 +- .../selftests/bpf/prog_tests/resolve_btfids.c | 4 +- 10 files changed, 328 insertions(+), 131 deletions(-) create mode 100755 scripts/gen-btf.sh diff --git a/MAINTAINERS b/MAINTAINERS index 5b11839cba9d..cb1898a85b05 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4766,6 +4766,7 @@ F: net/sched/act_bpf.c F: net/sched/cls_bpf.c F: samples/bpf/ F: scripts/bpf_doc.py +F: scripts/gen-btf.sh F: scripts/Makefile.btf F: scripts/pahole-version.sh F: tools/bpf/ diff --git a/scripts/Makefile.btf b/scripts/Makefile.btf index 840a55de42da..562a04b40e06 100644 --- a/scripts/Makefile.btf +++ b/scripts/Makefile.btf @@ -18,13 +18,15 @@ pahole-flags-$(call test-ge, $(pahole-ver), 126) =3D -= j$(JOBS) --btf_features=3Denc =20 pahole-flags-$(call test-ge, $(pahole-ver), 130) +=3D --btf_features=3Datt= ributes =20 -ifneq ($(KBUILD_EXTMOD),) -module-pahole-flags-$(call test-ge, $(pahole-ver), 128) +=3D --btf_feature= s=3Ddistilled_base -endif - endif =20 pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) +=3D --lang_exclude=3Drust =20 export PAHOLE_FLAGS :=3D $(pahole-flags-y) -export MODULE_PAHOLE_FLAGS :=3D $(module-pahole-flags-y) + +resolve-btfids-flags-y :=3D +resolve-btfids-flags-$(CONFIG_WERROR) +=3D --fatal_warnings +resolve-btfids-flags-$(if $(KBUILD_EXTMOD),y) +=3D --distill_base +resolve-btfids-flags-$(if $(KBUILD_VERBOSE),y) +=3D --verbose + +export RESOLVE_BTFIDS_FLAGS :=3D $(resolve-btfids-flags-y) diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 149e12ff5700..422c56dc878e 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -42,9 +42,8 @@ quiet_cmd_btf_ko =3D BTF [M] $@ cmd_btf_ko =3D \ if [ ! -f $(objtree)/vmlinux ]; then \ printf "Skipping BTF generation for %s due to unavailability of vmlinux\= n" $@ 1>&2; \ - else \ - LLVM_OBJCOPY=3D"$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE= _FLAGS) --btf_base $(objtree)/vmlinux $@; \ - $(RESOLVE_BTFIDS) -b $(objtree)/vmlinux $@; \ + else \ + $(srctree)/scripts/gen-btf.sh --btf_base $(objtree)/vmlinux $@; \ fi; =20 # Same as newer-prereqs, but allows to exclude specified extra dependencies diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index cd788cac9d91..20a988f4fe0c 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -71,7 +71,7 @@ targets +=3D vmlinux.unstripped .vmlinux.export.o vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o .vmlinux.export.o $(= KBUILD_LDS) FORCE +$(call if_changed_dep,link_vmlinux) ifdef CONFIG_DEBUG_INFO_BTF -vmlinux.unstripped: $(RESOLVE_BTFIDS) +vmlinux.unstripped: $(RESOLVE_BTFIDS) $(srctree)/scripts/gen-btf.sh endif =20 ifdef CONFIG_BUILDTIME_TABLE_SORT diff --git a/scripts/gen-btf.sh b/scripts/gen-btf.sh new file mode 100755 index 000000000000..06c6d8becaa2 --- /dev/null +++ b/scripts/gen-btf.sh @@ -0,0 +1,157 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2025 Meta Platforms, Inc. and affiliates. +# +# This script generates BTF data for the provided ELF file. +# +# Kernel BTF generation involves these conceptual steps: +# 1. pahole generates BTF from DWARF data +# 2. resolve_btfids applies kernel-specific btf2btf +# transformations and computes data for .BTF_ids section +# 3. the result gets linked/objcopied into the target binary +# +# How step (3) should be done differs between vmlinux, and +# kernel modules, which is the primary reason for the existence +# of this script. +# +# For modules the script expects vmlinux passed in as --btf_base. +# Generated .BTF, .BTF.base and .BTF_ids sections become embedded +# into the input ELF file with objcopy. +# +# For vmlinux the input file remains unchanged and two files are produced: +# - ${1}.btf.o ready for linking into vmlinux +# - ${1}.BTF_ids with .BTF_ids data blob +# This output is consumed by scripts/link-vmlinux.sh + +set -e + +usage() +{ + echo "Usage: $0 [--btf_base ] " + exit 1 +} + +BTF_BASE=3D"" + +while [ $# -gt 0 ]; do + case "$1" in + --btf_base) + BTF_BASE=3D"$2" + shift 2 + ;; + -*) + echo "Unknown option: $1" >&2 + usage + ;; + *) + break + ;; + esac +done + +if [ $# -ne 1 ]; then + usage +fi + +ELF_FILE=3D"$1" +shift + +is_enabled() { + grep -q "^$1=3Dy" ${objtree}/include/config/auto.conf +} + +info() +{ + printf " %-7s %s\n" "${1}" "${2}" +} + +case "${KBUILD_VERBOSE}" in +*1*) + set -x + ;; +esac + + +gen_btf_data() +{ + info BTF "${ELF_FILE}" + btf1=3D"${ELF_FILE}.BTF.1" + ${PAHOLE} -J ${PAHOLE_FLAGS} \ + ${BTF_BASE:+--btf_base ${BTF_BASE}} \ + --btf_encode_detached=3D${btf1} \ + "${ELF_FILE}" + + info BTFIDS "${ELF_FILE}" + ${RESOLVE_BTFIDS} ${RESOLVE_BTFIDS_FLAGS} \ + ${BTF_BASE:+--btf_base ${BTF_BASE}} \ + --btf ${btf1} "${ELF_FILE}" +} + +gen_btf_o() +{ + local btf_data=3D${ELF_FILE}.btf.o + + # Create ${btf_data} which contains just .BTF section but no symbols. Add + # SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all + # deletes all symbols including __start_BTF and __stop_BTF, which will + # be redefined in the linker script. + info OBJCOPY "${btf_data}" + echo "" | ${CC} ${CLANG_FLAGS} -c -x c -o ${btf_data} - + ${OBJCOPY} --add-section .BTF=3D${ELF_FILE}.BTF \ + --set-section-flags .BTF=3Dalloc,readonly ${btf_data} + ${OBJCOPY} --only-section=3D.BTF --strip-all ${btf_data} + + # Change e_type to ET_REL so that it can be used to link final vmlinux. + # GNU ld 2.35+ and lld do not allow an ET_EXEC input. + if is_enabled CONFIG_CPU_BIG_ENDIAN; then + et_rel=3D'\0\1' + else + et_rel=3D'\1\0' + fi + printf "${et_rel}" | dd of=3D"${btf_data}" conv=3Dnotrunc bs=3D1 seek=3D1= 6 status=3Dnone +} + +embed_btf_data() +{ + info OBJCOPY "${ELF_FILE}.BTF" + ${OBJCOPY} --add-section .BTF=3D${ELF_FILE}.BTF ${ELF_FILE} + + # a module might not have a .BTF_ids or .BTF.base section + local btf_base=3D"${ELF_FILE}.BTF.base" + if [ -f "${btf_base}" ]; then + ${OBJCOPY} --add-section .BTF.base=3D${btf_base} ${ELF_FILE} + fi + local btf_ids=3D"${ELF_FILE}.BTF_ids" + if [ -f "${btf_ids}" ]; then + ${OBJCOPY} --update-section .BTF_ids=3D${btf_ids} ${ELF_FILE} + fi +} + +cleanup() +{ + rm -f "${ELF_FILE}.BTF.1" + rm -f "${ELF_FILE}.BTF" + if [ "${BTFGEN_MODE}" =3D "module" ]; then + rm -f "${ELF_FILE}.BTF.base" + rm -f "${ELF_FILE}.BTF_ids" + fi +} +trap cleanup EXIT + +BTFGEN_MODE=3D"vmlinux" +if [ -n "${BTF_BASE}" ]; then + BTFGEN_MODE=3D"module" +fi + +gen_btf_data + +case "${BTFGEN_MODE}" in +vmlinux) + gen_btf_o + ;; +module) + embed_btf_data + ;; +esac + +exit 0 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 4ab44c73da4d..e2207e612ac3 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -106,34 +106,6 @@ vmlinux_link() ${kallsymso} ${btf_vmlinux_bin_o} ${arch_vmlinux_o} ${ldlibs} } =20 -# generate .BTF typeinfo from DWARF debuginfo -# ${1} - vmlinux image -gen_btf() -{ - local btf_data=3D${1}.btf.o - - info BTF "${btf_data}" - LLVM_OBJCOPY=3D"${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${1} - - # Create ${btf_data} which contains just .BTF section but no symbols. Add - # SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all - # deletes all symbols including __start_BTF and __stop_BTF, which will - # be redefined in the linker script. Add 2>/dev/null to suppress GNU - # objcopy warnings: "empty loadable segment detected at ..." - ${OBJCOPY} --only-section=3D.BTF --set-section-flags .BTF=3Dalloc,readonl= y \ - --strip-all ${1} "${btf_data}" 2>/dev/null - # Change e_type to ET_REL so that it can be used to link final vmlinux. - # GNU ld 2.35+ and lld do not allow an ET_EXEC input. - if is_enabled CONFIG_CPU_BIG_ENDIAN; then - et_rel=3D'\0\1' - else - et_rel=3D'\1\0' - fi - printf "${et_rel}" | dd of=3D"${btf_data}" conv=3Dnotrunc bs=3D1 seek=3D1= 6 status=3Dnone - - btf_vmlinux_bin_o=3D${btf_data} -} - # Create ${2}.o file with all symbols from the ${1} object file kallsyms() { @@ -205,6 +177,7 @@ if is_enabled CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX; then fi =20 btf_vmlinux_bin_o=3D +btfids_vmlinux=3D kallsymso=3D strip_debug=3D generate_map=3D @@ -232,11 +205,13 @@ if is_enabled CONFIG_KALLSYMS || is_enabled CONFIG_DE= BUG_INFO_BTF; then fi =20 if is_enabled CONFIG_DEBUG_INFO_BTF; then - if ! gen_btf .tmp_vmlinux1; then + if ! ${srctree}/scripts/gen-btf.sh .tmp_vmlinux1; then echo >&2 "Failed to generate BTF for vmlinux" echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF" exit 1 fi + btf_vmlinux_bin_o=3D.tmp_vmlinux1.btf.o + btfids_vmlinux=3D.tmp_vmlinux1.BTF_ids fi =20 if is_enabled CONFIG_KALLSYMS; then @@ -289,14 +264,9 @@ fi =20 vmlinux_link "${VMLINUX}" =20 -# fill in BTF IDs if is_enabled CONFIG_DEBUG_INFO_BTF; then - info BTFIDS "${VMLINUX}" - RESOLVE_BTFIDS_ARGS=3D"" - if is_enabled CONFIG_WERROR; then - RESOLVE_BTFIDS_ARGS=3D" --fatal_warnings " - fi - ${RESOLVE_BTFIDS} ${RESOLVE_BTFIDS_ARGS} "${VMLINUX}" + info OBJCOPY ${btfids_vmlinux} + ${OBJCOPY} --update-section .BTF_ids=3D${btfids_vmlinux} ${VMLINUX} fi =20 mksysmap "${VMLINUX}" System.map diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/mai= n.c index e721e20a2bbd..2cbc252259be 100644 --- a/tools/bpf/resolve_btfids/main.c +++ b/tools/bpf/resolve_btfids/main.c @@ -71,9 +71,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -124,6 +126,7 @@ struct object { =20 struct btf *btf; struct btf *base_btf; + bool distill_base; =20 struct { int fd; @@ -324,42 +327,16 @@ static struct btf_id *add_symbol(struct rb_root *root= , char *name, size_t size) return btf_id__add(root, id, BTF_ID_KIND_SYM); } =20 -/* Older libelf.h and glibc elf.h might not yet define the ELF compression= types. */ -#ifndef SHF_COMPRESSED -#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */ -#endif - -/* - * The data of compressed section should be aligned to 4 - * (for 32bit) or 8 (for 64 bit) bytes. The binutils ld - * sets sh_addralign to 1, which makes libelf fail with - * misaligned section error during the update: - * FAILED elf_update(WRITE): invalid section alignment - * - * While waiting for ld fix, we fix the compressed sections - * sh_addralign value manualy. - */ -static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh) +static void bswap_32_data(void *data, u32 nr_bytes) { - int expected =3D gelf_getclass(elf) =3D=3D ELFCLASS32 ? 4 : 8; - - if (!(sh->sh_flags & SHF_COMPRESSED)) - return 0; - - if (sh->sh_addralign =3D=3D expected) - return 0; + u32 cnt, i; + u32 *ptr; =20 - pr_debug2(" - fixing wrong alignment sh_addralign %u, expected %u\n", - sh->sh_addralign, expected); + cnt =3D nr_bytes / sizeof(u32); + ptr =3D data; =20 - sh->sh_addralign =3D expected; - - if (gelf_update_shdr(scn, sh) =3D=3D 0) { - pr_err("FAILED cannot update section header: %s\n", - elf_errmsg(-1)); - return -1; - } - return 0; + for (i =3D 0; i < cnt; i++) + ptr[i] =3D bswap_32(ptr[i]); } =20 static int elf_collect(struct object *obj) @@ -380,7 +357,7 @@ static int elf_collect(struct object *obj) =20 elf_version(EV_CURRENT); =20 - elf =3D elf_begin(fd, ELF_C_RDWR_MMAP, NULL); + elf =3D elf_begin(fd, ELF_C_READ_MMAP_PRIVATE, NULL); if (!elf) { close(fd); pr_err("FAILED cannot create ELF descriptor: %s\n", @@ -443,21 +420,20 @@ static int elf_collect(struct object *obj) obj->efile.symbols_shndx =3D idx; obj->efile.strtabidx =3D sh.sh_link; } else if (!strcmp(name, BTF_IDS_SECTION)) { + /* + * If target endianness differs from host, we need to bswap32 + * the .BTF_ids section data on load, because .BTF_ids has + * Elf_Type =3D ELF_T_BYTE, and so libelf returns data buffer in + * the target endianness. We repeat this on dump. + */ + if (obj->efile.encoding !=3D ELFDATANATIVE) { + pr_debug("bswap_32 .BTF_ids data from target to host endianness\n"); + bswap_32_data(data->d_buf, data->d_size); + } obj->efile.idlist =3D data; obj->efile.idlist_shndx =3D idx; obj->efile.idlist_addr =3D sh.sh_addr; - } else if (!strcmp(name, BTF_BASE_ELF_SEC)) { - /* If a .BTF.base section is found, do not resolve - * BTF ids relative to vmlinux; resolve relative - * to the .BTF.base section instead. btf__parse_split() - * will take care of this once the base BTF it is - * passed is NULL. - */ - obj->base_btf_path =3D NULL; } - - if (compressed_section_fix(elf, scn, &sh)) - return -1; } =20 return 0; @@ -587,11 +563,26 @@ static int load_btf(struct object *obj) obj->base_btf =3D base_btf; obj->btf =3D btf; =20 + if (obj->base_btf && obj->distill_base) { + err =3D btf__distill_base(obj->btf, &base_btf, &btf); + if (err) { + pr_err("FAILED to distill base BTF: %s\n", strerror(errno)); + goto out_err; + } + + btf__free(obj->base_btf); + btf__free(obj->btf); + obj->base_btf =3D base_btf; + obj->btf =3D btf; + } + return 0; =20 out_err: btf__free(base_btf); btf__free(btf); + obj->base_btf =3D NULL; + obj->btf =3D NULL; return err; } =20 @@ -760,24 +751,6 @@ static int sets_patch(struct object *obj) */ BUILD_BUG_ON((u32 *)set8->pairs !=3D &set8->pairs[0].id); qsort(set8->pairs, set8->cnt, sizeof(set8->pairs[0]), cmp_id); - - /* - * When ELF endianness does not match endianness of the - * host, libelf will do the translation when updating - * the ELF. This, however, corrupts SET8 flags which are - * already in the target endianness. So, let's bswap - * them to the host endianness and libelf will then - * correctly translate everything. - */ - if (obj->efile.encoding !=3D ELFDATANATIVE) { - int i; - - set8->flags =3D bswap_32(set8->flags); - for (i =3D 0; i < set8->cnt; i++) { - set8->pairs[i].flags =3D - bswap_32(set8->pairs[i].flags); - } - } break; default: pr_err("Unexpected btf_id_kind %d for set '%s'\n", id->kind, id->name); @@ -793,8 +766,6 @@ static int sets_patch(struct object *obj) =20 static int symbols_patch(struct object *obj) { - off_t err; - if (__symbols_patch(obj, &obj->structs) || __symbols_patch(obj, &obj->unions) || __symbols_patch(obj, &obj->typedefs) || @@ -805,20 +776,90 @@ static int symbols_patch(struct object *obj) if (sets_patch(obj)) return -1; =20 - /* Set type to ensure endian translation occurs. */ - obj->efile.idlist->d_type =3D ELF_T_WORD; + return 0; +} =20 - elf_flagdata(obj->efile.idlist, ELF_C_SET, ELF_F_DIRTY); +static int dump_raw_data(const char *out_path, const void *data, u32 size) +{ + size_t written; + FILE *file; =20 - err =3D elf_update(obj->efile.elf, ELF_C_WRITE); - if (err < 0) { - pr_err("FAILED elf_update(WRITE): %s\n", - elf_errmsg(-1)); + file =3D fopen(out_path, "wb"); + if (!file) { + pr_err("Couldn't open %s for writing\n", out_path); + return -1; + } + + written =3D fwrite(data, 1, size, file); + if (written !=3D size) { + pr_err("Failed to write data to %s\n", out_path); + fclose(file); + unlink(out_path); + return -1; + } + + fclose(file); + pr_debug("Dumped %lu bytes of data to %s\n", size, out_path); + + return 0; +} + +static int dump_raw_btf_ids(struct object *obj, const char *out_path) +{ + Elf_Data *data =3D obj->efile.idlist; + int err; + + if (!data || !data->d_buf) { + pr_debug("%s has no BTF_ids data to dump\n", obj->path); + return 0; + } + + /* + * If target endianness differs from host, we need to bswap32 the + * .BTF_ids section data before dumping so that the output is in + * target endianness. + */ + if (obj->efile.encoding !=3D ELFDATANATIVE) { + pr_debug("bswap_32 .BTF_ids data from host to target endianness\n"); + bswap_32_data(data->d_buf, data->d_size); + } + + err =3D dump_raw_data(out_path, data->d_buf, data->d_size); + if (err) + return -1; + + return 0; +} + +static int dump_raw_btf(struct btf *btf, const char *out_path) +{ + const void *raw_btf_data; + u32 raw_btf_size; + int err; + + raw_btf_data =3D btf__raw_data(btf, &raw_btf_size); + if (!raw_btf_data) { + pr_err("btf__raw_data() failed\n"); + return -1; } =20 - pr_debug("update %s for %s\n", - err >=3D 0 ? "ok" : "failed", obj->path); - return err < 0 ? -1 : 0; + err =3D dump_raw_data(out_path, raw_btf_data, raw_btf_size); + if (err) + return -1; + + return 0; +} + +static inline int make_out_path(char *buf, u32 buf_sz, const char *in_path= , const char *suffix) +{ + int len =3D snprintf(buf, buf_sz, "%s%s", in_path, suffix); + + if (len < 0 || len >=3D buf_sz) { + pr_err("Output path is too long: %s%s\n", in_path, suffix); + return -E2BIG; + } + + return 0; } =20 static const char * const resolve_btfids_usage[] =3D { @@ -840,6 +881,8 @@ int main(int argc, const char **argv) .sets =3D RB_ROOT, }; bool fatal_warnings =3D false; + char out_path[PATH_MAX]; + struct option btfid_options[] =3D { OPT_INCR('v', "verbose", &verbose, "be more verbose (show errors, etc)"), @@ -849,6 +892,8 @@ int main(int argc, const char **argv) "path of file providing base BTF"), OPT_BOOLEAN(0, "fatal_warnings", &fatal_warnings, "turn warnings into errors"), + OPT_BOOLEAN(0, "distill_base", &obj.distill_base, + "distill --btf_base and emit .BTF.base section data"), OPT_END() }; int err =3D -1; @@ -860,6 +905,9 @@ int main(int argc, const char **argv) =20 obj.path =3D argv[0]; =20 + if (load_btf(&obj)) + goto out; + if (elf_collect(&obj)) goto out; =20 @@ -869,23 +917,37 @@ int main(int argc, const char **argv) */ if (obj.efile.idlist_shndx =3D=3D -1 || obj.efile.symbols_shndx =3D=3D -1) { - pr_debug("Cannot find .BTF_ids or symbols sections, nothing to do\n"); - err =3D 0; - goto out; + pr_debug("Cannot find .BTF_ids or symbols sections, skip symbols resolut= ion\n"); + goto dump_btf; } =20 if (symbols_collect(&obj)) goto out; =20 - if (load_btf(&obj)) - goto out; - if (symbols_resolve(&obj)) goto out; =20 if (symbols_patch(&obj)) goto out; =20 + err =3D make_out_path(out_path, sizeof(out_path), obj.path, BTF_IDS_SECTI= ON); + err =3D err ?: dump_raw_btf_ids(&obj, out_path); + if (err) + goto out; + +dump_btf: + err =3D make_out_path(out_path, sizeof(out_path), obj.path, BTF_ELF_SEC); + err =3D err ?: dump_raw_btf(obj.btf, out_path); + if (err) + goto out; + + if (obj.base_btf && obj.distill_base) { + err =3D make_out_path(out_path, sizeof(out_path), obj.path, BTF_BASE_ELF= _SEC); + err =3D err ?: dump_raw_btf(obj.base_btf, out_path); + if (err) + goto out; + } + if (!(fatal_warnings && warnings)) err =3D 0; out: diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftes= ts/bpf/.gitignore index 19c1638e312a..b8bf51b7a0b0 100644 --- a/tools/testing/selftests/bpf/.gitignore +++ b/tools/testing/selftests/bpf/.gitignore @@ -45,3 +45,6 @@ xdp_synproxy xdp_hw_metadata xdp_features verification_cert.h +*.BTF +*.BTF_ids +*.BTF.base diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests= /bpf/Makefile index ffd0a4c354c7..f28a32b16ff0 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -4,6 +4,7 @@ include ../../../scripts/Makefile.arch include ../../../scripts/Makefile.include =20 CXX ?=3D $(CROSS_COMPILE)g++ +OBJCOPY ?=3D $(CROSS_COMPILE)objcopy =20 CURDIR :=3D $(abspath .) TOOLSDIR :=3D $(abspath ../../..) @@ -653,9 +654,10 @@ $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \ | $(TRUNNER_OUTPUT)/%.test.d $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@) $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -MMD -MT $$@ -c $(CURDIR)/$$< $$(L= DLIBS) -o $$(@F) - $$(if $$(TEST_NEEDS_BTFIDS), \ - $$(call msg,BTFIDS,$(TRUNNER_BINARY),$$@) \ - $(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.bpf.o $$@) + $$(if $$(TEST_NEEDS_BTFIDS), \ + $$(call msg,BTFIDS,$(TRUNNER_BINARY),$$@) \ + $(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.bpf.o $$@; \ + $(OBJCOPY) --update-section .BTF_ids=3D$$@.BTF_ids $$@) =20 $(TRUNNER_TEST_OBJS:.o=3D.d): $(TRUNNER_OUTPUT)/%.test.d: \ $(TRUNNER_TESTS_DIR)/%.c \ @@ -894,6 +896,7 @@ EXTRA_CLEAN :=3D $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \ prog_tests/tests.h map_tests/tests.h verifier/tests.h \ feature bpftool $(TEST_KMOD_TARGETS) \ $(addprefix $(OUTPUT)/,*.o *.d *.skel.h *.lskel.h *.subskel.h \ + *.BTF *.BTF_ids *.BTF.base \ no_alu32 cpuv4 bpf_gcc \ liburandom_read.so) \ $(OUTPUT)/FEATURE-DUMP.selftests \ diff --git a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c b/tool= s/testing/selftests/bpf/prog_tests/resolve_btfids.c index 51544372f52e..41dfaaabb73f 100644 --- a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c +++ b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c @@ -101,9 +101,9 @@ static int resolve_symbols(void) int type_id; __u32 nr; =20 - btf =3D btf__parse_elf("btf_data.bpf.o", NULL); + btf =3D btf__parse_raw("resolve_btfids.test.o.BTF"); if (CHECK(libbpf_get_error(btf), "resolve", - "Failed to load BTF from btf_data.bpf.o\n")) + "Failed to load BTF from resolve_btfids.test.o.BTF\n")) return -1; =20 nr =3D btf__type_cnt(btf); --=20 2.52.0