[ARC] Fix ld testsuite failures.
[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.
6f2750fe 3# Copyright (C) 2000-2016 Free Software Foundation, Inc.
a2b64bed 4#
f96b4a7b
NC
5# This file is part of the GNU Binutils.
6#
7# This program is free software; you can redistribute it and/or modify
a2b64bed 8# it under the terms of the GNU General Public License as published by
f96b4a7b 9# the Free Software Foundation; either version 3 of the License, or
a2b64bed 10# (at your option) any later version.
f96b4a7b 11#
a2b64bed
NC
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.
f96b4a7b 16#
a2b64bed
NC
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
f96b4a7b
NC
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
252b5132
RH
21
22set test1 "NOCROSSREFS 1"
23set test2 "NOCROSSREFS 2"
b239e909 24set test3 "NOCROSSREFS 3"
252b5132 25
7f6a71ff 26if { ![is_remote host] && [which $CC] == 0 } {
252b5132
RH
27 untested $test1
28 untested $test2
b239e909 29 untested $test3
252b5132
RH
30 return
31}
32
14f2c476
AM
33global CFLAGS
34set old_CFLAGS "$CFLAGS"
35
379d3f1f
L
36# Pass -fplt to CC since -fno-plt doesn't work with NOCROSSREFS tests.
37global PLT_CFLAGS
38set old_CC "$CC"
39set CC "$CC $PLT_CFLAGS"
40
e0001a05
NC
41# Xtensa targets currently default to putting literal values in a separate
42# section and that requires linker script support, so put literals in text.
e0001a05
NC
43if [istarget xtensa*-*-*] {
44 set CFLAGS "$CFLAGS -mtext-section-literals"
45}
46
97e5838e
AM
47# If we have a compiler that doesn't use/reference dot-symbols, then
48# calls to functions reference the .opd section function descriptor.
49# This makes NOCROSSREFS rather useless on powerpc64.
14f2c476 50if [istarget powerpc64-*-*] {
97e5838e
AM
51 set CFLAGS "$CFLAGS -mcall-aixdesc"
52}
53
4dcdce13
NC
54# Prevent the use of the MeP's small data area which references a symbol
55# called __sdabase which will not be defined by our test linker scripts.
56if [istarget mep*-*-elf] {
57 set CFLAGS "-mtiny=0"
58}
59
ac145307
BS
60# The .dsbt section and __c6xabi_DSBT_BASE are not defined in our test
61# linker scripts.
62if [istarget tic6x*-*-*] {
63 set CFLAGS "-mno-dsbt -msdata=none"
64}
65
252b5132
RH
66if { ![ld_compile $CC "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \
67 || ![ld_compile $CC "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } {
68 unresolved $test1
69 unresolved $test2
14f2c476 70 set CFLAGS "$old_CFLAGS"
379d3f1f 71 set CC "$old_CC"
252b5132
RH
72 return
73}
74
1688b748 75set flags [big_or_little_endian]
252b5132 76
1b19eb81
AO
77if [istarget sh64*-*-elf] {
78 # This is what gcc passes to ld by default.
79 set flags "-mshelf32"
80}
81
a9fa4610
CZ
82# arc-elf32 requires the symbol __SDATA_BEGIN__ to always be present.
83if [istarget arc*-*-elf32] {
84 set flags "$flags --defsym=__SDATA_BEGIN__=0"
85}
86
08ccf96b
L
87# IA64 has both ordered and unordered sections in an input file.
88setup_xfail ia64-*-*
89
7f6a71ff 90set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"]
252b5132
RH
91
92set exec_output [prune_warnings $exec_output]
93
94regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
95
96if [string match "" $exec_output] then {
97 fail $test1
98} else {
99 verbose -log "$exec_output"
dbc37f89 100 if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] {
252b5132
RH
101 pass $test1
102 } else {
103 fail $test1
104 }
105}
106
107# Check cross references within a single object.
108
109if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } {
110 unresolved $test2
14f2c476 111 set CFLAGS "$old_CFLAGS"
379d3f1f 112 set CC "$old_CC"
252b5132
RH
113 return
114}
115
7f6a71ff 116set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"]
252b5132
RH
117set exec_output [prune_warnings $exec_output]
118
119regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
120
121if [string match "" $exec_output] then {
122 fail $test2
123} else {
124 verbose -log "$exec_output"
125 if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
126 pass $test2
127 } else {
128 fail $test2
129 }
130}
b239e909
L
131
132# Check cross references for ld -r
133
134if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } {
135 unresolved $test3
14f2c476 136 set CFLAGS "$old_CFLAGS"
379d3f1f 137 set CC "$old_CC"
b239e909
L
138 return
139}
140
141if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] {
142 unresolved $test3
14f2c476 143 set CFLAGS "$old_CFLAGS"
379d3f1f 144 set CC "$old_CC"
b239e909
L
145 return
146}
147
7f6a71ff 148set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o"]
b239e909
L
149
150set exec_output [prune_warnings $exec_output]
151
152regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
153
154if [string match "" $exec_output] then {
155 pass $test3
156} else {
157 verbose -log "$exec_output"
158 fail $test3
159}
14f2c476
AM
160
161set CFLAGS "$old_CFLAGS"
379d3f1f 162set CC "$old_CC"
This page took 0.854716 seconds and 4 git commands to generate.