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___AVAILABILITY |
11 | #define _LIBCPP___AVAILABILITY |
12 | |
13 | #include <__config> |
14 | |
15 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
16 | # pragma GCC system_header |
17 | #endif |
18 | |
19 | // Libc++ is shipped by various vendors. In particular, it is used as a system |
20 | // library on macOS, iOS and other Apple platforms. In order for users to be |
21 | // able to compile a binary that is intended to be deployed to an older version |
22 | // of a platform, Clang provides availability attributes [1]. These attributes |
23 | // can be placed on declarations and are used to describe the life cycle of a |
24 | // symbol in the library. |
25 | // |
26 | // The main goal is to ensure a compile-time error if a symbol that hasn't been |
27 | // introduced in a previously released library is used in a program that targets |
28 | // that previously released library. Normally, this would be a load-time error |
29 | // when one tries to launch the program against the older library. |
30 | // |
31 | // For example, the filesystem library was introduced in the dylib in macOS 10.15. |
32 | // If a user compiles on a macOS 10.15 host but targets macOS 10.13 with their |
33 | // program, the compiler would normally not complain (because the required |
34 | // declarations are in the headers), but the dynamic loader would fail to find |
35 | // the symbols when actually trying to launch the program on macOS 10.13. To |
36 | // turn this into a compile-time issue instead, declarations are annotated with |
37 | // when they were introduced, and the compiler can produce a diagnostic if the |
38 | // program references something that isn't available on the deployment target. |
39 | // |
40 | // This mechanism is general in nature, and any vendor can add their markup to |
41 | // the library (see below). Whenever a new feature is added that requires support |
42 | // in the shared library, a macro should be added below to mark this feature |
43 | // as unavailable. When vendors decide to ship the feature as part of their |
44 | // shared library, they can update the markup appropriately. |
45 | // |
46 | // Furthermore, many features in the standard library have corresponding |
47 | // feature-test macros. When a feature is made unavailable on some deployment |
48 | // target, a macro should be defined to signal that it is unavailable. That |
49 | // macro can then be picked up when feature-test macros are generated (see |
50 | // generate_feature_test_macro_components.py) to make sure that feature-test |
51 | // macros don't announce a feature as being implemented if it has been marked |
52 | // as unavailable. |
53 | // |
54 | // Note that this mechanism is disabled by default in the "upstream" libc++. |
55 | // Availability annotations are only meaningful when shipping libc++ inside |
56 | // a platform (i.e. as a system library), and so vendors that want them should |
57 | // turn those annotations on at CMake configuration time. |
58 | // |
59 | // [1]: https://clang.llvm.org/docs/AttributeReference.html#availability |
60 | |
61 | |
62 | // For backwards compatibility, allow users to define _LIBCPP_DISABLE_AVAILABILITY |
63 | // for a while. |
64 | #if defined(_LIBCPP_DISABLE_AVAILABILITY) |
65 | # if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) |
66 | # define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS |
67 | # endif |
68 | #endif |
69 | |
70 | // Availability markup is disabled when building the library, or when the compiler |
71 | // doesn't support the proper attributes. |
72 | #if defined(_LIBCPP_BUILDING_LIBRARY) || \ |
73 | defined(_LIBCXXABI_BUILDING_LIBRARY) || \ |
74 | !__has_feature(attribute_availability_with_strict) || \ |
75 | !__has_feature(attribute_availability_in_templates) || \ |
76 | !__has_extension(pragma_clang_attribute_external_declaration) |
77 | # if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) |
78 | # define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS |
79 | # endif |
80 | #endif |
81 | |
82 | #if defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) |
83 | |
84 | // This controls the availability of std::shared_mutex and std::shared_timed_mutex, |
85 | // which were added to the dylib later. |
86 | # define _LIBCPP_AVAILABILITY_SHARED_MUTEX |
87 | // # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_mutex |
88 | // # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex |
89 | |
90 | // These macros control the availability of std::bad_optional_access and |
91 | // other exception types. These were put in the shared library to prevent |
92 | // code bloat from every user program defining the vtable for these exception |
93 | // types. |
94 | // |
95 | // Note that when exceptions are disabled, the methods that normally throw |
96 | // these exceptions can be used even on older deployment targets, but those |
97 | // methods will abort instead of throwing. |
98 | # define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS |
99 | # define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS |
100 | # define _LIBCPP_AVAILABILITY_BAD_ANY_CAST |
101 | |
102 | // This controls the availability of std::uncaught_exceptions(). |
103 | # define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS |
104 | |
105 | // This controls the availability of the sized version of ::operator delete, |
106 | // ::operator delete[], and their align_val_t variants, which were all added |
107 | // in C++17, and hence not present in early dylibs. |
108 | # define _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE |
109 | |
110 | // This controls the availability of the std::future_error exception. |
111 | // |
112 | // Note that when exceptions are disabled, the methods that normally throw |
113 | // std::future_error can be used even on older deployment targets, but those |
114 | // methods will abort instead of throwing. |
115 | # define _LIBCPP_AVAILABILITY_FUTURE_ERROR |
116 | |
117 | // This controls the availability of std::type_info's vtable. |
118 | // I can't imagine how using std::type_info can work at all if |
119 | // this isn't supported. |
120 | # define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE |
121 | |
122 | // This controls the availability of std::locale::category members |
123 | // (e.g. std::locale::collate), which are defined in the dylib. |
124 | # define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY |
125 | |
126 | // This controls the availability of atomic operations on std::shared_ptr |
127 | // (e.g. `std::atomic_store(std::shared_ptr)`), which require a shared |
128 | // lock table located in the dylib. |
129 | # define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
130 | |
131 | // These macros control the availability of all parts of <filesystem> that |
132 | // depend on something in the dylib. |
133 | # define _LIBCPP_AVAILABILITY_FILESYSTEM |
134 | # define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH |
135 | # define _LIBCPP_AVAILABILITY_FILESYSTEM_POP |
136 | // # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem |
137 | |
138 | // This controls the availability of floating-point std::to_chars functions. |
139 | // These overloads were added later than the integer overloads. |
140 | # define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT |
141 | |
142 | // This controls the availability of the C++20 synchronization library, |
143 | // which requires shared library support for various operations |
144 | // (see libcxx/src/atomic.cpp). This includes <barier>, <latch>, |
145 | // <semaphore>, and notification functions on std::atomic. |
146 | # define _LIBCPP_AVAILABILITY_SYNC |
147 | // # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait |
148 | // # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier |
149 | // # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_latch |
150 | // # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore |
151 | |
152 | // This controls the availability of the C++20 format library. |
153 | // The library is in development and not ABI stable yet. P2216 is |
154 | // retroactively accepted in C++20. This paper contains ABI breaking |
155 | // changes. |
156 | # define _LIBCPP_AVAILABILITY_FORMAT |
157 | // # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format |
158 | |
159 | // This controls whether the std::__libcpp_assertion_handler default |
160 | // assertion handler is provided by the library. |
161 | // |
162 | // Note that when users provide their own custom assertion handler, |
163 | // it doesn't matter whether the dylib provides a default handler, |
164 | // and the availability markup can actually give a false positive |
165 | // diagnostic (it will think that no handler is provided, when in |
166 | // reality the user has provided their own). |
167 | // |
168 | // Users can pass -D_LIBCPP_AVAILABILITY_CUSTOM_ASSERTION_HANDLER_PROVIDED |
169 | // to the compiler to tell the library to ignore the fact that the |
170 | // default handler isn't available on their deployment target. Note that |
171 | // defining this macro but failing to define a custom assertion handler |
172 | // will lead to a load-time error on back-deployment targets, so it |
173 | // should be avoided. |
174 | # define _LIBCPP_AVAILABILITY_DEFAULT_ASSERTION_HANDLER |
175 | |
176 | #elif defined(__APPLE__) |
177 | |
178 | # define _LIBCPP_AVAILABILITY_SHARED_MUTEX \ |
179 | __attribute__((availability(macos,strict,introduced=10.12))) \ |
180 | __attribute__((availability(ios,strict,introduced=10.0))) \ |
181 | __attribute__((availability(tvos,strict,introduced=10.0))) \ |
182 | __attribute__((availability(watchos,strict,introduced=3.0))) |
183 | # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200) || \ |
184 | (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 100000) || \ |
185 | (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 100000) || \ |
186 | (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 30000) |
187 | # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_mutex |
188 | # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex |
189 | # endif |
190 | |
191 | // Note: bad_optional_access & friends were not introduced in the matching |
192 | // macOS and iOS versions, so the version mismatch between macOS and others |
193 | // is intended. |
194 | # define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS \ |
195 | __attribute__((availability(macos,strict,introduced=10.13))) \ |
196 | __attribute__((availability(ios,strict,introduced=12.0))) \ |
197 | __attribute__((availability(tvos,strict,introduced=12.0))) \ |
198 | __attribute__((availability(watchos,strict,introduced=5.0))) |
199 | # define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS \ |
200 | _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS |
201 | # define _LIBCPP_AVAILABILITY_BAD_ANY_CAST \ |
202 | _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS |
203 | |
204 | # define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS \ |
205 | __attribute__((availability(macos,strict,introduced=10.12))) \ |
206 | __attribute__((availability(ios,strict,introduced=10.0))) \ |
207 | __attribute__((availability(tvos,strict,introduced=10.0))) \ |
208 | __attribute__((availability(watchos,strict,introduced=3.0))) |
209 | |
210 | # define _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE \ |
211 | __attribute__((availability(macos,strict,introduced=10.12))) \ |
212 | __attribute__((availability(ios,strict,introduced=10.0))) \ |
213 | __attribute__((availability(tvos,strict,introduced=10.0))) \ |
214 | __attribute__((availability(watchos,strict,introduced=3.0))) |
215 | |
216 | # define _LIBCPP_AVAILABILITY_FUTURE_ERROR \ |
217 | __attribute__((availability(ios,strict,introduced=6.0))) |
218 | |
219 | # define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE \ |
220 | __attribute__((availability(macos,strict,introduced=10.9))) \ |
221 | __attribute__((availability(ios,strict,introduced=7.0))) |
222 | |
223 | # define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY \ |
224 | __attribute__((availability(macos,strict,introduced=10.9))) \ |
225 | __attribute__((availability(ios,strict,introduced=7.0))) |
226 | |
227 | # define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR \ |
228 | __attribute__((availability(macos,strict,introduced=10.9))) \ |
229 | __attribute__((availability(ios,strict,introduced=7.0))) |
230 | |
231 | # define _LIBCPP_AVAILABILITY_FILESYSTEM \ |
232 | __attribute__((availability(macos,strict,introduced=10.15))) \ |
233 | __attribute__((availability(ios,strict,introduced=13.0))) \ |
234 | __attribute__((availability(tvos,strict,introduced=13.0))) \ |
235 | __attribute__((availability(watchos,strict,introduced=6.0))) |
236 | # define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH \ |
237 | _Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \ |
238 | _Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \ |
239 | _Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \ |
240 | _Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))") |
241 | # define _LIBCPP_AVAILABILITY_FILESYSTEM_POP \ |
242 | _Pragma("clang attribute pop") \ |
243 | _Pragma("clang attribute pop") \ |
244 | _Pragma("clang attribute pop") \ |
245 | _Pragma("clang attribute pop") |
246 | # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \ |
247 | (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \ |
248 | (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000) || \ |
249 | (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000) |
250 | # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem |
251 | # endif |
252 | |
253 | # define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT \ |
254 | __attribute__((unavailable)) |
255 | |
256 | # define _LIBCPP_AVAILABILITY_SYNC \ |
257 | __attribute__((availability(macos,strict,introduced=11.0))) \ |
258 | __attribute__((availability(ios,strict,introduced=14.0))) \ |
259 | __attribute__((availability(tvos,strict,introduced=14.0))) \ |
260 | __attribute__((availability(watchos,strict,introduced=7.0))) |
261 | # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \ |
262 | (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000) || \ |
263 | (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 140000) || \ |
264 | (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 70000) |
265 | # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait |
266 | # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier |
267 | # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_latch |
268 | # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore |
269 | # endif |
270 | |
271 | # define _LIBCPP_AVAILABILITY_FORMAT \ |
272 | __attribute__((unavailable)) |
273 | # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format |
274 | |
275 | # define _LIBCPP_AVAILABILITY_DEFAULT_ASSERTION_HANDLER \ |
276 | __attribute__((unavailable)) |
277 | #else |
278 | |
279 | // ...New vendors can add availability markup here... |
280 | |
281 | # error "It looks like you're trying to enable vendor availability markup, but you haven't defined the corresponding macros yet!" |
282 | |
283 | #endif |
284 | |
285 | // Define availability attributes that depend on _LIBCPP_NO_EXCEPTIONS. |
286 | // Those are defined in terms of the availability attributes above, and |
287 | // should not be vendor-specific. |
288 | #if defined(_LIBCPP_NO_EXCEPTIONS) |
289 | # define _LIBCPP_AVAILABILITY_FUTURE |
290 | # define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST |
291 | # define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS |
292 | # define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS |
293 | #else |
294 | # define _LIBCPP_AVAILABILITY_FUTURE _LIBCPP_AVAILABILITY_FUTURE_ERROR |
295 | # define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _LIBCPP_AVAILABILITY_BAD_ANY_CAST |
296 | # define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS |
297 | # define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS |
298 | #endif |
299 | |
300 | // Define the special assertion handler availability attribute, which can be silenced by |
301 | // users if they provide their own custom assertion handler. The rest of the code should |
302 | // not use the *_DEFAULT_* macro directly, since that would make it ignore the fact that |
303 | // the user provided a custom handler. |
304 | #if defined(_LIBCPP_AVAILABILITY_CUSTOM_ASSERTION_HANDLER_PROVIDED) |
305 | # define _LIBCPP_AVAILABILITY_ASSERTION_HANDLER /* nothing */ |
306 | #else |
307 | # define _LIBCPP_AVAILABILITY_ASSERTION_HANDLER _LIBCPP_AVAILABILITY_DEFAULT_ASSERTION_HANDLER |
308 | #endif |
309 | |
310 | #endif // _LIBCPP___AVAILABILITY |
311 | |