Commit | Line | Data |
---|---|---|
90c984fc | 1 | # Expect script for various indirect symbol tests. |
b3adc24a | 2 | # Copyright (C) 2012-2020 Free Software Foundation, Inc. |
90c984fc L |
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 | ||
83a23418 YZ |
29 | # Skip target where -shared is not supported |
30 | ||
31 | if ![check_shared_lib_support] { | |
32 | return | |
33 | } | |
34 | ||
90c984fc | 35 | # Check if compiler works |
44ed8092 | 36 | if { ![check_compiler_available] } { |
90c984fc L |
37 | return |
38 | } | |
39 | ||
36591ba1 SL |
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 | ||
90c984fc L |
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] | |
6e33951e L |
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] | |
aef28989 L |
69 | || ![ld_compile $CC $srcdir/$subdir/pr18720b.c tmpdir/pr18720b.o] |
70 | || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553d.c tmpdir/pr19553d.o] | |
71 | || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553c.c tmpdir/pr19553c.o] | |
72 | || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553b.c tmpdir/pr19553b.o] | |
73 | || ![ld_compile $CC $srcdir/$subdir/pr19553a.c tmpdir/pr19553a.o] } { | |
90c984fc L |
74 | unresolved "Indirect symbol tests" |
75 | return | |
76 | } | |
77 | ||
78 | set build_tests { | |
79 | {"Build libindirect1c.so" | |
80 | "-shared" "-fPIC" | |
81 | {indirect1c.c} {} "libindirect1c.so"} | |
82 | {"Build libindirect3c.so" | |
83 | "-shared" "-fPIC" | |
84 | {indirect3c.c} {} "libindirect3c.so"} | |
85 | {"Build libindirect4c.so" | |
86 | "-shared" "-fPIC" | |
87 | {indirect4c.c} {} "libindirect4c.so"} | |
c5d37467 AM |
88 | {"Build libindirect5.so" |
89 | "-shared -Wl,--version-script=indirect5.map" "-fPIC" | |
90 | {indirect5b.c} {} "libindirect5.so"} | |
6e33951e L |
91 | {"Build libpr18720c.so" |
92 | "-shared" "-fPIC" | |
93 | {pr18720c.c} {} "libpr18720c.so"} | |
94 | {"Build pr18720b1.o" | |
95 | "-r -nostdlib tmpdir/pr18720b.o" "" | |
96 | {dummy.c} {} "pr18720b1.o"} | |
4deb8f71 L |
97 | {"Build pr18720a" |
98 | "tmpdir/pr18720a.o tmpdir/pr18720b.o tmpdir/libpr18720c.so" "" | |
99 | {check-ptr-eq.c} {{readelf {--dyn-syms} pr18720.rd}} "pr18720a"} | |
aef28989 L |
100 | {"Build libpr19553b.so" |
101 | "-shared -Wl,--version-script=pr19553.map" "-fPIC" | |
102 | {pr19553b.c} {} "libpr19553b.so"} | |
103 | {"Build libpr19553c.so" | |
104 | "-shared -Wl,--version-script=pr19553.map" "-fPIC" | |
105 | {pr19553c.c} {} "libpr19553c.so"} | |
106 | {"Build libpr19553d.so" | |
107 | "-shared tmpdir/libpr19553c.so" "-fPIC" | |
108 | {pr19553d.c} {} "libpr19553d.so"} | |
90c984fc L |
109 | } |
110 | ||
111 | run_cc_link_tests $build_tests | |
112 | ||
6e05870c | 113 | set string ": final link failed: bad value" |
90c984fc L |
114 | set string1 ": local symbol \`foo\' in tmpdir/indirect1b.o is referenced by DSO" |
115 | ||
116 | set testname "Indirect symbol 1a" | |
117 | set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/indirect1b.o tmpdir/libindirect1c.so" | |
118 | check_link_message "$cmd" [list $string1 $string] "$testname" | |
119 | ||
120 | set testname "Indirect symbol 1b" | |
121 | set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/libindirect1c.so tmpdir/indirect1b.o" | |
122 | check_link_message "$cmd" [list $string1 $string] "$testname" | |
123 | ||
9793eb77 | 124 | set string2 ": no symbol version section for versioned symbol \`foo@FOO\'" |
90c984fc L |
125 | set testname "Indirect symbol 2" |
126 | set cmd "$ld -shared -o tmpdir/indirect2.so tmpdir/indirect2.o" | |
847d5183 | 127 | check_link_message "$cmd" [list $string2] "$testname" |
90c984fc | 128 | |
90c984fc L |
129 | set run_tests { |
130 | {"Run with libindirect3c.so 1" | |
d9816402 | 131 | "-Wl,--no-as-needed tmpdir/indirect3a.o tmpdir/indirect3b.o tmpdir/libindirect3c.so" "" |
90c984fc L |
132 | {dummy.c} "indirect3a" "indirect3.out"} |
133 | {"Run with libindirect3c.so 2" | |
d9816402 | 134 | "-Wl,--no-as-needed tmpdir/indirect3a.o tmpdir/libindirect3c.so tmpdir/indirect3b.o" "" |
90c984fc L |
135 | {dummy.c} "indirect3b" "indirect3.out"} |
136 | {"Run with libindirect3c.so 3" | |
d9816402 | 137 | "-Wl,--no-as-needed tmpdir/indirect3b.o tmpdir/libindirect3c.so tmpdir/indirect3a.o" "" |
90c984fc L |
138 | {dummy.c} "indirect3c" "indirect3.out"} |
139 | {"Run with libindirect3c.so 4" | |
d9816402 | 140 | "-Wl,--no-as-needed tmpdir/libindirect3c.so tmpdir/indirect3b.o tmpdir/indirect3a.o" "" |
90c984fc L |
141 | {dummy.c} "indirect3d" "indirect3.out"} |
142 | {"Run with libindirect4c.so 1" | |
d9816402 | 143 | "-Wl,--no-as-needed tmpdir/indirect4a.o tmpdir/indirect4b.o tmpdir/libindirect4c.so" "" |
90c984fc L |
144 | {dummy.c} "indirect4a" "indirect4.out"} |
145 | {"Run with libindirect4c.so 2" | |
d9816402 | 146 | "-Wl,--no-as-needed tmpdir/indirect4a.o tmpdir/libindirect4c.so tmpdir/indirect4b.o" "" |
90c984fc L |
147 | {dummy.c} "indirect4b" "indirect4.out"} |
148 | {"Run with libindirect4c.so 3" | |
d9816402 | 149 | "-Wl,--no-as-needed tmpdir/indirect4b.o tmpdir/libindirect4c.so tmpdir/indirect4a.o" "" |
90c984fc L |
150 | {dummy.c} "indirect4c" "indirect4.out"} |
151 | {"Run with libindirect4c.so 4" | |
d9816402 | 152 | "-Wl,--no-as-needed tmpdir/libindirect4c.so tmpdir/indirect4b.o tmpdir/indirect4a.o" "" |
90c984fc | 153 | {dummy.c} "indirect4d" "indirect4.out"} |
c5d37467 | 154 | {"Run indirect5 1" |
afe9edbf L |
155 | "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libindirect5.so" "" |
156 | {indirect5a.c} "indirect5a" "indirect5.out" "$NOPIE_CFLAGS"} | |
c5d37467 | 157 | {"Run indirect5 2" |
afe9edbf L |
158 | "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/indirect5a.o tmpdir/libindirect5.so" "" |
159 | {dummy.c} "indirect5b" "indirect5.out" "$NOPIE_CFLAGS"} | |
c5d37467 | 160 | {"Run indirect6 1" |
afe9edbf L |
161 | "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libindirect5.so" "" |
162 | {indirect6a.c} "indirect6a" "indirect5.out" "$NOPIE_CFLAGS"} | |
c5d37467 | 163 | {"Run indirect6 2" |
afe9edbf L |
164 | "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/indirect6a.o tmpdir/libindirect5.so" "" |
165 | {dummy.c} "indirect6b" "indirect5.out" "$NOPIE_CFLAGS"} | |
6e33951e | 166 | {"Run with libpr18720c.so 1" |
d9816402 | 167 | "-Wl,--no-as-needed tmpdir/pr18720a.o tmpdir/pr18720b.o tmpdir/libpr18720c.so" "" |
6e33951e L |
168 | {check-ptr-eq.c} "pr18720a" "pr18720.out"} |
169 | {"Run with libpr18720c.so 2" | |
d9816402 | 170 | "-Wl,--no-as-needed tmpdir/pr18720a.o tmpdir/libpr18720c.so tmpdir/pr18720b.o" "" |
6e33951e L |
171 | {check-ptr-eq.c} "pr18720b" "pr18720.out"} |
172 | {"Run with libpr18720c.so 3" | |
d9816402 | 173 | "-Wl,--no-as-needed tmpdir/pr18720b.o tmpdir/libpr18720c.so tmpdir/pr18720a.o" "" |
6e33951e L |
174 | {check-ptr-eq.c} "pr18720c" "pr18720.out"} |
175 | {"Run with libpr18720c.so 4" | |
d9816402 | 176 | "-Wl,--no-as-needed tmpdir/libpr18720c.so tmpdir/pr18720b.o tmpdir/pr18720a.o" "" |
6e33951e L |
177 | {check-ptr-eq.c} "pr18720d" "pr18720.out"} |
178 | {"Run with libpr18720c.so 5" | |
d9816402 | 179 | "-Wl,--no-as-needed tmpdir/libpr18720c.so tmpdir/pr18720b1.o tmpdir/pr18720a.o" "" |
6e33951e | 180 | {check-ptr-eq.c} "pr18720d" "pr18720.out"} |
aef28989 | 181 | {"Run with libpr19553b.so" |
d9816402 | 182 | "-Wl,--no-as-needed tmpdir/libpr19553b.so tmpdir/libpr19553d.so -Wl,-rpath-link,." "" |
aef28989 L |
183 | {pr19553a.c} "pr19553b" "pr19553b.out"} |
184 | {"Run with libpr19553c.so" | |
d9816402 | 185 | "-Wl,--no-as-needed tmpdir/libpr19553c.so tmpdir/libpr19553b.so tmpdir/libpr19553d.so" "" |
aef28989 L |
186 | {pr19553a.c} "pr19553c" "pr19553c.out"} |
187 | {"Run with libpr19553d.so" | |
d9816402 | 188 | "-Wl,--no-as-needed tmpdir/libpr19553d.so tmpdir/libpr19553b.so -Wl,-rpath-link,." "" |
aef28989 | 189 | {pr19553a.c} "pr19553d" "pr19553d.out"} |
90c984fc L |
190 | } |
191 | ||
982c6f26 | 192 | run_ld_link_exec_tests $run_tests |
c5d37467 AM |
193 | |
194 | # Check that "bar" is not dynamic in the executable | |
195 | proc check_dynamic_syms { test } { | |
196 | global nm | |
197 | set cmd "$nm -D $test > dump.out" | |
198 | send_log "$cmd\n" | |
199 | catch "exec $cmd" comp_output | |
200 | if ![string match "" $comp_output] then { | |
201 | send_log "$comp_output\n" | |
202 | return 0 | |
203 | } | |
204 | if { [string match "* bar\n*" [file_contents "dump.out"]] } then { | |
205 | verbose "output is [file_contents "dump.out"]" | |
206 | return 0 | |
207 | } | |
208 | return 1 | |
209 | } | |
210 | ||
211 | foreach t [list indirect5a indirect5b indirect6a indirect6b] { | |
212 | set testname [concat $t "dynsym"] | |
213 | if { [check_dynamic_syms tmpdir/$t] } { | |
214 | pass $testname | |
215 | } else { | |
216 | fail $testname | |
217 | } | |
218 | } | |
219 | ||
220 | send_log "$CC -fPIE -pie $srcdir/$subdir/main.c -o tmpdir/pie" | |
221 | catch "exec $CC -fPIE -pie $srcdir/$subdir/main.c -o tmpdir/pie" exec_output | |
222 | send_log "$exec_output" | |
223 | if { ! [string match "" $exec_output] } { | |
224 | return | |
225 | } | |
226 | ||
227 | set pie_tests { | |
228 | {"Run indirect5 3" | |
229 | "-pie -Wl,--no-as-needed tmpdir/libindirect5.so" "" | |
230 | {indirect5a.c} "indirect5c" "indirect5.out" "-fPIE"} | |
231 | {"Run indirect5 4" | |
232 | "-pie -Wl,--no-as-needed tmpdir/indirect5a.o tmpdir/libindirect5.so" "" | |
233 | {dummy.c} "indirect5d" "indirect5.out" "-fPIE"} | |
234 | {"Run indirect6 3" | |
235 | "-pie -Wl,--no-as-needed tmpdir/libindirect5.so" "" | |
236 | {indirect6a.c} "indirect6c" "indirect5.out" "-fPIE"} | |
237 | {"Run indirect6 4" | |
238 | "-pie -Wl,--no-as-needed tmpdir/indirect6a.o tmpdir/libindirect5.so" "-fPIE" | |
239 | {dummy.c} "indirect6d" "indirect5.out" "-fPIE"} | |
240 | } | |
241 | ||
242 | run_ld_link_exec_tests $pie_tests | |
243 | ||
244 | foreach t [list indirect5c indirect5d indirect6c indirect6d] { | |
245 | set testname [concat $t "dynsym"] | |
246 | if { [check_dynamic_syms tmpdir/$t] } { | |
247 | pass $testname | |
248 | } else { | |
249 | fail $testname | |
250 | } | |
251 | } |