[libcxx][modules] protects users from relying on detail headers

libc++ has started splicing standard library headers into much more
fine-grained content for maintainability. It's very likely that outdated
and naive tooling (some of which is outside of LLVM's scope) will
suggest users include things such as <__ranges/access.h> instead of
<ranges>, and Hyrum's law suggests that users will eventually begin to
rely on this without the help of tooling. As such, this commit
intends to protect users from themselves, by making it a hard error for
anyone outside of the standard library to include libc++ detail headers.

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

GitOrigin-RevId: 5aaefa510ef055e8f044ca89e352d4313f3aba49
diff --git a/include/threading_support.h b/include/threading_support.h
new file mode 100644
index 0000000..3e533f9
--- /dev/null
+++ b/include/threading_support.h
@@ -0,0 +1,14 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef _LIBCXXABI_THREADING_SUPPORT_H
+#define _LIBCXXABI_THREADING_SUPPORT_H
+
+#pragma GCC system_header
+#include <__threading_support>
+
+#endif // _LIBCXXABI_THREADING_SUPPORT_H
diff --git a/src/cxa_exception_storage.cpp b/src/cxa_exception_storage.cpp
index 3a3233a..ce44c3a 100644
--- a/src/cxa_exception_storage.cpp
+++ b/src/cxa_exception_storage.cpp
@@ -12,7 +12,7 @@
 
 #include "cxa_exception.h"
 
-#include <__threading_support>
+#include "threading_support.h"
 
 #if defined(_LIBCXXABI_HAS_NO_THREADS)
 
diff --git a/src/cxa_guard_impl.h b/src/cxa_guard_impl.h
index 72940cc..b3c3202 100644
--- a/src/cxa_guard_impl.h
+++ b/src/cxa_guard_impl.h
@@ -56,7 +56,7 @@
 
 #include <limits.h>
 #include <stdlib.h>
-#include <__threading_support>
+#include "threading_support.h"
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 #  if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB)
 #    pragma comment(lib, "pthread")
diff --git a/src/cxa_thread_atexit.cpp b/src/cxa_thread_atexit.cpp
index 665f9e5..1a04ddd 100644
--- a/src/cxa_thread_atexit.cpp
+++ b/src/cxa_thread_atexit.cpp
@@ -8,7 +8,7 @@
 
 #include "abort_message.h"
 #include "cxxabi.h"
-#include <__threading_support>
+#include "threading_support.h"
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 #if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB)
 #pragma comment(lib, "pthread")
diff --git a/src/fallback_malloc.cpp b/src/fallback_malloc.cpp
index 1d6c380..9db431e 100644
--- a/src/fallback_malloc.cpp
+++ b/src/fallback_malloc.cpp
@@ -8,7 +8,7 @@
 
 #include "fallback_malloc.h"
 
-#include <__threading_support>
+#include "threading_support.h"
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 #if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB)
 #pragma comment(lib, "pthread")
diff --git a/test/test_exception_storage.pass.cpp b/test/test_exception_storage.pass.cpp
index 934cc4b..4f1121b 100644
--- a/test/test_exception_storage.pass.cpp
+++ b/test/test_exception_storage.pass.cpp
@@ -9,7 +9,7 @@
 #include <algorithm>
 #include <cstdio>
 #include <cstdlib>
-#include <__threading_support>
+#include "threading_support.h"
 #include <unistd.h>
 
 #include "../src/cxa_exception.h"
diff --git a/test/test_fallback_malloc.pass.cpp b/test/test_fallback_malloc.pass.cpp
index cc59129..886b9a5 100644
--- a/test/test_fallback_malloc.pass.cpp
+++ b/test/test_fallback_malloc.pass.cpp
@@ -9,7 +9,7 @@
 #include <cstdio>
 #include <deque>
 
-#include <__threading_support>
+#include "threading_support.h"
 
 typedef std::deque<void *> container;