Simplify handling of /DISCARD/. NFC.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 12 Sep 2016 16:05:16 +0000 (16:05 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 12 Sep 2016 16:05:16 +0000 (16:05 +0000)
llvm-svn: 281222

lld/ELF/LinkerScript.cpp
lld/ELF/LinkerScript.h

index ef8ccb9..e3f3051 100644 (file)
@@ -149,14 +149,10 @@ getComparator(SortKind K) {
 }
 
 template <class ELFT>
-void LinkerScript<ELFT>::discard(OutputSectionCommand &Cmd) {
-  for (const std::unique_ptr<BaseCommand> &Base : Cmd.Commands) {
-    if (auto *Cmd = dyn_cast<InputSectionDescription>(Base.get())) {
-      for (InputSectionBase<ELFT> *S : getInputSections(Cmd)) {
-        S->Live = false;
-        reportDiscarded(S);
-      }
-    }
+void LinkerScript<ELFT>::discard(ArrayRef<InputSectionBase<ELFT> *> V) {
+  for (InputSectionBase<ELFT> *S : V) {
+    S->Live = false;
+    reportDiscarded(S);
   }
 }
 
@@ -228,12 +224,13 @@ void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
     }
 
     if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base1.get())) {
+      std::vector<InputSectionBase<ELFT> *> V = createInputSectionList(*Cmd);
+
       if (Cmd->Name == "/DISCARD/") {
-        discard(*Cmd);
+        discard(V);
         continue;
       }
 
-      std::vector<InputSectionBase<ELFT> *> V = createInputSectionList(*Cmd);
       if (V.empty())
         continue;
 
index ea57ee9..9232715 100644 (file)
@@ -188,7 +188,7 @@ private:
   std::vector<InputSectionBase<ELFT> *>
   getInputSections(const InputSectionDescription *);
 
-  void discard(OutputSectionCommand &Cmd);
+  void discard(ArrayRef<InputSectionBase<ELFT> *> V);
 
   std::vector<InputSectionBase<ELFT> *>
   createInputSectionList(OutputSectionCommand &Cmd);