1 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic -pie-copy-relocations \
2 ; RUN: | FileCheck -check-prefix=X64 %s
3 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic -pie-copy-relocations \
4 ; RUN: | FileCheck -check-prefix=X32 %s
6 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic -pie-copy-relocations \
7 ; RUN: | FileCheck -check-prefix=X64 %s
8 ; RUN: llc < %s -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic -pie-copy-relocations \
9 ; RUN: | FileCheck -check-prefix=X32 %s
12 @a = global i32 0, align 4
14 define i32 @my_access_global_a() #0 {
15 ; X32-LABEL: my_access_global_a:
16 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
17 ; X32-NEXT: movl a@GOTOFF(%eax), %eax
18 ; X64-LABEL: my_access_global_a:
19 ; X64: movl a(%rip), %eax
22 %0 = load i32, i32* @a, align 4
27 @b = weak global i32 0, align 4
29 define i32 @my_access_global_b() #0 {
30 ; X32-LABEL: my_access_global_b:
31 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
32 ; X32-NEXT: movl b@GOTOFF(%eax), %eax
33 ; X64-LABEL: my_access_global_b:
34 ; X64: movl b(%rip), %eax
37 %0 = load i32, i32* @b, align 4
42 @c = internal global i32 0, align 4
44 define i32 @my_access_global_c() #0 {
45 ; X32-LABEL: my_access_global_c:
46 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
47 ; X32-NEXT: movl c@GOTOFF(%eax), %eax
48 ; X64-LABEL: my_access_global_c:
49 ; X64: movl c(%rip), %eax
52 %0 = load i32, i32* @c, align 4
56 ; External Linkage, only declaration.
57 @d = external global i32, align 4
59 define i32 @my_access_global_load_d() #0 {
60 ; X32-LABEL: my_access_global_load_d:
61 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
62 ; X32-NEXT: movl d@GOTOFF(%eax), %eax
63 ; X64-LABEL: my_access_global_load_d:
64 ; X64: movl d(%rip), %eax
67 %0 = load i32, i32* @d, align 4
71 ; ExternalWeak Linkage
72 @e = extern_weak global i32, align 4
74 define i32* @my_access_global_d() #0 {
75 ; X32-LABEL: my_access_global_d:
76 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
77 ; X32: movl e@GOT(%eax), %eax
78 ; X64-LABEL: my_access_global_d:
79 ; X64: movq e@GOTPCREL(%rip), %rax
85 ; ExternalWeak hidden Linkage
86 @he = extern_weak hidden global i32, align 4
88 define i32* @my_access_global_he() #0 {
89 ; X32-LABEL: my_access_global_he:
90 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
91 ; X32: movl he@GOT(%eax), %eax
92 ; X64-LABEL: my_access_global_he:
93 ; X64: movq he@GOTPCREL(%rip), %rax
98 ; External Linkage, only declaration, store a value.
100 define i32 @my_access_global_store_d() #0 {
101 ; X32-LABEL: my_access_global_store_d:
102 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
103 ; X32-NEXT: movl $2, d@GOTOFF(%eax)
104 ; X64-LABEL: my_access_global_store_d:
105 ; X64: movl $2, d(%rip)
108 store i32 2, i32* @d, align 4
112 ; External Linkage, function pointer access.
113 declare i32 @access_fp(i32 ()*)
116 define i32 @my_access_fp_foo() #0 {
117 ; X32-LABEL: my_access_fp_foo:
118 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %ebx
119 ; X32-NEXT: movl foo@GOT(%ebx), %eax
120 ; X64-LABEL: my_access_fp_foo:
121 ; X64: movq foo@GOTPCREL(%rip), %rdi
124 %call = call i32 @access_fp(i32 ()* @foo)
128 ; LinkOnceODR Linkage, function pointer access.
132 define linkonce_odr i32 @bar() comdat {
137 define i32 @my_access_fp_bar() #0 {
138 ; X32-LABEL: my_access_fp_bar:
139 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %ebx
140 ; X32-NEXT: leal bar@GOTOFF(%ebx), %eax
141 ; X64-LABEL: my_access_fp_bar:
142 ; X64: leaq bar(%rip), %rdi
145 %call = call i32 @access_fp(i32 ()* @bar)
149 !llvm.module.flags = !{!0, !1}
150 !0 = !{i32 1, !"PIC Level", i32 1}
151 !1 = !{i32 1, !"PIE Level", i32 1}