diff options
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index a29776badf3..ef5733d1604 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -242,6 +242,12 @@ LinkerScript<ELFT>::createInputSectionList(OutputSectionCommand &Cmd) { template <class ELFT> void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) { for (const std::unique_ptr<BaseCommand> &Base1 : Opt.Commands) { + if (auto *Cmd = dyn_cast<SymbolAssignment>(Base1.get())) { + if (shouldDefine<ELFT>(Cmd)) + addRegular<ELFT>(Cmd); + continue; + } + if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base1.get())) { if (Cmd->Name == "/DISCARD/") { discard(*Cmd); @@ -260,9 +266,6 @@ void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) { OutputSections->push_back(OutSec); for (InputSectionBase<ELFT> *Sec : V) OutSec->addSection(Sec); - } else if (auto *Cmd2 = dyn_cast<SymbolAssignment>(Base1.get())) { - if (shouldDefine<ELFT>(Cmd2)) - addRegular<ELFT>(Cmd2); } } @@ -270,14 +273,14 @@ void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) { for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab<ELFT>::X->getObjectFiles()) { for (InputSectionBase<ELFT> *S : F->getSections()) { - if (!isDiscarded(S) && !S->OutSec) { - OutputSectionBase<ELFT> *OutSec; - bool IsNew; - std::tie(OutSec, IsNew) = Factory.create(S, getOutputSectionName(S)); - if (IsNew) - OutputSections->push_back(OutSec); - OutSec->addSection(S); - } + if (isDiscarded(S) || S->OutSec) + continue; + OutputSectionBase<ELFT> *OutSec; + bool IsNew; + std::tie(OutSec, IsNew) = Factory.create(S, getOutputSectionName(S)); + if (IsNew) + OutputSections->push_back(OutSec); + OutSec->addSection(S); } } |