reloc-jalr.ll
7.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic -mips-tail-calls=1 \
; RUN: -O2 < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-32,JALR-32R2,TAILCALL-32R2
; RUN: llc -mtriple=mips64-linux-gnu -relocation-model=pic -mips-tail-calls=1 \
; RUN: -O2 < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-64,JALR-64R2,TAILCALL-64R2
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic -mips-tail-calls=1 \
; RUN: -O2 -mcpu=mips32r6 -mips-compact-branches=always < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-32,JALR-32R6,TAILCALL-32R6
; RUN: llc -mtriple=mips64-linux-gnu -relocation-model=pic -mips-tail-calls=1 \
; RUN: -O2 -mcpu=mips64r6 -mips-compact-branches=always < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-64,JALR-64R6,TAILCALL-64R6
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic -mips-tail-calls=1 \
; RUN: -O2 -mcpu=mips32r6 -mips-compact-branches=never < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-32,JALR-32R2,TAILCALL-32R2
; RUN: llc -mtriple=mips64-linux-gnu -relocation-model=pic -mips-tail-calls=1 \
; RUN: -O2 -mcpu=mips64r6 -mips-compact-branches=never < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-64,JALR-64R2,TAILCALL-64R2
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic -mips-tail-calls=1 \
; RUN: -O2 -mattr=+micromips -mcpu=mips32r2 < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-MM,TAILCALL-MM
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic -mips-tail-calls=1 \
; RUN: -O2 -mattr=+micromips -mcpu=mips32r6 < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-MM,TAILCALL-MM
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic \
; RUN: -O0 < %s | FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-32,JALR-32R2,PIC-NOTAILCALL-R2
; RUN: llc -mtriple=mips64-linux-gnu -relocation-model=pic \
; RUN: -O0 < %s | FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-64,JALR-64R2,PIC-NOTAILCALL-R2
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic \
; RUN: -O0 -mcpu=mips32r6 -mips-compact-branches=always < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-32,JALR-32R6,PIC-NOTAILCALL-R6
; RUN: llc -mtriple=mips64-linux-gnu -relocation-model=pic \
; RUN: -O0 -mcpu=mips64r6 -mips-compact-branches=always < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-64,JALR-64R6,PIC-NOTAILCALL-R6
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic \
; RUN: -O0 -mcpu=mips32r6 -mips-compact-branches=never < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-32,JALR-32R2,PIC-NOTAILCALL-R2
; RUN: llc -mtriple=mips64-linux-gnu -relocation-model=pic \
; RUN: -O0 -mcpu=mips64r6 -mips-compact-branches=never < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-64,JALR-64R2,PIC-NOTAILCALL-R2
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic \
; RUN: -O0 -mattr=+micromips -mcpu=mips32r2 < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-MM,PIC-NOTAILCALL-MM
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic \
; RUN: -O0 -mattr=+micromips -mcpu=mips32r6 < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,JALR-ALL,JALR-MM,PIC-NOTAILCALL-MM
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic -mips-tail-calls=1 \
; RUN: -O2 -mips-jalr-reloc=false < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,NORELOC
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=static -mips-tail-calls=1 \
; RUN: -O2 < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,NORELOC
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=pic -mips-tail-calls=1 \
; RUN: -O0 -mips-jalr-reloc=false < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,NORELOC
; RUN: llc -mtriple=mips-linux-gnu -relocation-model=static -mips-tail-calls=1 \
; RUN: -O0 < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,NORELOC
; RUN: llc -mtriple=mips64-linux-gnu -relocation-model=pic -mips-tail-calls=1 \
; RUN: -O2 -mips-jalr-reloc=false < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,NORELOC
; RUN: llc -mtriple=mips64-linux-gnu -mips-tail-calls=1 \
; RUN: -O2 -relocation-model=static < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,NORELOC
; RUN: llc -mtriple=mips64-linux-gnu -relocation-model=pic \
; RUN: -O0 -mips-jalr-reloc=false < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,NORELOC
; RUN: llc -mtriple=mips64-linux-gnu -relocation-model=static \
; RUN: -O0 < %s | \
; RUN: FileCheck %s -check-prefixes=ALL,NORELOC
define internal void @foo() noinline {
entry:
ret void
}
define void @checkCall() {
entry:
; ALL-LABEL: checkCall:
; ALL-NOT: MIPS_JALR
call void @foo()
; JALR-32: .reloc ([[TMPLABEL:\$.+]]), R_MIPS_JALR, foo
; JALR-64: .reloc [[TMPLABEL:\..+]], R_MIPS_JALR, foo
; JALR-MM: .reloc ([[TMPLABEL:\$.+]]), R_MICROMIPS_JALR, foo
; JALR-ALL-NEXT: [[TMPLABEL]]:
; JALR-32R2-NEXT: jalr $25
; JALR-64R2-NEXT: jalr $25
; JALR-32R6-NEXT: jalrc $25
; JALR-64R6-NEXT: jalrc $25
; JALR-MM-NEXT: jalr $25
; ALL-NOT: MIPS_JALR
ret void
}
define void @checkTailCall() {
entry:
; ALL-LABEL: checkTailCall:
; ALL-NOT: MIPS_JALR
tail call void @foo()
; JALR-32: .reloc ([[TMPLABEL:\$.+]]), R_MIPS_JALR, foo
; JALR-64: .reloc [[TMPLABEL:\..+]], R_MIPS_JALR, foo
; JALR-MM: .reloc ([[TMPLABEL:\$.+]]), R_MICROMIPS_JALR, foo
; JALR-ALL-NEXT: [[TMPLABEL]]:
; TAILCALL-32R2-NEXT: jr $25
; TAILCALL-64R2-NEXT: jr $25
; TAILCALL-MM-NEXT: jrc $25
; TAILCALL-32R6-NEXT: jrc $25
; TAILCALL-64R6-NEXT: jrc $25
; PIC-NOTAILCALL-R2-NEXT: jalr $25
; PIC-NOTAILCALL-R6-NEXT: jalrc $25
; PIC-NOTAILCALL-MM-NEXT: jalr $25
; ALL-NOT: MIPS_JALR
ret void
}
; Check that we don't emit R_MIPS_JALR relocations against function pointers.
; This resulted in run-time crashes until lld was modified to ignore
; R_MIPS_JALR relocations against data symbols (commit 5bab291b7b).
; However, the better approach is to not emit these relocations in the first
; place so check that we no longer emit them.
; Previously we were adding them for local dynamic TLS function pointers and
; function pointers with internal linkage.
@fnptr_internal = internal global void()* @checkFunctionPointerCall
@fnptr_internal_const = internal constant void()* @checkFunctionPointerCall
@fnptr_const = constant void()* @checkFunctionPointerCall
@fnptr_global = global void()* @checkFunctionPointerCall
define void @checkFunctionPointerCall() {
entry:
; ALL-LABEL: checkFunctionPointerCall:
; ALL-NOT: MIPS_JALR
%func_internal = load void()*, void()** @fnptr_internal
call void %func_internal()
%func_internal_const = load void()*, void()** @fnptr_internal_const
call void %func_internal_const()
%func_const = load void()*, void()** @fnptr_const
call void %func_const()
%func_global = load void()*, void()** @fnptr_global
call void %func_global()
ret void
}
@tls_fnptr_gd = thread_local global void()* @checkTlsFunctionPointerCall
@tls_fnptr_ld = thread_local(localdynamic) global void()* @checkTlsFunctionPointerCall
@tls_fnptr_ie = thread_local(initialexec) global void()* @checkTlsFunctionPointerCall
@tls_fnptr_le = thread_local(localexec) global void()* @checkTlsFunctionPointerCall
define void @checkTlsFunctionPointerCall() {
entry:
; There should not be any *JALR relocations in this function other than the
; calls to __tls_get_addr:
; ALL-LABEL: checkTlsFunctionPointerCall:
; ALL-NOT: MIPS_JALR
; JALR-ALL: .reloc {{.+}}MIPS_JALR, __tls_get_addr
; ALL-NOT: MIPS_JALR
; JALR-ALL: .reloc {{.+}}MIPS_JALR, __tls_get_addr
; ALL-NOT: _MIPS_JALR
%func_gd = load void()*, void()** @tls_fnptr_gd
call void %func_gd()
%func_ld = load void()*, void()** @tls_fnptr_ld
call void %func_ld()
%func_ie = load void()*, void()** @tls_fnptr_ie
call void %func_ie()
%func_le = load void()*, void()** @tls_fnptr_le
call void %func_le()
ret void
}