1# Expect script for ld-plugin tests 2# Copyright (C) 2010-2014 Free Software Foundation, Inc. 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 26# And a compiler to be available. 27set can_compile 1 28set failure_kind "unresolved" 29if { [which $CC] == 0 } { 30 # Don't fail immediately, 31 set can_compile 0 32 set failure_kind "unsupported" 33} 34 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 44# Use libtool to find full path to plugin rather than worrying 45# about run paths or anything like that. 46catch "exec $base_dir/libtool --config" lt_config 47verbose "Full lt config: $lt_config" 3 48# Look for "objdir=.libs" 49regexp -line "^objdir=.*$" "$lt_config" lt_objdir 50verbose "lt_objdir line is '$lt_objdir'" 3 51set lt_objdir [regsub "objdir=" "$lt_objdir" ""] 52set plugin_path "$base_dir/$lt_objdir/$plugin_name" 53verbose "Full plugin path $plugin_path" 2 54 55set regclm "-plugin-opt registerclaimfile" 56set regas "-plugin-opt registerallsymbolsread" 57set regcln "-plugin-opt registercleanup" 58 59if { [istarget m681*-*-*] || [istarget m68hc1*-*-*] || [istarget m9s12x*-*-*] } { 60 # otherwise get FAILS due to _.frame 61 set CFLAGS "$CFLAGS -fomit-frame-pointer" 62} 63# In order to define symbols in plugin options in the list of tests below, 64# we need to know if the platform prepends an underscore to C symbols, 65# which we find out by compiling the test objects now. If there is any 66# error compiling, we defer reporting it until after the list of tests has 67# been initialised, so that we can use the names in the list to report; 68# otherwise, we scan one of the files with 'nm' and look for a known symbol 69# in the output to see if it is prefixed or not. 70set failed_compile 0 71set _ "" 72set plugin_nm_output "" 73if { $can_compile && \ 74 (![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main.c tmpdir/main.o] \ 75 || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/func.c tmpdir/func.o] \ 76 || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/text.c tmpdir/text.o]) } { 77 # Defer fail until we have list of tests set. 78 set failed_compile 1 79} 80 81if { $can_compile && !$failed_compile } { 82 # Find out if symbols have prefix on this platform before setting tests. 83 catch "exec $NM tmpdir/func.o" plugin_nm_output 84 if { [regexp "_func" "$plugin_nm_output"] } { 85 set _ "_" 86 } 87} 88 89set testobjfiles "tmpdir/main.o tmpdir/func.o tmpdir/text.o" 90set testobjfiles_notext "tmpdir/main.o tmpdir/func.o" 91# Rather than having libs we just define dummy values for anything 92# we may need to link a target exe; we aren't going to run it anyway. 93set libs "[ld_simple_link_defsyms] --defsym ${_}printf=${_}main --defsym ${_}puts=${_}main" 94 95set plugin_tests [list \ 96 [list "load plugin" "-plugin $plugin_path \ 97 $testobjfiles $libs" "" "" "" {{ld plugin-1.d}} "main.x" ] \ 98 [list "fail plugin onload" "-plugin $plugin_path -plugin-opt failonload \ 99 $testobjfiles $libs" "" "" "" {{ld plugin-2.d}} "main.x" ] \ 100 [list "fail plugin allsymbolsread" "-plugin $plugin_path $regas \ 101 -plugin-opt failallsymbolsread \ 102 $testobjfiles $libs" "" "" "" {{ld plugin-3.d}} "main.x" ] \ 103 [list "fail plugin cleanup" "-plugin $plugin_path -plugin-opt failcleanup \ 104 $regcln \ 105 $testobjfiles $libs" "" "" "" {{ld plugin-4.d}} "main.x" ] \ 106 [list "plugin all hooks" "-plugin $plugin_path $regclm $regas $regcln \ 107 $testobjfiles $libs" "" "" "" {{ld plugin-5.d}} "main.x" ] \ 108 [list "plugin claimfile lost symbol" "-plugin $plugin_path $regclm \ 109 $regas $regcln -plugin-opt claim:tmpdir/func.o \ 110 $testobjfiles $libs" "" "" "" {{ld plugin-6.d}} "main.x" ] \ 111 [list "plugin claimfile replace symbol" "-plugin $plugin_path $regclm \ 112 $regas $regcln -plugin-opt claim:tmpdir/func.o \ 113 -plugin-opt sym:${_}func::0:0:0 \ 114 $testobjfiles $libs" "" "" "" {{ld plugin-7.d}} "main.x" ] \ 115 [list "plugin claimfile resolve symbol" "-plugin $plugin_path $regclm \ 116 $regas $regcln -plugin-opt claim:tmpdir/func.o \ 117 -plugin-opt sym:${_}func::0:0:0 \ 118 -plugin-opt sym:${_}func2::0:0:0 \ 119 -plugin-opt dumpresolutions \ 120 $testobjfiles $libs" "" "" "" {{ld plugin-8.d}} "main.x" ] \ 121 [list "plugin claimfile replace file" "-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 $testobjfiles $libs" "" "" "" {{ld plugin-9.d}} "main.x" ] \ 128] 129 130set plugin_lib_tests [list \ 131 [list "plugin ignore lib" "-plugin $plugin_path $regclm \ 132 $regas $regcln -plugin-opt claim:tmpdir/func.o \ 133 -plugin-opt sym:${_}func::0:0:0 \ 134 -plugin-opt sym:${_}func2::0:0:0 \ 135 -plugin-opt dumpresolutions \ 136 -plugin-opt add:tmpdir/func.o \ 137 $testobjfiles_notext -Ltmpdir -ltext $libs" "" "" "" {{ld plugin-10.d}} "main.x" ] \ 138 [list "plugin claimfile replace lib" "-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 \ 143 -plugin-opt add:tmpdir/func.o \ 144 -plugin-opt claim:tmpdir/libtext.a \ 145 -plugin-opt sym:${_}text::0:0:0 \ 146 -plugin-opt add:tmpdir/text.o \ 147 $testobjfiles_notext -Ltmpdir -ltext $libs" "" "" "" {{ld plugin-11.d}} "main.x" ] \ 148] 149 150set plugin_extra_elf_tests [list \ 151 [list "plugin set symbol visibility" "-plugin $plugin_path $regclm \ 152 $regas $regcln -plugin-opt claim:tmpdir/func.o \ 153 -plugin-opt sym:${_}func::0:0:0 \ 154 -plugin-opt sym:${_}func1::0:1:0 \ 155 -plugin-opt sym:${_}func2::0:2:0 \ 156 -plugin-opt sym:${_}func3::0:3:0 \ 157 -plugin-opt dumpresolutions \ 158 -plugin-opt add:tmpdir/func.o \ 159 -plugin-opt add:tmpdir/func1p.o \ 160 -plugin-opt add:tmpdir/func2i.o \ 161 -plugin-opt add:tmpdir/func3h.o \ 162 $testobjfiles $libs --verbose=2" "" "" "" {{ld plugin-12.d} \ 163 {readelf -s plugin-vis-1.d}} "main.x" ] \ 164] 165 166if { !$can_compile || $failed_compile } { 167 foreach testitem $plugin_tests { 168 $failure_kind [lindex $testitem 0] 169 } 170 if { [is_elf_format] } { 171 foreach testitem $plugin_extra_elf_tests { 172 $failure_kind [lindex $testitem 0] 173 } 174 } 175 return 176} 177 178run_ld_link_tests $plugin_tests 179 180if { [is_elf_format] \ 181 && [ld_compile "$CC $CFLAGS" $srcdir/$subdir/func1p.c tmpdir/func1p.o] \ 182 && [ld_compile "$CC $CFLAGS" $srcdir/$subdir/func2i.c tmpdir/func2i.o] \ 183 && [ld_compile "$CC $CFLAGS" $srcdir/$subdir/func3h.c tmpdir/func3h.o] } { 184 run_ld_link_tests $plugin_extra_elf_tests 185} 186 187if ![ar_simple_create $ar "" "tmpdir/libtext.a" "tmpdir/text.o"] { 188 foreach testitem $plugin_lib_tests { 189 unresolved [lindex $testitem 0] 190 } 191} else { 192 run_ld_link_tests $plugin_lib_tests 193} 194