diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2017-06-08 04:17:04 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2017-06-08 04:17:04 +0000 |
commit | e76231b64738e478eda40a59632705d08a85438b (patch) | |
tree | 0e98f0562df5c182e63125431798b6863707f301 | |
parent | 4a7ac59b37f65e936aa21a83501a45a028a14e24 (diff) | |
download | bcm5719-llvm-e76231b64738e478eda40a59632705d08a85438b.tar.gz bcm5719-llvm-e76231b64738e478eda40a59632705d08a85438b.zip |
Move fabricateDefaultCommands earlier.
This then requires delaying a call to getHeaderSize.
llvm-svn: 304961
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 10 | ||||
-rw-r--r-- | lld/ELF/Writer.cpp | 11 |
2 files changed, 13 insertions, 8 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index b31ae68089a..9dd7ba52be1 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -444,7 +444,7 @@ void LinkerScript::fabricateDefaultCommands() { 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::fabricateDefaultCommands() { 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 diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index a8ab1437e4e..ad95a8acced 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1207,6 +1207,12 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() { 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>::finalizeSections() { 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 |