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.

llvm-svn: 303384
This commit is contained in:
Rafael Espindola 2017-05-18 21:30:14 +00:00
parent 795de8a7bd
commit a46f688e8f
4 changed files with 19 additions and 13 deletions

View File

@ -440,9 +440,6 @@ void LinkerScript::fabricateDefaultCommands() {
// For each OutputSection that needs a VA fabricate an OutputSectionCommand // For each OutputSection that needs a VA fabricate an OutputSectionCommand
// with an InputSectionDescription describing the InputSections // with an InputSectionDescription describing the InputSections
for (OutputSection *Sec : *OutputSections) { for (OutputSection *Sec : *OutputSections) {
if (!(Sec->Flags & SHF_ALLOC))
continue;
auto *OSCmd = make<OutputSectionCommand>(Sec->Name); auto *OSCmd = make<OutputSectionCommand>(Sec->Name);
OSCmd->Sec = Sec; OSCmd->Sec = Sec;
SecToCommand[Sec] = OSCmd; SecToCommand[Sec] = OSCmd;

View File

@ -21,6 +21,7 @@
#include "MapFile.h" #include "MapFile.h"
#include "InputFiles.h" #include "InputFiles.h"
#include "LinkerScript.h"
#include "OutputSections.h" #include "OutputSections.h"
#include "Strings.h" #include "Strings.h"
#include "SymbolTable.h" #include "SymbolTable.h"
@ -99,7 +100,7 @@ getSymbolStrings(ArrayRef<DefinedRegular *> Syms) {
} }
template <class ELFT> template <class ELFT>
void elf::writeMapFile(ArrayRef<OutputSection *> OutputSections) { void elf::writeMapFile(llvm::ArrayRef<BaseCommand *> Script) {
if (Config->MapFile.empty()) if (Config->MapFile.empty())
return; return;
@ -122,7 +123,11 @@ void elf::writeMapFile(ArrayRef<OutputSection *> OutputSections) {
<< " Align Out In Symbol\n"; << " Align Out In Symbol\n";
// Print out file contents. // 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); writeHeader<ELFT>(OS, OSec->Addr, OSec->Size, OSec->Alignment);
OS << OSec->Name << '\n'; OS << OSec->Name << '\n';
@ -137,7 +142,7 @@ void elf::writeMapFile(ArrayRef<OutputSection *> OutputSections) {
} }
} }
template void elf::writeMapFile<ELF32LE>(ArrayRef<OutputSection *>); template void elf::writeMapFile<ELF32LE>(ArrayRef<BaseCommand *>);
template void elf::writeMapFile<ELF32BE>(ArrayRef<OutputSection *>); template void elf::writeMapFile<ELF32BE>(ArrayRef<BaseCommand *>);
template void elf::writeMapFile<ELF64LE>(ArrayRef<OutputSection *>); template void elf::writeMapFile<ELF64LE>(ArrayRef<BaseCommand *>);
template void elf::writeMapFile<ELF64BE>(ArrayRef<OutputSection *>); template void elf::writeMapFile<ELF64BE>(ArrayRef<BaseCommand *>);

View File

@ -14,9 +14,8 @@
namespace lld { namespace lld {
namespace elf { namespace elf {
class OutputSection; struct BaseCommand;
template <class ELFT> template <class ELFT> void writeMapFile(llvm::ArrayRef<BaseCommand *> Script);
void writeMapFile(llvm::ArrayRef<OutputSection *> OutputSections);
} }
} }

View File

@ -288,8 +288,13 @@ template <class ELFT> void Writer<ELFT>::run() {
if (ErrorCount) if (ErrorCount)
return; 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. // Handle -Map option.
writeMapFile<ELFT>(OutputSections); writeMapFile<ELFT>(Script->Opt.Commands);
if (ErrorCount) if (ErrorCount)
return; return;