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. Signed-off-by: Alan Maguire --- btf_encoder.c | 20 +++++++++++++++++++- dwarves.h | 4 ++++ pahole.c | 7 +++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/btf_encoder.c b/btf_encoder.c index b37ee7f..074ec72 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -2549,6 +2549,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_kind_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)); @@ -2562,7 +2572,15 @@ 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); + + opts.add_kind_layout = conf_load->encode_btf_kind_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 21d4166..49ade3e 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 encode_btf_kind_layout; bool btf_gen_floats; bool btf_encode_force; bool reproducible_build; diff --git a/pahole.c b/pahole.c index ef01e58..66b6bdb 100644 --- a/pahole.c +++ b/pahole.c @@ -1209,6 +1209,11 @@ static bool attributes_check(void) return btf__add_type_attr != NULL; } +static bool kind_layout_check(void) +{ + return btf__new_empty_opts != NULL; +} + struct btf_feature { const char *name; const char *option_alias; @@ -1234,6 +1239,8 @@ struct btf_feature { BTF_NON_DEFAULT_FEATURE(global_var, encode_btf_global_vars, false), BTF_NON_DEFAULT_FEATURE_CHECK(attributes, btf_attributes, false, attributes_check), + BTF_NON_DEFAULT_FEATURE_CHECK(kind_layout, encode_btf_kind_layout, false, + kind_layout_check), }; #define BTF_MAX_FEATURE_STR 1024 -- 2.43.5 Add this optional feature to btf_features description. Signed-off-by: Alan Maguire --- man-pages/pahole.1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/man-pages/pahole.1 b/man-pages/pahole.1 index 3125de3..0226103 100644 --- a/man-pages/pahole.1 +++ b/man-pages/pahole.1 @@ -337,6 +337,8 @@ Supported non-standard features (not enabled for 'default') of split BTF with a possibly changed base, storing it in a .BTF.base ELF section. global_var Encode all global variables using BTF_KIND_VAR in BTF. + kind_layout Encode information about BTF kinds available at encoding + time in kind layout section in BTF. .fi So for example, specifying \-\-btf_encode=var,enum64 will result in a BTF encoding that (as well as encoding basic BTF information) will contain variables and enum64 values. -- 2.43.5