[lld] r265462 - Make TLS work for PIE executables on x86-64.

Ed Schouten via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 13:51:51 PDT 2016


Author: ed
Date: Tue Apr  5 15:51:50 2016
New Revision: 265462

URL: http://llvm.org/viewvc/llvm-project?rev=265462&view=rev
Log:
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

Added:
    lld/trunk/test/ELF/x86-64-tls-pie.s
Modified:
    lld/trunk/ELF/Target.cpp

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=265462&r1=265461&r2=265462&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Tue Apr  5 15:51:50 2016
@@ -818,6 +818,8 @@ bool X86_64TargetInfo::isRelRelative(uin
   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:

Added: lld/trunk/test/ELF/x86-64-tls-pie.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-tls-pie.s?rev=265462&view=auto
==============================================================================
--- lld/trunk/test/ELF/x86-64-tls-pie.s (added)
+++ lld/trunk/test/ELF/x86-64-tls-pie.s Tue Apr  5 15:51:50 2016
@@ -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 at TPOFF(%rax)
+
+	movq	%fs:0, %rdx
+	movq	i at GOTTPOFF(%rip), %rcx
+	movl	$3, (%rdx,%rcx)
+
+	.section	.tbss.i,"awT", at nobits
+	.globl	i
+i:
+	.long	0
+	.size	i, 4




More information about the llvm-commits mailing list