From: Alan Maguire <alan.maguire@oracle.com>
To: andrii@kernel.org, jolsa@kernel.org, acme@redhat.com,
quentin@isovalent.com
Cc: eddyz87@gmail.com, mykolal@fb.com, ast@kernel.org,
daniel@iogearbox.net, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, john.fastabend@gmail.com,
kpsingh@kernel.org, sdf@google.com, haoluo@google.com,
houtao1@huawei.com, bpf@vger.kernel.org, masahiroy@kernel.org,
mcgrof@kernel.org, nathan@kernel.org,
Alan Maguire <alan.maguire@oracle.com>
Subject: [RFC dwarves] btf_encoder: add base_ref BTF feature to generate split BTF with base refs
Date: Fri, 22 Mar 2024 10:24:42 +0000 [thread overview]
Message-ID: <20240322102455.98558-2-alan.maguire@oracle.com> (raw)
In-Reply-To: <20240322102455.98558-1-alan.maguire@oracle.com>
Adding "base_ref" to --btf_features when generating split BTF will generate
split and base reference BTF - the latter allows us to map references from
split BTF to base BTF, even if that base BTF has changed. It does this
by providing just enough information about the base types in the
.BTF.base_ref section.
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
btf_encoder.c | 43 ++++++++++++++++++++++++++++++-------------
dwarves.h | 1 +
pahole.c | 28 ++++++++++++++++------------
3 files changed, 47 insertions(+), 25 deletions(-)
diff --git a/btf_encoder.c b/btf_encoder.c
index e1e3529..ec5fa87 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -75,7 +75,8 @@ struct btf_encoder {
verbose,
force,
gen_floats,
- is_rel;
+ is_rel,
+ gen_base_ref;
uint32_t array_index_id;
struct {
struct var_info *vars;
@@ -1255,9 +1256,9 @@ static int btf_encoder__write_raw_file(struct btf_encoder *encoder)
return err;
}
-static int btf_encoder__write_elf(struct btf_encoder *encoder)
+static int btf_encoder__write_elf(struct btf_encoder *encoder, const struct btf *btf,
+ const char *btf_secname)
{
- struct btf *btf = encoder->btf;
const char *filename = encoder->filename;
GElf_Shdr shdr_mem, *shdr;
Elf_Data *btf_data = NULL;
@@ -1297,7 +1298,7 @@ static int btf_encoder__write_elf(struct btf_encoder *encoder)
if (shdr == NULL)
continue;
char *secname = elf_strptr(elf, strndx, shdr->sh_name);
- if (strcmp(secname, ".BTF") == 0) {
+ if (strcmp(secname, btf_secname) == 0) {
btf_data = elf_getdata(scn, btf_data);
break;
}
@@ -1341,11 +1342,11 @@ static int btf_encoder__write_elf(struct btf_encoder *encoder)
goto unlink;
}
- snprintf(cmd, sizeof(cmd), "%s --add-section .BTF=%s %s",
- llvm_objcopy, tmp_fn, filename);
+ snprintf(cmd, sizeof(cmd), "%s --add-section %s=%s %s",
+ llvm_objcopy, btf_secname, tmp_fn, filename);
if (system(cmd)) {
- fprintf(stderr, "%s: failed to add .BTF section to '%s': %d!\n",
- __func__, filename, errno);
+ fprintf(stderr, "%s: failed to add %s section to '%s': %d!\n",
+ __func__, btf_secname, filename, errno);
goto unlink;
}
@@ -1380,12 +1381,27 @@ int btf_encoder__encode(struct btf_encoder *encoder)
fprintf(stderr, "%s: btf__dedup failed!\n", __func__);
return -1;
}
-
- if (encoder->raw_output)
+ if (encoder->raw_output) {
err = btf_encoder__write_raw_file(encoder);
- else
- err = btf_encoder__write_elf(encoder);
-
+ } else {
+ struct btf *btf = encoder->btf;
+
+ if (encoder->gen_base_ref) {
+ btf = btf__new_split_base_ref(encoder->btf);
+ if (!btf) {
+ fprintf(stderr, "could not generate base reference split BTF: %s\n",
+ strerror(errno));
+ return -1;
+ }
+ }
+ err = btf_encoder__write_elf(encoder, btf, BTF_ELF_SEC);
+ if (!err && encoder->gen_base_ref)
+ err = btf_encoder__write_elf(encoder, btf__base_btf(btf), BTF_BASE_REF_ELF_SEC);
+ if (btf != encoder->btf) {
+ btf__free((struct btf *)btf__base_btf(btf));
+ btf__free(btf);
+ }
+ }
return err;
}
@@ -1659,6 +1675,7 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
encoder->force = conf_load->btf_encode_force;
encoder->gen_floats = conf_load->btf_gen_floats;
encoder->skip_encoding_vars = conf_load->skip_encoding_btf_vars;
+ encoder->gen_base_ref = conf_load->btf_gen_base_ref;
encoder->verbose = verbose;
encoder->has_index_type = false;
encoder->need_index_type = false;
diff --git a/dwarves.h b/dwarves.h
index be0e29a..ad01979 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -87,6 +87,7 @@ struct conf_load {
bool skip_encoding_btf_vars;
bool btf_gen_floats;
bool btf_encode_force;
+ bool btf_gen_base_ref;
uint8_t hashtable_bits;
uint8_t max_hashtable_bits;
uint16_t kabi_prefix_len;
diff --git a/pahole.c b/pahole.c
index 0b9c2de..965285d 100644
--- a/pahole.c
+++ b/pahole.c
@@ -1264,23 +1264,25 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
* BTF encoding apply; we encode type/decl tags, do not encode
* floats, etc. This ensures backwards compatibility.
*/
-#define BTF_FEATURE(name, alias, default_value) \
- { #name, #alias, &conf_load.alias, default_value }
+#define BTF_FEATURE(name, alias, default_value, enable_for_all) \
+ { #name, #alias, &conf_load.alias, default_value, enable_for_all }
struct btf_feature {
const char *name;
const char *option_alias;
bool *conf_value;
bool default_value;
+ bool enable_for_all;
} btf_features[] = {
- BTF_FEATURE(encode_force, btf_encode_force, false),
- BTF_FEATURE(var, skip_encoding_btf_vars, true),
- BTF_FEATURE(float, btf_gen_floats, false),
- BTF_FEATURE(decl_tag, skip_encoding_btf_decl_tag, true),
- BTF_FEATURE(type_tag, skip_encoding_btf_type_tag, true),
- BTF_FEATURE(enum64, skip_encoding_btf_enum64, true),
- BTF_FEATURE(optimized_func, btf_gen_optimized, false),
- BTF_FEATURE(consistent_func, skip_encoding_btf_inconsistent_proto, false),
+ BTF_FEATURE(encode_force, btf_encode_force, false, true),
+ BTF_FEATURE(var, skip_encoding_btf_vars, true, true),
+ BTF_FEATURE(float, btf_gen_floats, false, true),
+ BTF_FEATURE(decl_tag, skip_encoding_btf_decl_tag, true, true),
+ BTF_FEATURE(type_tag, skip_encoding_btf_type_tag, true, true),
+ BTF_FEATURE(enum64, skip_encoding_btf_enum64, true, true),
+ BTF_FEATURE(optimized_func, btf_gen_optimized, false, true),
+ BTF_FEATURE(consistent_func, skip_encoding_btf_inconsistent_proto, false, true),
+ BTF_FEATURE(base_ref, btf_gen_base_ref, false, false),
};
#define BTF_MAX_FEATURE_STR 1024
@@ -1348,8 +1350,10 @@ static void parse_btf_features(const char *features, bool strict)
if (strcmp(features, "all") == 0) {
int i;
- for (i = 0; i < ARRAY_SIZE(btf_features); i++)
- enable_btf_feature(&btf_features[i]);
+ for (i = 0; i < ARRAY_SIZE(btf_features); i++) {
+ if (btf_features[i].enable_for_all)
+ enable_btf_feature(&btf_features[i]);
+ }
return;
}
--
2.39.3
next prev parent reply other threads:[~2024-03-22 10:25 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-22 10:24 [RFC bpf-next 00/13] bpf: support resilient split BTF Alan Maguire
2024-03-22 10:24 ` Alan Maguire [this message]
2024-03-22 10:24 ` [RFC bpf-next 01/13] libbpf: add support to btf__add_fwd() for ENUM64 Alan Maguire
2024-03-29 21:59 ` Andrii Nakryiko
2024-03-22 10:24 ` [RFC bpf-next 02/13] libbpf: add btf__new_split_base_ref() creating split BTF with reference base BTF Alan Maguire
2024-03-29 22:00 ` Andrii Nakryiko
2024-04-04 15:21 ` Alan Maguire
2024-04-04 22:49 ` Andrii Nakryiko
2024-03-22 10:24 ` [RFC bpf-next 03/13] selftests/bpf: test split base reference BTF generation Alan Maguire
2024-03-22 10:24 ` [RFC bpf-next 04/13] libbpf: add btf__parse_opts() API for flexible BTF parsing Alan Maguire
2024-03-29 22:00 ` Andrii Nakryiko
2024-03-22 10:24 ` [RFC bpf-next 05/13] bpftool: support displaying raw split BTF using base reference BTF as base Alan Maguire
2024-03-22 10:24 ` [RFC bpf-next 06/13] kbuild,bpf: switch to using --btf_features for pahole v1.26 and later Alan Maguire
2024-03-29 22:01 ` Andrii Nakryiko
2024-03-22 10:24 ` [RFC bpf-next 07/13] resolve_btfids: use .BTF.base_ref BTF as base BTF if -r option is used Alan Maguire
2024-03-22 10:24 ` [RFC bpf-next 08/13] kbuild, bpf: add module-specific pahole/resolve_btfids flags for base reference BTF Alan Maguire
2024-03-23 2:50 ` Alexei Starovoitov
2024-03-25 9:51 ` Alan Maguire
2024-03-25 16:41 ` Alexei Starovoitov
2024-03-22 10:24 ` [RFC bpf-next 09/13] libbpf: split BTF reconciliation Alan Maguire
2024-03-29 22:01 ` Andrii Nakryiko
2024-04-05 10:06 ` Alan Maguire
2024-04-05 19:58 ` Andrii Nakryiko
2024-03-22 10:24 ` [RFC bpf-next 10/13] module, bpf: store BTF base reference pointer in struct module Alan Maguire
2024-03-22 10:24 ` [RFC bpf-next 11/13] libbpf,bpf: share BTF reconcile-related code with kernel Alan Maguire
2024-03-29 22:04 ` Andrii Nakryiko
2024-04-01 15:58 ` Andrii Nakryiko
2024-03-22 10:24 ` [RFC bpf-next 12/13] selftests/bpf: extend base reference tests cover BTF reconciliation Alan Maguire
2024-03-22 10:24 ` [RFC bpf-next 13/13] bpftool: support displaying reconciled-with-base split BTF Alan Maguire
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=20240322102455.98558-2-alan.maguire@oracle.com \
--to=alan.maguire@oracle.com \
--cc=acme@redhat.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=houtao1@huawei.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=masahiroy@kernel.org \
--cc=mcgrof@kernel.org \
--cc=mykolal@fb.com \
--cc=nathan@kernel.org \
--cc=quentin@isovalent.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--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