[lld] r303384 - Use linker script commands in writeMapFile.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu May 18 14:30:15 PDT 2017


Author: rafael
Date: Thu May 18 16:30:14 2017
New Revision: 303384

URL: http://llvm.org/viewvc/llvm-project?rev=303384&view=rev
Log:
Use linker script commands in writeMapFile.

This converts the last (chronologically) user of OutputSections to use
the linker script commands instead.

The idea is to convert all uses after fabricateDefaultCommands, so
that we have a single representation.

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

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=303384&r1=303383&r2=303384&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu May 18 16:30:14 2017
@@ -440,9 +440,6 @@ void LinkerScript::fabricateDefaultComma
   // For each OutputSection that needs a VA fabricate an OutputSectionCommand
   // with an InputSectionDescription describing the InputSections
   for (OutputSection *Sec : *OutputSections) {
-    if (!(Sec->Flags & SHF_ALLOC))
-      continue;
-
     auto *OSCmd = make<OutputSectionCommand>(Sec->Name);
     OSCmd->Sec = Sec;
     SecToCommand[Sec] = OSCmd;

Modified: lld/trunk/ELF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MapFile.cpp?rev=303384&r1=303383&r2=303384&view=diff
==============================================================================
--- lld/trunk/ELF/MapFile.cpp (original)
+++ lld/trunk/ELF/MapFile.cpp Thu May 18 16:30:14 2017
@@ -21,6 +21,7 @@
 
 #include "MapFile.h"
 #include "InputFiles.h"
+#include "LinkerScript.h"
 #include "OutputSections.h"
 #include "Strings.h"
 #include "SymbolTable.h"
@@ -99,7 +100,7 @@ getSymbolStrings(ArrayRef<DefinedRegular
 }
 
 template <class ELFT>
-void elf::writeMapFile(ArrayRef<OutputSection *> OutputSections) {
+void elf::writeMapFile(llvm::ArrayRef<BaseCommand *> Script) {
   if (Config->MapFile.empty())
     return;
 
@@ -122,7 +123,11 @@ void elf::writeMapFile(ArrayRef<OutputSe
      << " Align Out     In      Symbol\n";
 
   // Print out file contents.
-  for (OutputSection *OSec : OutputSections) {
+  for (BaseCommand *Base : Script) {
+    auto *Cmd = dyn_cast<OutputSectionCommand>(Base);
+    if (!Cmd)
+      continue;
+    OutputSection *OSec = Cmd->Sec;
     writeHeader<ELFT>(OS, OSec->Addr, OSec->Size, OSec->Alignment);
     OS << OSec->Name << '\n';
 
@@ -137,7 +142,7 @@ void elf::writeMapFile(ArrayRef<OutputSe
   }
 }
 
-template void elf::writeMapFile<ELF32LE>(ArrayRef<OutputSection *>);
-template void elf::writeMapFile<ELF32BE>(ArrayRef<OutputSection *>);
-template void elf::writeMapFile<ELF64LE>(ArrayRef<OutputSection *>);
-template void elf::writeMapFile<ELF64BE>(ArrayRef<OutputSection *>);
+template void elf::writeMapFile<ELF32LE>(ArrayRef<BaseCommand *>);
+template void elf::writeMapFile<ELF32BE>(ArrayRef<BaseCommand *>);
+template void elf::writeMapFile<ELF64LE>(ArrayRef<BaseCommand *>);
+template void elf::writeMapFile<ELF64BE>(ArrayRef<BaseCommand *>);

Modified: lld/trunk/ELF/MapFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MapFile.h?rev=303384&r1=303383&r2=303384&view=diff
==============================================================================
--- lld/trunk/ELF/MapFile.h (original)
+++ lld/trunk/ELF/MapFile.h Thu May 18 16:30:14 2017
@@ -14,9 +14,8 @@
 
 namespace lld {
 namespace elf {
-class OutputSection;
-template <class ELFT>
-void writeMapFile(llvm::ArrayRef<OutputSection *> OutputSections);
+struct BaseCommand;
+template <class ELFT> void writeMapFile(llvm::ArrayRef<BaseCommand *> Script);
 }
 }
 

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=303384&r1=303383&r2=303384&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu May 18 16:30:14 2017
@@ -288,8 +288,13 @@ 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();
+
   // Handle -Map option.
-  writeMapFile<ELFT>(OutputSections);
+  writeMapFile<ELFT>(Script->Opt.Commands);
   if (ErrorCount)
     return;
 




More information about the llvm-commits mailing list