[lld] r307178 - Merge createOrphanCommands into addOrphanSections.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 5 10:50:43 PDT 2017
Author: rafael
Date: Wed Jul 5 10:50:43 2017
New Revision: 307178
URL: http://llvm.org/viewvc/llvm-project?rev=307178&view=rev
Log:
Merge createOrphanCommands into addOrphanSections.
This is a bit simpler and avoids a walk over OutputSections.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=307178&r1=307177&r2=307178&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Jul 5 10:50:43 2017
@@ -481,19 +481,31 @@ void LinkerScript::fabricateDefaultComma
// Add sections that didn't match any sections command.
void LinkerScript::addOrphanSections(OutputSectionFactory &Factory) {
+ unsigned NumCommands = Opt.Commands.size();
for (InputSectionBase *S : InputSections) {
if (!S->Live || S->Parent)
continue;
StringRef Name = getOutputSectionName(S->Name);
- auto I = llvm::find_if(Opt.Commands, [&](BaseCommand *Base) {
+ auto End = Opt.Commands.begin() + NumCommands;
+ auto I = std::find_if(Opt.Commands.begin(), End, [&](BaseCommand *Base) {
if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
return Cmd->Name == Name;
return false;
});
- if (I == Opt.Commands.end()) {
+ OutputSectionCommand *Cmd;
+ if (I == End) {
Factory.addInputSec(S, Name);
+ OutputSection *Sec = S->getOutputSection();
+ assert(Sec->SectionIndex == INT_MAX);
+ OutputSectionCommand *&CmdRef = SecToCommand[Sec];
+ if (!CmdRef) {
+ CmdRef = createOutputSectionCommand(Sec->Name, "<internal>");
+ CmdRef->Sec = Sec;
+ Opt.Commands.push_back(CmdRef);
+ }
+ Cmd = CmdRef;
} else {
- auto *Cmd = cast<OutputSectionCommand>(*I);
+ Cmd = cast<OutputSectionCommand>(*I);
Factory.addInputSec(S, Name, Cmd->Sec);
if (OutputSection *Sec = Cmd->Sec) {
SecToCommand[Sec] = Cmd;
@@ -501,10 +513,10 @@ void LinkerScript::addOrphanSections(Out
assert(Sec->SectionIndex == INT_MAX || Sec->SectionIndex == Index);
Sec->SectionIndex = Index;
}
- auto *ISD = make<InputSectionDescription>("");
- ISD->Sections.push_back(cast<InputSection>(S));
- Cmd->Commands.push_back(ISD);
}
+ auto *ISD = make<InputSectionDescription>("");
+ ISD->Sections.push_back(cast<InputSection>(S));
+ Cmd->Commands.push_back(ISD);
}
}
@@ -759,21 +771,6 @@ void LinkerScript::adjustSectionsAfterSo
removeEmptyCommands();
}
-void LinkerScript::createOrphanCommands() {
- for (OutputSection *Sec : OutputSections) {
- if (Sec->SectionIndex != INT_MAX)
- continue;
- OutputSectionCommand *Cmd =
- createOutputSectionCommand(Sec->Name, "<internal>");
- Cmd->Sec = Sec;
- SecToCommand[Sec] = Cmd;
- auto *ISD = make<InputSectionDescription>("");
- ISD->Sections = Sec->Sections;
- Cmd->Commands.push_back(ISD);
- Opt.Commands.push_back(Cmd);
- }
-}
-
void LinkerScript::processNonSectionCommands() {
for (BaseCommand *Base : Opt.Commands) {
if (auto *Cmd = dyn_cast<SymbolAssignment>(Base))
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=307178&r1=307177&r2=307178&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Wed Jul 5 10:50:43 2017
@@ -279,7 +279,6 @@ public:
bool hasLMA(OutputSection *Sec);
bool shouldKeep(InputSectionBase *S);
void assignOffsets(OutputSectionCommand *Cmd);
- void createOrphanCommands();
void processNonSectionCommands();
void assignAddresses();
void allocateHeaders(std::vector<PhdrEntry> &Phdrs);
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=307178&r1=307177&r2=307178&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Jul 5 10:50:43 2017
@@ -181,7 +181,6 @@ template <class ELFT> void Writer<ELFT>:
// Linker scripts may have left some input sections unassigned.
// Assign such sections using the default rule.
Script->addOrphanSections(Factory);
- Script->createOrphanCommands();
} else {
// If linker script does not contain SECTIONS commands, create
// output sections by default rules. We still need to give the
More information about the llvm-commits
mailing list