public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature
@ 2026-02-26  8:52 Alan Maguire
  2026-02-26  8:52 ` [PATCH v3 dwarves 1/2] pahole: Add "layout" BTF " Alan Maguire
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Alan Maguire @ 2026-02-26  8:52 UTC (permalink / raw)
  To: andrii, ast
  Cc: daniel, martin.lau, eddyz87, song, yonghong.song, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, qmo, ihor.solodrai, mykyta.yatsenko5,
	dwarves, bpf, Alan Maguire

A soon-to-arrive v9 series will add support to add BTF layout
information to BTF; this describes the BTF kinds known about at
time of encoding in order to support parsing even in cases where
the kinds are not known to the parser; the layout relates a
BTF kind to the amount of space it consumes via an optional single
element following the BTF type or a set of vlen-specified objects.

This series implements the support for the BTF "layout" feature
but does not require the libbpf changes to support it; the feature
test uses a weak declaration of btf__new_empty_opts() to handle the
unsupported case.

To test pahole with this feature, the following approach can be used;

1. Specify -DLIBBPF_EMBEDDED=OFF option to cmake
2. Install latest libbpf with associated patch series with layout support

Alternatively with embedded libbpf the changes can be applied to
the embedded libbpf in lib/bpf/src.

Changes since v2 [1]:

- Resynced, renamed kind_layout -> layout
- Avoid encoding layout info in split BTF since it is a waste of space

Changes since v1 [2]:

 - Resynced with latest pahole

[1] https://lore.kernel.org/dwarves/20251210202752.813919-1-alan.maguire@oracle.com/
[2] https://lore.kernel.org/dwarves/20250528095349.788793-1-alan.maguire@oracle.com/

Alan Maguire (2):
  pahole: Add "layout" BTF encoding feature
  man-pages: describe layout BTF feature

 btf_encoder.c      | 21 ++++++++++++++++++++-
 dwarves.h          |  4 ++++
 man-pages/pahole.1 |  2 ++
 pahole.c           |  6 ++++++
 4 files changed, 32 insertions(+), 1 deletion(-)

-- 
2.39.3


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 dwarves 1/2] pahole: Add "layout" BTF encoding feature
  2026-02-26  8:52 [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature Alan Maguire
@ 2026-02-26  8:52 ` Alan Maguire
  2026-02-26  8:52 ` [PATCH v3 dwarves 2/2] man-pages: describe layout BTF feature Alan Maguire
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Alan Maguire @ 2026-02-26  8:52 UTC (permalink / raw)
  To: andrii, ast
  Cc: daniel, martin.lau, eddyz87, song, yonghong.song, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, qmo, ihor.solodrai, mykyta.yatsenko5,
	dwarves, bpf, Alan Maguire

Add support to pahole to add BTF kind layout info which describes the
BTF kinds supported at encoding time.  Since an older libbpf can be used
to build pahole add declaration for btf_new_opts and add a feature test
to check for the btf__new_empty_opts() function.

Also skip adding layout information for split BTF; it is redundant as
the base BTF will have the same information, and would just waste
space.

Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
 btf_encoder.c | 21 ++++++++++++++++++++-
 dwarves.h     |  4 ++++
 pahole.c      |  6 ++++++
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/btf_encoder.c b/btf_encoder.c
index aa7cd1c..99298e3 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -2679,6 +2679,16 @@ out:
 	return err;
 }
 
+/* Needed for older libbpf to support weak declaration of btf__new_empty_opts() */
+#ifndef btf_new_opts__last_field
+struct btf_new_opts {
+	size_t sz;
+	struct btf *base_btf;
+	bool add_layout;
+	size_t:0;
+};
+#endif
+
 struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, bool verbose, struct conf_load *conf_load)
 {
 	struct btf_encoder *encoder = zalloc(sizeof(*encoder));
@@ -2692,7 +2702,16 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
 		if (encoder->source_filename == NULL || encoder->filename == NULL)
 			goto out_delete;
 
-		encoder->btf = btf__new_empty_split(base_btf);
+		if (btf__new_empty_opts) {
+			LIBBPF_OPTS(btf_new_opts, opts);
+
+			/* only add layout to base BTF; no need to repeat for split. */
+			opts.add_layout = !base_btf && conf_load->btf_gen_layout;
+			opts.base_btf = base_btf;
+			encoder->btf = btf__new_empty_opts(&opts);
+		} else {
+			encoder->btf = btf__new_empty_split(base_btf);
+		}
 		if (encoder->btf == NULL)
 			goto out_delete;
 
diff --git a/dwarves.h b/dwarves.h
index d7c6474..5ec16e7 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -46,6 +46,8 @@ enum load_steal_kind {
 	LSK__ABORT,
 };
 
+struct btf_new_opts;
+
 /*
  * Weak declarations of libbpf APIs that are version-dependent
  */
@@ -55,6 +57,7 @@ __weak extern int btf__add_enum64(struct btf *btf, const char *name, __u32 byte_
 __weak extern int btf__add_enum64_value(struct btf *btf, const char *name, __u64 value);
 __weak extern int btf__add_type_attr(struct btf *btf, const char *value, int ref_type_id);
 __weak extern int btf__distill_base(const struct btf *src_btf, struct btf **new_base_btf, struct btf **new_split_btf);
+__weak extern struct btf *btf__new_empty_opts(struct btf_new_opts *opts);
 
 /*
  * BTF combines all the types into one big CU using btf_dedup(), so for something
@@ -95,6 +98,7 @@ struct conf_load {
 	bool			skip_encoding_btf_inconsistent_proto;
 	bool			skip_encoding_btf_vars;
 	bool			encode_btf_global_vars;
+	bool			btf_gen_layout;
 	bool			btf_gen_floats;
 	bool			btf_encode_force;
 	bool			reproducible_build;
diff --git a/pahole.c b/pahole.c
index 02a0d19..7eafc88 100644
--- a/pahole.c
+++ b/pahole.c
@@ -1209,6 +1209,11 @@ static bool attributes_check(void)
 	return btf__add_type_attr != NULL;
 }
 
+static bool layout_check(void)
+{
+	return btf__new_empty_opts != NULL;
+}
+
 struct btf_feature {
 	const char      *name;
 	const char      *option_alias;
@@ -1235,6 +1240,7 @@ struct btf_feature {
 	BTF_NON_DEFAULT_FEATURE_CHECK(attributes, btf_attributes, false,
 				      attributes_check),
 	BTF_NON_DEFAULT_FEATURE(true_signature, true_signature, false),
+	BTF_NON_DEFAULT_FEATURE_CHECK(layout, btf_gen_layout, false, layout_check)
 };
 
 #define BTF_MAX_FEATURE_STR	1024
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 dwarves 2/2] man-pages: describe layout BTF feature
  2026-02-26  8:52 [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature Alan Maguire
  2026-02-26  8:52 ` [PATCH v3 dwarves 1/2] pahole: Add "layout" BTF " Alan Maguire
