1; RUN: llc -mtriple x86_64-pc-linux -relocation-model=static < %s | \
2; RUN:   FileCheck --check-prefixes=COMMON,STATIC %s
3; RUN: llc -mtriple x86_64-pc-linux -relocation-model=pic < %s | \
4; RUN:   FileCheck --check-prefixes=COMMON,CHECK %s
5; RUN: llc -mtriple x86_64-pc-linux -relocation-model=dynamic-no-pic < %s | \
6; RUN:   FileCheck --check-prefixes=COMMON,CHECK %s
7
8; 32 bits
9
10; RUN: llc -mtriple i386-pc-linux \
11; RUN:     -relocation-model=pic     < %s | FileCheck --check-prefix=CHECK32 %s
12
13; globals
14
15@strong_default_global = global i32 42
16define i32* @get_strong_default_global() {
17  ret i32* @strong_default_global
18}
19; CHECK: movq strong_default_global@GOTPCREL(%rip), %rax
20; STATIC: movl $strong_default_global, %eax
21; CHECK32: movl strong_default_global@GOT(%eax), %eax
22
23@strong_hidden_global = hidden global i32 42
24define i32* @get_hidden_default_global() {
25  ret i32* @strong_hidden_global
26}
27; CHECK: leaq strong_hidden_global(%rip), %rax
28; STATIC: movl $strong_hidden_global, %eax
29; CHECK32: leal strong_hidden_global@GOTOFF(%eax), %eax
30
31@weak_default_global = weak global i32 42
32define i32* @get_weak_default_global() {
33  ret i32* @weak_default_global
34}
35; CHECK: movq weak_default_global@GOTPCREL(%rip), %rax
36; STATIC: movl $weak_default_global, %eax
37; CHECK32: movl weak_default_global@GOT(%eax), %eax
38
39@external_default_global = external global i32
40define i32* @get_external_default_global() {
41  ret i32* @external_default_global
42}
43; CHECK: movq external_default_global@GOTPCREL(%rip), %rax
44; STATIC: movq external_default_global@GOTPCREL(%rip), %rax
45; CHECK32: movl external_default_global@GOT(%eax), %eax
46
47@strong_local_global = dso_local global i32 42
48define i32* @get_strong_local_global() {
49  ret i32* @strong_local_global
50}
51; CHECK: leaq .Lstrong_local_global$local(%rip), %rax
52; STATIC: movl $strong_local_global, %eax
53; CHECK32: leal .Lstrong_local_global$local@GOTOFF(%eax), %eax
54
55@weak_local_global = weak dso_local global i32 42
56define i32* @get_weak_local_global() {
57  ret i32* @weak_local_global
58}
59; CHECK: leaq weak_local_global(%rip), %rax
60; STATIC: movl $weak_local_global, %eax
61; CHECK32: leal weak_local_global@GOTOFF(%eax), %eax
62
63@external_local_global = external dso_local global i32
64define i32* @get_external_local_global() {
65  ret i32* @external_local_global
66}
67; CHECK: leaq external_local_global(%rip), %rax
68; STATIC: movl $external_local_global, %eax
69; CHECK32: leal external_local_global@GOTOFF(%eax), %eax
70
71
72@strong_preemptable_global = dso_preemptable global i32 42
73define i32* @get_strong_preemptable_global() {
74  ret i32* @strong_preemptable_global
75}
76; CHECK: movq strong_preemptable_global@GOTPCREL(%rip), %rax
77; STATIC: movl $strong_preemptable_global, %eax
78; CHECK32: movl strong_preemptable_global@GOT(%eax), %eax
79
80@weak_preemptable_global = weak dso_preemptable global i32 42
81define i32* @get_weak_preemptable_global() {
82  ret i32* @weak_preemptable_global
83}
84; CHECK: movq weak_preemptable_global@GOTPCREL(%rip), %rax
85; STATIC: movl $weak_preemptable_global, %eax
86; CHECK32: movl weak_preemptable_global@GOT(%eax), %eax
87
88@external_preemptable_global = external dso_preemptable global i32
89define i32* @get_external_preemptable_global() {
90  ret i32* @external_preemptable_global
91}
92; CHECK: movq external_preemptable_global@GOTPCREL(%rip), %rax
93; STATIC: movq external_preemptable_global@GOTPCREL(%rip), %rax
94; CHECK32: movl external_preemptable_global@GOT(%eax), %eax
95
96; aliases
97@aliasee = global i32 42
98
99@strong_default_alias = alias i32, i32* @aliasee
100define i32* @get_strong_default_alias() {
101  ret i32* @strong_default_alias
102}
103; CHECK: movq strong_default_alias@GOTPCREL(%rip), %rax
104; STATIC: movl $strong_default_alias, %eax
105; CHECK32: movl strong_default_alias@GOT(%eax), %eax
106
107@strong_hidden_alias = hidden alias i32, i32* @aliasee
108define i32* @get_strong_hidden_alias() {
109  ret i32* @strong_hidden_alias
110}
111; CHECK: leaq strong_hidden_alias(%rip), %rax
112; STATIC: movl $strong_hidden_alias, %eax
113; CHECK32: leal strong_hidden_alias@GOTOFF(%eax), %eax
114
115@weak_default_alias = weak alias i32, i32* @aliasee
116define i32* @get_weak_default_alias() {
117  ret i32* @weak_default_alias
118}
119; CHECK: movq weak_default_alias@GOTPCREL(%rip), %rax
120; STATIC: movl $weak_default_alias, %eax
121; CHECK32: movl weak_default_alias@GOT(%eax), %eax
122
123@strong_local_alias = dso_local alias i32, i32* @aliasee
124define i32* @get_strong_local_alias() {
125  ret i32* @strong_local_alias
126}
127; CHECK: leaq .Lstrong_local_alias$local(%rip), %rax
128; STATIC: movl $strong_local_alias, %eax
129; CHECK32: leal .Lstrong_local_alias$local@GOTOFF(%eax), %eax
130
131@weak_local_alias = weak dso_local alias i32, i32* @aliasee
132define i32* @get_weak_local_alias() {
133  ret i32* @weak_local_alias
134}
135; CHECK: leaq weak_local_alias(%rip), %rax
136; STATIC: movl $weak_local_alias, %eax
137; CHECK32: leal weak_local_alias@GOTOFF(%eax), %eax
138
139
140@strong_preemptable_alias = dso_preemptable alias i32, i32* @aliasee
141define i32* @get_strong_preemptable_alias() {
142  ret i32* @strong_preemptable_alias
143}
144; CHECK: movq strong_preemptable_alias@GOTPCREL(%rip), %rax
145; STATIC: movl $strong_preemptable_alias, %eax
146; CHECK32: movl strong_preemptable_alias@GOT(%eax), %eax
147
148@weak_preemptable_alias = weak dso_preemptable alias i32, i32* @aliasee
149define i32* @get_weak_preemptable_alias() {
150  ret i32* @weak_preemptable_alias
151}
152; CHECK: movq weak_preemptable_alias@GOTPCREL(%rip), %rax
153; STATIC: movl $weak_preemptable_alias, %eax
154; CHECK32: movl weak_preemptable_alias@GOT(%eax), %eax
155
156; functions
157
158define void @strong_default_function() {
159  ret void
160}
161define void()* @get_strong_default_function() {
162  ret void()* @strong_default_function
163}
164; CHECK: movq strong_default_function@GOTPCREL(%rip), %rax
165; STATIC: movl $strong_default_function, %eax
166; CHECK32: movl strong_default_function@GOT(%eax), %eax
167
168define hidden void @strong_hidden_function() {
169  ret void
170}
171define void()* @get_strong_hidden_function() {
172  ret void()* @strong_hidden_function
173}
174; CHECK: leaq strong_hidden_function(%rip), %rax
175; STATIC: movl $strong_hidden_function, %eax
176; CHECK32: leal strong_hidden_function@GOTOFF(%eax), %eax
177
178define weak void @weak_default_function() {
179  ret void
180}
181define void()* @get_weak_default_function() {
182  ret void()* @weak_default_function
183}
184; CHECK: movq weak_default_function@GOTPCREL(%rip), %rax
185; STATIC: movl $weak_default_function, %eax
186; CHECK32: movl weak_default_function@GOT(%eax), %eax
187
188declare void @external_default_function()
189define void()* @get_external_default_function() {
190  ret void()* @external_default_function
191}
192; CHECK: movq external_default_function@GOTPCREL(%rip), %rax
193; STATIC: movq external_default_function@GOTPCREL(%rip), %rax
194; CHECK32: movl external_default_function@GOT(%eax), %eax
195
196define dso_local void @strong_local_function() {
197  ret void
198}
199define void()* @get_strong_local_function() {
200  ret void()* @strong_local_function
201}
202; COMMON:     {{^}}strong_local_function:
203; CHECK-NEXT: .Lstrong_local_function$local:
204; CHECK: leaq .Lstrong_local_function$local(%rip), %rax
205; STATIC: movl $strong_local_function, %eax
206; CHECK32: leal .Lstrong_local_function$local@GOTOFF(%eax), %eax
207
208define weak dso_local void @weak_local_function() {
209  ret void
210}
211define void()* @get_weak_local_function() {
212  ret void()* @weak_local_function
213}
214; CHECK: leaq weak_local_function(%rip), %rax
215; STATIC: movl $weak_local_function, %eax
216; CHECK32: leal weak_local_function@GOTOFF(%eax), %eax
217
218declare dso_local void @external_local_function()
219define void()* @get_external_local_function() {
220  ret void()* @external_local_function
221}
222; CHECK: leaq external_local_function(%rip), %rax
223; STATIC: movl $external_local_function, %eax
224; CHECK32: leal external_local_function@GOTOFF(%eax), %eax
225
226
227define dso_preemptable void @strong_preemptable_function() {
228  ret void
229}
230define void()* @get_strong_preemptable_function() {
231  ret void()* @strong_preemptable_function
232}
233; CHECK: movq strong_preemptable_function@GOTPCREL(%rip), %rax
234; STATIC: movl $strong_preemptable_function, %eax
235; CHECK32: movl strong_preemptable_function@GOT(%eax), %eax
236
237define weak dso_preemptable void @weak_preemptable_function() {
238  ret void
239}
240define void()* @get_weak_preemptable_function() {
241  ret void()* @weak_preemptable_function
242}
243; CHECK: movq weak_preemptable_function@GOTPCREL(%rip), %rax
244; STATIC: movl $weak_preemptable_function, %eax
245; CHECK32: movl weak_preemptable_function@GOT(%eax), %eax
246
247declare dso_preemptable void @external_preemptable_function()
248define void()* @get_external_preemptable_function() {
249  ret void()* @external_preemptable_function
250}
251; CHECK: movq external_preemptable_function@GOTPCREL(%rip), %rax
252; STATIC: movq external_preemptable_function@GOTPCREL(%rip), %rax
253; CHECK32: movl external_preemptable_function@GOT(%eax), %eax
254
255!llvm.module.flags = !{!0}
256!0 = !{i32 7, !"PIC Level", i32 2}
257
258; COMMON:     {{^}}strong_local_global:
259; CHECK-NEXT: .Lstrong_local_global$local:
260
261; COMMON:      .globl strong_default_alias
262; COMMON-NEXT: .set strong_default_alias, aliasee
263; COMMON-NEXT: .globl strong_hidden_alias
264; COMMON-NEXT: .hidden strong_hidden_alias
265; COMMON-NEXT: .set strong_hidden_alias, aliasee
266; COMMON-NEXT: .weak weak_default_alias
267; COMMON-NEXT: .set weak_default_alias, aliasee
268; COMMON-NEXT: .globl strong_local_alias
269; COMMON-NEXT: .set strong_local_alias, aliasee
270; CHECK-NEXT:  .set .Lstrong_local_alias$local, aliasee
271; COMMON-NEXT: .weak weak_local_alias
272; COMMON-NEXT: .set weak_local_alias, aliasee
273; COMMON-NEXT: .globl strong_preemptable_alias
274; COMMON-NEXT: .set strong_preemptable_alias, aliasee
275; COMMON-NEXT: .weak weak_preemptable_alias
276; COMMON-NEXT: .set weak_preemptable_alias, aliasee
277