Index: ELF/InputFiles.h =================================================================== --- ELF/InputFiles.h +++ ELF/InputFiles.h @@ -83,6 +83,10 @@ return Sections; } + // Returns object file symbols. It is a runtime error to call this function + // on files not of ObjectKind type. + ArrayRef getSymbols() const; + // Filename of .a which contained this file. If this file was // not in an archive file, it is the empty string. We use this // string for creating error messages. @@ -101,6 +105,10 @@ InputFile(Kind K, MemoryBufferRef M); std::vector Sections; + // List of all symbols referenced or defined by this file. + // Applicable for ObjectKind files only. + std::vector SymbolBodies; + private: const Kind FileKind; }; @@ -157,7 +165,6 @@ static std::vector *> Instances; - ArrayRef getSymbols(); ArrayRef getLocalSymbols(); ObjFile(MemoryBufferRef M, StringRef ArchiveName); @@ -204,9 +211,6 @@ bool shouldMerge(const Elf_Shdr &Sec); SymbolBody *createSymbolBody(const Elf_Sym *Sym); - // List of all symbols referenced or defined by this file. - std::vector SymbolBodies; - // .shstrtab contents. StringRef SectionStringTable; Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -39,6 +39,13 @@ InputFile::InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {} +ArrayRef InputFile::getSymbols() const { + assert(FileKind == ObjectKind); + if (SymbolBodies.empty()) + return {}; + return llvm::makeArrayRef(SymbolBodies).slice(1); +} + Optional elf::readFile(StringRef Path) { // The --chroot option changes our virtual root directory. // This is useful when you are dealing with files created by --reproduce. @@ -167,12 +174,6 @@ return makeArrayRef(this->SymbolBodies).slice(1, this->FirstNonLocal - 1); } -template ArrayRef ObjFile::getSymbols() { - if (this->SymbolBodies.empty()) - return this->SymbolBodies; - return makeArrayRef(this->SymbolBodies).slice(1); -} - template void ObjFile::parse(DenseSet &ComdatGroups) { // Read section and symbol tables. Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -418,7 +418,6 @@ return LA->OutSecOff < LB->OutSecOff; } -template static void finalizeShtGroup(OutputSection *OS, ArrayRef Sections) { assert(Config->Relocatable && Sections.size() == 1); @@ -429,8 +428,7 @@ // sh_info then contain index of an entry in symbol table section which // provides signature of the section group. - ObjFile *Obj = Sections[0]->getFile(); - ArrayRef Symbols = Obj->getSymbols(); + ArrayRef Symbols = Sections[0]->File->getSymbols(); OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info - 1]); } @@ -460,7 +458,7 @@ } if (Type == SHT_GROUP) { - finalizeShtGroup(this, Sections); + finalizeShtGroup(this, Sections); return; }