]>
Commit | Line | Data |
---|---|---|
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. | |
23 | if ![check_plugin_api_available] { | |
24 | return | |
25 | } | |
26 | ||
27 | pass "plugin API enabled" | |
28 | ||
29 | global base_dir | |
30 | ||
31 | # Look for the name we can dlopen in the test plugin's libtool control script. | |
32 | set plugin_name [file_contents "$base_dir/libldtestplug.la"] | |
33 | set plugin_name [regsub "'.*" [regsub ".*dlname='" "$plugin_name" ""] ""] | |
34 | verbose "plugin name is '$plugin_name'" | |
35 | ||
36 | # Use libtool to find full path to plugin rather than worrying | |
37 | # about run paths or anything like that. | |
38 | catch "exec $base_dir/libtool --config" lt_config | |
39 | verbose "Full lt config: $lt_config" 3 | |
40 | # Look for "objdir=.libs" | |
41 | regexp -line "^objdir=.*$" "$lt_config" lt_objdir | |
42 | verbose "lt_objdir line is '$lt_objdir'" 3 | |
43 | set lt_objdir [regsub "objdir=" "$lt_objdir" ""] | |
44 | set plugin_path "$base_dir/$lt_objdir/$plugin_name" | |
45 | verbose "Full plugin path $plugin_path" 2 | |
46 | ||
47 | set testobjfiles "$HOSTING_CRT0 tmpdir/main.o tmpdir/func.o tmpdir/text.o" | |
48 | set testobjfiles_notext "$HOSTING_CRT0 tmpdir/main.o tmpdir/func.o" | |
49 | set libs "$LIBS $HOSTING_LIBS" | |
50 | ||
51 | set regclm "-plugin-opt registerclaimfile" | |
52 | set regas "-plugin-opt registerallsymbolsread" | |
53 | set regcln "-plugin-opt registercleanup" | |
54 | ||
55 | # In order to define symbols in plugin options in the list of tests below, | |
56 | # we need to know if the platform prepends an underscore to C symbols, | |
57 | # which we find out by compiling the test objects now. If there is any | |
58 | # error compiling, we defer reporting it until after the list of tests has | |
59 | # been initialised, so that we can use the names in the list to report; | |
60 | # otherwise, we scan one of the files with 'nm' and look for a known symbol | |
61 | # in the output to see if it is prefixed or not. | |
62 | set failed_compile 0 | |
63 | set _ "" | |
64 | set plugin_nm_output "" | |
65 | if { ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main.c tmpdir/main.o] | |
66 | || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/func.c tmpdir/func.o] | |
67 | || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/text.c tmpdir/text.o] } { | |
68 | # Defer fail until we have list of tests set. | |
69 | set failed_compile 1 | |
70 | } else { | |
71 | # Find out if symbols have prefix on this platform before setting tests. | |
72 | catch "exec $NM tmpdir/func.o" plugin_nm_output | |
73 | if { [regexp "_func" "$plugin_nm_output"] } { | |
74 | set _ "_" | |
75 | } | |
76 | } | |
77 | ||
78 | set plugin_tests [list \ | |
79 | [list "load plugin" "-plugin $plugin_path \ | |
80 | $testobjfiles $libs" "" "" {{ld plugin-1.d}} "main.x" ] \ | |
81 | [list "fail plugin onload" "-plugin $plugin_path -plugin-opt failonload \ | |
82 | $testobjfiles $libs" "" "" {{ld plugin-2.d}} "main.x" ] \ | |
83 | [list "fail plugin allsymbolsread" "-plugin $plugin_path $regas \ | |
84 | -plugin-opt failallsymbolsread \ | |
85 | $testobjfiles $libs" "" "" {{ld plugin-3.d}} "main.x" ] \ | |
86 | [list "fail plugin cleanup" "-plugin $plugin_path -plugin-opt failcleanup \ | |
87 | $regcln \ | |
88 | $testobjfiles $libs" "" "" {{ld plugin-4.d}} "main.x" ] \ | |
89 | [list "plugin all hooks" "-plugin $plugin_path $regclm $regas $regcln \ | |
90 | $testobjfiles $libs" "" "" {{ld plugin-5.d}} "main.x" ] \ | |
91 | [list "plugin claimfile lost symbol" "-plugin $plugin_path $regclm \ | |
92 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
93 | $testobjfiles $libs" "" "" {{ld plugin-6.d}} "main.x" ] \ | |
94 | [list "plugin claimfile replace symbol" "-plugin $plugin_path $regclm \ | |
95 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
96 | -plugin-opt sym:${_}func::0:0:0 \ | |
97 | $testobjfiles $libs" "" "" {{ld plugin-7.d}} "main.x" ] \ | |
98 | [list "plugin claimfile resolve symbol" "-plugin $plugin_path $regclm \ | |
99 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
100 | -plugin-opt sym:${_}func::0:0:0 \ | |
101 | -plugin-opt sym:${_}func2::0:0:0 \ | |
102 | -plugin-opt dumpresolutions \ | |
103 | $testobjfiles $libs" "" "" {{ld plugin-8.d}} "main.x" ] \ | |
104 | [list "plugin claimfile replace file" "-plugin $plugin_path $regclm \ | |
105 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
106 | -plugin-opt sym:${_}func::0:0:0 \ | |
107 | -plugin-opt sym:${_}func2::0:0:0 \ | |
108 | -plugin-opt dumpresolutions \ | |
109 | -plugin-opt add:tmpdir/func.o \ | |
110 | $testobjfiles $libs" "" "" {{ld plugin-9.d}} "main.x" ] \ | |
111 | ] | |
112 | ||
113 | set plugin_lib_tests [list \ | |
114 | [list "plugin ignore lib" "-plugin $plugin_path $regclm \ | |
115 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
116 | -plugin-opt sym:${_}func::0:0:0 \ | |
117 | -plugin-opt sym:${_}func2::0:0:0 \ | |
118 | -plugin-opt dumpresolutions \ | |
119 | -plugin-opt add:tmpdir/func.o \ | |
120 | $testobjfiles_notext -Ltmpdir -ltext $libs" "" "" {{ld plugin-10.d}} "main.x" ] \ | |
121 | [list "plugin claimfile replace lib" "-plugin $plugin_path $regclm \ | |
122 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
123 | -plugin-opt sym:${_}func::0:0:0 \ | |
124 | -plugin-opt sym:${_}func2::0:0:0 \ | |
125 | -plugin-opt dumpresolutions \ | |
126 | -plugin-opt add:tmpdir/func.o \ | |
127 | -plugin-opt claim:tmpdir/libtext.a \ | |
128 | -plugin-opt sym:${_}text::0:0:0 \ | |
129 | -plugin-opt add:tmpdir/text.o \ | |
130 | $testobjfiles_notext -Ltmpdir -ltext $libs" "" "" {{ld plugin-11.d}} "main.x" ] \ | |
131 | ] | |
132 | ||
133 | set plugin_extra_elf_tests [list \ | |
134 | [list "plugin set symbol visibility" "-plugin $plugin_path $regclm \ | |
135 | $regas $regcln -plugin-opt claim:tmpdir/func.o \ | |
136 | -plugin-opt sym:${_}func::0:0:0 \ | |
137 | -plugin-opt sym:${_}func1::0:1:0 \ | |
138 | -plugin-opt sym:${_}func2::0:2:0 \ | |
139 | -plugin-opt sym:${_}func3::0:3:0 \ | |
140 | -plugin-opt dumpresolutions \ | |
141 | $testobjfiles $libs" "" "" {{ld plugin-ignore.d} \ | |
142 | {readelf -s plugin-vis-1.d}} "main.x" ] \ | |
143 | ] | |
144 | ||
145 | if { $failed_compile != 0 } { | |
146 | foreach testitem $plugin_tests { | |
147 | unresolved [lindex $testitem 0] | |
148 | } | |
149 | if { [is_elf_format] } { | |
150 | foreach testitem $plugin_extra_elf_tests { | |
151 | unresolved [lindex $testitem 0] | |
152 | } | |
153 | } | |
154 | return | |
155 | } | |
156 | ||
157 | run_ld_link_tests $plugin_tests | |
158 | ||
159 | if { [is_elf_format] } { | |
160 | run_ld_link_tests $plugin_extra_elf_tests | |
161 | } | |
162 | ||
163 | if ![ar_simple_create $ar "" "tmpdir/libtext.a" "tmpdir/text.o"] { | |
164 | foreach testitem $plugin_lib_tests { | |
165 | unresolved [lindex $testitem 0] | |
166 | } | |
167 | } else { | |
168 | run_ld_link_tests $plugin_lib_tests | |
169 | } |