[PATCH] D39047: [ELF] - Hide LinkerScript::removeEmptyCommands().

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 18 05:02:22 PDT 2017


grimar created this revision.
Herald added a subscriber: emaste.

With little code reordering it is possible to make
`removeEmptyCommands` to be private. Does not seem
it worth to allow it leak to public interface and also
simplifies code a bit.


https://reviews.llvm.org/D39047

Files:
  ELF/LinkerScript.cpp
  ELF/LinkerScript.h
  ELF/Writer.cpp


Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1294,7 +1294,6 @@
   removeUnusedSyntheticSections();
 
   sortSections();
-  Script->removeEmptyCommands();
 
   // Now that we have the final list, create a list of all the
   // OutputSections for convenience.
Index: ELF/LinkerScript.h
===================================================================
--- ELF/LinkerScript.h
+++ ELF/LinkerScript.h
@@ -217,6 +217,8 @@
   uint64_t advance(uint64_t Size, unsigned Align);
   void output(InputSection *Sec);
 
+  void removeEmptyCommands();
+
   std::unique_ptr<AddressState> Ctx;
   OutputSection *Aether;
 
@@ -234,7 +236,6 @@
 
   void fabricateDefaultCommands();
   void addOrphanSections(OutputSectionFactory &Factory);
-  void removeEmptyCommands();
   void adjustSectionsBeforeSorting();
   void adjustSectionsAfterSorting();
 
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -696,19 +696,6 @@
 }
 
 void LinkerScript::adjustSectionsAfterSorting() {
-  // Try and find an appropriate memory region to assign offsets in.
-  for (BaseCommand *Base : SectionCommands) {
-    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)
-        Sec->Alignment =
-            std::max<uint32_t>(Sec->Alignment, Sec->AlignExpr().getValue());
-    }
-  }
-
   // If output section command doesn't specify any segments,
   // and we haven't previously assigned any section to segment,
   // then we simply assign section to the very first load segment.
@@ -738,6 +725,19 @@
       DefPhdrs = Sec->Phdrs;
     }
   }
+
+  removeEmptyCommands();
+
+  // Try and find an appropriate memory region to assign offsets in.
+  for (BaseCommand *Base : SectionCommands) {
+    if (auto *Sec = dyn_cast<OutputSection>(Base)) {
+      Sec->MemRegion = findMemoryRegion(Sec);
+      // Handle align (e.g. ".foo : ALIGN(16) { ... }").
+      if (Sec->AlignExpr)
+        Sec->Alignment =
+            std::max<uint32_t>(Sec->Alignment, Sec->AlignExpr().getValue());
+    }
+  }
 }
 
 static OutputSection *findFirstSection(PhdrEntry *Load) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39047.119462.patch
Type: text/x-patch
Size: 2376 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171018/23cf71e3/attachment-0001.bin>


More information about the llvm-commits mailing list