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