| 1 | # Test that the linker reports undefined symbol errors correctly. |
| 2 | # By Ian Lance Taylor, Cygnus Support |
| 3 | # |
| 4 | # Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001 |
| 5 | # Free Software Foundation, Inc. |
| 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 |
| 19 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | |
| 21 | set testund "undefined" |
| 22 | set testfn "undefined function" |
| 23 | set testline "undefined line" |
| 24 | |
| 25 | if { [which $CC] == 0 } { |
| 26 | verbose "Could not find C compiler!" 1 |
| 27 | untested $testund |
| 28 | untested $testfn |
| 29 | untested $testline |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | if ![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 | |
| 41 | catch "exec rm -f tmpdir/undefined" exec_output |
| 42 | |
| 43 | set flags [big_or_little_endian] |
| 44 | |
| 45 | # Using -e start prevents the SunOS linker from trying to build a |
| 46 | # shared library. |
| 47 | send_log "$ld -e start $flags -o tmpdir/undefined tmpdir/undefined.o\n" |
| 48 | verbose "$ld -e start $flags -o tmpdir/undefined tmpdir/undefined.o" |
| 49 | |
| 50 | catch "exec $ld -e start $flags -o tmpdir/undefined tmpdir/undefined.o" exec_output |
| 51 | send_log "$exec_output\n" |
| 52 | verbose "$exec_output" |
| 53 | |
| 54 | proc 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 | |
| 64 | set mu "undefined reference to `*this_function_is_not_defined'" |
| 65 | checkund $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 | |
| 72 | # Just doesn't work for PA ELF. No clue why. |
| 73 | setup_xfail "hppa*-*-*elf*" |
| 74 | |
| 75 | # With dwarf-2, we can't get the function in which the reference |
| 76 | # occurs; see below. |
| 77 | setup_xfail "hppa*64*-*-*" |
| 78 | setup_xfail "mn10300-*-elf" |
| 79 | setup_xfail "sh-*-*" |
| 80 | |
| 81 | set mf "tmpdir/undefined.o: In function `function':" |
| 82 | checkund $mf $testfn |
| 83 | |
| 84 | # COFF SH gets this test wrong--it reports line 10, because although |
| 85 | # the jump is at line 9, the function address, and the reloc, is |
| 86 | # stored at the end of the function. |
| 87 | setup_xfail "sh-*-*" |
| 88 | |
| 89 | # ARM PE defaults to using stabs debugging, which we can't handle for |
| 90 | # a COFF file. |
| 91 | #setup_xfail "arm*-*-pe*" |
| 92 | #setup_xfail "thumb*-*-pe*" |
| 93 | |
| 94 | # Just doesn't work for PA ELF. No clue why. |
| 95 | setup_xfail "hppa*-*-*elf*" |
| 96 | |
| 97 | set ml "undefined.c:9: undefined reference to `*this_function_is_not_defined'" |
| 98 | # With targets that use elf/dwarf2, such as the arm-elf and thumb-elf |
| 99 | # toolchains, the code in bfd/elf.c:_bfd_elf_find_nearest_line() is called |
| 100 | # in order to locate the file name/line number where the undefined |
| 101 | # reference occurs. Unfortunately this tries to use the dwarf2 debug |
| 102 | # information held in the .debug_info section. This section contains a series |
| 103 | # of comp_unit structures, each of which has a low/high address range |
| 104 | # representing the span of memory locations covered by that structure. The |
| 105 | # structures also index into other structures held in the .debug_line section |
| 106 | # and together they can translate memory locations back into file/function/line |
| 107 | # number addresses in the source code. Since the information about the memory |
| 108 | # region covered by a comp_unit is only determined at link time, the low/high |
| 109 | # addresses in the .debug_info section and the line addresses in the .debug_line |
| 110 | # section are computed by generating relocs against known symbols in the object |
| 111 | # code. |
| 112 | # |
| 113 | # When the undefined reference is detected, the relocs in the dwarf2 |
| 114 | # debug sections have not yet been resolved, so the low/high addresses and the |
| 115 | # line number address are all set at zero. Thus when _bfd_elf_find_nearest_line() |
| 116 | # calls _bfd_dwarf2_find_nearest_line() no comp_unit can be found which |
| 117 | # actually covers the address where the reference occured, and so |
| 118 | # _bfd_elf_find_nearest_line() fails. |
| 119 | # |
| 120 | # The upshot of all of this, is that the error message reported by the |
| 121 | # linker, instead of having a source file name & line number as in: |
| 122 | # |
| 123 | # undefined.c:9: undefined reference to `this_function_is_not_defined' |
| 124 | # |
| 125 | # has an object file & section address instead: |
| 126 | # |
| 127 | # undefined.0(.text+0xc): undefined reference to `this_function_is_not_defined' |
| 128 | # |
| 129 | # hence the xfails below. |
| 130 | |
| 131 | #setup_xfail arm-*-elf |
| 132 | setup_xfail i?86-*-freebsd* |
| 133 | #setup_xfail strongarm-*-elf |
| 134 | #setup_xfail thumb-*-elf |
| 135 | setup_xfail mcore-*-elf |
| 136 | setup_xfail mips-sgi-irix6* |
| 137 | |
| 138 | # The undefined test fails on 31 bit s/390 because the address of the |
| 139 | # function `this_function_is_not_defined' is stored in the literal pool of |
| 140 | # the function. Therefore the line number in the error message is 8 instead |
| 141 | # of 9. On 64 bit s/390 this works because of the new brasl instruction that |
| 142 | # doesn't need a literal pool entry. |
| 143 | setup_xfail s390-*-* |
| 144 | |
| 145 | checkund $ml $testline |