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 <alan.maguire@xxxxxxxxxx> --- btf_encoder.c | 10 +++++++++- dwarves.h | 13 ++++++++++++- pahole.c | 7 +++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 0bc2334..2f166d5 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -2425,7 +2425,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 36c6898..72b5099 100644 --- a/dwarves.h +++ b/dwarves.h @@ -45,6 +45,16 @@ enum load_steal_kind { LSK__STOP_LOADING, }; +/* 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 + /* * Weak declarations of libbpf APIs that are version-dependent */ @@ -54,7 +64,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 * like a allyesconfig vmlinux kernel we can get over 65535 types. @@ -94,6 +104,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 333e71a..797305e 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; @@ -1232,6 +1237,8 @@ struct btf_feature { BTF_NON_DEFAULT_FEATURE_CHECK(distilled_base, btf_gen_distilled_base, false, distilled_base_check), BTF_NON_DEFAULT_FEATURE(global_var, encode_btf_global_vars, false), + BTF_NON_DEFAULT_FEATURE_CHECK(kind_layout, encode_btf_kind_layout, false, + kind_layout_check), BTF_NON_DEFAULT_FEATURE_CHECK(attributes, btf_attributes, false, attributes_check), }; -- 2.39.3