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