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@weak_default_global = weak global i32 42
24define i32* @get_weak_default_global() {
25  ret i32* @weak_default_global
26}
27; CHECK: movq weak_default_global@GOTPCREL(%rip), %rax
28; STATIC: movl $weak_default_global, %eax
29; CHECK32: movl weak_default_global@GOT(%eax), %eax
30
31@external_default_global = external global i32
32define i32* @get_external_default_global() {
33  ret i32* @external_default_global
34}
35; CHECK: movq external_default_global@GOTPCREL(%rip), %rax
36; STATIC: movl $external_default_global, %eax
37; CHECK32: movl external_default_global@GOT(%eax), %eax
38
39@strong_local_global = dso_local global i32 42
40define i32* @get_strong_local_global() {
41  ret i32* @strong_local_global
42}
43; CHECK: leaq .Lstrong_local_global$local(%rip), %rax
44; STATIC: movl $.Lstrong_local_global$local, %eax
45; CHECK32: leal .Lstrong_local_global$local@GOTOFF(%eax), %eax
46
47@weak_local_global = weak dso_local global i32 42
48define i32* @get_weak_local_global() {
49  ret i32* @weak_local_global
50}
51; CHECK: leaq weak_local_global(%rip), %rax
52; STATIC: movl $weak_local_global, %eax
53; CHECK32: leal weak_local_global@GOTOFF(%eax), %eax
54
55@external_local_global = external dso_local global i32
56define i32* @get_external_local_global() {
57  ret i32* @external_local_global
58}
59; CHECK: leaq external_local_global(%rip), %rax
60; STATIC: movl $external_local_global, %eax
61; CHECK32: leal external_local_global@GOTOFF(%eax), %eax
62
63
64@strong_preemptable_global = dso_preemptable global i32 42
65define i32* @get_strong_preemptable_global() {
66  ret i32* @strong_preemptable_global
67}
68; CHECK: movq strong_preemptable_global@GOTPCREL(%rip), %rax
69; STATIC: movl $strong_preemptable_global, %eax
70; CHECK32: movl strong_preemptable_global@GOT(%eax), %eax
71
72@weak_preemptable_global = weak dso_preemptable global i32 42
73define i32* @get_weak_preemptable_global() {
74  ret i32* @weak_preemptable_global
75}
76; CHECK: movq weak_preemptable_global@GOTPCREL(%rip), %rax
77; STATIC: movl $weak_preemptable_global, %eax
78; CHECK32: movl weak_preemptable_global@GOT(%eax), %eax
79
80@external_preemptable_global = external dso_preemptable global i32
81define i32* @get_external_preemptable_global() {
82  ret i32* @external_preemptable_global
83}
84; CHECK: movq external_preemptable_global@GOTPCREL(%rip), %rax
85; STATIC: movl $external_preemptable_global, %eax
86; CHECK32: movl external_preemptable_global@GOT(%eax), %eax
87
88; aliases
89@aliasee = global i32 42
90
91@strong_default_alias = alias i32, i32* @aliasee
92define i32* @get_strong_default_alias() {
93  ret i32* @strong_default_alias
94}
95; CHECK: movq strong_default_alias@GOTPCREL(%rip), %rax
96; STATIC: movl $strong_default_alias, %eax
97; CHECK32: movl strong_default_alias@GOT(%eax), %eax
98
99@weak_default_alias = weak alias i32, i32* @aliasee
100define i32* @get_weak_default_alias() {
101  ret i32* @weak_default_alias
102}
103; CHECK: movq weak_default_alias@GOTPCREL(%rip), %rax
104; STATIC: movl $weak_default_alias, %eax
105; CHECK32: movl weak_default_alias@GOT(%eax), %eax
106
107@strong_local_alias = dso_local alias i32, i32* @aliasee
108define i32* @get_strong_local_alias() {
109  ret i32* @strong_local_alias
110}
111; CHECK: leaq .Lstrong_local_alias$local(%rip), %rax
112; STATIC: movl $.Lstrong_local_alias$local, %eax
113; CHECK32: leal .Lstrong_local_alias$local@GOTOFF(%eax), %eax
114
115@weak_local_alias = weak dso_local alias i32, i32* @aliasee
116define i32* @get_weak_local_alias() {
117  ret i32* @weak_local_alias
118}
119; CHECK: leaq weak_local_alias(%rip), %rax
120; STATIC: movl $weak_local_alias, %eax
121; CHECK32: leal weak_local_alias@GOTOFF(%eax), %eax
122
123
124@strong_preemptable_alias = dso_preemptable alias i32, i32* @aliasee
125define i32* @get_strong_preemptable_alias() {
126  ret i32* @strong_preemptable_alias
127}
128; CHECK: movq strong_preemptable_alias@GOTPCREL(%rip), %rax
129; STATIC: movl $strong_preemptable_alias, %eax
130; CHECK32: movl strong_preemptable_alias@GOT(%eax), %eax
131
132@weak_preemptable_alias = weak dso_preemptable alias i32, i32* @aliasee
133define i32* @get_weak_preemptable_alias() {
134  ret i32* @weak_preemptable_alias
135}
136; CHECK: movq weak_preemptable_alias@GOTPCREL(%rip), %rax
137; STATIC: movl $weak_preemptable_alias, %eax
138; CHECK32: movl weak_preemptable_alias@GOT(%eax), %eax
139
140; functions
141
142define void @strong_default_function() {
143  ret void
144}
145define void()* @get_strong_default_function() {
146  ret void()* @strong_default_function
147}
148; CHECK: movq strong_default_function@GOTPCREL(%rip), %rax
149; STATIC: movl $strong_default_function, %eax
150; CHECK32: movl strong_default_function@GOT(%eax), %eax
151
152define weak void @weak_default_function() {
153  ret void
154}
155define void()* @get_weak_default_function() {
156  ret void()* @weak_default_function
157}
158; CHECK: movq weak_default_function@GOTPCREL(%rip), %rax
159; STATIC: movl $weak_default_function, %eax
160; CHECK32: movl weak_default_function@GOT(%eax), %eax
161
162declare void @external_default_function()
163define void()* @get_external_default_function() {
164  ret void()* @external_default_function
165}
166; CHECK: movq external_default_function@GOTPCREL(%rip), %rax
167; STATIC: movl $external_default_function, %eax
168; CHECK32: movl external_default_function@GOT(%eax), %eax
169
170define dso_local void @strong_local_function() {
171  ret void
172}
173define void()* @get_strong_local_function() {
174  ret void()* @strong_local_function
175}
176; COMMON:     {{^}}strong_local_function:
177; COMMON-NEXT: .Lstrong_local_function$local:
178; CHECK: leaq .Lstrong_local_function$local(%rip), %rax
179; STATIC: movl $.Lstrong_local_function$local, %eax
180; CHECK32: leal .Lstrong_local_function$local@GOTOFF(%eax), %eax
181
182define weak dso_local void @weak_local_function() {
183  ret void
184}
185define void()* @get_weak_local_function() {
186  ret void()* @weak_local_function
187}
188; CHECK: leaq weak_local_function(%rip), %rax
189; STATIC: movl $weak_local_function, %eax
190; CHECK32: leal weak_local_function@GOTOFF(%eax), %eax
191
192declare dso_local void @external_local_function()
193define void()* @get_external_local_function() {
194  ret void()* @external_local_function
195}
196; CHECK: leaq external_local_function(%rip), %rax
197; STATIC: movl $external_local_function, %eax
198; CHECK32: leal external_local_function@GOTOFF(%eax), %eax
199
200
201define dso_preemptable void @strong_preemptable_function() {
202  ret void
203}
204define void()* @get_strong_preemptable_function() {
205  ret void()* @strong_preemptable_function
206}
207; CHECK: movq strong_preemptable_function@GOTPCREL(%rip), %rax
208; STATIC: movl $strong_preemptable_function, %eax
209; CHECK32: movl strong_preemptable_function@GOT(%eax), %eax
210
211define weak dso_preemptable void @weak_preemptable_function() {
212  ret void
213}
214define void()* @get_weak_preemptable_function() {
215  ret void()* @weak_preemptable_function
216}
217; CHECK: movq weak_preemptable_function@GOTPCREL(%rip), %rax
218; STATIC: movl $weak_preemptable_function, %eax
219; CHECK32: movl weak_preemptable_function@GOT(%eax), %eax
220
221declare dso_preemptable void @external_preemptable_function()
222define void()* @get_external_preemptable_function() {
223  ret void()* @external_preemptable_function
224}
225; CHECK: movq external_preemptable_function@GOTPCREL(%rip), %rax
226; STATIC: movl $external_preemptable_function, %eax
227; CHECK32: movl external_preemptable_function@GOT(%eax), %eax
228
229; COMMON:     {{^}}strong_local_global:
230; COMMON-NEXT: .Lstrong_local_global$local:
231
232; COMMON:      .globl strong_default_alias
233; COMMON-NEXT: .set strong_default_alias, aliasee
234; COMMON-NEXT: .weak weak_default_alias
235; COMMON-NEXT: .set weak_default_alias, aliasee
236; COMMON-NEXT: .globl strong_local_alias
237; COMMON-NEXT: .set strong_local_alias, aliasee
238; COMMON-NEXT: .set .Lstrong_local_alias$local, aliasee
239; COMMON-NEXT: .weak weak_local_alias
240; COMMON-NEXT: .set weak_local_alias, aliasee
241; COMMON-NEXT: .globl strong_preemptable_alias
242; COMMON-NEXT: .set strong_preemptable_alias, aliasee
243; COMMON-NEXT: .weak weak_preemptable_alias
244; COMMON-NEXT: .set weak_preemptable_alias, aliasee
245