1 |
120 |
khays |
# Test that the linker reports undefined symbol errors correctly.
|
2 |
|
|
# By Ian Lance Taylor, Cygnus Support
|
3 |
|
|
#
|
4 |
|
|
# Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
5 |
|
|
# 2005, 2007, 2008, 2010, 2011 Free Software Foundation, Inc.
|
6 |
|
|
#
|
7 |
|
|
# This file is part of the GNU Binutils.
|
8 |
|
|
#
|
9 |
|
|
# This program is free software; you can redistribute it and/or modify
|
10 |
|
|
# it under the terms of the GNU General Public License as published by
|
11 |
|
|
# the Free Software Foundation; either version 3 of the License, or
|
12 |
|
|
# (at your option) any later version.
|
13 |
|
|
#
|
14 |
|
|
# This program is distributed in the hope that it will be useful,
|
15 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
|
|
# GNU General Public License for more details.
|
18 |
|
|
#
|
19 |
|
|
# You should have received a copy of the GNU General Public License
|
20 |
|
|
# along with this program; if not, write to the Free Software
|
21 |
|
|
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
22 |
|
|
# MA 02110-1301, USA.
|
23 |
|
|
|
24 |
|
|
set testund "undefined"
|
25 |
|
|
set testfn "undefined function"
|
26 |
|
|
set testline "undefined line"
|
27 |
|
|
|
28 |
|
|
if { ![is_remote host] && [which $CC] == 0 } {
|
29 |
|
|
verbose "Could not find C compiler!" 1
|
30 |
|
|
untested $testund
|
31 |
|
|
untested $testfn
|
32 |
|
|
untested $testline
|
33 |
|
|
return
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
if ![ld_compile "$CC -g" $srcdir/$subdir/undefined.c tmpdir/undefined.o] {
|
37 |
|
|
verbose "Unable to compile test file!" 1
|
38 |
|
|
unresolved $testund
|
39 |
|
|
unresolved $testfn
|
40 |
|
|
unresolved $testline
|
41 |
|
|
return
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
remote_file host delete "tmpdir/undefined"
|
45 |
|
|
|
46 |
|
|
set flags [big_or_little_endian]
|
47 |
|
|
|
48 |
|
|
# Using -e start prevents the SunOS linker from trying to build a
|
49 |
|
|
# shared library.
|
50 |
|
|
send_log "$ld -e start $flags -o tmpdir/undefined tmpdir/undefined.o\n"
|
51 |
|
|
set exec_output [run_host_cmd "$ld" "-e start $flags -o tmpdir/undefined tmpdir/undefined.o"]
|
52 |
|
|
|
53 |
|
|
send_log "$exec_output\n"
|
54 |
|
|
verbose "$exec_output"
|
55 |
|
|
|
56 |
|
|
proc checkund { string testname } {
|
57 |
|
|
global exec_output
|
58 |
|
|
|
59 |
|
|
if [string match "*$string*" $exec_output] {
|
60 |
|
|
pass $testname
|
61 |
|
|
} else {
|
62 |
|
|
fail $testname
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
set mu "undefined reference to `*this_function_is_not_defined'"
|
67 |
|
|
checkund $mu $testund
|
68 |
|
|
|
69 |
|
|
# ARM PE defaults to using stabs debugging, which we can't handle for
|
70 |
|
|
# a COFF file.
|
71 |
|
|
#setup_xfail "arm*-*-pe*"
|
72 |
|
|
|
73 |
|
|
# For Xtensa on GNU Linux systems (or any other system where PIC code is
|
74 |
|
|
# always used), the address of the undefined function is in a literal pool
|
75 |
|
|
# outside the function, so that both the "undefined function" and "undefined
|
76 |
|
|
# line" tests fail.
|
77 |
|
|
setup_xfail xtensa*-*-linux*
|
78 |
|
|
|
79 |
|
|
set mf "tmpdir/undefined.o* In function `function':"
|
80 |
|
|
checkund $mf $testfn
|
81 |
|
|
|
82 |
|
|
if ![is_elf_format] {
|
83 |
|
|
# COFF SH gets this test wrong--it reports line 10, because although
|
84 |
|
|
# the jump is at line 9, the function address, and the reloc, is
|
85 |
|
|
# stored at the end of the function.
|
86 |
|
|
setup_xfail "sh-*-*"
|
87 |
|
|
|
88 |
|
|
# ARM PE defaults to using stabs debugging, which we can't handle for
|
89 |
|
|
# a COFF file.
|
90 |
|
|
#setup_xfail "arm*-*-pe*"
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
set ml "undefined.c:9: undefined reference to `*this_function_is_not_defined'"
|
94 |
|
|
# With targets that use elf/dwarf2, such as the arm-elf
|
95 |
|
|
# toolchain, the code in bfd/elf.c:_bfd_elf_find_nearest_line() is called
|
96 |
|
|
# in order to locate the file name/line number where the undefined
|
97 |
|
|
# reference occurs. Unfortunately this tries to use the dwarf2 debug
|
98 |
|
|
# information held in the .debug_info section. This section contains a series
|
99 |
|
|
# of comp_unit structures, each of which has a low/high address range
|
100 |
|
|
# representing the span of memory locations covered by that structure. The
|
101 |
|
|
# structures also index into other structures held in the .debug_line section
|
102 |
|
|
# and together they can translate memory locations back into file/function/line
|
103 |
|
|
# number addresses in the source code. Since the information about the memory
|
104 |
|
|
# region covered by a comp_unit is only determined at link time, the low/high
|
105 |
|
|
# addresses in the .debug_info section and the line addresses in the .debug_line
|
106 |
|
|
# section are computed by generating relocs against known symbols in the object
|
107 |
|
|
# code.
|
108 |
|
|
#
|
109 |
|
|
# When the undefined reference is detected, the relocs in the dwarf2
|
110 |
|
|
# debug sections have not yet been resolved, so the low/high addresses and the
|
111 |
|
|
# line number address are all set at zero. Thus when _bfd_elf_find_nearest_line()
|
112 |
|
|
# calls _bfd_dwarf2_find_nearest_line() no comp_unit can be found which
|
113 |
|
|
# actually covers the address where the reference occured, and so
|
114 |
|
|
# _bfd_elf_find_nearest_line() fails.
|
115 |
|
|
#
|
116 |
|
|
# The upshot of all of this, is that the error message reported by the
|
117 |
|
|
# linker, instead of having a source file name & line number as in:
|
118 |
|
|
#
|
119 |
|
|
# undefined.c:9: undefined reference to `this_function_is_not_defined'
|
120 |
|
|
#
|
121 |
|
|
# has an object file & section address instead:
|
122 |
|
|
#
|
123 |
|
|
# undefined.0(.text+0xc): undefined reference to `this_function_is_not_defined'
|
124 |
|
|
#
|
125 |
|
|
# hence the xfails below.
|
126 |
|
|
|
127 |
|
|
setup_xfail mcore-*-elf
|
128 |
|
|
setup_xfail mep-*-*
|
129 |
|
|
setup_xfail mips-sgi-irix6*
|
130 |
|
|
setup_xfail "sh64-*-*"
|
131 |
|
|
|
132 |
|
|
# The undefined test fails on 31 bit s/390 because the address of the
|
133 |
|
|
# function `this_function_is_not_defined' is stored in the literal pool of
|
134 |
|
|
# the function. Therefore the line number in the error message is 8 instead
|
135 |
|
|
# of 9. On 64 bit s/390 this works because of the new brasl instruction that
|
136 |
|
|
# doesn't need a literal pool entry.
|
137 |
|
|
setup_xfail s390-*-*
|
138 |
|
|
|
139 |
|
|
# See comments above for Xtensa.
|
140 |
|
|
setup_xfail xtensa*-*-linux*
|
141 |
|
|
setup_xfail hppa*64*-*-*
|
142 |
|
|
|
143 |
|
|
checkund $ml $testline
|