Index: ELF/InputFiles.h =================================================================== --- ELF/InputFiles.h +++ 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. @@ -94,6 +101,8 @@ protected: InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {} + std::vector Sections; + private: const Kind FileKind; }; @@ -196,9 +205,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: ELF/SyntheticSections.h =================================================================== --- ELF/SyntheticSections.h +++ ELF/SyntheticSections.h @@ -499,7 +499,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; @@ -763,6 +763,7 @@ static InputSection *Common; static StringTableSection *DynStrTab; static InputSection *Interp; + static GdbIndexSection *GdbIndex; static GotPltSection *GotPlt; static IgotPltSection *IgotPlt; static MipsRldMapSection *MipsRldMap; @@ -778,7 +779,6 @@ static SymbolTableSection *DynSymTab; static EhFrameHeader *EhFrameHdr; static GnuHashTableSection *GnuHashTab; - static GdbIndexSection *GdbIndex; static GotSection *Got; static EhFrameSection *EhFrame; static MipsGotSection *MipsGot; @@ -796,7 +796,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: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -1690,8 +1690,7 @@ return (HeaderSize == 0) ? InX::Plt->getSize() : 0; } -template -GdbIndexSection::GdbIndexSection() +GdbIndexSection::GdbIndexSection() : SyntheticSection(0, SHT_PROGBITS, 1, ".gdb_index"), StringPool(llvm::StringTableBuilder::ELF) {} @@ -1723,7 +1722,6 @@ return nullptr; } -template static std::vector readAddressArea(DWARFContext &Dwarf, InputSection *Sec, size_t CurrentCU) { std::vector Ret; @@ -1732,9 +1730,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(), @@ -1770,7 +1766,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) { @@ -1785,11 +1781,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); @@ -1808,7 +1804,7 @@ } } -template void GdbIndexSection::finalizeContents() { +void GdbIndexSection::finalizeContents() { if (Finalized) return; Finalized = true; @@ -1837,12 +1833,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. @@ -1896,7 +1892,7 @@ StringPool.write(Buf); } -template bool GdbIndexSection::empty() const { +bool GdbIndexSection::empty() const { return !Out::DebugInfo; } @@ -2254,6 +2250,7 @@ InputSection *InX::Common; StringTableSection *InX::DynStrTab; InputSection *InX::Interp; +GdbIndexSection *InX::GdbIndex; GotPltSection *InX::GotPlt; IgotPltSection *InX::IgotPlt; MipsRldMapSection *InX::MipsRldMap; @@ -2345,11 +2342,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: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -428,7 +428,7 @@ Add(In::IgotPlt); if (Config->GdbIndex) { - In::GdbIndex = make>(); + In::GdbIndex = make(); Add(In::GdbIndex); }