From d57c58d75d22a9c7b5922f5d4f7e57d153d67c6a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 7 Jun 2017 02:31:19 +0000 Subject: Move clearOutputSections earlier. NFC. This now just requires not calling assignOffsets after it. llvm-svn: 304861 --- lld/ELF/Writer.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lld') diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 444384dc8b4..5ee7e20d7e6 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1115,10 +1115,8 @@ template void Writer::sortSections() { static void applySynthetic(const std::vector &Sections, std::function Fn) { for (SyntheticSection *SS : Sections) - if (SS && SS->getParent() && !SS->empty()) { + if (SS && SS->getParent() && !SS->empty()) Fn(SS); - SS->getParent()->assignOffsets(); - } } // We need to add input synthetic sections early in createSyntheticSections() @@ -1233,6 +1231,12 @@ template void Writer::finalizeSections() { Out::ProgramHeaders->Size = sizeof(Elf_Phdr) * Phdrs.size(); } + // Compute the size of .rela.dyn and .rela.plt early since we need + // them to populate .dynamic. + for (SyntheticSection *SS : {In::RelaDyn, In::RelaPlt}) + if (SS->getParent() && !SS->empty()) + SS->getParent()->assignOffsets(); + // Dynamic section must be the last one in this list and dynamic // symbol table section (DynSymTab) must be the first one. applySynthetic({InX::DynSymTab, InX::Bss, InX::BssRelRo, @@ -1268,6 +1272,7 @@ template void Writer::finalizeSections() { for (BaseCommand *Base : Script->Opt.Commands) if (auto *Cmd = dyn_cast(Base)) OutputSectionCommands.push_back(Cmd); + clearOutputSections(); // Fill other section headers. The dynamic table is finalized // at the end because some tags like RELSZ depend on result @@ -1278,8 +1283,6 @@ template void Writer::finalizeSections() { // createThunks may have added local symbols to the static symbol table applySynthetic({InX::SymTab, InX::ShStrTab, InX::StrTab}, [](SyntheticSection *SS) { SS->postThunkContents(); }); - - clearOutputSections(); } template void Writer::addPredefinedSections() { -- cgit v1.2.3