1 # Test that the linker reports undefined symbol errors correctly.
2 # By Ian Lance Taylor
, Cygnus Support
4 # Copyright
(C
) 1995, 1996, 1997, 2000 Free Software Foundation
6 # This file 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
2 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.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
20 set testund
"undefined"
21 set testfn
"undefined function"
22 set testline
"undefined line"
24 if { [which $CC
] == 0 } {
25 verbose
"Could not find C compiler!" 1
32 if ![ld_compile
"$CC -g" $srcdir/$subdir/undefined.c tmpdir/undefined.o] {
33 verbose
"Unable to compile test file!" 1
40 catch
"exec rm -f tmpdir/undefined" exec_output
42 # Using
-e start prevents the SunOS linker from trying to build a
44 send_log
"$ld -e start -o tmpdir/undefined tmpdir/undefined.o\n"
45 verbose
"$ld -e start -o tmpdir/undefined tmpdir/undefined.o"
47 catch
"exec $ld -e start -o tmpdir/undefined tmpdir/undefined.o" exec_output
48 send_log
"$exec_output\n"
49 verbose
"$exec_output"
51 proc checkund
{ string testname
} {
54 if [string match
"*$string*" $exec_output] {
61 set mu
"undefined reference to `this_function_is_not_defined'"
64 # ARM PE defaults to using stabs debugging
, which we can
't handle for
66 #setup_xfail "arm*-*-pe*"
67 #setup_xfail "thumb*-*-pe*"
69 # Just doesn't work
for PA ELF. No clue why.
70 setup_xfail
"hppa*-*-*elf*"
72 # With dwarf
-2, we can
't get the function in which the reference
74 setup_xfail "hppa*64*-*-*"
75 setup_xfail "mn10300-*-elf"
78 set mf "tmpdir/undefined.o: In function `function':"
81 # COFF SH gets this test wrong
--it reports line
10, because although
82 # the jump is at line
9, the function address
, and the reloc
, is
83 # stored at the end of the function.
86 # ARM PE defaults to using stabs debugging
, which we can
't handle for
88 #setup_xfail "arm*-*-pe*"
89 #setup_xfail "thumb*-*-pe*"
91 # Just doesn't work
for PA ELF. No clue why.
92 setup_xfail
"hppa*-*-*elf*"
94 set ml
"undefined.c:9: undefined reference to `this_function_is_not_defined'"
95 # With targets that use elf
/dwarf2
, such as the arm
-elf and thumb
-elf
96 # toolchains
, the code in bfd
/elf.c
:_bfd_elf_find_nearest_line
() is called
97 # in order to locate the file
name/line number where the undefined
98 # reference occurs. Unfortunately this tries to use the dwarf2 debug
99 # information held in the .debug_info section. This section contains a series
100 # of comp_unit structures
, each of which has a low
/high address range
101 # representing the span of memory locations covered by that structure. The
102 # structures also index into other structures held in the .debug_line section
103 # and together they can
translate memory locations
back into file
/function
/line
104 # number addresses in the source code. Since the information about the memory
105 # region covered by a comp_unit is only determined at link time
, the low
/high
106 # addresses in the .debug_info section and the line addresses in the .debug_line
107 # section are computed by generating relocs against known symbols in the object
110 # When the undefined reference is detected
, the relocs in the dwarf2
111 # debug sections have not yet been resolved
, so the low
/high addresses and the
112 # line number address are all
set at zero. Thus when _bfd_elf_find_nearest_line
()
113 # calls _bfd_dwarf2_find_nearest_line
() no comp_unit can be found which
114 # actually covers the address where the reference occured
, and so
115 # _bfd_elf_find_nearest_line
() fails.
117 # The upshot of all of this
, is that the error message reported by the
118 # linker
, instead of having a source file
name & line number as in
:
120 # undefined.c
:9: undefined reference to `this_function_is_not_defined
'
122 # has an object file & section address instead:
124 # undefined.0(.text+0xc): undefined reference to `this_function_is_not_defined'
126 # hence the xfails below.
128 #setup_xfail arm
-*-elf
129 #setup_xfail strongarm
-*-elf
130 #setup_xfail thumb
-*-elf
131 setup_xfail mcore
-*-elf
132 setup_xfail mips
-sgi
-irix6
*
134 checkund $ml $testline