Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -1171,10 +1171,10 @@ add({DT_MIPS_RLD_MAP, InX::MipsRldMap}); } - getParent()->Link = this->Link; + add({DT_NULL, 0ULL}); - // +1 for DT_NULL - this->Size = (Entries.size() + 1) * this->Entsize; + getParent()->Link = this->Link; + this->Size = Entries.size() * this->Entsize; } template void DynamicSection::writeTo(uint8_t *Buf) { Index: test/ELF/dynamic-no-rosegment.s =================================================================== --- test/ELF/dynamic-no-rosegment.s +++ test/ELF/dynamic-no-rosegment.s @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld -shared --no-rosegment -z rodynamic -o %t %t.o +# RUN: llvm-readobj -dynamic-table -s %t | FileCheck %s + +# CHECK: DynamicSection [ (6 entries) +# CHECK-NEXT: Tag Type Name/Value +# CHECK-NEXT: 0x0000000000000006 SYMTAB 0x120 +# CHECK-NEXT: 0x000000000000000B SYMENT 24 (bytes) +# CHECK-NEXT: 0x0000000000000005 STRTAB 0x1A8 +# CHECK-NEXT: 0x000000000000000A STRSZ 1 (bytes) +# CHECK-NEXT: 0x0000000000000004 HASH 0x138 +# CHECK-NEXT: 0x0000000000000000 NULL 0x0 +# CHECK-NEXT: ]