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