Clear OutSec->Sections.

Once the dummy linker script is created, we want it to be used for
everything to avoid having two redundant representations that can get
out of sync.

We were already clearing OutputSections. With this patch we clear the
Sections vector of every OutputSection.

llvm-svn: 303703
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 7a21d2b..0528434b 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -46,6 +46,7 @@
   void run();
 
 private:
+  void clearOutputSections();
   void createSyntheticSections();
   void copyLocalSymbols();
   void addSectionSymbols();
@@ -198,6 +199,15 @@
   V.erase(std::remove(V.begin(), V.end(), nullptr), V.end());
 }
 
+template <class ELFT> void Writer<ELFT>::clearOutputSections() {
+  // Clear the OutputSections to make sure it is not used anymore. Any
+  // code from this point on should be using the linker script
+  // commands.
+  for (OutputSection *Sec : OutputSections)
+    Sec->Sections.clear();
+  OutputSections.clear();
+}
+
 // The main function of the writer.
 template <class ELFT> void Writer<ELFT>::run() {
   // Create linker-synthesized sections such as .got or .plt.
@@ -288,10 +298,7 @@
   if (ErrorCount)
     return;
 
-  // Clear the OutputSections to make sure it is not used anymore. Any
-  // code from this point on should be using the linker script
-  // commands.
-  OutputSections.clear();
+  clearOutputSections();
 
   // Handle -Map option.
   writeMapFile<ELFT>(Script->Opt.Commands);