[libc++abi] Use from-scratch testing configs for libc++abi by default

Like we have been doing for libc++ for a while now, start using
from-scratch testing configurations for libc++abi.

As a fly-by fix, remove the LIBCXXABI_NO_TIMER macro, which was defined
but never used.

Differential Revision: https://reviews.llvm.org/D125242

GitOrigin-RevId: 851bfc07c86e7f84ee38d918cb4b6b49a47434f1
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 76d54f8..bc7354e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -143,7 +143,24 @@
 option(LIBCXXABI_HERMETIC_STATIC_LIBRARY
   "Do not export any symbols from the static library." ${LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT})
 
-set(LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/lit.site.cfg.in" CACHE STRING
+if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+  set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared-gcc.cfg.in")
+elseif(MINGW)
+  set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-mingw.cfg.in")
+elseif(WIN32) # clang-cl
+  if (LIBCXXABI_ENABLE_SHARED)
+    set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared-clangcl.cfg.in")
+  else()
+    set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-static-clangcl.cfg.in")
+  endif()
+else()
+  if (LIBCXXABI_ENABLE_SHARED)
+    set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared.cfg.in")
+  else()
+    set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-static.cfg.in")
+  endif()
+endif()
+set(LIBCXXABI_TEST_CONFIG "${LIBCXXABI_DEFAULT_TEST_CONFIG}" CACHE STRING
   "The path to the Lit testing configuration to use when running the tests.
    If a relative path is provided, it is assumed to be relative to '<monorepo>/libcxxabi/test/configs'.")
 if (NOT IS_ABSOLUTE "${LIBCXXABI_TEST_CONFIG}")
diff --git a/test/configs/apple-libc++abi-backdeployment.cfg.in b/test/configs/apple-libc++abi-backdeployment.cfg.in
index 510ab8a..e94f15c 100644
--- a/test/configs/apple-libc++abi-backdeployment.cfg.in
+++ b/test/configs/apple-libc++abi-backdeployment.cfg.in
@@ -45,7 +45,7 @@
     '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else ''
 ))
 config.substitutions.append(('%{compile_flags}',
-    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} -DLIBCXXABI_NO_TIMER -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS ' +
+    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS ' +
     '-I %{libcxx}/test/support -I %{libcxx}/src'
 ))
 config.substitutions.append(('%{link_flags}',
diff --git a/test/configs/apple-libc++abi-shared.cfg.in b/test/configs/apple-libc++abi-shared.cfg.in
index 3a744db..20298bc 100644
--- a/test/configs/apple-libc++abi-shared.cfg.in
+++ b/test/configs/apple-libc++abi-shared.cfg.in
@@ -6,7 +6,7 @@
     '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else ''
 ))
 config.substitutions.append(('%{compile_flags}',
-    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} -DLIBCXXABI_NO_TIMER -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS ' +
+    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS ' +
     '-I %{libcxx}/test/support -I %{libcxx}/src'
 ))
 config.substitutions.append(('%{link_flags}',
diff --git a/test/configs/cmake-bridge.cfg.in b/test/configs/cmake-bridge.cfg.in
index 4c37681..d61303a 100644
--- a/test/configs/cmake-bridge.cfg.in
+++ b/test/configs/cmake-bridge.cfg.in
@@ -30,6 +30,11 @@
 config.substitutions.append(('%{libcxx}', '@LIBCXXABI_LIBCXX_PATH@'))
 config.substitutions.append(('%{include}', '@LIBCXXABI_SOURCE_DIR@/include'))
 config.substitutions.append(('%{cxx-include}', '@LIBCXXABI_HEADER_DIR@/include/c++/v1'))
-config.substitutions.append(('%{cxx-target-include}', '@LIBCXXABI_HEADER_DIR@/%{triple}/include/c++/v1'))
+config.substitutions.append(('%{cxx-target-include}', '@LIBCXXABI_HEADER_DIR@/include/%{triple}/c++/v1'))
 config.substitutions.append(('%{lib}', '@LIBCXXABI_LIBRARY_DIR@'))
 config.substitutions.append(('%{executor}', '@LIBCXXABI_EXECUTOR@'))
+
+if @LIBCXXABI_USE_LLVM_UNWINDER@:
+    config.substitutions.append(('%{maybe-include-libunwind}', '-I "@LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL@"'))
+else:
+    config.substitutions.append(('%{maybe-include-libunwind}', ''))
diff --git a/test/configs/ibm-libc++abi-shared.cfg.in b/test/configs/ibm-libc++abi-shared.cfg.in
index 874e735..402841f 100644
--- a/test/configs/ibm-libc++abi-shared.cfg.in
+++ b/test/configs/ibm-libc++abi-shared.cfg.in
@@ -4,8 +4,8 @@
 
 config.substitutions.append(('%{flags}',''))
 config.substitutions.append(('%{compile_flags}',
-    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} ' +
-    '-D__LIBC_NO_CPP_MATH_OVERLOADS__ -DLIBCXXABI_NO_TIMER ' +
+    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} ' +
+    '-D__LIBC_NO_CPP_MATH_OVERLOADS__ ' +
     '-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS ' +
     '-I %{libcxx}/test/support -I %{libcxx}/src'
 ))
