1 # Test handling of weak undefined symbols
2 # Copyright (C) 2001-2016 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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,
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"
26 if { ![is_elf_format] && ![is_pecoff_format] } then {
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.
32 } elseif {![ld_simple_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-*-*]} {
40 } elseif {![is_remote host] && [which $objdump] == 0} then {
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
47 set output_regexp ".*Contents of section .data:.*0000 00000000 11111111.*"
49 if {[regexp $output_regexp $exec_output]} then {
56 # When linking a shared lib, weak undefined symbols should become dynamic.
57 set testname "weak undefined function symbols in shared lib"
60 switch -glob $target_triplet {
63 powerpc* { set asflags "--defsym BL=1" }
64 hppa* { set asflags "--defsym HPPA=1" }
66 x86_64* { set asflags "--defsym CALLPLT=1" }
69 if { $asflags == "" || ![is_elf_format] || ![check_shared_lib_support]} then {
71 } elseif {![ld_assemble $as "$asflags $srcdir/$subdir/weak-fundef.s" \
72 tmpdir/weak-fundef.o]} then {
74 } elseif {![ld_simple_link $ld tmpdir/weak-fundef.so \
75 "--shared tmpdir/weak-fundef.o"]} then {
77 } elseif {![is_remote host] && [which $nm] == 0} then {
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
84 set output_regexp ".*w undef_weak_fun.*"
86 if {[regexp $output_regexp $exec_output]} then {
92 # When linking a dynamic executable, weak undefined symbols become dynamic.
93 set testname "weak undefined function symbols in dynamic exe"
95 if {![ld_simple_link $ld tmpdir/weak-fundef \
96 "--no-as-needed tmpdir/weak-fundef.o tmpdir/weak-fundef.so"]} then {
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
103 if {[regexp $output_regexp $exec_output]} then {