Commit | Line | Data |
---|---|---|
5d3236ee | 1 | # Expect script for ld-plugin tests |
6f2750fe | 2 | # Copyright (C) 2010-2016 Free Software Foundation, Inc. |
5d3236ee DK |
3 | # |
4 | # This file is part of the GNU Binutils. | |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 3 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
19 | # MA 02110-1301, USA. | |
20 | ||
21 | # These tests require the plugin API to be configured in. | |
22 | if ![check_plugin_api_available] { | |
23 | return | |
24 | } | |
25 | ||
c3842ce5 DK |
26 | # And a compiler to be available. |
27 | set can_compile 1 | |
e0ae9e28 | 28 | set failure_kind "unresolved" |
c3842ce5 DK |
29 | if { [which $CC] == 0 } { |
30 | # Don't fail immediately, | |
31 | set can_compile 0 | |
e0ae9e28 | 32 | set failure_kind "unsupported" |
c3842ce5 DK |
33 | } |
34 | ||
5d3236ee DK |
35 | pass "plugin API enabled" |
36 | ||
37 | global base_dir | |
38 | ||
39 | # Look for the name we can dlopen in the test plugin's libtool control script. | |
40 | set plugin_name [file_contents "$base_dir/libldtestplug.la"] | |
41 | set plugin_name [regsub "'.*" [regsub ".*dlname='" "$plugin_name" ""] ""] | |
760f6ee8 NC |
42 | # Even though the API supports plugins it does not mean that the |
43 | # linker was configured with --enable-plugins. Check for that here. | |
44 | if { $plugin_name == "" } { | |
45 | verbose "The linker is not configured to support plugins" | |
46 | return | |
47 | } | |
5d3236ee DK |
48 | verbose "plugin name is '$plugin_name'" |
49 | ||
439b7f41 L |
50 | set plugin2_name [file_contents "$base_dir/libldtestplug2.la"] |
51 | set plugin2_name [regsub "'.*" [regsub ".*dlname='" "$plugin2_name" ""] ""] | |
52 | verbose "plugin2 name is '$plugin2_name'" | |
53 | ||
54 | set plugin3_name [file_contents "$base_dir/libldtestplug3.la"] | |
55 | set plugin3_name [regsub "'.*" [regsub ".*dlname='" "$plugin3_name" ""] ""] | |
56 | verbose "plugin3 name is '$plugin3_name'" | |
57 | ||
5d3236ee DK |
58 | # Use libtool to find full path to plugin rather than worrying |
59 | # about run paths or anything like that. | |
60 | catch "exec $base_dir/libtool --config" lt_config | |
61 | verbose "Full lt config: $lt_config" 3 | |
62 | # Look for "objdir=.libs" | |
63 | regexp -line "^objdir=.*$" "$lt_config" lt_objdir | |
64 | verbose "lt_objdir line is '$lt_objdir'" 3 | |
65 | set lt_objdir [regsub "objdir=" "$lt_objdir" ""] | |
66 | set plugin_path "$base_dir/$lt_objdir/$plugin_name" | |
439b7f41 L |
67 | set plugin2_path "$base_dir/$lt_objdir/$plugin2_name" |
68 | set plugin3_path "$base_dir/$lt_objdir/$plugin3_name" | |
5d3236ee | 69 | verbose "Full plugin path $plugin_path" 2 |
439b7f41 L |
70 | verbose "Full plugin2 path $plugin2_path" 2 |
71 | verbose "Full plugin3 path $plugin3_path" 2 | |
5d3236ee | 72 | |
5d3236ee DK |
73 | set regclm "-plugin-opt registerclaimfile" |
74 | set regas "-plugin-opt registerallsymbolsread" | |
f58926a6 | 75 | set regassilent "-plugin-opt registerallsymbolsreadsilent" |
5d3236ee DK |
76 | set regcln "-plugin-opt registercleanup" |
77 | ||
6927f982 NC |
78 | if { [istarget m681*-*-*] || [istarget m68hc1*-*-*] || [istarget m9s12x*-*-*] } { |
79 | # otherwise get FAILS due to _.frame | |
80 | set CFLAGS "$CFLAGS -fomit-frame-pointer" | |
81 | } | |
5d3236ee DK |
82 | # In order to define symbols in plugin options in the list of tests below, |
83 | # we need to know if the platform prepends an underscore to C symbols, | |
84 | # which we find out by compiling the test objects now. If there is any | |
85 | # error compiling, we defer reporting it until after the list of tests has | |
86 | # been initialised, so that we can use the names in the list to report; | |
87 | # otherwise, we scan one of the files with 'nm' and look for a known symbol | |
88 | # in the output to see if it is prefixed or not. | |
89 | set failed_compile 0 | |
90 | set _ "" | |
91 | set plugin_nm_output "" | |
c3842ce5 DK |
92 | if { $can_compile && \ |
93 | (![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main.c tmpdir/main.o] \ | |
94 | || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/func.c tmpdir/func.o] \ | |
f58926a6 L |
95 | || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/text.c tmpdir/text.o] \ |
96 | || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/dummy.s tmpdir/dummy.o] \ | |
97 | || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/pr17973.s tmpdir/pr17973.o]) } { | |
5d3236ee DK |
98 | # Defer fail until we have list of tests set. |
99 | set failed_compile 1 | |
c3842ce5 DK |
100 | } |
101 | ||
102 | if { $can_compile && !$failed_compile } { | |
5d3236ee DK |
103 | # Find out if symbols have prefix on this platform before setting tests. |
104 | catch "exec $NM tmpdir/func.o" plugin_nm_output | |
105 | if { [regexp "_func" "$plugin_nm_output"] } { | |
106 | set _ "_" | |
107 | } | |
108 | } | |
109 | ||
36fe835f DK |
110 | set testobjfiles "tmpdir/main.o tmpdir/func.o tmpdir/text.o" |
111 | set testobjfiles_notext "tmpdir/main.o tmpdir/func.o" | |
439b7f41 L |
112 | set testsrcfiles "tmpdir/main.o $srcdir/$subdir/func.c tmpdir/text.o" |
113 | set testsrcfiles_notext "tmpdir/main.o $srcdir/$subdir/func.c" | |
36fe835f DK |
114 | # Rather than having libs we just define dummy values for anything |
115 | # we may need to link a target exe; we aren't going to run it anyway. | |
283c0b82 | 116 | set libs "[ld_simple_link_defsyms] --defsym ${_}printf=${_}main --defsym ${_}puts=${_}main" |
36fe835f | 117 | |
5d3236ee DK |
118 | set plugin_tests [list \ |
119 | [list "load plugin" "-plugin $plugin_path \ | |
897aea50 | 120 | $testobjfiles $libs" "" "" "" {{ld plugin-1.d}} "main.x" ] \ |
5d3236ee | 121 | [list "fail plugin onload" "-plugin $plugin_path -plugin-opt failonload \ |
897aea50 | 122 | $testobjfiles $libs" "" "" "" {{ld plugin-2.d}} "main.x" ] \ |
5d3236ee DK |
123 | [list "fail plugin allsymbolsread" "-plugin $plugin_path $regas \ |
124 | -plugin-opt failallsymbolsread \ | |
897aea50 | 125 | $testobjfiles $libs" "" "" "" {{ld plugin-3.d}} "main.x" ] \ |
5d3236ee DK |
126 | [list "fail plugin cleanup" "-plugin $plugin_path -plugin-opt failcleanup \ |
127 | $regcln \ | |
897aea50 | 128 | $testobjfiles $libs" "" "" "" {{ld plugin-4.d}} "main.x" ] \ |
5d3236ee | 129 | [list "plugin all hooks" "-plugin $plugin_path $regclm $regas $regcln \ |
897aea50 | 130 | $testobjfiles $libs" "" "" "" {{ld plugin-5.d}} "main.x" ] \ |
5d3236ee DK |
131 | [list "plugin claimfile lost symbol" "-plugin $plugin_path $regclm \ |
132 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
897aea50 | 133 | $testobjfiles $libs" "" "" "" {{ld plugin-6.d}} "main.x" ] \ |
5d3236ee DK |
134 | [list "plugin claimfile replace symbol" "-plugin $plugin_path $regclm \ |
135 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
136 | -plugin-opt sym:${_}func::0:0:0 \ | |
897aea50 | 137 | $testobjfiles $libs" "" "" "" {{ld plugin-7.d}} "main.x" ] \ |
5d3236ee DK |
138 | [list "plugin claimfile resolve symbol" "-plugin $plugin_path $regclm \ |
139 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
140 | -plugin-opt sym:${_}func::0:0:0 \ | |
141 | -plugin-opt sym:${_}func2::0:0:0 \ | |
142 | -plugin-opt dumpresolutions \ | |
897aea50 | 143 | $testobjfiles $libs" "" "" "" {{ld plugin-8.d}} "main.x" ] \ |
5d3236ee DK |
144 | [list "plugin claimfile replace file" "-plugin $plugin_path $regclm \ |
145 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
146 | -plugin-opt sym:${_}func::0:0:0 \ | |
147 | -plugin-opt sym:${_}func2::0:0:0 \ | |
148 | -plugin-opt dumpresolutions \ | |
149 | -plugin-opt add:tmpdir/func.o \ | |
897aea50 | 150 | $testobjfiles $libs" "" "" "" {{ld plugin-9.d}} "main.x" ] \ |
439b7f41 L |
151 | [list "load plugin with source" "-plugin $plugin_path $regclm \ |
152 | -plugin-opt claim:$srcdir/$subdir/func.c \ | |
153 | $testsrcfiles $libs" "" "" "" {{ld plugin-13.d}} "main.x" ] \ | |
154 | [list "plugin claimfile lost symbol with source" \ | |
155 | "-plugin $plugin_path $regclm $regas $regcln \ | |
156 | -plugin-opt claim:$srcdir/$subdir/func.c \ | |
157 | $testsrcfiles $libs" "" "" "" {{ld plugin-14.d}} "main.x" ] \ | |
158 | [list "plugin claimfile replace symbol with source" \ | |
159 | "-plugin $plugin_path $regclm $regas $regcln \ | |
160 | -plugin-opt claim:$srcdir/$subdir/func.c \ | |
161 | -plugin-opt sym:${_}func::0:0:0 \ | |
162 | $testsrcfiles $libs" "" "" "" {{ld plugin-15.d}} "main.x" ] \ | |
163 | [list "plugin claimfile resolve symbol with source" \ | |
164 | "-plugin $plugin_path $regclm $regas $regcln \ | |
165 | -plugin-opt claim:$srcdir/$subdir/func.c \ | |
166 | -plugin-opt sym:${_}func::0:0:0 \ | |
167 | -plugin-opt sym:${_}func2::0:0:0 \ | |
168 | -plugin-opt dumpresolutions \ | |
169 | $testsrcfiles $libs" "" "" "" {{ld plugin-16.d}} "main.x" ] \ | |
170 | [list "plugin claimfile replace file with source" \ | |
171 | "-plugin $plugin_path $regclm $regas $regcln \ | |
172 | -plugin-opt claim:$srcdir/$subdir/func.c \ | |
173 | -plugin-opt sym:${_}func::0:0:0 \ | |
174 | -plugin-opt sym:${_}func2::0:0:0 \ | |
175 | -plugin-opt dumpresolutions \ | |
176 | -plugin-opt add:tmpdir/func.o \ | |
177 | $testsrcfiles $libs" "" "" "" {{ld plugin-17.d}} "main.x" ] \ | |
178 | [list "load plugin with source not claimed" "-plugin $plugin_path $regclm \ | |
179 | $testsrcfiles $libs" "" "" "" {{ld plugin-26.d}} "main.x" ] \ | |
45e81354 L |
180 | [list "plugin fatal error" "-plugin $plugin2_path -plugin-opt fatal \ |
181 | $testobjfiles $libs" "" "" "" {{ld plugin-27.d}} "main.x" ] \ | |
182 | [list "plugin error" "-plugin $plugin2_path -plugin-opt error \ | |
183 | $testobjfiles $libs" "" "" "" {{ld plugin-28.d}} "main.x" ] \ | |
184 | [list "plugin warning" "-plugin $plugin2_path -plugin-opt warning \ | |
185 | $testobjfiles $libs" "" "" "" {{ld plugin-29.d}} "main.x" ] \ | |
f58926a6 L |
186 | [list "PR ld/17973" "-plugin $plugin2_path -shared $regassilent \ |
187 | -plugin-opt add:tmpdir/pr17973.o \ | |
188 | tmpdir/dummy.o" "" "" "" {{readelf -sW pr17973.d}} "main.x" ] \ | |
5d3236ee DK |
189 | ] |
190 | ||
191 | set plugin_lib_tests [list \ | |
192 | [list "plugin ignore lib" "-plugin $plugin_path $regclm \ | |
193 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
194 | -plugin-opt sym:${_}func::0:0:0 \ | |
195 | -plugin-opt sym:${_}func2::0:0:0 \ | |
196 | -plugin-opt dumpresolutions \ | |
197 | -plugin-opt add:tmpdir/func.o \ | |
897aea50 | 198 | $testobjfiles_notext -Ltmpdir -ltext $libs" "" "" "" {{ld plugin-10.d}} "main.x" ] \ |
5d3236ee DK |
199 | [list "plugin claimfile replace lib" "-plugin $plugin_path $regclm \ |
200 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
201 | -plugin-opt sym:${_}func::0:0:0 \ | |
202 | -plugin-opt sym:${_}func2::0:0:0 \ | |
203 | -plugin-opt dumpresolutions \ | |
204 | -plugin-opt add:tmpdir/func.o \ | |
205 | -plugin-opt claim:tmpdir/libtext.a \ | |
206 | -plugin-opt sym:${_}text::0:0:0 \ | |
207 | -plugin-opt add:tmpdir/text.o \ | |
897aea50 | 208 | $testobjfiles_notext -Ltmpdir -ltext $libs" "" "" "" {{ld plugin-11.d}} "main.x" ] \ |
439b7f41 L |
209 | [list "plugin ignore lib with source" \ |
210 | "-plugin $plugin_path $regclm $regas $regcln \ | |
211 | -plugin-opt claim:$srcdir/$subdir/func.c \ | |
212 | -plugin-opt sym:${_}func::0:0:0 \ | |
213 | -plugin-opt sym:${_}func2::0:0:0 \ | |
214 | -plugin-opt dumpresolutions \ | |
215 | -plugin-opt add:tmpdir/func.o \ | |
216 | $testsrcfiles_notext -Ltmpdir -ltext $libs" "" "" "" {{ld plugin-18.d}} "main.x" ] \ | |
217 | [list "plugin claimfile replace lib with source" \ | |
218 | "-plugin $plugin_path $regclm $regas $regcln \ | |
219 | -plugin-opt claim:$srcdir/$subdir/func.c \ | |
220 | -plugin-opt sym:${_}func::0:0:0 \ | |
221 | -plugin-opt sym:${_}func2::0:0:0 \ | |
222 | -plugin-opt dumpresolutions \ | |
223 | -plugin-opt add:tmpdir/func.o \ | |
224 | -plugin-opt claim:tmpdir/libtext.a \ | |
225 | -plugin-opt sym:${_}text::0:0:0 \ | |
226 | -plugin-opt add:tmpdir/text.o \ | |
227 | $testsrcfiles_notext -Ltmpdir -ltext $libs" "" "" "" {{ld plugin-19.d}} "main.x" ] \ | |
5d3236ee DK |
228 | ] |
229 | ||
230 | set plugin_extra_elf_tests [list \ | |
231 | [list "plugin set symbol visibility" "-plugin $plugin_path $regclm \ | |
232 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
233 | -plugin-opt sym:${_}func::0:0:0 \ | |
234 | -plugin-opt sym:${_}func1::0:1:0 \ | |
235 | -plugin-opt sym:${_}func2::0:2:0 \ | |
236 | -plugin-opt sym:${_}func3::0:3:0 \ | |
237 | -plugin-opt dumpresolutions \ | |
9e2278f5 | 238 | -plugin-opt add:tmpdir/func.o \ |
c4139418 L |
239 | -plugin-opt add:tmpdir/func1p.o \ |
240 | -plugin-opt add:tmpdir/func2i.o \ | |
241 | -plugin-opt add:tmpdir/func3h.o \ | |
897aea50 | 242 | $testobjfiles $libs --verbose=2" "" "" "" {{ld plugin-12.d} \ |
c4139418 | 243 | {readelf -s plugin-vis-1.d}} "main.x" ] \ |
439b7f41 L |
244 | [list "plugin set symbol visibility with source" \ |
245 | "-plugin $plugin_path $regclm $regas $regcln \ | |
246 | -plugin-opt claim:$srcdir/$subdir/func.c \ | |
247 | -plugin-opt sym:${_}func::0:0:0 \ | |
248 | -plugin-opt sym:${_}func1::0:1:0 \ | |
249 | -plugin-opt sym:${_}func2::0:2:0 \ | |
250 | -plugin-opt sym:${_}func3::0:3:0 \ | |
251 | -plugin-opt dumpresolutions \ | |
252 | -plugin-opt add:tmpdir/func.o \ | |
253 | -plugin-opt add:tmpdir/func1p.o \ | |
254 | -plugin-opt add:tmpdir/func2i.o \ | |
255 | -plugin-opt add:tmpdir/func3h.o \ | |
256 | $testsrcfiles $libs --verbose=2" "" "" "" {{ld plugin-12.d} \ | |
257 | {readelf -s plugin-vis-1.d}} "main.x" ] \ | |
5d3236ee DK |
258 | ] |
259 | ||
c3842ce5 | 260 | if { !$can_compile || $failed_compile } { |
5d3236ee | 261 | foreach testitem $plugin_tests { |
e0ae9e28 | 262 | $failure_kind [lindex $testitem 0] |
5d3236ee DK |
263 | } |
264 | if { [is_elf_format] } { | |
265 | foreach testitem $plugin_extra_elf_tests { | |
e0ae9e28 | 266 | $failure_kind [lindex $testitem 0] |
5d3236ee DK |
267 | } |
268 | } | |
269 | return | |
270 | } | |
271 | ||
272 | run_ld_link_tests $plugin_tests | |
273 | ||
c4139418 L |
274 | if { [is_elf_format] \ |
275 | && [ld_compile "$CC $CFLAGS" $srcdir/$subdir/func1p.c tmpdir/func1p.o] \ | |
276 | && [ld_compile "$CC $CFLAGS" $srcdir/$subdir/func2i.c tmpdir/func2i.o] \ | |
277 | && [ld_compile "$CC $CFLAGS" $srcdir/$subdir/func3h.c tmpdir/func3h.o] } { | |
5d3236ee DK |
278 | run_ld_link_tests $plugin_extra_elf_tests |
279 | } | |
280 | ||
281 | if ![ar_simple_create $ar "" "tmpdir/libtext.a" "tmpdir/text.o"] { | |
282 | foreach testitem $plugin_lib_tests { | |
283 | unresolved [lindex $testitem 0] | |
284 | } | |
285 | } else { | |
286 | run_ld_link_tests $plugin_lib_tests | |
287 | } | |
439b7f41 L |
288 | |
289 | set plugin_src_tests [list \ | |
290 | [list "plugin 2 with source lib" \ | |
291 | "-plugin $plugin2_path $regclm $regas $regcln \ | |
292 | -plugin-opt dumpresolutions \ | |
293 | tmpdir/main.o -Ltmpdir -ltext -lfunc $libs" "" "" "" {{ld plugin-20.d}} "main.x" ] \ | |
294 | [list "load plugin 2 with source" \ | |
295 | "-plugin $plugin2_path $regclm $regas $regcln \ | |
296 | -plugin-opt dumpresolutions \ | |
297 | $testsrcfiles $libs" "" "" "" {{ld plugin-21.d}} "main.x" ] \ | |
298 | [list "load plugin 2 with source and -r" \ | |
299 | "-r -plugin $plugin2_path $regclm $regas $regcln \ | |
300 | -plugin-opt dumpresolutions \ | |
301 | $testsrcfiles $libs" "" "" "" {{ld plugin-24.d}} "main.x" ] \ | |
302 | [list "plugin 3 with source lib" \ | |
303 | "-plugin $plugin3_path $regclm $regas $regcln \ | |
304 | -plugin-opt dumpresolutions \ | |
305 | tmpdir/main.o -Ltmpdir -ltext -lfunc $libs" "" "" "" {{ld plugin-22.d}} "main.x" ] \ | |
306 | [list "load plugin 3 with source" \ | |
307 | "-plugin $plugin3_path $regclm $regas $regcln \ | |
308 | -plugin-opt dumpresolutions \ | |
309 | $testsrcfiles $libs" "" "" "" {{ld plugin-23.d}} "main.x" ] \ | |
310 | [list "load plugin 3 with source and -r" \ | |
311 | "-r -plugin $plugin3_path $regclm $regas $regcln \ | |
312 | -plugin-opt dumpresolutions \ | |
313 | $testsrcfiles $libs" "" "" "" {{ld plugin-25.d}} "main.x" ] \ | |
314 | ] | |
315 | ||
316 | # Check if nm --plugin works. | |
317 | set testname "nm --plugin" | |
318 | set nm_plugin "$NM --plugin $plugin2_path $srcdir/$subdir/func.c" | |
319 | catch "exec $nm_plugin" plugin_nm_output | |
320 | send_log "$nm_plugin\n" | |
321 | send_log "$plugin_nm_output\n" | |
322 | if { [regexp "0+ T func" "$plugin_nm_output"] && | |
323 | [regexp "0+ T _func" "$plugin_nm_output"] } { | |
324 | pass $testname | |
325 | } else { | |
326 | fail $testname | |
327 | } | |
328 | ||
329 | # Check if ar --plugin works. | |
330 | file delete tmpdir/libfunc.a | |
331 | if [ar_simple_create $ar "--plugin $plugin2_path" "tmpdir/libfunc.a" \ | |
332 | "tmpdir/main.o $srcdir/$subdir/func.c"] { | |
333 | set testname "ar --plugin" | |
334 | set nm_plugin "$NM -s --plugin $plugin2_path tmpdir/libfunc.a" | |
335 | catch "exec $nm_plugin" plugin_nm_output | |
336 | send_log "$nm_plugin\n" | |
337 | send_log "$plugin_nm_output\n" | |
338 | if { [regexp "func in func.c" "$plugin_nm_output"] && | |
339 | [regexp "_func in func.c" "$plugin_nm_output"] } { | |
340 | pass $testname | |
341 | run_ld_link_tests $plugin_src_tests | |
342 | } else { | |
343 | fail $testname | |
344 | } | |
345 | } else { | |
346 | foreach testitem $plugin_src_tests { | |
347 | unresolved [lindex $testitem 0] | |
348 | } | |
349 | } |