[lld] r303703 - Clear OutSec->Sections.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 15:54:07 PDT 2017


Author: rafael
Date: Tue May 23 17:54:06 2017
New Revision: 303703

URL: http://llvm.org/viewvc/llvm-project?rev=303703&view=rev
Log:
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.

Modified:
    lld/trunk/ELF/MapFile.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MapFile.cpp?rev=303703&r1=303702&r2=303703&view=diff
==============================================================================
--- lld/trunk/ELF/MapFile.cpp (original)
+++ lld/trunk/ELF/MapFile.cpp Tue May 23 17:54:06 2017
@@ -132,12 +132,17 @@ void elf::writeMapFile(llvm::ArrayRef<Ba
     OS << OSec->Name << '\n';
 
     // Dump symbols for each input section.
-    for (InputSection *IS : OSec->Sections) {
-      writeHeader<ELFT>(OS, OSec->Addr + IS->OutSecOff, IS->getSize(),
-                        IS->Alignment);
-      OS << indent(1) << toString(IS) << '\n';
-      for (DefinedRegular *Sym : SectionSyms[IS])
-        OS << SymStr[Sym] << '\n';
+    for (BaseCommand *Base : Cmd->Commands) {
+      auto *ISD = dyn_cast<InputSectionDescription>(Base);
+      if (!ISD)
+        continue;
+      for (InputSection *IS : ISD->Sections) {
+        writeHeader<ELFT>(OS, OSec->Addr + IS->OutSecOff, IS->getSize(),
+                          IS->Alignment);
+        OS << indent(1) << toString(IS) << '\n';
+        for (DefinedRegular *Sym : SectionSyms[IS])
+          OS << SymStr[Sym] << '\n';
+      }
     }
   }
 }

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=303703&r1=303702&r2=303703&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue May 23 17:54:06 2017
@@ -46,6 +46,7 @@ public:
   void run();
 
 private:
+  void clearOutputSections();
   void createSyntheticSections();
   void copyLocalSymbols();
   void addSectionSymbols();
@@ -198,6 +199,15 @@ template <class ELFT> static void combin
   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 @@ template <class ELFT> void Writer<ELFT>:
   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);




More information about the llvm-commits mailing list