2005-10-17 Jim Blandy <jimb@redhat.com>
[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.
aef6203b 3# Copyright 2000, 2001, 2002, 2003, 2004
a2b64bed
NC
4# Free Software Foundation, Inc.
5#
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.
10#
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.
15#
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
75be928b 18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
252b5132
RH
19
20set test1 "NOCROSSREFS 1"
21set test2 "NOCROSSREFS 2"
b239e909 22set test3 "NOCROSSREFS 3"
252b5132
RH
23
24if { [which $CC] == 0 } {
25 untested $test1
26 untested $test2
b239e909 27 untested $test3
252b5132
RH
28 return
29}
30
e0001a05
NC
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.
33global CFLAGS
34if [istarget xtensa*-*-*] {
35 set CFLAGS "$CFLAGS -mtext-section-literals"
36}
37
252b5132
RH
38if { ![ld_compile $CC "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \
39 || ![ld_compile $CC "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } {
40 unresolved $test1
41 unresolved $test2
42 return
43}
44
1688b748 45set flags [big_or_little_endian]
252b5132 46
1b19eb81
AO
47if [istarget sh64*-*-elf] {
48 # This is what gcc passes to ld by default.
49 set flags "-mshelf32"
50}
51
08ccf96b
L
52# IA64 has both ordered and unordered sections in an input file.
53setup_xfail ia64-*-*
54
252b5132
RH
55verbose -log "$ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"
56
57catch "exec $ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o" exec_output
58
59set exec_output [prune_warnings $exec_output]
60
61regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
62
63if [string match "" $exec_output] then {
64 fail $test1
65} else {
66 verbose -log "$exec_output"
dbc37f89 67 if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] {
252b5132
RH
68 pass $test1
69 } else {
70 fail $test1
71 }
72}
73
74# Check cross references within a single object.
75
76if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } {
77 unresolved $test2
78 return
79}
80
81verbose -log "$ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"
82
83catch "exec $ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o" exec_output
84
85set exec_output [prune_warnings $exec_output]
86
87regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
88
89if [string match "" $exec_output] then {
90 fail $test2
91} else {
92 verbose -log "$exec_output"
93 if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
94 pass $test2
95 } else {
96 fail $test2
97 }
98}
b239e909
L
99
100# Check cross references for ld -r
101
102if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } {
103 unresolved $test3
104 return
105}
106
107if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] {
108 unresolved $test3
109 return
110}
111
112verbose -log "$ld $flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o"
113
114catch "exec $ld $flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o" exec_output
115
116set exec_output [prune_warnings $exec_output]
117
118regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
119
120if [string match "" $exec_output] then {
121 pass $test3
122} else {
123 verbose -log "$exec_output"
124 fail $test3
125}
This page took 0.312843 seconds and 4 git commands to generate.