[libc++] Use init_priority(100) when possible
authorLouis Dionne <ldionne.2@gmail.com>
Wed, 3 Feb 2021 21:25:06 +0000 (16:25 -0500)
committerLouis Dionne <ldionne.2@gmail.com>
Wed, 6 Oct 2021 19:53:56 +0000 (15:53 -0400)
Priorities below 101 are reserved for the implementation, so that's what
we should be using here. That is unfortunately only supported on more
recent versions of Clang. See https://reviews.llvm.org/D31413 for details.

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

libcxx/include/__config
libcxx/src/experimental/memory_resource.cpp
libcxx/src/iostream.cpp

index 856b7b3..31f98fa 100644 (file)
@@ -1330,7 +1330,13 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
 #endif
 
 #if __has_attribute(init_priority)
-# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
+    // TODO: Remove this once we drop support for building libc++ with old Clangs
+#   if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \
+       (defined(__apple_build_version__) && __apple_build_version__ < 13000000)
+#     define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
+#   else
+#     define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100)))
+#   endif
 #else
 # define _LIBCPP_INIT_PRIORITY_MAX
 #endif
index ffe8021..5f9d3b8 100644 (file)
@@ -76,7 +76,9 @@ union ResourceInitHelper {
   ~ResourceInitHelper() {}
 };
 
+# 79 "memory_resource.cpp" 1 3
 _LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
+# 81 "memory_resource.cpp" 2
 
 } // end namespace
 
index 16e05cf..99bd528 100644 (file)
@@ -73,7 +73,12 @@ __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_t
 #endif
 ;
 
+// Hacky way to make the compiler believe that we're inside a system header so
+// it doesn't flag the use of the init_priority attribute with a value that's
+// reserved for the implementation (we're the implementation).
+# 80 "iostream.cpp" 1 3
 _LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX;
+# 82 "iostream.cpp" 2
 
 // On Windows the TLS storage for locales needs to be initialized before we create
 // the standard streams, otherwise it may not be alive during program termination