2000-10-31 Philip Blundell <philb@gnu.org>
[binutils.git] / ld / testsuite / ld-undefined / undefined.exp
blobe49b90cc91bfc0c8f67f2f0e1dba77b687390b38
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
26 untested $testund
27 untested $testfn
28 untested $testline
29 return
32 if ![ld_compile "$CC -g" $srcdir/$subdir/undefined.c tmpdir/undefined.o] {
33 verbose "Unable to compile test file!" 1
34 unresolved $testund
35 unresolved $testfn
36 unresolved $testline
37 return
40 catch "exec rm -f tmpdir/undefined" exec_output
42 # Using -e start prevents the SunOS linker from trying to build a
43 # shared library.
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 } {
52 global exec_output
54 if [string match "*$string*" $exec_output] {
55 pass $testname
56 } else {
57 fail $testname
61 set mu "undefined reference to `this_function_is_not_defined'"
62 checkund $mu $testund
64 # ARM PE defaults to using stabs debugging, which we can't handle for
65 # a COFF file.
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
73 # occurs; see below.
74 setup_xfail "hppa*64*-*-*"
75 setup_xfail "mn10300-*-elf"
76 setup_xfail "sh-*-*"
78 set mf "tmpdir/undefined.o: In function `function':"
79 checkund $mf $testfn
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.
84 setup_xfail "sh-*-*"
86 # ARM PE defaults to using stabs debugging, which we can't handle for
87 # a COFF file.
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
108 # code.
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