Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | # Test NOCROSSREFS in a linker script. |
2 | # By Ian Lance Taylor, Cygnus Support. | |
aa820537 | 3 | # Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2007 |
a2b64bed NC |
4 | # Free Software Foundation, Inc. |
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 | |
a2b64bed | 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 |
a2b64bed | 11 | # (at your option) any later version. |
f96b4a7b | 12 | # |
a2b64bed NC |
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 | # |
a2b64bed NC |
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 test1 "NOCROSSREFS 1" | |
24 | set test2 "NOCROSSREFS 2" | |
b239e909 | 25 | set test3 "NOCROSSREFS 3" |
252b5132 | 26 | |
7f6a71ff | 27 | if { ![is_remote host] && [which $CC] == 0 } { |
252b5132 RH |
28 | untested $test1 |
29 | untested $test2 | |
b239e909 | 30 | untested $test3 |
252b5132 RH |
31 | return |
32 | } | |
33 | ||
14f2c476 AM |
34 | global CFLAGS |
35 | set old_CFLAGS "$CFLAGS" | |
36 | ||
e0001a05 NC |
37 | # Xtensa targets currently default to putting literal values in a separate |
38 | # section and that requires linker script support, so put literals in text. | |
e0001a05 NC |
39 | if [istarget xtensa*-*-*] { |
40 | set CFLAGS "$CFLAGS -mtext-section-literals" | |
41 | } | |
42 | ||
97e5838e AM |
43 | # If we have a compiler that doesn't use/reference dot-symbols, then |
44 | # calls to functions reference the .opd section function descriptor. | |
45 | # This makes NOCROSSREFS rather useless on powerpc64. | |
14f2c476 | 46 | if [istarget powerpc64-*-*] { |
97e5838e AM |
47 | set CFLAGS "$CFLAGS -mcall-aixdesc" |
48 | } | |
49 | ||
4dcdce13 NC |
50 | # Prevent the use of the MeP's small data area which references a symbol |
51 | # called __sdabase which will not be defined by our test linker scripts. | |
52 | if [istarget mep*-*-elf] { | |
53 | set CFLAGS "-mtiny=0" | |
54 | } | |
55 | ||
ac145307 BS |
56 | # The .dsbt section and __c6xabi_DSBT_BASE are not defined in our test |
57 | # linker scripts. | |
58 | if [istarget tic6x*-*-*] { | |
59 | set CFLAGS "-mno-dsbt -msdata=none" | |
60 | } | |
61 | ||
252b5132 RH |
62 | if { ![ld_compile $CC "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \ |
63 | || ![ld_compile $CC "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } { | |
64 | unresolved $test1 | |
65 | unresolved $test2 | |
14f2c476 | 66 | set CFLAGS "$old_CFLAGS" |
252b5132 RH |
67 | return |
68 | } | |
69 | ||
1688b748 | 70 | set flags [big_or_little_endian] |
252b5132 | 71 | |
1b19eb81 AO |
72 | if [istarget sh64*-*-elf] { |
73 | # This is what gcc passes to ld by default. | |
74 | set flags "-mshelf32" | |
75 | } | |
76 | ||
08ccf96b L |
77 | # IA64 has both ordered and unordered sections in an input file. |
78 | setup_xfail ia64-*-* | |
79 | ||
7f6a71ff | 80 | set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"] |
252b5132 RH |
81 | |
82 | set exec_output [prune_warnings $exec_output] | |
83 | ||
84 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
85 | ||
86 | if [string match "" $exec_output] then { | |
87 | fail $test1 | |
88 | } else { | |
89 | verbose -log "$exec_output" | |
dbc37f89 | 90 | if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] { |
252b5132 RH |
91 | pass $test1 |
92 | } else { | |
93 | fail $test1 | |
94 | } | |
95 | } | |
96 | ||
97 | # Check cross references within a single object. | |
98 | ||
99 | if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } { | |
100 | unresolved $test2 | |
14f2c476 | 101 | set CFLAGS "$old_CFLAGS" |
252b5132 RH |
102 | return |
103 | } | |
104 | ||
7f6a71ff | 105 | set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"] |
252b5132 RH |
106 | set exec_output [prune_warnings $exec_output] |
107 | ||
108 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
109 | ||
110 | if [string match "" $exec_output] then { | |
111 | fail $test2 | |
112 | } else { | |
113 | verbose -log "$exec_output" | |
114 | if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] { | |
115 | pass $test2 | |
116 | } else { | |
117 | fail $test2 | |
118 | } | |
119 | } | |
b239e909 L |
120 | |
121 | # Check cross references for ld -r | |
122 | ||
123 | if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } { | |
124 | unresolved $test3 | |
14f2c476 | 125 | set CFLAGS "$old_CFLAGS" |
b239e909 L |
126 | return |
127 | } | |
128 | ||
129 | if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] { | |
130 | unresolved $test3 | |
14f2c476 | 131 | set CFLAGS "$old_CFLAGS" |
b239e909 L |
132 | return |
133 | } | |
134 | ||
7f6a71ff | 135 | set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o"] |
b239e909 L |
136 | |
137 | set exec_output [prune_warnings $exec_output] | |
138 | ||
139 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
140 | ||
141 | if [string match "" $exec_output] then { | |
142 | pass $test3 | |
143 | } else { | |
144 | verbose -log "$exec_output" | |
145 | fail $test3 | |
146 | } | |
14f2c476 AM |
147 | |
148 | set CFLAGS "$old_CFLAGS" |