[PATCH] D33327: Use linker script commands in writeMapFile

Rafael Ávila de Espíndola via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 18 10:55:00 PDT 2017


rafael created this revision.
Herald added a subscriber: emaste.

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.


https://reviews.llvm.org/D33327

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


Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -288,8 +288,13 @@
   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;
 
Index: ELF/MapFile.h
===================================================================
--- ELF/MapFile.h
+++ ELF/MapFile.h
@@ -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);
 }
 }
 
Index: ELF/MapFile.cpp
===================================================================
--- ELF/MapFile.cpp
+++ ELF/MapFile.cpp
@@ -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 @@
 }
 
 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 @@
      << " 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 @@
   }
 }
 
-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 *>);
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -440,9 +440,6 @@
   // 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33327.99464.patch
Type: text/x-patch
Size: 2957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170518/62823880/attachment.bin>


More information about the llvm-commits mailing list