]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-mips-elf/mips-elf.exp
MIPS/BFD: Don't stop processing on `bfd_reloc_outofrange'
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-mips-elf / mips-elf.exp
1 # Expect script for MIPS ELF linker tests
2 # Copyright (C) 2002-2016 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 linux_gnu [expr [istarget mips*-*-linux*]]
61 set embedded_elf [expr [istarget mips*-*-elf]]
62
63 # Set defaults.
64 set abi_asflags(o32) "-32"
65 set abi_asflags(n32) "-march=from-abi -n32 -EB"
66 set abi_asflags(n64) "-march=from-abi -64 -EB"
67 set abi_ldflags(o32) ""
68 set abi_ldflags(n32) -melf32bmipn32
69 set abi_ldflags(n64) -melf64bmip
70
71 # Override as needed.
72 if { [istarget *-*-irix6*] } {
73 set abi_asflags(o32) "-32 -EB"
74 set abi_ldflags(o32) -melf32bsmip
75 } elseif { [istarget mips64*-linux*] } {
76 set abi_asflags(o32) "-32 -EB"
77 set abi_ldflags(o32) -melf32btsmip
78 } elseif { [istarget mips64*-*freebsd*] } {
79 set abi_asflags(o32) "-32 -EB"
80 set abi_ldflags(o32) -melf32btsmip_fbsd
81 }
82 if { [istarget mips*-*-linux*] || [istarget mips*-sde-elf*]
83 || [istarget mips*-mti-elf*] || [istarget mips*-img-elf*]} {
84 set abi_ldflags(n32) -melf32btsmipn32
85 set abi_ldflags(n64) -melf64btsmip
86 } elseif { [istarget mips64*-*freebsd*] } {
87 set abi_ldflags(n32) -melf32btsmipn32_fbsd
88 set abi_ldflags(n64) -melf64btsmip_fbsd
89 }
90
91 if { $linux_gnu } {
92 run_ld_link_tests [list \
93 [list "Dummy shared library for MIPS16 PIC test 1" \
94 "-shared -melf32btsmip" "" \
95 "-EB -32 -mips1" \
96 { mips16-pic-1-dummy.s } \
97 {} \
98 "mips16-pic-1-dummy.so"] \
99 [list "MIPS16 PIC test 1" \
100 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-1-dummy.so" "" \
101 "-EB -32 -mips1 -I $srcdir/$subdir" \
102 { mips16-pic-1a.s mips16-pic-1b.s } \
103 { { objdump { -dr -j.text } mips16-pic-1.dd }
104 { readelf -A mips16-pic-1.gd } } \
105 "mips16-pic-1"] \
106 [list "MIPS16 PIC test 2" \
107 "-melf32btsmip -T mips16-pic-1.ld -shared" "" \
108 "-EB -32 -mips1 -I $srcdir/$subdir" \
109 { mips16-pic-2a.s mips16-pic-2b.s } \
110 { { objdump { -dr -j.text } mips16-pic-2.dd } \
111 { readelf -A mips16-pic-2.gd } \
112 { readelf --symbols mips16-pic-2.nd } \
113 { readelf --relocs mips16-pic-2.rd } \
114 { readelf -d mips16-pic-2.ad } } \
115 "mips16-pic-2"] \
116 [list "MIPS16 PIC test 3" \
117 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-1-dummy.so" "" \
118 "-EB -32 -mips1 -I $srcdir/$subdir" \
119 { mips16-pic-3a.s mips16-pic-3b.s } \
120 { { objdump -dr mips16-pic-3.dd } \
121 { readelf --relocs mips16-pic-3.rd } \
122 { readelf -A mips16-pic-3.gd } } \
123 "mips16-pic-3"] \
124 [list "MIPS16 PIC test 4 (shared library)" \
125 "-shared -melf32btsmip -T mips16-pic-1.ld --version-script mips16-pic-4.ver" "" \
126 "-EB -32 -mips1" \
127 { mips16-pic-4a.s mips16-pic-4b.s } \
128 { { objdump -dr mips16-pic-4a.dd } \
129 { readelf --symbols mips16-pic-4a.nd } \
130 { readelf -A mips16-pic-4a.gd } } \
131 "mips16-pic-4.so"] \
132 [list "MIPS16 PIC test 4 (executable)" \
133 "-melf32btsmip -T mips16-pic-1.ld tmpdir/mips16-pic-4.so" "" \
134 "-EB -32 -mips1" \
135 { mips16-pic-4c.s } \
136 { { objdump -dr mips16-pic-4b.dd } } \
137 "mips16-pic-4"]]
138 }
139
140 # Check MIPS16 markings being passed through link.
141 run_dump_test "mips16-1"
142
143 # MIPS branch offset final link checking.
144 run_dump_test "branch-misc-1"
145
146 # Jalx test
147 run_dump_test "jalx-1"
148
149 if { $linux_gnu } {
150 run_ld_link_tests [list \
151 [list "Dummy shared library for JALX test 2" \
152 "-shared -nostdlib -melf32btsmip" "" \
153 "-G0 -EB -mmicromips -no-mdebug -mabi=32 -march=mips32r2 -KPIC" \
154 { jalx-2-printf.s } \
155 {} \
156 "libjalx-2.so"] \
157 [list "Dummy external function for JALX test 2" \
158 "-r -melf32btsmip" "" \
159 "-G0 -EB -no-mdebug -mabi=32 -march=mips32r2 -mno-shared -call_nonpic" \
160 { jalx-2-ex.s } \
161 {} \
162 "jalx-2-ex.o.r"] \
163 [list "MIPS JALX test 2" \
164 "-nostdlib -T jalx-2.ld tmpdir/libjalx-2.so tmpdir/jalx-2-ex.o.r -melf32btsmip" "" \
165 "-G0 -EB -mmicromips -no-mdebug -mabi=32 -march=mips32r2 -mno-shared -call_nonpic" \
166 { jalx-2-main.s } \
167 { { objdump -d jalx-2.dd } } \
168 "jalx-2"]]
169 }
170
171 run_dump_test "jalx-addend" [list [list ld $abi_ldflags(o32)]]
172 run_dump_test "jalx-local" [list [list ld $abi_ldflags(o32)]]
173 if $has_newabi {
174 run_dump_test "jalx-addend-n32" [list [list ld $abi_ldflags(n32)]]
175 run_dump_test "jalx-local-n32" [list [list ld $abi_ldflags(n32)]]
176 run_dump_test "jalx-addend-n64" [list [list ld $abi_ldflags(n64)]]
177 run_dump_test "jalx-local-n64" [list [list ld $abi_ldflags(n64)]]
178 }
179
180 run_dump_test "unaligned-jalx-0" [list [list ld $abi_ldflags(o32)]]
181 run_dump_test "unaligned-jalx-1" [list [list ld $abi_ldflags(o32)]]
182 run_dump_test "unaligned-jalx-mips16-0" [list [list ld $abi_ldflags(o32)]]
183 run_dump_test "unaligned-jalx-mips16-1" [list [list ld $abi_ldflags(o32)]]
184 run_dump_test "unaligned-jalx-micromips-0" [list [list ld $abi_ldflags(o32)]]
185 run_dump_test "unaligned-jalx-micromips-1" [list [list ld $abi_ldflags(o32)]]
186
187 run_dump_test "unaligned-lwpc-0" [list [list ld $abi_ldflags(o32)]]
188 run_dump_test "unaligned-lwpc-1" [list [list ld $abi_ldflags(o32)]]
189 run_dump_test "unaligned-ldpc-0" [list [list ld $abi_ldflags(o32)]]
190 run_dump_test "unaligned-ldpc-1" [list [list ld $abi_ldflags(o32)]]
191
192 # Test multi-got link. We only do this on GNU/Linux because it requires
193 # the "traditional" emulations.
194 if { $linux_gnu } {
195 run_dump_test "multi-got-1"
196 run_dump_test "multi-got-no-shared"
197 run_dump_test "multi-got-hidden-1"
198 run_dump_test "multi-got-hidden-2"
199 }
200
201 # Test __gnu_local_gp accesses
202 if { $linux_gnu } {
203 run_dump_test "no-shared-1-o32"
204 if { $has_newabi } {
205 run_dump_test "no-shared-1-n32"
206 run_dump_test "no-shared-1-n64"
207 }
208 }
209
210 # Test PIE debug dynamic tags
211 if { $linux_gnu } {
212 run_dump_test "pie-o32"
213 if { $has_newabi } {
214 run_dump_test "pie-n32"
215 run_dump_test "pie-n64"
216 }
217 }
218
219 if $has_newabi {
220 if { $embedded_elf } {
221 run_dump_test "elf-rel-got-n32-embed" \
222 [list [list ld $abi_ldflags(n32)]]
223 run_dump_test "elf-rel-xgot-n32-embed" \
224 [list [list ld $abi_ldflags(n32)]]
225 } else {
226 run_dump_test "elf-rel-got-n32" [list [list ld $abi_ldflags(n32)]]
227 run_dump_test "elf-rel-xgot-n32" [list [list ld $abi_ldflags(n32)]]
228 }
229 if { $linux_gnu } {
230 run_dump_test "elf-rel-got-n64-linux" \
231 [list [list ld $abi_ldflags(n64)]]
232 run_dump_test "elf-rel-xgot-n64-linux" \
233 [list [list ld $abi_ldflags(n64)]]
234 } elseif { $embedded_elf } {
235 run_dump_test "elf-rel-got-n64-embed" \
236 [list [list ld $abi_ldflags(n64)]]
237 run_dump_test "elf-rel-xgot-n64-embed" \
238 [list [list ld $abi_ldflags(n64)]]
239 } else {
240 run_dump_test "elf-rel-got-n64" [list [list ld $abi_ldflags(n64)]]
241 run_dump_test "elf-rel-xgot-n64" [list [list ld $abi_ldflags(n64)]]
242 }
243
244 run_dump_test "relax-jalr-n32"
245 run_dump_test "relax-jalr-n32-shared"
246 run_dump_test "relax-jalr-n64"
247 run_dump_test "relax-jalr-n64-shared"
248 }
249
250 if { $linux_gnu } {
251 run_dump_test "rel32-o32"
252 if { $has_newabi } {
253 run_dump_test "rel32-n32"
254 run_dump_test "rel64"
255 }
256 # The first test checks that a mixed PIC/non-PIC relocatable link
257 # will not introduce any stubs itself, but will flag PIC functions
258 # for the final link.
259 #
260 # The second test checks that we insert stubs for calls from
261 # non-PIC functions to PIC functions when linking the original
262 # two objects together.
263 #
264 # The third test checks that we do the same when linking the
265 # result of the first link (with no other source files).
266 run_ld_link_tests {
267 {"PIC and non-PIC test 1 (relocatable)" "-r -melf32btsmip" ""
268 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
269 {{objdump -dr pic-and-nonpic-1-rel.dd}
270 {readelf --symbols pic-and-nonpic-1-rel.nd}}
271 "pic-and-nonpic-1-rel.o"}
272 {"PIC and non-PIC test 1 (static 1)"
273 "-melf32btsmip -Tpic-and-nonpic-1.ld" ""
274 "-32 -EB -mips2" {pic-and-nonpic-1a.s pic-and-nonpic-1b.s}
275 {{objdump -dr pic-and-nonpic-1.dd}
276 {readelf --symbols pic-and-nonpic-1.nd}}
277 "pic-and-nonpic-1-static1.o"}
278 {"PIC and non-PIC test 1 (static 2)"
279 "-melf32btsmip -Tpic-and-nonpic-1.ld tmpdir/pic-and-nonpic-1-rel.o" ""
280 "" {}
281 {{objdump -dr pic-and-nonpic-1.dd}
282 {readelf --symbols pic-and-nonpic-1.nd}}
283 "pic-and-nonpic-1-static2.o"}
284 }
285 run_dump_test "pic-and-nonpic-2"
286 run_ld_link_tests {
287 {"PIC and non-PIC test 3 (shared library)"
288 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld" ""
289 "-32 -EB -mips2" {pic-and-nonpic-3a.s}
290 {{readelf --segments pic-and-nonpic-3a.sd}
291 {readelf -A pic-and-nonpic-3a.gd}
292 {objdump -dr pic-and-nonpic-3a.dd}}
293 "pic-and-nonpic-3a.so"}
294 {"PIC and non-PIC test 3 (executable)"
295 "-melf32btsmip -Tpic-and-nonpic-3b.ld tmpdir/pic-and-nonpic-3a.so" ""
296 "-32 -EB -mips2" {pic-and-nonpic-3b.s}
297 {{readelf --segments pic-and-nonpic-3b.sd}
298 {objdump -dr pic-and-nonpic-3b.dd}
299 {objdump {-s -j.got.plt} pic-and-nonpic-3b.pd}
300 {readelf -A pic-and-nonpic-3b.gd}
301 {readelf --relocs pic-and-nonpic-3b.rd}
302 {readelf --symbols pic-and-nonpic-3b.nd}
303 {readelf -d pic-and-nonpic-3b.ad}}
304 "pic-and-nonpic-3b"}
305 }
306 run_dump_test "pic-and-nonpic-3-error"
307 run_ld_link_tests {
308 {"PIC and non-PIC test 4 (shared library)"
309 "-melf32btsmip -shared -Tpic-and-nonpic-3a.ld" ""
310 "-32 -EB -mips2" {pic-and-nonpic-4a.s}
311 {}
312 "pic-and-nonpic-4a.so"}
313 {"PIC and non-PIC test 4 (executable)"
314 "-melf32btsmip -Tpic-and-nonpic-4b.ld tmpdir/pic-and-nonpic-4a.so" ""
315 "-32 -EB -mips2" {pic-and-nonpic-4b.s}
316 {{readelf --segments pic-and-nonpic-4b.sd}
317 {objdump -dr pic-and-nonpic-4b.dd}
318 {objdump {-s -j.got -j.data} pic-and-nonpic-4b.gd}
319 {readelf --relocs pic-and-nonpic-4b.rd}
320 {readelf --symbols pic-and-nonpic-4b.nd}
321 {readelf -d pic-and-nonpic-4b.ad}}
322 "pic-and-nonpic-4b"}
323 }
324 run_dump_test "pic-and-nonpic-4-error"
325 run_ld_link_tests {
326 {"PIC and non-PIC test 5 (executable)"
327 "-melf32btsmip -Tpic-and-nonpic-5b.ld tmpdir/pic-and-nonpic-3a.so tmpdir/pic-and-nonpic-4a.so" ""
328 "-32 -EB -mips2" {pic-and-nonpic-5a.s pic-and-nonpic-5b.s}
329 {{readelf --segments pic-and-nonpic-5b.sd}
330 {objdump -dr pic-and-nonpic-5b.dd}
331 {objdump {-s -j.got.plt -j.data} pic-and-nonpic-5b.pd}
332 {readelf -A pic-and-nonpic-5b.gd}
333 {readelf --relocs pic-and-nonpic-5b.rd}
334 {readelf --symbols pic-and-nonpic-5b.nd}
335 {readelf -d pic-and-nonpic-5b.ad}}
336 "pic-and-nonpic-5b"}
337 }
338 set abis { o32 -32 elf32btsmip }
339 if $has_newabi {
340 lappend abis n32 -n32 elf32btsmipn32
341 lappend abis n64 -64 elf64btsmip
342 }
343 foreach { abi flag emul } $abis {
344 run_ld_link_tests [list \
345 [list "PIC and non-PIC test 6 ($abi shared library)" \
346 "-m$emul -shared -Tpic-and-nonpic-3a.ld" "" \
347 "$flag -EB -mips3" \
348 [list "pic-and-nonpic-6-${abi}a.s"] {} \
349 "pic-and-nonpic-6-${abi}.so"] \
350 [list "PIC and non-PIC test 6 ($abi executable)" \
351 "-m$emul -Tpic-and-nonpic-6.ld tmpdir/pic-and-nonpic-6-${abi}.so" "" \
352 "$flag -EB -mips3" \
353 [list "pic-and-nonpic-6-${abi}b.s" \
354 "pic-and-nonpic-6-${abi}c.s"] \
355 [list "readelf {--wide --segments} pic-and-nonpic-6-${abi}.sd" \
356 "objdump -dr pic-and-nonpic-6-${abi}.dd" \
357 "objdump {-s -j.got.plt} pic-and-nonpic-6-${abi}.pd" \
358 "readelf -A pic-and-nonpic-6-${abi}.gd" \
359 "readelf --relocs pic-and-nonpic-6-${abi}.rd" \
360 "readelf --symbols pic-and-nonpic-6-${abi}.nd" \
361 "readelf -d pic-and-nonpic-6-${abi}.ad"] \
362 "pic-and-nonpic-6-${abi}"]]
363
364 # This checks whether our linker scripts get the scope of _gp right,
365 # and must therefore use default scripts. If they don't, then -- in
366 # addition to dumps failing to match -- the final link fails with:
367 #
368 # ld: gp-hidden.o: undefined reference to symbol '_gp'
369 # ld: note: '_gp' is defined in DSO ./tmpdir/gp-hidden-lib-${abi}.so
370 # so try adding it to the linker command line
371 #
372 set suff64 [string map {o32 "" n32 "" n64 -64} $abi]
373 run_ld_link_tests [list \
374 [list \
375 "_gp scope test ($abi shared library)" \
376 "$abi_ldflags($abi) -shared" "" \
377 "$abi_asflags($abi) -KPIC" \
378 { gp-hidden-lib.s } \
379 [list \
380 "readelf --relocs gp-hidden-lib${suff64}.rd" \
381 "readelf --syms gp-hidden.sd"] \
382 "gp-hidden-lib-${abi}.so"] \
383 [list \
384 "_gp scope test ($abi versioned library)" \
385 "$abi_ldflags($abi) -shared -version-script gp-hidden-ver.ver tmpdir/gp-hidden-lib-${abi}.so" "" \
386 "$abi_asflags($abi) -KPIC" \
387 { gp-hidden-ver.s } \
388 [list \
389 "readelf --relocs gp-hidden-ver${suff64}.rd" \
390 "readelf --syms gp-hidden.sd"] \
391 "gp-hidden-ver-${abi}.so"] \
392 [list \
393 "_gp scope test ($abi executable)" \
394 "$abi_ldflags($abi) -e 0 -rpath-link . tmpdir/gp-hidden-ver-${abi}.so" "" \
395 "$abi_asflags($abi) -call_nonpic" \
396 { gp-hidden.s } \
397 [list \
398 "readelf --relocs gp-hidden${suff64}.rd" \
399 "readelf --syms gp-hidden.sd"] \
400 "gp-hidden-${abi}"]]
401 }
402 }
403
404 if { $embedded_elf } {
405 run_dump_test "region1"
406 }
407
408 if $embedded_elf {
409 # This could work on other targets too, but would need the appropriate
410 # ld -m switch.
411 run_dump_test "reloc-1-rel"
412 }
413 if $has_newabi {
414 run_dump_test "reloc-1-n32" [list [list ld $abi_ldflags(n32)]]
415 run_dump_test "reloc-1-n64" [list [list ld $abi_ldflags(n64)]]
416 }
417 run_dump_test "reloc-2"
418 run_dump_test "reloc-merge-lo16"
419 run_dump_test "reloc-3"
420 if {$has_newabi} {
421 run_dump_test "reloc-3-n32"
422 }
423 run_dump_test "reloc-4"
424 run_dump_test "reloc-5"
425 if { $has_newabi } {
426 run_ld_link_tests [list \
427 [list \
428 "reloc test 6a" \
429 "-shared $abi_ldflags(n32)" "" \
430 "$abi_asflags(n32)" \
431 "reloc-6a.s" \
432 {} \
433 "reloc-6a.so"] \
434 [list \
435 "reloc test 6b" \
436 "$abi_ldflags(n32) tmpdir/reloc-6a.so" "" \
437 "$abi_asflags(n32)" \
438 "reloc-6b.s" \
439 {} \
440 "reloc-6b"]]
441 }
442
443 if {$has_newabi && $linux_gnu} {
444 run_dump_test "eh-frame1-n32"
445 run_dump_test "eh-frame1-n64"
446 run_dump_test "eh-frame2-n32"
447 run_dump_test "eh-frame2-n64"
448 }
449 if {$embedded_elf} {
450 run_dump_test "eh-frame3"
451 run_dump_test "eh-frame4"
452 }
453 if {$linux_gnu} {
454 set eh_frame5_test {
455 {"MIPS eh-frame 5"
456 "-melf32btsmip -shared -Teh-frame5.ld" ""
457 "-32 -EB"
458 {eh-frame5.s}
459 {{readelf {--relocs -wf} eh-frame5.d}}
460 "eh-frame5.so"}
461 }
462 run_ld_link_tests $eh_frame5_test
463 }
464
465 if {$embedded_elf} {
466 run_dump_test "compact-eh1"
467 run_dump_test "compact-eh2"
468 run_dump_test "compact-eh3"
469 }
470
471 if {$linux_gnu} {
472 run_dump_test "compact-eh4"
473 run_dump_test "compact-eh5"
474 run_dump_test "compact-eh6"
475 }
476
477 run_dump_test "jaloverflow"
478 run_dump_test "jaloverflow-2"
479 run_dump_test "undefweak-overflow" [list [list as $abi_asflags(o32)] \
480 [list ld $abi_ldflags(o32)]]
481
482 if {$has_newabi} {
483 run_dump_test "undefweak-overflow" [list [list as $abi_asflags(n32)] \
484 [list ld $abi_ldflags(n32)]]
485 run_dump_test "undefweak-overflow" [list [list as $abi_asflags(n64)] \
486 [list ld $abi_ldflags(n64)]]
487 }
488
489 if {$has_newabi} {
490 run_dump_test "jalbal" [list [list ld $abi_ldflags(n32)]]
491 }
492
493 run_dump_test "mode-change-error-1"
494
495 run_dump_test "mips16-hilo"
496 if {$has_newabi} {
497 run_dump_test "mips16-hilo-n32"
498 }
499
500 if { $linux_gnu } {
501 if { $has_newabi } {
502 run_dump_test "textrel-1"
503 }
504 run_dump_test "got-page-1"
505 if $has_newabi {
506 run_dump_test "got-page-2"
507 run_dump_test "dyn-sec64"
508 }
509 run_dump_test "got-page-3"
510 run_ld_link_tests [subst {
511 {"GOT page 4 (one file)" "-shared $abi_ldflags(o32) -T got-page-1.ld"
512 "" "$abi_asflags(o32) -mips2" {got-page-4b.s}
513 {{objdump -dr got-page-4a.d}
514 {readelf -A got-page-4a.got}}
515 "got-page-4a.so"}
516 {"GOT page 4 (two files)" "-shared $abi_ldflags(o32) -T got-page-1.ld"
517 "" "$abi_asflags(o32) -mips2" {got-page-4a.s got-page-4b.s}
518 {{objdump -dr got-page-4b.d}
519 {readelf -A got-page-4b.got}}
520 "got-page-4b.so"}
521 }]
522 if $has_newabi {
523 run_ld_link_tests [subst {
524 {"GOT page 5" "-shared $abi_ldflags(n32) -T got-page-1.ld"
525 "" "$abi_asflags(n32)" {got-page-5.s}
526 {{objdump -dr got-page-5.d}
527 {readelf -A got-page-5.got}}
528 "got-page-5.so"}
529 {"GOT page 6" "-shared $abi_ldflags(n32) -T got-page-1.ld"
530 "" "$abi_asflags(n32)" {got-page-6.s}
531 {{objdump -dr got-page-6.d}
532 {readelf -A got-page-6.got}}
533 "got-page-6.so"}
534 {"GOT page 7 (order 1)" "-shared $abi_ldflags(n32) -T got-page-1.ld"
535 "" "$abi_asflags(n32)"
536 {got-page-7a.s got-page-7b.s got-page-7c.s got-page-7d.s
537 got-page-7e.s}
538 {{objdump -dr got-page-7.d}
539 {readelf -A got-page-7.got}}
540 "got-page-7a.so"}
541 {"GOT page 7 (order 2)" "-shared $abi_ldflags(n32) -T got-page-1.ld"
542 "" "$abi_asflags(n32)"
543 {got-page-7e.s got-page-7a.s got-page-7b.s got-page-7c.s
544 got-page-7d.s}
545 {{objdump -dr got-page-7.d}
546 {readelf -A got-page-7.got}}
547 "got-page-7b.so"}
548 }]
549 }
550 run_dump_test "got-dump-1"
551 if $has_newabi {
552 run_dump_test "got-dump-2"
553 }
554 run_dump_test "reloc-estimate-1"
555 }
556
557 if $has_newabi {
558 run_dump_test "emit-relocs-1"
559 }
560
561 run_dump_test "hash1a"
562 run_dump_test "hash1b"
563 run_dump_test "hash1c"
564
565 if {[istarget mips*-*-linux*]} {
566 # The number of symbols that are always included in the symbol table
567 # for these tests. The 4 are:
568 #
569 # the null symbol entry
570 # the .MIPS.stubs section symbol
571 set base_syms 2
572 foreach dynsym { 7fff 8000 fff0 10000 2fe80 } {
573 run_ld_link_tests \
574 [list [list \
575 "Stub for dynsym 0x$dynsym" \
576 "-shared -melf32btsmip -T stub-dynsym-1.ld" "" \
577 [concat \
578 "-EB -march=mips1 -32 -KPIC" \
579 "--defsym base_syms=$base_syms" \
580 "--defsym dynsym=0x$dynsym"] \
581 [list "stub-dynsym-1.s"] \
582 [list [list \
583 "objdump" "-dz" \
584 "stub-dynsym-1-$dynsym.d"]] \
585 "stub-dynsym-1-$dynsym"]]
586 }
587 }
588
589 # For tests which may involve multiple files, use run_ld_link_tests.
590
591 # List contains test-items with 3 items followed by 2 lists:
592 # 0:name 1:ld early options 2:ld late options 3:assembler options
593 # 4:filenames of assembler files 5: action and options. 6: name of output file
594
595 # Actions:
596 # objdump: Apply objdump options on result. Compare with regex (last arg).
597 # nm: Apply nm options on result. Compare with regex (last arg).
598 # readelf: Apply readelf options on result. Compare with regex (last arg).
599
600 set mips_tls_tests {
601 {"Static executable with TLS" "-static -melf32btsmip -T mips-dyn.ld" ""
602 "-EB -march=mips1 -32 -KPIC" {tlsbin-o32.s}
603 {{objdump {-dr -m mips:isa32r2} tlsbin-o32.d} {objdump -srj.got tlsbin-o32.got}}
604 "tls-static-o32"}
605 {"Shared library with TLS" "-shared -melf32btsmip -T mips-lib.ld" ""
606 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
607 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32.got}}
608 "tlslib-o32.so"}
609 {"Dynamic executable with TLS"
610 "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32.so" ""
611 "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s}
612 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32.d} {objdump -Rsj.got tlsdyn-o32.got}}
613 "tls-dynamic-o32"}
614 {"Shared library with multiple GOTs and TLS"
615 "-shared -melf32btsmip -T mips-lib.ld" ""
616 "-EB -march=mips1 -32 -KPIC" {tls-multi-got-1-1.s tls-multi-got-1-2.s}
617 {{readelf {-d -r} tls-multi-got-1.r}
618 {objdump {-dr -m mips:isa32r2} tls-multi-got-1.d}
619 {objdump -Rsj.got tls-multi-got-1.got}}
620 "tlslib-multi.so"}
621 {"Shared library with TLS and versioning"
622 "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib.ver" ""
623 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
624 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-ver.got}}
625 "tlslib-o32-ver.so"}
626 {"Dynamic executable with TLS and versioning"
627 "-melf32btsmip -T mips-dyn.ld tmpdir/tlslib-o32-ver.so" ""
628 "-EB -march=mips1 -32 -KPIC" {tlsdyn-o32.s tlsdyn-o32-2.s}
629 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-1.d} {objdump -Rsj.got tlsdyn-o32-1.got}}
630 "tls-dynamic-o32-ver"}
631 {"Dynamic executable with TLS and versioning (order 2)"
632 "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32-2.o" ""
633 "-EB -march=mips1 -32 -KPIC" {}
634 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-2.d} {objdump -Rsj.got tlsdyn-o32-2.got}}
635 "tls-dynamic-o32-ver-2"}
636 {"Dynamic executable with TLS and versioning (order 3)"
637 "-melf32btsmip -T mips-dyn.ld tmpdir/tlsdyn-o32-2.o tmpdir/tlslib-o32-ver.so tmpdir/tlsdyn-o32.o" ""
638 "-EB -march=mips1 -32 -KPIC" {}
639 {{objdump {-dr -m mips:isa32r2} tlsdyn-o32-3.d} {objdump -Rsj.got tlsdyn-o32-3.got}}
640 "tls-dynamic-o32-ver-3"}
641 {"Shared library with TLS and hidden symbols"
642 "-shared -melf32btsmip -T mips-lib.ld --version-script tlslib-hidden.ver" ""
643 "-EB -march=mips1 -32 -KPIC" {tlslib-o32.s}
644 {{objdump {-dr -m mips:isa32r2} tlslib-o32.d} {objdump -Rsj.got tlslib-o32-hidden.got}}
645 "tlslib-o32-hidden.so"}
646 {"Shared library with TLS and hidden symbols (2)"
647 "-shared -melf32btsmip -T mips-lib.ld" ""
648 "-EB -march=mips1 -32 -KPIC" {tls-hidden2a.s tls-hidden2b.s}
649 {{objdump -drj.text tls-hidden2.d} {objdump -sj.got tls-hidden2-got.d}}
650 "tls-hidden2.so"}
651 {"Shared library with TLS and hidden symbols (3)"
652 "-shared -melf32btsmip -T tls-hidden3.ld" ""
653 "-EB -march=mips2 -32 -KPIC" {tls-hidden3a.s tls-hidden3b.s}
654 {{objdump -dj.text tls-hidden3.d} {objdump -sj.got tls-hidden3.got}
655 {readelf --relocs tls-hidden3.r}}
656 "tls-hidden3.so"}
657 {"Shared library with TLS and hidden symbols (4)"
658 "-shared -melf32btsmip -T tls-hidden3.ld" ""
659 "-EB -march=mips2 -32 -KPIC" {tls-hidden4a.s tls-hidden4b.s}
660 {{objdump -sj.got tls-hidden4.got} {readelf --relocs tls-hidden4.r}}
661 "tls-hidden4.so"}
662 }
663
664 if {[istarget mips*-*-linux*]} {
665 run_ld_link_tests $mips_tls_tests
666 }
667
668 set mips16_call_global_test [list \
669 [list "Global calls from mips16" \
670 "$abi_ldflags(o32) -T no-shared-1.ld" "" \
671 "$abi_asflags(o32) -mips32r2" \
672 {mips16-call-global-1.s mips16-call-global-2.s mips16-call-global-3.s} \
673 {{objdump -dr mips16-call-global.d}} \
674 "mips16-call-global"]]
675
676 run_ld_link_tests $mips16_call_global_test
677
678 set mips16_intermix_test [list \
679 [list "Intermixing mips32 and mips16 functions" \
680 "$abi_ldflags(o32)" "" \
681 "$abi_asflags(o32) -mips32r2" \
682 {mips16-intermix-1.s mips16-intermix-2.s} \
683 {{objdump -t mips16-intermix.d}} \
684 "mips16-intermix"]]
685
686 run_ld_link_tests $mips16_intermix_test
687
688 run_dump_test "mips16-local-stubs-1"
689
690 set mips16_fp_stub_test [list \
691 [list "Floating-point stub for mips16 functions" \
692 "$abi_ldflags(o32)" "" \
693 "$abi_asflags(o32) -mips32r2" \
694 {mips16-fp-stub-1.s mips16-fp-stub-2.s} \
695 {{readelf --debug-dump=frames mips16-fp-stub.d}} \
696 "mips16-fp-stub"]]
697
698 run_ld_link_tests $mips16_fp_stub_test
699
700 set o32flagslist [list [list as $abi_asflags(o32)] [list ld $abi_ldflags(o32)]]
701
702 foreach firstfpabi [list 0 1 2 3 4 5 6 7 ] {
703 foreach secondfpabi [list 4 5 6 7 ] {
704 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}" $o32flagslist
705 }
706 }
707 foreach firstfpabi [list 4 5 6 7 ] {
708 foreach secondfpabi [list 0 1 2 3 8 9] {
709 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}" $o32flagslist
710 }
711 }
712 foreach firstfpabi [list 0 1 2 3 ] {
713 foreach secondfpabi [list 0 1 2 3 8 9] {
714 run_dump_test "attr-gnu-4-${firstfpabi}${secondfpabi}"
715 }
716 }
717
718 run_dump_test "attr-gnu-4-81"
719
720 run_dump_test "attr-gnu-8-00"
721 run_dump_test "attr-gnu-8-01"
722 run_dump_test "attr-gnu-8-02"
723 run_dump_test "attr-gnu-8-10"
724 run_dump_test "attr-gnu-8-11"
725 run_dump_test "attr-gnu-8-12"
726 run_dump_test "attr-gnu-8-20"
727 run_dump_test "attr-gnu-8-21"
728 run_dump_test "attr-gnu-8-22"
729
730 run_dump_test "attr-gnu-4-0-ph" $o32flagslist
731 run_dump_test "attr-gnu-4-1-ph" $o32flagslist
732 run_dump_test "attr-gnu-4-2-ph" $o32flagslist
733 run_dump_test "attr-gnu-4-3-ph" $o32flagslist
734 run_dump_test "attr-gnu-4-4-ph" $o32flagslist
735 run_dump_test "attr-gnu-4-5-ph" $o32flagslist
736 run_dump_test "attr-gnu-4-6-ph" $o32flagslist
737 run_dump_test "attr-gnu-4-7-ph" $o32flagslist
738
739 if $has_newabi {
740 run_dump_test "attr-gnu-4-0-n32-ph"
741 run_dump_test "attr-gnu-4-1-n32-ph"
742 run_dump_test "attr-gnu-4-2-n32-ph"
743 run_dump_test "attr-gnu-4-3-n32-ph"
744 run_dump_test "attr-gnu-4-0-n64-ph"
745 run_dump_test "attr-gnu-4-1-n64-ph"
746 run_dump_test "attr-gnu-4-2-n64-ph"
747 run_dump_test "attr-gnu-4-3-n64-ph"
748 }
749
750 run_dump_test "abiflags-strip1-ph" $o32flagslist
751 run_dump_test "abiflags-strip2-ph" $o32flagslist
752 run_dump_test "abiflags-strip3-ph" $o32flagslist
753 run_dump_test "abiflags-strip4-ph" $o32flagslist
754 run_dump_test "abiflags-strip5-ph" $o32flagslist
755 run_dump_test "abiflags-strip6-ph" $o32flagslist
756 run_dump_test "abiflags-strip7-ph" $o32flagslist
757 run_dump_test "abiflags-strip8-ph" $o32flagslist
758 run_dump_test "abiflags-strip9-ph" $o32flagslist
759 run_dump_test "abiflags-strip10-ph" $o32flagslist
760
761 run_dump_test "nan-legacy"
762 run_dump_test "nan-2008"
763 run_dump_test "nan-mixed-1"
764 run_dump_test "nan-mixed-2"
765
766 if { $linux_gnu } {
767 run_ld_link_tests {
768 {"GOT and versioning 1"
769 "-shared -melf32btsmip --version-script got-vers-1.ver" ""
770 "-EB -mips2 -32" {got-vers-1a.s got-vers-1b.s}
771 {{readelf -d got-vers-1.dd}
772 {readelf --symbols got-vers-1.sd}
773 {readelf --relocs got-vers-1.rd}}
774 "got-vers-1.so"}
775 }
776 }
777
778 run_dump_test "undefined"
779
780 # Test the conversion from jr to b
781 if { $linux_gnu } {
782 run_dump_test "jr-to-b-1"
783 run_dump_test "jr-to-b-2"
784 }
785
786 # MIPS16 and microMIPS interlinking test.
787 run_dump_test "mips16-and-micromips"
788
789 # Export class call relocation tests.
790 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
791 foreach { abi } $abis {
792 set loadaddr [string map \
793 {o32 0x12340000 n32 0x12340000 n64 0x123456789abc0000} $abi]
794 set suff [subst \
795 [expr { [istarget *-*-irix*] \
796 ? [string map {o32 o32-irix n32 n32 n64 n64} $abi] \
797 : $abi }]]
798 run_ld_link_tests [list \
799 [list \
800 "MIPS export class call relocation test ($abi)" \
801 "$abi_ldflags($abi) -shared -Ttext $loadaddr -T export-class-call16.ld" "" \
802 "$abi_asflags($abi) -mips3 -KPIC" \
803 [list export-class-call16-${abi}.s export-class-call16-def.s] \
804 [list \
805 "objdump -d export-class-call16-${suff}.dd" \
806 "readelf -A export-class-call16-${abi}.gd"] \
807 "export-class-call16-${abi}.so"]]
808 }
809
810 # Magic __ehdr_start symbol tests.
811 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
812 foreach { abi } $abis {
813 set suff [string map {o32 o32 n32 new n64 new} $abi]
814 run_ld_link_tests [list \
815 [list \
816 "MIPS magic __ehdr_start symbol test 1 ($abi)" \
817 "$abi_ldflags($abi) -T ehdr_start-1.ld" "" \
818 "$abi_asflags($abi)" \
819 [list ehdr_start-${suff}.s] \
820 [list "readelf -s ehdr_start-1.nd"] \
821 "ehdr_start-1-${abi}"]]
822 if [regexp "(?:n32|n64)" "$abi"] {
823 setup_kfail "mips*-*-*" "ld/15428"
824 }
825 run_ld_link_tests [list \
826 [list \
827 "MIPS magic __ehdr_start symbol test 2 ($abi)" \
828 "$abi_ldflags($abi) -T ehdr_start-2.ld" "" \
829 "$abi_asflags($abi)" \
830 [list ehdr_start-${suff}.s] \
831 [list "readelf -s ehdr_start-2.nd"] \
832 "ehdr_start-2-${abi}"]]
833 }
834
835 # R_MIPS_JALR reloc tests.
836 set abis [concat o32 [expr {$has_newabi ? "n32 n64" : ""}]]
837 foreach { abi } $abis {
838 run_ld_link_tests [list \
839 [list \
840 "MIPS JALR reloc test ($abi)" \
841 "$abi_ldflags($abi) -T jalr3.ld" "" \
842 "$abi_asflags($abi)" \
843 [list ../../../gas/testsuite/gas/mips/jalr3.s] \
844 [list "objdump -d jalr3.dd"] \
845 "jalr3-${abi}"]]
846 }
847
848 proc build_mips_plt_lib { abi } {
849 global abi_asflags
850 global abi_ldflags
851
852 run_ld_link_tests [list \
853 [list "Shared $abi library for compressed PLT tests" \
854 "-shared $abi_ldflags($abi)" "" \
855 "$abi_asflags($abi)" \
856 { compressed-plt-1-dyn.s } \
857 {} \
858 "compressed-plt-1-${abi}-dyn.so"]]
859 }
860
861 proc run_mips_plt_test { name abi filter micromips suffix {extra {}} } {
862 global abi_asflags
863 global abi_ldflags
864
865 set as_flags "$abi_asflags($abi) --defsym filter=$filter"
866 append as_flags " --defsym micromips=$micromips --defsym $abi=1"
867 if {[string equal $abi o32]} {
868 append as_flags " -march=mips2"
869 }
870 set ld_flags "$abi_ldflags($abi) -T compressed-plt-1.ld"
871 set dynobj "tmpdir/compressed-plt-1-${abi}-dyn.so"
872 set files [list]
873 if { $filter & 3 } {
874 lappend files compressed-plt-1a.s
875 }
876 if { $filter & 12 } {
877 lappend files compressed-plt-1b.s
878 }
879 if { $filter & 16 } {
880 lappend files compressed-plt-1c.s
881 }
882 eval [list lappend files] $extra
883 set readelf_flags "-A --syms --relocs -d"
884 if { [string match "*word*" $suffix] } {
885 append readelf_flags " -x.data"
886 }
887 set objdump_flags "-d -Mgpr-names=numeric"
888 set basename "compressed-plt-1-${abi}-${suffix}"
889 run_ld_link_tests [list \
890 [list "$name" $ld_flags $dynobj \
891 "$as_flags" $files \
892 [list [list readelf $readelf_flags ${basename}.rd] \
893 [list objdump $objdump_flags ${basename}.od]] \
894 $basename]]
895 }
896
897 if { $linux_gnu } {
898 build_mips_plt_lib o32
899 run_mips_plt_test "o32 PLTs for standard encoding" o32 28 0 se
900 run_mips_plt_test "o32 PLTs for MIPS16 encoding" o32 19 0 mips16-only
901 run_mips_plt_test "o32 PLTs for microMIPS encoding" o32 19 1 umips-only
902 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16" \
903 o32 -1 0 mips16
904 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with %got" \
905 o32 -1 0 mips16-got compressed-plt-1d.s
906 run_mips_plt_test "o32 PLTs for mixed MIPS and MIPS16 with .word" \
907 o32 -1 0 mips16-word compressed-plt-1e.s
908 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS" \
909 o32 -1 1 umips
910 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with %got" \
911 o32 -1 1 umips-got compressed-plt-1d.s
912 run_mips_plt_test "o32 PLTs for mixed MIPS and microMIPS with .word" \
913 o32 -1 1 umips-word compressed-plt-1e.s
914
915 if $has_newabi {
916 build_mips_plt_lib n32
917 run_mips_plt_test "n32 PLTs for mixed MIPS and MIPS16" \
918 n32 -1 0 mips16
919 run_mips_plt_test "n32 PLTs for mixed MIPS and microMIPS" \
920 n32 -1 1 umips
921 }
922 }
923
924 # PR ld/19908 export class tests.
925 if { $linux_gnu } {
926 run_ld_link_tests [list \
927 [list "Shared library for MIPS export class symbol reference tests" \
928 "$abi_ldflags(o32) -shared" "" \
929 "$abi_asflags(o32)" \
930 { export-class-ref-f2.s } \
931 { { readelf --dyn-syms export-class-ref-lib.sd } } \
932 "export-class-ref-lib.so"]]
933 foreach { class flag } { internal 1 hidden 2 protected 3 } {
934 run_ld_link_tests [list \
935 [list "MIPS $class symbol reference test 1" \
936 "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
937 "$abi_asflags(o32) --defsym defv=$flag" \
938 { export-class-ref-f0.s export-class-ref-f1.s } \
939 [list [list readelf --dyn-syms export-$class-ref.sd] \
940 [list readelf --dyn-syms export-local-ref.sd]] \
941 "export-$class-ref"] \
942 [list "MIPS $class symbol reference test 2" \
943 "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
944 "$abi_asflags(o32) --defsym defv=$flag --defsym refv=$flag" \
945 { export-class-ref-f0.s export-class-ref-f1.s } \
946 [list [list readelf --dyn-syms export-$class-ref.sd] \
947 [list readelf --dyn-syms export-local-ref.sd]] \
948 "export-$class-ref"]]
949 }
950 }