diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index dfcd1508c876..a98c35974f53 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -146,9 +146,9 @@ uint32_t ELFFileBase::getSectionIndex(const Elf_Sym &Sym) const { } template -void ELFFileBase::initStringTable(ArrayRef Sections) { - if (!Symtab) - return; +void ELFFileBase::initSymtab(ArrayRef Sections, + const Elf_Shdr *Symtab) { + this->Symtab = Symtab; StringTable = check(ELFObj.getStringTableForSymtab(*Symtab, Sections)); } @@ -203,11 +203,11 @@ StringRef elf::ObjectFile::getShtGroupSignature(ArrayRef Sections, const Elf_Shdr &Sec) { const ELFFile &Obj = this->ELFObj; - const Elf_Shdr *Symtab = - check(object::getSection(Sections, Sec.sh_link)); - const Elf_Sym *Sym = check(Obj.getSymbol(Symtab, Sec.sh_info)); - StringRef Strtab = check(Obj.getStringTableForSymtab(*Symtab, Sections)); - return check(Sym->getName(Strtab)); + if (!this->Symtab) + this->initSymtab(Sections, + check(object::getSection(Sections, Sec.sh_link))); + const Elf_Sym *Sym = check(Obj.getSymbol(this->Symtab, Sec.sh_info)); + return check(Sym->getName(this->StringTable)); } template @@ -312,7 +312,7 @@ void elf::ObjectFile::initializeSections( } break; case SHT_SYMTAB: - this->Symtab = &Sec; + this->initSymtab(ObjSections, &Sec); break; case SHT_SYMTAB_SHNDX: this->SymtabSHNDX = check(Obj.getSHNDXTable(Sec, ObjSections)); @@ -442,7 +442,6 @@ elf::ObjectFile::createInputSection(const Elf_Shdr &Sec, template void elf::ObjectFile::initializeSymbols(ArrayRef Sections) { - this->initStringTable(Sections); Elf_Sym_Range Syms = this->getElfSymbols(false); uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end()); SymbolBodies.reserve(NumSymbols); @@ -576,7 +575,7 @@ template void SharedFile::parseSoName() { default: continue; case SHT_DYNSYM: - this->Symtab = &Sec; + this->initSymtab(Sections, &Sec); break; case SHT_DYNAMIC: DynamicSec = &Sec; @@ -596,8 +595,6 @@ template void SharedFile::parseSoName() { if (this->VersymSec && !this->Symtab) error("SHT_GNU_versym should be associated with symbol table"); - this->initStringTable(Sections); - // DSOs are identified by soname, and they usually contain // DT_SONAME tag in their header. But if they are missing, // filenames are used as default sonames. diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 886288cc53f9..7c6c7eb4ef3c 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -114,7 +114,7 @@ protected: const Elf_Shdr *Symtab = nullptr; ArrayRef SymtabSHNDX; StringRef StringTable; - void initStringTable(ArrayRef Sections); + void initSymtab(ArrayRef Sections, const Elf_Shdr *Symtab); }; // .o file.