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