Index: ELF/SyntheticSections.h =================================================================== --- ELF/SyntheticSections.h +++ ELF/SyntheticSections.h @@ -481,12 +481,17 @@ uint64_t OffsetInSec, Symbol *Sym, int64_t Addend, RelExpr Expr, RelType Type); void addReloc(const DynamicReloc &Reloc); - bool empty() const override { return Relocs.empty(); } + bool empty() const override { return Relocs.empty() && !IsIplt; } size_t getSize() const override { return Relocs.size() * this->Entsize; } size_t getRelativeRelocCount() const { return NumRelativeRelocs; } void finalizeContents() override; + int32_t DynamicTag, SizeDynamicTag; + // Used to keep empty .rela.iplt as otherwise __rela_iplt_start would have an + // invalid st_shndx. + bool IsIplt = false; + protected: std::vector Relocs; size_t NumRelativeRelocs = 0; Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -1496,8 +1496,11 @@ InputSection *SymTab = Config->Relocatable ? In.SymTab : In.DynSymTab; getParent()->Link = SymTab ? SymTab->getParent()->SectionIndex : 0; - if (In.RelaIplt == this || In.RelaPlt == this) - getParent()->Info = In.GotPlt->getParent()->SectionIndex; + if (In.RelaIplt == this || In.RelaPlt == this) { + uint32_t I = In.GotPlt->getParent()->SectionIndex; + if (I != UINT32_MAX) + getParent()->Info = I; + } } RelrBaseSection::RelrBaseSection() Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -396,6 +396,7 @@ ? ".rel.dyn" : In.RelaPlt->Name, false /*Sort*/); + In.RelaIplt->IsIplt = true; Add(In.RelaIplt); In.Plt = make(false);