diff --git a/test/configs/llvm-libc++abi-merged.cfg.in b/test/configs/llvm-libc++abi-merged.cfg.in
index c17cb08..e61c6af 100644
--- a/test/configs/llvm-libc++abi-merged.cfg.in
+++ b/test/configs/llvm-libc++abi-merged.cfg.in
@@ -6,7 +6,7 @@
     '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else ''
 ))
 config.substitutions.append(('%{compile_flags}',
-    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} -DLIBCXXABI_NO_TIMER -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS ' +
+    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS ' +
     '-I %{libcxx}/test/support -I %{libcxx}/src'
 ))
 config.substitutions.append(('%{link_flags}',
diff --git a/test/configs/llvm-libc++abi-mingw.cfg.in b/test/configs/llvm-libc++abi-mingw.cfg.in
new file mode 100644
index 0000000..b0e07d5
--- /dev/null
+++ b/test/configs/llvm-libc++abi-mingw.cfg.in
@@ -0,0 +1,25 @@
+# This testing configuration handles running the test suite against LLVM's libc++abi
+# using either a DLL or a static library, with MinGW/Clang on Windows.
+
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+
+config.substitutions.append(('%{flags}', ''))
+config.substitutions.append(('%{compile_flags}',
+    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -I %{libcxx}/test/support -I %{libcxx}/src -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS'
+))
+config.substitutions.append(('%{link_flags}',
+    '-nostdlib++ -L %{lib} -lc++ -lc++abi'
+))
+config.substitutions.append(('%{exec}',
+    '%{executor} --execdir %T --env PATH=%{lib} -- '
+))
+
+import os, site
+site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils'))
+import libcxx.test.params, libcxx.test.newconfig
+libcxx.test.newconfig.configure(
+    libcxx.test.params.DEFAULT_PARAMETERS,
+    libcxx.test.features.DEFAULT_FEATURES,
+    config,
+    lit_config
+)
diff --git a/test/configs/llvm-libc++abi-shared-clangcl.cfg.in b/test/configs/llvm-libc++abi-shared-clangcl.cfg.in
new file mode 100644
index 0000000..58d1e87
--- /dev/null
+++ b/test/configs/llvm-libc++abi-shared-clangcl.cfg.in
@@ -0,0 +1,25 @@
+# This testing configuration handles running the test suite against LLVM's libc++abi
+# using a DLL, with Clang-cl on Windows.
+
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+
+config.substitutions.append(('%{flags}', '--driver-mode=g++'))
+config.substitutions.append(('%{compile_flags}',
+    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -I %{libcxx}/test/support -I %{libcxx}/src -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX'
+))
+config.substitutions.append(('%{link_flags}',
+    '-nostdlib -L %{lib} -lc++ -lc++abi -lmsvcrt -lmsvcprt -loldnames'
+))
+config.substitutions.append(('%{exec}',
+    '%{executor} --execdir %T --env PATH=%{lib} -- '
+))
+
+import os, site
+site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils'))
+import libcxx.test.params, libcxx.test.newconfig
+libcxx.test.newconfig.configure(
+    libcxx.test.params.DEFAULT_PARAMETERS,
+    libcxx.test.features.DEFAULT_FEATURES,
+    config,
+    lit_config
+)
diff --git a/test/configs/llvm-libc++abi-shared-gcc.cfg.in b/test/configs/llvm-libc++abi-shared-gcc.cfg.in
new file mode 100644
index 0000000..325fcd5
--- /dev/null
+++ b/test/configs/llvm-libc++abi-shared-gcc.cfg.in
@@ -0,0 +1,26 @@
+# This testing configuration handles running the test suite against LLVM's libc++abi
+# using a shared library, with GCC. This is done differently from Clang because
+# GCC does not support the -nostdlib++ command-line flag.
+
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+
+config.substitutions.append(('%{flags}', ''))
+config.substitutions.append(('%{compile_flags}',
+    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -I %{libcxx}/test/support -I %{libcxx}/src -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS'
+))
+config.substitutions.append(('%{link_flags}',
+    '-L %{lib} -Wl,-rpath,%{lib} -nodefaultlibs -lc++ -lc++abi -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc -latomic'
+))
+config.substitutions.append(('%{exec}',
+    '%{executor} --execdir %T -- '
+))
+
+import os, site
+site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils'))
+import libcxx.test.params, libcxx.test.newconfig
+libcxx.test.newconfig.configure(
+    libcxx.test.params.DEFAULT_PARAMETERS,
+    libcxx.test.features.DEFAULT_FEATURES,
+    config,
+    lit_config
+)
diff --git a/test/configs/llvm-libc++abi-shared.cfg.in b/test/configs/llvm-libc++abi-shared.cfg.in
new file mode 100644
index 0000000..f742574
--- /dev/null
+++ b/test/configs/llvm-libc++abi-shared.cfg.in
@@ -0,0 +1,27 @@
+# This testing configuration handles running the test suite against LLVM's libc++abi
+# using a shared library.
+
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+
+config.substitutions.append(('%{flags}',
+    '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else ''
+))
+config.substitutions.append(('%{compile_flags}',
+    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -I %{libcxx}/test/support -I %{libcxx}/src -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS'
+))
+config.substitutions.append(('%{link_flags}',
+    '-nostdlib++ -L %{lib} -Wl,-rpath,%{lib} -lc++ -lc++abi -pthread'
+))
+config.substitutions.append(('%{exec}',
+    '%{executor} --execdir %T -- '
+))
+
+import os, site
+site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils'))
+import libcxx.test.params, libcxx.test.newconfig
+libcxx.test.newconfig.configure(
+    libcxx.test.params.DEFAULT_PARAMETERS,
+    libcxx.test.features.DEFAULT_FEATURES,
+    config,
+    lit_config
+)
diff --git a/test/configs/llvm-libc++abi-static-clangcl.cfg.in b/test/configs/llvm-libc++abi-static-clangcl.cfg.in
new file mode 100644
index 0000000..8820c5b
--- /dev/null
+++ b/test/configs/llvm-libc++abi-static-clangcl.cfg.in
@@ -0,0 +1,25 @@
+# This testing configuration handles running the test suite against LLVM's libc++abi
+# using a static library, with Clang-cl on Windows.
+
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+
+config.substitutions.append(('%{flags}', '--driver-mode=g++'))
+config.substitutions.append(('%{compile_flags}',
+    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -I %{libcxx}/test/support  -I %{libcxx}/src -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX'
+))
+config.substitutions.append(('%{link_flags}',
+    '-nostdlib -L %{lib} -llibc++ -llibc++abi -lmsvcrt -lmsvcprt -loldnames'
+))
+config.substitutions.append(('%{exec}',
+    '%{executor} --execdir %T --env PATH=%{lib} -- '
+))
+
+import os, site
+site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils'))
+import libcxx.test.params, libcxx.test.newconfig
+libcxx.test.newconfig.configure(
+    libcxx.test.params.DEFAULT_PARAMETERS,
+    libcxx.test.features.DEFAULT_FEATURES,
+    config,
+    lit_config
+)
diff --git a/test/configs/llvm-libc++abi-static.cfg.in b/test/configs/llvm-libc++abi-static.cfg.in
new file mode 100644
index 0000000..c3e7c0a
--- /dev/null
+++ b/test/configs/llvm-libc++abi-static.cfg.in
@@ -0,0 +1,27 @@
+# This testing configuration handles running the test suite against LLVM's libc++abi
+# using a static library.
+
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+
+config.substitutions.append(('%{flags}',
+    '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else ''
+))
+config.substitutions.append(('%{compile_flags}',
+    '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -I %{libcxx}/test/support -I %{libcxx}/src -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS'
+))
+config.substitutions.append(('%{link_flags}',
+    '-nostdlib++ -L %{lib} -lc++ -lc++abi -pthread'
+))
+config.substitutions.append(('%{exec}',
+    '%{executor} --execdir %T -- '
+))
+
+import os, site
+site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils'))
+import libcxx.test.params, libcxx.test.newconfig
+libcxx.test.newconfig.configure(
+    libcxx.test.params.DEFAULT_PARAMETERS,
+    libcxx.test.features.DEFAULT_FEATURES,
+    config,
+    lit_config
+)
diff --git a/test/cxa_thread_atexit_test.pass.cpp b/test/cxa_thread_atexit_test.pass.cpp
index 0f9324b..16186e3 100644
--- a/test/cxa_thread_atexit_test.pass.cpp
+++ b/test/cxa_thread_atexit_test.pass.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: libcxxabi-no-threads
+// UNSUPPORTED: libcpp-has-no-threads
 // REQUIRES: linux
 
 #include <assert.h>
diff --git a/test/forced_unwind3.pass.cpp b/test/forced_unwind3.pass.cpp
index 3bcc797..3468813 100644
--- a/test/forced_unwind3.pass.cpp
+++ b/test/forced_unwind3.pass.cpp
@@ -10,7 +10,7 @@
 // what pthread_cancel does.
 
 // UNSUPPORTED: c++03
-// UNSUPPORTED: libcxxabi-no-threads
+// UNSUPPORTED: libcpp-has-no-threads
 // UNSUPPORTED: no-exceptions
 
 #include <assert.h>
diff --git a/test/guard_test_basic.pass.cpp b/test/guard_test_basic.pass.cpp
index 2ad8e11..6b15dd0 100644
--- a/test/guard_test_basic.pass.cpp
+++ b/test/guard_test_basic.pass.cpp
@@ -8,6 +8,13 @@
 //
 // UNSUPPORTED: c++03
 
+// Necessary because we include a private header of libc++abi, which
+// only understands _LIBCXXABI_HAS_NO_THREADS.
+#include "test_macros.h"
+#ifdef TEST_HAS_NO_THREADS
+# define _LIBCXXABI_HAS_NO_THREADS
+#endif
+
 #define TESTING_CXA_GUARD
 #include "../src/cxa_guard_impl.h"
 #include <cassert>
@@ -117,7 +124,7 @@
 
 int main(int, char**) {
   {
-#if defined(_LIBCXXABI_HAS_NO_THREADS)
+#if defined(TEST_HAS_NO_THREADS)
     static_assert(CurrentImplementation == Implementation::NoThreads, "");
     static_assert(std::is_same<SelectedImplementation, NoThreadsGuard>::value, "");
 #else
@@ -129,7 +136,7 @@
 #endif
   }
   {
-#if (defined(__APPLE__) || defined(__linux__))  && !defined(_LIBCXXABI_HAS_NO_THREADS)
+#if (defined(__APPLE__) || defined(__linux__))  && !defined(TEST_HAS_NO_THREADS)
     assert(PlatformThreadID);
 #endif
     if (PlatformThreadID != nullptr) {
diff --git a/test/guard_threaded_test.pass.cpp b/test/guard_threaded_test.pass.cpp
index ce589fe..fc94dd9 100644
--- a/test/guard_threaded_test.pass.cpp
+++ b/test/guard_threaded_test.pass.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03
-// UNSUPPORTED: libcxxabi-no-threads
+// UNSUPPORTED: libcpp-has-no-threads
 // UNSUPPORTED: no-exceptions
 
 #define TESTING_CXA_GUARD
diff --git a/test/libcxxabi/test/config.py b/test/libcxxabi/test/config.py
index 5855240..be93f15 100644
--- a/test/libcxxabi/test/config.py
+++ b/test/libcxxabi/test/config.py
@@ -50,7 +50,7 @@
             self.cxx.compile_flags += ['-funwind-tables']
         if not self.get_lit_bool('enable_threads', True):
             self.cxx.compile_flags += ['-D_LIBCXXABI_HAS_NO_THREADS']
-            self.config.available_features.add('libcxxabi-no-threads')
+            self.config.available_features.add('libcpp-has-no-threads')
         super(Configuration, self).configure_compile_flags()
 
     def configure_compile_flags_header_includes(self):
diff --git a/test/test_exception_storage.pass.cpp b/test/test_exception_storage.pass.cpp
index 934cc4b..f1cfe6e 100644
--- a/test/test_exception_storage.pass.cpp
+++ b/test/test_exception_storage.pass.cpp
@@ -14,6 +14,8 @@
 
 #include "../src/cxa_exception.h"
 
+#include "test_macros.h"
+
 typedef __cxxabiv1::__cxa_eh_globals globals_t ;
 
 void *thread_code (void *parm) {
@@ -29,20 +31,20 @@
         std::printf("Got different globals!\n");
 
     *result = (size_t) glob1;
-#ifndef _LIBCXXABI_HAS_NO_THREADS
+#ifndef TEST_HAS_NO_THREADS
     sleep ( 1 );
 #endif
     return parm;
 }
 
-#ifndef _LIBCXXABI_HAS_NO_THREADS
+#ifndef TEST_HAS_NO_THREADS
 #define NUMTHREADS  10
 size_t                 thread_globals [ NUMTHREADS ] = { 0 };
 std::__libcpp_thread_t   threads        [ NUMTHREADS ];
 #endif
 
 int main() {
-#ifndef _LIBCXXABI_HAS_NO_THREADS
+#ifndef TEST_HAS_NO_THREADS
 //  Make the threads, let them run, and wait for them to finish
     for ( int i = 0; i < NUMTHREADS; ++i )
         std::__libcpp_thread_create ( threads + i, thread_code, (void *) (thread_globals + i));
@@ -65,10 +67,10 @@
         }
     }
     return retVal;
-#else // _LIBCXXABI_HAS_NO_THREADS
+#else // TEST_HAS_NO_THREADS
     size_t thread_globals;
     thread_code(&thread_globals);
     // Check that __cxa_get_globals() is not NULL.
     return (thread_globals == 0) ? 1 : 0;
-#endif // !_LIBCXXABI_HAS_NO_THREADS
+#endif // !TEST_HAS_NO_THREADS
 }
diff --git a/test/test_fallback_malloc.pass.cpp b/test/test_fallback_malloc.pass.cpp
index cc59129..55713d2 100644
--- a/test/test_fallback_malloc.pass.cpp
+++ b/test/test_fallback_malloc.pass.cpp
@@ -11,6 +11,15 @@
 
 #include <__threading_support>
 
+// UNSUPPORTED: modules-build && libcpp-has-no-threads
+
+// Necessary because we include a private source file of libc++abi, which
+// only understands _LIBCXXABI_HAS_NO_THREADS.
+#include "test_macros.h"
+#ifdef TEST_HAS_NO_THREADS
+# define _LIBCXXABI_HAS_NO_THREADS
+#endif
+
 typedef std::deque<void *> container;
 
 // #define  DEBUG_FALLBACK_MALLOC
diff --git a/test/test_guard.pass.cpp b/test/test_guard.pass.cpp
index 01e5347..b02c71e 100644
--- a/test/test_guard.pass.cpp
+++ b/test/test_guard.pass.cpp
@@ -6,17 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "cxxabi.h"
-
 #include <cassert>
-
-#ifndef _LIBCXXABI_HAS_NO_THREADS
-#include <thread>
-#include "make_test_thread.h"
-#endif
+#include <cxxabi.h>
 
 #include "test_macros.h"
 
+#ifndef TEST_HAS_NO_THREADS
+#   include <thread>
+#   include "make_test_thread.h"
+#endif
+
 // Ensure that we initialize each variable once and only once.
 namespace test1 {
     static int run_count = 0;
@@ -83,7 +82,7 @@
     }
 }
 
-#ifndef _LIBCXXABI_HAS_NO_THREADS
+#ifndef TEST_HAS_NO_THREADS
 // A simple thread test of two threads racing to initialize a variable. This
 // isn't guaranteed to catch any particular threading problems.
 namespace test4 {
@@ -136,14 +135,14 @@
         assert(run_count == 1);
     }
 }
-#endif /* _LIBCXXABI_HAS_NO_THREADS */
+#endif /* TEST_HAS_NO_THREADS */
 
 int main(int, char**)
 {
     test1::test();
     test2::test();
     test3::test();
-#ifndef _LIBCXXABI_HAS_NO_THREADS
+#ifndef TEST_HAS_NO_THREADS
     test4::test();
     test5::test();
 #endif
diff --git a/test/thread_local_destruction_order.pass.cpp b/test/thread_local_destruction_order.pass.cpp
index c1e58f9..765cd7c 100644
--- a/test/thread_local_destruction_order.pass.cpp
+++ b/test/thread_local_destruction_order.pass.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03
-// UNSUPPORTED: libcxxabi-no-threads
+// UNSUPPORTED: libcpp-has-no-threads
 
 #include <cassert>
 #include <thread>