[lld] r296309 - Move SymbolTable<ELFT>::Sections out of the class.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 26 18:32:09 PST 2017
Author: ruiu
Date: Sun Feb 26 20:32:08 2017
New Revision: 296309
URL: http://llvm.org/viewvc/llvm-project?rev=296309&view=rev
Log:
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.
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/ICF.cpp
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/MarkLive.cpp
lld/trunk/ELF/SymbolTable.h
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/ELF/Target.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=296309&r1=296308&r2=296309&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sun Feb 26 20:32:08 2017
@@ -69,6 +69,7 @@ bool elf::link(ArrayRef<const char *> Ar
ErrorCount = 0;
ErrorOS = &Error;
Argv0 = Args[0];
+ InputSections.clear();
Tar = nullptr;
Config = make<Configuration>();
@@ -856,10 +857,10 @@ template <class ELFT> void LinkerDriver:
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:
// 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>();
Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=296309&r1=296308&r2=296309&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Sun Feb 26 20:32:08 2017
@@ -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 ge
}
// 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::functi
// 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.
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=296309&r1=296308&r2=296309&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Sun Feb 26 20:32:08 2017
@@ -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.
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=296309&r1=296308&r2=296309&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Sun Feb 26 20:32:08 2017
@@ -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 *);
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=296309&r1=296308&r2=296309&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Sun Feb 26 20:32:08 2017
@@ -252,7 +252,7 @@ void LinkerScript<ELFT>::computeInputSec
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
// 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));
}
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=296309&r1=296308&r2=296309&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Sun Feb 26 20:32:08 2017
@@ -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.
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=296309&r1=296308&r2=296309&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Sun Feb 26 20:32:08 2017
@@ -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);
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=296309&r1=296308&r2=296309&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Sun Feb 26 20:32:08 2017
@@ -130,7 +130,7 @@ MipsAbiFlagsSection<ELFT> *MipsAbiFlagsS
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> *MipsOptionsSec
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> *MipsReginfoSec
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);
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=296309&r1=296308&r2=296309&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Sun Feb 26 20:32:08 2017
@@ -60,7 +60,7 @@ static void or32le(uint8_t *P, int32_t 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;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=296309&r1=296308&r2=296309&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sun Feb 26 20:32:08 2017
@@ -164,7 +164,7 @@ template <class ELFT> static void combin
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 combin
(*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>:
// 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<
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::fu
}
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 removeUnusedSyntheticSection
// 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;
More information about the llvm-commits
mailing list