summaryrefslogtreecommitdiffstats
path: root/ld/testsuite/ld-scripts/crossref.exp
blob: c47e05ffc37b6376927abab48469caddf763d528 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Test NOCROSSREFS in a linker script.
# By Ian Lance Taylor, Cygnus Support.
#   Copyright 2000, 2001, 2002, 2003, 2004
#   Free Software Foundation, Inc.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.

set test1 "NOCROSSREFS 1"
set test2 "NOCROSSREFS 2"
set test3 "NOCROSSREFS 3"

if { [which $CC] == 0 } {
    untested $test1
    untested $test2
    untested $test3
    return
}

# Xtensa targets currently default to putting literal values in a separate
# section and that requires linker script support, so put literals in text.
global CFLAGS
if [istarget xtensa*-*-*] {
    set CFLAGS "$CFLAGS -mtext-section-literals"
}

# If we have a compiler that doesn't use/reference dot-symbols, then
# calls to functions reference the .opd section function descriptor.
# This makes NOCROSSREFS rather useless on powerpc64.
if [istarget powerpc64*-*-*] {
    set CFLAGS "$CFLAGS -mcall-aixdesc"
}

if { ![ld_compile $CC "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \
     || ![ld_compile $CC "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } {
    unresolved $test1
    unresolved $test2
    return
}

set flags [big_or_little_endian]

if [istarget sh64*-*-elf] {
    # This is what gcc passes to ld by default.
    set flags "-mshelf32"
}

# IA64 has both ordered and unordered sections in an input file.
setup_xfail ia64-*-*

verbose -log "$ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"

catch "exec $ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o" exec_output

set exec_output [prune_warnings $exec_output]

regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output

if [string match "" $exec_output] then {
    fail $test1
} else {
    verbose -log "$exec_output"
    if [regexp "prohibited cross reference from .* to `.*foo' in" $exec_output] {
	pass $test1
    } else {
	fail $test1
    }
}

# Check cross references within a single object.

if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } {
    unresolved $test2
    return
}

verbose -log "$ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"

catch "exec $ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o" exec_output

set exec_output [prune_warnings $exec_output]

regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output

if [string match "" $exec_output] then {
    fail $test2
} else {
    verbose -log "$exec_output"
    if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
	pass $test2
    } else {
	fail $test2
    }
}

# Check cross references for ld -r

if { ![ld_compile $CC "$srcdir/$subdir/cross4.c" tmpdir/cross4.o] } {
    unresolved $test3
    return
}

if ![ld_relocate $ld tmpdir/cross3-partial.o "tmpdir/cross1.o tmpdir/cross4.o"] {
    unresolved $test3
    return
}

verbose -log "$ld $flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o"

catch "exec $ld $flags -o tmpdir/cross3 -T $srcdir/$subdir/cross3.t tmpdir/cross3-partial.o tmpdir/cross2.o" exec_output

set exec_output [prune_warnings $exec_output]

regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output

if [string match "" $exec_output] then {
    pass $test3
} else {
    verbose -log "$exec_output"
    fail $test3
}
OpenPOWER on IntegriCloud