From a6fef0e5dbf938f8442e5adcd6b8c1b35db56d62 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 5 Jun 2017 23:43:49 +0000 Subject: [PATCH] Move clearOutputSections earlier. This moves clearOutputSections and OutputSectionCommands creation as early as possible without changing other code. llvm-svn: 304751 --- lld/ELF/Writer.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index dd95c9ac917c..9ffe6e984af5 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -258,13 +258,7 @@ template void Writer::run() { if (ErrorCount) return; - for (BaseCommand *Base : Script->Opt.Commands) - if (auto *Cmd = dyn_cast(Base)) - OutputSectionCommands.push_back(Cmd); - - clearOutputSections(); - - if (!Script->Opt.HasSections &&!Config->Relocatable) + if (!Script->Opt.HasSections && !Config->Relocatable) fixSectionAlignments(); // If -compressed-debug-sections is specified, we need to compress @@ -1267,6 +1261,9 @@ template void Writer::finalizeSections() { Script->fabricateDefaultCommands(); else Script->synchronize(); + for (BaseCommand *Base : Script->Opt.Commands) + if (auto *Cmd = dyn_cast(Base)) + OutputSectionCommands.push_back(Cmd); // Fill other section headers. The dynamic table is finalized // at the end because some tags like RELSZ depend on result @@ -1277,6 +1274,8 @@ 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() {