aboutsummaryrefslogtreecommitdiffstats
path: root/test/CodeGen/X86/tls-pie.ll
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-04-08 17:51:45 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-04-08 17:51:45 +0000
commit253933ee9ef2c413ecd782efeacc5d7b9bcda09a (patch)
tree4dd402f01a78ae40c9d6569bc5fba37f5af64501 /test/CodeGen/X86/tls-pie.ll
parent34797136cb9fa9f450c0e1c47983482083979dd4 (diff)
downloadexternal_llvm-253933ee9ef2c413ecd782efeacc5d7b9bcda09a.zip
external_llvm-253933ee9ef2c413ecd782efeacc5d7b9bcda09a.tar.gz
external_llvm-253933ee9ef2c413ecd782efeacc5d7b9bcda09a.tar.bz2
Teach LLVM about a PIE option which, when enabled on top of PIC, makes
optimizations which are valid for position independent code being linked into a single executable, but not for such code being linked into a shared library. I discussed the design of this with Eric Christopher, and the decision was to support an optional bit rather than a completely separate relocation model. Fundamentally, this is still PIC relocation, its just that certain optimizations are only valid under a PIC relocation model when the resulting code won't be in a shared library. The simplest path to here is to expose a single bit option in the TargetOptions. If folks have different/better designs, I'm all ears. =] I've included the first optimization based upon this: changing TLS models to the *Exec models when PIE is enabled. This is the LLVM component of PR12380 and is all of the hard work. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154294 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGen/X86/tls-pie.ll')
-rw-r--r--test/CodeGen/X86/tls-pie.ll64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/CodeGen/X86/tls-pie.ll b/test/CodeGen/X86/tls-pie.ll
new file mode 100644
index 0000000..6c739cb
--- /dev/null
+++ b/test/CodeGen/X86/tls-pie.ll
@@ -0,0 +1,64 @@
+; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu -relocation-model=pic -enable-pie \
+; RUN: | FileCheck -check-prefix=X32 %s
+; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu -relocation-model=pic -enable-pie \
+; RUN: | FileCheck -check-prefix=X64 %s
+
+@i = thread_local global i32 15
+@i2 = external thread_local global i32
+
+define i32 @f1() {
+; X32: f1:
+; X32: movl %gs:i@NTPOFF, %eax
+; X32-NEXT: ret
+; X64: f1:
+; X64: movabsq $i@TPOFF, %rax
+; X64-NEXT: movl %fs:(%rax), %eax
+; X64-NEXT: ret
+
+entry:
+ %tmp1 = load i32* @i
+ ret i32 %tmp1
+}
+
+define i32* @f2() {
+; X32: f2:
+; X32: movl %gs:0, %eax
+; X32-NEXT: leal i@NTPOFF(%eax), %eax
+; X32-NEXT: ret
+; X64: f2:
+; X64: movq %fs:0, %rax
+; X64-NEXT: addq $i@TPOFF, %rax
+; X64-NEXT: ret
+
+entry:
+ ret i32* @i
+}
+
+define i32 @f3() {
+; X32: f3:
+; X32: movl i2@INDNTPOFF, %eax
+; X32-NEXT: movl %gs:(%eax), %eax
+; X32-NEXT: ret
+; X64: f3:
+; X64: movq i2@GOTTPOFF(%rip), %rax
+; X64-NEXT: movl %fs:(%rax), %eax
+; X64-NEXT: ret
+
+entry:
+ %tmp1 = load i32* @i2
+ ret i32 %tmp1
+}
+
+define i32* @f4() {
+; X32: f4:
+; X32: movl %gs:0, %eax
+; X32-NEXT: addl i2@INDNTPOFF, %eax
+; X32-NEXT: ret
+; X64: f4:
+; X64: movq %fs:0, %rax
+; X64-NEXT: addq i2@GOTTPOFF(%rip), %rax
+; X64-NEXT: ret
+
+entry:
+ ret i32* @i2
+}