[lld] r299508 - Simplify and update comment.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 4 20:52:29 PDT 2017


Author: ruiu
Date: Tue Apr  4 22:52:28 2017
New Revision: 299508

URL: http://llvm.org/viewvc/llvm-project?rev=299508&view=rev
Log:
Simplify and update comment.

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=299508&r1=299507&r2=299508&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Apr  4 22:52:28 2017
@@ -658,17 +658,19 @@ void LinkerScript::assignOffsets(OutputS
     Dot = CurMemRegion->Offset;
   switchTo(Sec);
 
-  // Find the last section output location. We will output orphan sections
-  // there so that end symbols point to the correct location.
-  auto E =
+  // flush() may add orphan sections, so the order of flush() and
+  // symbol assignments is important. We want to call flush() first so
+  // that symbols pointing the end of the current section points to
+  // the location after orphan sections.
+  auto Mid =
       std::find_if(Cmd->Commands.rbegin(), Cmd->Commands.rend(),
                    [](BaseCommand *Cmd) { return !isa<SymbolAssignment>(Cmd); })
           .base();
-  for (auto I = Cmd->Commands.begin(); I != E; ++I)
+  for (auto I = Cmd->Commands.begin(); I != Mid; ++I)
     process(**I);
   flush();
-  std::for_each(E, Cmd->Commands.end(),
-                [this](BaseCommand *B) { process(*B); });
+  for (auto I = Mid, E = Cmd->Commands.end(); I != E; ++I)
+    process(**I);
 }
 
 void LinkerScript::removeEmptyCommands() {
@@ -765,13 +767,12 @@ void LinkerScript::adjustSectionsAfterSo
 //  /* The RW PT_LOAD starts here*/
 //  rw_sec : { *(rw_sec) }
 // would mean that the RW PT_LOAD would become unaligned.
-static bool shouldSkip(const BaseCommand &Cmd) {
+static bool shouldSkip(BaseCommand *Cmd) {
   if (isa<OutputSectionCommand>(Cmd))
     return false;
-  const auto *Assign = dyn_cast<SymbolAssignment>(&Cmd);
-  if (!Assign)
-    return true;
-  return Assign->Name != ".";
+  if (auto *Assign = dyn_cast<SymbolAssignment>(Cmd))
+    return Assign->Name != ".";
+  return true;
 }
 
 // Orphan sections are sections present in the input files which are
@@ -806,14 +807,9 @@ void LinkerScript::placeOrphanSections()
   // section. We do this because it is common to set a load address by starting
   // the script with ". = 0xabcd" and the expectation is that every section is
   // after that.
-  auto FirstSectionOrDotAssignment = std::find_if(
-      Opt.Commands.begin(), Opt.Commands.end(), [](BaseCommand *Cmd) {
-        if (isa<OutputSectionCommand>(Cmd))
-          return true;
-        if (auto *Assign = dyn_cast<SymbolAssignment>(Cmd))
-          return Assign->Name == ".";
-        return false;
-      });
+  auto FirstSectionOrDotAssignment =
+      std::find_if(Opt.Commands.begin(), Opt.Commands.end(),
+                   [](BaseCommand *Cmd) { return !shouldSkip(Cmd); });
   if (FirstSectionOrDotAssignment != Opt.Commands.end()) {
     CmdIndex = FirstSectionOrDotAssignment - Opt.Commands.begin();
     if (isa<SymbolAssignment>(**FirstSectionOrDotAssignment))
@@ -827,7 +823,7 @@ void LinkerScript::placeOrphanSections()
     // correct result.
     auto CmdIter = Opt.Commands.begin() + CmdIndex;
     auto E = Opt.Commands.end();
-    while (CmdIter != E && shouldSkip(**CmdIter)) {
+    while (CmdIter != E && shouldSkip(*CmdIter)) {
       ++CmdIter;
       ++CmdIndex;
     }




More information about the llvm-commits mailing list