2013-02-06 Sandra Loosemore <sandra@codesourcery.com>
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / indirect.exp
CommitLineData
90c984fc
L
1# Expect script for various indirect symbol tests.
2# Copyright 2012 Free Software Foundation, Inc.
3#
4# This file is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
17#
18
19#
20# Written by H.J. Lu (hongjiu.lu@intel.com)
21#
22
23# Exclude non-ELF targets.
24
25if ![is_elf_format] {
26 return
27}
28
83a23418
YZ
29# Skip target where -shared is not supported
30
31if ![check_shared_lib_support] {
32 return
33}
34
90c984fc
L
35# Check if compiler works
36if { [which $CC] == 0 } {
37 return
38}
39
36591ba1
SL
40# Some bare-metal targets don't support shared libs or PIC.
41if { ![run_host_cmd_yesno $CC "-shared -fPIC $srcdir/$subdir/dummy.c -o tmpdir/t.so"] } {
42 return
43}
44
90c984fc
L
45proc check_link_message { cmd string testname } {
46 send_log "$cmd\n"
47 verbose "$cmd"
48 catch "exec $cmd" exec_output
49 send_log "$exec_output\n"
50 verbose "$exec_output"
51
52 foreach str $string {
53 if [string match "*$str*" $exec_output] {
54 pass "$testname: $str"
55 } else {
56 fail "$testname: $str"
57 }
58 }
59}
60
61if { ![ld_compile $CC $srcdir/$subdir/indirect1a.c tmpdir/indirect1a.o]
62 || ![ld_compile $CC $srcdir/$subdir/indirect1b.c tmpdir/indirect1b.o]
63 || ![ld_compile "$CC -fPIC" $srcdir/$subdir/indirect2.c tmpdir/indirect2.o]
64 || ![ld_compile $CC $srcdir/$subdir/indirect3a.c tmpdir/indirect3a.o]
65 || ![ld_compile $CC $srcdir/$subdir/indirect3b.c tmpdir/indirect3b.o]
66 || ![ld_compile $CC $srcdir/$subdir/indirect4a.c tmpdir/indirect4a.o]
67 || ![ld_compile $CC $srcdir/$subdir/indirect4b.c tmpdir/indirect4b.o] } {
68 unresolved "Indirect symbol tests"
69 return
70}
71
72set build_tests {
73 {"Build libindirect1c.so"
74 "-shared" "-fPIC"
75 {indirect1c.c} {} "libindirect1c.so"}
76 {"Build libindirect3c.so"
77 "-shared" "-fPIC"
78 {indirect3c.c} {} "libindirect3c.so"}
79 {"Build libindirect4c.so"
80 "-shared" "-fPIC"
81 {indirect4c.c} {} "libindirect4c.so"}
82}
83
84run_cc_link_tests $build_tests
85
86global ld
87
88set string ": final link failed: Bad value"
89set string1 ": local symbol \`foo\' in tmpdir/indirect1b.o is referenced by DSO"
90
91set testname "Indirect symbol 1a"
92set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/indirect1b.o tmpdir/libindirect1c.so"
93check_link_message "$cmd" [list $string1 $string] "$testname"
94
95set testname "Indirect symbol 1b"
96set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/libindirect1c.so tmpdir/indirect1b.o"
97check_link_message "$cmd" [list $string1 $string] "$testname"
98
99set string ": final link failed: Nonrepresentable section on output"
100set string2 ": No symbol version section for versioned symbol \`foo@FOO\'"
101set testname "Indirect symbol 2"
102set cmd "$ld -shared -o tmpdir/indirect2.so tmpdir/indirect2.o"
103check_link_message "$cmd" [list $string2 $string] "$testname"
104
105# The following tests require running the executable generated by ld.
106if ![isnative] {
107 return
108}
109
110set run_tests {
111 {"Run with libindirect3c.so 1"
112 "tmpdir/indirect3a.o tmpdir/indirect3b.o tmpdir/libindirect3c.so" ""
113 {dummy.c} "indirect3a" "indirect3.out"}
114 {"Run with libindirect3c.so 2"
115 "tmpdir/indirect3a.o tmpdir/libindirect3c.so tmpdir/indirect3b.o" ""
116 {dummy.c} "indirect3b" "indirect3.out"}
117 {"Run with libindirect3c.so 3"
118 "tmpdir/indirect3b.o tmpdir/libindirect3c.so tmpdir/indirect3a.o" ""
119 {dummy.c} "indirect3c" "indirect3.out"}
120 {"Run with libindirect3c.so 4"
121 "tmpdir/libindirect3c.so tmpdir/indirect3b.o tmpdir/indirect3a.o" ""
122 {dummy.c} "indirect3d" "indirect3.out"}
123 {"Run with libindirect4c.so 1"
124 "tmpdir/indirect4a.o tmpdir/indirect4b.o tmpdir/libindirect4c.so" ""
125 {dummy.c} "indirect4a" "indirect4.out"}
126 {"Run with libindirect4c.so 2"
127 "tmpdir/indirect4a.o tmpdir/libindirect4c.so tmpdir/indirect4b.o" ""
128 {dummy.c} "indirect4b" "indirect4.out"}
129 {"Run with libindirect4c.so 3"
130 "tmpdir/indirect4b.o tmpdir/libindirect4c.so tmpdir/indirect4a.o" ""
131 {dummy.c} "indirect4c" "indirect4.out"}
132 {"Run with libindirect4c.so 4"
133 "tmpdir/libindirect4c.so tmpdir/indirect4b.o tmpdir/indirect4a.o" ""
134 {dummy.c} "indirect4d" "indirect4.out"}
135}
136
137run_ld_link_exec_tests [] $run_tests
This page took 0.053462 seconds and 4 git commands to generate.