2001-02-28 Matt Hiller <hiller@redhat.com>
[platform/upstream/binutils.git] / ld / testsuite / ld-undefined / undefined.exp
1 # Test that the linker reports undefined symbol errors correctly.
2 # By Ian Lance Taylor, Cygnus Support
3 #
4 #   Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation
5 #
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 set testund "undefined"
21 set testfn "undefined function"
22 set testline "undefined line"
23
24 if { [which $CC] == 0 } {
25     verbose "Could not find C compiler!" 1
26     untested $testund
27     untested $testfn
28     untested $testline
29     return
30 }
31
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
38 }
39
40 catch "exec rm -f tmpdir/undefined" exec_output
41
42 set flags [big_or_little_endian]
43
44 # Using -e start prevents the SunOS linker from trying to build a
45 # shared library.
46 send_log "$ld -e start $flags -o tmpdir/undefined tmpdir/undefined.o\n"
47 verbose "$ld -e start $flags -o tmpdir/undefined tmpdir/undefined.o"
48
49 catch "exec $ld -e start $flags -o tmpdir/undefined tmpdir/undefined.o" exec_output
50 send_log "$exec_output\n"
51 verbose "$exec_output"
52
53 proc checkund { string testname } {
54     global exec_output
55
56     if [string match "*$string*" $exec_output] {
57         pass $testname
58     } else {
59         fail $testname
60     }
61 }
62
63 set mu "undefined reference to `this_function_is_not_defined'"
64 checkund $mu $testund
65
66 # ARM PE defaults to using stabs debugging, which we can't handle for
67 # a COFF file.
68 #setup_xfail "arm*-*-pe*"
69 #setup_xfail "thumb*-*-pe*"
70
71 # Just doesn't work for PA ELF.  No clue why.
72 setup_xfail "hppa*-*-*elf*"
73
74 # With dwarf-2, we can't get the function in which the reference
75 # occurs; see below.
76 setup_xfail "hppa*64*-*-*"
77 setup_xfail "mn10300-*-elf"
78 setup_xfail "sh-*-*"
79
80 set mf "tmpdir/undefined.o: In function `function':"
81 checkund $mf $testfn
82
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 #setup_xfail "thumb*-*-pe*"
92
93 # Just doesn't work for PA ELF.  No clue why.
94 setup_xfail "hppa*-*-*elf*"
95
96 set ml "undefined.c:9: undefined reference to `this_function_is_not_defined'"
97 # With targets that use elf/dwarf2, such as the arm-elf and thumb-elf
98 # toolchains, the code in bfd/elf.c:_bfd_elf_find_nearest_line() is called
99 # in order to locate the file name/line number where the undefined
100 # reference occurs.  Unfortunately this tries to use the dwarf2 debug
101 # information held in the .debug_info section.  This section contains a series
102 # of comp_unit structures, each of which has a low/high address range
103 # representing the span of memory locations covered by that structure.  The
104 # structures also index into other structures held in the .debug_line section
105 # and together they can translate memory locations back into file/function/line
106 # number addresses in the source code.  Since the information about the memory
107 # region covered by a comp_unit is only determined at link time, the low/high
108 # addresses in the .debug_info section and the line addresses in the .debug_line
109 # section are computed by generating relocs against known symbols in the object
110 # code.
111 #
112 # When the undefined reference is detected, the relocs in the dwarf2
113 # debug sections have not yet been resolved, so the low/high addresses and the
114 # line number address are all set at zero.  Thus when _bfd_elf_find_nearest_line()
115 # calls _bfd_dwarf2_find_nearest_line() no comp_unit can be found which
116 # actually covers the address where the reference occured, and so
117 # _bfd_elf_find_nearest_line() fails.
118 #
119 # The upshot of all of this, is that the error message reported by the
120 # linker, instead of having a source file name & line number as in:
121 #
122 #   undefined.c:9: undefined reference to `this_function_is_not_defined'
123 #
124 # has an object file & section address instead:
125 #
126 #   undefined.0(.text+0xc): undefined reference to `this_function_is_not_defined'
127 #
128 # hence the xfails below.
129
130 #setup_xfail arm-*-elf
131 #setup_xfail strongarm-*-elf
132 #setup_xfail thumb-*-elf
133 setup_xfail mcore-*-elf
134 setup_xfail mips-sgi-irix6*
135
136 checkund $ml $testline