Run more ld tests when not native
[deliverable/binutils-gdb.git] / ld / testsuite / ld-undefined / weak-undef.exp
1 # Test handling of weak undefined symbols
2 # Copyright (C) 2001-2017 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 # The linker should accept references to undefined weaks without error,
22 # and resolve them to zero in a static executable. Ought to work for
23 # some a.out targets too.
24 set testname "weak undefined data symbols"
25
26 if { ![is_elf_format] && ![is_pecoff_format] } then {
27 unsupported $testname
28 } elseif {![ld_assemble $as $srcdir/$subdir/weak-undef.s \
29 tmpdir/weak-undef.o]} then {
30 # It's OK if .weak doesn't work on this target.
31 unresolved $testname
32 } elseif {![ld_link $ld tmpdir/weak-undef \
33 "tmpdir/weak-undef.o -T $srcdir/$subdir/weak-undef.t"]} then {
34 # Weak symbols are broken for non-i386 PE targets.
35 if {! [istarget i?86-*-*]} {
36 setup_xfail *-*-pe*
37 }
38 setup_xfail pj-*-*
39 fail $testname
40 } elseif {![is_remote host] && [which $objdump] == 0} then {
41 unresolved $testname
42 } else {
43 set exec_output [run_host_cmd "$objdump" "-s tmpdir/weak-undef"]
44 set exec_output [prune_warnings $exec_output]
45 verbose -log $exec_output
46
47 set output_regexp ".*Contents of section .data:.*0000 00000000 11111111.*"
48
49 if {[regexp $output_regexp $exec_output]} then {
50 pass $testname
51 } else {
52 fail $testname
53 }
54 }
55
56 # When linking a shared lib, weak undefined symbols should become dynamic.
57 set testname "weak undefined function symbols in shared lib"
58
59 set asflags ""
60 switch -glob $target_triplet {
61 aarch64* -
62 arm* -
63 powerpc* { set asflags "--defsym BL=1" }
64 hppa* { set asflags "--defsym HPPA=1" }
65 i\[3-7\]86* -
66 x86_64* { set asflags "--defsym CALLPLT=1" }
67 }
68
69 if { $asflags == "" || ![is_elf_format] || ![check_shared_lib_support]} then {
70 unsupported $testname
71 } elseif {![ld_assemble $as "$asflags $srcdir/$subdir/weak-fundef.s" \
72 tmpdir/weak-fundef.o]} then {
73 fail $testname
74 } elseif {![ld_link $ld tmpdir/weak-fundef.so \
75 "--shared tmpdir/weak-fundef.o"]} then {
76 fail $testname
77 } elseif {![is_remote host] && [which $nm] == 0} then {
78 unresolved $testname
79 } else {
80 set exec_output [run_host_cmd "$nm" "-D tmpdir/weak-fundef.so"]
81 set exec_output [prune_warnings $exec_output]
82 verbose -log $exec_output
83
84 set output_regexp ".*w undef_weak_fun.*"
85
86 if {[regexp $output_regexp $exec_output]} then {
87 pass $testname
88 } else {
89 fail $testname
90 }
91
92 # When linking a dynamic executable, weak undefined symbols become dynamic.
93 set testname "weak undefined function symbols in dynamic exe"
94
95 if {![ld_link $ld tmpdir/weak-fundef \
96 "--no-as-needed tmpdir/weak-fundef.o tmpdir/weak-fundef.so"]} then {
97 fail $testname
98 } else {
99 set exec_output [run_host_cmd "$nm" "-D tmpdir/weak-fundef"]
100 set exec_output [prune_warnings $exec_output]
101 verbose -log $exec_output
102
103 if {[regexp $output_regexp $exec_output]} then {
104 pass $testname
105 } else {
106 fail $testname
107 }
108 }
109 }
This page took 0.034352 seconds and 4 git commands to generate.