[lld] r278091 - Do not pass the SymbolTable to writeResult.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 8 20:38:23 PDT 2016
Author: ruiu
Date: Mon Aug 8 22:38:23 2016
New Revision: 278091
URL: http://llvm.org/viewvc/llvm-project?rev=278091&view=rev
Log:
Do not pass the SymbolTable to writeResult.
The SymbolTable is always accessible as Symtab<ELFT>::X,
so no need to pass it as an argument.
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Writer.cpp
lld/trunk/ELF/Writer.h
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=278091&r1=278090&r2=278091&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Mon Aug 8 22:38:23 2016
@@ -588,5 +588,5 @@ template <class ELFT> void LinkerDriver:
MS->splitIntoPieces();
}
- writeResult<ELFT>(&Symtab);
+ writeResult<ELFT>();
}
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=278091&r1=278090&r2=278091&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Aug 8 22:38:23 2016
@@ -40,7 +40,6 @@ public:
typedef typename ELFT::Sym Elf_Sym;
typedef typename ELFT::SymRange Elf_Sym_Range;
typedef typename ELFT::Rela Elf_Rela;
- Writer(SymbolTable<ELFT> &S) : Symtab(S) {}
void run();
private:
@@ -79,7 +78,6 @@ private:
void addStartStopSymbols(OutputSectionBase<ELFT> *Sec);
OutputSectionBase<ELFT> *findSection(StringRef Name);
- SymbolTable<ELFT> &Symtab;
std::vector<Phdr> Phdrs;
uintX_t FileSize;
@@ -110,7 +108,7 @@ template <class ELFT> static bool needsI
!Config->DynamicLinker.empty();
}
-template <class ELFT> void elf::writeResult(SymbolTable<ELFT> *Symtab) {
+template <class ELFT> void elf::writeResult() {
typedef typename ELFT::uint uintX_t;
typedef typename ELFT::Ehdr Elf_Ehdr;
@@ -213,7 +211,7 @@ template <class ELFT> void elf::writeRes
Out<ELFT>::ElfHeader = &ElfHeader;
Out<ELFT>::ProgramHeaders = &ProgramHeaders;
- Writer<ELFT>(*Symtab).run();
+ Writer<ELFT>().run();
}
template <class ELFT>
@@ -273,8 +271,7 @@ template <class ELFT> void Writer<ELFT>:
error(EC, "failed to write to the output file");
}
-template <class ELFT>
-static void reportUndefined(SymbolTable<ELFT> &Symtab, SymbolBody *Sym) {
+template <class ELFT> static void reportUndefined(SymbolBody *Sym) {
if (Config->UnresolvedSymbols == UnresolvedPolicy::Ignore)
return;
@@ -346,7 +343,7 @@ template <class ELFT> void Writer<ELFT>:
if (!Out<ELFT>::SymTab)
return;
for (const std::unique_ptr<elf::ObjectFile<ELFT>> &F :
- Symtab.getObjectFiles()) {
+ Symtab<ELFT>::X->getObjectFiles()) {
const char *StrTab = F->getStringTable().data();
for (SymbolBody *B : F->getLocalSymbols()) {
auto *DR = dyn_cast<DefinedRegular<ELFT>>(B);
@@ -504,15 +501,15 @@ void PhdrEntry<ELFT>::add(OutputSectionB
}
template <class ELFT>
-static Symbol *addOptionalSynthetic(SymbolTable<ELFT> &Table, StringRef Name,
+static Symbol *addOptionalSynthetic(StringRef Name,
OutputSectionBase<ELFT> *Sec,
typename ELFT::uint Val) {
- SymbolBody *S = Table.find(Name);
+ SymbolBody *S = Symtab<ELFT>::X->find(Name);
if (!S)
return nullptr;
if (!S->isUndefined() && !S->isShared())
return S->symbol();
- return Table.addSynthetic(Name, Sec, Val);
+ return Symtab<ELFT>::X->addSynthetic(Name, Sec, Val);
}
// The beginning and the ending of .rel[a].plt section are marked
@@ -525,10 +522,10 @@ template <class ELFT> void Writer<ELFT>:
if (isOutputDynamic<ELFT>() || !Out<ELFT>::RelaPlt)
return;
StringRef S = Config->Rela ? "__rela_iplt_start" : "__rel_iplt_start";
- addOptionalSynthetic(Symtab, S, Out<ELFT>::RelaPlt, 0);
+ addOptionalSynthetic(S, Out<ELFT>::RelaPlt, 0);
S = Config->Rela ? "__rela_iplt_end" : "__rel_iplt_end";
- addOptionalSynthetic(Symtab, S, Out<ELFT>::RelaPlt,
+ addOptionalSynthetic(S, Out<ELFT>::RelaPlt,
DefinedSynthetic<ELFT>::SectionEnd);
}
@@ -540,12 +537,12 @@ template <class ELFT> void Writer<ELFT>:
// so that it points to an absolute address which is relative to GOT.
// See "Global Data Symbols" in Chapter 6 in the following document:
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
- Symtab.addSynthetic("_gp", Out<ELFT>::Got, MipsGPOffset);
+ Symtab<ELFT>::X->addSynthetic("_gp", Out<ELFT>::Got, MipsGPOffset);
// On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
// start of function and 'gp' pointer into GOT.
Symbol *Sym =
- addOptionalSynthetic(Symtab, "_gp_disp", Out<ELFT>::Got, MipsGPOffset);
+ addOptionalSynthetic("_gp_disp", Out<ELFT>::Got, MipsGPOffset);
if (Sym)
ElfSym<ELFT>::MipsGpDisp = Sym->body();
@@ -553,8 +550,7 @@ template <class ELFT> void Writer<ELFT>:
// pointer. This symbol is used in the code generated by .cpload pseudo-op
// in case of using -mno-shared option.
// https://sourceware.org/ml/binutils/2004-12/msg00094.html
- addOptionalSynthetic(Symtab, "__gnu_local_gp", Out<ELFT>::Got,
- MipsGPOffset);
+ addOptionalSynthetic("__gnu_local_gp", Out<ELFT>::Got, MipsGPOffset);
}
// In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol
@@ -570,14 +566,14 @@ template <class ELFT> void Writer<ELFT>:
// Given that the symbol is effectively unused, we just create a dummy
// hidden one to avoid the undefined symbol error.
if (!Config->Relocatable)
- Symtab.addIgnored("_GLOBAL_OFFSET_TABLE_");
+ Symtab<ELFT>::X->addIgnored("_GLOBAL_OFFSET_TABLE_");
// __tls_get_addr is defined by the dynamic linker for dynamic ELFs. For
// static linking the linker is required to optimize away any references to
// __tls_get_addr, so it's not defined anywhere. Create a hidden definition
// to avoid the undefined symbol error.
if (!isOutputDynamic<ELFT>())
- Symtab.addIgnored("__tls_get_addr");
+ Symtab<ELFT>::X->addIgnored("__tls_get_addr");
// If linker script do layout we do not need to create any standart symbols.
if (ScriptConfig->HasContents)
@@ -585,15 +581,15 @@ template <class ELFT> void Writer<ELFT>:
auto Define = [this](StringRef S, DefinedRegular<ELFT> *&Sym1,
DefinedRegular<ELFT> *&Sym2) {
- Sym1 = Symtab.addIgnored(S, STV_DEFAULT);
+ Sym1 = Symtab<ELFT>::X->addIgnored(S, STV_DEFAULT);
// The name without the underscore is not a reserved name,
// so it is defined only when there is a reference against it.
assert(S.startswith("_"));
S = S.substr(1);
- if (SymbolBody *B = Symtab.find(S))
+ if (SymbolBody *B = Symtab<ELFT>::X->find(S))
if (B->isUndefined())
- Sym2 = Symtab.addAbsolute(S, STV_DEFAULT);
+ Sym2 = Symtab<ELFT>::X->addAbsolute(S, STV_DEFAULT);
};
Define("_end", ElfSym<ELFT>::End, ElfSym<ELFT>::End2);
@@ -619,7 +615,7 @@ void Writer<ELFT>::forEachRelSec(
std::function<void(InputSectionBase<ELFT> &, const typename ELFT::Shdr &)>
Fn) {
for (const std::unique_ptr<elf::ObjectFile<ELFT>> &F :
- Symtab.getObjectFiles()) {
+ Symtab<ELFT>::X->getObjectFiles()) {
for (InputSectionBase<ELFT> *C : F->getSections()) {
if (isDiscarded(C))
continue;
@@ -644,7 +640,7 @@ void Writer<ELFT>::forEachRelSec(
template <class ELFT> void Writer<ELFT>::createSections() {
for (const std::unique_ptr<elf::ObjectFile<ELFT>> &F :
- Symtab.getObjectFiles()) {
+ Symtab<ELFT>::X->getObjectFiles()) {
for (InputSectionBase<ELFT> *C : F->getSections()) {
if (isDiscarded(C)) {
reportDiscarded(C);
@@ -686,7 +682,7 @@ template <class ELFT> void Writer<ELFT>:
// Even the author of gold doesn't remember why gold behaves that way.
// https://sourceware.org/ml/binutils/2002-03/msg00360.html
if (isOutputDynamic<ELFT>())
- Symtab.addSynthetic("_DYNAMIC", Out<ELFT>::Dynamic, 0);
+ Symtab<ELFT>::X->addSynthetic("_DYNAMIC", Out<ELFT>::Dynamic, 0);
// Define __rel[a]_iplt_{start,end} symbols if needed.
addRelIpltSymbols();
@@ -712,13 +708,13 @@ template <class ELFT> void Writer<ELFT>:
// Now that we have defined all possible symbols including linker-
// synthesized ones. Visit all symbols to give the finishing touches.
- for (Symbol *S : Symtab.getSymbols()) {
+ for (Symbol *S : Symtab<ELFT>::X->getSymbols()) {
SymbolBody *Body = S->body();
// We only report undefined symbols in regular objects. This means that we
// will accept an undefined reference in bitcode if it can be optimized out.
if (S->IsUsedInRegularObj && Body->isUndefined() && !S->isWeak())
- reportUndefined<ELFT>(Symtab, Body);
+ reportUndefined<ELFT>(Body);
if (!includeInSymtab<ELFT>(*Body))
continue;
@@ -861,13 +857,12 @@ template <class ELFT> void Writer<ELFT>:
auto Define = [&](StringRef Start, StringRef End,
OutputSectionBase<ELFT> *OS) {
if (OS) {
- this->Symtab.addSynthetic(Start, OS, 0);
- this->Symtab.addSynthetic(End, OS, DefinedSynthetic<ELFT>::SectionEnd);
+ Symtab<ELFT>::X->addSynthetic(Start, OS, 0);
+ Symtab<ELFT>::X->addSynthetic(End, OS,
+ DefinedSynthetic<ELFT>::SectionEnd);
} else {
- addOptionalSynthetic(this->Symtab, Start,
- (OutputSectionBase<ELFT> *)nullptr, 0);
- addOptionalSynthetic(this->Symtab, End,
- (OutputSectionBase<ELFT> *)nullptr, 0);
+ addOptionalSynthetic(Start, (OutputSectionBase<ELFT> *)nullptr, 0);
+ addOptionalSynthetic(End, (OutputSectionBase<ELFT> *)nullptr, 0);
}
};
@@ -892,12 +887,13 @@ void Writer<ELFT>::addStartStopSymbols(O
StringSaver Saver(Alloc);
StringRef Start = Saver.save("__start_" + S);
StringRef Stop = Saver.save("__stop_" + S);
- if (SymbolBody *B = Symtab.find(Start))
+ if (SymbolBody *B = Symtab<ELFT>::X->find(Start))
if (B->isUndefined())
- Symtab.addSynthetic(Start, Sec, 0);
- if (SymbolBody *B = Symtab.find(Stop))
+ Symtab<ELFT>::X->addSynthetic(Start, Sec, 0);
+ if (SymbolBody *B = Symtab<ELFT>::X->find(Stop))
if (B->isUndefined())
- Symtab.addSynthetic(Stop, Sec, DefinedSynthetic<ELFT>::SectionEnd);
+ Symtab<ELFT>::X->addSynthetic(Stop, Sec,
+ DefinedSynthetic<ELFT>::SectionEnd);
}
template <class ELFT>
@@ -1280,10 +1276,10 @@ template <class ELFT> void Writer<ELFT>:
Out<ELFT>::BuildId->writeBuildId(Regions);
}
-template void elf::writeResult<ELF32LE>(SymbolTable<ELF32LE> *Symtab);
-template void elf::writeResult<ELF32BE>(SymbolTable<ELF32BE> *Symtab);
-template void elf::writeResult<ELF64LE>(SymbolTable<ELF64LE> *Symtab);
-template void elf::writeResult<ELF64BE>(SymbolTable<ELF64BE> *Symtab);
+template void elf::writeResult<ELF32LE>();
+template void elf::writeResult<ELF32BE>();
+template void elf::writeResult<ELF64LE>();
+template void elf::writeResult<ELF64BE>();
template struct elf::PhdrEntry<ELF32LE>;
template struct elf::PhdrEntry<ELF32BE>;
Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=278091&r1=278090&r2=278091&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Mon Aug 8 22:38:23 2016
@@ -23,7 +23,7 @@ template <class ELFT> class OutputSectio
template <class ELFT> class InputSectionBase;
template <class ELFT> class ObjectFile;
template <class ELFT> class SymbolTable;
-template <class ELFT> void writeResult(SymbolTable<ELFT> *Symtab);
+template <class ELFT> void writeResult();
template <class ELFT> void markLive();
template <class ELFT> bool isOutputDynamic();
template <class ELFT> bool isRelroSection(OutputSectionBase<ELFT> *Sec);
More information about the llvm-commits
mailing list