[PATCH] D22962: [ELF] - Linkerscript cleanup of LinkerScript<ELFT>::createSections()

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 29 07:39:52 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

Change extracted from D22749.

https://reviews.llvm.org/D22962

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

Index: ELF/LinkerScript.h
===================================================================
--- ELF/LinkerScript.h
+++ ELF/LinkerScript.h
@@ -141,7 +141,7 @@
   bool hasPhdrsCommands();
 
 private:
-  std::vector<std::pair<StringRef, const InputSectionDescription *>>
+  std::vector<std::pair<StringRef, ArrayRef<std::unique_ptr<BaseCommand>>>>
   getSectionMap();
 
   std::vector<InputSectionBase<ELFT> *>
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -74,21 +74,14 @@
   return false;
 }
 
-// Create a vector of (<output section name>, <input section name patterns>).
-// For example, if a returned vector contains (".text" (".foo.*" ".bar.*")),
-// input sections start with ".foo." or ".bar." should be added to
-// ".text" section.
+// Create a vector of (<output section name>, list of <BaseCommand *>).
 template <class ELFT>
-std::vector<std::pair<StringRef, const InputSectionDescription *>>
+std::vector<std::pair<StringRef, ArrayRef<std::unique_ptr<BaseCommand>>>>
 LinkerScript<ELFT>::getSectionMap() {
-  std::vector<std::pair<StringRef, const InputSectionDescription *>> Ret;
-
+  std::vector<std::pair<StringRef, ArrayRef<std::unique_ptr<BaseCommand>>>> Ret;
   for (const std::unique_ptr<BaseCommand> &Base1 : Opt.Commands)
     if (auto *Cmd1 = dyn_cast<OutputSectionCommand>(Base1.get()))
-      for (const std::unique_ptr<BaseCommand> &Base2 : Cmd1->Commands)
-        if (auto *Cmd2 = dyn_cast<InputSectionDescription>(Base2.get()))
-          Ret.emplace_back(Cmd1->Name, Cmd2);
-
+      Ret.emplace_back(Cmd1->Name, Cmd1->Commands);
   return Ret;
 }
 
@@ -138,14 +131,19 @@
 
   for (auto &P : getSectionMap()) {
     StringRef OutputName = P.first;
-    const InputSectionDescription *I = P.second;
-    for (InputSectionBase<ELFT> *S : getInputSections(I)) {
-      if (OutputName == "/DISCARD/") {
-        S->Live = false;
-        reportDiscarded(S);
+    for (const std::unique_ptr<BaseCommand> &Cmd : P.second) {
+      auto *InCmd = dyn_cast<InputSectionDescription>(Cmd.get());
+      if (!InCmd)
         continue;
+
+      for (InputSectionBase<ELFT> *S : getInputSections(InCmd)) {
+        if (OutputName == "/DISCARD/") {
+          S->Live = false;
+          reportDiscarded(S);
+          continue;
+        }
+        Add(S, OutputName);
       }
-      Add(S, OutputName);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22962.66120.patch
Type: text/x-patch
Size: 2494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160729/a935df57/attachment.bin>


More information about the llvm-commits mailing list