[lld] r278439 - Replace a variadic forwarding template function with less complex ones.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 11 16:22:52 PDT 2016
Author: ruiu
Date: Thu Aug 11 18:22:52 2016
New Revision: 278439
URL: http://llvm.org/viewvc/llvm-project?rev=278439&view=rev
Log:
Replace a variadic forwarding template function with less complex ones.
Modified:
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=278439&r1=278438&r2=278439&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Aug 11 18:22:52 2016
@@ -44,33 +44,29 @@ using namespace lld::elf;
ScriptConfiguration *elf::ScriptConfig;
template <class ELFT>
-static Symbol *addSymbolToSymtabAux(StringRef Name, uint8_t StOther) {
- return Symtab<ELFT>::X->addRegular(Name, STB_GLOBAL, StOther);
+static void addRegular(SymbolAssignment *Cmd) {
+ Symbol *Sym = Symtab<ELFT>::X->addRegular(Cmd->Name, STB_GLOBAL, STV_DEFAULT);
+ Sym->Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
+ Cmd->Sym = Sym->body();
}
template <class ELFT>
-static Symbol *addSymbolToSymtabAux(StringRef Name, typename ELFT::uint Value,
- OutputSectionBase<ELFT> *Section) {
- return Symtab<ELFT>::X->addSynthetic(Name, Section, Value);
+static void addSynthetic(SymbolAssignment *Cmd,
+ OutputSectionBase<ELFT> *Section) {
+ Symbol *Sym = Symtab<ELFT>::X->addSynthetic(Cmd->Name, Section, 0);
+ Sym->Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
+ Cmd->Sym = Sym->body();
}
-template <class ELFT, class... ArgsT>
-static bool addSymbolToSymtab(SymbolAssignment &Cmd, ArgsT... Args) {
- if (Cmd.Name == ".")
+// If a symbol was in PROVIDE(), we need to define it only when
+// it is an undefined symbol.
+template <class ELFT> static bool shouldDefine(SymbolAssignment *Cmd) {
+ if (Cmd->Name == ".")
return false;
-
- // If a symbol was in PROVIDE(), define it only when it is an
- // undefined symbol.
- SymbolBody *B = Symtab<ELFT>::X->find(Cmd.Name);
- if (Cmd.Provide && !(B && B->isUndefined()))
- return false;
-
- Symbol *Sym =
- addSymbolToSymtabAux<ELFT>(Cmd.Name, std::forward<ArgsT>(Args)...);
-
- Sym->Visibility = Cmd.Hidden ? STV_HIDDEN : STV_DEFAULT;
- Cmd.Sym = Sym->body();
- return true;
+ if (!Cmd->Provide)
+ return true;
+ SymbolBody *B = Symtab<ELFT>::X->find(Cmd->Name);
+ return B && B->isUndefined();
}
bool SymbolAssignment::classof(const BaseCommand *C) {
@@ -218,14 +214,19 @@ void OutputSectionBuilder<ELFT>::addSect
}
template <class ELFT> void OutputSectionBuilder<ELFT>::flushSymbols() {
- for (std::unique_ptr<LayoutInputSection<ELFT>> &I : PendingSymbols)
- if (I->Cmd->Name == "." || addSymbolToSymtab<ELFT>(*I->Cmd, 0, Current)) {
- // Only regular output sections are supported.
- if (dyn_cast_or_null<OutputSection<ELFT>>(Current)) {
+ // Only regular output sections are supported.
+ if (dyn_cast_or_null<OutputSection<ELFT>>(Current)) {
+ for (std::unique_ptr<LayoutInputSection<ELFT>> &I : PendingSymbols) {
+ if (I->Cmd->Name == ".") {
+ Current->addSection(I.get());
+ OwningSections.push_back(std::move(I));
+ } else if (shouldDefine<ELFT>(I->Cmd)) {
+ addSynthetic<ELFT>(I->Cmd, Current);
Current->addSection(I.get());
OwningSections.push_back(std::move(I));
}
}
+ }
PendingSymbols.clear();
}
@@ -301,7 +302,8 @@ void LinkerScript<ELFT>::createSections(
Builder.flushSection();
} else if (auto *Cmd2 = dyn_cast<SymbolAssignment>(Base1.get())) {
- addSymbolToSymtab<ELFT>(*Cmd2, STV_DEFAULT);
+ if (shouldDefine<ELFT>(Cmd2))
+ addRegular<ELFT>(Cmd2);
}
// Add all other input sections, which are not listed in script.
More information about the llvm-commits
mailing list