From 6d18d388c5da61ac7f4c14a43d6008f3f5e64edd Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 3 Nov 2016 13:24:29 +0000 Subject: [PATCH] Pass the section table around instead of recomputing it. llvm-svn: 285904 --- lld/ELF/InputFiles.cpp | 28 ++++++++++++++++------------ lld/ELF/InputFiles.h | 7 ++++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index a2ef1cc..f504ae0 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -150,10 +150,11 @@ uint32_t ELFFileBase::getSectionIndex(const Elf_Sym &Sym) const { return I; } -template void ELFFileBase::initStringTable() { +template +void ELFFileBase::initStringTable(ArrayRef Sections) { if (!Symtab) return; - StringTable = check(ELFObj.getStringTableForSymtab(*Symtab)); + StringTable = check(ELFObj.getStringTableForSymtab(*Symtab, Sections)); } template @@ -194,8 +195,9 @@ template uint32_t elf::ObjectFile::getMipsGp0() const { template void elf::ObjectFile::parse(DenseSet &ComdatGroups) { // Read section and symbol tables. - initializeSections(ComdatGroups); - initializeSymbols(); + ArrayRef ObjSections = check(this->ELFObj.sections()); + initializeSections(ComdatGroups, ObjSections); + initializeSymbols(ObjSections); } // Sections with SHT_GROUP and comdat bits define comdat section groups. @@ -209,7 +211,7 @@ elf::ObjectFile::getShtGroupSignature(ArrayRef Sections, 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)); + StringRef Strtab = check(Obj.getStringTableForSymtab(*Symtab, Sections)); return check(Sym->getName(Strtab)); } @@ -279,9 +281,9 @@ bool elf::ObjectFile::shouldMerge(const Elf_Shdr &Sec) { template void elf::ObjectFile::initializeSections( - DenseSet &ComdatGroups) { + DenseSet &ComdatGroups, + ArrayRef ObjSections) { const ELFFile &Obj = this->ELFObj; - ArrayRef ObjSections = check(Obj.sections()); uint64_t Size = ObjSections.size(); Sections.resize(Size); unsigned I = -1; @@ -443,8 +445,9 @@ elf::ObjectFile::createInputSection(const Elf_Shdr &Sec, return make>(this, &Sec, Name); } -template void elf::ObjectFile::initializeSymbols() { - this->initStringTable(); +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); @@ -601,7 +604,7 @@ template void SharedFile::parseSoName() { if (this->VersymSec && !this->Symtab) error("SHT_GNU_versym should be associated with symbol table"); - this->initStringTable(); + this->initStringTable(Sections); // DSOs are identified by soname, and they usually contain // DT_SONAME tag in their header. But if they are missing, @@ -889,12 +892,13 @@ template std::vector LazyObjectFile::getElfSymbols() { typedef typename ELFT::SymRange Elf_Sym_Range; const ELFFile Obj = createELFObj(this->MB); - for (const Elf_Shdr &Sec : check(Obj.sections())) { + ArrayRef Sections = check(Obj.sections()); + for (const Elf_Shdr &Sec : Sections) { if (Sec.sh_type != SHT_SYMTAB) continue; Elf_Sym_Range Syms = Obj.symbols(&Sec); uint32_t FirstNonLocal = Sec.sh_info; - StringRef StringTable = check(Obj.getStringTableForSymtab(Sec)); + StringRef StringTable = check(Obj.getStringTableForSymtab(Sec, Sections)); std::vector V; for (const Elf_Sym &Sym : Syms.slice(FirstNonLocal)) if (Sym.st_shndx != SHN_UNDEF) diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index f2f0f8c..4454604 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(); + void initStringTable(ArrayRef Sections); }; // .o file. @@ -179,8 +179,9 @@ public: private: void - initializeSections(llvm::DenseSet &ComdatGroups); - void initializeSymbols(); + initializeSections(llvm::DenseSet &ComdatGroups, + ArrayRef ObjSections); + void initializeSymbols(ArrayRef Sections); void initializeDwarfLine(); InputSectionBase *getRelocTarget(const Elf_Shdr &Sec); InputSectionBase *createInputSection(const Elf_Shdr &Sec, -- 2.7.4