Add new NOCROSSREFS_TO linker script command
[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 (C) 2000-2016 Free Software Foundation, Inc.
4 #
5 # This file is part of the GNU Binutils.
6 #
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.
11 #
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.
16 #
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,
20 # MA 02110-1301, USA.
21
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"
29
30 if { ![is_remote host] && [which $CC] == 0 } {
31 untested $test1
32 untested $test2
33 untested $test3
34 untested $test4
35 untested $test5
36 untested $test6
37 untested $test7
38 return
39 }
40
41 global CFLAGS
42 set old_CFLAGS "$CFLAGS"
43
44 # Pass -fplt to CC since -fno-plt doesn't work with NOCROSSREFS tests.
45 global PLT_CFLAGS
46 set old_CC "$CC"
47 set CC "$CC $PLT_CFLAGS"
48
49 # Xtensa targets currently default to putting literal values in a separate
50 # section and that requires linker script support, so put literals in text.
51 if [istarget xtensa*-*-*] {
52 set CFLAGS "$CFLAGS -mtext-section-literals"
53 }
54
55 # If we have a compiler that doesn't use/reference dot-symbols, then
56 # calls to functions reference the .opd section function descriptor.
57 # This makes NOCROSSREFS rather useless on powerpc64.
58 if [istarget powerpc64-*-*] {
59 set CFLAGS "$CFLAGS -mcall-aixdesc"
60 }
61
62 # Prevent the use of the MeP's small data area which references a symbol
63 # called __sdabase which will not be defined by our test linker scripts.
64 if [istarget mep*-*-elf] {
65 set CFLAGS "-mtiny=0"
66 }
67
68 # The .dsbt section and __c6xabi_DSBT_BASE are not defined in our test
69 # linker scripts.
70 if [istarget tic6x*-*-*] {
71 set CFLAGS "-mno-dsbt -msdata=none"
72 }
73
74 if { ![ld_compile $CC "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \
75 || ![ld_compile $CC "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } {
76 unresolved $test1
77 unresolved $test2
78 set CFLAGS "$old_CFLAGS"
79 set CC "$old_CC"
80 return
81 }
82
83 set flags [big_or_little_endian]
84
85 if [istarget sh64*-*-elf] {
86 # This is what gcc passes to ld by default.
87 set flags "-mshelf32"
88 }
89
90 # arc-elf32 requires the symbol __SDATA_BEGIN__ to always be present.
91 if [istarget arc*-*-elf32] {
92 set flags "$flags --defsym=__SDATA_BEGIN__=0"
93 }
94
95 # IA64 has both ordered and unordered sections in an input file.
96 setup_xfail ia64-*-*
97
98 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"]
99
100 set exec_output [prune_warnings $exec_output]
101
102 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
103
104 if [string match "" $exec_output] then {
105 fail $test1
106 } else {
107 verbose -log "$exec_output"
108 if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] {
109 pass $test1
110 } else {
111 fail $test1
112 }
113 }
114
115 # Check cross references within a single object.
116
117 if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } {
118 unresolved $test2
119 set CFLAGS "$old_CFLAGS"
120 set CC "$old_CC"
121 return
122 }
123
124 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"]
125 set exec_output [prune_warnings $exec_output]
126
127 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
128
129 if [string match "" $exec_output] then {
130 fail $test2
131 } else {
132 verbose -log "$exec_output"
133 if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
134 pass $test2
135 } else {
136 fail $test2
137 }
138 }
139
140 # Check cross references for ld -r
141
142 if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } {
143 unresolved $test3
144 set CFLAGS "$old_CFLAGS"
145 set CC "$old_CC"
146 return
147 }
148
149 if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] {
150 unresolved $test3
151 set CFLAGS "$old_CFLAGS"
152 set CC "$old_CC"
153 return
154 }
155
156 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o"]
157
158 set exec_output [prune_warnings $exec_output]
159
160 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
161
162 if [string match "" $exec_output] then {
163 pass $test3
164 } else {
165 verbose -log "$exec_output"
166 fail $test3
167 }
168
169 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross4 -T $srcdir/$subdir/cross4.t tmpdir/cross4.o"]
170 set exec_output [prune_warnings $exec_output]
171
172 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
173
174 if [string match "" $exec_output] then {
175 pass $test4
176 } else {
177 verbose -log "$exec_output"
178 fail $test4
179 }
180
181 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross5 -T $srcdir/$subdir/cross5.t tmpdir/cross4.o"]
182 set exec_output [prune_warnings $exec_output]
183
184 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
185
186 if [string match "" $exec_output] then {
187 fail $test5
188 } else {
189 verbose -log "$exec_output"
190 if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
191 pass $test5
192 } else {
193 fail $test5
194 }
195 }
196
197 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross6 -T $srcdir/$subdir/cross6.t tmpdir/cross3.o"]
198 set exec_output [prune_warnings $exec_output]
199
200 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
201
202 if [string match "" $exec_output] then {
203 pass $test6
204 } else {
205 verbose -log "$exec_output"
206 fail $test6
207 }
208
209 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross7 -T $srcdir/$subdir/cross7.t tmpdir/cross3.o"]
210 set exec_output [prune_warnings $exec_output]
211
212 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
213
214 if [string match "" $exec_output] then {
215 fail $test7
216 } else {
217 verbose -log "$exec_output"
218 if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
219 pass $test7
220 } else {
221 fail $test7
222 }
223 }
224
225 set CFLAGS "$old_CFLAGS"
226 set CC "$old_CC"
This page took 0.035827 seconds and 4 git commands to generate.