Skip to content

Commit

Permalink
[ELF] Fix SysV hash tables with --no-rosegment
Browse files Browse the repository at this point in the history
When setting up the chain, we copy over the bucket's previous symbol
index, assuming that this index will be 0 (STN_UNDEF) for an unused
bucket (marking the end of the chain). When linking with --no-rosegment,
however, unused buckets will in fact contain the padding value, and so
the hash table will end up containing invalid chains. Zero out the hash
table section explicitly to avoid this, similar to what's already done
for GNU hash sections.

Differential Revision: https://reviews.llvm.org/D41928

llvm-svn: 322259
  • Loading branch information
smeenai committed Jan 11, 2018
1 parent bb9c6fc commit d79bbf4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,9 @@ void HashTableSection::finalizeContents() {
}

void HashTableSection::writeTo(uint8_t *Buf) {
// See comment in GnuHashTableSection::writeTo.
memset(Buf, 0, Size);

unsigned NumSymbols = InX::DynSymTab->getNumSymbols();

uint32_t *P = reinterpret_cast<uint32_t *>(Buf);
Expand Down
13 changes: 13 additions & 0 deletions lld/test/ELF/sysv-hash-no-rosegment.s
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d79bbf4

Please sign in to comment.