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