[PATCH] D30976: [ELF] - Detemplate GdbIndexSection.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 20 17:22:30 PDT 2017
Thinking a bit more about it, LGTM.
Our file class hierarchy is already a bit odd, but this is consistent
with its oddness.
If we wanted to be more precise, we would probably need some mixins:
* Things that go in a archive (.bc, .o, binary)
* Things that have sections (.o, binary)
Cheers,
Rafael
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
> grimar updated this revision to Diff 92312.
> grimar added a comment.
>
> - Rebased.
>
>
> https://reviews.llvm.org/D30976
>
> Files:
> ELF/InputFiles.h
> ELF/SyntheticSections.cpp
> ELF/SyntheticSections.h
> ELF/Writer.cpp
>
> Index: ELF/Writer.cpp
> ===================================================================
> --- ELF/Writer.cpp
> +++ ELF/Writer.cpp
> @@ -428,7 +428,7 @@
> Add(In<ELFT>::IgotPlt);
>
> if (Config->GdbIndex) {
> - In<ELFT>::GdbIndex = make<GdbIndexSection<ELFT>>();
> + In<ELFT>::GdbIndex = make<GdbIndexSection>();
> Add(In<ELFT>::GdbIndex);
> }
>
> Index: ELF/SyntheticSections.h
> ===================================================================
> --- ELF/SyntheticSections.h
> +++ ELF/SyntheticSections.h
> @@ -499,7 +499,7 @@
> size_t HeaderSize;
> };
>
> -template <class ELFT> 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<ELFT> *DynSymTab;
> static EhFrameHeader<ELFT> *EhFrameHdr;
> static GnuHashTableSection<ELFT> *GnuHashTab;
> - static GdbIndexSection<ELFT> *GdbIndex;
> static GotSection<ELFT> *Got;
> static EhFrameSection<ELFT> *EhFrame;
> static MipsGotSection<ELFT> *MipsGot;
> @@ -796,7 +796,6 @@
> template <class ELFT> DynamicSection<ELFT> *In<ELFT>::Dynamic;
> template <class ELFT> SymbolTableSection<ELFT> *In<ELFT>::DynSymTab;
> template <class ELFT> EhFrameHeader<ELFT> *In<ELFT>::EhFrameHdr;
> -template <class ELFT> GdbIndexSection<ELFT> *In<ELFT>::GdbIndex;
> template <class ELFT> GnuHashTableSection<ELFT> *In<ELFT>::GnuHashTab;
> template <class ELFT> GotSection<ELFT> *In<ELFT>::Got;
> template <class ELFT> EhFrameSection<ELFT> *In<ELFT>::EhFrame;
> Index: ELF/SyntheticSections.cpp
> ===================================================================
> --- ELF/SyntheticSections.cpp
> +++ ELF/SyntheticSections.cpp
> @@ -1690,8 +1690,7 @@
> return (HeaderSize == 0) ? InX::Plt->getSize() : 0;
> }
>
> -template <class ELFT>
> -GdbIndexSection<ELFT>::GdbIndexSection()
> +GdbIndexSection::GdbIndexSection()
> : SyntheticSection(0, SHT_PROGBITS, 1, ".gdb_index"),
> StringPool(llvm::StringTableBuilder::ELF) {}
>
> @@ -1723,18 +1722,15 @@
> return nullptr;
> }
>
> -template <class ELFT>
> static std::vector<AddressEntry>
> readAddressArea(DWARFContext &Dwarf, InputSection *Sec, size_t CurrentCU) {
> std::vector<AddressEntry> Ret;
>
> for (std::unique_ptr<DWARFCompileUnit> &CU : Dwarf.compile_units()) {
> DWARFAddressRangesVector Ranges;
> CU->collectAddressRanges(Ranges);
>
> - ArrayRef<InputSectionBase *> Sections =
> - Sec->template getFile<ELFT>()->getSections();
> -
> + ArrayRef<InputSectionBase *> Sections = Sec->File->getSections();
> for (std::pair<uint64_t, uint64_t> &R : Ranges)
> if (InputSectionBase *S = findSection(Sections, R.first))
> Ret.push_back({S, R.first - S->getOffsetInFile(),
> @@ -1770,7 +1766,7 @@
> std::unique_ptr<llvm::LoadedObjectInfo> clone() const override { return {}; }
> };
>
> -template <class ELFT> void GdbIndexSection<ELFT>::readDwarf(InputSection *Sec) {
> +void GdbIndexSection::readDwarf(InputSection *Sec) {
> Expected<std::unique_ptr<object::ObjectFile>> Obj =
> object::ObjectFile::createObjectFile(Sec->File->MB);
> if (!Obj) {
> @@ -1785,11 +1781,11 @@
> for (std::pair<uint64_t, uint64_t> &P : readCuList(Dwarf, Sec))
> CompilationUnits.push_back(P);
>
> - for (AddressEntry &Ent : readAddressArea<ELFT>(Dwarf, Sec, CuId))
> + for (AddressEntry &Ent : readAddressArea(Dwarf, Sec, CuId))
> AddressArea.push_back(Ent);
>
> std::vector<std::pair<StringRef, uint8_t>> NamesAndTypes =
> - readPubNamesAndTypes(Dwarf, ELFT::TargetEndianness == support::little);
> + readPubNamesAndTypes(Dwarf, Config->IsLE);
>
> for (std::pair<StringRef, uint8_t> &Pair : NamesAndTypes) {
> uint32_t Hash = hash(Pair.first);
> @@ -1808,7 +1804,7 @@
> }
> }
>
> -template <class ELFT> void GdbIndexSection<ELFT>::finalizeContents() {
> +void GdbIndexSection::finalizeContents() {
> if (Finalized)
> return;
> Finalized = true;
> @@ -1837,12 +1833,12 @@
> StringPool.finalizeInOrder();
> }
>
> -template <class ELFT> size_t GdbIndexSection<ELFT>::getSize() const {
> - const_cast<GdbIndexSection<ELFT> *>(this)->finalizeContents();
> +size_t GdbIndexSection::getSize() const {
> + const_cast<GdbIndexSection *>(this)->finalizeContents();
> return StringPoolOffset + StringPool.getSize();
> }
>
> -template <class ELFT> void GdbIndexSection<ELFT>::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 <class ELFT> bool GdbIndexSection<ELFT>::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<ELF64LE>;
> template class elf::HashTableSection<ELF64BE>;
>
> -template class elf::GdbIndexSection<ELF32LE>;
> -template class elf::GdbIndexSection<ELF32BE>;
> -template class elf::GdbIndexSection<ELF64LE>;
> -template class elf::GdbIndexSection<ELF64BE>;
> -
> template class elf::EhFrameHeader<ELF32LE>;
> template class elf::EhFrameHeader<ELF32BE>;
> template class elf::EhFrameHeader<ELF64LE>;
> 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<InputSectionBase *> 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<InputSectionBase *> 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<InputSectionBase *> Sections;
> -
> // List of all symbols referenced or defined by this file.
> std::vector<SymbolBody *> SymbolBodies;
>
> @@ -320,10 +326,6 @@
> explicit BinaryFile(MemoryBufferRef M) : InputFile(BinaryKind, M) {}
> static bool classof(const InputFile *F) { return F->kind() == BinaryKind; }
> template <class ELFT> void parse();
> - ArrayRef<InputSectionBase *> getSections() const { return Sections; }
> -
> -private:
> - std::vector<InputSectionBase *> Sections;
> };
>
> InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "",
More information about the llvm-commits
mailing list