commit 32721b1a1c0a5e4a6e0080fedc0ee57c49fde74a Author: Daniel Xu Date: Wed Mar 6 16:34:42 2024 -0700 pahole: Save btf_id for encoded functions Save the btf_id of the inserted function so that we can reuse it later without having to walk all of BTF to pull out the function name -> id mapping. diff --git a/btf_encoder.c b/btf_encoder.c index 89d994a..253e568 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -63,6 +63,7 @@ struct elf_function { size_t prefixlen; struct function *function; struct btf_encoder_state state; + int btf_id; }; struct var_info { @@ -905,7 +906,7 @@ static int32_t btf_encoder__save_func(struct btf_encoder *encoder, struct functi return 0; } -static int32_t btf_encoder__add_func(struct btf_encoder *encoder, struct function *fn) +static int32_t btf_encoder__add_func(struct btf_encoder *encoder, struct function *fn, struct elf_function *func) { int btf_fnproto_id, btf_fn_id, tag_type_id; struct llvm_annotation *annot; @@ -927,6 +928,7 @@ static int32_t btf_encoder__add_func(struct btf_encoder *encoder, struct functio return -1; } } + func->btf_id = btf_fn_id; return 0; } @@ -980,7 +982,7 @@ static void btf_encoder__add_saved_funcs(struct btf_encoder *encoder) } } else { encoder->type_id_off = func->state.type_id_off; - btf_encoder__add_func(encoder, fn); + btf_encoder__add_func(encoder, fn, func); } fn->proto.processed = 1; } @@ -2249,7 +2251,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, struct co if (save) err = btf_encoder__save_func(encoder, fn, func); else - err = btf_encoder__add_func(encoder, fn); + err = btf_encoder__add_func(encoder, fn, func); if (err) goto out; }