[PATCH] D38393: [ELF] - Stop removing sections in removeUnusedSyntheticSections().

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 2 02:12:58 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL314654: [ELF] - Stop removing sections in removeUnusedSyntheticSections(). (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D38393?vs=117103&id=117309#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38393

Files:
  lld/trunk/ELF/LinkerScript.cpp
  lld/trunk/ELF/Writer.cpp


Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -1054,8 +1054,7 @@
 }
 
 template <class ELFT> void Writer<ELFT>::sortSections() {
-  if (Script->Opt.HasSections)
-    Script->adjustSectionsBeforeSorting();
+  Script->adjustSectionsBeforeSorting();
 
   // Don't sort if using -r. It is not necessary and we want to preserve the
   // relative order for SHF_LINK_ORDER sections.
@@ -1197,8 +1196,7 @@
     // If there are no other sections in the output section, remove it from the
     // output.
     if (OS->Commands.empty())
-      llvm::erase_if(Script->Opt.Commands,
-                     [&](BaseCommand *Cmd) { return Cmd == OS; });
+      OS->Live = false;
   }
 }
 
@@ -1304,6 +1302,7 @@
   removeUnusedSyntheticSections();
 
   sortSections();
+  Script->removeEmptyCommands();
 
   // Now that we have the final list, create a list of all the
   // OutputSections for convenience.
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -677,6 +677,8 @@
   // Try and find an appropriate memory region to assign offsets in.
   for (BaseCommand *Base : Opt.Commands) {
     if (auto *Sec = dyn_cast<OutputSection>(Base)) {
+      if (!Sec->Live)
+        continue;
       Sec->MemRegion = findMemoryRegion(Sec);
       // Handle align (e.g. ".foo : ALIGN(16) { ... }").
       if (Sec->AlignExpr)
@@ -713,8 +715,6 @@
       DefPhdrs = Sec->Phdrs;
     }
   }
-
-  removeEmptyCommands();
 }
 
 static OutputSection *findFirstSection(PhdrEntry *Load) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38393.117309.patch
Type: text/x-patch
Size: 1698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171002/a4063b13/attachment.bin>


More information about the llvm-commits mailing list