forked from OSchip/llvm-project
Make TLS work for PIE executables on x86-64.
While trying to get PIE work on CloudABI for x86-64, I noticed that even though GNU ld would generate functional binaries, LLD would not. It turns out that we generate relocations for referencing TLS objects inside of the text segment, which shouldn't happen. This change extends the isRelRelative() function to list some additional relocation types that should be treated as relative. This makes my C library unit testing binary work on x86-64. Approved by: ruiu Differential Revision: http://reviews.llvm.org/D18688 Fixes bug: https://llvm.org/bugs/show_bug.cgi?id=27174 llvm-svn: 265462
This commit is contained in:
parent
9def2afd5c
commit
639a333730
|
@ -818,6 +818,8 @@ bool X86_64TargetInfo::isRelRelative(uint32_t Type) const {
|
|||
switch (Type) {
|
||||
default:
|
||||
return false;
|
||||
case R_X86_64_GOTTPOFF:
|
||||
case R_X86_64_TPOFF32:
|
||||
case R_X86_64_DTPOFF32:
|
||||
case R_X86_64_DTPOFF64:
|
||||
case R_X86_64_PC8:
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
# REQUIRES: x86
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-cloudabi %s -o %t1.o
|
||||
# RUN: ld.lld -pie %t1.o -o %t
|
||||
# RUN: llvm-readobj -r %t | FileCheck %s
|
||||
|
||||
# Bug 27174: R_X86_64_TPOFF32 and R_X86_64_GOTTPOFF relocations should
|
||||
# be eliminated when building a PIE executable, as the static TLS layout
|
||||
# is fixed.
|
||||
#
|
||||
# CHECK: Relocations [
|
||||
# CHECK-NEXT: ]
|
||||
|
||||
.globl _start
|
||||
_start:
|
||||
movq %fs:0, %rax
|
||||
movl $3, i@TPOFF(%rax)
|
||||
|
||||
movq %fs:0, %rdx
|
||||
movq i@GOTTPOFF(%rip), %rcx
|
||||
movl $3, (%rdx,%rcx)
|
||||
|
||||
.section .tbss.i,"awT",@nobits
|
||||
.globl i
|
||||
i:
|
||||
.long 0
|
||||
.size i, 4
|
Loading…
Reference in New Issue