From 2b6631bb36e3416b3aedba78ea6756b3a760c330 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 15 Aug 2017 17:01:39 +0000 Subject: [PATCH] Remove GdbIndexSection::finalizeContents. GdbIndexSection doesn't need lazy finalization because when an instance of the class is created, we already know all debug info sections. We can initialize the instnace in the ctor. llvm-svn: 310931 --- lld/ELF/SyntheticSections.cpp | 39 +++++++++++++---------------------- lld/ELF/SyntheticSections.h | 7 ++----- lld/ELF/Writer.cpp | 20 +++++++++++------- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index ad7b0987cc83..ebd77c83be17 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1708,10 +1708,6 @@ unsigned PltSection::getPltRelocOff() const { return (HeaderSize == 0) ? InX::Plt->getSize() : 0; } -GdbIndexSection::GdbIndexSection(std::vector &&Chunks) - : SyntheticSection(0, SHT_PROGBITS, 1, ".gdb_index"), - StringPool(llvm::StringTableBuilder::ELF), Chunks(std::move(Chunks)) {} - // The hash function used for .gdb_index version 5 or above. static uint32_t gdbHash(StringRef Str) { uint32_t R = 0; @@ -1793,7 +1789,7 @@ void GdbIndexSection::buildIndex() { bool IsNew; GdbSymbol *Sym; - std::tie(IsNew, Sym) = SymbolTable.add(Hash, Offset); + std::tie(IsNew, Sym) = HashTab.add(Hash, Offset); if (IsNew) { Sym->CuVectorIndex = CuVectors.size(); CuVectors.resize(CuVectors.size() + 1); @@ -1840,44 +1836,37 @@ static size_t getAddressAreaSize(ArrayRef Arr) { return Ret; } -void GdbIndexSection::finalizeContents() { - if (Finalized) - return; - Finalized = true; - +GdbIndexSection::GdbIndexSection(std::vector &&C) + : SyntheticSection(0, SHT_PROGBITS, 1, ".gdb_index"), + StringPool(llvm::StringTableBuilder::ELF), Chunks(std::move(C)) { buildIndex(); - - SymbolTable.finalizeContents(); + HashTab.finalizeContents(); // GdbIndex header consist from version fields // and 5 more fields with different kinds of offsets. CuTypesOffset = CuListOffset + getCuSize(Chunks) * CompilationUnitSize; SymTabOffset = CuTypesOffset + getAddressAreaSize(Chunks) * AddressEntrySize; - - ConstantPoolOffset = - SymTabOffset + SymbolTable.getCapacity() * SymTabEntrySize; + ConstantPoolOffset = SymTabOffset + HashTab.getCapacity() * SymTabEntrySize; for (std::set &CuVec : CuVectors) { CuVectorsOffset.push_back(CuVectorsSize); CuVectorsSize += OffsetTypeSize * (CuVec.size() + 1); } StringPoolOffset = ConstantPoolOffset + CuVectorsSize; - StringPool.finalizeInOrder(); } size_t GdbIndexSection::getSize() const { - const_cast(this)->finalizeContents(); return StringPoolOffset + StringPool.getSize(); } 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. - write32le(Buf + 12, CuTypesOffset); // Address area offset. - write32le(Buf + 16, SymTabOffset); // Symbol table offset. - write32le(Buf + 20, ConstantPoolOffset); // Constant pool offset. + write32le(Buf, 7); // Write version + write32le(Buf + 4, CuListOffset); // CU list offset + write32le(Buf + 8, CuTypesOffset); // Types CU list offset + write32le(Buf + 12, CuTypesOffset); // Address area offset + write32le(Buf + 16, SymTabOffset); // Symbol table offset + write32le(Buf + 20, ConstantPoolOffset); // Constant pool offset Buf += 24; // Write the CU list. @@ -1902,8 +1891,8 @@ void GdbIndexSection::writeTo(uint8_t *Buf) { } // Write the symbol table. - for (size_t I = 0; I < SymbolTable.getCapacity(); ++I) { - GdbSymbol *Sym = SymbolTable.getSymbol(I); + for (size_t I = 0; I < HashTab.getCapacity(); ++I) { + GdbSymbol *Sym = HashTab.getSymbol(I); if (Sym) { size_t NameOffset = Sym->NameOffset + StringPoolOffset - ConstantPoolOffset; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index ddd8ca99a61b..81761d893c1b 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -504,14 +504,14 @@ class GdbIndexSection final : public SyntheticSection { public: GdbIndexSection(std::vector &&Chunks); - void finalizeContents() override; void writeTo(uint8_t *Buf) override; size_t getSize() const override; bool empty() const override; +private: // Symbol table is a hash table for types and names. // It is the area of gdb index. - GdbHashTab SymbolTable; + GdbHashTab HashTab; // CU vector is a part of constant pool area of section. std::vector> CuVectors; @@ -523,7 +523,6 @@ public: // object and used to build different areas of gdb index. std::vector Chunks; -private: void buildIndex(); uint32_t CuTypesOffset; @@ -533,8 +532,6 @@ private: size_t CuVectorsSize = 0; std::vector CuVectorsOffset; - - bool Finalized = false; }; template GdbIndexSection *createGdbIndex(); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 56ba9624461e..a243a0b9bbe6 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1293,14 +1293,18 @@ template void Writer::finalizeSections() { // Dynamic section must be the last one in this list and dynamic // symbol table section (DynSymTab) must be the first one. - applySynthetic({InX::DynSymTab, InX::Bss, InX::BssRelRo, - InX::GnuHashTab, In::HashTab, InX::SymTab, - InX::ShStrTab, InX::StrTab, In::VerDef, - InX::DynStrTab, InX::GdbIndex, InX::Got, - InX::MipsGot, InX::IgotPlt, InX::GotPlt, - In::RelaDyn, In::RelaIplt, In::RelaPlt, - InX::Plt, InX::Iplt, In::EhFrameHdr, - In::VerSym, In::VerNeed, InX::Dynamic}, + applySynthetic({InX::DynSymTab, InX::Bss, + InX::BssRelRo, InX::GnuHashTab, + In::HashTab, InX::SymTab, + InX::ShStrTab, InX::StrTab, + In::VerDef, InX::DynStrTab, + InX::Got, InX::MipsGot, + InX::IgotPlt, InX::GotPlt, + In::RelaDyn, In::RelaIplt, + In::RelaPlt, InX::Plt, + InX::Iplt, In::EhFrameHdr, + In::VerSym, In::VerNeed, + InX::Dynamic}, [](SyntheticSection *SS) { SS->finalizeContents(); }); // Some architectures use small displacements for jump instructions.