Commit | Line | Data |
---|---|---|
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 | |
20 | set test1 "NOCROSSREFS 1" | |
21 | set test2 "NOCROSSREFS 2" | |
b239e909 | 22 | set test3 "NOCROSSREFS 3" |
252b5132 RH |
23 | |
24 | if { [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. | |
33 | global CFLAGS | |
34 | if [istarget xtensa*-*-*] { | |
35 | set CFLAGS "$CFLAGS -mtext-section-literals" | |
36 | } | |
37 | ||
97e5838e AM |
38 | # If we have a compiler that doesn't use/reference dot-symbols, then |
39 | # calls to functions reference the .opd section function descriptor. | |
40 | # This makes NOCROSSREFS rather useless on powerpc64. | |
41 | if [istarget powerpc64*-*-*] { | |
42 | set CFLAGS "$CFLAGS -mcall-aixdesc" | |
43 | } | |
44 | ||
252b5132 RH |
45 | if { ![ld_compile $CC "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \ |
46 | || ![ld_compile $CC "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } { | |
47 | unresolved $test1 | |
48 | unresolved $test2 | |
49 | return | |
50 | } | |
51 | ||
1688b748 | 52 | set flags [big_or_little_endian] |
252b5132 | 53 | |
1b19eb81 AO |
54 | if [istarget sh64*-*-elf] { |
55 | # This is what gcc passes to ld by default. | |
56 | set flags "-mshelf32" | |
57 | } | |
58 | ||
08ccf96b L |
59 | # IA64 has both ordered and unordered sections in an input file. |
60 | setup_xfail ia64-*-* | |
61 | ||
252b5132 RH |
62 | verbose -log "$ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o" |
63 | ||
64 | catch "exec $ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o" exec_output | |
65 | ||
66 | set exec_output [prune_warnings $exec_output] | |
67 | ||
68 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
69 | ||
70 | if [string match "" $exec_output] then { | |
71 | fail $test1 | |
72 | } else { | |
73 | verbose -log "$exec_output" | |
dbc37f89 | 74 | if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] { |
252b5132 RH |
75 | pass $test1 |
76 | } else { | |
77 | fail $test1 | |
78 | } | |
79 | } | |
80 | ||
81 | # Check cross references within a single object. | |
82 | ||
83 | if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } { | |
84 | unresolved $test2 | |
85 | return | |
86 | } | |
87 | ||
88 | verbose -log "$ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o" | |
89 | ||
90 | catch "exec $ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o" exec_output | |
91 | ||
92 | set exec_output [prune_warnings $exec_output] | |
93 | ||
94 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
95 | ||
96 | if [string match "" $exec_output] then { | |
97 | fail $test2 | |
98 | } else { | |
99 | verbose -log "$exec_output" | |
100 | if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] { | |
101 | pass $test2 | |
102 | } else { | |
103 | fail $test2 | |
104 | } | |
105 | } | |
b239e909 L |
106 | |
107 | # Check cross references for ld -r | |
108 | ||
109 | if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } { | |
110 | unresolved $test3 | |
111 | return | |
112 | } | |
113 | ||
114 | if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] { | |
115 | unresolved $test3 | |
116 | return | |
117 | } | |
118 | ||
119 | verbose -log "$ld $flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o" | |
120 | ||
121 | catch "exec $ld $flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o" exec_output | |
122 | ||
123 | set exec_output [prune_warnings $exec_output] | |
124 | ||
125 | regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output | |
126 | ||
127 | if [string match "" $exec_output] then { | |
128 | pass $test3 | |
129 | } else { | |
130 | verbose -log "$exec_output" | |
131 | fail $test3 | |
132 | } |