Skip to content

Commit 7c49052

Browse files
committed
[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
1 parent 19a3e24 commit 7c49052

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

libcxx/include/__config

+7-1
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,13 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
13301330
#endif
13311331

13321332
#if __has_attribute(init_priority)
1333-
# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1333+
// TODO: Remove this once we drop support for building libc++ with old Clangs
1334+
# if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \
1335+
(defined(__apple_build_version__) && __apple_build_version__ < 13000000)
1336+
# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1337+
# else
1338+
# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100)))
1339+
# endif
13341340
#else
13351341
# define _LIBCPP_INIT_PRIORITY_MAX
13361342
#endif

libcxx/src/experimental/memory_resource.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ union ResourceInitHelper {
7676
~ResourceInitHelper() {}
7777
};
7878

79+
# 79 "memory_resource.cpp" 1 3
7980
_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
81+
# 81 "memory_resource.cpp" 2
8082

8183
} // end namespace
8284

libcxx/src/iostream.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_t
7373
#endif
7474
;
7575

76+
// Hacky way to make the compiler believe that we're inside a system header so
77+
// it doesn't flag the use of the init_priority attribute with a value that's
78+
// reserved for the implementation (we're the implementation).
79+
# 80 "iostream.cpp" 1 3
7680
_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX;
81+
# 82 "iostream.cpp" 2
7782

7883
// On Windows the TLS storage for locales needs to be initialized before we create
7984
// the standard streams, otherwise it may not be alive during program termination

0 commit comments

Comments
 (0)