diff options
Diffstat (limited to 'lld/ELF/Writer.cpp')
-rw-r--r-- | lld/ELF/Writer.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index d2499fb54c5..ab1c5fe3ac9 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1452,6 +1452,22 @@ static uint64_t computeFlags(uint64_t Flags) { return Flags; } +// Prior to finalizeContents() an OutputSection containing SyntheticSections +// may have 0 Size, but contain SyntheticSections that haven't had their size +// calculated yet. We must use SyntheticSection->empty() for these sections. +static bool isOutputSectionZeroSize(const OutputSection* Sec) { + if (Sec->Size > 0) + return false; + for (BaseCommand *BC : Sec->SectionCommands) { + if (auto *ISD = dyn_cast<InputSectionDescription>(BC)) + for (InputSection *IS : ISD->Sections) + if (SyntheticSection *SS = dyn_cast<SyntheticSection>(IS)) + if (!SS->empty()) + return false; + } + return true; +} + // Decide which program headers to create and which sections to include in each // one. template <class ELFT> std::vector<PhdrEntry *> Writer<ELFT>::createPhdrs() { @@ -1517,7 +1533,7 @@ template <class ELFT> std::vector<PhdrEntry *> Writer<ELFT>::createPhdrs() { bool InRelroPhdr = false; bool IsRelroFinished = false; for (OutputSection *Sec : OutputSections) { - if (!needsPtLoad(Sec)) + if (!needsPtLoad(Sec) || isOutputSectionZeroSize(Sec)) continue; if (isRelroSection(Sec)) { InRelroPhdr = true; |