2005-10-04 H.J. Lu <hongjiu.lu@intel.com>
[deliverable/binutils-gdb.git] / ld / testsuite / ld-scripts / crossref.exp
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.
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
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
19
20 set test1 "NOCROSSREFS 1"
21 set test2 "NOCROSSREFS 2"
22 set test3 "NOCROSSREFS 3"
23
24 if { [which $CC] == 0 } {
25 untested $test1
26 untested $test2
27 untested $test3
28 return
29 }
30
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"
36 }
37
38 if { ![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
45 set flags [big_or_little_endian]
46
47 if [istarget sh64*-*-elf] {
48 # This is what gcc passes to ld by default.
49 set flags "-mshelf32"
50 }
51
52 # IA64 has both ordered and unordered sections in an input file.
53 setup_xfail ia64-*-*
54
55 verbose -log "$ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"
56
57 catch "exec $ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o" exec_output
58
59 set exec_output [prune_warnings $exec_output]
60
61 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
62
63 if [string match "" $exec_output] then {
64 fail $test1
65 } else {
66 verbose -log "$exec_output"
67 if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] {
68 pass $test1
69 } else {
70 fail $test1
71 }
72 }
73
74 # Check cross references within a single object.
75
76 if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } {
77 unresolved $test2
78 return
79 }
80
81 verbose -log "$ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"
82
83 catch "exec $ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o" exec_output
84
85 set exec_output [prune_warnings $exec_output]
86
87 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
88
89 if [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 }
99
100 # Check cross references for ld -r
101
102 if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } {
103 unresolved $test3
104 return
105 }
106
107 if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] {
108 unresolved $test3
109 return
110 }
111
112 verbose -log "$ld $flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o"
113
114 catch "exec $ld $flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o" exec_output
115
116 set exec_output [prune_warnings $exec_output]
117
118 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
119
120 if [string match "" $exec_output] then {
121 pass $test3
122 } else {
123 verbose -log "$exec_output"
124 fail $test3
125 }
This page took 0.033027 seconds and 5 git commands to generate.