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