libstdc++: Add "futex" and "gthreads" effective-target keywords
authorJonathan Wakely <jwakely@redhat.com>
Thu, 26 Nov 2020 14:13:32 +0000 (14:13 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 26 Nov 2020 16:15:52 +0000 (16:15 +0000)
This adds a new "futex" effective-target keyword that can be used to
selectively enable/disable tests based on _GLIBCXX_HAVE_LINUX_FUTEX,
instead of checking for that macro in the code.

It also adds "gthreads" as another one, to make the result of the
dg-require-gthreads directive usable in target selectors.

With these new keywords two tests that are currently only run for linux
can also be run for targets using gthr-single.h (e.g. AIX single-thread
multilib, and targets without a gthreads implementation).

libstdc++-v3/ChangeLog:

* testsuite/18_support/96817.cc: Use new effective-target
keywords to select supported targets more effectively.
* testsuite/30_threads/call_once/66146.cc: Likewise.
* testsuite/lib/libstdc++.exp (check_effective_target_futex):
Define new proc.
(check_effective_target_gthreads): Define new proc to replace
dg-require-gthreads.

libstdc++-v3/testsuite/18_support/96817.cc
libstdc++-v3/testsuite/30_threads/call_once/66146.cc
libstdc++-v3/testsuite/lib/libstdc++.exp

index 4591a7288a5761957caa093c0e16f67b3046ef5a..7f35f0311c3429e64cbbcfb2fe47b2c9801d7c68 100644 (file)
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-options "-pthread"  }
-// { dg-do run { target *-*-linux-gnu } }
-// { dg-require-effective-target pthread }
+// { dg-do run }
+// { dg-additional-options "-pthread" { target pthread } }
+
+// Static init cannot detect recursion for gthreads targets without futexes
+// (and the futex case can only detect it if __libc_single_threaded==true).
+// { dg-skip-if "unsupported" { gthreads && { ! futex } } }
 
 // PR libstdc++/96817
 
 #include <exception>
 #include <stdlib.h>
 
-#ifndef _GLIBCXX_HAVE_LINUX_FUTEX
-# error "This test requries futex support in the library"
-#endif
-
 int init()
 {
 #if __has_include(<sys/single_threaded.h>)
index b1ca0eb6fe8f2f89ed1a451888f84dd58fb66f7f..a9c99485fa068798591152c93985bd9e2e515fac 100644 (file)
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++11 } }
-// { dg-skip-if "" { pthread && { ! *-*-*linux* } } }
 // { dg-additional-options "-pthread" { target pthread } }
 
+// Currently std::call_once is broken for gthreads targets without futexes:
+// { dg-skip-if "see PR 66146" { gthreads && { ! futex } } }
+
 #include <mutex>
 #include <cstdlib>
 #include <testsuite_hooks.h>
index fc1e8f242fd13e4b0e123d50e6e88705b13731f5..9ba4ced48830ba5bdc1d975dfd9afec08707fc1d 100644 (file)
@@ -1613,6 +1613,38 @@ proc check_effective_target_tbb-backend { } {
     }]
 }
 
+# Return 1 if futex syscall is available
+proc check_effective_target_futex { } {
+    return [check_v3_target_prop_cached et_futex {
+       # Set up and compile a C++ test program that depends on tbb
+       set src futex[pid].cc
+       set exe futex[pid].x
+
+       set f [open $src "w"]
+       puts $f "#include <bits/c++config.h>"
+       puts $f "#if ! _GLIBCXX_HAVE_LINUX_FUTEX"
+       puts $f "#  error No futex syscall available"
+       puts $f "#endif"
+       close $f
+
+       set lines [v3_target_compile $src /dev/null preprocess ""]
+       file delete $src
+
+       if [string match "" $lines] {
+           # No error message, preprocessing succeeded.
+           verbose "check_v3_futex: `1'" 2
+           return 1
+       }
+       verbose "check_v3_futex: `0'" 2
+       return 0
+    }]
+}
+
+# Return 1 if futex syscall is available
+proc check_effective_target_gthreads { } {
+    return [check_v3_target_gthreads_timed]
+}
+
 set additional_prunes ""
 
 if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)] \