commit da19399c6c9d942430974aca5af4409d89ece5bd Author: Daniel Xu Date: Tue Mar 12 20:40:13 2024 -0600 XXX: merge collected function info diff --git a/btf_encoder.c b/btf_encoder.c index 2ea58ea..609611d 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -730,6 +730,8 @@ static int32_t btf_encoder__add_var_secinfo(struct btf_encoder *encoder, uint32_ return gobuffer__add(&encoder->percpu_secinfo, &si, sizeof(si)); } +static void btf_encoder__append_functions(struct btf_encoder *encoder, struct btf_encoder *other); + int32_t btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other) { struct gobuffer *var_secinfo_buf = &other->percpu_secinfo; @@ -744,6 +746,7 @@ int32_t btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder return 0; btf_encoder__add_saved_funcs(other); + btf_encoder__append_functions(encoder, other); for (i = 0; i < nr_var_secinfo; i++) { vsi = (struct btf_var_secinfo *)var_secinfo_buf->entries + i; @@ -1016,6 +1019,31 @@ static void *reallocarray_grow(void *ptr, int *nmemb, size_t size) return new; } +static void btf_encoder__append_functions(struct btf_encoder *encoder, struct btf_encoder *other) +{ + int want = encoder->functions.cnt + other->functions.cnt; + size_t entry_sz = sizeof(encoder->functions.entries[0]); + void *end; + + if (encoder->functions.allocated < want) { + void *new = realloc(encoder->functions.entries, want * entry_sz); + encoder->functions.entries = new; + encoder->functions.allocated = want; + } + + end = &encoder->functions.entries[encoder->functions.cnt]; + memcpy(end, other->functions.entries, other->functions.cnt * entry_sz); + encoder->functions.cnt += other->functions.cnt; + encoder->functions.suffix_cnt += other->functions.suffix_cnt; +} + +void btf_encoder__finalize(struct btf_encoder *encoder) +{ + size_t entry_sz = sizeof(encoder->functions.entries[0]); + + qsort(encoder->functions.entries, encoder->functions.cnt, entry_sz, functions_cmp); +} + static int btf_encoder__collect_function(struct btf_encoder *encoder, GElf_Sym *sym) { struct elf_function *new; diff --git a/btf_encoder.h b/btf_encoder.h index f54c95a..06eaa26 100644 --- a/btf_encoder.h +++ b/btf_encoder.h @@ -26,5 +26,6 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, struct co struct btf *btf_encoder__btf(struct btf_encoder *encoder); int btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other); +void btf_encoder__finalize(struct btf_encoder *encoder); #endif /* _BTF_ENCODER_H_ */ diff --git a/pahole.c b/pahole.c index 353a080..f63b5a7 100644 --- a/pahole.c +++ b/pahole.c @@ -3213,6 +3213,7 @@ static int pahole_threads_collect(struct conf_load *conf, int nr_threads, void * if (err < 0) goto out; } + btf_encoder__finalize(btf_encoder); err = 0; out: