[PATCH] D22909: [ELF] - Linkerscript: remove getSectionMap()

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 28 03:27:33 PDT 2016


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

I think recent patches shows that getSectionMap() is a bit excessive,
since anyways we need to have access to base command somehow in createSections().
At the same time one of pending patches moves "Add" lambda out from this method,
what will make it a bit shorter.
So I suggest to remove getSectionMap() for simplification.

https://reviews.llvm.org/D22909

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

Index: ELF/LinkerScript.h
===================================================================
--- ELF/LinkerScript.h
+++ ELF/LinkerScript.h
@@ -133,9 +133,6 @@
   bool hasPhdrsCommands();
 
 private:
-  std::vector<std::pair<StringRef, const InputSectionDescription *>>
-  getSectionMap();
-
   std::vector<InputSectionBase<ELFT> *>
   getInputSections(const InputSectionDescription *);
 
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -74,24 +74,6 @@
   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.
-template <class ELFT>
-std::vector<std::pair<StringRef, const InputSectionDescription *>>
-LinkerScript<ELFT>::getSectionMap() {
-  std::vector<std::pair<StringRef, const InputSectionDescription *>> 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);
-
-  return Ret;
-}
-
 // Returns input sections filtered by given glob patterns.
 template <class ELFT>
 std::vector<InputSectionBase<ELFT> *>
@@ -125,16 +107,22 @@
     Sec->addSection(C);
   };
 
-  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);
-        continue;
+  for (const std::unique_ptr<BaseCommand> &Base1 : Opt.Commands) {
+    if (auto *OutCmd = dyn_cast<OutputSectionCommand>(Base1.get())) {
+      for (const std::unique_ptr<BaseCommand> &Base2 : OutCmd->Commands) {
+        auto *InCmd = dyn_cast<InputSectionDescription>(Base2.get());
+        if (!InCmd)
+          continue;
+
+        for (InputSectionBase<ELFT> *S : getInputSections(InCmd)) {
+          if (OutCmd->Name == "/DISCARD/") {
+            S->Live = false;
+            reportDiscarded(S);
+            continue;
+          }
+          Add(S, OutCmd->Name);
+        }
       }
-      Add(S, OutputName);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22909.65898.patch
Type: text/x-patch
Size: 2555 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160728/3ebd9496/attachment.bin>


More information about the llvm-commits mailing list