aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-elf/indirect.exp
blob: d5d3abc52c2df36a96fd3b1c9b82d35706792dec (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
133
134
135
136
137
# Expect script for various indirect symbol tests.
#   Copyright 2012 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.
#

#
# Written by H.J. Lu (hongjiu.lu@intel.com)
#

# Exclude non-ELF targets.

if ![is_elf_format] {
    return
}

# Skip target where -shared is not supported

if ![check_shared_lib_support] {
    return
}

# Check if compiler works
if { [which $CC] == 0 } {
    return
}

# Some bare-metal targets don't support shared libs or PIC.
if { ![run_host_cmd_yesno $CC "-shared -fPIC $srcdir/$subdir/dummy.c -o tmpdir/t.so"] } {
    return
}

proc check_link_message { cmd string testname } {
    send_log "$cmd\n"
    verbose "$cmd"
    catch "exec $cmd" exec_output
    send_log "$exec_output\n"
    verbose "$exec_output"

    foreach str $string {
	if [string match "*$str*" $exec_output] {
	    pass "$testname: $str"
	} else {
	    fail "$testname: $str"
	}
    }
}

if { ![ld_compile $CC $srcdir/$subdir/indirect1a.c tmpdir/indirect1a.o]
     || ![ld_compile $CC $srcdir/$subdir/indirect1b.c tmpdir/indirect1b.o]
     || ![ld_compile "$CC -fPIC" $srcdir/$subdir/indirect2.c tmpdir/indirect2.o]
     || ![ld_compile $CC $srcdir/$subdir/indirect3a.c tmpdir/indirect3a.o]
     || ![ld_compile $CC $srcdir/$subdir/indirect3b.c tmpdir/indirect3b.o]
     || ![ld_compile $CC $srcdir/$subdir/indirect4a.c tmpdir/indirect4a.o]
     || ![ld_compile $CC $srcdir/$subdir/indirect4b.c tmpdir/indirect4b.o] } {
    unresolved "Indirect symbol tests"
    return
}

set build_tests {
  {"Build libindirect1c.so"
   "-shared" "-fPIC"
   {indirect1c.c} {} "libindirect1c.so"}
  {"Build libindirect3c.so"
   "-shared" "-fPIC"
   {indirect3c.c} {} "libindirect3c.so"}
  {"Build libindirect4c.so"
   "-shared" "-fPIC"
   {indirect4c.c} {} "libindirect4c.so"}
}

run_cc_link_tests $build_tests

global ld

set string ": final link failed: Bad value"
set string1 ": local symbol \`foo\' in tmpdir/indirect1b.o is referenced by DSO"

set testname "Indirect symbol 1a"
set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/indirect1b.o tmpdir/libindirect1c.so"
check_link_message "$cmd" [list $string1 $string] "$testname"

set testname "Indirect symbol 1b"
set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/libindirect1c.so tmpdir/indirect1b.o"
check_link_message "$cmd" [list $string1 $string] "$testname"

set string ": final link failed: Nonrepresentable section on output"
set string2 ": No symbol version section for versioned symbol \`foo@FOO\'"
set testname "Indirect symbol 2"
set cmd "$ld -shared  -o tmpdir/indirect2.so tmpdir/indirect2.o"
check_link_message "$cmd" [list $string2 $string] "$testname"

# The following tests require running the executable generated by ld.
if ![isnative] {
    return
}

set run_tests {
    {"Run with libindirect3c.so 1"
     "tmpdir/indirect3a.o tmpdir/indirect3b.o tmpdir/libindirect3c.so" ""
     {dummy.c} "indirect3a" "indirect3.out"}
    {"Run with libindirect3c.so 2"
     "tmpdir/indirect3a.o tmpdir/libindirect3c.so tmpdir/indirect3b.o" ""
     {dummy.c} "indirect3b" "indirect3.out"}
    {"Run with libindirect3c.so 3"
     "tmpdir/indirect3b.o tmpdir/libindirect3c.so tmpdir/indirect3a.o" ""
     {dummy.c} "indirect3c" "indirect3.out"}
    {"Run with libindirect3c.so 4"
     "tmpdir/libindirect3c.so tmpdir/indirect3b.o tmpdir/indirect3a.o" ""
     {dummy.c} "indirect3d" "indirect3.out"}
    {"Run with libindirect4c.so 1"
     "tmpdir/indirect4a.o tmpdir/indirect4b.o tmpdir/libindirect4c.so" ""
     {dummy.c} "indirect4a" "indirect4.out"}
    {"Run with libindirect4c.so 2"
     "tmpdir/indirect4a.o tmpdir/libindirect4c.so tmpdir/indirect4b.o" ""
     {dummy.c} "indirect4b" "indirect4.out"}
    {"Run with libindirect4c.so 3"
     "tmpdir/indirect4b.o tmpdir/libindirect4c.so tmpdir/indirect4a.o" ""
     {dummy.c} "indirect4c" "indirect4.out"}
    {"Run with libindirect4c.so 4"
     "tmpdir/libindirect4c.so tmpdir/indirect4b.o tmpdir/indirect4a.o" ""
     {dummy.c} "indirect4d" "indirect4.out"}
}

run_ld_link_exec_tests [] $run_tests