Index: ELF/InputFiles.h =================================================================== --- ELF/InputFiles.h +++ ELF/InputFiles.h @@ -17,6 +17,7 @@ #include "lld/Core/LLVM.h" #include "lld/Core/Reproduce.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/CachedHashString.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" @@ -83,6 +84,15 @@ return Sections; } + // Returns object file symbols. It is a runtime error to call this function + // on files not of ObjectKind type. + ArrayRef getObjSymbols() const { + assert(FileKind == ObjectKind); + if (SymbolBodies.empty()) + return SymbolBodies; + return llvm::makeArrayRef(SymbolBodies).slice(1); + } + // 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 +111,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 +171,6 @@ static std::vector *> Instances; - ArrayRef getSymbols(); ArrayRef getLocalSymbols(); ObjFile(MemoryBufferRef M, StringRef ArchiveName); @@ -204,9 +217,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 @@ -167,12 +167,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/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -227,7 +227,7 @@ SrcFile = toString(File); // Find a function symbol that encloses a given location. - for (SymbolBody *B : getFile()->getSymbols()) + for (SymbolBody *B : getFile()->getObjSymbols()) if (auto *D = dyn_cast(B)) if (D->Section == this && D->Type == STT_FUNC) if (D->Value <= Offset && Offset < D->Value + D->Size) @@ -285,7 +285,7 @@ Archive = (" in archive " + File->ArchiveName).str(); // Find a symbol that encloses a given location. - for (SymbolBody *B : getFile()->getSymbols()) + for (SymbolBody *B : getFile()->getObjSymbols()) if (auto *D = dyn_cast(B)) if (D->Section == this && D->Value <= Off && Off < D->Value + D->Size) return Filename + ":(" + toString(*D) + ")" + Archive; Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -1019,7 +1019,6 @@ return LA->OutSecOff < LB->OutSecOff; } -template static void finalizeShtGroup(OutputSection *OS, ArrayRef Sections) { assert(Config->Relocatable && Sections.size() == 1); @@ -1030,8 +1029,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->getObjSymbols(); OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info - 1]); } @@ -1062,7 +1060,7 @@ uint32_t Type = Sec->Type; if (Type == SHT_GROUP) { - finalizeShtGroup(Sec, Sections); + finalizeShtGroup(Sec, Sections); return; } Index: ELF/MapFile.cpp =================================================================== --- ELF/MapFile.cpp +++ ELF/MapFile.cpp @@ -52,7 +52,7 @@ template std::vector getSymbols() { std::vector V; for (ObjFile *File : ObjFile::Instances) - for (SymbolBody *B : File->getSymbols()) + for (SymbolBody *B : File->getObjSymbols()) if (B->File == File && !B->isSection()) if (auto *Sym = dyn_cast(B)) if (Sym->Section && Sym->Section->Live) Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -894,7 +894,7 @@ // Build a map from sections to their priorities. DenseMap SectionOrder; for (ObjFile *File : ObjFile::Instances) { - for (SymbolBody *Body : File->getSymbols()) { + for (SymbolBody *Body : File->getObjSymbols()) { auto *D = dyn_cast(Body); if (!D || !D->Section) continue;