@ 2026-02-26  8:52 ` Alan Maguire
  2026-04-02  8:00 ` [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature Alan Maguire
  2026-04-03 21:08 ` Jiri Olsa
  3 siblings, 0 replies; 6+ messages in thread
From: Alan Maguire @ 2026-02-26  8:52 UTC (permalink / raw)
  To: andrii, ast
  Cc: daniel, martin.lau, eddyz87, song, yonghong.song, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, qmo, ihor.solodrai, mykyta.yatsenko5,
	dwarves, bpf, Alan Maguire

Add this optional feature to btf_features description.

Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
 man-pages/pahole.1 | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/man-pages/pahole.1 b/man-pages/pahole.1
index 90a8f45..5680447 100644
--- a/man-pages/pahole.1
+++ b/man-pages/pahole.1
@@ -341,6 +341,8 @@ Supported non-standard features (not enabled for 'default')
 	                   (rather than source-level) signatures are used;
                            for gcc these are ".isra.0" and ".costprop.0"
                            optimized functions
+	layout             Encode information about BTF kinds available at encoding     
+	                   time in layout section in BTF.
 
 .fi
 
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature
  2026-02-26  8:52 [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature Alan Maguire
  2026-02-26  8:52 ` [PATCH v3 dwarves 1/2] pahole: Add "layout" BTF " Alan Maguire
  2026-02-26  8:52 ` [PATCH v3 dwarves 2/2] man-pages: describe layout BTF feature Alan Maguire
@ 2026-04-02  8:00 ` Alan Maguire
  2026-04-02 14:03   ` Alexei Starovoitov
  2026-04-03 21:08 ` Jiri Olsa
  3 siblings, 1 reply; 6+ messages in thread
From: Alan Maguire @ 2026-04-02  8:00 UTC (permalink / raw)
  To: andrii, ast
  Cc: daniel, martin.lau, eddyz87, song, yonghong.song, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, qmo, ihor.solodrai, mykyta.yatsenko5,
	dwarves, bpf

On 26/02/2026 08:52, Alan Maguire wrote:
> A soon-to-arrive v9 series will add support to add BTF layout
> information to BTF; this describes the BTF kinds known about at
> time of encoding in order to support parsing even in cases where
> the kinds are not known to the parser; the layout relates a
> BTF kind to the amount of space it consumes via an optional single
> element following the BTF type or a set of vlen-specified objects.
> 
> This series implements the support for the BTF "layout" feature
> but does not require the libbpf changes to support it; the feature
> test uses a weak declaration of btf__new_empty_opts() to handle the
> unsupported case.
> 
> To test pahole with this feature, the following approach can be used;
> 
> 1. Specify -DLIBBPF_EMBEDDED=OFF option to cmake
> 2. Install latest libbpf with associated patch series with layout support
> 
> Alternatively with embedded libbpf the changes can be applied to
> the embedded libbpf in lib/bpf/src.
> 
> Changes since v2 [1]:
> 
> - Resynced, renamed kind_layout -> layout
> - Avoid encoding layout info in split BTF since it is a waste of space
> 
> Changes since v1 [2]:
> 
>  - Resynced with latest pahole
> 
> [1] https://lore.kernel.org/dwarves/20251210202752.813919-1-alan.maguire@oracle.com/
> [2] https://lore.kernel.org/dwarves/20250528095349.788793-1-alan.maguire@oracle.com/
>

Now that the kernel/libbpf side has landed, I'm aiming to land the pahole side shortly.
We'll need to resync with libbpf when it is synced on github too, but for now it would
be good to get these patches in; unless anyone objects I'll do this today. Thanks!
 
> Alan Maguire (2):
>   pahole: Add "layout" BTF encoding feature
>   man-pages: describe layout BTF feature
> 
>  btf_encoder.c      | 21 ++++++++++++++++++++-
>  dwarves.h          |  4 ++++
>  man-pages/pahole.1 |  2 ++
>  pahole.c           |  6 ++++++
>  4 files changed, 32 insertions(+), 1 deletion(-)
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature
  2026-04-02  8:00 ` [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature Alan Maguire
@ 2026-04-02 14:03   ` Alexei Starovoitov
  0 siblings, 0 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2026-04-02 14:03 UTC (permalink / raw)
  To: Alan Maguire
  Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Eduard, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Quentin Monnet,
	Ihor Solodrai, Mykyta Yatsenko, dwarves, bpf

On Thu, Apr 2, 2026 at 1:01 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> On 26/02/2026 08:52, Alan Maguire wrote:
> > A soon-to-arrive v9 series will add support to add BTF layout
> > information to BTF; this describes the BTF kinds known about at
> > time of encoding in order to support parsing even in cases where
> > the kinds are not known to the parser; the layout relates a
> > BTF kind to the amount of space it consumes via an optional single
> > element following the BTF type or a set of vlen-specified objects.
> >
> > This series implements the support for the BTF "layout" feature
> > but does not require the libbpf changes to support it; the feature
> > test uses a weak declaration of btf__new_empty_opts() to handle the
> > unsupported case.
> >
> > To test pahole with this feature, the following approach can be used;
> >
> > 1. Specify -DLIBBPF_EMBEDDED=OFF option to cmake
> > 2. Install latest libbpf with associated patch series with layout support
> >
> > Alternatively with embedded libbpf the changes can be applied to
> > the embedded libbpf in lib/bpf/src.
> >
> > Changes since v2 [1]:
> >
> > - Resynced, renamed kind_layout -> layout
> > - Avoid encoding layout info in split BTF since it is a waste of space
> >
> > Changes since v1 [2]:
> >
> >  - Resynced with latest pahole
> >
> > [1] https://lore.kernel.org/dwarves/20251210202752.813919-1-alan.maguire@oracle.com/
> > [2] https://lore.kernel.org/dwarves/20250528095349.788793-1-alan.maguire@oracle.com/
> >
>
> Now that the kernel/libbpf side has landed, I'm aiming to land the pahole side shortly.
> We'll need to resync with libbpf when it is synced on github too, but for now it would
> be good to get these patches in; unless anyone objects I'll do this today. Thanks!

Ship it. You could have landed it the same day kernel patches landed.
There was no need for delay.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature
  2026-02-26  8:52 [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature Alan Maguire
                   ` (2 preceding siblings ...)
  2026-04-02  8:00 ` [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature Alan Maguire
@ 2026-04-03 21:08 ` Jiri Olsa
  3 siblings, 0 replies; 6+ messages in thread
From: Jiri Olsa @ 2026-04-03 21:08 UTC (permalink / raw)
  To: Alan Maguire
  Cc: andrii, ast, daniel, martin.lau, eddyz87, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, qmo, ihor.solodrai,
	mykyta.yatsenko5, dwarves, bpf

On Thu, Feb 26, 2026 at 08:52:38AM +0000, Alan Maguire wrote:
> A soon-to-arrive v9 series will add support to add BTF layout
> information to BTF; this describes the BTF kinds known about at
> time of encoding in order to support parsing even in cases where
> the kinds are not known to the parser; the layout relates a
> BTF kind to the amount of space it consumes via an optional single
> element following the BTF type or a set of vlen-specified objects.
> 
> This series implements the support for the BTF "layout" feature
> but does not require the libbpf changes to support it; the feature
> test uses a weak declaration of btf__new_empty_opts() to handle the
> unsupported case.
> 
> To test pahole with this feature, the following approach can be used;
> 
> 1. Specify -DLIBBPF_EMBEDDED=OFF option to cmake
> 2. Install latest libbpf with associated patch series with layout support
> 
> Alternatively with embedded libbpf the changes can be applied to
> the embedded libbpf in lib/bpf/src.
> 
> Changes since v2 [1]:
> 
> - Resynced, renamed kind_layout -> layout
> - Avoid encoding layout info in split BTF since it is a waste of space
> 
> Changes since v1 [2]:
> 
>  - Resynced with latest pahole
> 
> [1] https://lore.kernel.org/dwarves/20251210202752.813919-1-alan.maguire@oracle.com/
> [2] https://lore.kernel.org/dwarves/20250528095349.788793-1-alan.maguire@oracle.com/
> 
> Alan Maguire (2):
>   pahole: Add "layout" BTF encoding feature
>   man-pages: describe layout BTF feature

lgtm

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

> 
>  btf_encoder.c      | 21 ++++++++++++++++++++-
>  dwarves.h          |  4 ++++
>  man-pages/pahole.1 |  2 ++
>  pahole.c           |  6 ++++++
>  4 files changed, 32 insertions(+), 1 deletion(-)
> 
> -- 
> 2.39.3
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-04-03 21:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-26  8:52 [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature Alan Maguire
2026-02-26  8:52 ` [PATCH v3 dwarves 1/2] pahole: Add "layout" BTF " Alan Maguire
2026-02-26  8:52 ` [PATCH v3 dwarves 2/2] man-pages: describe layout BTF feature Alan Maguire
2026-04-02  8:00 ` [PATCH v3 dwarves 0/2] pahole: add BTF layout encoding feature Alan Maguire
2026-04-02 14:03   ` Alexei Starovoitov
2026-04-03 21:08 ` Jiri Olsa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox