[lld] r319863 - Fix broken .gnu.hash section if -no-rosegment is given.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 5 16:49:48 PST 2017
Author: ruiu
Date: Tue Dec 5 16:49:48 2017
New Revision: 319863
URL: http://llvm.org/viewvc/llvm-project?rev=319863&view=rev
Log:
Fix broken .gnu.hash section if -no-rosegment is given.
We fill executable sections with trap instructions (0xcc or equivalent).
If a .gnu.hash section was put into an executable segment, we created
corrupted .gnu.hash section. This patch fixes the issue.
Added:
lld/trunk/test/ELF/gnu-hash-table-rwsegment.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=319863&r1=319862&r2=319863&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue Dec 5 16:49:48 2017
@@ -1710,6 +1710,11 @@ void GnuHashTableSection::finalizeConten
}
void GnuHashTableSection::writeTo(uint8_t *Buf) {
+ // The output buffer is not guaranteed to be zero-cleared because we pre-
+ // fill executable sections with trap instructions. This is a precaution
+ // for that case, which happens only when -no-rosegment is given.
+ memset(Buf, 0, Size);
+
// Write a header.
write32(Buf, NBuckets);
write32(Buf + 4, InX::DynSymTab->getNumSymbols() - Symbols.size());
Added: lld/trunk/test/ELF/gnu-hash-table-rwsegment.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gnu-hash-table-rwsegment.s?rev=319863&view=auto
==============================================================================
--- lld/trunk/test/ELF/gnu-hash-table-rwsegment.s (added)
+++ lld/trunk/test/ELF/gnu-hash-table-rwsegment.s Tue Dec 5 16:49:48 2017
@@ -0,0 +1,20 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld -shared -hash-style=gnu --no-rosegment -o %t.so %t.o
+# RUN: llvm-readobj -gnu-hash-table %t.so | FileCheck %s
+
+# CHECK: GnuHashTable {
+# CHECK-NEXT: Num Buckets: 1
+# CHECK-NEXT: First Hashed Symbol Index: 1
+# CHECK-NEXT: Num Mask Words: 1
+# CHECK-NEXT: Shift Count: 6
+# CHECK-NEXT: Bloom Filter: [0x400000000004204]
+# CHECK-NEXT: Buckets: [1]
+# CHECK-NEXT: Values: [0xB8860BA, 0xB887389]
+# CHECK-NEXT: }
+
+.globl foo, bar
+foo:
+bar:
+ ret
More information about the llvm-commits
mailing list