From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Clark Williams <williams@redhat.com>,
Kate Carcia <kcarcia@redhat.com>,
dwarves@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>,
"Jose E. Marchesi" <jose.marchesi@oracle.com>,
Namhyung Kim <namhyung@kernel.org>,
Nick Alcock <nick.alcock@oracle.com>,
Yonghong Song <yonghong.song@linux.dev>
Subject: [PATCH 3/4] libbpf: Add support for detecting and dedup'ing a BTF archive
Date: Thu, 7 Aug 2025 15:25:37 -0300 [thread overview]
Message-ID: <20250807182538.136498-4-acme@kernel.org> (raw)
In-Reply-To: <20250807182538.136498-1-acme@kernel.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
As defined by being a series of BTF raw_data concatenated that then
are combined using btf__add_btf() to then be passed to btf__dedup().
This is a simpler interface, a more involved one, maybe for pahole
would involve doing the same approach as for encoding BTF from DWARF:
create a series of threads that would load the BTF archive in parallel
to then dedup it.
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: "Jose E. Marchesi" <jose.marchesi@oracle.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nick Alcock <nick.alcock@oracle.com>
Cc: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/bpf/btf.c | 38 ++++++++++++++++++++++++++++++++++++++
tools/lib/bpf/btf.h | 3 +++
2 files changed, 41 insertions(+)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index ee45d461d53bea9a..73a6d94eeda125e1 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1127,6 +1127,44 @@ struct btf *btf__new(const void *data, __u32 size)
return libbpf_ptr(btf_new(data, size, NULL, false));
}
+bool btf__is_archive(const struct btf *btf)
+{
+ return btf->extra_raw_data;
+}
+
+int btf__dedup_archive(struct btf *btf, const void *data, __u32 size, const struct btf_dedup_opts *opts)
+{
+ __u32 raw_size = btf->raw_size;
+ struct btf *brother;
+ int err = 0;
+
+ while (size > raw_size) {
+ data += raw_size;
+ size -= raw_size;
+ brother = btf_new(data, size, btf->base_btf, btf->raw_data_is_mmap);
+
+ if (IS_ERR(brother)) {
+ err = PTR_ERR(brother);
+ pr_debug("%s: __btf_new() failed! %d\n", __func__, err);
+ goto out;
+ }
+
+ if (btf__add_btf(btf, brother) < 0) {
+ err = -errno;
+ pr_debug("%s: btf__add_btf() failed: %d(%s)!\n", __func__, errno, strerror(errno));
+ btf__free(brother);
+ goto out;
+ }
+
+ raw_size = brother->raw_size;
+ btf__free(brother);
+ }
+
+ err = btf__dedup(btf, opts);
+out:
+ return libbpf_err(err);
+}
+
struct btf *btf__new_split(const void *data, __u32 size, struct btf *base_btf)
{
return libbpf_ptr(btf_new(data, size, base_btf, false));
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index ccfd905f03dfe7b6..71a6b8e037f5c98b 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -258,6 +258,9 @@ struct btf_dedup_opts {
#define btf_dedup_opts__last_field force_collisions
LIBBPF_API int btf__dedup(struct btf *btf, const struct btf_dedup_opts *opts);
+LIBBPF_API int btf__dedup_archive(struct btf *btf, const void *data, __u32 size,
+ const struct btf_dedup_opts *opts);
+LIBBPF_API bool btf__is_archive(const struct btf *btf);
/**
* @brief **btf__relocate()** will check the split BTF *btf* for references
--
2.50.1
next prev parent reply other threads:[~2025-08-07 18:26 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-07 18:25 [RFC 0/4] BTF archive with unmodified pahole+toolchain Arnaldo Carvalho de Melo
2025-08-07 18:25 ` [PATCH 1/4] libbpf: Simplify error handling removing needless repeated err checks Arnaldo Carvalho de Melo
2025-08-07 18:25 ` [PATCH 2/4] libbpf: Check if there is extra data at the end of a BTF Arnaldo Carvalho de Melo
2025-08-07 18:25 ` Arnaldo Carvalho de Melo [this message]
2025-08-07 18:25 ` [PATCH 4/4] libbpf: Check if an ELF .BTF section is an archive and combine/dedup Arnaldo Carvalho de Melo
2025-08-07 18:46 ` [RFC 0/4] BTF archive with unmodified pahole+toolchain Arnaldo Carvalho de Melo
2025-08-07 20:23 ` Arnaldo Carvalho de Melo
2025-08-08 2:09 ` Alexei Starovoitov
[not found] ` <CA+JHD92DODDESCfwiiCs_ZQ5bGesK5NC+xe5EvONF5g+-Bg+9Q@mail.gmail.com>
2025-08-08 2:52 ` Alexei Starovoitov
2025-08-08 3:25 ` Arnaldo Carvalho de Melo
2025-08-08 3:33 ` Sam James
2025-08-08 3:54 ` Arnaldo Carvalho de Melo
2025-08-08 14:45 ` Nick Alcock
2025-08-08 15:15 ` Nick Alcock
2025-08-08 18:28 ` Eduard Zingerman
2025-08-08 19:10 ` Arnaldo Carvalho de Melo
2025-08-08 20:15 ` Eduard Zingerman
2025-08-08 20:59 ` Arnaldo Carvalho de Melo
2025-08-21 21:35 ` Nick Alcock
2025-08-27 0:14 ` Alexei Starovoitov
2025-09-15 10:11 ` Nick Alcock
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250807182538.136498-4-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=alan.maguire@oracle.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=dwarves@vger.kernel.org \
--cc=jolsa@kernel.org \
--cc=jose.marchesi@oracle.com \
--cc=kcarcia@redhat.com \
--cc=namhyung@kernel.org \
--cc=nick.alcock@oracle.com \
--cc=williams@redhat.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox