ld/testsuite/
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / indirect.exp
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
25 if ![is_elf_format] {
26 return
27 }
28
29 # Skip target where -shared is not supported
30
31 if ![check_shared_lib_support] {
32 return
33 }
34
35 # Check if compiler works
36 if { [which $CC] == 0 } {
37 return
38 }
39
40 proc check_link_message { cmd string testname } {
41 send_log "$cmd\n"
42 verbose "$cmd"
43 catch "exec $cmd" exec_output
44 send_log "$exec_output\n"
45 verbose "$exec_output"
46
47 foreach str $string {
48 if [string match "*$str*" $exec_output] {
49 pass "$testname: $str"
50 } else {
51 fail "$testname: $str"
52 }
53 }
54 }
55
56 if { ![ld_compile $CC $srcdir/$subdir/indirect1a.c tmpdir/indirect1a.o]
57 || ![ld_compile $CC $srcdir/$subdir/indirect1b.c tmpdir/indirect1b.o]
58 || ![ld_compile "$CC -fPIC" $srcdir/$subdir/indirect2.c tmpdir/indirect2.o]
59 || ![ld_compile $CC $srcdir/$subdir/indirect3a.c tmpdir/indirect3a.o]
60 || ![ld_compile $CC $srcdir/$subdir/indirect3b.c tmpdir/indirect3b.o]
61 || ![ld_compile $CC $srcdir/$subdir/indirect4a.c tmpdir/indirect4a.o]
62 || ![ld_compile $CC $srcdir/$subdir/indirect4b.c tmpdir/indirect4b.o] } {
63 unresolved "Indirect symbol tests"
64 return
65 }
66
67 set build_tests {
68 {"Build libindirect1c.so"
69 "-shared" "-fPIC"
70 {indirect1c.c} {} "libindirect1c.so"}
71 {"Build libindirect3c.so"
72 "-shared" "-fPIC"
73 {indirect3c.c} {} "libindirect3c.so"}
74 {"Build libindirect4c.so"
75 "-shared" "-fPIC"
76 {indirect4c.c} {} "libindirect4c.so"}
77 }
78
79 run_cc_link_tests $build_tests
80
81 global ld
82
83 set string ": final link failed: Bad value"
84 set string1 ": local symbol \`foo\' in tmpdir/indirect1b.o is referenced by DSO"
85
86 set testname "Indirect symbol 1a"
87 set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/indirect1b.o tmpdir/libindirect1c.so"
88 check_link_message "$cmd" [list $string1 $string] "$testname"
89
90 set testname "Indirect symbol 1b"
91 set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/libindirect1c.so tmpdir/indirect1b.o"
92 check_link_message "$cmd" [list $string1 $string] "$testname"
93
94 set string ": final link failed: Nonrepresentable section on output"
95 set string2 ": No symbol version section for versioned symbol \`foo@FOO\'"
96 set testname "Indirect symbol 2"
97 set cmd "$ld -shared -o tmpdir/indirect2.so tmpdir/indirect2.o"
98 check_link_message "$cmd" [list $string2 $string] "$testname"
99
100 # The following tests require running the executable generated by ld.
101 if ![isnative] {
102 return
103 }
104
105 set run_tests {
106 {"Run with libindirect3c.so 1"
107 "tmpdir/indirect3a.o tmpdir/indirect3b.o tmpdir/libindirect3c.so" ""
108 {dummy.c} "indirect3a" "indirect3.out"}
109 {"Run with libindirect3c.so 2"
110 "tmpdir/indirect3a.o tmpdir/libindirect3c.so tmpdir/indirect3b.o" ""
111 {dummy.c} "indirect3b" "indirect3.out"}
112 {"Run with libindirect3c.so 3"
113 "tmpdir/indirect3b.o tmpdir/libindirect3c.so tmpdir/indirect3a.o" ""
114 {dummy.c} "indirect3c" "indirect3.out"}
115 {"Run with libindirect3c.so 4"
116 "tmpdir/libindirect3c.so tmpdir/indirect3b.o tmpdir/indirect3a.o" ""
117 {dummy.c} "indirect3d" "indirect3.out"}
118 {"Run with libindirect4c.so 1"
119 "tmpdir/indirect4a.o tmpdir/indirect4b.o tmpdir/libindirect4c.so" ""
120 {dummy.c} "indirect4a" "indirect4.out"}
121 {"Run with libindirect4c.so 2"
122 "tmpdir/indirect4a.o tmpdir/libindirect4c.so tmpdir/indirect4b.o" ""
123 {dummy.c} "indirect4b" "indirect4.out"}
124 {"Run with libindirect4c.so 3"
125 "tmpdir/indirect4b.o tmpdir/libindirect4c.so tmpdir/indirect4a.o" ""
126 {dummy.c} "indirect4c" "indirect4.out"}
127 {"Run with libindirect4c.so 4"
128 "tmpdir/libindirect4c.so tmpdir/indirect4b.o tmpdir/indirect4a.o" ""
129 {dummy.c} "indirect4d" "indirect4.out"}
130 }
131
132 run_ld_link_exec_tests [] $run_tests
This page took 0.037866 seconds and 5 git commands to generate.