[libcxx-commits] [libcxx] 7c49052 - [libc++] Use init_priority(100) when possible
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 6 12:54:07 PDT 2021
Author: Louis Dionne
Date: 2021-10-06T15:53:56-04:00
New Revision: 7c49052b170f76f19be64a5572d31ad8f5df4e61
URL: https://github.com/llvm/llvm-project/commit/7c49052b170f76f19be64a5572d31ad8f5df4e61
DIFF: https://github.com/llvm/llvm-project/commit/7c49052b170f76f19be64a5572d31ad8f5df4e61.diff
LOG: [libc++] Use init_priority(100) when possible
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
Added:
Modified:
libcxx/include/__config
libcxx/src/experimental/memory_resource.cpp
libcxx/src/iostream.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 856b7b384593..31f98faaa721 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -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
diff --git a/libcxx/src/experimental/memory_resource.cpp b/libcxx/src/experimental/memory_resource.cpp
index ffe8021514fc..5f9d3b8a4cbe 100644
--- a/libcxx/src/experimental/memory_resource.cpp
+++ b/libcxx/src/experimental/memory_resource.cpp
@@ -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
diff --git a/libcxx/src/iostream.cpp b/libcxx/src/iostream.cpp
index 16e05cf0698c..99bd5288842a 100644
--- a/libcxx/src/iostream.cpp
+++ b/libcxx/src/iostream.cpp
@@ -73,7 +73,12 @@ __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream at _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
More information about the libcxx-commits
mailing list