Properly merge hidden versioned symbol
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / indirect.exp
1 # Expect script for various indirect symbol tests.
2 # Copyright (C) 2012-2015 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 # Some bare-metal targets don't support shared libs or PIC.
41 if { ![run_host_cmd_yesno $CC "-shared -fPIC $srcdir/$subdir/dummy.c -o tmpdir/t.so"] } {
42 return
43 }
44
45 proc 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
61 if { ![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 || ![ld_compile "$CC -O2 -fPIC -I../bfd" $srcdir/$subdir/pr18720a.c tmpdir/pr18720a.o]
69 || ![ld_compile $CC $srcdir/$subdir/pr18720b.c tmpdir/pr18720b.o] } {
70 unresolved "Indirect symbol tests"
71 return
72 }
73
74 set build_tests {
75 {"Build libindirect1c.so"
76 "-shared" "-fPIC"
77 {indirect1c.c} {} "libindirect1c.so"}
78 {"Build libindirect3c.so"
79 "-shared" "-fPIC"
80 {indirect3c.c} {} "libindirect3c.so"}
81 {"Build libindirect4c.so"
82 "-shared" "-fPIC"
83 {indirect4c.c} {} "libindirect4c.so"}
84 {"Build libpr18720c.so"
85 "-shared" "-fPIC"
86 {pr18720c.c} {} "libpr18720c.so"}
87 {"Build pr18720b1.o"
88 "-r -nostdlib tmpdir/pr18720b.o" ""
89 {dummy.c} {} "pr18720b1.o"}
90 }
91
92 run_cc_link_tests $build_tests
93
94 global ld
95
96 set string ": final link failed: Bad value"
97 set string1 ": local symbol \`foo\' in tmpdir/indirect1b.o is referenced by DSO"
98
99 set testname "Indirect symbol 1a"
100 set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/indirect1b.o tmpdir/libindirect1c.so"
101 check_link_message "$cmd" [list $string1 $string] "$testname"
102
103 set testname "Indirect symbol 1b"
104 set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/libindirect1c.so tmpdir/indirect1b.o"
105 check_link_message "$cmd" [list $string1 $string] "$testname"
106
107 set string ": final link failed: Nonrepresentable section on output"
108 set string2 ": No symbol version section for versioned symbol \`foo@FOO\'"
109 set testname "Indirect symbol 2"
110 set cmd "$ld -shared -o tmpdir/indirect2.so tmpdir/indirect2.o"
111 check_link_message "$cmd" [list $string2 $string] "$testname"
112
113 # The following tests require running the executable generated by ld.
114 if ![isnative] {
115 return
116 }
117
118 set run_tests {
119 {"Run with libindirect3c.so 1"
120 "tmpdir/indirect3a.o tmpdir/indirect3b.o tmpdir/libindirect3c.so" ""
121 {dummy.c} "indirect3a" "indirect3.out"}
122 {"Run with libindirect3c.so 2"
123 "tmpdir/indirect3a.o tmpdir/libindirect3c.so tmpdir/indirect3b.o" ""
124 {dummy.c} "indirect3b" "indirect3.out"}
125 {"Run with libindirect3c.so 3"
126 "tmpdir/indirect3b.o tmpdir/libindirect3c.so tmpdir/indirect3a.o" ""
127 {dummy.c} "indirect3c" "indirect3.out"}
128 {"Run with libindirect3c.so 4"
129 "tmpdir/libindirect3c.so tmpdir/indirect3b.o tmpdir/indirect3a.o" ""
130 {dummy.c} "indirect3d" "indirect3.out"}
131 {"Run with libindirect4c.so 1"
132 "tmpdir/indirect4a.o tmpdir/indirect4b.o tmpdir/libindirect4c.so" ""
133 {dummy.c} "indirect4a" "indirect4.out"}
134 {"Run with libindirect4c.so 2"
135 "tmpdir/indirect4a.o tmpdir/libindirect4c.so tmpdir/indirect4b.o" ""
136 {dummy.c} "indirect4b" "indirect4.out"}
137 {"Run with libindirect4c.so 3"
138 "tmpdir/indirect4b.o tmpdir/libindirect4c.so tmpdir/indirect4a.o" ""
139 {dummy.c} "indirect4c" "indirect4.out"}
140 {"Run with libindirect4c.so 4"
141 "tmpdir/libindirect4c.so tmpdir/indirect4b.o tmpdir/indirect4a.o" ""
142 {dummy.c} "indirect4d" "indirect4.out"}
143 {"Run with libpr18720c.so 1"
144 "tmpdir/pr18720a.o tmpdir/pr18720b.o tmpdir/libpr18720c.so" ""
145 {check-ptr-eq.c} "pr18720a" "pr18720.out"}
146 {"Run with libpr18720c.so 2"
147 "tmpdir/pr18720a.o tmpdir/libpr18720c.so tmpdir/pr18720b.o" ""
148 {check-ptr-eq.c} "pr18720b" "pr18720.out"}
149 {"Run with libpr18720c.so 3"
150 "tmpdir/pr18720b.o tmpdir/libpr18720c.so tmpdir/pr18720a.o" ""
151 {check-ptr-eq.c} "pr18720c" "pr18720.out"}
152 {"Run with libpr18720c.so 4"
153 "tmpdir/libpr18720c.so tmpdir/pr18720b.o tmpdir/pr18720a.o" ""
154 {check-ptr-eq.c} "pr18720d" "pr18720.out"}
155 {"Run with libpr18720c.so 5"
156 "tmpdir/libpr18720c.so tmpdir/pr18720b1.o tmpdir/pr18720a.o" ""
157 {check-ptr-eq.c} "pr18720d" "pr18720.out"}
158 }
159
160 run_ld_link_exec_tests [] $run_tests
This page took 0.036218 seconds and 5 git commands to generate.