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