summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-10-06 23:06:55 +0000
committerRui Ueyama <ruiu@google.com>2017-10-06 23:06:55 +0000
commitd2f225fdef3120443b8f92382de5bacfc2985ba7 (patch)
tree93b359c30e99200e5af68aee6d63b748c90d8cfc
parentedafba200f8da2b67a41bfec3d104a2e02bec0e0 (diff)
downloadbcm5719-llvm-d2f225fdef3120443b8f92382de5bacfc2985ba7.tar.gz
bcm5719-llvm-d2f225fdef3120443b8f92382de5bacfc2985ba7.zip
Simplify LinkerScript::addOrphanSections. NFCI.
This patch moves a std::find to a new function. It also removes the following piece of code. I believe it should be fine because all tests still pass. unsigned Index = std::distance(Opt.Commands.begin(), I); assert(Sec->SectionIndex == INT_MAX || Sec->SectionIndex == Index); Sec->SectionIndex = Index; llvm-svn: 315125
-rw-r--r--lld/ELF/LinkerScript.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 6cfbc5d4585..85c170b142f 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -443,29 +443,32 @@ void LinkerScript::fabricateDefaultCommands() {
make<SymbolAssignment>(".", Expr, ""));
}
+static OutputSection *findByName(ArrayRef<BaseCommand *> Vec,
+ StringRef Name) {
+ for (BaseCommand *Base : Vec)
+ if (auto *Sec = dyn_cast<OutputSection>(Base))
+ if (Sec->Name == Name)
+ return Sec;
+ return nullptr;
+}
+
// Add sections that didn't match any sections command.
void LinkerScript::addOrphanSections(OutputSectionFactory &Factory) {
- unsigned NumCommands = Opt.Commands.size();
+ unsigned End = Opt.Commands.size();
+
for (InputSectionBase *S : InputSections) {
if (!S->Live || S->Parent)
continue;
+
StringRef Name = getOutputSectionName(S->Name);
- auto End = Opt.Commands.begin() + NumCommands;
- auto I = std::find_if(Opt.Commands.begin(), End, [&](BaseCommand *Base) {
- if (auto *Sec = dyn_cast<OutputSection>(Base))
- return Sec->Name == Name;
- return false;
- });
log(toString(S) + " is being placed in '" + Name + "'");
- if (I == End) {
+
+ if (OutputSection *Sec = findByName(
+ makeArrayRef(Opt.Commands).slice(0, End), Name)) {
+ Factory.addInputSec(S, Name, Sec);
+ } else {
Factory.addInputSec(S, Name, nullptr);
assert(S->getOutputSection()->SectionIndex == INT_MAX);
- } else {
- OutputSection *Sec = cast<OutputSection>(*I);
- Factory.addInputSec(S, Name, Sec);
- unsigned Index = std::distance(Opt.Commands.begin(), I);
- assert(Sec->SectionIndex == INT_MAX || Sec->SectionIndex == Index);
- Sec->SectionIndex = Index;
}
}
}
OpenPOWER on IntegriCloud