From: Rui Ueyama Date: Thu, 11 Aug 2016 23:22:52 +0000 (+0000) Subject: Replace a variadic forwarding template function with less complex ones. X-Git-Tag: llvmorg-4.0.0-rc1~12665 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1602421c852d9d7fddbe8c5f014d7861a7848865;p=platform%2Fupstream%2Fllvm.git Replace a variadic forwarding template function with less complex ones. llvm-svn: 278439 --- diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index f47bba5..8ec3977 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -44,33 +44,29 @@ using namespace lld::elf; ScriptConfiguration *elf::ScriptConfig; template -static Symbol *addSymbolToSymtabAux(StringRef Name, uint8_t StOther) { - return Symtab::X->addRegular(Name, STB_GLOBAL, StOther); +static void addRegular(SymbolAssignment *Cmd) { + Symbol *Sym = Symtab::X->addRegular(Cmd->Name, STB_GLOBAL, STV_DEFAULT); + Sym->Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT; + Cmd->Sym = Sym->body(); } template -static Symbol *addSymbolToSymtabAux(StringRef Name, typename ELFT::uint Value, - OutputSectionBase *Section) { - return Symtab::X->addSynthetic(Name, Section, Value); +static void addSynthetic(SymbolAssignment *Cmd, + OutputSectionBase *Section) { + Symbol *Sym = Symtab::X->addSynthetic(Cmd->Name, Section, 0); + Sym->Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT; + Cmd->Sym = Sym->body(); } -template -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 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::X->find(Cmd.Name); - if (Cmd.Provide && !(B && B->isUndefined())) - return false; - - Symbol *Sym = - addSymbolToSymtabAux(Cmd.Name, std::forward(Args)...); - - Sym->Visibility = Cmd.Hidden ? STV_HIDDEN : STV_DEFAULT; - Cmd.Sym = Sym->body(); - return true; + if (!Cmd->Provide) + return true; + SymbolBody *B = Symtab::X->find(Cmd->Name); + return B && B->isUndefined(); } bool SymbolAssignment::classof(const BaseCommand *C) { @@ -218,14 +214,19 @@ void OutputSectionBuilder::addSection(StringRef OutputName, } template void OutputSectionBuilder::flushSymbols() { - for (std::unique_ptr> &I : PendingSymbols) - if (I->Cmd->Name == "." || addSymbolToSymtab(*I->Cmd, 0, Current)) { - // Only regular output sections are supported. - if (dyn_cast_or_null>(Current)) { + // Only regular output sections are supported. + if (dyn_cast_or_null>(Current)) { + for (std::unique_ptr> &I : PendingSymbols) { + if (I->Cmd->Name == ".") { + Current->addSection(I.get()); + OwningSections.push_back(std::move(I)); + } else if (shouldDefine(I->Cmd)) { + addSynthetic(I->Cmd, Current); Current->addSection(I.get()); OwningSections.push_back(std::move(I)); } } + } PendingSymbols.clear(); } @@ -301,7 +302,8 @@ void LinkerScript::createSections( Builder.flushSection(); } else if (auto *Cmd2 = dyn_cast(Base1.get())) { - addSymbolToSymtab(*Cmd2, STV_DEFAULT); + if (shouldDefine(Cmd2)) + addRegular(Cmd2); } // Add all other input sections, which are not listed in script.