From: Louis Dionne Date: Wed, 3 Feb 2021 21:25:06 +0000 (-0500) Subject: [libc++] Use init_priority(100) when possible X-Git-Tag: upstream/15.0.7~29413 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7c49052b170f76f19be64a5572d31ad8f5df4e61;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/libcxx/include/__config b/libcxx/include/__config index 856b7b3..31f98fa 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 ffe8021..5f9d3b8 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 16e05cf..99bd528 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@_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