9579df653ea31340505eae33975240b247741363
[external/binutils.git] / ld / testsuite / ld-i386 / i386.exp
1 # Expect script for ld-i386 tests
2 #   Copyright (C) 2002-2019 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 global ASFLAGS
23 set saved_ASFLAGS "$ASFLAGS"
24 if { [is_elf_format] \
25      && ([istarget "i?86-*-*"] || [istarget "x86_64-*-*"]) } {
26     set ASFLAGS "$ASFLAGS -mx86-used-note=no"
27 }
28
29 # Test i386 linking; all types of relocs.  This tests the assembler and
30 # tools like objdump as well as the linker.
31
32 if {[istarget "i?86-*-vxworks"]} {
33     set i386tests {
34         {"VxWorks shared library test 1"
35          "-shared -Tvxworks1.ld --hash-style=sysv" ""
36          "" {vxworks1-lib.s}
37          {{readelf --relocs vxworks1-lib.rd} {objdump -dr vxworks1-lib.dd}
38           {readelf --symbols vxworks1-lib.nd} {readelf -d vxworks1-lib.td}}
39          "libvxworks1.so"}
40         {"VxWorks executable test 1 (dynamic)" \
41          "tmpdir/libvxworks1.so -Tvxworks1.ld --hash-style=sysv -q --force-dynamic" ""
42          "" {vxworks1.s}
43          {{readelf --relocs vxworks1.rd} {objdump -dr vxworks1.dd}}
44          "vxworks1"}
45         {"VxWorks executable test 2 (dynamic)" \
46          "-Tvxworks1.ld --hash-style=sysv -q --force-dynamic" ""
47          "" {vxworks2.s}
48          {{readelf --segments vxworks2.sd}}
49          "vxworks2"}
50         {"VxWorks executable test 2 (static)"
51          "-Tvxworks1.ld --hash-style=sysv" ""
52          "" {vxworks2.s}
53          {{readelf --segments vxworks2-static.sd}}
54          "vxworks2"}
55     }
56     run_ld_link_tests $i386tests
57     run_dump_test "vxworks1-static"
58 }
59
60 if [istarget "*-*-go32*"] {
61     run_ld_link_tests {{"go32 stub" "" "" "" {zero.s} {} "go32stub"}}
62
63     set src "tmpdir/go32stub"
64     set dest "tmpdir/go32stub-copy"
65
66     set test "go32 stub patch the source"
67     set fi [open $src r+]
68     fconfigure $fi -translation binary
69     if {[read $fi 2] != "MZ"} {
70         fail $test
71     } else {
72         pass $test
73         seek $fi 0x40
74         puts -nonewline $fi "objcopy-test-go32stub"
75     }
76     close $fi
77
78     set test "go32 stub objcopy"
79     set status [remote_exec build $OBJCOPY "$OBJCOPYFLAGS $src $dest"]
80     set exec_output [lindex $status 1]
81     set exec_output [prune_warnings $exec_output]
82     if [string match "" $exec_output] then {
83         pass $test
84     } else {
85         send_log "$exec_output\n"
86         verbose "$exec_output" 1
87         fail $test
88     }
89
90     # cmp would compare the whole files and some data after the initial exe
91     # stub could differ.
92     set test "go32 stub comparison after objcopy"
93     set fi [open $src]
94     fconfigure $fi -translation binary
95     set src_stub [read $fi 2048]
96     close $fi
97     set fi [open $dest]
98     fconfigure $fi -translation binary
99     set dest_stub [read $fi 2048]
100     close $fi
101     if {$src_stub == $dest_stub} {
102         pass $test
103     } else {
104         fail $test
105     }
106 }
107
108 if { !([istarget "i?86-*-elf*"]
109        || [istarget "i?86-*-linux*"]
110        || [istarget "i?86-*-gnu*"]
111        || [istarget "i?86-*-nacl*"]
112        || [istarget "x86_64-*-elf*"]
113        || [istarget "x86_64-*-nacl*"]
114        || [istarget "x86_64-*-linux*"]
115        || [istarget "amd64-*-linux*"]) } {
116     return
117 }
118
119 # List contains test-items with 3 items followed by 2 lists:
120 # 0:name 1:ld early options 2:ld late options 3:assembler options
121 # 4:filenames of assembler files 5: action and options. 6: name of output file
122
123 # Actions:
124 # objdump: Apply objdump options on result.  Compare with regex (last arg).
125 # nm: Apply nm options on result.  Compare with regex (last arg).
126 # readelf: Apply readelf options on result.  Compare with regex (last arg).
127
128 set i386tests {
129     {"Helper shared library (basic PLT test)"
130       "-shared -melf_i386" "" "--32" {pltlib.s} {} "libpltlib.so"}
131     {"basic PLT generation (non-PIC)"
132      "-melf_i386 tmpdir/libpltlib.so" "" "--32" {plt.s}
133      {{objdump -drj.plt plt.pd}} "plt"}
134     {"basic PLT generation (PIC)"
135      "-shared -melf_i386 tmpdir/libpltlib.so" "" "--32" {plt-pic.s}
136      {{objdump -drj.plt plt-pic.pd}} "libplt-pic.so"}
137     {"TLS -fpic -shared transitions"
138      "-shared -melf_i386 --no-ld-generated-unwind-info \
139       -z noseparate-code --hash-style=sysv" ""
140      "--32" {tlspic1.s tlspic2.s}
141      {{readelf -Ssrl tlspic.rd} {objdump -drj.text tlspic.dd}
142       {objdump -sj.got tlspic.sd} {objdump -sj.tdata tlspic.td}}
143       "libtlspic.so"}
144     {"TLS -fpic -shared transitions without PLT"
145      "-shared -melf_i386 --no-ld-generated-unwind-info \
146       -z noseparate-code --hash-style=sysv" ""
147      "-mrelax-relocations=yes --32"
148      {tlspic3.s tlspic2.s}
149      {{readelf -Ssrl tlspic2.rd} {objdump -drj.text tlspic2.dd}
150       {objdump -sj.got tlspic2.sd} {objdump -sj.tdata tlspic2.td}}
151       "libtlspic2.so"}
152     {"TLS descriptor -fpic -shared transitions"
153      "-shared -melf_i386 --no-ld-generated-unwind-info \
154       -z noseparate-code --hash-style=sysv" ""
155      "--32" {tlsdesc.s tlspic2.s}
156      {{readelf -Ssrl tlsdesc.rd} {objdump -drj.text tlsdesc.dd}
157       {objdump "-s -j.got -j.got.plt" tlsdesc.sd} {objdump -sj.tdata tlsdesc.td}}
158       "libtlsdesc.so"}
159     {"Helper shared library" "-shared -melf_i386" ""
160      "--32" {tlslib.s} {} "libtlslib.so"}
161     {"TLS -fpic and -fno-pic exec transitions"
162      "-melf_i386 tmpdir/libtlslib.so --no-ld-generated-unwind-info \
163       -z noseparate-code --hash-style=sysv" ""
164      "--32" {tlsbinpic.s tlsbin.s}
165      {{readelf -Ssrl tlsbin.rd} {objdump -drj.text tlsbin.dd}
166       {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}}
167       "tlsbin"}
168     {"TLS -fpic and -fno-pic exec transitions without PLT"
169      "-melf_i386 tmpdir/libtlslib.so --no-ld-generated-unwind-info \
170       -z noseparate-code --hash-style=sysv" ""
171      "-mrelax-relocations=yes --32"
172      {tlsbinpic2.s tlsbin.s}
173      {{readelf -Ssrl tlsbin2.rd} {objdump -drj.text tlsbin2.dd}
174       {objdump -sj.got tlsbin2.sd} {objdump -sj.tdata tlsbin2.td}}
175       "tlsbin2"}
176     {"TLS descriptor -fpic and -fno-pic exec transitions"
177      "-melf_i386 tmpdir/libtlslib.so --no-ld-generated-unwind-info \
178       -z noseparate-code --hash-style=sysv" ""
179      "--32" {tlsbindesc.s tlsbin.s}
180      {{readelf -Ssrl tlsbindesc.rd} {objdump -drj.text tlsbindesc.dd}
181       {objdump -sj.got tlsbindesc.sd} {objdump -sj.tdata tlsbindesc.td}}
182       "tlsbindesc"}
183     {"TLS -fno-pic -shared"
184      "-shared -melf_i386 --no-ld-generated-unwind-info \
185       -z noseparate-code --hash-style=sysv" ""
186      "--32" {tlsnopic1.s tlsnopic2.s}
187      {{readelf -Ssrl tlsnopic.rd} {objdump -drj.text tlsnopic.dd}
188       {objdump -sj.got tlsnopic.sd}} "libtlsnopic.so"}
189     {"TLS with global dynamic and descriptors"
190      "-shared -melf_i386 --no-ld-generated-unwind-info \
191       -z noseparate-code --hash-style=sysv" ""
192      "--32" {tlsgdesc.s}
193      {{readelf -Ssrl tlsgdesc.rd} {objdump -drj.text tlsgdesc.dd}}
194       "libtlsgdesc.so"}
195     {"TLS in debug sections" "-melf_i386" ""
196      "--32" {tlsg.s}
197      {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}
198     {"TLS @indntpoff with %eax" "-melf_i386" "" "--32" {tlsindntpoff.s}
199      {{objdump -drj.text tlsindntpoff.dd}} "tlsindntpoff"}
200     {"Reloc section order" "-shared -melf_i386 -z nocombreloc" "" "--32"
201      {reloc.s} {{objdump -hw reloc.d}} "reloc.so"}
202     {"Basic --emit-relocs support" "-shared -melf_i386 --emit-relocs" "" "--32"
203      {emit-relocs.s} {{readelf --relocs emit-relocs.rd}} "emit-relocs.so"}
204     {"-z combreloc relocation sections" "-shared -melf_i386 -z combreloc" ""
205      "--32" {combreloc.s} {{readelf -r combreloc.d}} "combreloc.so"}
206     {"TLS GD->LE transition" "-melf_i386" ""
207      "--32" {tlsgd1.s}
208      {{objdump -dwr tlsgd1.dd}} "tlsgd1"}
209     {"TLS GD->LE transition without PLT" "-melf_i386" ""
210      "-mrelax-relocations=yes --32"
211      {tlsgd3.s}
212      {{objdump -dwr tlsgd3.dd}} "tlsgd3"}
213     {"TLS LD->LE transition" "-melf_i386" ""
214      "--32" {tlsld1.s}
215      {{objdump -dwr tlsld1.dd}} "tlsld1"}
216     {"TLS LD->LE transition without PLT" "-melf_i386" ""
217      "-mrelax-relocations=yes --32"
218      {tlsld2.s}
219      {{objdump -dwr tlsld2.dd}} "tlsld2"}
220     {"TLS IE->LE transition" "-melf_i386" ""
221      "--32" {tlsie1.s}
222      {{objdump -dwr tlsie1.dd}} "tlsie1"}
223     {"PR ld/17313 (1)" "-melf_i386" ""
224      "--32 -mx86-used-note=yes" {zero.s} {} ""}
225     {"PR ld/17313 (2)" "-melf_i386 -shared --just-symbols=tmpdir/zero.o" ""
226      "--32 -mx86-used-note=yes" {lea1.s} {} "libpr17313.so"}
227     {"PR ld/17306 (1)" "-melf_i386" ""
228      "--32 -mx86-used-note=yes" {pr17306b.s} {} ""}
229     {"PR ld/17306 (2)" "-melf_i386 -shared -Bsymbolic --just-symbols=tmpdir/pr17306b.o" ""
230      "--32 -mx86-used-note=yes" {pr17306a.s} {} "libpr17306.so"}
231     {"PR ld/17709 (1)" "-melf_i386 -shared" ""
232      "--32 -mx86-used-note=yes" {pr17709a.s} {} "libpr17709.so"}
233     {"PR ld/17709 (2)" "-melf_i386 tmpdir/libpr17709.so" ""
234      "--32 -mx86-used-note=yes"
235      {pr17709b.s} {{readelf -r pr17709.rd}} "pr17709"}
236     {"Build pr19827a.o" "" ""
237      "--32 -mx86-used-note=yes" { pr19827a.S }}
238     {"Build pr19827b.so" "-melf_i386 -shared" ""
239      "--32 -mx86-used-note=yes"
240      { pr19827b.S } {} "pr19827b.so"}
241     {"Build pr19827" "-melf_i386 -pie tmpdir/pr19827a.o tmpdir/pr19827b.so" ""
242      "--32 -mx86-used-note=yes"
243      { dummy.s } {{readelf {-rW} pr19827.rd}} "pr19827"}
244     {"Build pr19827.so" "-melf_i386 -shared -Bsymbolic" ""
245      "--32 -mx86-used-note=yes"
246      { pr19827a.S }  {{readelf {-rW} pr19827.rd}} "pr19827.so"}
247 }
248
249 # So as to avoid rewriting every last test case here in a nacl variant,
250 # we use black magic to massage the generic cases into nacl-variant cases.
251 if [istarget "*-*-nacl*"] {
252     # Change all the -melf_i386 to -melf_i386_nacl so linking can succeed.
253     regsub -all elf_i386 $i386tests elf_i386_nacl i386tests
254
255     # Same, applied to all the run_dump_test cases.
256     set options_regsub(ld) {elf_i386 elf_i386_nacl}
257
258     # The section/segment layout differs too much for the vanilla
259     # readelf output files to match.  So massage the cases so that
260     # they refer to a foo-nacl.rd file instead of a foo.rd file.
261     regsub -all {([a-z0-9]+)\.rd} $i386tests {\1-nacl.rd} i386tests
262
263     # Likewise for PLTs.
264     regsub -all -- {([a-z0-9]+)\.pd} $i386tests {\1-nacl.pd} i386tests
265 }
266
267 proc iamcu_tests {} {
268     if {[istarget "*-*-nacl*"]} then {
269         return
270     }
271
272     global as
273     global srcdir
274     global subdir
275
276     if ![ld_assemble $as "--32 -march=iamcu $srcdir/$subdir/start.s" tmpdir/startiamcu.o] {
277         unresolved "Build Intel MCU start.o"
278         return
279     }
280
281     if ![ld_assemble $as "--32 $srcdir/$subdir/start.s" tmpdir/start32.o] {
282         unresolved "Build ia32 start.o"
283         return
284      }
285
286     if ![ld_assemble $as "--32 -march=iamcu $srcdir/$subdir/foo.s" tmpdir/fooiamcu.o] {
287         unresolved "Build Intel MCU foo.o"
288         return
289     }
290
291     if ![ld_assemble $as "--32 $srcdir/$subdir/foo.s" tmpdir/foo32.o] {
292         unresolved "Build ia32 foo.o"
293         return
294     }
295
296     run_dump_test "abs-iamcu"
297     run_dump_test "iamcu-1"
298     run_dump_test "iamcu-2"
299     run_dump_test "iamcu-3"
300     run_dump_test "iamcu-4"
301 }
302
303 iamcu_tests
304
305 run_ld_link_tests $i386tests
306
307 run_dump_test "abs"
308 run_dump_test "pcrel8"
309 run_dump_test "pcrel16"
310 run_dump_test "pcrel16abs"
311 run_dump_test "alloc"
312 run_dump_test "warn1"
313 run_dump_test "tlsgd2"
314 run_dump_test "tlsgd4"
315 run_dump_test "tlsie2"
316 run_dump_test "tlsie3"
317 run_dump_test "tlsie4"
318 run_dump_test "tlsie5"
319 run_dump_test "hidden1"
320 run_dump_test "hidden2"
321 run_dump_test "hidden3"
322 run_dump_test "protected1"
323 run_dump_test "protected2"
324 run_dump_test "protected3"
325 run_dump_test "protected4"
326 run_dump_test "protected5"
327 run_dump_test "protected6a"
328 run_dump_test "protected6b"
329 run_dump_test "protected7"
330 run_dump_test "tlspie1"
331 run_dump_test "tlspie2"
332 run_dump_test "tlspie3a"
333 run_dump_test "tlspie3b"
334 run_dump_test "tlspie3c"
335 run_dump_test "nogot1"
336 run_dump_test "nogot2"
337 run_dump_test "discarded1"
338 run_dump_test "pr12718"
339 run_dump_test "pr12921"
340 run_dump_test "pr12570a"
341 run_dump_test "pr12570b"
342 run_dump_test "lea1a"
343 run_dump_test "lea1b"
344 run_dump_test "lea1c"
345 run_dump_test "lea1d"
346 run_dump_test "lea1e"
347 run_dump_test "lea1f"
348 run_dump_test "mov1a"
349 run_dump_test "mov1b"
350 run_dump_test "mov2a"
351 run_dump_test "mov2b"
352 run_dump_test "mov3"
353 run_dump_test "branch1"
354 run_dump_test "call1"
355 run_dump_test "call2"
356 run_dump_test "call3a"
357 run_dump_test "call3b"
358 run_dump_test "call3c"
359 run_dump_test "call3d"
360 run_dump_test "call3e"
361 run_dump_test "call3f"
362 run_dump_test "call3g"
363 run_dump_test "call3h"
364 run_dump_test "jmp1"
365 run_dump_test "jmp2"
366 run_dump_test "load1"
367 run_dump_test "load1-nacl"
368 run_dump_test "load2"
369 run_dump_test "load3"
370 run_dump_test "load4a"
371 run_dump_test "load4b"
372 run_dump_test "load5a"
373 run_dump_test "load5b"
374 run_dump_test "load6"
375 run_dump_test "load7"
376 run_dump_test "pr19175"
377 run_dump_test "pr19615"
378 run_dump_test "pr19636-1a"
379 run_dump_test "pr19636-1b"
380 run_dump_test "pr19636-1c"
381 run_dump_test "pr19636-1d"
382 run_dump_test "pr19636-1d-nacl"
383 run_dump_test "pr19636-1e"
384 run_dump_test "pr19636-1f"
385 run_dump_test "pr19636-1g"
386 run_dump_test "pr19636-1h"
387 run_dump_test "pr19636-1i"
388 run_dump_test "pr19636-1j"
389 run_dump_test "pr19636-1k"
390 run_dump_test "pr19636-1l"
391 run_dump_test "pr19636-2a"
392 run_dump_test "pr19636-2b"
393 run_dump_test "pr19636-2c"
394 run_dump_test "pr19636-2c-nacl"
395 run_dump_test "pr19636-2d"
396 run_dump_test "pr19636-2d-nacl"
397 run_dump_test "pr19636-2e"
398 run_dump_test "pr19636-2e-nacl"
399 run_dump_test "pr19636-3a"
400 run_dump_test "pr19636-3b"
401 run_dump_test "pr19636-3c"
402 run_dump_test "pr19636-3d"
403 run_dump_test "pr19636-3e"
404 run_dump_test "pr19636-3f"
405 run_dump_test "pr19636-3g"
406 run_dump_test "pr19636-3h"
407 run_dump_test "pr19636-3i"
408 run_dump_test "pr19636-4a"
409 run_dump_test "pr19636-4b"
410 run_dump_test "pr19636-4c"
411 run_dump_test "pr19636-4d"
412 run_dump_test "pr19645"
413 run_dump_test "pr19609-1a"
414 run_dump_test "pr19609-1b"
415 run_dump_test "pr19609-1c"
416 run_dump_test "pr19609-1d"
417 run_dump_test "pr19609-1e"
418 run_dump_test "pr19609-1f"
419 run_dump_test "pr19609-1g"
420 run_dump_test "pr19609-1h"
421 run_dump_test "pr19609-1i"
422 run_dump_test "pr19609-2a"
423 run_dump_test "pr19609-2b"
424 run_dump_test "pr19609-2c"
425 run_dump_test "undefweaka"
426 run_dump_test "undefweakb"
427 run_dump_test "pr19539"
428 run_dump_test "pr20117"
429 run_dump_test "pr20244-1a"
430 run_dump_test "pr20244-1b"
431 run_dump_test "pr20244-1c"
432 run_dump_test "pr20244-2a"
433 run_dump_test "pr20244-2b"
434 run_dump_test "pr20244-2c"
435 run_dump_test "pr20244-2d"
436 run_dump_test "pr20244-4a"
437 run_dump_test "pr20244-4b"
438 run_dump_test "pr20244-4c"
439 run_dump_test "pr20253-3"
440 run_dump_test "pr20253-4a"
441 run_dump_test "pr20253-4b"
442 run_dump_test "pr20253-4c"
443 run_dump_test "pr20253-5"
444 run_dump_test "pr20515"
445 run_dump_test "property-x86-3"
446 run_dump_test "property-x86-4a"
447 run_dump_test "property-x86-4b"
448 run_dump_test "property-x86-5"
449 run_dump_test "property-x86-ibt1a"
450 run_dump_test "property-x86-ibt1b"
451 run_dump_test "property-x86-ibt2"
452 run_dump_test "property-x86-ibt3a"
453 run_dump_test "property-x86-ibt3b"
454 run_dump_test "property-x86-ibt4"
455 run_dump_test "property-x86-ibt5"
456 run_dump_test "property-x86-shstk1a"
457 run_dump_test "property-x86-shstk1b"
458 run_dump_test "property-x86-shstk2"
459 run_dump_test "property-x86-shstk3a"
460 run_dump_test "property-x86-shstk3b"
461 run_dump_test "property-x86-shstk4"
462 run_dump_test "property-x86-shstk5"
463 run_dump_test "property-x86-cet1"
464 run_dump_test "property-x86-cet2a"
465 run_dump_test "property-x86-cet2b"
466 run_dump_test "property-x86-cet3a"
467 run_dump_test "property-x86-cet3b"
468 run_dump_test "property-x86-cet4a"
469 run_dump_test "property-x86-cet4b"
470 run_dump_test "property-x86-cet5a"
471 run_dump_test "property-x86-cet5b"
472 run_dump_test "property-x86-cet6"
473 run_dump_test "pie1"
474 run_dump_test "pie1-nacl"
475 run_dump_test "pr21884"
476 run_dump_test "pr21884-nacl"
477 run_dump_test "pr22115-1a"
478 run_dump_test "pr22115-1b"
479 run_dump_test "pr22115-1c"
480 run_dump_test "pr22115-1d"
481 run_dump_test "pr22135"
482 run_dump_test "pr22782"
483 run_dump_test "pr22929"
484 run_dump_test "pr23189"
485 run_dump_test "pr23194"
486 run_dump_test "pr23372a"
487 run_dump_test "pr23372b"
488 run_dump_test "pr23372c"
489 run_dump_test "pr23372d"
490 run_dump_test "pr23486a"
491 run_dump_test "pr23486b"
492 run_dump_test "pr23486c"
493 run_dump_test "pr23486d"
494 run_dump_test "pr23854"
495 run_dump_test "pr23930"
496 run_dump_test "pr24322a"
497 run_dump_test "pr24322b"
498
499 if { !([istarget "i?86-*-linux*"]
500        || [istarget "i?86-*-gnu*"]
501        || [istarget "i?86-*-nacl*"]
502        || [istarget "x86_64-*-nacl*"]
503        || [istarget "x86_64-*-linux*"]) } {
504     set ASFLAGS "$saved_ASFLAGS"
505     return
506 }
507
508 run_dump_test "compressed1"
509 run_dump_test "pr12627"
510 run_dump_test "pr13302"
511 run_dump_test "pr14215"
512 run_dump_test "pr17057"
513 run_dump_test "pr17935-1"
514 run_dump_test "pr17935-2"
515 run_dump_test "pr18801a"
516 run_dump_test "pr18801b"
517 run_dump_test "pr18815"
518 run_dump_test "pr19939a"
519 run_dump_test "pr19939b"
520 run_dump_test "tlsdesc2"
521
522 proc undefined_weak {cflags ldflags} {
523     set testname "Undefined weak symbol"
524     if { ![ string match "" $cflags$ldflags] } {
525         set testname "$testname ($cflags $ldflags)"
526     }
527
528     if { [string match "*-fPIE*" $cflags]
529          && ![string match "*-z nodynamic-undefined-weak*" $ldflags] } {
530         set weak_symbol "Weak defined"
531     } else {
532         set weak_symbol "Weak undefined"
533     }
534
535     run_cc_link_tests [list \
536         [list \
537             "Build libpr19704a.so" \
538             "-shared -Wl,-soname,libpr19704.so" \
539             "-Wa,-mrelax-relocations=yes" \
540             { dummy.s } \
541             {} \
542             "libpr19704a.so" \
543         ] \
544         [list \
545             "Build libpr19704b.so" \
546             "-shared -Wl,-soname,libpr19704.so" \
547             "-fPIC -Wa,-mrelax-relocations=yes" \
548             { pr19704b.c } \
549             {} \
550             "libpr19704b.so" \
551         ] \
552     ]
553
554     exec cp tmpdir/libpr19704a.so tmpdir/libpr19704.so
555
556     run_ld_link_exec_tests [list \
557         [list \
558             "Run pr19704" \
559             "$ldflags tmpdir/libpr19704.so -Wl,-R,tmpdir" \
560             "-Wa,-mrelax-relocations=yes" \
561             { pr19704a.c } \
562             "pr19704" \
563             "pr19704.out" \
564             "$cflags" \
565         ] \
566     ]
567
568     exec cp tmpdir/libpr19704b.so tmpdir/libpr19704.so
569
570     set exec_output [run_host_cmd tmpdir/pr19704 ""]
571     if {![string match $weak_symbol $exec_output]} {
572         fail $testname
573     } else {
574         pass $testname
575     }
576 }
577
578 # Add $PLT_CFLAGS if PLT is expected.
579 global PLT_CFLAGS
580
581 # Must be Linux native with the C compiler
582 if { [isnative]
583      && [istarget "i?86-*-linux*"]
584      && [which $CC] != 0 } {
585     run_cc_link_tests [list \
586         [list \
587             "Build plt-lib.so" \
588             "-shared" \
589             "-fPIC -Wa,-mrelax-relocations=yes" \
590             { plt-lib.c } \
591             {} \
592             "libplt-lib.so" \
593         ] \
594         [list \
595             "Build libplt-main1.a" \
596             "" \
597             "-fPIC -Wa,-mrelax-relocations=yes,-mrelax-relocations=yes" \
598             { plt-main1.c } \
599             {{readelf {-Wr} plt-main1.rd}} \
600             "libplt-main1.a" \
601         ] \
602         [list \
603             "Build libplt-main2.a" \
604             "" \
605             "-fPIC -Wa,-mrelax-relocations=yes,-mrelax-relocations=yes" \
606             { plt-main2.c } \
607             {{readelf {-Wr} plt-main2.rd}} \
608             "libplt-main2.a" \
609         ] \
610         [list \
611             "Build libplt-main3.a" \
612             "" \
613             "-fPIC -Wa,-mrelax-relocations=yes,-mrelax-relocations=yes $PLT_CFLAGS" \
614             { plt-main3.c } \
615             {{readelf {-Wr} plt-main3.rd}} \
616             "libplt-main3.a" \
617         ] \
618         [list \
619             "Build libplt-main4.a" \
620             "" \
621             "-fPIC -Wa,-mrelax-relocations=yes,-mrelax-relocations=yes $PLT_CFLAGS" \
622             { plt-main4.c } \
623             {{readelf {-Wr} plt-main4.rd}} \
624             "libplt-main4.a" \
625         ] \
626         [list \
627             "Build plt-main" \
628             "tmpdir/plt-main1.o tmpdir/plt-main2.o tmpdir/plt-main3.o \
629              tmpdir/plt-main4.o tmpdir/libplt-lib.so" \
630             "-Wa,-mrelax-relocations=yes" \
631             { plt-main5.c } \
632             {{readelf {-Wr} plt-main.rd}} \
633             "plt-main" \
634         ] \
635         [list \
636             "Build plt-main with PIE" \
637             "tmpdir/plt-main1.o tmpdir/plt-main2.o tmpdir/plt-main3.o \
638              tmpdir/plt-main4.o tmpdir/libplt-lib.so -pie" \
639             "-fPIC -Wa,-mrelax-relocations=yes" \
640             { plt-main5.c } \
641             {{readelf {-Wr} plt-main.rd}} \
642             "plt-main" \
643         ] \
644         [list \
645             "Build copyreloc-lib.so" \
646             "-shared" \
647             "-fPIC -Wa,-mrelax-relocations=yes" \
648             { copyreloc-lib.c } \
649             {} \
650             "copyreloc-lib.so" \
651         ] \
652         [list \
653             "Build libcopyreloc-main.a" \
654             "" \
655             "-Wa,-mrelax-relocations=yes" \
656             { copyreloc-main.S } \
657             {} \
658             "libcopyreloc-main.a" \
659         ] \
660         [list \
661             "Build copyreloc-main with PIE and GOTOFF (1)" \
662             "tmpdir/copyreloc-main.o tmpdir/copyreloc-lib.so -pie" \
663             "-Wa,-mrelax-relocations=yes" \
664             { dummy.s } \
665             {{readelf {-Wr} copyreloc-main1.rd}} \
666             "copyreloc-main" \
667         ] \
668         [list \
669             "Build copyreloc-main with PIE and GOTOFF (2)" \
670             "tmpdir/copyreloc-main.o tmpdir/copyreloc-lib.so -pie" \
671             "-Wa,-mrelax-relocations=yes" \
672             { dummy.s } \
673             {{readelf {-Wr} copyreloc-main2.rd}} \
674             "copyreloc-main" \
675         ] \
676         [list \
677             "Build pr17689.so" \
678             "-shared" \
679             "-fPIC -Wa,-mrelax-relocations=yes" \
680             { pr17689a.c } \
681             {} \
682             "pr17689.so" \
683         ] \
684         [list \
685             "Build pr17689.so with -z now" \
686             "-shared -Wl,-z,now" \
687             "-fPIC -Wa,-mrelax-relocations=yes" \
688             { pr17689a.c } \
689             {{readelf {-Wr} pr17689now.rd}} \
690             "pr17689now.so" \
691         ] \
692         [list \
693             "Build pr17689ver.so" \
694             "-shared -Wl,--version-script,pr17689a.t" \
695             "-fPIC -Wa,-mrelax-relocations=yes" \
696             { pr17689a.c } \
697             {} \
698             "pr17689ver.so" \
699         ] \
700         [list \
701             "Build pr17689.a" \
702             "" \
703             "-Wa,-mrelax-relocations=yes" \
704             { pr17689b.S } \
705             {} \
706             "pr17689.a" \
707         ] \
708         [list \
709             "Build pr17689 with PIE and GOTOFF" \
710             "tmpdir/pr17689b.o tmpdir/pr17689.so -pie" \
711             "-Wa,-mrelax-relocations=yes" \
712             { dummy.c } \
713             {{readelf {-Wr} pr17689.rd}} \
714             "pr17689" \
715         ] \
716         [list \
717             "Build pr17689 with PIE, -z now and GOTOFF" \
718             "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,now" \
719             "-Wa,-mrelax-relocations=yes" \
720             { dummy.c } \
721             {{readelf {-Wr} pr17689now.rd}} \
722             "pr17689now" \
723         ] \
724         [list \
725             "Build pr17689ver with PIE and GOTOFF" \
726             "tmpdir/pr17689b.o tmpdir/pr17689ver.so -pie" \
727             "-Wa,-mrelax-relocations=yes" \
728             { dummy.c } \
729             {{readelf {-Wr} pr17689ver.rd}} \
730             "pr17689ver" \
731         ] \
732         [list \
733             "Build pr17827 with PIE and GOTOFF" \
734             "tmpdir/pr17689b.o tmpdir/pr17689.so -pie" \
735             "-Wa,-mrelax-relocations=yes" \
736             { dummy.c } \
737             {{readelf {-Wr} pr17827.rd}} \
738             "pr17827" \
739         ] \
740         [list \
741             "Build pr18900.so" \
742             "-shared" \
743             "-fPIC -Wa,-mrelax-relocations=yes" \
744             { pr18900a.c } \
745             "" \
746             "pr18900.so" \
747         ] \
748         [list \
749             "Build pr18900.o" \
750             "-r -nostdlib" \
751             "-Wa,-mrelax-relocations=yes" \
752             { pr18900b.c pr18900c.c } \
753             "" \
754             "pr18900.o" \
755         ] \
756         [list \
757             "Build pr18900a" \
758             "tmpdir/pr18900.o tmpdir/pr18900.so" \
759             "-Wa,-mrelax-relocations=yes" \
760             { dummy.s } \
761             {{readelf {-Wrd} pr18900a.rd}} \
762             "pr18900a" \
763         ] \
764         [list \
765             "Build pr18900b" \
766             "-Wl,--as-needed tmpdir/pr18900.o tmpdir/pr18900.so" \
767             "-Wa,-mrelax-relocations=yes" \
768             { dummy.s } \
769             {{readelf {-Wrd} pr18900b.rd}} \
770             "pr18900b" \
771         ] \
772         [list \
773             "Build pr19031.so" \
774             "-shared" \
775             "-fPIC -Wa,-mrelax-relocations=yes" \
776             { pr19031a.c } \
777             "" \
778             "pr19031.so" \
779         ] \
780         [list \
781             "Build got1d.so" \
782             "-shared" \
783             "-Wa,-mrelax-relocations=yes" \
784             { got1d.S } \
785             "" \
786             "got1d.so" \
787         ] \
788         [list \
789             "Build gotpc1.o" \
790             "-r -nostdlib" \
791             "-Wa,-mrelax-relocations=yes" \
792             { got1a.S got1b.c got1c.c } \
793             "" \
794             "gotpc1.o" \
795         ] \
796         [list \
797             "Build gotpc1" \
798             "$NOPIE_LDFLAGS -Wl,--as-needed tmpdir/gotpc1.o tmpdir/got1d.so" \
799             "-Wa,-mx86-used-note=no" \
800             { dummy.s } \
801             {{objdump {-dw} got1.dd}} \
802             "got1" \
803         ] \
804         [list \
805             "Build pr19319.so" \
806             "-shared" \
807             "-Wa,-mx86-used-note=no" \
808             { pr19319a.S } \
809             "" \
810             "pr19319.so" \
811         ] \
812         [list \
813             "Build pr19319" \
814             "-pie -nostdlib -nostartfiles tmpdir/pr19319.so" \
815             "-Wa,-mrelax-relocations=yes" \
816             { pr19319b.S } \
817             {{objdump {-dw} pr19319.dd}} \
818             "pr19319" \
819         ] \
820         [list \
821             "Build pr24276.so" \
822             "-shared -nostdlib -nostartfiles \
823              -Ltmpdir $srcdir/$subdir/pr24276.dso" \
824             "-Wa,-mx86-used-note=yes" \
825             { pr19319b.S } \
826             {{warning_output pr24276.warn}} \
827             "pr24276.so" \
828         ] \
829         [list \
830             "Build property 1" \
831             "" \
832             "-Wa,-mx86-used-note=no" \
833             {pass.c property-no-copy.S} \
834             {{readelf {-n} property-1.r}} \
835             "property-1" \
836         ] \
837         [list \
838             "Build property 1 (.o)" \
839             "-r -nostdlib" \
840             "-Wa,-mx86-used-note=yes" \
841             {pass.c property-no-copy.S} \
842             {{readelf {-n} property-1a.r}} \
843             "property-1.o" \
844         ] \
845         [list \
846             "Build property 1 (.so)" \
847             "-shared" \
848             "-fPIC -Wa,-mx86-used-note=no" \
849             {pass.c property-no-copy.S} \
850             {{readelf {-n} property-1.r}} \
851             "property-1.so" \
852         ] \
853         [list \
854             "Build property 2" \
855             "" \
856             "-Wa,-mx86-used-note=no" \
857             {pass.c property-stack.S} \
858             {{readelf {-n} property-2.r}} \
859             "property-2" \
860         ] \
861         [list \
862             "Build property 2 (.o)" \
863             "-r -nostdlib" \
864             "-Wa,-mx86-used-note=yes" \
865             {pass.c property-stack.S} \
866             {{readelf {-n} property-2a.r}} \
867             "property-2.o" \
868         ] \
869         [list \
870             "Build property 2 (.so)" \
871             "-shared" \
872             "-fPIC -Wa,-mx86-used-note=no" \
873             {pass.c property-stack.S} \
874             {{readelf {-n} property-2.r}} \
875             "property-2.so" \
876         ] \
877         [list \
878             "Build property 3" \
879             "" \
880             "-Wa,-mx86-used-note=no" \
881             {pass.c property-stack.S property-x86-1.S} \
882             {{readelf {-n} property-3.r}} \
883             "property-3" \
884         ] \
885         [list \
886             "Build property 3 (.o)" \
887             "-r -nostdlib" \
888             "-Wa,-mx86-used-note=yes" \
889             {pass.c property-x86-1.S property-stack.S} \
890             {{readelf {-n} property-3a.r}} \
891             "property-3.o" \
892         ] \
893         [list \
894             "Build property 3 (.so)" \
895             "-shared" \
896             "-fPIC -Wa,-mx86-used-note=no" \
897             {property-x86-1.S pass.c property-stack.S} \
898             {{readelf {-n} property-3.r}} \
899             "property-3.so" \
900         ] \
901         [list \
902             "Build property 4" \
903             "" \
904             "-Wa,-mx86-used-note=no" \
905             {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
906             {{readelf {-n} property-4.r}} \
907             "property-4" \
908         ] \
909         [list \
910             "Build property 4 (.o)" \
911             "-r -nostdlib" \
912             "-Wa,-mx86-used-note=yes" \
913             {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
914             {{readelf {-n} property-4a.r}} \
915             "property-4.o" \
916         ] \
917         [list \
918             "Build property 4 (.so)" \
919             "-shared" \
920             "-fPIC -Wa,-mx86-used-note=no" \
921             {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
922             {{readelf {-n} property-4.r}} \
923             "property-4.so" \
924         ] \
925         [list \
926             "Build property 4 (-Wl,-z,stack-size=0)" \
927             "-Wl,-z,stack-size=0" \
928             "-Wa,-mx86-used-note=no" \
929             {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
930             {{readelf {-n} property-4.r}} \
931             "property-4" \
932         ] \
933         [list \
934             "Build property 5" \
935             "-Wl,-z,stack-size=0x900000" \
936             "-Wa,-mx86-used-note=no" \
937             {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
938             {{readelf {-n} property-5.r}} \
939             "property-5" \
940         ] \
941         [list \
942             "Build property 5 (.o)" \
943             "-r -nostdlib -Wl,-z,stack-size=0x900000" \
944             "-Wa,-mx86-used-note=yes" \
945             {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
946             {{readelf {-n} property-5a.r}} \
947             "property-5.o" \
948         ] \
949         [list \
950             "Build property 5 (.so)" \
951             "-shared -Wl,-z,stack-size=0x900000" \
952             "-fPIC -Wa,-mx86-used-note=no" \
953             {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
954             {{readelf {-n} property-5.r}} \
955             "property-5.so" \
956         ] \
957         [list \
958             "Build property-6.so" \
959             "-shared" \
960             "-fPIC -Wa,-mx86-used-note=no" \
961             {property-6a.c property-6c.S} \
962             {{readelf {-n} property-6.r}} \
963             "property-6.so" \
964         ] \
965         [list \
966             "Build property-6.o" \
967             "-r -nostdlib" \
968             "-Wa,-mx86-used-note=yes" \
969             {property-6b.c property-stack.S} \
970             {{readelf {-n} property-2a.r}} \
971             "property-6.o" \
972         ] \
973         [list \
974             "Build property-6" \
975             "-Wl,--as-needed tmpdir/property-6.o tmpdir/property-6.so" \
976             "-Wa,-mx86-used-note=no" \
977             { dummy.s } \
978             {{readelf {-n} property-2.r}} \
979             "property-6" \
980         ] \
981         [list \
982             "Build property 7a (.o)" \
983             "-r -nostdlib" \
984             "-Wa,-mx86-used-note=yes" \
985             {property-unsorted-1.S} \
986             {{readelf {-n} property-7a.r}} \
987             "property-7a.o" \
988         ] \
989         [list \
990             "Build property 7b (.o)" \
991             "-r -nostdlib" \
992             "-Wa,-mx86-used-note=yes" \
993             {property-unsorted-2.S} \
994             {{readelf {-n} property-7a.r}} \
995             "property-7b.o" \
996         ] \
997     ]
998
999     run_ld_link_exec_tests [list \
1000         [list \
1001             "Run plt-main" \
1002             "tmpdir/plt-main1.o tmpdir/plt-main2.o tmpdir/plt-main3.o \
1003              tmpdir/plt-main4.o tmpdir/libplt-lib.so" \
1004             "-Wa,-mx86-used-note=yes" \
1005             { plt-main5.c } \
1006             "plt-main" \
1007             "plt-main.out" \
1008         ] \
1009         [list \
1010             "Run plt-main with PIE" \
1011             "tmpdir/plt-main1.o tmpdir/plt-main2.o tmpdir/plt-main3.o \
1012              tmpdir/plt-main4.o tmpdir/libplt-lib.so -pie" \
1013             "-Wa,-mx86-used-note=yes" \
1014             { plt-main5.c } \
1015             "plt-main-pie" \
1016             "plt-main.out" \
1017             "-fPIC" \
1018         ] \
1019         [list \
1020             "Run copyreloc-main with PIE and GOTOFF" \
1021             "-Wl,--as-needed tmpdir/copyreloc-main.o tmpdir/copyreloc-lib.so -pie" \
1022             "-Wa,-mx86-used-note=yes" \
1023             { dummy.s } \
1024             "copyreloc-main" \
1025             "copyreloc-main.out" \
1026         ] \
1027         [list \
1028             "Run pr17689 with PIE and GOTOFF" \
1029             "tmpdir/pr17689b.o tmpdir/pr17689.so -pie" \
1030             "-Wa,-mx86-used-note=yes" \
1031             { dummy.c } \
1032             "pr17689" \
1033             "pr17689.out" \
1034         ] \
1035         [list \
1036             "Run pr17689 with PIE, -z now and GOTOFF" \
1037             "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -z now" \
1038             "-Wa,-mx86-used-note=yes" \
1039             { dummy.c } \
1040             "pr17689now" \
1041             "pr17689.out" \
1042         ] \
1043         [list \
1044             "Run pr17689ver with PIE and GOTOFF" \
1045             "tmpdir/pr17689b.o tmpdir/pr17689ver.so -pie" \
1046             "-Wa,-mx86-used-note=yes" \
1047             { dummy.c } \
1048             "pr17689ver" \
1049             "pr17689.out" \
1050         ] \
1051         [list \
1052             "Run pr18900" \
1053             "tmpdir/pr18900.o tmpdir/pr18900.so" \
1054             "-Wa,-mx86-used-note=yes" \
1055             { dummy.s } \
1056             "pr18900" \
1057             "pr18900.out" \
1058         ] \
1059         [list \
1060             "Run pr19031" \
1061             "$NOPIE_LDFLAGS tmpdir/pr19031.so" \
1062             "-Wa,-mx86-used-note=yes" \
1063             { pr19031b.S pr19031c.c } \
1064             "pr19031" \
1065             "pr19031.out" \
1066             "$NOPIE_CFLAGS" \
1067         ] \
1068         [list \
1069             "Run got1" \
1070             "$NOPIE_LDFLAGS tmpdir/got1d.so" \
1071             "-Wa,-mx86-used-note=yes" \
1072             { got1a.S got1b.c got1c.c } \
1073             "got1" \
1074             "got1.out" \
1075         ] \
1076         [list \
1077             "Run property 1" \
1078             "" \
1079             "-Wa,-mx86-used-note=yes" \
1080             {pass.c property-no-copy.S} \
1081             "property-1" "pass.out" \
1082         ] \
1083         [list \
1084             "Run property 1 (PIE)" \
1085             "-pie" \
1086             "-Wa,-mx86-used-note=yes" \
1087             {pass.c property-no-copy.S} \
1088             "property-1-pie" "pass.out" "-fPIE" \
1089         ] \
1090         [list \
1091             "Run property 1 (static)" \
1092             "-static" \
1093             "-Wa,-mx86-used-note=yes" \
1094             {pass.c property-no-copy.S} \
1095             "property-1-static" "pass.out" \
1096         ] \
1097         [list \
1098             "Run property 2" \
1099             "" \
1100             "-Wa,-mx86-used-note=yes" \
1101             {pass.c property-stack.S} \
1102             "property-2" "pass.out" \
1103         ] \
1104         [list \
1105             "Run property 2 (PIE)" \
1106             "-pie" \
1107             "-Wa,-mx86-used-note=yes" \
1108             {pass.c property-stack.S} \
1109             "property-2-pie" "pass.out" "-fPIE" \
1110         ] \
1111         [list \
1112             "Run property 2 (static)" \
1113             "-static" \
1114             "-Wa,-mx86-used-note=yes" \
1115             {pass.c property-stack.S} \
1116             "property-3-static" "pass.out" \
1117         ] \
1118         [list \
1119             "Run property 3" \
1120             "" \
1121             "-Wa,-mx86-used-note=yes" \
1122             {pass.c property-stack.S property-x86-1.S} \
1123             "property-3" "pass.out" \
1124         ] \
1125         [list \
1126             "Run property 3 (PIE)" \
1127             "-pie" \
1128             "-Wa,-mx86-used-note=yes" \
1129             {pass.c property-x86-1.S property-stack.S} \
1130             "property-3-pie" "pass.out" "-fPIE" \
1131         ] \
1132         [list \
1133             "Run property 3 (static)" \
1134             "-static" \
1135             "-Wa,-mx86-used-note=yes" \
1136             {property-x86-1.S pass.c property-stack.S} \
1137             "property-3-static" "pass.out" \
1138         ] \
1139         [list \
1140             "Run property 4" \
1141             "" \
1142             "-Wa,-mx86-used-note=yes" \
1143             {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
1144             "property-4" "pass.out" \
1145         ] \
1146         [list \
1147             "Run property 4 (PIE)" \
1148             "-pie" \
1149             "-Wa,-mx86-used-note=yes" \
1150             {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
1151             "property-4-pie" "pass.out" "-fPIE" \
1152         ] \
1153         [list \
1154             "Run property 4 (static)" \
1155             "-static" \
1156             "-Wa,-mx86-used-note=yes" \
1157             {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
1158             "property-4-static" "pass.out" \
1159         ] \
1160         [list \
1161             "Run property 5" \
1162             "-Wl,-z,stack-size=0x900000" \
1163             "-Wa,-mx86-used-note=yes" \
1164             {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
1165             "property-5" "pass.out" \
1166         ] \
1167         [list \
1168             "Run property 5 (PIE)" \
1169             "-pie -Wl,-z,stack-size=0x900000" \
1170             "-Wa,-mx86-used-note=yes" \
1171             {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
1172             "property-5-pie" "pass.out" "-fPIE" \
1173         ] \
1174         [list \
1175             "Run property 5 (static)" \
1176             "-static -Wl,-z,stack-size=0x900000" \
1177             "-Wa,-mx86-used-note=yes" \
1178             {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
1179             "property-5-static" "pass.out" \
1180         ] \
1181     ]
1182
1183     undefined_weak "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS"
1184     undefined_weak "-fPIE" "$NOPIE_LDFLAGS"
1185     undefined_weak "-fPIE" "-pie"
1186     undefined_weak "-fPIE" "-z nodynamic-undefined-weak $NOPIE_LDFLAGS"
1187     undefined_weak "-fPIE" "-pie -z nodynamic-undefined-weak"
1188 }
1189
1190 global NOPIE_CFLAGS NOPIE_LDFLAGS
1191
1192 # Must be native with the C compiler and working IFUNC support,
1193 if { [isnative]
1194      && [check_ifunc_available]
1195      && [istarget "i?86-*-*"]
1196      && [which $CC] != 0 } {
1197     run_cc_link_tests [list \
1198         [list \
1199             "Build ifunc-1a.o ifunc-1b.o ifunc-1c.o ifunc-1d.o" \
1200             "" \
1201             "-fPIC -O2 -g -Wa,-mx86-used-note=yes" \
1202             { ifunc-1a.c ifunc-1b.S ifunc-1c.S ifunc-1d.S } \
1203         ] \
1204         [list \
1205             "Build pr21168a.o" \
1206             "" \
1207             "-Wa,-mx86-used-note=yes" \
1208             { pr21168a.c } \
1209         ] \
1210         [list \
1211             "Build pr21168.so" \
1212             "-shared" \
1213             "-Wa,-mx86-used-note=yes" \
1214             { pr21168b.S } \
1215             "" \
1216             "pr21168.so" \
1217         ] \
1218     ]
1219
1220     run_ld_link_exec_tests [list \
1221         [list \
1222             "Run ifunc-1a" \
1223             "tmpdir/ifunc-1a.o tmpdir/ifunc-1b.o \
1224              tmpdir/ifunc-1c.o tmpdir/ifunc-1d.o" \
1225             "-Wa,-mx86-used-note=yes" \
1226             { dummy.c } \
1227             "ifunc-1a" \
1228             "pass.out" \
1229         ] \
1230         [list \
1231             "Run ifunc-1b" \
1232             "--static tmpdir/ifunc-1a.o tmpdir/ifunc-1b.o \
1233             tmpdir/ifunc-1c.o tmpdir/ifunc-1d.o" \
1234             "-Wa,-mx86-used-note=yes" \
1235             { dummy.c } \
1236             "ifunc-1b" \
1237             "pass.out" \
1238         ] \
1239         [list \
1240             "Run pr21168" \
1241             "tmpdir/pr21168a.o tmpdir/pr21168.so" \
1242             "-Wa,-mx86-used-note=yes" \
1243             { dummy.c } \
1244             "pr21168" \
1245             "pass.out" \
1246         ] \
1247     ]
1248
1249     if { [istarget "i?86-*-linux*"] } {
1250         run_cc_link_tests [list \
1251             [list \
1252                 "Build pr21168.so with -z ibtplt" \
1253                 "-shared -Wl,-z,ibtplt" \
1254                 "-Wa,-mx86-used-note=yes" \
1255                 { pr21168b.S } \
1256                 "" \
1257                 "pr21168-ibt.so" \
1258             ] \
1259             [list \
1260                 "Build ifunc-1a with -z ibtplt" \
1261                 "-Wl,-z,ibtplt $NOPIE_LDFLAGS tmpdir/ifunc-1a.o \
1262                  tmpdir/ifunc-1b.o tmpdir/ifunc-1c.o tmpdir/ifunc-1d.o" \
1263                 "-Wa,-mx86-used-note=yes" \
1264                 { dummy.c } \
1265                 {{objdump {-dw} plt-main-ibt.dd}} \
1266                 "ifunc-1a-ibt" \
1267             ] \
1268             [list \
1269                 "Build ifunc-1a with PIE -z ibtplt" \
1270                 "-Wl,-z,ibtplt -pie tmpdir/ifunc-1a.o \
1271                  tmpdir/ifunc-1b.o tmpdir/ifunc-1c.o tmpdir/ifunc-1d.o" \
1272                 "-Wa,-mx86-used-note=yes" \
1273                 { dummy.c } \
1274                 {{objdump {-dw} plt-pie-ibt.dd}} \
1275                 "ifunc-1a-pie-ibt" \
1276             ] \
1277         ]
1278
1279         run_ld_link_exec_tests [list \
1280             [list \
1281                 "Run ifunc-1a with -z ibtplt" \
1282                 "-Wl,-z,ibtplt $NOPIE_LDFLAGS tmpdir/ifunc-1a.o \
1283                  tmpdir/ifunc-1b.o tmpdir/ifunc-1c.o tmpdir/ifunc-1d.o" \
1284                 "-Wa,-mx86-used-note=yes" \
1285                 { dummy.c } \
1286                 "ifunc-1a-ibt" \
1287                 "pass.out" \
1288             ] \
1289             [list \
1290                 "Run ifunc-1a with PIE -z ibtplt" \
1291                 "-Wl,-z,ibtplt -pie tmpdir/ifunc-1a.o \
1292                  tmpdir/ifunc-1b.o tmpdir/ifunc-1c.o tmpdir/ifunc-1d.o" \
1293                 "-Wa,-mx86-used-note=yes" \
1294                 { dummy.c } \
1295                 "ifunc-1a-pie-ibt" \
1296                 "pass.out" \
1297             ] \
1298             [list \
1299                 "Run pr21168 with -z ibtplt" \
1300                 "tmpdir/pr21168a.o tmpdir/pr21168-ibt.so" \
1301                 "-Wa,-mx86-used-note=yes" \
1302                 { dummy.c } \
1303                 "pr21168-ibt" \
1304                 "pass.out" \
1305             ] \
1306         ]
1307     }
1308 }
1309
1310 # Must be native with the C compiler.
1311 if { [isnative]
1312      && [istarget "i?86-*-*"]
1313      && [which $CC] != 0 } {
1314     run_cc_link_tests [list \
1315         [list \
1316             "Build pr22001-1.so" \
1317             "-shared" \
1318             "-Wa,-mx86-used-note=yes" \
1319             { pr22001-1a.c } \
1320             {} \
1321             "pr22001-1.so" \
1322         ] \
1323         [list \
1324             "Build pr21997-1.so" \
1325             "-shared" \
1326             "-Wa,-mx86-used-note=yes" \
1327             { property-stack.S property-no-copy.S pr21997-1a.S } \
1328             {} \
1329             "pr21997-1.so" \
1330         ] \
1331         [list \
1332             "Build pr22842.so" \
1333             "-shared" \
1334             "-fPIC -Wa,-mx86-used-note=yes" \
1335             { pr22842a.c } \
1336             {} \
1337             "pr22842.so" \
1338         ] \
1339     ]
1340
1341     run_ld_link_exec_tests [list \
1342         [list \
1343             "Run weakundef1 without PIE" \
1344             "$NOPIE_LDFLAGS" \
1345             "-Wa,-mx86-used-note=yes" \
1346             { weakundef1.c } \
1347             "weakundef1pie" \
1348             "pass.out" \
1349             "$NOPIE_CFLAGS" \
1350         ] \
1351         [list \
1352             "Run pr22001-1" \
1353             "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
1354             "-Wa,-mx86-used-note=yes" \
1355             { pr22001-1b.c } \
1356             "pr22001-1" \
1357             "pass.out" \
1358             "$NOPIE_CFLAGS" \
1359         ] \
1360         [list \
1361             "Run pr22001-1 (PIE 1)" \
1362             "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
1363             "-Wa,-mx86-used-note=yes" \
1364             { pr22001-1c.S } \
1365             "pr22001-1-pie-1" \
1366             "pass.out" \
1367         ] \
1368         [list \
1369             "Run pr22001-1 (PIE 2)" \
1370             "-pie -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
1371             "-Wa,-mx86-used-note=yes" \
1372             { pr22001-1c.S } \
1373             "pr22001-1-pie-2" \
1374             "pass.out" \
1375         ] \
1376         [list \
1377             "Run pr22001-1 (PIC 1)" \
1378             "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
1379             "-Wa,-mx86-used-note=yes" \
1380             { pr22001-1b.c } \
1381             "pr22001-1-pic-1" \
1382             "pass.out" \
1383             "-fPIC" \
1384         ] \
1385         [list \
1386             "Run pr22001-1 (PIC 2)" \
1387             "-pie -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
1388             "-Wa,-mx86-used-note=yes" \
1389             { pr22001-1b.c } \
1390             "pr22001-1-pic-2" \
1391             "pass.out" \
1392             "-fPIC" \
1393         ] \
1394         [list \
1395             "Run pr21997-1" \
1396             "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \
1397             "-Wa,-mx86-used-note=yes" \
1398             { pr21997-1b.c } \
1399             "pr21997-1" \
1400             "pass.out" \
1401             "$NOPIE_CFLAGS" \
1402         ] \
1403         [list \
1404             "Run pr21997-1 (PIC 1)" \
1405             "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \
1406             "-Wa,-mx86-used-note=yes" \
1407             { pr21997-1b.c } \
1408             "pr21997-1-pic-1" \
1409             "pass.out" \
1410             "-fPIC" \
1411         ] \
1412         [list \
1413             "Run pr21997-1 (PIC 2)" \
1414             "-pie -Wl,--no-as-needed tmpdir/pr21997-1.so" \
1415             "-Wa,-mx86-used-note=yes" \
1416             { pr21997-1b.c } \
1417             "pr21997-1-pic-2" \
1418             "pass.out" \
1419             "-fPIC" \
1420         ] \
1421         [list \
1422             "Run pr21997-1 (PIE 1)" \
1423             "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \
1424             "-Wa,-mx86-used-note=yes" \
1425             { pr21997-1c.S } \
1426             "pr21997-1-pie-1" \
1427             "pass.out" \
1428         ] \
1429         [list \
1430             "Run pr21997-1 (PIE 2)" \
1431             "-pie -Wl,--no-as-needed tmpdir/pr21997-1.so" \
1432             "-Wa,-mx86-used-note=yes" \
1433             { pr21997-1c.S } \
1434             "pr21997-1-pie-2" \
1435             "pass.out" \
1436         ] \
1437         [list \
1438             "Build pr22842" \
1439             "-pie -Wl,--no-as-needed tmpdir/pr22842.so" \
1440             "-Wa,-mx86-used-note=yes" \
1441             { pr22842b.S } \
1442             "pr22842" \
1443             "pass.out" \
1444         ] \
1445         [list \
1446             "Run pr23997" \
1447             "" \
1448             "" \
1449             { ../ld-x86-64/pr23997a.s ../ld-x86-64/pr23997b.c \
1450               ../ld-x86-64/pr23997c.c } \
1451             "pr23997" \
1452             "pass.out" \
1453         ] \
1454     ]
1455
1456     if { [at_least_gcc_version 5 0] } {
1457         run_ld_link_exec_tests [list \
1458             [list \
1459                 "Run weakundef1 with PIE" \
1460                 "-pie" \
1461                 "-Wa,-mx86-used-note=yes" \
1462                 { weakundef1.c } \
1463                 "weakundef1pie" \
1464                 "pass.out" \
1465                 "-fPIE" \
1466             ] \
1467         ]
1468     }
1469 }
1470
1471 if { !([istarget "i?86-*-linux*"]
1472        || [istarget "x86_64-*-linux*"]) } {
1473     set ASFLAGS "$saved_ASFLAGS"
1474     return
1475 }
1476
1477 run_ld_link_tests [list \
1478     [list \
1479         "basic PLT generation (non-PIC, -z now)" \
1480         "-z now -melf_i386 --hash-style=sysv \
1481          -z noseparate-code tmpdir/libpltlib.so" \
1482         "" \
1483         "--32" \
1484         {plt2.s} \
1485         {{readelf -SW plt2.rd} {objdump -dwr plt2.dd}} \
1486         "plt2" \
1487     ] \
1488     [list \
1489         "basic PLT generation (PIC, -z now)" \
1490         "-z now -shared -melf_i386 tmpdir/libpltlib.so" \
1491         "" \
1492         "--32 -mx86-used-note=yes" \
1493         {plt-pic.s} \
1494         {{objdump -dwr plt-pic2.dd}} \
1495         "plt-pic2.so" \
1496     ] \
1497     [list \
1498         "Build pr21626.so" \
1499         "-shared -melf_i386" \
1500         "" \
1501         "--32 -mx86-used-note=yes" \
1502         {property-x86-3.s} \
1503         "" \
1504         "pr21626.so" \
1505     ] \
1506     [list \
1507         "Build pr21626" \
1508         "-melf_i386 tmpdir/pr21626.so" \
1509         "" \
1510         "--32 -mx86-used-note=yes" \
1511         {start.s foo.s} \
1512         "" \
1513         "pr21626" \
1514     ] \
1515 ]
1516
1517 # Linux only tests
1518 run_dump_test "pltgot-1"
1519 run_dump_test "pltgot-2"
1520 run_dump_test "pr20830"
1521 run_dump_test "ibt-plt-1"
1522 run_dump_test "ibt-plt-2a"
1523 run_dump_test "ibt-plt-2b"
1524 run_dump_test "ibt-plt-2c"
1525 run_dump_test "ibt-plt-2d"
1526 run_dump_test "ibt-plt-3a"
1527 run_dump_test "ibt-plt-3b"
1528 run_dump_test "ibt-plt-3c"
1529 run_dump_test "ibt-plt-3d"
1530
1531 set ASFLAGS "$saved_ASFLAGS"