[lld] r286827 - Delay removing empty section commands. NFC.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 14 06:33:50 PST 2016


Author: rafael
Date: Mon Nov 14 08:33:49 2016
New Revision: 286827

URL: http://llvm.org/viewvc/llvm-project?rev=286827&view=rev
Log:
Delay removing empty section commands. NFC.

To fix pr30997 we will have to keep them a bit longer, this just
splits that part of the diff.

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=286827&r1=286826&r2=286827&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Nov 14 08:33:49 2016
@@ -526,21 +526,19 @@ template <class ELFT> void LinkerScript<
         auto *Cmd = dyn_cast<OutputSectionCommand>(Base.get());
         if (!Cmd)
           return false;
-        std::vector<OutputSectionBase *> Secs =
-            findSections<ELFT>(Cmd->Name, *OutputSections);
-        if (!Secs.empty())
-          return false;
-        for (const std::unique_ptr<BaseCommand> &I : Cmd->Commands)
-          if (!isa<InputSectionDescription>(I.get()))
-            return false;
-        return true;
+        return findSections<ELFT>(Cmd->Name, *OutputSections).empty();
       });
   Opt.Commands.erase(Pos, Opt.Commands.end());
 }
 
-template <class ELFT> void LinkerScript<ELFT>::adjustSectionsBeforeSorting() {
-  removeEmptyCommands();
+static bool isAllSectionDescription(const OutputSectionCommand &Cmd) {
+  for (const std::unique_ptr<BaseCommand> &I : Cmd.Commands)
+    if (!isa<InputSectionDescription>(*I))
+      return false;
+  return true;
+}
 
+template <class ELFT> void LinkerScript<ELFT>::adjustSectionsBeforeSorting() {
   // If the output section contains only symbol assignments, create a
   // corresponding output section. The bfd linker seems to only create them if
   // '.' is assigned to, but creating these section should not have any bad
@@ -559,9 +557,14 @@ template <class ELFT> void LinkerScript<
       continue;
     }
 
+    if (isAllSectionDescription(*Cmd))
+      continue;
+
     auto *OutSec = make<OutputSection<ELFT>>(Cmd->Name, Type, Flags);
     OutputSections->push_back(OutSec);
   }
+
+  removeEmptyCommands();
 }
 
 // When placing orphan sections, we want to place them after symbol assignments




More information about the llvm-commits mailing list