Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -1843,7 +1843,9 @@ write32(P++, NumSymbols); // nchain uint32_t *Buckets = P; + memset(Buckets, STN_UNDEF, NumSymbols * 4); uint32_t *Chains = P + NumSymbols; + Chains[STN_UNDEF] = STN_UNDEF; for (const SymbolTableEntry &S : InX::DynSymTab->getSymbols()) { Symbol *Sym = S.Sym; Index: test/ELF/sysv-hash-no-rosegment.s =================================================================== --- /dev/null +++ test/ELF/sysv-hash-no-rosegment.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld -shared --no-rosegment -o %t %t.o +# RUN: llvm-readobj -hash-table %t | FileCheck %s + +# CHECK: HashTable { +# CHECK-NEXT: Num Buckets: 2 +# CHECK-NEXT: Num Chains: 2 +# CHECK-NEXT: Buckets: [1, 0] +# CHECK-NEXT: Chains: [0, 0] +# CHECK-NEXT: } + +callq undef@PLT