From 0aae7e72a2a11ef1fd2a3b4fd18c8d8d49e0c21b Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 1 May 2017 11:02:55 -0700 Subject: [PATCH] x86: Run GNU2 TLS tests with working GNU2 TLS support Check if GNU2 TLS really works before running GNU2 TLS tests. * testsuite/ld-i386/tls.exp: Run GNU2 TLS tests only if there is working GNU2 TLS support. * testsuite/ld-x86-64/tls.exp: Likewise. * testsuite/lib/ld-lib.exp (check_gnu2_tls_available): New proc. --- ld/ChangeLog | 7 ++++ ld/testsuite/ld-i386/tls.exp | 5 +++ ld/testsuite/ld-x86-64/tls.exp | 5 +++ ld/testsuite/lib/ld-lib.exp | 64 ++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) diff --git a/ld/ChangeLog b/ld/ChangeLog index e15ee0ad63a..238404d2341 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2017-05-01 H.J. Lu + + * testsuite/ld-i386/tls.exp: Run GNU2 TLS tests only if there + is working GNU2 TLS support. + * testsuite/ld-x86-64/tls.exp: Likewise. + * testsuite/lib/ld-lib.exp (check_gnu2_tls_available): New proc. + 2017-04-28 H.J. Lu * testsuite/config/default.exp (GNU2_CFLAGS): New. Set diff --git a/ld/testsuite/ld-i386/tls.exp b/ld/testsuite/ld-i386/tls.exp index 504b0f671a2..7a99e4626ca 100644 --- a/ld/testsuite/ld-i386/tls.exp +++ b/ld/testsuite/ld-i386/tls.exp @@ -177,6 +177,11 @@ run_ld_link_exec_tests [list \ ] \ ] +# Run-time tests which require working GNU2 TLS support. +if { ![check_gnu2_tls_available] } { + return +} + run_cc_link_tests [list \ [list \ "Build libtlsdesc1.so" \ diff --git a/ld/testsuite/ld-x86-64/tls.exp b/ld/testsuite/ld-x86-64/tls.exp index 6b4852bc831..5282146c295 100644 --- a/ld/testsuite/ld-x86-64/tls.exp +++ b/ld/testsuite/ld-x86-64/tls.exp @@ -201,6 +201,11 @@ run_cc_link_tests [list \ ] \ ] +# Run-time tests which require working GNU2 TLS support. +if { ![check_gnu2_tls_available] } { + return +} + run_ld_link_exec_tests [list \ [list \ "Run tlsdesc1" \ diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp index b60fcadf058..aecc7008385 100644 --- a/ld/testsuite/lib/ld-lib.exp +++ b/ld/testsuite/lib/ld-lib.exp @@ -2210,3 +2210,67 @@ proc check_libdl_available { } { } return $libdl_available_saved } + +# Returns true if GNU2 TLS works. + +proc check_gnu2_tls_available { } { + global gnu2_tls_available_saved + global CC + global GNU2_CFLAGS + + if {![info exists gnu2_tls_available_saved]} { + if { [which $CC] == 0 || "$GNU2_CFLAGS" == "" } { + set gnu2_tls_available_saved 0 + return 0 + } + # Check if GNU2 TLS works. + set flags "$GNU2_CFLAGS" + 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/gnu2_tls[pid]" + set src1 ${basename}1.c + set output1 ${basename}.so + set f [open $src1 "w"] + puts $f "extern __thread int zzz;" + puts $f "int foo (void)" + puts $f "{" + puts $f " return zzz;" + puts $f "}" + close $f + if [is_remote host] { + set src1 [remote_download host $src1] + } + set src2 ${basename}2.c + set output2 ${basename}.exe + set f [open $src2 "w"] + puts $f "__thread int zzz = 20;" + puts $f "extern int foo (void);" + puts $f "int main (void)" + puts $f "{" + puts $f " if (foo () != 20) __builtin_abort ();" + puts $f " return 0; " + puts $f "}" + close $f + if [is_remote host] { + set src2 [remote_download host $src2] + } + set gnu2_tls_available_saved [run_host_cmd_yesno "$CC" "-fPIC -shared $flags $src1 -o $output1"] + if { $gnu2_tls_available_saved == 1 } { + set gnu2_tls_available_saved [run_host_cmd_yesno "$CC" "$flags $src2 $output1 -o $output2"] + if { $gnu2_tls_available_saved == 1 } { + set gnu2_tls_available_saved [run_host_cmd_yesno "$output2" ""] + } + } + remote_file host delete $src1 + remote_file host delete $output1 + remote_file host delete $src2 + remote_file host delete $output2 + file delete $src1 $src2 + } + return $gnu2_tls_available_saved +} -- 2.30.2