1 # Test NOCROSSREFS in a linker script.
2 # By Ian Lance Taylor, Cygnus Support.
3 # Copyright (C) 2000-2020 Free Software Foundation, Inc.
5 # This file is part of the GNU Binutils.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
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.
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
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 set test1 "NOCROSSREFS 1"
23 set test2 "NOCROSSREFS 2"
24 set test3 "NOCROSSREFS 3"
25 set test4 "NOCROSSREFS_TO 1"
26 set test5 "NOCROSSREFS_TO 2"
27 set test6 "NOCROSSREFS_TO 3"
28 set test7 "NOCROSSREFS_TO 4"
30 if { ![check_compiler_available] } {
41 set old_CFLAGS "$CFLAGS"
43 # Pass -fplt to CC since -fno-plt doesn't work with NOCROSSREFS tests.
44 # Also add $NOPIE_CFLAGS since PIE doesn't work NOCROSSREFS tests.
46 set CC "$CC $PLT_CFLAGS $NOPIE_CFLAGS"
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.
50 if [istarget xtensa*-*-*] {
51 set CFLAGS "$CFLAGS -mtext-section-literals"
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.
56 if [istarget mep*-*-elf] {
60 # The .dsbt section and __c6xabi_DSBT_BASE are not defined in our test
62 if [istarget tic6x*-*-*] {
63 set CFLAGS "-mno-dsbt -msdata=none"
66 if { ![ld_compile $CC "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \
67 || ![ld_compile $CC "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } {
70 set CFLAGS "$old_CFLAGS"
75 set flags [big_or_little_endian]
77 # arc-elf32 requires the symbol __SDATA_BEGIN__ to always be present.
78 if [istarget arc*-*-elf32] {
79 set flags "$flags --defsym=__SDATA_BEGIN__=0"
82 # IA64 has both ordered and unordered sections in an input file.
85 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"]
87 set exec_output [prune_warnings $exec_output]
89 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
91 if [string match "" $exec_output] then {
94 verbose -log "$exec_output"
95 if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] {
102 # Check cross references within a single object.
104 if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } {
106 set CFLAGS "$old_CFLAGS"
111 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"]
112 set exec_output [prune_warnings $exec_output]
114 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
116 if [string match "" $exec_output] then {
119 verbose -log "$exec_output"
120 if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
127 # Check cross references for ld -r
129 if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } {
131 set CFLAGS "$old_CFLAGS"
136 if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] {
138 set CFLAGS "$old_CFLAGS"
143 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o"]
145 set exec_output [prune_warnings $exec_output]
147 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
149 if [string match "" $exec_output] then {
152 verbose -log "$exec_output"
156 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross4 -T $srcdir/$subdir/cross4.t tmpdir/cross4.o"]
157 set exec_output [prune_warnings $exec_output]
159 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
161 if [string match "" $exec_output] then {
164 verbose -log "$exec_output"
168 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross5 -T $srcdir/$subdir/cross5.t tmpdir/cross4.o"]
169 set exec_output [prune_warnings $exec_output]
171 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
173 if [string match "" $exec_output] then {
176 verbose -log "$exec_output"
177 if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
184 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross6 -T $srcdir/$subdir/cross6.t tmpdir/cross3.o"]
185 set exec_output [prune_warnings $exec_output]
187 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
189 if [string match "" $exec_output] then {
192 verbose -log "$exec_output"
196 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross7 -T $srcdir/$subdir/cross7.t tmpdir/cross3.o"]
197 set exec_output [prune_warnings $exec_output]
199 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
201 if [string match "" $exec_output] then {
204 verbose -log "$exec_output"
205 if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
212 set CFLAGS "$old_CFLAGS"