From 82e5b5101a6adf737284fa209a02985ef047b351 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Thu, 24 Jun 2021 10:01:27 -0300 Subject: [PATCH] core: Make function->name a real string For the threaded code we want to access strings in tags at the same time that the string table may grow in another thread making the previous pointer invalid, so, to avoid excessive locking, use plain strings. The way the tools work will either consume the just produced CU straight away or keep just one copy of each data structure when we keep all CUs in memory, so lets try stopping using strings_t for strings. For the function->name case we get the bonus of removing the need of a debug_fmt_ops->function() callback receiving the 'cu', just access the string directly. Signed-off-by: Arnaldo Carvalho de Melo --- btf_encoder.c | 2 +- btf_loader.c | 7 ++++++- ctf_loader.c | 11 +---------- dwarf_loader.c | 2 +- dwarves.c | 4 +--- dwarves.h | 13 +++---------- 6 files changed, 13 insertions(+), 26 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 1b0e583..c79c5d2 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -1425,7 +1425,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu) } btf_fnproto_id = btf_encoder__add_func_proto(encoder, cu, &fn->proto, type_id_off); - name = dwarves__active_loader->strings__ptr(cu, fn->name); + name = function__name(fn, cu); btf_fn_id = btf_encoder__add_ref_type(encoder, BTF_KIND_FUNC, btf_fnproto_id, name, false); if (btf_fnproto_id < 0 || btf_fn_id < 0) { err = -1; diff --git a/btf_loader.c b/btf_loader.c index 75ec674..3fc2a4a 100644 --- a/btf_loader.c +++ b/btf_loader.c @@ -35,6 +35,11 @@ */ extern struct strings *strings; +static const char *cu__btf_str(struct cu *cu, uint32_t offset) +{ + return offset ? btf__str_by_offset(cu->priv, offset) : NULL; +} + static void *tag__alloc(const size_t size) { struct tag *tag = zalloc(size); @@ -89,7 +94,7 @@ static int create_new_function(struct cu *cu, const struct btf_type *tp, uint32_ func->btf = 1; func->proto.tag.tag = DW_TAG_subprogram; func->proto.tag.type = tp->type; - func->name = tp->name_off; + func->name = cu__btf_str(cu, tp->name_off); INIT_LIST_HEAD(&func->lexblock.tags); cu__add_tag_with_id(cu, &func->proto.tag, id); diff --git a/ctf_loader.c b/ctf_loader.c index 9f03f09..44b70d3 100644 --- a/ctf_loader.c +++ b/ctf_loader.c @@ -94,7 +94,7 @@ static struct function *function__new(uint16_t **ptr, GElf_Sym *sym, if (func != NULL) { func->lexblock.ip.addr = elf_sym__value(sym); func->lexblock.size = elf_sym__size(sym); - func->name = sym->st_name; + func->name = elf_sym__name(sym, ctf->symtab); func->vtable_entry = -1; func->external = elf_sym__bind(sym) == STB_GLOBAL; INIT_LIST_HEAD(&func->vtable_node); @@ -691,14 +691,6 @@ static int cu__fixup_ctf_bitfields(struct cu *cu) return err; } -static const char *ctf__function_name(struct function *func, - const struct cu *cu) -{ - struct ctf *ctf = cu->priv; - - return ctf->symtab->symstrs->d_buf + func->name; -} - static const char *ctf__variable_name(const struct variable *var, const struct cu *cu) { @@ -763,7 +755,6 @@ int ctf__load_file(struct cus *cus, struct conf_load *conf, struct debug_fmt_ops ctf__ops = { .name = "ctf", - .function__name = ctf__function_name, .load_file = ctf__load_file, .variable__name = ctf__variable_name, .strings__ptr = ctf__strings_ptr, diff --git a/dwarf_loader.c b/dwarf_loader.c index 48469a4..ea463c1 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -1058,7 +1058,7 @@ static struct function *function__new(Dwarf_Die *die, struct cu *cu) if (func != NULL) { ftype__init(&func->proto, die, cu); lexblock__init(&func->lexblock, cu, die); - func->name = strings__add(strings, attr_string(die, DW_AT_name)); + func->name = strdup_attr_string(die, DW_AT_name); func->linkage_name = strdup_attr_string(die, DW_AT_MIPS_linkage_name); func->inlined = attr_numeric(die, DW_AT_inline); func->declaration = dwarf_hasattr(die, DW_AT_declaration); diff --git a/dwarves.c b/dwarves.c index be8195f..602c928 100644 --- a/dwarves.c +++ b/dwarves.c @@ -1306,9 +1306,7 @@ void lexblock__add_lexblock(struct lexblock *block, struct lexblock *child) const char *function__name(struct function *func, const struct cu *cu) { - if (cu->dfops && cu->dfops->function__name) - return cu->dfops->function__name(func, cu); - return s(cu, func->name); + return func->name; } static void parameter__delete(struct parameter *parm, struct cu *cu) diff --git a/dwarves.h b/dwarves.h index 75d003d..b32f17b 100644 --- a/dwarves.h +++ b/dwarves.h @@ -183,15 +183,10 @@ enum dwarf_languages { /** struct debug_fmt_ops - specific to the underlying debug file format * - * @function__name - will be called by function__name(), giving a chance to - * formats such as CTF to get this from some other place - * than the global strings table. CTF does this by storing - * GElf_Sym->st_name in function->name, and by using - * function->name as an index into the .strtab ELF section. - * @variable__name - will be called by variable__name(), see @function_name + * @variable__name - will be called by variable__name() * cu__delete - called at cu__delete(), to give a chance to formats such as * CTF to keep the .strstab ELF section available till the cu is - * deleted. See @function__name + * deleted. */ struct debug_fmt_ops { const char *name; @@ -208,8 +203,6 @@ struct debug_fmt_ops { const struct cu *cu); void (*tag__free_orig_info)(struct tag *tag, struct cu *cu); - const char *(*function__name)(struct function *tag, - const struct cu *cu); const char *(*variable__name)(const struct variable *var, const struct cu *cu); const char *(*strings__ptr)(const struct cu *cu, strings_t s); @@ -806,7 +799,7 @@ struct function { struct ftype proto; struct lexblock lexblock; struct rb_node rb_node; - strings_t name; + const char *name; const char *linkage_name; uint32_t cu_total_size_inline_expansions; uint16_t cu_total_nr_inline_expansions;