[lld] r304961 - Move fabricateDefaultCommands earlier.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 7 21:17:05 PDT 2017
Author: rafael
Date: Wed Jun 7 23:17:04 2017
New Revision: 304961
URL: http://llvm.org/viewvc/llvm-project?rev=304961&view=rev
Log:
Move fabricateDefaultCommands earlier.
This then requires delaying a call to getHeaderSize.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=304961&r1=304960&r2=304961&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Jun 7 23:17:04 2017
@@ -444,7 +444,7 @@ void LinkerScript::fabricateDefaultComma
std::vector<BaseCommand *> Commands;
// Define start address
- uint64_t StartAddr = Config->ImageBase + elf::getHeaderSize();
+ uint64_t StartAddr = -1;
// The Sections with -T<section> have been sorted in order of ascending
// address. We must lower StartAddr if the lowest -T<section address> as
@@ -452,8 +452,12 @@ void LinkerScript::fabricateDefaultComma
for (auto& KV : Config->SectionStartMap)
StartAddr = std::min(StartAddr, KV.second);
- Commands.push_back(
- make<SymbolAssignment>(".", [=] { return StartAddr; }, ""));
+ Commands.push_back(make<SymbolAssignment>(
+ ".",
+ [=] {
+ return std::min(StartAddr, Config->ImageBase + elf::getHeaderSize());
+ },
+ ""));
// For each OutputSection that needs a VA fabricate an OutputSectionCommand
// with an InputSectionDescription describing the InputSections
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=304961&r1=304960&r2=304961&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Jun 7 23:17:04 2017
@@ -1207,6 +1207,12 @@ template <class ELFT> void Writer<ELFT>:
Sec->ShName = InX::ShStrTab->addString(Sec->Name);
}
+ if (!Script->Opt.HasSections)
+ Script->fabricateDefaultCommands();
+ for (BaseCommand *Base : Script->Opt.Commands)
+ if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
+ OutputSectionCommands.push_back(Cmd);
+
// Binary and relocatable output does not have PHDRS.
// The headers have to be created before finalize as that can influence the
// image base and the dynamic section on mips includes the image base.
@@ -1216,11 +1222,6 @@ template <class ELFT> void Writer<ELFT>:
Out::ProgramHeaders->Size = sizeof(Elf_Phdr) * Phdrs.size();
}
- if (!Script->Opt.HasSections)
- Script->fabricateDefaultCommands();
- for (BaseCommand *Base : Script->Opt.Commands)
- if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
- OutputSectionCommands.push_back(Cmd);
clearOutputSections();
// Compute the size of .rela.dyn and .rela.plt early since we need
More information about the llvm-commits
mailing list