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