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