summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2017-05-30 01:30:14 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2017-05-30 01:30:14 +0000
commit2d9a3be2ab4444ce222abcfd2eb5c490986c42a6 (patch)
tree59e6c7396988959df9105cd15d3c6b58773c60f4
parenta607ba6134491074fb9b848a391464e42a8c1eaf (diff)
downloadbcm5719-llvm-2d9a3be2ab4444ce222abcfd2eb5c490986c42a6.tar.gz
bcm5719-llvm-2d9a3be2ab4444ce222abcfd2eb5c490986c42a6.zip
Keep a list of all OutputSectionCommands.
Now that we are trying to use the linker script representation as the canonycal one, there are a few loops looking for just OutputSectionCommands. Create a vector with just the OutputSectionCommands once that is stable to simplify the rest of the code. llvm-svn: 304181
-rw-r--r--lld/ELF/MapFile.cpp15
-rw-r--r--lld/ELF/MapFile.h5
-rw-r--r--lld/ELF/Writer.cpp29
3 files changed, 21 insertions, 28 deletions
diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp
index 806e99e3d9d..e0c7d8cd8b1 100644
--- a/lld/ELF/MapFile.cpp
+++ b/lld/ELF/MapFile.cpp
@@ -100,7 +100,7 @@ getSymbolStrings(ArrayRef<DefinedRegular *> Syms) {
}
template <class ELFT>
-void elf::writeMapFile(llvm::ArrayRef<BaseCommand *> Script) {
+void elf::writeMapFile(llvm::ArrayRef<OutputSectionCommand *> Script) {
if (Config->MapFile.empty())
return;
@@ -123,10 +123,7 @@ void elf::writeMapFile(llvm::ArrayRef<BaseCommand *> Script) {
<< " Align Out In Symbol\n";
// Print out file contents.
- for (BaseCommand *Base : Script) {
- auto *Cmd = dyn_cast<OutputSectionCommand>(Base);
- if (!Cmd)
- continue;
+ for (OutputSectionCommand *Cmd : Script) {
OutputSection *OSec = Cmd->Sec;
writeHeader<ELFT>(OS, OSec->Addr, OSec->Size, OSec->Alignment);
OS << OSec->Name << '\n';
@@ -147,7 +144,7 @@ void elf::writeMapFile(llvm::ArrayRef<BaseCommand *> Script) {
}
}
-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 *>);
+template void elf::writeMapFile<ELF32LE>(ArrayRef<OutputSectionCommand *>);
+template void elf::writeMapFile<ELF32BE>(ArrayRef<OutputSectionCommand *>);
+template void elf::writeMapFile<ELF64LE>(ArrayRef<OutputSectionCommand *>);
+template void elf::writeMapFile<ELF64BE>(ArrayRef<OutputSectionCommand *>);
diff --git a/lld/ELF/MapFile.h b/lld/ELF/MapFile.h
index f50ef00061f..68d8ba8d4a0 100644
--- a/lld/ELF/MapFile.h
+++ b/lld/ELF/MapFile.h
@@ -14,8 +14,9 @@
namespace lld {
namespace elf {
-struct BaseCommand;
-template <class ELFT> void writeMapFile(llvm::ArrayRef<BaseCommand *> Script);
+struct OutputSectionCommand;
+template <class ELFT>
+void writeMapFile(llvm::ArrayRef<OutputSectionCommand *> Script);
}
}
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index e539d8ffce6..72035365be2 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -74,6 +74,7 @@ private:
std::unique_ptr<FileOutputBuffer> Buffer;
std::vector<OutputSection *> OutputSections;
+ std::vector<OutputSectionCommand *> OutputSectionCommands;
OutputSectionFactory Factory{OutputSections};
void addRelIpltSymbols();
@@ -262,6 +263,10 @@ template <class ELFT> void Writer<ELFT>::run() {
Script->fabricateDefaultCommands();
}
+ for (BaseCommand *Base : Script->Opt.Commands)
+ if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
+ OutputSectionCommands.push_back(Cmd);
+
// If -compressed-debug-sections is specified, we need to compress
// .debug_* sections. Do it right now because it changes the size of
// output sections.
@@ -311,7 +316,7 @@ template <class ELFT> void Writer<ELFT>::run() {
// Handle -Map option.
- writeMapFile<ELFT>(Script->Opt.Commands);
+ writeMapFile<ELFT>(OutputSectionCommands);
if (ErrorCount)
return;
@@ -1315,10 +1320,9 @@ void Writer<ELFT>::addStartStopSymbols(OutputSection *Sec) {
template <class ELFT>
OutputSectionCommand *Writer<ELFT>::findSectionCommand(StringRef Name) {
- for (BaseCommand *Base : Script->Opt.Commands)
- if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
- if (Cmd->Name == Name)
- return Cmd;
+ for (OutputSectionCommand *Cmd : OutputSectionCommands)
+ if (Cmd->Name == Name)
+ return Cmd;
return nullptr;
}
@@ -1769,10 +1773,7 @@ template <class ELFT> void Writer<ELFT>::openFile() {
template <class ELFT> void Writer<ELFT>::writeSectionsBinary() {
uint8_t *Buf = Buffer->getBufferStart();
- for (BaseCommand *Base : Script->Opt.Commands) {
- auto *Cmd = dyn_cast<OutputSectionCommand>(Base);
- if (!Cmd)
- continue;
+ for (OutputSectionCommand *Cmd : OutputSectionCommands) {
OutputSection *Sec = Cmd->Sec;
if (Sec->Flags & SHF_ALLOC)
Cmd->writeTo<ELFT>(Buf + Sec->Offset);
@@ -1799,19 +1800,13 @@ template <class ELFT> void Writer<ELFT>::writeSections() {
// In -r or -emit-relocs mode, write the relocation sections first as in
// ELf_Rel targets we might find out that we need to modify the relocated
// section while doing it.
- for (BaseCommand *Base : Script->Opt.Commands) {
- auto *Cmd = dyn_cast<OutputSectionCommand>(Base);
- if (!Cmd)
- continue;
+ for (OutputSectionCommand *Cmd : OutputSectionCommands) {
OutputSection *Sec = Cmd->Sec;
if (Sec->Type == SHT_REL || Sec->Type == SHT_RELA)
Cmd->writeTo<ELFT>(Buf + Sec->Offset);
}
- for (BaseCommand *Base : Script->Opt.Commands) {
- auto *Cmd = dyn_cast<OutputSectionCommand>(Base);
- if (!Cmd)
- continue;
+ for (OutputSectionCommand *Cmd : OutputSectionCommands) {
OutputSection *Sec = Cmd->Sec;
if (Sec != Out::Opd && Sec != EhFrameHdr && Sec->Type != SHT_REL &&
Sec->Type != SHT_RELA)
OpenPOWER on IntegriCloud