Index: lld/trunk/ELF/InputFiles.h =================================================================== --- lld/trunk/ELF/InputFiles.h +++ lld/trunk/ELF/InputFiles.h @@ -74,6 +74,13 @@ StringRef getName() const { return MB.getBufferIdentifier(); } MemoryBufferRef MB; + // If it is a file that can have sections, like object file or binary file, + // then method returns them. + ArrayRef getSections() const { + assert(FileKind == ObjectKind || FileKind == BinaryKind); + return Sections; + } + // 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. @@ -88,6 +95,8 @@ protected: InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {} + std::vector Sections; + private: const Kind FileKind; }; @@ -190,9 +199,6 @@ bool shouldMerge(const Elf_Shdr &Sec); SymbolBody *createSymbolBody(const Elf_Sym *Sym); - // List of all sections defined by this file. - std::vector Sections; - // List of all symbols referenced or defined by this file. std::vector SymbolBodies; @@ -320,10 +326,6 @@ explicit BinaryFile(MemoryBufferRef M) : InputFile(BinaryKind, M) {} static bool classof(const InputFile *F) { return F->kind() == BinaryKind; } template void parse(); - ArrayRef getSections() const { return Sections; } - -private: - std::vector Sections; }; InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "", Index: lld/trunk/ELF/SyntheticSections.h =================================================================== --- lld/trunk/ELF/SyntheticSections.h +++ lld/trunk/ELF/SyntheticSections.h @@ -497,7 +497,7 @@ size_t HeaderSize; }; -template class GdbIndexSection final : public SyntheticSection { +class GdbIndexSection final : public SyntheticSection { const unsigned OffsetTypeSize = 4; const unsigned CuListOffset = 6 * OffsetTypeSize; const unsigned CompilationUnitSize = 16; @@ -762,6 +762,7 @@ static InputSection *Common; static StringTableSection *DynStrTab; static InputSection *Interp; + static GdbIndexSection *GdbIndex; static GotPltSection *GotPlt; static IgotPltSection *IgotPlt; static MipsGotSection *MipsGot; @@ -777,7 +778,6 @@ static SymbolTableSection *DynSymTab; static EhFrameHeader *EhFrameHdr; static GnuHashTableSection *GnuHashTab; - static GdbIndexSection *GdbIndex; static GotSection *Got; static EhFrameSection *EhFrame; static HashTableSection *HashTab; @@ -793,7 +793,6 @@ template DynamicSection *In::Dynamic; template SymbolTableSection *In::DynSymTab; template EhFrameHeader *In::EhFrameHdr; -template GdbIndexSection *In::GdbIndex; template GnuHashTableSection *In::GnuHashTab; template GotSection *In::Got; template EhFrameSection *In::EhFrame; Index: lld/trunk/ELF/SyntheticSections.cpp =================================================================== --- lld/trunk/ELF/SyntheticSections.cpp +++ lld/trunk/ELF/SyntheticSections.cpp @@ -1674,8 +1674,7 @@ return (HeaderSize == 0) ? InX::Plt->getSize() : 0; } -template -GdbIndexSection::GdbIndexSection() +GdbIndexSection::GdbIndexSection() : SyntheticSection(0, SHT_PROGBITS, 1, ".gdb_index"), StringPool(llvm::StringTableBuilder::ELF) {} @@ -1707,7 +1706,6 @@ return nullptr; } -template static std::vector readAddressArea(DWARFContext &Dwarf, InputSection *Sec, size_t CurrentCU) { std::vector Ret; @@ -1716,9 +1714,7 @@ DWARFAddressRangesVector Ranges; CU->collectAddressRanges(Ranges); - ArrayRef Sections = - Sec->template getFile()->getSections(); - + ArrayRef Sections = Sec->File->getSections(); for (std::pair &R : Ranges) if (InputSectionBase *S = findSection(Sections, R.first)) Ret.push_back({S, R.first - S->getOffsetInFile(), @@ -1754,7 +1750,7 @@ std::unique_ptr clone() const override { return {}; } }; -template void GdbIndexSection::readDwarf(InputSection *Sec) { +void GdbIndexSection::readDwarf(InputSection *Sec) { Expected> Obj = object::ObjectFile::createObjectFile(Sec->File->MB); if (!Obj) { @@ -1769,11 +1765,11 @@ for (std::pair &P : readCuList(Dwarf, Sec)) CompilationUnits.push_back(P); - for (AddressEntry &Ent : readAddressArea(Dwarf, Sec, CuId)) + for (AddressEntry &Ent : readAddressArea(Dwarf, Sec, CuId)) AddressArea.push_back(Ent); std::vector> NamesAndTypes = - readPubNamesAndTypes(Dwarf, ELFT::TargetEndianness == support::little); + readPubNamesAndTypes(Dwarf, Config->IsLE); for (std::pair &Pair : NamesAndTypes) { uint32_t Hash = hash(Pair.first); @@ -1792,7 +1788,7 @@ } } -template void GdbIndexSection::finalizeContents() { +void GdbIndexSection::finalizeContents() { if (Finalized) return; Finalized = true; @@ -1821,12 +1817,12 @@ StringPool.finalizeInOrder(); } -template size_t GdbIndexSection::getSize() const { - const_cast *>(this)->finalizeContents(); +size_t GdbIndexSection::getSize() const { + const_cast(this)->finalizeContents(); return StringPoolOffset + StringPool.getSize(); } -template void GdbIndexSection::writeTo(uint8_t *Buf) { +void GdbIndexSection::writeTo(uint8_t *Buf) { write32le(Buf, 7); // Write version. write32le(Buf + 4, CuListOffset); // CU list offset. write32le(Buf + 8, CuTypesOffset); // Types CU list offset. @@ -1880,7 +1876,7 @@ StringPool.write(Buf); } -template bool GdbIndexSection::empty() const { +bool GdbIndexSection::empty() const { return !Out::DebugInfo; } @@ -2239,6 +2235,7 @@ InputSection *InX::Common; StringTableSection *InX::DynStrTab; InputSection *InX::Interp; +GdbIndexSection *InX::GdbIndex; GotPltSection *InX::GotPlt; IgotPltSection *InX::IgotPlt; MipsGotSection *InX::MipsGot; @@ -2321,11 +2318,6 @@ template class elf::HashTableSection; template class elf::HashTableSection; -template class elf::GdbIndexSection; -template class elf::GdbIndexSection; -template class elf::GdbIndexSection; -template class elf::GdbIndexSection; - template class elf::EhFrameHeader; template class elf::EhFrameHeader; template class elf::EhFrameHeader; Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -428,7 +428,7 @@ Add(In::IgotPlt); if (Config->GdbIndex) { - In::GdbIndex = make>(); + In::GdbIndex = make(); Add(In::GdbIndex); }