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,22 @@ +# 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 [ (10 entries) +# CHECK-NEXT: Tag Type Name/Value +# CHECK-NEXT: 0x0000000000000017 JMPREL 0x278 +# CHECK-NEXT: 0x0000000000000002 PLTRELSZ 24 (bytes) +# CHECK-NEXT: 0x0000000000000003 PLTGOT 0x1000 +# CHECK-NEXT: 0x0000000000000014 PLTREL RELA +# CHECK-NEXT: 0x0000000000000006 SYMTAB 0x160 +# CHECK-NEXT: 0x000000000000000B SYMENT 24 (bytes) +# CHECK-NEXT: 0x0000000000000005 STRTAB 0x268 +# CHECK-NEXT: 0x000000000000000A STRSZ 12 (bytes) +# CHECK-NEXT: 0x0000000000000004 HASH 0x1A8 +# CHECK-NEXT: 0x0000000000000000 NULL 0x0 +# CHECK-NEXT: ] + +.globl _start +_start: + callq foo@PLT