* elf.c (bfd_section_from_shdr): Remove extraneous breaks.
[binutils.git] / ld / testsuite / ld-scripts / crossref.exp
blobc47e05ffc37b6376927abab48469caddf763d528
1 # Test NOCROSSREFS in a linker script.
2 # By Ian Lance Taylor, Cygnus Support.
3 # Copyright 2000, 2001, 2002, 2003, 2004
4 # Free Software Foundation, Inc.
6 # This file is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
20 set test1 "NOCROSSREFS 1"
21 set test2 "NOCROSSREFS 2"
22 set test3 "NOCROSSREFS 3"
24 if { [which $CC] == 0 } {
25 untested $test1
26 untested $test2
27 untested $test3
28 return
31 # Xtensa targets currently default to putting literal values in a separate
32 # section and that requires linker script support, so put literals in text.
33 global CFLAGS
34 if [istarget xtensa*-*-*] {
35 set CFLAGS "$CFLAGS -mtext-section-literals"
38 # If we have a compiler that doesn't use/reference dot-symbols, then
39 # calls to functions reference the .opd section function descriptor.
40 # This makes NOCROSSREFS rather useless on powerpc64.
41 if [istarget powerpc64*-*-*] {
42 set CFLAGS "$CFLAGS -mcall-aixdesc"
45 if { ![ld_compile $CC "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \
46 || ![ld_compile $CC "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } {
47 unresolved $test1
48 unresolved $test2
49 return
52 set flags [big_or_little_endian]
54 if [istarget sh64*-*-elf] {
55 # This is what gcc passes to ld by default.
56 set flags "-mshelf32"
59 # IA64 has both ordered and unordered sections in an input file.
60 setup_xfail ia64-*-*
62 verbose -log "$ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"
64 catch "exec $ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o" exec_output
66 set exec_output [prune_warnings $exec_output]
68 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
70 if [string match "" $exec_output] then {
71 fail $test1
72 } else {
73 verbose -log "$exec_output"
74 if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] {
75 pass $test1
76 } else {
77 fail $test1
81 # Check cross references within a single object.
83 if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } {
84 unresolved $test2
85 return
88 verbose -log "$ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"
90 catch "exec $ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o" exec_output
92 set exec_output [prune_warnings $exec_output]
94 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
96 if [string match "" $exec_output] then {
97 fail $test2
98 } else {
99 verbose -log "$exec_output"
100 if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
101 pass $test2
102 } else {
103 fail $test2
107 # Check cross references for ld -r
109 if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } {
110 unresolved $test3
111 return
114 if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] {
115 unresolved $test3
116 return
119 verbose -log "$ld $flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o"
121 catch "exec $ld $flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o" exec_output
123 set exec_output [prune_warnings $exec_output]
125 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
127 if [string match "" $exec_output] then {
128 pass $test3
129 } else {
130 verbose -log "$exec_output"
131 fail $test3