*** empty log message ***
[deliverable/binutils-gdb.git] / ld / testsuite / ld-plugin / plugin.exp
CommitLineData
5d3236ee
DK
1# Expect script for ld-plugin tests
2# Copyright 2010
3# Free Software Foundation, Inc.
4#
5# This file is part of the GNU Binutils.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
21
22# These tests require the plugin API to be configured in.
23if ![check_plugin_api_available] {
24 return
25}
26
c3842ce5
DK
27# And a compiler to be available.
28set can_compile 1
e0ae9e28 29set failure_kind "unresolved"
c3842ce5
DK
30if { [which $CC] == 0 } {
31 # Don't fail immediately,
32 set can_compile 0
e0ae9e28 33 set failure_kind "unsupported"
c3842ce5
DK
34}
35
5d3236ee
DK
36pass "plugin API enabled"
37
38global base_dir
39
40# Look for the name we can dlopen in the test plugin's libtool control script.
41set plugin_name [file_contents "$base_dir/libldtestplug.la"]
42set plugin_name [regsub "'.*" [regsub ".*dlname='" "$plugin_name" ""] ""]
43verbose "plugin name is '$plugin_name'"
44
45# Use libtool to find full path to plugin rather than worrying
46# about run paths or anything like that.
47catch "exec $base_dir/libtool --config" lt_config
48verbose "Full lt config: $lt_config" 3
49# Look for "objdir=.libs"
50regexp -line "^objdir=.*$" "$lt_config" lt_objdir
51verbose "lt_objdir line is '$lt_objdir'" 3
52set lt_objdir [regsub "objdir=" "$lt_objdir" ""]
53set plugin_path "$base_dir/$lt_objdir/$plugin_name"
54verbose "Full plugin path $plugin_path" 2
55
5d3236ee
DK
56set regclm "-plugin-opt registerclaimfile"
57set regas "-plugin-opt registerallsymbolsread"
58set regcln "-plugin-opt registercleanup"
59
6927f982
NC
60if { [istarget m681*-*-*] || [istarget m68hc1*-*-*] || [istarget m9s12x*-*-*] } {
61 # otherwise get FAILS due to _.frame
62 set CFLAGS "$CFLAGS -fomit-frame-pointer"
63}
5d3236ee
DK
64# In order to define symbols in plugin options in the list of tests below,
65# we need to know if the platform prepends an underscore to C symbols,
66# which we find out by compiling the test objects now. If there is any
67# error compiling, we defer reporting it until after the list of tests has
68# been initialised, so that we can use the names in the list to report;
69# otherwise, we scan one of the files with 'nm' and look for a known symbol
70# in the output to see if it is prefixed or not.
71set failed_compile 0
72set _ ""
73set plugin_nm_output ""
c3842ce5
DK
74if { $can_compile && \
75 (![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main.c tmpdir/main.o] \
76 || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/func.c tmpdir/func.o] \
77 || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/text.c tmpdir/text.o]) } {
5d3236ee
DK
78 # Defer fail until we have list of tests set.
79 set failed_compile 1
c3842ce5
DK
80}
81
82if { $can_compile && !$failed_compile } {
5d3236ee
DK
83 # Find out if symbols have prefix on this platform before setting tests.
84 catch "exec $NM tmpdir/func.o" plugin_nm_output
85 if { [regexp "_func" "$plugin_nm_output"] } {
86 set _ "_"
87 }
88}
89
36fe835f
DK
90set testobjfiles "tmpdir/main.o tmpdir/func.o tmpdir/text.o"
91set testobjfiles_notext "tmpdir/main.o tmpdir/func.o"
92# Rather than having libs we just define dummy values for anything
93# we may need to link a target exe; we aren't going to run it anyway.
283c0b82 94set libs "[ld_simple_link_defsyms] --defsym ${_}printf=${_}main --defsym ${_}puts=${_}main"
36fe835f 95
5d3236ee
DK
96set plugin_tests [list \
97 [list "load plugin" "-plugin $plugin_path \
98 $testobjfiles $libs" "" "" {{ld plugin-1.d}} "main.x" ] \
99 [list "fail plugin onload" "-plugin $plugin_path -plugin-opt failonload \
100 $testobjfiles $libs" "" "" {{ld plugin-2.d}} "main.x" ] \
101 [list "fail plugin allsymbolsread" "-plugin $plugin_path $regas \
102 -plugin-opt failallsymbolsread \
103 $testobjfiles $libs" "" "" {{ld plugin-3.d}} "main.x" ] \
104 [list "fail plugin cleanup" "-plugin $plugin_path -plugin-opt failcleanup \
105 $regcln \
106 $testobjfiles $libs" "" "" {{ld plugin-4.d}} "main.x" ] \
107 [list "plugin all hooks" "-plugin $plugin_path $regclm $regas $regcln \
108 $testobjfiles $libs" "" "" {{ld plugin-5.d}} "main.x" ] \
109 [list "plugin claimfile lost symbol" "-plugin $plugin_path $regclm \
110 $regas $regcln -plugin-opt claim:tmpdir/func.o \
111 $testobjfiles $libs" "" "" {{ld plugin-6.d}} "main.x" ] \
112 [list "plugin claimfile replace symbol" "-plugin $plugin_path $regclm \
113 $regas $regcln -plugin-opt claim:tmpdir/func.o \
114 -plugin-opt sym:${_}func::0:0:0 \
115 $testobjfiles $libs" "" "" {{ld plugin-7.d}} "main.x" ] \
116 [list "plugin claimfile resolve symbol" "-plugin $plugin_path $regclm \
117 $regas $regcln -plugin-opt claim:tmpdir/func.o \
118 -plugin-opt sym:${_}func::0:0:0 \
119 -plugin-opt sym:${_}func2::0:0:0 \
120 -plugin-opt dumpresolutions \
121 $testobjfiles $libs" "" "" {{ld plugin-8.d}} "main.x" ] \
122 [list "plugin claimfile replace file" "-plugin $plugin_path $regclm \
123 $regas $regcln -plugin-opt claim:tmpdir/func.o \
124 -plugin-opt sym:${_}func::0:0:0 \
125 -plugin-opt sym:${_}func2::0:0:0 \
126 -plugin-opt dumpresolutions \
127 -plugin-opt add:tmpdir/func.o \
128 $testobjfiles $libs" "" "" {{ld plugin-9.d}} "main.x" ] \
129]
130
131set plugin_lib_tests [list \
132 [list "plugin ignore lib" "-plugin $plugin_path $regclm \
133 $regas $regcln -plugin-opt claim:tmpdir/func.o \
134 -plugin-opt sym:${_}func::0:0:0 \
135 -plugin-opt sym:${_}func2::0:0:0 \
136 -plugin-opt dumpresolutions \
137 -plugin-opt add:tmpdir/func.o \
138 $testobjfiles_notext -Ltmpdir -ltext $libs" "" "" {{ld plugin-10.d}} "main.x" ] \
139 [list "plugin claimfile replace lib" "-plugin $plugin_path $regclm \
140 $regas $regcln -plugin-opt claim:tmpdir/func.o \
141 -plugin-opt sym:${_}func::0:0:0 \
142 -plugin-opt sym:${_}func2::0:0:0 \
143 -plugin-opt dumpresolutions \
144 -plugin-opt add:tmpdir/func.o \
145 -plugin-opt claim:tmpdir/libtext.a \
146 -plugin-opt sym:${_}text::0:0:0 \
147 -plugin-opt add:tmpdir/text.o \
148 $testobjfiles_notext -Ltmpdir -ltext $libs" "" "" {{ld plugin-11.d}} "main.x" ] \
149]
150
151set plugin_extra_elf_tests [list \
152 [list "plugin set symbol visibility" "-plugin $plugin_path $regclm \
153 $regas $regcln -plugin-opt claim:tmpdir/func.o \
154 -plugin-opt sym:${_}func::0:0:0 \
155 -plugin-opt sym:${_}func1::0:1:0 \
156 -plugin-opt sym:${_}func2::0:2:0 \
157 -plugin-opt sym:${_}func3::0:3:0 \
158 -plugin-opt dumpresolutions \
9e2278f5 159 -plugin-opt add:tmpdir/func.o \
c4139418
L
160 -plugin-opt add:tmpdir/func1p.o \
161 -plugin-opt add:tmpdir/func2i.o \
162 -plugin-opt add:tmpdir/func3h.o \
163 $testobjfiles $libs --verbose=2" "" "" {{ld plugin-12.d} \
164 {readelf -s plugin-vis-1.d}} "main.x" ] \
5d3236ee
DK
165]
166
c3842ce5 167if { !$can_compile || $failed_compile } {
5d3236ee 168 foreach testitem $plugin_tests {
e0ae9e28 169 $failure_kind [lindex $testitem 0]
5d3236ee
DK
170 }
171 if { [is_elf_format] } {
172 foreach testitem $plugin_extra_elf_tests {
e0ae9e28 173 $failure_kind [lindex $testitem 0]
5d3236ee
DK
174 }
175 }
176 return
177}
178
179run_ld_link_tests $plugin_tests
180
c4139418
L
181if { [is_elf_format] \
182 && [ld_compile "$CC $CFLAGS" $srcdir/$subdir/func1p.c tmpdir/func1p.o] \
183 && [ld_compile "$CC $CFLAGS" $srcdir/$subdir/func2i.c tmpdir/func2i.o] \
184 && [ld_compile "$CC $CFLAGS" $srcdir/$subdir/func3h.c tmpdir/func3h.o] } {
5d3236ee
DK
185 run_ld_link_tests $plugin_extra_elf_tests
186}
187
188if ![ar_simple_create $ar "" "tmpdir/libtext.a" "tmpdir/text.o"] {
189 foreach testitem $plugin_lib_tests {
190 unresolved [lindex $testitem 0]
191 }
192} else {
193 run_ld_link_tests $plugin_lib_tests
194}
This page took 0.117986 seconds and 4 git commands to generate.