From c22ee0ad9de7efff74942263c71b1878003e3eda Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 20 Nov 2014 08:59:42 -0800 Subject: [PATCH] Run IFUNC run-time tests only if IFUNC is supported * lib/ld-lib.exp (check_ifunc_available): New. * ld-ifunc/ifunc.exp: Run IFUNC run-time tests only if IFUNC is supported. --- ld/testsuite/ChangeLog | 6 ++++++ ld/testsuite/ld-ifunc/ifunc.exp | 22 +++++++++++++------ ld/testsuite/lib/ld-lib.exp | 47 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 1a96da9..f8478bd 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-11-20 H.J. Lu + + * lib/ld-lib.exp (check_ifunc_available): New. + * ld-ifunc/ifunc.exp: Run IFUNC run-time tests only if IFUNC + is supported. + 2014-11-20 Terry Guo * ld-arm/attr-merge-nosection-1.d: New file. diff --git a/ld/testsuite/ld-ifunc/ifunc.exp b/ld/testsuite/ld-ifunc/ifunc.exp index 3faced1..d2382f8 100644 --- a/ld/testsuite/ld-ifunc/ifunc.exp +++ b/ld/testsuite/ld-ifunc/ifunc.exp @@ -404,6 +404,21 @@ run_ld_link_exec_tests [] [list \ "ifunc-common-1.out" \ "-g" \ ] \ +] + +set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] +foreach t $test_list { + # We need to strip the ".d", but can leave the dirname. + verbose [file rootname $t] + run_dump_test [file rootname $t] +} + +# Run-time tests which require working IFUNC support. +if { ![check_ifunc_available] } { + return +} + +run_ld_link_exec_tests [] [list \ [list \ "Run pr16467" \ "tmpdir/pr16467c.o tmpdir/libpr16467b.so tmpdir/libpr16467a.so" \ @@ -414,10 +429,3 @@ run_ld_link_exec_tests [] [list \ "" \ ] \ ] - -set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] -foreach t $test_list { - # We need to strip the ".d", but can leave the dirname. - verbose [file rootname $t] - run_dump_test [file rootname $t] -} diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp index 09213bc..870cd12 100644 --- a/ld/testsuite/lib/ld-lib.exp +++ b/ld/testsuite/lib/ld-lib.exp @@ -1820,6 +1820,53 @@ proc check_as_cfi { } { return $success } +# Returns true if IFUNC works. + +proc check_ifunc_available { } { + global ifunc_available_saved + global CC + + if {![info exists ifunc_available_saved]} { + if { [which $CC] == 0 } { + set ifunc_available_saved 0 + return 0 + } + # Check if gcc supports -flto -fuse-linker-plugin + set flags "" + if [board_info [target_info name] exists cflags] { + append flags " [board_info [target_info name] cflags]" + } + if [board_info [target_info name] exists ldflags] { + append flags " [board_info [target_info name] ldflags]" + } + + set basename "tmpdir/ifunc[pid]" + set src ${basename}.c + set output ${basename}.out + set f [open $src "w"] + puts $f "extern int library_func2 (void);" + puts $f "int main (void)" + puts $f "{" + puts $f " if (library_func2 () != 2) __builtin_abort ();" + puts $f " return 0; " + puts $f "}" + puts $f "static int library_func1 (void) {return 2; }" + puts $f "void *foo (void) __asm__ (\"library_func2\");" + puts $f "void *foo (void) { return library_func1; }" + puts $f "__asm__(\".type library_func2, %gnu_indirect_function\");" + close $f + remote_download host $src + set ifunc_available_saved [run_host_cmd_yesno "$CC" "$flags $src -o $output"] + if { $ifunc_available_saved == 1 } { + set ifunc_available_saved [run_host_cmd_yesno "$output" ""] + } + remote_file host delete $src + remote_file host delete $output + file delete $src + } + return $ifunc_available_saved +} + # Provide virtual target "cfi" for targets supporting CFI. rename "istarget" "istarget_ld" -- 2.7.4