1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CONFIGURATION_AVAILABILITY_H
11#define _LIBCPP___CONFIGURATION_AVAILABILITY_H
12
13#include <__configuration/compiler.h>
14#include <__configuration/language.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20// This file defines a framework that can be used by vendors to encode the version of an operating system that various
21// features of libc++ has been shipped in. This is primarily intended to allow safely deploying an executable built with
22// a new version of the library on a platform containing an older version of the built library.
23// Detailed documentation for this can be found at https://libcxx.llvm.org/VendorDocumentation.html#availability-markup
24
25// Availability markup is disabled when building the library, or when a non-Clang
26// compiler is used because only Clang supports the necessary attributes.
27//
28// We also allow users to force-disable availability markup via the `_LIBCPP_DISABLE_AVAILABILITY`
29// macro because that is the only way to work around a Clang bug related to availability
30// attributes: https://llvm.org/PR134151.
31// Once that bug has been fixed, we should remove the macro.
32#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || \
33 !defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_DISABLE_AVAILABILITY)
34# undef _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
35# define _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS 0
36#endif
37
38// When availability annotations are disabled, we take for granted that features introduced
39// in all versions of the library are available.
40#if !_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
41
42# define _LIBCPP_INTRODUCED_IN_LLVM_22 1
43# define _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE /* nothing */
44
45# define _LIBCPP_INTRODUCED_IN_LLVM_21 1
46# define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE /* nothing */
47
48# define _LIBCPP_INTRODUCED_IN_LLVM_20 1
49# define _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE /* nothing */
50
51# define _LIBCPP_INTRODUCED_IN_LLVM_19 1
52# define _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE /* nothing */
53
54# define _LIBCPP_INTRODUCED_IN_LLVM_18 1
55# define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE /* nothing */
56
57# define _LIBCPP_INTRODUCED_IN_LLVM_16 1
58# define _LIBCPP_INTRODUCED_IN_LLVM_16_ATTRIBUTE /* nothing */
59
60# define _LIBCPP_INTRODUCED_IN_LLVM_15 1
61# define _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE /* nothing */
62
63# define _LIBCPP_INTRODUCED_IN_LLVM_14 1
64# define _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE /* nothing */
65
66# define _LIBCPP_INTRODUCED_IN_LLVM_12 1
67# define _LIBCPP_INTRODUCED_IN_LLVM_12_ATTRIBUTE /* nothing */
68
69#elif defined(__APPLE__)
70
71// clang-format off
72
73// LLVM 22
74// TODO: Fill this in
75# define _LIBCPP_INTRODUCED_IN_LLVM_22 0
76# define _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE __attribute__((unavailable))
77
78// LLVM 21
79// TODO: Fill this in
80# define _LIBCPP_INTRODUCED_IN_LLVM_21 0
81# define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE __attribute__((unavailable))
82
83// LLVM 20
84//
85// Note that versions for most Apple OSes were bumped forward and aligned in that release.
86# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 260000) || \
87 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 260000) || \
88 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 260000) || \
89 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 260000) || \
90 (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 100000)
91# define _LIBCPP_INTRODUCED_IN_LLVM_20 0
92# else
93# define _LIBCPP_INTRODUCED_IN_LLVM_20 1
94# endif
95# define _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE \
96 __attribute__((availability(macos, strict, introduced = 26.0))) \
97 __attribute__((availability(ios, strict, introduced = 26.0))) \
98 __attribute__((availability(tvos, strict, introduced = 26.0))) \
99 __attribute__((availability(watchos, strict, introduced = 26.0))) \
100 __attribute__((availability(bridgeos, strict, introduced = 10.0)))
101
102// LLVM 19
103# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 150400) || \
104 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 180400) || \
105 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 180400) || \
106 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 110400) || \
107 (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 90400)
108# define _LIBCPP_INTRODUCED_IN_LLVM_19 0
109# else
110# define _LIBCPP_INTRODUCED_IN_LLVM_19 1
111# endif
112# define _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE \
113 __attribute__((availability(macos, strict, introduced = 15.4))) \
114 __attribute__((availability(ios, strict, introduced = 18.4))) \
115 __attribute__((availability(tvos, strict, introduced = 18.4))) \
116 __attribute__((availability(watchos, strict, introduced = 11.4))) \
117 __attribute__((availability(bridgeos, strict, introduced = 9.4)))
118
119// LLVM 18
120# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 150000) || \
121 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 180000) || \
122 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 180000) || \
123 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 110000) || \
124 (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 90000) || \
125 (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 240000)
126# define _LIBCPP_INTRODUCED_IN_LLVM_18 0
127# else
128# define _LIBCPP_INTRODUCED_IN_LLVM_18 1
129# endif
130# define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE \
131 __attribute__((availability(macos, strict, introduced = 15.0))) \
132 __attribute__((availability(ios, strict, introduced = 18.0))) \
133 __attribute__((availability(tvos, strict, introduced = 18.0))) \
134 __attribute__((availability(watchos, strict, introduced = 11.0))) \
135 __attribute__((availability(bridgeos, strict, introduced = 9.0))) \
136 __attribute__((availability(driverkit, strict, introduced = 24.0)))
137
138// LLVM 16
139# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140000) || \
140 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 170000) || \
141 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 170000) || \
142 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100000) || \
143 (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 80000) || \
144 (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 230000)
145# define _LIBCPP_INTRODUCED_IN_LLVM_16 0
146# else
147# define _LIBCPP_INTRODUCED_IN_LLVM_16 1
148# endif
149# define _LIBCPP_INTRODUCED_IN_LLVM_16_ATTRIBUTE \
150 __attribute__((availability(macos, strict, introduced = 14.0))) \
151 __attribute__((availability(ios, strict, introduced = 17.0))) \
152 __attribute__((availability(tvos, strict, introduced = 17.0))) \
153 __attribute__((availability(watchos, strict, introduced = 10.0))) \
154 __attribute__((availability(bridgeos, strict, introduced = 8.0))) \
155 __attribute__((availability(driverkit, strict, introduced = 23.0)))
156
157// LLVM 15
158# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130300) || \
159 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160300) || \
160 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160300) || \
161 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90300) || \
162 (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 70500) || \
163 (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 220400)
164# define _LIBCPP_INTRODUCED_IN_LLVM_15 0
165# else
166# define _LIBCPP_INTRODUCED_IN_LLVM_15 1
167# endif
168# define _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE \
169 __attribute__((availability(macos, strict, introduced = 13.3))) \
170 __attribute__((availability(ios, strict, introduced = 16.3))) \
171 __attribute__((availability(tvos, strict, introduced = 16.3))) \
172 __attribute__((availability(watchos, strict, introduced = 9.3))) \
173 __attribute__((availability(bridgeos, strict, introduced = 7.5))) \
174 __attribute__((availability(driverkit, strict, introduced = 22.4)))
175
176// LLVM 14
177# define _LIBCPP_INTRODUCED_IN_LLVM_14 _LIBCPP_INTRODUCED_IN_LLVM_15
178# define _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE
179
180// LLVM 12
181# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 120300) || \
182 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150300) || \
183 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150300) || \
184 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80300) || \
185 (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 60000) || \
186 (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 210300)
187# define _LIBCPP_INTRODUCED_IN_LLVM_12 0
188# else
189# define _LIBCPP_INTRODUCED_IN_LLVM_12 1
190# endif
191# define _LIBCPP_INTRODUCED_IN_LLVM_12_ATTRIBUTE \
192 __attribute__((availability(macos, strict, introduced = 12.3))) \
193 __attribute__((availability(ios, strict, introduced = 15.3))) \
194 __attribute__((availability(tvos, strict, introduced = 15.3))) \
195 __attribute__((availability(watchos, strict, introduced = 8.3))) \
196 __attribute__((availability(bridgeos, strict, introduced = 6.0))) \
197 __attribute__((availability(driverkit, strict, introduced = 21.3)))
198
199# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101300) || \
200 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150000) || \
201 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150000) || \
202 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 70000) || \
203 (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 190000)
204# warning "The selected platform is no longer supported by libc++."
205# endif
206
207#else
208
209// ...New vendors can add availability markup here...
210
211# error \
212 "It looks like you're trying to enable vendor availability markup, but you haven't defined the corresponding macros yet!"
213
214#endif
215
216// This controls the availability of new implementation of std::atomic's
217// wait, notify_one and notify_all. The new implementation uses
218// the native atomic wait/notify operations on platforms that support them
219// based on the size of the atomic type, instead of the type itself.
220#define _LIBCPP_AVAILABILITY_HAS_NEW_SYNC _LIBCPP_INTRODUCED_IN_LLVM_22
221#define _LIBCPP_AVAILABILITY_NEW_SYNC _LIBCPP_INTRODUCED_IN_LLVM_22_ATTRIBUTE
222
223// Enable additional explicit instantiations of iostreams components. This
224// reduces the number of weak definitions generated in programs that use
225// iostreams by providing a single strong definition in the shared library.
226//
227// TODO: Enable additional explicit instantiations on GCC once it supports exclude_from_explicit_instantiation,
228// or once libc++ doesn't use the attribute anymore.
229// TODO: Enable them on Windows once https://llvm.org/PR41018 has been fixed.
230#if !defined(_LIBCPP_COMPILER_GCC) && !defined(_WIN32)
231# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 _LIBCPP_INTRODUCED_IN_LLVM_12
232#else
233# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0
234#endif
235
236// This controls the availability of floating-point std::to_chars functions.
237// These overloads were added later than the integer overloads.
238#define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14
239#define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE
240
241// This controls whether the library claims to provide a default verbose
242// termination function, and consequently whether the headers will try
243// to use it when the mechanism isn't overriden at compile-time.
244#define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15
245#define _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE
246
247// This controls the availability of the C++17 std::pmr library,
248// which is implemented in large part in the built library.
249//
250// TODO: Enable std::pmr markup once https://llvm.org/PR40340 has been fixed
251// Until then, it is possible for folks to try to use `std::pmr` when back-deploying to targets that don't support
252// it and it'll be a load-time error, but we don't have a good alternative because the library won't compile if we
253// use availability annotations until that bug has been fixed.
254#define _LIBCPP_AVAILABILITY_HAS_PMR _LIBCPP_INTRODUCED_IN_LLVM_16
255#define _LIBCPP_AVAILABILITY_PMR
256
257// These macros controls the availability of __cxa_init_primary_exception
258// in the built library, which std::make_exception_ptr might use
259// (see libcxx/include/__exception/exception_ptr.h).
260#define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18
261#define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE
262
263// This controls the availability of C++23 <print>, which
264// has a dependency on the built library (it needs access to
265// the underlying buffer types of std::cout, std::cerr, and std::clog.
266#define _LIBCPP_AVAILABILITY_HAS_PRINT _LIBCPP_INTRODUCED_IN_LLVM_18
267#define _LIBCPP_AVAILABILITY_PRINT _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE
268
269// This controls the availability of the C++20 time zone database.
270// The parser code is built in the library.
271#define _LIBCPP_AVAILABILITY_HAS_TZDB _LIBCPP_INTRODUCED_IN_LLVM_19
272#define _LIBCPP_AVAILABILITY_TZDB _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE
273
274// These macros determine whether we assume that std::bad_function_call and
275// std::bad_expected_access provide a key function in the dylib. This allows
276// centralizing their vtable and typeinfo instead of having all TUs provide
277// a weak definition that then gets deduplicated.
278#define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19
279#define _LIBCPP_AVAILABILITY_BAD_FUNCTION_CALL_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE
280#define _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19
281#define _LIBCPP_AVAILABILITY_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE
282
283// This controls the availability of floating-point std::from_chars functions.
284// These overloads were added later than the integer overloads.
285#define _LIBCPP_AVAILABILITY_HAS_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20
286#define _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE
287
288// This controls whether `std::__hash_memory` is available in the dylib, which
289// is used for some `std::hash` specializations.
290#define _LIBCPP_AVAILABILITY_HAS_HASH_MEMORY _LIBCPP_INTRODUCED_IN_LLVM_21
291// No attribute, since we've had hash in the headers before
292
293// This controls whether we provide a message for `bad_function_call::what()` that specific to `std::bad_function_call`.
294// See https://wg21.link/LWG2233. This requires `std::bad_function_call::what()` to be available in the dylib.
295#define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE _LIBCPP_INTRODUCED_IN_LLVM_21
296// No attribute, since we've had bad_function_call::what() in the headers before
297
298// Only define a bunch of symbols in the dylib if we need to be compatible with LLVM 7 headers or older
299# if defined(_LIBCPP_BUILDING_LIBRARY) && _LIBCPP_AVAILABILITY_MINIMUM_HEADER_VERSION < 8
300# define _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8
301# else
302# define _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 _LIBCPP_HIDE_FROM_ABI
303# endif
304
305#endif // _LIBCPP___CONFIGURATION_AVAILABILITY_H
306