summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Writer.cpp13
1 files changed, 8 insertions, 5 deletions
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 <class ELFT> void Writer<ELFT>::sortSections() {
static void applySynthetic(const std::vector<SyntheticSection *> &Sections,
std::function<void(SyntheticSection *)> 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 <class ELFT> void Writer<ELFT>::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<ELFT>::RelaDyn, In<ELFT>::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 <class ELFT> void Writer<ELFT>::finalizeSections() {
for (BaseCommand *Base : Script->Opt.Commands)
if (auto *Cmd = dyn_cast<OutputSectionCommand>(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 <class ELFT> void Writer<ELFT>::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 <class ELFT> void Writer<ELFT>::addPredefinedSections() {
OpenPOWER on IntegriCloud