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