]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-mips-elf/mips-elf.exp
MIPS/LD/testsuite: Make Linux dumps for n64 GOT relocation tests the default
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-mips-elf / mips-elf.exp
1 # Expect script for MIPS ELF linker tests
2 # Copyright (C) 2002-2018 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21
22 if {[istarget "mips*-*-vxworks"]} {
23 set mipsvxtests {
24 {"VxWorks shared library test 1" "-shared -Tvxworks1.ld" ""
25 "-mips2" {vxworks1-lib.s}
26 {{readelf --relocs vxworks1-lib.rd} {objdump -dr vxworks1-lib.dd}
27 {readelf --symbols vxworks1-lib.nd} {readelf -d vxworks1-lib.td}}
28 "libvxworks1.so"}
29 {"VxWorks executable test 1 (dynamic)" \
30 "tmpdir/libvxworks1.so -Tvxworks1.ld -q --force-dynamic" ""
31 "-mips2" {vxworks1.s}
32 {{readelf --relocs vxworks1.rd} {objdump -dr vxworks1.dd}}
33 "vxworks1"}
34 {"VxWorks executable test 2 (dynamic)" \
35 "-Tvxworks1.ld -q --force-dynamic" ""
36 "-mips2" {vxworks2.s}
37 {{readelf --segments vxworks2.sd}}
38 "vxworks2"}
39 {"VxWorks executable test 2 (static)"
40 "-Tvxworks1.ld" ""
41 "-mips2" {vxworks2.s}
42 {{readelf --segments vxworks2-static.sd}}
43 "vxworks2"}
44 }
45 run_ld_link_tests $mipsvxtests
46 run_dump_test "vxworks1-static"
47 run_dump_test "vxworks-forced-local-1"
48 return
49 }
50
51 if {![istarget mips*-*-*] || ![is_elf_format]} {
52 return
53 }
54
55 set has_newabi [expr [istarget *-*-irix6*] \
56 || [istarget mips*-*-linux*] \
57 || [istarget mips*-sde-elf*] \
58 || [istarget mips*-mti-elf*] \
59 || [istarget mips*-img-elf*]]
60 set has_elf32 [expr ![istarget *-*-openbsd*]]
61 set irix [expr [istarget *-*-irix*]]
62 set linux_gnu [expr [istarget mips*-*-linux*]]
63 set embedded_elf [expr [istarget mips*-*-elf]]
64
65 # Set defaults.
66 set abi_asflags(o32) "-32"
67 set abi_asflags(n32) "-march=from-abi -n32 -EB"
68 set abi_asflags(n64) "-march=from-abi -64 -EB"
69 set abi_ldflags(o32) ""
70 set abi_ldflags(n32) -melf32bmipn32
71 set abi_ldflags(n64) -melf64bmip
72
73 # Override as needed.
74 if { [istarget *-*-irix6*] } {
75 set abi_asflags(o32) "-32 -EB"
76 set abi_ldflags(o32) -melf32bsmip
77 } elseif { [istarget mips64*-linux*] } {
78 set abi_asflags(o32) "-32 -EB"
79 set abi_ldflags(o32) -melf32btsmip
80 } elseif { [istarget mips64*-*freebsd*] } {
81 set abi_asflags(o32) "-32 -EB"
82 set abi_ldflags(o32) -melf32btsmip_fbsd
83 }
84 if { [istarget mips*-*-linux*] || [istarget mips*-sde-elf*]
85 || [istarget mips*-mti-elf*] || [istarget mips*-img-elf*]} {
86 set abi_ldflags(n32) -melf32btsmipn32
87 set abi_ldflags(n64) -melf64btsmip
88 } elseif { [istarget mips64*-*freebsd*] } {
89 set abi_ldflags(n32) -melf32btsmipn32_fbsd
90 set abi_ldflags(n64) -melf64btsmip_fbsd
91 }
92
93 if { $linux_gnu } {
94 run_ld_link_tests [list \
95 [list "Dummy shared library for MIPS16 PIC test 1" \
96 "-shared -melf32btsmip" "" \
97 "-EB -32 -mips1" \
98 { mips16-pic-1-dummy.s } \
99 {} \
100 "mips16-pic-1-dummy.so"] \
101 [list "MIPS16 PIC test 1" \
102 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-1-dummy.so" "" \
103 "-EB -32 -mips1 -I $srcdir/$subdir" \
104 { mips16-pic-1a.s mips16-pic-1b.s } \
105 { { objdump { -dr -j.text } mips16-pic-1.dd }
106 { readelf -A mips16-pic-1.gd } } \
107 "mips16-pic-1"] \
108 [list "MIPS16 PIC test 2" \
109 "-melf32btsmip -T mips16-pic-1.ld -shared" "" \
110 "-EB -32 -mips1 -I $srcdir/$subdir" \
111 { mips16-pic-2a.s mips16-pic-2b.s } \
112 { { objdump { -dr -j.text } mips16-pic-2.dd } \
113 { readelf -A mips16-pic-2.gd } \
114 { readelf --symbols mips16-pic-2.nd } \
115 { readelf --relocs mips16-pic-2.rd } \
116 { readelf -d mips16-pic-2.ad } } \
117 "mips16-pic-2"] \
118 [list "MIPS16 PIC test 3" \
119 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-1-dummy.so" "" \
120 "-EB -32 -mips1 -I $srcdir/$subdir" \
121 { mips16-pic-3a.s mips16-pic-3b.s } \
122 { { objdump -dr mips16-pic-3.dd } \
123 { readelf --relocs mips16-pic-3.rd } \
124 { readelf -A mips16-pic-3.gd } } \
125 "mips16-pic-3"] \
126 [list "MIPS16 PIC test 4 (shared library)" \
127 "-shared -melf32btsmip -T mips16-pic-1.ld --version-script mips16-pic-4.ver" "" \
128 "-EB -32 -mips1" \
129 { mips16-pic-4a.s mips16-pic-4b.s } \
130 { { objdump -dr mips16-pic-4a.dd } \
131 { readelf --symbols mips16-pic-4a.nd } \
132 { readelf -A mips16-pic-4a.gd } } \
133 "mips16-pic-4.so"] \
134 [list "MIPS16 PIC test 4 (executable)" \
135 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-4.so" "" \
136 "-EB -32 -mips1" \
137 { mips16-pic-4c.s } \
138 { { objdump -dr mips16-pic-4b.dd } } \
139 "mips16-pic-4"]]
140 }
141
142 # Check MIPS16 markings being passed through link.
143 run_dump_test "mips16-1"
144
145 # MIPS branch offset final link checking.
146 run_dump_test "branch-misc-1"
147 run_dump_test "branch-misc-2"
148 run_dump_test "branch-absolute" [list [list ld $abi_ldflags(o32)]]
149 run_dump_test "branch-absolute-addend" [list [list ld $abi_ldflags(o32)]]
150 if $has_newabi {
151 run_dump_test "branch-absolute-n32" [list [list ld $abi_ldflags(n32)]]
152 run_dump_test "branch-absolute-addend-n32" \
153 [list [list ld $abi_ldflags(n32)]]
154 run_dump_test "branch-absolute-n64" [list [list ld $abi_ldflags(n64)]]
155 run_dump_test "branch-absolute-addend-n64" \
156 [list [list ld $abi_ldflags(n64)]]
157 }
158
159 run_dump_test "mips16-pcrel-0" [list [list ld $abi_ldflags(o32)]]
160 run_dump_test "mips16-pcrel-1" [list [list ld $abi_ldflags(o32)]]
161 run_dump_test "mips16e2-pcrel-0" [list [list ld $abi_ldflags(o32)]]
162 run_dump_test "mips16e2-pcrel-1" [list [list ld $abi_ldflags(o32)]]
163 run_dump_test "mips16-pcrel-addend-2" [list [list ld $abi_ldflags(o32)]]
164 run_dump_test "mips16-pcrel-addend-6" [list [list ld $abi_ldflags(o32)]]
165 run_dump_test "mips16e2-pcrel-addend-2" [list [list ld $abi_ldflags(o32)]]
166 run_dump_test "mips16e2-pcrel-addend-6" [list [list ld $abi_ldflags(o32)]]
167 if $has_newabi {
168 run_dump_test "mips16-pcrel-n32-0" [list [list ld $abi_ldflags(n32)]]
169 run_dump_test "mips16-pcrel-n32-1" [list [list ld $abi_ldflags(n32)]]
170 run_dump_test "mips16-pcrel-n64-sym32-0" [list [list ld $abi_ldflags(n64)]]
171 run_dump_test "mips16-pcrel-n64-sym32-1" [list [list ld $abi_ldflags(n64)]]
172 run_dump_test "mips16e2-pcrel-n32-0" [list [list ld $abi_ldflags(n32)]]
173 run_dump_test "mips16e2-pcrel-n32-1" [list [list ld $abi_ldflags(n32)]]
174 run_dump_test "mips16e2-pcrel-n64-sym32-0" \
175 [list [list ld $abi_ldflags(n64)]]
176 run_dump_test "mips16e2-pcrel-n64-sym32-1" \
177 [list [list ld $abi_ldflags(n64)]]
178 }
179
180 run_dump_test "mips16-branch-2" [list [list ld $abi_ldflags(o32)]]
181 run_dump_test "mips16-branch-3" [list [list ld $abi_ldflags(o32)]]
182 run_dump_test "mips16-branch-addend-2" [list [list ld $abi_ldflags(o32)]]
183 run_dump_test "mips16-branch-addend-3" [list [list ld $abi_ldflags(o32)]]
184 run_dump_test "mips16-branch-absolute" [list [list ld $abi_ldflags(o32)]]
185 run_dump_test "mips16-branch-absolute-1" [list [list ld $abi_ldflags(o32)]]
186 run_dump_test "mips16-branch-absolute-2" [list [list ld $abi_ldflags(o32)]]
187 run_dump_test "mips16-branch-absolute-addend" \
188 [list [list ld $abi_ldflags(o32)]]
189 run_dump_test "mips16-branch-absolute-addend-1" \
190 [list [list ld $abi_ldflags(o32)]]
191 if $has_newabi {
192 run_dump_test "mips16-branch-absolute-n32" \
193 [list [list ld $abi_ldflags(n32)]]
194 run_dump_test "mips16-branch-absolute-n32-1" \
195 [list [list ld $abi_ldflags(n32)]]
196 run_dump_test "mips16-branch-absolute-n32-2" \
197 [list [list ld $abi_ldflags(n32)]]
198 run_dump_test "mips16-branch-absolute-addend-n32" \
199 [list [list ld $abi_ldflags(n32)]]
200 run_dump_test "mips16-branch-absolute-addend-n32-1" \
201 [list [list ld $abi_ldflags(n32)]]
202 run_dump_test "mips16-branch-absolute-n64" \
203 [list [list ld $abi_ldflags(n64)]]
204 run_dump_test "mips16-branch-absolute-n64-1" \
205 [list [list ld $abi_ldflags(n64)]]
206 run_dump_test "mips16-branch-absolute-n64-2" \
207 [list [list ld $abi_ldflags(n64)]]
208 run_dump_test "mips16-branch-absolute-addend-n64" \
209 [list [list ld $abi_ldflags(n64)]]
210 run_dump_test "mips16-branch-absolute-addend-n64-1" \
211 [list [list ld $abi_ldflags(n64)]]
212 }
213
214 run_dump_test "micromips-branch-absolute" [list [list ld $abi_ldflags(o32)]]
215 run_dump_test "micromips-branch-absolute-addend" \
216 [list [list ld $abi_ldflags(o32)]]
217 if $has_newabi {
218 run_dump_test "micromips-branch-absolute-n32" \
219 [list [list ld $abi_ldflags(n32)]]
220 run_dump_test "micromips-branch-absolute-addend-n32" \
221 [list [list ld $abi_ldflags(n32)]]
222 run_dump_test "micromips-branch-absolute-n64" \
223 [list [list ld $abi_ldflags(n64)]]
224 run_dump_test "micromips-branch-absolute-addend-n64" \
225 [list [list ld $abi_ldflags(n64)]]
226 }
227
228 # Jalx test
229 run_dump_test "jalx-1"
230
231 if { $linux_gnu } {
232 run_ld_link_tests [list \
233 [list "Dummy shared library for JALX test 2" \
234 "-shared -nostdlib -melf32btsmip" "" \
235 "-G0 -EB -mmicromips -no-mdebug -mabi=32 -march=mips32r2 -KPIC" \
236 { jalx-2-printf.s } \
237 {} \
238 "libjalx-2.so"] \
239 [list "Dummy external function for JALX test 2" \
240 "-r -melf32btsmip" "" \
241 "-G0 -EB -no-mdebug -mabi=32 -march=mips32r2 -mno-shared -call_nonpic" \
242 { jalx-2-ex.s } \
243 {} \
244 "jalx-2-ex.o.r"] \
245 [list "MIPS JALX test 2" \
246 "-nostdlib -T jalx-2.ld tmpdir/libjalx-2.so tmpdir/jalx-2-ex.o.r -melf32btsmip" "" \
247 "-G0 -EB -mmicromips -no-mdebug -mabi=32 -march=mips32r2 -mno-shared -call_nonpic" \
248 { jalx-2-main.s } \
249 { { objdump -d jalx-2.dd } } \
250 "jalx-2"]]
251 }
252
253 run_dump_test "jalx-addend" [list [list ld $abi_ldflags(o32)]]
254 run_dump_test "jalx-local" [list [list ld $abi_ldflags(o32)]]
255 run_dump_test "bal-jalx-addend" [list [list ld $abi_ldflags(o32)]]
256 run_dump_test "bal-jalx-addend-micromips" [list [list ld $abi_ldflags(o32)]]
257 run_dump_test "bal-jalx-local" [list [list ld $abi_ldflags(o32)]]
258 run_dump_test "bal-jalx-local-micromips" [list [list ld $abi_ldflags(o32)]]
259 run_dump_test "bal-jalx-pic" [list [list ld $abi_ldflags(o32)]]
260 run_dump_test "bal-jalx-pic-micromips" [list [list ld $abi_ldflags(o32)]]
261 run_dump_test "bal-jalx-pic-ignore" [list [list ld $abi_ldflags(o32)]]
262 run_dump_test "bal-jalx-pic-ignore-micromips" \
263 [list [list ld $abi_ldflags(o32)]]
264 if $has_newabi {
265 run_dump_test "jalx-addend-n32" [list [list ld $abi_ldflags(n32)]]
266 run_dump_test "jalx-local-n32" [list [list ld $abi_ldflags(n32)]]
267 run_dump_test "bal-jalx-addend-n32" [list [list ld $abi_ldflags(n32)]]
268 run_dump_test "bal-jalx-addend-micromips-n32" \
269 [list [list ld $abi_ldflags(n32)]]
270 run_dump_test "bal-jalx-local-n32" [list [list ld $abi_ldflags(n32)]]
271 run_dump_test "bal-jalx-local-micromips-n32" \
272 [list [list ld $abi_ldflags(n32)]]
273 run_dump_test "bal-jalx-pic-n32" [list [list ld $abi_ldflags(n32)]]
274 run_dump_test "bal-jalx-pic-micromips-n32" \
275 [list [list ld $abi_ldflags(n32)]]
276 run_dump_test "bal-jalx-pic-ignore-n32" [list [list ld $abi_ldflags(n32)]]
277 run_dump_test "bal-jalx-pic-ignore-micromips-n32" \
278 [list [list ld $abi_ldflags(n32)]]
279 run_dump_test "jalx-addend-n64" [list [list ld $abi_ldflags(n64)]]
280 run_dump_test "jalx-local-n64" [list [list ld $abi_ldflags(n64)]]
281 run_dump_test "bal-jalx-addend-n64" [list [list ld $abi_ldflags(n64)]]
282 run_dump_test "bal-jalx-addend-micromips-n64" \
283 [list [list ld $abi_ldflags(n64)]]
284 run_dump_test "bal-jalx-local-n64" [list [list ld $abi_ldflags(n64)]]
285 run_dump_test "bal-jalx-local-micromips-n64" \
286 [list [list ld $abi_ldflags(n64)]]
287 run_dump_test "bal-jalx-pic-n64" [list [list ld $abi_ldflags(n64)]]
288 run_dump_test "bal-jalx-pic-micromips-n64" \
289 [list [list ld $abi_ldflags(n64)]]
290 run_dump_test "bal-jalx-pic-ignore-n64" [list [list ld $abi_ldflags(n64)]]
291 run_dump_test "bal-jalx-pic-ignore-micromips-n64" \
292 [list [list ld $abi_ldflags(n64)]]
293 }
294
295 run_dump_test "unaligned-jalx-0" [list [list ld $abi_ldflags(o32)]]
296 run_dump_test "unaligned-jalx-1" [list [list ld $abi_ldflags(o32)]]
297 run_dump_test "unaligned-jalx-2" [list [list ld $abi_ldflags(o32)]]
298 run_dump_test "unaligned-jalx-3" [list [list ld $abi_ldflags(o32)]]
299 run_dump_test "unaligned-jalx-mips16-0" [list [list ld $abi_ldflags(o32)]]
300 run_dump_test "unaligned-jalx-mips16-1" [list [list ld $abi_ldflags(o32)]]
301 run_dump_test "unaligned-jalx-micromips-0" [list [list ld $abi_ldflags(o32)]]
302 run_dump_test "unaligned-jalx-micromips-1" [list [list ld $abi_ldflags(o32)]]
303
304 if $has_newabi {
305 run_dump_test "unaligned-jalx-addend-0" \
306 [list [list ld $abi_ldflags(n32)]]
307 run_dump_test "unaligned-jalx-addend-1" \
308 [list [list ld $abi_ldflags(n32)]]
309 run_dump_test "unaligned-jalx-addend-2" \
310 [list [list ld $abi_ldflags(n32)]]
311 run_dump_test "unaligned-jalx-addend-3" \
312 [list [list ld $abi_ldflags(n32)]]
313 run_dump_test "unaligned-jalx-addend-mips16-0" \
314 [list [list ld $abi_ldflags(n32)]]
315 run_dump_test "unaligned-jalx-addend-mips16-1" \
316 [list [list ld $abi_ldflags(n32)]]
317 run_dump_test "unaligned-jalx-addend-micromips-0" \
318 [list [list ld $abi_ldflags(n32)]]
319 run_dump_test "unaligned-jalx-addend-micromips-1" \
320 [list [list ld $abi_ldflags(n32)]]
321 }
322
323 run_dump_test "unaligned-branch" [list [list ld $abi_ldflags(o32)]]
324
325 if $has_newabi {
326 run_dump_test "unaligned-branch-2" \
327 [list [list ld $abi_ldflags(n32)]]
328 run_dump_test "unaligned-branch-ignore-2" \
329 [list [list ld $abi_ldflags(n32)]]
330 run_dump_test "unaligned-branch-r6-1" \
331 [list [list ld $abi_ldflags(n32)]]
332 run_dump_test "unaligned-branch-ignore-r6-1" \
333 [list [list ld $abi_ldflags(n32)]]
334 run_dump_test "unaligned-branch-r6-2" \
335 [list [list ld $abi_ldflags(n32)]]
336 run_dump_test "unaligned-branch-mips16" \
337 [list [list ld $abi_ldflags(n32)]]
338 run_dump_test "unaligned-branch-ignore-mips16" \
339 [list [list ld $abi_ldflags(n32)]]
340 run_dump_test "unaligned-branch-micromips" \
341 [list [list ld $abi_ldflags(n32)]]
342 run_dump_test "unaligned-branch-ignore-micromips" \
343 [list [list ld $abi_ldflags(n32)]]
344 run_dump_test "unaligned-jump" \
345 [list [list ld $abi_ldflags(n32)]]
346 run_dump_test "unaligned-jump-mips16" \
347 [list [list ld $abi_ldflags(n32)]]
348 run_dump_test "unaligned-jump-micromips" \
349 [list [list ld $abi_ldflags(n32)]]
350 }
351
352 run_dump_test "unaligned-lwpc-0" [list [list ld $abi_ldflags(o32)]]
353 run_dump_test "unaligned-lwpc-1" [list [list ld $abi_ldflags(o32)]]
354 run_dump_test "unaligned-ldpc-0" [list [list ld $abi_ldflags(o32)]]
355 run_dump_test "unaligned-ldpc-1" [list [list ld $abi_ldflags(o32)]]
356
357 # Test multi-got link. We only do this on GNU/Linux because it requires
358 # the "traditional" emulations.
359 if { $linux_gnu } {
360 run_dump_test "multi-got-1"
361 run_dump_test "multi-got-no-shared"
362 run_dump_test "multi-got-hidden-1"
363 run_dump_test "multi-got-hidden-2"
364 }
365
366 # Test __gnu_local_gp accesses
367 if { $linux_gnu } {
368 run_dump_test "no-shared-1-o32"
369 if { $has_newabi } {
370 run_dump_test "no-shared-1-n32"
371 run_dump_test "no-shared-1-n64"
372 }
373 }
374
375 # Test PIE debug dynamic tags
376 if { $linux_gnu } {
377 run_dump_test "pie-o32"
378 if { $has_newabi } {
379 run_dump_test "pie-n32"
380 run_dump_test "pie-n64"
381 }
382 }
383
384 if $has_newabi {
385 if { $embedded_elf } {
386 run_dump_test "elf-rel-got-n32-embed" \
387 [list [list ld $abi_ldflags(n32)]]
388 run_dump_test "elf-rel-xgot-n32-embed" \
389 [list [list ld $abi_ldflags(n32)]]
390 } else {
391 run_dump_test "elf-rel-got-n32" [list [list ld $abi_ldflags(n32)]]
392 run_dump_test "elf-rel-xgot-n32" [list [list ld $abi_ldflags(n32)]]
393 }
394 if { $irix } {
395 run_dump_test "elf-rel-got-n64-irix" \
396 [list [list ld $abi_ldflags(n64)]]
397 run_dump_test "elf-rel-xgot-n64-irix" \
398 [list [list ld $abi_ldflags(n64)]]
399 } elseif { $embedded_elf } {
400 run_dump_test "elf-rel-got-n64-embed" \
401 [list [list ld $abi_ldflags(n64)]]
402 run_dump_test "elf-rel-xgot-n64-embed" \
403 [list [list ld $abi_ldflags(n64)]]
404 } else {
405 run_dump_test "elf-rel-got-n64" [list [list ld $abi_ldflags(n64)]]
406 run_dump_test "elf-rel-xgot-n64" [list [list ld $abi_ldflags(n64)]]
407 }
408
409 run_dump_test "relax-jalr-n32"
410 run_dump_test "relax-jalr-n32-shared"
411 run_dump_test "relax-jalr-n64"
412 run_dump_test "relax-jalr-n64-shared"
413 }
414
415 if { $linux_gnu } {
416 run_dump_test "rel32-o32"
417 if { $has_newabi } {
418 run_dump_test "rel32-n32"
419 run_dump_test "rel64"
420 }
421 # The first test checks that a mixed PIC/non-PIC relocatable link
422 # will not introduce any stubs itself, but will flag PIC functions
423 # for the final link.
424 #
425 # The second test checks that we insert stubs for calls from
426 # non-PIC functions to PIC functions when linking the original
427 # two objects together.
428 #
429 # The third test checks that we do the same when linking the
430 # result of the first link (with no other source files).
431 #
432 # We then repeat the same three tests for microMIPS stubs.
433 run_ld_link_tests {
434 {"PIC and non-PIC test 1 (relocatable)" "-r -melf32btsmip" ""
435 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
436 {{objdump -dr pic-and-nonpic-1-rel.dd}
437 {readelf --symbols pic-and-nonpic-1-rel.nd}}
438 "pic-and-nonpic-1-rel.o"}
439 {"PIC and non-PIC test 1 (static 1)"
440 "-melf32btsmip -Tpic-and-nonpic-1.ld" ""
441 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
442 {{objdump -dr pic-and-nonpic-1.dd}
443 {readelf --symbols pic-and-nonpic-1.nd}}
444 "pic-and-nonpic-1-static1.o"}
445 {"PIC and non-PIC test 1 (static 2)"
446 "-melf32btsmip -Tpic-and-nonpic-1.ld tmpdir/pic-and-nonpic-1-rel.o" ""
447 "" {}
448 {{objdump -dr pic-and-nonpic-1.dd}
449 {readelf --symbols pic-and-nonpic-1.nd}}
450 "pic-and-nonpic-1-static2.o"}
451 {"PIC and non-PIC test 1, microMIPS (relocatable)"
452 "-r -melf32btsmip" ""
453 "-32 -EB -mips2"
454 {pic-and-nonpic-1a-micromips.s pic-and-nonpic-1b-micromips.s}
455 {{objdump -dr pic-and-nonpic-1-micromips-rel.dd}
456 {readelf --symbols pic-and-nonpic-1-micromips-rel.nd}}
457 "pic-and-nonpic-1-micromips-rel.o"}
458 {"PIC and non-PIC test 1, microMIPS (static 1)"
459 "-melf32btsmip -Tpic-and-nonpic-1.ld" ""
460 "-32 -EB -mips2"
461 {pic-and-nonpic-1a-micromips.s pic-and-nonpic-1b-micromips.s}
462 {{objdump -dr pic-and-nonpic-1-micromips.dd}
463 {readelf --symbols pic-and-nonpic-1-micromips.nd}}
464 "pic-and-nonpic-1-micromips-static1.o"}
465 }
466 # The final executable produced with the following test is supposed
467 # to be the same as one produced with the preceding test, however
468 # as noted in PR ld/20453 it is not. Consequently output from
469 # `objdump -dr' is not the same either. Expect:
470 #
471 # regexp_diff match failure
472 # regexp "^ 4103c: f001 0415 jalx 41054 <f3>$"
473 # line " 4103c: f001 0400 jalx 41000 <.pic.f3>"
474 #
475 # from the test below due to this problem.
476 setup_kfail "mips*-*-*" "ld/20453"
477 # The final check below should be folded into the `run_ld_link_tests'
478 # call above once `setup_kfail' has been removed.
479 run_ld_link_tests {
480 {"PIC and non-PIC test 1, microMIPS (static 2)"
481 "-melf32btsmip -Tpic-and-nonpic-1.ld \
482 tmpdir/pic-and-nonpic-1-micromips-rel.o" ""
483 "" {}
484 {{objdump -dr pic-and-nonpic-1-micromips.dd}
485 {readelf --symbols pic-and-nonpic-1-micromips.nd}}
486 "pic-and-nonpic-1-micromips-static2.o"}
487 }
488 run_dump_test "pic-and-nonpic-2"
489 run_ld_link_tests {
490 {"PIC and non-PIC test 3 (shared library)"
491 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld" ""
492 "-32 -EB -mips2" {pic-and-nonpic-3a.s}
493 {{readelf --segments pic-and-nonpic-3a.sd}
494 {readelf -A pic-and-nonpic-3a.gd}
495 {objdump -dr pic-and-nonpic-3a.dd}}
496 "pic-and-nonpic-3a.so"}
497 {"PIC and non-PIC test 3 (executable)"
498 "-melf32btsmip -Tpic-and-nonpic-3b.ld tmpdir/pic-and-nonpic-3a.so" ""
499 "-32 -EB -mips2" {pic-and-nonpic-3b.s}
500 {{readelf --segments pic-and-nonpic-3b.sd}
501 {objdump -dr pic-and-nonpic-3b.dd}
502 {objdump {-s -j.got.plt} pic-and-nonpic-3b.pd}
503 {readelf -A pic-and-nonpic-3b.gd}
504 {readelf --relocs pic-and-nonpic-3b.rd}
505 {readelf --symbols pic-and-nonpic-3b.nd}
506 {readelf -d pic-and-nonpic-3b.ad}}
507 "pic-and-nonpic-3b"}
508 }
509 run_dump_test "pic-and-nonpic-3-error"
510 run_ld_link_tests {
511 {"PIC and non-PIC test 4 (shared library)"
512 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld" ""
513 "-32 -EB -mips2" {pic-and-nonpic-4a.s}
514 {}
515 "pic-and-nonpic-4a.so"}
516 {"PIC and non-PIC test 4 (executable)"
517 "-melf32btsmip -Tpic-and-nonpic-4b.ld tmpdir/pic-and-nonpic-4a.so" ""
518 "-32 -EB -mips2" {pic-and-nonpic-4b.s}
519 {{readelf --segments pic-and-nonpic-4b.sd}
520 {objdump -dr pic-and-nonpic-4b.dd}
521 {objdump {-s -j.got -j.data} pic-and-nonpic-4b.gd}
522 {readelf --relocs pic-and-nonpic-4b.rd}
523 {readelf --symbols pic-and-nonpic-4b.nd}
524 {readelf -d pic-and-nonpic-4b.ad}}
525 "pic-and-nonpic-4b"}
526 }
527 run_dump_test "pic-and-nonpic-4-error"
528 run_ld_link_tests {
529 {"PIC and non-PIC test 5 (executable)"
530 "-melf32btsmip -Tpic-and-nonpic-5b.ld tmpdir/pic-and-nonpic-3a.so tmpdir/pic-and-nonpic-4a.so" ""
531 "-32 -EB -mips2" {pic-and-nonpic-5a.s pic-and-nonpic-5b.s}
532 {{readelf --segments pic-and-nonpic-5b.sd}
533 {objdump -dr pic-and-nonpic-5b.dd}
534 {objdump {-s -j.got.plt -j.data} pic-and-nonpic-5b.pd}
535 {readelf -A pic-and-nonpic-5b.gd}
536 {readelf --relocs pic-and-nonpic-5b.rd}
537 {readelf --symbols pic-and-nonpic-5b.nd}
538 {readelf -d pic-and-nonpic-5b.ad}}
539 "pic-and-nonpic-5b"}
540 }
541 set abis { o32 -32 elf32btsmip }
542 if $has_newabi {
543 lappend abis n32 -n32 elf32btsmipn32
544 lappend abis n64 -64 elf64btsmip
545 }
546 foreach { abi flag emul } $abis {
547 run_ld_link_tests [list \
548 [list "PIC and non-PIC test 6 ($abi shared library)" \
549 "-m$emul -shared -Tpic-and-nonpic-3a.ld" "" \
550 "$flag -EB -mips3" \
551 [list "pic-and-nonpic-6-${abi}a.s"] {} \
552 "pic-and-nonpic-6-${abi}.so"] \
553 [list "PIC and non-PIC test 6 ($abi executable)" \
554 "-m$emul -Tpic-and-nonpic-6.ld tmpdir/pic-and-nonpic-6-${abi}.so" "" \
555 "$flag -EB -mips3" \
556 [list "pic-and-nonpic-6-${abi}b.s" \
557 "pic-and-nonpic-6-${abi}c.s"] \
558 [list "readelf {--wide --segments} pic-and-nonpic-6-${abi}.sd" \
559 "objdump -dr pic-and-nonpic-6-${abi}.dd" \
560 "objdump {-s -j.got.plt} pic-and-nonpic-6-${abi}.pd" \
561 "readelf -A pic-and-nonpic-6-${abi}.gd" \
562 "readelf --relocs pic-and-nonpic-6-${abi}.rd" \
563 "readelf --symbols pic-and-nonpic-6-${abi}.nd" \
564 "readelf -d pic-and-nonpic-6-${abi}.ad"] \
565 "pic-and-nonpic-6-${abi}"]]
566
567 # This checks whether our linker scripts get the scope of _gp right,
568 # and must therefore use default scripts. If they don't, then -- in
569 # addition to dumps failing to match -- the final link fails with:
570 #
571 # ld: gp-hidden.o: undefined reference to symbol '_gp'
572 # ld: note: '_gp' is defined in DSO ./tmpdir/gp-hidden-lib-${abi}.so
573 # so try adding it to the linker command line
574 #
575 set suff64 [string map {o32 "" n32 "" n64 -64} $abi]
576 run_ld_link_tests [list \
577 [list \
578 "_gp scope test ($abi shared library)" \
579 "$abi_ldflags($abi) -shared" "" \
580 "$abi_asflags($abi) -KPIC" \
581 { gp-hidden-lib.s } \
582 [list \
583 "readelf --relocs gp-hidden-lib${suff64}.rd" \
584 "readelf --syms gp-hidden.sd"] \
585 "gp-hidden-lib-${abi}.so"] \
586 [list \
587 "_gp scope test ($abi versioned library)" \
588 "$abi_ldflags($abi) -shared -version-script gp-hidden-ver.ver tmpdir/gp-hidden-lib-${abi}.so" "" \
589 "$abi_asflags($abi) -KPIC" \
590 { gp-hidden-ver.s } \
591 [list \
592 "readelf --relocs gp-hidden-ver${suff64}.rd" \
593 "readelf --syms gp-hidden.sd"] \
594 "gp-hidden-ver-${abi}.so"] \
595 [list \
596 "_gp scope test ($abi executable)" \
597 "$abi_ldflags($abi) -e 0 -rpath-link . tmpdir/gp-hidden-ver-${abi}.so" "" \
598 "$abi_asflags($abi) -call_nonpic" \
599 { gp-hidden.s } \
600 [list \
601 "readelf --relocs gp-hidden${suff64}.rd" \
602 "readelf --syms gp-hidden.sd"] \
603 "gp-hidden-${abi}"]]
604 }
605 }
606
607 if { $embedded_elf } {
608 run_dump_test "region1"
609 }
610
611 if $embedded_elf {
612 # This could work on other targets too, but would need the appropriate
613 # ld -m switch.
614 run_dump_test "reloc-1-rel"
615 }
616 if $has_newabi {
617 run_dump_test "reloc-1-n32" [list [list ld $abi_ldflags(n32)]]
618 run_dump_test "reloc-1-n64" [list [list ld $abi_ldflags(n64)]]
619 }
620 run_dump_test "reloc-2"
621 run_dump_test "reloc-merge-lo16"
622 run_dump_test "reloc-3"
623 if {$has_newabi} {
624 run_dump_test "reloc-3-n32"
625 }
626 run_dump_test "reloc-4"
627 run_dump_test "reloc-5"
628 if { $has_newabi } {
629 run_ld_link_tests [list \
630 [list \
631 "reloc test 6a" \
632 "-shared $abi_ldflags(n32)" "" \
633 "$abi_asflags(n32)" \
634 "reloc-6a.s" \
635 {} \
636 "reloc-6a.so"] \
637 [list \
638 "reloc test 6b" \
639 "$abi_ldflags(n32) tmpdir/reloc-6a.so" "" \
640 "$abi_asflags(n32)" \
641 "reloc-6b.s" \
642 {} \
643 "reloc-6b"]]
644 }
645
646 run_dump_test "reloc-local-overflow" [list [list ld $abi_ldflags(o32)]]
647 run_ld_link_tests [list \
648 [list \
649 "MIPS link ELF o32 PIC comdat GOT16/LO16 relocation pairing" \
650 "$abi_ldflags(o32) -e bar" "" "$abi_asflags(o32) -mno-pdr" \
651 "../../../gas/testsuite/gas/mips/comdat-reloc.s" \
652 {} \
653 "comdat-reloc"]]
654
655 if {$has_newabi && $linux_gnu} {
656 run_dump_test "eh-frame1-n32"
657 run_dump_test "eh-frame1-n64"
658 run_dump_test "eh-frame2-n32"
659 run_dump_test "eh-frame2-n64"
660 }
661 if {$embedded_elf} {
662 run_dump_test "eh-frame3"
663 run_dump_test "eh-frame4"
664 }
665 if {$linux_gnu} {
666 set eh_frame5_test {
667 {"MIPS eh-frame 5"
668 "-melf32btsmip -shared -Teh-frame5.ld" ""
669 "-32 -EB"
670 {eh-frame5.s}
671 {{readelf {--relocs -wf} eh-frame5.d}}
672 "eh-frame5.so"}
673 }
674 run_ld_link_tests $eh_frame5_test
675 }
676
677 if {$embedded_elf} {
678 run_dump_test "compact-eh1"
679 run_dump_test "compact-eh2"
680 run_dump_test "compact-eh3"
681 }
682
683 if {$linux_gnu} {
684 run_dump_test "compact-eh4"
685 run_dump_test "compact-eh5"
686 run_dump_test "compact-eh6"
687 }
688
689 run_dump_test "jaloverflow"
690 run_dump_test "jaloverflow-2"
691
692 run_dump_test "jal-global-overflow-0" [list [list ld $abi_ldflags(o32)]]
693 run_dump_test "jal-global-overflow-1" [list [list ld $abi_ldflags(o32)]]
694 run_dump_test "jal-local-overflow-0" [list [list ld $abi_ldflags(o32)]]
695 run_dump_test "jal-local-overflow-1" [list [list ld $abi_ldflags(o32)]]
696
697 run_dump_test "undefweak-overflow" [list [list as $abi_asflags(o32)] \
698 [list ld $abi_ldflags(o32)]]
699
700 if {$has_newabi} {
701 run_dump_test "undefweak-overflow" [list [list name (n32)] \
702 [list as $abi_asflags(n32)] \
703 [list ld $abi_ldflags(n32)]]
704 run_dump_test "undefweak-overflow" [list [list name (n64)] \
705 [list as $abi_asflags(n64)] \
706 [list ld $abi_ldflags(n64)]]
707 }
708
709 if {$has_newabi} {
710 run_dump_test "jalbal" [list [list ld $abi_ldflags(n32)]]
711 }
712
713 run_dump_test "mode-change-error-1"
714
715 run_dump_test "mips16-hilo"
716 if {$has_newabi} {
717 run_dump_test "mips16-hilo-n32"
718 }
719
720 if { $linux_gnu } {
721 if { $has_newabi } {
722 run_dump_test "textrel-1"
723 }
724 run_dump_test "got-page-1"
725 if $has_newabi {
726 run_dump_test "got-page-2"
727 run_dump_test "dyn-sec64"
728 }
729 run_dump_test "got-page-3"
730 run_ld_link_tests [subst {
731 {"GOT page 4 (one file)" "-shared $abi_ldflags(o32) -T got-page-1.ld"
732 "" "$abi_asflags(o32) -mips2" {got-page-4b.s}
733 {{objdump -dr got-page-4a.d}
734 {readelf -A got-page-4a.got}}
735 "got-page-4a.so"}
736 {"GOT page 4 (two files)" "-shared $abi_ldflags(o32) -T got-page-1.ld"
737 "" "$abi_asflags(o32) -mips2" {got-page-4a.s got-page-4b.s}
738 {{objdump -dr got-page-4b.d}
739 {readelf -A got-page-4b.got}}
740 "got-page-4b.so"}
741 }]
742 if $has_newabi {
743 run_ld_link_tests [subst {
744 {"GOT page 5" "-shared $abi_ldflags(n32) -T got-page-1.ld"
745 "" "$abi_asflags(n32)" {got-page-5.s}
746 {{objdump -dr got-page-5.d}
747 {readelf -A got-page-5.got}}
748 "got-page-5.so"}
749 {"GOT page 6" "-shared $abi_ldflags(n32) -T got-page-1.ld"
750 "" "$abi_asflags(n32)" {got-page-6.s}
751 {{objdump -dr got-page-6.d}
752 {readelf -A got-page-6.got}}
753 "got-page-6.so"}
754 {"GOT page 7 (order 1)" "-shared $abi_ldflags(n32) -T got-page-1.ld"
755 "" "$abi_asflags(n32)"
756 {got-page-7a.s got-page-7b.s got-page-7c.s got-page-7d.s
757 got-page-7e.s}
758 {{objdump -dr got-page-7.d}
759 {readelf -A got-page-7.got}}
760 "got-page-7a.so"}
761 {"GOT page 7 (order 2)" "-shared $abi_ldflags(n32) -T got-page-1.ld"
762 "" "$abi_asflags(n32)"
763 {got-page-7e.s got-page-7a.s got-page-7b.s got-page-7c.s
764 got-page-7d.s}
765 {{objdump -dr got-page-7.d}
766 {readelf -A got-page-7.got}}
767 "got-page-7b.so"}
768 }]
769 }
770 run_dump_test "got-dump-1"
771 if $has_newabi {
772 run_dump_test "got-dump-2"
773 }
774 run_dump_test "reloc-estimate-1"
775 }
776
777 if $has_newabi {
778 run_dump_test "emit-relocs-1"
779 }
780
781 run_dump_test "hash1a"
782 run_dump_test "hash1b"
783 run_dump_test "hash1c"
784
785 if { $linux_gnu } {
786 # The number of symbols that are always included in the symbol table
787 # for these tests.
788 # the null symbol entry
789 set base_syms 1
790 foreach { isa aflag lflag suffix } \
791 { MIPS -march=mips1 "" "" \
792 microMIPS -mmicromips "" -micromips \
793 "microMIPS insn32" "-mmicromips -minsn32" --insn32 \
794 -micromips-insn32 } {
795 foreach dynsym { 7fff 8000 fff0 10000 2fe80 } {
796 run_ld_link_tests \
797 [list [list \
798 "Stub for dynsym 0x$dynsym ($isa)" \
799 "-shared -melf32btsmip -T stub-dynsym-1.ld $lflag" \
800 "" \
801 [concat \
802 "-EB $aflag -32 -KPIC" \
803 "--defsym base_syms=$base_syms" \
804 "--defsym dynsym=0x$dynsym"] \
805 [list "stub-dynsym-1.s"] \
806 [list [list \
807 "objdump" "-dz" \
808 "stub-dynsym$suffix-1-$dynsym.d"]] \
809 "stub-dynsym$suffix-1-$dynsym"]]
810 }
811 run_ld_link_tests [list \
812 [list \
813 "Retained stubs for dynsyms ($isa)" \
814 "-shared -melf32btsmip -T stub-dynsym-2.ld $lflag" "" \
815 "-EB $aflag -32 -KPIC" \
816 [list "stub-dynsym-2.s"] \
817 [list \
818 [list \
819 "objdump" \
820 "-dz -j .MIPS.stubs" \
821 "stub-dynsym$suffix-2.dd"] \
822 [list \
823 "readelf" \
824 "--dyn-syms" \
825 "stub-dynsym$suffix-2.sd"] \
826 [list \
827 "readelf" \
828 "-A" \
829 "stub-dynsym$suffix-2.gd"]] \
830 "stub-dynsym$suffix-2"] \
831 [list \
832 "Discarded stubs for dynsyms ($isa)" \
833 "-shared -melf32btsmip -T stub-dynsym-discard-2.ld $lflag" \
834 "" \
835 "-EB $aflag -32 -KPIC" \
836 [list "stub-dynsym-2.s"] \
837 [list \
838 [list \
839 "readelf" \
840 "--dyn-syms" \
841 "stub-dynsym-discard-2.sd"] \
842 [list \
843 "readelf" \
844 "-A" \
845 "stub-dynsym-discard-2.gd"]] \
846 "stub-dynsym-discard$suffix-2"]]
847 }
848 }
849
850 # For tests which may involve multiple files, use run_ld_link_tests.
851
852 # List contains test-items with 3 items followed by 2 lists:
853 # 0:name 1:ld early options 2:ld late options 3:assembler options
854 # 4:filenames of assembler files 5: action and options. 6: name of output file
855
856 # Actions:
857 # objdump: Apply objdump options on result. Compare with regex (last arg).
858 # nm: Apply nm options on result. Compare with regex (last arg).
859 # readelf: Apply readelf options on result. Compare with regex (last arg).
860
861 set mips_tls_tests {
862 {"Static executable with TLS" "-static -melf32btsmip -T mips-dyn.ld" ""
863 "-EB -march=mips1 -32 -KPIC" {tlsbin-o32.s}
864 {{objdump {-dr -m mips:isa32r2} tlsbin-o32.d} {objdump -srj.got tlsbin-o32.got}}
865 "tls-static-o32"}
866 {"Shared library with TLS" "-shared -melf32btsmip -T mips-lib.ld" ""
867 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
868 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32.got}}
869 "tlslib-o32.so"}
870 {"Dynamic executable with TLS"
871 "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32.so" ""
872 "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s}
873 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32.d} {objdump -Rsj.got tlsdyn-o32.got}}
874 "tls-dynamic-o32"}
875 {"Shared library with multiple GOTs and TLS"
876 "-shared -melf32btsmip -T mips-lib.ld" ""
877 "-EB -march=mips1 -32 -KPIC" {tls-multi-got-1-1.s tls-multi-got-1-2.s}
878 {{readelf {-d -r} tls-multi-got-1.r}
879 {objdump {-dr -m mips:isa32r2} tls-multi-got-1.d}
880 {objdump -Rsj.got tls-multi-got-1.got}}
881 "tlslib-multi.so"}
882 {"Shared library with TLS and versioning"
883 "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib.ver" ""
884 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
885 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-ver.got}}
886 "tlslib-o32-ver.so"}
887 {"Dynamic executable with TLS and versioning"
888 "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32-ver.so" ""
889 "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s tlsdyn-o32-2.s}
890 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-1.d} {objdump -Rsj.got tlsdyn-o32-1.got}}
891 "tls-dynamic-o32-ver"}
892 {"Dynamic executable with TLS and versioning (order 2)"
893 "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32-2.o" ""
894 "-EB -march=mips1 -32 -KPIC" {}
895 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-2.d} {objdump -Rsj.got tlsdyn-o32-2.got}}
896 "tls-dynamic-o32-ver-2"}
897 {"Dynamic executable with TLS and versioning (order 3)"
898 "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32-2.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32.o" ""
899 "-EB -march=mips1 -32 -KPIC" {}
900 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-3.d} {objdump -Rsj.got tlsdyn-o32-3.got}}
901 "tls-dynamic-o32-ver-3"}
902 {"Shared library with TLS and hidden symbols"
903 "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib-hidden.ver" ""
904 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
905 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-hidden.got}}
906 "tlslib-o32-hidden.so"}
907 {"Shared library with TLS and hidden symbols (2)"
908 "-shared -melf32btsmip -T mips-lib.ld" ""
909 "-EB -march=mips1 -32 -KPIC" {tls-hidden2a.s tls-hidden2b.s}
910 {{objdump -drj.text tls-hidden2.d} {objdump -sj.got tls-hidden2-got.d}}
911 "tls-hidden2.so"}
912 {"Shared library with TLS and hidden symbols (3)"
913 "-shared -melf32btsmip -T tls-hidden3.ld" ""
914 "-EB -march=mips2 -32 -KPIC" {tls-hidden3a.s tls-hidden3b.s}
915 {{objdump -dj.text tls-hidden3.d} {objdump -sj.got tls-hidden3.got}
916 {readelf --relocs tls-hidden3.r}}
917 "tls-hidden3.so"}
918 {"Shared library with TLS and hidden symbols (4)"
919 "-shared -melf32btsmip -T tls-hidden3.ld" ""
920 "-EB -march=mips2 -32 -KPIC" {tls-hidden4a.s tls-hidden4b.s}
921 {{objdump -sj.got tls-hidden4.got} {readelf --relocs tls-hidden4.r}}
922 "tls-hidden4.so"}
923 }
924
925 if { $linux_gnu } {
926 run_ld_link_tests $mips_tls_tests
927 }
928
929 set mips16_call_global_test [list \
930 [list "Global calls from mips16" \
931 "$abi_ldflags(o32) -T no-shared-1.ld" "" \
932 "$abi_asflags(o32) -mips32r2" \
933 {mips16-call-global-1.s mips16-call-global-2.s mips16-call-global-3.s} \
934 {{objdump -dr mips16-call-global.d}} \
935 "mips16-call-global"]]
936
937 run_ld_link_tests $mips16_call_global_test
938
939 set mips16_intermix_test [list \
940 [list "Intermixing mips32 and mips16 functions" \
941 "$abi_ldflags(o32)" "" \
942 "$abi_asflags(o32) -mips32r2" \
943 {mips16-intermix-1.s mips16-intermix-2.s} \
944 {{objdump -t mips16-intermix.d}} \
945 "mips16-intermix"]]
946
947 run_ld_link_tests $mips16_intermix_test
948
949 run_dump_test "mips16-local-stubs-1"
950
951 set mips16_fp_stub_test [list \
952 [list "Floating-point stub for mips16 functions" \
953 "$abi_ldflags(o32)" "" \
954 "$abi_asflags(o32) -mips32r2" \
955 {mips16-fp-stub-1.s mips16-fp-stub-2.s} \
956 {{readelf --debug-dump=frames mips16-fp-stub.d}} \
957 "mips16-fp-stub"]]
958
959 run_ld_link_tests $mips16_fp_stub_test
960
961 set o32flagslist [list [list as $abi_asflags(o32)] [list ld $abi_ldflags(o32)]]
962
963 foreach firstfpabi [list 0 1 2 3 4 5 6 7 ] {
964 foreach secondfpabi [list 4 5 6 7 ] {
965 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}" $o32flagslist
966 }
967 }
968 foreach firstfpabi [list 4 5 6 7 ] {
969 foreach secondfpabi [list 0 1 2 3 8 9] {
970 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}" $o32flagslist
971 }
972 }
973 foreach firstfpabi [list 0 1 2 3 ] {
974 foreach secondfpabi [list 0 1 2 3 8 9] {
975 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}"
976 }
977 }
978
979 run_dump_test "attr-gnu-4-81"
980
981 run_dump_test "attr-gnu-8-00"
982 run_dump_test "attr-gnu-8-01"
983 run_dump_test "attr-gnu-8-02"
984 run_dump_test "attr-gnu-8-10"
985 run_dump_test "attr-gnu-8-11"
986 run_dump_test "attr-gnu-8-12"
987 run_dump_test "attr-gnu-8-20"
988 run_dump_test "attr-gnu-8-21"
989 run_dump_test "attr-gnu-8-22"
990
991 run_dump_test "attr-gnu-4-0-ph" $o32flagslist
992 run_dump_test "attr-gnu-4-1-ph" $o32flagslist
993 run_dump_test "attr-gnu-4-2-ph" $o32flagslist
994 run_dump_test "attr-gnu-4-3-ph" $o32flagslist
995 run_dump_test "attr-gnu-4-4-ph" $o32flagslist
996 run_dump_test "attr-gnu-4-5-ph" $o32flagslist
997 run_dump_test "attr-gnu-4-6-ph" $o32flagslist
998 run_dump_test "attr-gnu-4-7-ph" $o32flagslist
999
1000 if $has_newabi {
1001 run_dump_test "attr-gnu-4-0-n32-ph"
1002 run_dump_test "attr-gnu-4-1-n32-ph"
1003 run_dump_test "attr-gnu-4-2-n32-ph"
1004 run_dump_test "attr-gnu-4-3-n32-ph"
1005 run_dump_test "attr-gnu-4-0-n64-ph"
1006 run_dump_test "attr-gnu-4-1-n64-ph"
1007 run_dump_test "attr-gnu-4-2-n64-ph"
1008 run_dump_test "attr-gnu-4-3-n64-ph"
1009 }
1010
1011 run_dump_test "abiflags-strip1-ph" $o32flagslist
1012 run_dump_test "abiflags-strip2-ph" $o32flagslist
1013 run_dump_test "abiflags-strip3-ph" $o32flagslist
1014 run_dump_test "abiflags-strip4-ph" $o32flagslist
1015 run_dump_test "abiflags-strip5-ph" $o32flagslist
1016 run_dump_test "abiflags-strip6-ph" $o32flagslist
1017 run_dump_test "abiflags-strip7-ph" $o32flagslist
1018 run_dump_test "abiflags-strip8-ph" $o32flagslist
1019 run_dump_test "abiflags-strip9-ph" $o32flagslist
1020 run_dump_test "abiflags-strip10-ph" $o32flagslist
1021
1022 run_dump_test "nan-legacy"
1023 run_dump_test "nan-2008"
1024 run_dump_test "nan-mixed-1"
1025 run_dump_test "nan-mixed-2"
1026
1027 if { $linux_gnu } {
1028 run_ld_link_tests {
1029 {"GOT and versioning 1"
1030 "-shared -melf32btsmip --version-script got-vers-1.ver" ""
1031 "-EB -mips2 -32" {got-vers-1a.s got-vers-1b.s}
1032 {{readelf -d got-vers-1.dd}
1033 {readelf --symbols got-vers-1.sd}
1034 {readelf --relocs got-vers-1.rd}}
1035 "got-vers-1.so"}
1036 }
1037 }
1038
1039 run_dump_test "undefined"
1040 run_dump_test "undefined-warn"
1041
1042 # Test the conversion from jr to b
1043 if { $linux_gnu } {
1044 run_dump_test "jr-to-b-1"
1045 run_dump_test "jr-to-b-2"
1046 }
1047
1048 # MIPS16 and microMIPS interlinking test.
1049 run_dump_test "mips16-and-micromips"
1050
1051 # Export class call relocation tests.
1052 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
1053 foreach { abi } $abis {
1054 set loadaddr [string map \
1055 {o32 0x12340000 n32 0x12340000 n64 0x123456789abc0000} $abi]
1056 set suff [subst \
1057 [expr { $irix \
1058 ? [string map {o32 o32-irix n32 n32 n64 n64} $abi] \
1059 : $abi }]]
1060 run_ld_link_tests [list \
1061 [list \
1062 "MIPS export class call relocation test ($abi)" \
1063 "$abi_ldflags($abi) -shared -Ttext $loadaddr -T export-class-call16.ld" "" \
1064 "$abi_asflags($abi) -mips3 -KPIC" \
1065 [list export-class-call16-${abi}.s export-class-call16-def.s] \
1066 [list \
1067 "objdump -d export-class-call16-${suff}.dd" \
1068 "readelf -A export-class-call16-${abi}.gd"] \
1069 "export-class-call16-${abi}.so"]]
1070 }
1071
1072 # Magic __ehdr_start symbol tests.
1073 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
1074 foreach { abi } $abis {
1075 set suff [string map {o32 o32 n32 new n64 new} $abi]
1076 run_ld_link_tests [list \
1077 [list \
1078 "MIPS magic __ehdr_start symbol test 1 ($abi)" \
1079 "$abi_ldflags($abi) -T ehdr_start-1.ld" "" \
1080 "$abi_asflags($abi)" \
1081 [list ehdr_start-${suff}.s] \
1082 [list "readelf -s ehdr_start-1.nd"] \
1083 "ehdr_start-1-${abi}"] \
1084 [list \
1085 "MIPS magic __ehdr_start symbol test 2 ($abi)" \
1086 "$abi_ldflags($abi) -T ehdr_start-2.ld" "" \
1087 "$abi_asflags($abi)" \
1088 [list ehdr_start-${suff}.s] \
1089 [list "readelf -s ehdr_start-2.nd"] \
1090 "ehdr_start-2-${abi}"]]
1091 }
1092
1093 # R_MIPS_JALR reloc tests.
1094 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
1095 foreach { abi } $abis {
1096 run_ld_link_tests [list \
1097 [list \
1098 "MIPS JALR reloc test ($abi)" \
1099 "$abi_ldflags($abi) -T jalr3.ld" "" \
1100 "$abi_asflags($abi)" \
1101 [list ../../../gas/testsuite/gas/mips/jalr3.s] \
1102 [list "objdump -d jalr3.dd"] \
1103 "jalr3-${abi}"] \
1104 [list \
1105 "MIPS JALR reloc unaligned/cross-mode link test ($abi)" \
1106 "$abi_ldflags($abi) -T jalr3.ld" "" \
1107 "$abi_asflags($abi)" \
1108 [list ../../../gas/testsuite/gas/mips/jalr4.s] \
1109 [list "objdump {-d --prefix-addresses --show-raw-insn} jalr4.dd"] \
1110 "jalr4-${abi}"] \
1111 [list \
1112 "MIPSr6 JALR reloc unaligned/cross-mode link test ($abi)" \
1113 "$abi_ldflags($abi) -T jalr3.ld" "" \
1114 [string map \
1115 [list -32 "-mips32r6 -32" \
1116 -n32 "-mips64r6 -n32" \
1117 -64 "-mips64r6 -64"] \
1118 [regsub -- -march=from-abi $abi_asflags($abi) ""]] \
1119 {../../../gas/testsuite/gas/mips/jalr4.s} \
1120 {{objdump {-d --prefix-addresses --show-raw-insn} jalr4-r6.dd}} \
1121 "jalr4-${abi}"]]
1122 }
1123
1124 proc build_mips_plt_lib { abi } {
1125 global abi_asflags
1126 global abi_ldflags
1127
1128 run_ld_link_tests [list \
1129 [list "Shared $abi library for compressed PLT tests" \
1130 "-shared $abi_ldflags($abi)" "" \
1131 "$abi_asflags($abi)" \
1132 { compressed-plt-1-dyn.s } \
1133 {} \
1134 "compressed-plt-1-${abi}-dyn.so"]]
1135 }
1136
1137 proc run_mips_plt_test { name abi filter micromips suffix {extra {}} } {
1138 global abi_asflags
1139 global abi_ldflags
1140
1141 set as_flags "$abi_asflags($abi) --defsym filter=$filter"
1142 append as_flags " --defsym micromips=$micromips --defsym $abi=1"
1143 if {[string equal $abi o32]} {
1144 append as_flags " -march=mips2"
1145 }
1146 set ld_flags "$abi_ldflags($abi) -T compressed-plt-1.ld"
1147 set dynobj "tmpdir/compressed-plt-1-${abi}-dyn.so"
1148 set files [list]
1149 if { $filter & 7 } {
1150 lappend files compressed-plt-1a.s
1151 }
1152 if { $filter & 56 } {
1153 lappend files compressed-plt-1b.s
1154 }
1155 if { $filter & 64 } {
1156 lappend files compressed-plt-1c.s
1157 }
1158 eval [list lappend files] $extra
1159 set readelf_flags "-A --syms --relocs -d"
1160 if { [string match "*word*" $suffix] } {
1161 append readelf_flags " -x.data"
1162 }
1163 set objdump_flags "-d -Mgpr-names=numeric"
1164 set basename "compressed-plt-1-${abi}-${suffix}"
1165 run_ld_link_tests [list \
1166 [list "$name" $ld_flags $dynobj \
1167 "$as_flags" $files \
1168 [list [list readelf $readelf_flags ${basename}.rd] \
1169 [list objdump $objdump_flags ${basename}.od]] \
1170 $basename]]
1171 }
1172
1173 if { $linux_gnu } {
1174 build_mips_plt_lib o32
1175 run_mips_plt_test "o32 PLTs for standard encoding" o32 104 0 se
1176 run_mips_plt_test "o32 PLTs for standard branches" o32 16 0 branch
1177 run_mips_plt_test "o32 PLTs for MIPS16 encoding" o32 69 0 mips16-only
1178 run_mips_plt_test "o32 PLTs for MIPS16 branches" o32 2 0 mips16-bronly
1179 run_mips_plt_test "o32 PLTs for microMIPS encoding" o32 69 1 umips-only
1180 run_mips_plt_test "o32 PLTs for microMIPS branches" o32 2 1 umips-bronly
1181 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16" \
1182 o32 109 0 mips16
1183 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 branches" \
1184 o32 18 0 mips16-branch
1185 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with %got" \
1186 o32 109 0 mips16-got compressed-plt-1d.s
1187 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with .word" \
1188 o32 109 0 mips16-word compressed-plt-1e.s
1189 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS" \
1190 o32 109 1 umips
1191 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS branches" \
1192 o32 18 1 umips-branch
1193 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with %got" \
1194 o32 109 1 umips-got compressed-plt-1d.s
1195 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with .word" \
1196 o32 109 1 umips-word compressed-plt-1e.s
1197
1198 if $has_newabi {
1199 build_mips_plt_lib n32
1200 run_mips_plt_test "n32 PLTs for mixed MIPS and MIPS16" \
1201 n32 109 0 mips16
1202 run_mips_plt_test "n32 PLTs for mixed MIPS and microMIPS" \
1203 n32 109 1 umips
1204 }
1205 }
1206
1207 # Verify graceful handling of n64 PLT 32-bit range overflows. Given
1208 # that the alignment of `.got.plt' is 8 the highest usable positive
1209 # address is 0x7fff7ff8 and the lowest usable negative address is
1210 # 0xffffffff7fff8000.
1211 if { $linux_gnu } {
1212 run_ld_link_tests [list \
1213 [list "Shared library for MIPS n64 PLT 32-bit range tests" \
1214 "-shared $abi_ldflags(n64)" "" \
1215 "$abi_asflags(n64)" \
1216 { n64-plt-lib.s } \
1217 {} \
1218 "n64-plt-lib.so"] \
1219 [list "MIPS n64 PLT 32-bit range test 1" \
1220 "$abi_ldflags(n64) -T n64-plt-1.ld -e foo" \
1221 "tmpdir/n64-plt-lib.so" \
1222 "$abi_asflags(n64)" \
1223 { n64-plt.s } \
1224 { { objdump -d n64-plt-1.dd } \
1225 { readelf -A n64-plt-1.gd } } \
1226 "n64-plt-1"] \
1227 [list "MIPS n64 PLT 32-bit range test 2" \
1228 "$abi_ldflags(n64) -T n64-plt-2.ld -e foo" \
1229 "tmpdir/n64-plt-lib.so" \
1230 "$abi_asflags(n64)" \
1231 { n64-plt.s } \
1232 { { ld n64-plt-2.ed } } \
1233 "n64-plt-2"] \
1234 [list "MIPS n64 PLT 32-bit range test 3" \
1235 "$abi_ldflags(n64) -T n64-plt-3.ld -e foo" \
1236 "tmpdir/n64-plt-lib.so" \
1237 "$abi_asflags(n64)" \
1238 { n64-plt.s } \
1239 { { ld n64-plt-3.ed } } \
1240 "n64-plt-3"] \
1241 [list "MIPS n64 PLT 32-bit range test 4" \
1242 "$abi_ldflags(n64) -T n64-plt-4.ld -e foo" \
1243 "tmpdir/n64-plt-lib.so" \
1244 "$abi_asflags(n64)" \
1245 { n64-plt.s } \
1246 { { objdump -d n64-plt-4.dd } \
1247 { readelf -A n64-plt-4.gd } } \
1248 "n64-plt-4"]]
1249 }
1250
1251 # PR ld/19908 export class tests.
1252 if { $linux_gnu } {
1253 run_ld_link_tests [list \
1254 [list "Shared library for MIPS export class symbol reference tests" \
1255 "$abi_ldflags(o32) -shared" "" \
1256 "$abi_asflags(o32)" \
1257 { export-class-ref-f2.s } \
1258 { { readelf --dyn-syms export-class-ref-lib.sd } } \
1259 "export-class-ref-lib.so"]]
1260 foreach { class flag } { internal 1 hidden 2 protected 3 } {
1261 run_ld_link_tests [list \
1262 [list "MIPS $class symbol reference test 1" \
1263 "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
1264 "$abi_asflags(o32) --defsym defv=$flag" \
1265 { export-class-ref-f0.s export-class-ref-f1.s } \
1266 [list [list readelf --dyn-syms export-$class-ref.sd] \
1267 [list readelf --dyn-syms export-local-ref.sd]] \
1268 "export-$class-ref"] \
1269 [list "MIPS $class symbol reference test 2" \
1270 "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
1271 "$abi_asflags(o32) --defsym defv=$flag --defsym refv=$flag" \
1272 { export-class-ref-f0.s export-class-ref-f1.s } \
1273 [list [list readelf --dyn-syms export-$class-ref.sd] \
1274 [list readelf --dyn-syms export-local-ref.sd]] \
1275 "export-$class-ref"]]
1276 }
1277 }
1278
1279 # PR ld/21334 GOT relocation in static binary test.
1280 run_ld_link_tests [list \
1281 [list \
1282 "PR ld/21334 MIPS GOT16 relocation in static binary" \
1283 "$abi_ldflags(o32) -e foo -T pr21334.ld" "" "$abi_asflags(o32)" \
1284 {pr21334.s} \
1285 {{objdump {-d --prefix-addresses} pr21334.dd} \
1286 {readelf -A pr21334.gd}} \
1287 "pr21334"]]
1288
1289 # Check that the ISA level is consistently II for the LSI 4010.
1290 run_dump_test "lsi-4010-isa" [list [list ld $abi_ldflags(o32)]]
1291
1292 # PIC branch relaxation with offset tests. We need to use our version
1293 # of `prune_warnings' to get rid of GAS branch relaxation noise.
1294 rename prune_warnings mips_old_prune_warnings
1295 proc prune_warnings { msg } {
1296 set msg1 "Assembler messages:"
1297 set msg2 "Warning: relaxed out-of-range branch into a jump"
1298 set msgx "(?:$msg1|$msg2)"
1299 regsub -all "(^|\[\n\r\]*)\[^\n\r\]*: $msgx\[\n\r\]*" $msg "\\1" msg
1300 return [mips_old_prune_warnings $msg]
1301 }
1302 run_ld_link_tests [list \
1303 [list \
1304 "MIPS link PIC branch relaxation with offset" \
1305 "$abi_ldflags(o32) -shared -T relax-offset.ld" "" \
1306 "$abi_asflags(o32) -relax-branch -mips2" \
1307 {../../../gas/testsuite/gas/mips/relax-offset.s} \
1308 {{objdump \
1309 {-d --prefix-addresses --show-raw-insn} \
1310 relax-offset.dd} \
1311 {readelf -A relax-offset.gd}} \
1312 "relax-offset"] \
1313 [list \
1314 "microMIPS link PIC branch relaxation with offset" \
1315 "$abi_ldflags(o32) -shared -T relax-offset.ld" "" \
1316 "$abi_asflags(o32) -relax-branch -mmicromips" \
1317 {../../../gas/testsuite/gas/mips/relax-offset.s} \
1318 {{objdump \
1319 {-d --prefix-addresses --show-raw-insn} \
1320 relax-offset-umips.dd} \
1321 {readelf -A relax-offset-umips.gd}} \
1322 "relax-offset-umips"]]
1323 rename prune_warnings ""
1324 rename mips_old_prune_warnings prune_warnings
1325
1326 # Verify that we can link ELF input into the `binary' output format.
1327 run_dump_test "binary"
1328
1329 # Verify special section processing.
1330 if $has_elf32 {
1331 run_dump_test "reginfo-0"
1332 run_dump_test "reginfo-0r"
1333 run_dump_test "reginfo-1"
1334 run_dump_test "reginfo-1r"
1335 run_dump_test "reginfo-2"
1336 run_dump_test "reginfo-2r"
1337 }
1338 run_dump_test "mips-abiflags-0"
1339 run_dump_test "mips-abiflags-0r"
1340 run_dump_test "mips-abiflags-1"
1341 run_dump_test "mips-abiflags-1r"
1342 run_dump_test "mips-abiflags-2"
1343 run_dump_test "mips-abiflags-2r"
1344
1345 # Test that _gp_disp symbol is not present in symbol tables.
1346 run_dump_test "gp-disp-sym" [list [list as $abi_asflags(o32)] \
1347 [list ld $abi_ldflags(o32)]]