diff options
| author | Rui Ueyama <ruiu@google.com> | 2017-02-27 02:32:08 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2017-02-27 02:32:08 +0000 |
| commit | 536a26706fb31adbfda4f20a9582f76009168cb2 (patch) | |
| tree | ec4e2c7deb0bb973dd92c1ecbd9fdc38d634c862 | |
| parent | 02a036f2e6706c09ac7b43a1d2027c64c0dd9d6d (diff) | |
| download | bcm5719-llvm-536a26706fb31adbfda4f20a9582f76009168cb2.tar.gz bcm5719-llvm-536a26706fb31adbfda4f20a9582f76009168cb2.zip | |
Move SymbolTable<ELFT>::Sections out of the class.
The list of all input sections was defined in SymbolTable class for a
historical reason. The list itself is not a template. However, because
SymbolTable class is a template, we needed to pass around ELFT to access
the list. This patch moves the list out of the class so that it doesn't
need ELFT.
llvm-svn: 296309
| -rw-r--r-- | lld/ELF/Driver.cpp | 22 | ||||
| -rw-r--r-- | lld/ELF/ICF.cpp | 7 | ||||
| -rw-r--r-- | lld/ELF/InputSection.cpp | 2 | ||||
| -rw-r--r-- | lld/ELF/InputSection.h | 3 | ||||
| -rw-r--r-- | lld/ELF/LinkerScript.cpp | 4 | ||||
| -rw-r--r-- | lld/ELF/MarkLive.cpp | 2 | ||||
| -rw-r--r-- | lld/ELF/SymbolTable.h | 2 | ||||
| -rw-r--r-- | lld/ELF/SyntheticSections.cpp | 8 | ||||
| -rw-r--r-- | lld/ELF/Target.cpp | 2 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 14 |
10 files changed, 33 insertions, 33 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 821d14a13d0..72bb10984ef 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -69,6 +69,7 @@ bool elf::link(ArrayRef<const char *> Args, bool CanExitEarly, ErrorCount = 0; ErrorOS = &Error; Argv0 = Args[0]; + InputSections.clear(); Tar = nullptr; Config = make<Configuration>(); @@ -856,10 +857,10 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { for (elf::ObjectFile<ELFT> *F : Symtab.getObjectFiles()) for (InputSectionBase *S : F->getSections()) if (S && S != &InputSection::Discarded) - Symtab.Sections.push_back(S); + InputSections.push_back(S); for (BinaryFile *F : Symtab.getBinaryFiles()) for (InputSectionBase *S : F->getSections()) - Symtab.Sections.push_back(cast<InputSection>(S)); + InputSections.push_back(cast<InputSection>(S)); // Do size optimizations: garbage collection and identical code folding. if (Config->GcSections) @@ -869,15 +870,14 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { // MergeInputSection::splitIntoPieces needs to be called before // any call of MergeInputSection::getOffset. Do that. - forEach(Symtab.Sections.begin(), Symtab.Sections.end(), - [](InputSectionBase *S) { - if (!S->Live) - return; - if (Decompressor::isCompressedELFSection(S->Flags, S->Name)) - S->uncompress<ELFT>(); - if (auto *MS = dyn_cast<MergeInputSection<ELFT>>(S)) - MS->splitIntoPieces(); - }); + forEach(InputSections.begin(), InputSections.end(), [](InputSectionBase *S) { + if (!S->Live) + return; + if (Decompressor::isCompressedELFSection(S->Flags, S->Name)) + S->uncompress<ELFT>(); + if (auto *MS = dyn_cast<MergeInputSection<ELFT>>(S)) + MS->splitIntoPieces(); + }); // Write the result to the file. writeResult<ELFT>(); diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index db802fd5868..f88fdca22a6 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -77,7 +77,6 @@ #include "Config.h" #include "SymbolTable.h" #include "Threads.h" - #include "llvm/ADT/Hashing.h" #include "llvm/Object/ELF.h" #include "llvm/Support/ELF.h" @@ -159,7 +158,7 @@ template <class ELFT> static uint32_t getHash(InputSection *S) { } // Returns true if section S is subject of ICF. -template <class ELFT> static bool isEligible(InputSection *S) { +static bool isEligible(InputSection *S) { // .init and .fini contains instructions that must be executed to // initialize and finalize the process. They cannot and should not // be merged. @@ -336,9 +335,9 @@ void ICF<ELFT>::forEachClass(std::function<void(size_t, size_t)> Fn) { // The main function of ICF. template <class ELFT> void ICF<ELFT>::run() { // Collect sections to merge. - for (InputSectionBase *Sec : Symtab<ELFT>::X->Sections) + for (InputSectionBase *Sec : InputSections) if (auto *S = dyn_cast<InputSection>(Sec)) - if (isEligible<ELFT>(S)) + if (isEligible(S)) Sections.push_back(S); // Initially, we use hash values to partition sections. diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 54dc97bea81..064f12fbf51 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -33,6 +33,8 @@ using namespace llvm::support::endian; using namespace lld; using namespace lld::elf; +std::vector<InputSectionBase *> elf::InputSections; + // Returns a string to construct an error message. std::string lld::toString(const InputSectionBase *Sec) { // File can be absent if section is synthetic. diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 39f799a3761..98a3d9d4cb0 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -288,6 +288,9 @@ private: void copyRelocations(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels); }; +// The list of all input sections. +extern std::vector<InputSectionBase *> InputSections; + } // namespace elf std::string toString(const elf::InputSectionBase *); diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index bb104090eb1..3b045f08555 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -252,7 +252,7 @@ void LinkerScript<ELFT>::computeInputSections(InputSectionDescription *I) { for (SectionPattern &Pat : I->SectionPatterns) { size_t SizeBefore = I->Sections.size(); - for (InputSectionBase *S : Symtab<ELFT>::X->Sections) { + for (InputSectionBase *S : InputSections) { if (S->Assigned) continue; // For -emit-relocs we have to ignore entries like @@ -391,7 +391,7 @@ void LinkerScript<ELFT>::processCommands(OutputSectionFactory &Factory) { // Add sections that didn't match any sections command. template <class ELFT> void LinkerScript<ELFT>::addOrphanSections(OutputSectionFactory &Factory) { - for (InputSectionBase *S : Symtab<ELFT>::X->Sections) + for (InputSectionBase *S : InputSections) if (S->Live && !S->OutSec) Factory.addInputSec<ELFT>(S, getOutputSectionName(S->Name)); } diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index e2a62603d6c..c9d3c29599e 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -236,7 +236,7 @@ template <class ELFT> void elf::markLive() { // Preserve special sections and those which are specified in linker // script KEEP command. - for (InputSectionBase *Sec : Symtab<ELFT>::X->Sections) { + for (InputSectionBase *Sec : InputSections) { // .eh_frame is always marked as live now, but also it can reference to // sections that contain personality. We preserve all non-text sections // referred by .eh_frame here. diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h index c35f479a55d..e2db444f3f1 100644 --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -91,8 +91,6 @@ public: void trace(StringRef Name); void wrap(StringRef Name); - std::vector<InputSectionBase *> Sections; - private: std::vector<SymbolBody *> findByVersion(SymbolVersion Ver); std::vector<SymbolBody *> findAllByVersion(SymbolVersion Ver); diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 4275748ac00..48c9f7dafb7 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -130,7 +130,7 @@ MipsAbiFlagsSection<ELFT> *MipsAbiFlagsSection<ELFT>::create() { Elf_Mips_ABIFlags Flags = {}; bool Create = false; - for (InputSectionBase *Sec : Symtab<ELFT>::X->Sections) { + for (InputSectionBase *Sec : InputSections) { if (!Sec->Live || Sec->Type != SHT_MIPS_ABIFLAGS) continue; Sec->Live = false; @@ -197,7 +197,7 @@ MipsOptionsSection<ELFT> *MipsOptionsSection<ELFT>::create() { Elf_Mips_RegInfo Reginfo = {}; bool Create = false; - for (InputSectionBase *Sec : Symtab<ELFT>::X->Sections) { + for (InputSectionBase *Sec : InputSections) { if (!Sec->Live || Sec->Type != SHT_MIPS_OPTIONS) continue; Sec->Live = false; @@ -253,7 +253,7 @@ MipsReginfoSection<ELFT> *MipsReginfoSection<ELFT>::create() { Elf_Mips_RegInfo Reginfo = {}; bool Create = false; - for (InputSectionBase *Sec : Symtab<ELFT>::X->Sections) { + for (InputSectionBase *Sec : InputSections) { if (!Sec->Live || Sec->Type != SHT_MIPS_REGINFO) continue; Sec->Live = false; @@ -1718,7 +1718,7 @@ GdbIndexSection<ELFT>::GdbIndexSection() StringPool(llvm::StringTableBuilder::ELF) {} template <class ELFT> void GdbIndexSection<ELFT>::parseDebugSections() { - for (InputSectionBase *S : Symtab<ELFT>::X->Sections) + for (InputSectionBase *S : InputSections) if (InputSection *IS = dyn_cast<InputSection>(S)) if (IS->OutSec && IS->Name == ".debug_info") readDwarf(IS); diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 046b6a23d48..54768711b65 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -60,7 +60,7 @@ static void or32le(uint8_t *P, int32_t V) { write32le(P, read32le(P) | V); } static void or32be(uint8_t *P, int32_t V) { write32be(P, read32be(P) | V); } template <class ELFT> static std::string getErrorLoc(uint8_t *Loc) { - for (InputSectionBase *D : Symtab<ELFT>::X->Sections) { + for (InputSectionBase *D : InputSections) { auto *IS = dyn_cast_or_null<InputSection>(D); if (!IS || !IS->OutSec) continue; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 4d7755714a8..ce36ddee478 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -164,7 +164,7 @@ template <class ELFT> static void combineMergableSections() { typedef typename ELFT::uint uintX_t; std::vector<MergeSyntheticSection<ELFT> *> MergeSections; - for (InputSectionBase *&S : Symtab<ELFT>::X->Sections) { + for (InputSectionBase *&S : InputSections) { MergeInputSection<ELFT> *MS = dyn_cast<MergeInputSection<ELFT>>(S); if (!MS) continue; @@ -195,7 +195,7 @@ template <class ELFT> static void combineMergableSections() { (*I)->addSection(MS); } - std::vector<InputSectionBase *> &V = Symtab<ELFT>::X->Sections; + std::vector<InputSectionBase *> &V = InputSections; V.erase(std::remove(V.begin(), V.end(), nullptr), V.end()); } @@ -307,9 +307,7 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() { // you can call lld::elf::main more than once as a library. memset(&Out::First, 0, sizeof(Out)); - auto Add = [](InputSectionBase *Sec) { - Symtab<ELFT>::X->Sections.push_back(Sec); - }; + auto Add = [](InputSectionBase *Sec) { InputSections.push_back(Sec); }; // Create singleton output sections. Out::Bss = make<OutputSection>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); @@ -902,7 +900,7 @@ static void sortBySymbolsOrder(ArrayRef<OutputSection *> OutputSections) { template <class ELFT> void Writer<ELFT>::forEachRelSec(std::function<void(InputSectionBase &)> Fn) { - for (InputSectionBase *IS : Symtab<ELFT>::X->Sections) { + for (InputSectionBase *IS : InputSections) { if (!IS->Live) continue; // Scan all relocations. Each relocation goes through a series @@ -918,7 +916,7 @@ void Writer<ELFT>::forEachRelSec(std::function<void(InputSectionBase &)> Fn) { } template <class ELFT> void Writer<ELFT>::createSections() { - for (InputSectionBase *IS : Symtab<ELFT>::X->Sections) + for (InputSectionBase *IS : InputSections) if (IS) Factory.addInputSec<ELFT>(IS, getOutputSectionName(IS->Name)); @@ -1043,7 +1041,7 @@ static void removeUnusedSyntheticSections(std::vector<OutputSection *> &V) { // All input synthetic sections that can be empty are placed after // all regular ones. We iterate over them all and exit at first // non-synthetic. - for (InputSectionBase *S : llvm::reverse(Symtab<ELFT>::X->Sections)) { + for (InputSectionBase *S : llvm::reverse(InputSections)) { SyntheticSection<ELFT> *SS = dyn_cast<SyntheticSection<ELFT>>(S); if (!SS) return; |

