[lld] r322259 - [ELF] Fix SysV hash tables with --no-rosegment
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 22:57:01 PST 2018
Author: smeenai
Date: Wed Jan 10 22:57:01 2018
New Revision: 322259
URL: http://llvm.org/viewvc/llvm-project?rev=322259&view=rev
Log:
[ELF] Fix SysV hash tables with --no-rosegment
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
Added:
lld/trunk/test/ELF/sysv-hash-no-rosegment.s
Modified:
lld/trunk/ELF/SyntheticSections.cpp
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=322259&r1=322258&r2=322259&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Wed Jan 10 22:57:01 2018
@@ -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);
Added: lld/trunk/test/ELF/sysv-hash-no-rosegment.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/sysv-hash-no-rosegment.s?rev=322259&view=auto
==============================================================================
--- lld/trunk/test/ELF/sysv-hash-no-rosegment.s (added)
+++ lld/trunk/test/ELF/sysv-hash-no-rosegment.s Wed Jan 10 22:57:01 2018
@@ -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
More information about the llvm-commits
mailing list