0b56d3ff21e9c58a6bfed276ec605a44f4ddc8fc
[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
26 if { ![is_remote host] && [which $CC] == 0 } {
27 untested $test1
28 untested $test2
29 untested $test3
30 return
31 }
32
33 global CFLAGS
34 set old_CFLAGS "$CFLAGS"
35
36 # Pass -fplt to CC since -fno-plt doesn't work with NOCROSSREFS tests.
37 global PLT_CFLAGS
38 set old_CC "$CC"
39 set CC "$CC $PLT_CFLAGS"
40
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.
43 if [istarget xtensa*-*-*] {
44 set CFLAGS "$CFLAGS -mtext-section-literals"
45 }
46
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.
50 if [istarget powerpc64-*-*] {
51 set CFLAGS "$CFLAGS -mcall-aixdesc"
52 }
53
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.
56 if [istarget mep*-*-elf] {
57 set CFLAGS "-mtiny=0"
58 }
59
60 # The .dsbt section and __c6xabi_DSBT_BASE are not defined in our test
61 # linker scripts.
62 if [istarget tic6x*-*-*] {
63 set CFLAGS "-mno-dsbt -msdata=none"
64 }
65
66 if { ![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
70 set CFLAGS "$old_CFLAGS"
71 set CC "$old_CC"
72 return
73 }
74
75 set flags [big_or_little_endian]
76
77 if [istarget sh64*-*-elf] {
78 # This is what gcc passes to ld by default.
79 set flags "-mshelf32"
80 }
81
82 # IA64 has both ordered and unordered sections in an input file.
83 setup_xfail ia64-*-*
84
85 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"]
86
87 set exec_output [prune_warnings $exec_output]
88
89 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
90
91 if [string match "" $exec_output] then {
92 fail $test1
93 } else {
94 verbose -log "$exec_output"
95 if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] {
96 pass $test1
97 } else {
98 fail $test1
99 }
100 }
101
102 # Check cross references within a single object.
103
104 if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } {
105 unresolved $test2
106 set CFLAGS "$old_CFLAGS"
107 set CC "$old_CC"
108 return
109 }
110
111 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"]
112 set exec_output [prune_warnings $exec_output]
113
114 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
115
116 if [string match "" $exec_output] then {
117 fail $test2
118 } else {
119 verbose -log "$exec_output"
120 if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
121 pass $test2
122 } else {
123 fail $test2
124 }
125 }
126
127 # Check cross references for ld -r
128
129 if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } {
130 unresolved $test3
131 set CFLAGS "$old_CFLAGS"
132 set CC "$old_CC"
133 return
134 }
135
136 if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] {
137 unresolved $test3
138 set CFLAGS "$old_CFLAGS"
139 set CC "$old_CC"
140 return
141 }
142
143 set exec_output [run_host_cmd "$ld" "$flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o"]
144
145 set exec_output [prune_warnings $exec_output]
146
147 regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
148
149 if [string match "" $exec_output] then {
150 pass $test3
151 } else {
152 verbose -log "$exec_output"
153 fail $test3
154 }
155
156 set CFLAGS "$old_CFLAGS"
157 set CC "$old_CC"
This page took 0.045829 seconds and 3 git commands to generate.