[PATCH] D41928: [ELF] Fix SysV hash tables with --no-rosegment

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 10 17:20:58 PST 2018


smeenai created this revision.
smeenai added reviewers: espindola, grimar, ruiu.
Herald added a subscriber: emaste.

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. Explicitly
zero-initialize the buckets to fix this problem. Also explicitly
zero-initialize the chain entry for STN_UNDEF; I don't think this is
actually necessary, but it doesn't hurt, and should make the hash table
identical both with and without --no-rosegment.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D41928

Files:
  ELF/SyntheticSections.cpp
  test/ELF/sysv-hash-no-rosegment.s


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 at PLT
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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41928.129376.patch
Type: text/x-patch
Size: 1018 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180111/e15498aa/attachment.bin>


More information about the llvm-commits mailing list