diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 206184b279f7..e7092822b80d 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1230,6 +1230,7 @@ template void Writer::finalizeSections() { for (BaseCommand *Base : Script->Opt.Commands) if (auto *Cmd = dyn_cast(Base)) OutputSectionCommands.push_back(Cmd); + clearOutputSections(); // Dynamic section must be the last one in this list and dynamic // symbol table section (DynSymTab) must be the first one. @@ -1243,8 +1244,6 @@ template void Writer::finalizeSections() { In::VerSym, In::VerNeed, InX::Dynamic}, [](SyntheticSection *SS) { SS->finalizeContents(); }); - clearOutputSections(); - // Some architectures use small displacements for jump instructions. // It is linker's responsibility to create thunks containing long // jump instructions if jump targets are too far. Create thunks.