Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | # Test NOCROSSREFS in a linker script. |
2 | # By Ian Lance Taylor, Cygnus Support. | |
2571583a | 3 | # Copyright (C) 2000-2017 Free Software Foundation, Inc. |
a2b64bed | 4 | # |
f96b4a7b NC |
5 | # This file is part of the GNU Binutils. |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
a2b64bed | 8 | # it under the terms of the GNU General Public License as published by |
f96b4a7b | 9 | # the Free Software Foundation; either version 3 of the License, or |
a2b64bed | 10 | # (at your option) any later version. |
f96b4a7b | 11 | # |
a2b64bed NC |
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. | |
f96b4a7b | 16 | # |
a2b64bed NC |
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 | |
f96b4a7b NC |
19 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | # MA 02110-1301, USA. | |
252b5132 RH |
21 | |
22 | set test1 "NOCROSSREFS 1" | |
23 | set test2 "NOCROSSREFS 2" | |
b239e909 | 24 | set test3 "NOCROSSREFS 3" |
cdf96953 MF |
25 | set test4 "NOCROSSREFS_TO 1" |
26 | set test5 "NOCROSSREFS_TO 2" | |
27 | set test6 "NOCROSSREFS_TO 3" | |
28 | set test7 "NOCROSSREFS_TO 4" | |
252b5132 | 29 | |
7f6a71ff | 30 | if { ![is_remote host] && [which $CC] == 0 } { |
252b5132 RH |
31 | untested $test1 |
32 | untested $test2 | |
b239e909 | 33 | untested $test3 |
cdf96953 MF |
34 | untested $test4 |
35 | untested $test5 | |
36 | untested $test6 | |
37 | untested $test7 | |
252b5132 RH |
38 | return |
39 | } | |
40 | ||
14f2c476 AM |
41 | global CFLAGS |
42 | set old_CFLAGS "$CFLAGS" | |
43 | ||
379d3f1f L |
44 | # Pass -fplt to CC since -fno-plt doesn't work with NOCROSSREFS tests. |
45 | global PLT_CFLAGS | |
46 | set old_CC "$CC" | |
47 | set CC "$CC $PLT_CFLAGS" | |
48 | ||
e0001a05 NC |
49 | # Xtensa targets currently default to putting literal values in a separate |
50 | # section and that requires linker script support, so put literals in text. | |
e0001a05 NC |
51 | if [istarget xtensa*-*-*] { |
52 | set CFLAGS "$CFLAGS -mtext-section-literals" | |
53 | } | |
54 | ||
4dcdce13 NC |
55 | # Prevent the use of the MeP's small data area which references a symbol |
56 | # called __sdabase which will not be defined by our test linker scripts. | |
57 | if [istarget mep*-*-elf] { | |
58 | set CFLAGS "-mtiny=0" | |
59 | } | |
60 | ||
ac145307 BS |
61 | # The .dsbt section and __c6xabi_DSBT_BASE are not defined in our test |
62 | # linker scripts. | |
63 | if [istarget tic6x*-*-*] { | |
64 | set CFLAGS "-mno-dsbt -msdata=none" | |
65 | } | |
66 | ||
252b5132 RH |
67 | if { ![ld_compile $CC "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \ |
68 | || ![ld_compile $CC "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } { | |
69 | unresolved $test1 | |
70 | unresolved $test2 | |
14f2c476 | 71 | set CFLAGS "$old_CFLAGS" |
379d3f1f | 72 | set CC "$old_CC" |
252b5132 RH |
73 | return |
74 | } | |
75 | ||
1688b748 | 76 | set flags [big_or_little_endian] |
252b5132 | 77 | |
1b19eb81 AO |
78 | if [istarget sh64*-*-elf] { |
79 | # This is what gcc passes to ld by default. | |
80 | set flags "-mshelf32" | |
81 | } | |
82 | ||
a9fa4610 CZ |
83 | # arc-elf32 requires the symbol __SDATA_BEGIN__ to always be present. |
84 | if [istarget arc*-*-elf32] { | |
85 | set flags "$flags --defsym=__SDATA_BEGIN__=0" | |
86 | } | |
87 | ||
08ccf96b L |
88 | # IA64 has both ordered and unordered sections in an input file. |
89 | setup_xfail ia64-*-* | |
90 | ||
7f6a71ff | 91 | set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"] |
252b5132 RH |
92 | |
93 | set exec_output [prune_warnings $exec_output] | |
94 | ||
95 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
96 | ||
97 | if [string match "" $exec_output] then { | |
98 | fail $test1 | |
99 | } else { | |
100 | verbose -log "$exec_output" | |
dbc37f89 | 101 | if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] { |
252b5132 RH |
102 | pass $test1 |
103 | } else { | |
104 | fail $test1 | |
105 | } | |
106 | } | |
107 | ||
108 | # Check cross references within a single object. | |
109 | ||
110 | if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } { | |
111 | unresolved $test2 | |
14f2c476 | 112 | set CFLAGS "$old_CFLAGS" |
379d3f1f | 113 | set CC "$old_CC" |
252b5132 RH |
114 | return |
115 | } | |
116 | ||
7f6a71ff | 117 | set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"] |
252b5132 RH |
118 | set exec_output [prune_warnings $exec_output] |
119 | ||
120 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
121 | ||
122 | if [string match "" $exec_output] then { | |
123 | fail $test2 | |
124 | } else { | |
125 | verbose -log "$exec_output" | |
126 | if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] { | |
127 | pass $test2 | |
128 | } else { | |
129 | fail $test2 | |
130 | } | |
131 | } | |
b239e909 L |
132 | |
133 | # Check cross references for ld -r | |
134 | ||
135 | if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } { | |
136 | unresolved $test3 | |
14f2c476 | 137 | set CFLAGS "$old_CFLAGS" |
379d3f1f | 138 | set CC "$old_CC" |
b239e909 L |
139 | return |
140 | } | |
141 | ||
142 | if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] { | |
143 | unresolved $test3 | |
14f2c476 | 144 | set CFLAGS "$old_CFLAGS" |
379d3f1f | 145 | set CC "$old_CC" |
b239e909 L |
146 | return |
147 | } | |
148 | ||
7f6a71ff | 149 | 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 |
150 | |
151 | set exec_output [prune_warnings $exec_output] | |
152 | ||
153 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
154 | ||
155 | if [string match "" $exec_output] then { | |
156 | pass $test3 | |
157 | } else { | |
158 | verbose -log "$exec_output" | |
159 | fail $test3 | |
160 | } | |
14f2c476 | 161 | |
cdf96953 MF |
162 | set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross4 -T $srcdir/$subdir/cross4.t tmpdir/cross4.o"] |
163 | set exec_output [prune_warnings $exec_output] | |
164 | ||
165 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
166 | ||
167 | if [string match "" $exec_output] then { | |
168 | pass $test4 | |
169 | } else { | |
170 | verbose -log "$exec_output" | |
171 | fail $test4 | |
172 | } | |
173 | ||
174 | set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross5 -T $srcdir/$subdir/cross5.t tmpdir/cross4.o"] | |
175 | set exec_output [prune_warnings $exec_output] | |
176 | ||
177 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
178 | ||
179 | if [string match "" $exec_output] then { | |
180 | fail $test5 | |
181 | } else { | |
182 | verbose -log "$exec_output" | |
183 | if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] { | |
184 | pass $test5 | |
185 | } else { | |
186 | fail $test5 | |
187 | } | |
188 | } | |
189 | ||
190 | set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross6 -T $srcdir/$subdir/cross6.t tmpdir/cross3.o"] | |
191 | set exec_output [prune_warnings $exec_output] | |
192 | ||
193 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
194 | ||
195 | if [string match "" $exec_output] then { | |
196 | pass $test6 | |
197 | } else { | |
198 | verbose -log "$exec_output" | |
199 | fail $test6 | |
200 | } | |
201 | ||
202 | set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross7 -T $srcdir/$subdir/cross7.t tmpdir/cross3.o"] | |
203 | set exec_output [prune_warnings $exec_output] | |
204 | ||
205 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
206 | ||
207 | if [string match "" $exec_output] then { | |
208 | fail $test7 | |
209 | } else { | |
210 | verbose -log "$exec_output" | |
211 | if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] { | |
212 | pass $test7 | |
213 | } else { | |
214 | fail $test7 | |
215 | } | |
216 | } | |
217 | ||
14f2c476 | 218 | set CFLAGS "$old_CFLAGS" |
379d3f1f | 219 | set CC "$old_CC" |