Skip to content

Commit 441f231

Browse files
committed
Revert "perf: cache symbol names to avoid per-call strlen"
This reverts commit 5f272c4 as it broke tests.
1 parent 1f44c6c commit 441f231

4 files changed

Lines changed: 5 additions & 21 deletions

File tree

src/input-files.cc

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,6 @@ InputFile<E>::InputFile(Context<E> &ctx, MappedFile *mf)
9393
shstrtab = this->get_string(ctx, shstrtab_idx);
9494
}
9595

96-
template <typename E>
97-
void InputFile<E>::populate_symbol_names() {
98-
symbol_names.reserve(elf_syms.size());
99-
for (const ElfSym<E> &esym : elf_syms) {
100-
const char *p = symbol_strtab.data() + esym.st_name;
101-
symbol_names.emplace_back(p, strlen(p));
102-
}
103-
}
104-
10596
template <typename E>
10697
ElfShdr<E> *InputFile<E>::find_section(i64 type) {
10798
for (ElfShdr<E> &sec : elf_sections)
@@ -338,7 +329,7 @@ void ObjectFile<E>::initialize_sections(Context<E> &ctx) {
338329
signature = this->shstrtab.data() +
339330
this->elf_sections[get_shndx(esym)].sh_name;
340331
} else {
341-
signature = this->symbol_names[shdr.sh_info];
332+
signature = this->symbol_strtab.data() + esym.st_name;
342333
}
343334

344335
// Ignore a broken comdat group GCC emits for .debug_macros.
@@ -655,7 +646,7 @@ void ObjectFile<E>::initialize_symbols(Context<E> &ctx) {
655646
if (esym.st_type == STT_SECTION)
656647
name = this->shstrtab.data() + this->elf_sections[get_shndx(esym)].sh_name;
657648
else
658-
name = this->symbol_names[i];
649+
name = this->symbol_strtab.data() + esym.st_name;
659650

660651
Symbol<E> &sym = this->local_syms[i];
661652
sym.set_name(name);
@@ -683,7 +674,7 @@ void ObjectFile<E>::initialize_symbols(Context<E> &ctx) {
683674
has_common_symbol = true;
684675

685676
// Get a symbol name
686-
std::string_view key = this->symbol_names[i];
677+
std::string_view key = this->symbol_strtab.data() + esym.st_name;
687678
std::string_view name = key;
688679

689680
// Parse symbol version after atsign
@@ -898,7 +889,6 @@ void ObjectFile<E>::parse(Context<E> &ctx) {
898889
this->first_global = symtab_sec->sh_info;
899890
this->elf_syms = this->template get_data<ElfSym<E>>(ctx, *symtab_sec);
900891
this->symbol_strtab = this->get_string(ctx, symtab_sec->sh_link);
901-
this->populate_symbol_names();
902892

903893
if (ElfShdr<E> *shdr = this->find_section(SHT_SYMTAB_SHNDX))
904894
symtab_shndx_sec = this->template get_data<U32<E>>(ctx, *shdr);

src/lto-unix.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ ObjectFile<E> *read_lto_object(Context<E> &ctx, MappedFile *mf) {
675675

676676
obj->symbol_strtab = save_string(ctx, strtab);
677677
obj->elf_syms = obj->lto_elf_syms;
678-
obj->populate_symbol_names();
679678
obj->initialize_symbols(ctx);
680679
plugin_symbols.clear();
681680
return obj;

src/mold.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,11 +1709,6 @@ class InputFile {
17091709
std::string_view shstrtab;
17101710
std::string_view symbol_strtab;
17111711

1712-
// Parallel to elf_syms; cached to avoid per-call strlen.
1713-
std::vector<std::string_view> symbol_names;
1714-
1715-
void populate_symbol_names();
1716-
17171712
bool as_needed = false;
17181713
bool has_init_array = false;
17191714
bool has_ctors = false;

src/passes.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,8 +2178,8 @@ void parse_symbol_version(Context<E> &ctx) {
21782178
if (sym->file != file)
21792179
continue;
21802180

2181-
std::string_view name = file->symbol_names[i];
2182-
std::string_view ver = name.substr(name.find('@') + 1);
2181+
const char *name = file->symbol_strtab.data() + file->elf_syms[i].st_name;
2182+
std::string_view ver = strchr(name, '@') + 1;
21832183

21842184
bool is_default = false;
21852185
if (ver.starts_with('@')) {

0 commit comments

Comments
 (0)