@@ -93,6 +93,15 @@ 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+
96105template <typename E>
97106ElfShdr<E> *InputFile<E>::find_section(i64 type) {
98107 for (ElfShdr<E> &sec : elf_sections)
@@ -329,7 +338,7 @@ void ObjectFile<E>::initialize_sections(Context<E> &ctx) {
329338 signature = this ->shstrtab .data () +
330339 this ->elf_sections [get_shndx (esym)].sh_name ;
331340 } else {
332- signature = this ->symbol_strtab . data () + esym. st_name ;
341+ signature = this ->symbol_names [shdr. sh_info ] ;
333342 }
334343
335344 // Ignore a broken comdat group GCC emits for .debug_macros.
@@ -646,7 +655,7 @@ void ObjectFile<E>::initialize_symbols(Context<E> &ctx) {
646655 if (esym.st_type == STT_SECTION)
647656 name = this ->shstrtab .data () + this ->elf_sections [get_shndx (esym)].sh_name ;
648657 else
649- name = this ->symbol_strtab . data () + esym. st_name ;
658+ name = this ->symbol_names [i] ;
650659
651660 Symbol<E> &sym = this ->local_syms [i];
652661 sym.set_name (name);
@@ -674,7 +683,7 @@ void ObjectFile<E>::initialize_symbols(Context<E> &ctx) {
674683 has_common_symbol = true ;
675684
676685 // Get a symbol name
677- std::string_view key = this ->symbol_strtab . data () + esym. st_name ;
686+ std::string_view key = this ->symbol_names [i] ;
678687 std::string_view name = key;
679688
680689 // Parse symbol version after atsign
@@ -889,6 +898,7 @@ void ObjectFile<E>::parse(Context<E> &ctx) {
889898 this ->first_global = symtab_sec->sh_info ;
890899 this ->elf_syms = this ->template get_data <ElfSym<E>>(ctx, *symtab_sec);
891900 this ->symbol_strtab = this ->get_string (ctx, symtab_sec->sh_link );
901+ this ->populate_symbol_names ();
892902
893903 if (ElfShdr<E> *shdr = this ->find_section (SHT_SYMTAB_SHNDX))
894904 symtab_shndx_sec = this ->template get_data <U32<E>>(ctx, *shdr);
0 commit comments