1 # Test NOCROSSREFS in a linker script.
2 # By Ian Lance Taylor, Cygnus Support.
3 # Copyright (C) 2000-2014 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"
26 if { ![is_remote host] && [which $CC] == 0 } {
34 set old_CFLAGS "$CFLAGS"
36 # Xtensa targets currently default to putting literal values in a separate
37 # section and that requires linker script support, so put literals in text.
38 if [istarget xtensa*-*-*] {
39 set CFLAGS "$CFLAGS -mtext-section-literals"
42 # If we have a compiler that doesn't use/reference dot-symbols, then
43 # calls to functions reference the .opd section function descriptor.
44 # This makes NOCROSSREFS rather useless on powerpc64.
45 if [istarget powerpc64-*-*] {
46 set CFLAGS "$CFLAGS -mcall-aixdesc"
49 # Prevent the use of the MeP's small data area which references a symbol
50 # called __sdabase which will not be defined by our test linker scripts.
51 if [istarget mep*-*-elf] {
55 # The .dsbt section and __c6xabi_DSBT_BASE are not defined in our test
57 if [istarget tic6x*-*-*] {
58 set CFLAGS "-mno-dsbt -msdata=none"
61 if { ![ld_compile $CC "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \
62 || ![ld_compile $CC "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } {
65 set CFLAGS "$old_CFLAGS"
69 set flags [big_or_little_endian]
71 if [istarget sh64*-*-elf] {
72 # This is what gcc passes to ld by default.
76 # IA64 has both ordered and unordered sections in an input file.
79 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"]
81 set exec_output [prune_warnings $exec_output]
83 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
85 if [string match "" $exec_output] then {
88 verbose -log "$exec_output"
89 if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] {
96 # Check cross references within a single object.
98 if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } {
100 set CFLAGS "$old_CFLAGS"
104 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"]
105 set exec_output [prune_warnings $exec_output]
107 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
109 if [string match "" $exec_output] then {
112 verbose -log "$exec_output"
113 if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
120 # Check cross references for ld -r
122 if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } {
124 set CFLAGS "$old_CFLAGS"
128 if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] {
130 set CFLAGS "$old_CFLAGS"
134 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o"]
136 set exec_output [prune_warnings $exec_output]
138 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
140 if [string match "" $exec_output] then {
143 verbose -log "$exec_output"
147 set CFLAGS "$old_CFLAGS"