From a113a4194c00b9867e2a1091fbd460b625e0d8bf Mon Sep 17 00:00:00 2001 From: Eugene Leviant Date: Mon, 21 Nov 2016 09:24:43 +0000 Subject: [PATCH] [ELF] Convert GdbIndexSection to input section Differential revision: https://reviews.llvm.org/D26854 llvm-svn: 287526 --- lld/ELF/OutputSections.cpp | 50 ------------------------------------------- lld/ELF/OutputSections.h | 27 ----------------------- lld/ELF/SyntheticSections.cpp | 48 +++++++++++++++++++++++++++++++++++++++++ lld/ELF/SyntheticSections.h | 29 +++++++++++++++++++++++++ lld/ELF/Writer.cpp | 11 +++++----- 5 files changed, 83 insertions(+), 82 deletions(-) diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index e4bc68d..85635e7 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -10,7 +10,6 @@ #include "OutputSections.h" #include "Config.h" #include "EhFrame.h" -#include "GdbIndex.h" #include "LinkerScript.h" #include "Memory.h" #include "Strings.h" @@ -63,50 +62,6 @@ void OutputSectionBase::writeHeaderTo(typename ELFT::Shdr *Shdr) { Shdr->sh_name = ShName; } -template -GdbIndexSection::GdbIndexSection() - : OutputSectionBase(".gdb_index", SHT_PROGBITS, 0) {} - -template void GdbIndexSection::parseDebugSections() { - std::vector *> &IS = - static_cast *>(Out::DebugInfo)->Sections; - - for (InputSection *I : IS) - readDwarf(I); -} - -template -void GdbIndexSection::readDwarf(InputSection *I) { - std::vector> CuList = readCuList(I); - CompilationUnits.insert(CompilationUnits.end(), CuList.begin(), CuList.end()); -} - -template void GdbIndexSection::finalize() { - parseDebugSections(); - - // GdbIndex header consist from version fields - // and 5 more fields with different kinds of offsets. - CuTypesOffset = CuListOffset + CompilationUnits.size() * CompilationUnitSize; - this->Size = CuTypesOffset; -} - -template 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, CuTypesOffset); // Symbol table offset - write32le(Buf + 20, CuTypesOffset); // Constant pool offset - Buf += 24; - - // Write the CU list. - for (std::pair CU : CompilationUnits) { - write64le(Buf, CU.first); - write64le(Buf + 8, CU.second); - Buf += 16; - } -} - // Returns the number of version definition entries. Because the first entry // is for the version definition itself, it is the number of versioned symbols // plus one. Note that we don't support multiple versions yet. @@ -908,11 +863,6 @@ template class VersionDefinitionSection; template class VersionDefinitionSection; template class VersionDefinitionSection; -template class GdbIndexSection; -template class GdbIndexSection; -template class GdbIndexSection; -template class GdbIndexSection; - template class OutputSectionFactory; template class OutputSectionFactory; template class OutputSectionFactory; diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 0c1c027..43995c7 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -11,7 +11,6 @@ #define LLD_ELF_OUTPUT_SECTIONS_H #include "Config.h" -#include "GdbIndex.h" #include "Relocations.h" #include "lld/Core/LLVM.h" @@ -105,30 +104,6 @@ public: uint32_t Link = 0; }; -template class GdbIndexSection final : public OutputSectionBase { - typedef typename ELFT::uint uintX_t; - - const unsigned OffsetTypeSize = 4; - const unsigned CuListOffset = 6 * OffsetTypeSize; - const unsigned CompilationUnitSize = 16; - const unsigned AddressEntrySize = 16 + OffsetTypeSize; - const unsigned SymTabEntrySize = 2 * OffsetTypeSize; - -public: - GdbIndexSection(); - void finalize() override; - void writeTo(uint8_t *Buf) override; - - // Pairs of [CU Offset, CU length]. - std::vector> CompilationUnits; - -private: - void parseDebugSections(); - void readDwarf(InputSection *I); - - uint32_t CuTypesOffset; -}; - // For more information about .gnu.version and .gnu.version_r see: // https://www.akkadia.org/drepper/symbol-versioning @@ -338,7 +313,6 @@ template struct Out { static uint8_t First; static EhFrameHeader *EhFrameHdr; static EhOutputSection *EhFrame; - static GdbIndexSection *GdbIndex; static OutputSection *Bss; static OutputSection *MipsRldMap; static OutputSectionBase *Opd; @@ -391,7 +365,6 @@ template uint64_t getHeaderSize() { template uint8_t Out::First; template EhFrameHeader *Out::EhFrameHdr; template EhOutputSection *Out::EhFrame; -template GdbIndexSection *Out::GdbIndex; template OutputSection *Out::Bss; template OutputSection *Out::MipsRldMap; template OutputSectionBase *Out::Opd; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 8f66ade0..65ca423 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1360,6 +1360,49 @@ template size_t PltSection::getSize() const { return Target->PltHeaderSize + Entries.size() * Target->PltEntrySize; } +template +GdbIndexSection::GdbIndexSection() + : SyntheticSection(0, SHT_PROGBITS, 1, ".gdb_index") {} + +template void GdbIndexSection::parseDebugSections() { + std::vector *> &IS = + static_cast *>(Out::DebugInfo)->Sections; + + for (InputSection *I : IS) + readDwarf(I); +} + +template +void GdbIndexSection::readDwarf(InputSection *I) { + std::vector> CuList = readCuList(I); + CompilationUnits.insert(CompilationUnits.end(), CuList.begin(), CuList.end()); +} + +template void GdbIndexSection::finalize() { + parseDebugSections(); + + // GdbIndex header consist from version fields + // and 5 more fields with different kinds of offsets. + CuTypesOffset = CuListOffset + CompilationUnits.size() * CompilationUnitSize; +} + +template 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, CuTypesOffset); // Symbol table offset + write32le(Buf + 20, CuTypesOffset); // Constant pool offset + Buf += 24; + + // Write the CU list. + for (std::pair CU : CompilationUnits) { + write64le(Buf, CU.first); + write64le(Buf + 8, CU.second); + Buf += 16; + } +} + template InputSection *elf::createCommonSection(); template InputSection *elf::createCommonSection(); template InputSection *elf::createCommonSection(); @@ -1469,3 +1512,8 @@ template class elf::PltSection; template class elf::PltSection; template class elf::PltSection; template class elf::PltSection; + +template class elf::GdbIndexSection; +template class elf::GdbIndexSection; +template class elf::GdbIndexSection; +template class elf::GdbIndexSection; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index e441f99..106e84e 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -10,6 +10,7 @@ #ifndef LLD_ELF_SYNTHETIC_SECTION_H #define LLD_ELF_SYNTHETIC_SECTION_H +#include "GdbIndex.h" #include "InputSection.h" #include "llvm/ADT/SmallPtrSet.h" @@ -502,6 +503,32 @@ private: std::vector> Entries; }; +template +class GdbIndexSection final : public SyntheticSection { + typedef typename ELFT::uint uintX_t; + + const unsigned OffsetTypeSize = 4; + const unsigned CuListOffset = 6 * OffsetTypeSize; + const unsigned CompilationUnitSize = 16; + const unsigned AddressEntrySize = 16 + OffsetTypeSize; + const unsigned SymTabEntrySize = 2 * OffsetTypeSize; + +public: + GdbIndexSection(); + void finalize() override; + void writeTo(uint8_t *Buf) override; + size_t getSize() const override { return CuTypesOffset; } + + // Pairs of [CU Offset, CU length]. + std::vector> CompilationUnits; + +private: + void parseDebugSections(); + void readDwarf(InputSection *I); + + uint32_t CuTypesOffset; +}; + template InputSection *createCommonSection(); template InputSection *createInterpSection(); template MergeInputSection *createCommentSection(); @@ -514,6 +541,7 @@ template struct In { static StringTableSection *DynStrTab; static SymbolTableSection *DynSymTab; static GnuHashTableSection *GnuHashTab; + static GdbIndexSection *GdbIndex; static GotSection *Got; static MipsGotSection *MipsGot; static GotPltSection *GotPlt; @@ -535,6 +563,7 @@ template InputSection *In::Common; template DynamicSection *In::Dynamic; template StringTableSection *In::DynStrTab; template SymbolTableSection *In::DynSymTab; +template GdbIndexSection *In::GdbIndex; template GnuHashTableSection *In::GnuHashTab; template GotSection *In::Got; template MipsGotSection *In::MipsGot; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 213ecf6..64c80b9 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -268,7 +268,7 @@ template void Writer::createSyntheticSections() { if (Config->SysvHash) In::HashTab = make>(); if (Config->GdbIndex) - Out::GdbIndex = make>(); + In::GdbIndex = make>(); In::RelaPlt = make>( Config->Rela ? ".rela.plt" : ".rel.plt", false /*Sort*/); @@ -979,8 +979,9 @@ template void Writer::finalizeSections() { finalizeSynthetic( {In::DynSymTab, In::GnuHashTab, In::HashTab, In::SymTab, In::ShStrTab, In::StrTab, - In::DynStrTab, In::Got, In::MipsGot, In::GotPlt, - In::RelaDyn, In::RelaPlt, In::Plt, In::Dynamic}); + In::DynStrTab, In::GdbIndex, In::Got, + In::MipsGot, In::GotPlt, In::RelaDyn, + In::RelaPlt, In::Plt, In::Dynamic}); } template bool Writer::needsGot() { @@ -1006,8 +1007,8 @@ template void Writer::addPredefinedSections() { // This order is not the same as the final output order // because we sort the sections using their attributes below. - if (Out::GdbIndex && Out::DebugInfo) - Add(Out::GdbIndex); + if (In::GdbIndex && Out::DebugInfo) + addInputSec(In::GdbIndex); addInputSec(In::SymTab); addInputSec(In::ShStrTab); addInputSec(In::StrTab); -- 2.7.4