blob: ecbc33fd66f5c975bbd8eec2b848b109df265840 [file] [log] [blame]
Josh Gaobfb6bae2016-07-15 17:25:21 -07001/*
Elliott Hughesdfb74c52016-10-24 12:53:17 -07002 * Copyright (C) 2016 The Android Open Source Project
Josh Gaobfb6bae2016-07-15 17:25:21 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
Elliott Hughesdfb74c52016-10-24 12:53:17 -07008 * http://www.apache.org/licenses/LICENSE-2.0
Josh Gaobfb6bae2016-07-15 17:25:21 -07009 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Elliott Hughesc0f46562018-11-09 15:38:52 -080017#pragma once
Josh Gaobfb6bae2016-07-15 17:25:21 -070018
Logan Chiend7d9ebc2019-11-27 07:25:07 -080019// The `annotate` attribute always pulls the annotated (inline) function into the object files, thus
20// we should only annotate headers when we are running versioner.
21#if defined(__BIONIC_VERSIONER)
22
Elliott Hughesa1b5ca22024-04-22 20:10:53 +000023#define __INTRODUCED_IN(api_level) __attribute__((__annotate__("introduced_in=" #api_level)))
Dan Alberte25abd92024-05-15 17:55:55 +000024#define __DEPRECATED_IN(api_level, msg) __attribute__((__annotate__("deprecated_in=" #api_level)))
25#define __REMOVED_IN(api_level, msg) __attribute__((__annotate__("obsoleted_in=" #api_level)))
Elliott Hughesa1b5ca22024-04-22 20:10:53 +000026#define __INTRODUCED_IN_32(api_level) __attribute__((__annotate__("introduced_in_32=" #api_level)))
27#define __INTRODUCED_IN_64(api_level) __attribute__((__annotate__("introduced_in_64=" #api_level)))
Josh Gaobfb6bae2016-07-15 17:25:21 -070028
Elliott Hughesa1b5ca22024-04-22 20:10:53 +000029#define __VERSIONER_NO_GUARD __attribute__((__annotate__("versioner_no_guard")))
30#define __VERSIONER_FORTIFY_INLINE __attribute__((__annotate__("versioner_fortify_inline")))
Logan Chiend7d9ebc2019-11-27 07:25:07 -080031
32#else
33
Jiyong Park23bfed22020-08-10 13:35:05 +090034// When headers are not processed by the versioner (i.e. compiled into object files),
35// the availability attributed is emitted instead. The clang compiler will make the symbol weak
36// when targeting old api_level and enforce the reference to the symbol to be guarded with
37// __builtin_available(android api_level, *).
38
39// The 'strict' flag is required for NDK clients where the use of "-Wunguarded-availability" cannot
40// be enforced. In the case, the absence of 'strict' makes it possible to call an unavailable API
41// without the __builtin_available check, which will cause a link error at runtime.
42// Android platform build system defines this macro along with -Wunguarded-availability
Elliott Hughesa37b1812021-02-11 12:56:39 -080043#if defined(__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__)
Dan Albert398e1aa2024-05-01 22:06:54 +000044#define __BIONIC_AVAILABILITY(__what, ...) __attribute__((__availability__(android,__what __VA_OPT__(,) __VA_ARGS__)))
Jiyong Park23bfed22020-08-10 13:35:05 +090045#else
Dan Albert398e1aa2024-05-01 22:06:54 +000046#define __BIONIC_AVAILABILITY(__what, ...) __attribute__((__availability__(android,strict,__what __VA_OPT__(,) __VA_ARGS__)))
Jiyong Park23bfed22020-08-10 13:35:05 +090047#endif
48
Elliott Hughesa37b1812021-02-11 12:56:39 -080049#define __INTRODUCED_IN(api_level) __BIONIC_AVAILABILITY(introduced=api_level)
Dan Alberte25abd92024-05-15 17:55:55 +000050#define __DEPRECATED_IN(api_level, msg) __BIONIC_AVAILABILITY(deprecated=api_level, message=msg)
51#define __REMOVED_IN(api_level, msg) __BIONIC_AVAILABILITY(obsoleted=api_level, message=msg)
Jiyong Park23bfed22020-08-10 13:35:05 +090052
53// The same availability attribute can't be annotated multiple times. Therefore, the macros are
54// defined for the configuration that it is valid for so that declarations like the below doesn't
55// cause inconsistent availability values which is an error with -Wavailability:
56//
57// void foo() __INTRODUCED_IN_32(30) __INTRODUCED_IN_64(31);
58//
Jiyong Park23bfed22020-08-10 13:35:05 +090059#if !defined(__LP64__)
Elliott Hughesa37b1812021-02-11 12:56:39 -080060#define __INTRODUCED_IN_32(api_level) __BIONIC_AVAILABILITY(introduced=api_level)
Logan Chiend7d9ebc2019-11-27 07:25:07 -080061#define __INTRODUCED_IN_64(api_level)
Jiyong Park23bfed22020-08-10 13:35:05 +090062#else
63#define __INTRODUCED_IN_32(api_level)
Elliott Hughesa37b1812021-02-11 12:56:39 -080064#define __INTRODUCED_IN_64(api_level) __BIONIC_AVAILABILITY(introduced=api_level)
Jiyong Park23bfed22020-08-10 13:35:05 +090065#endif
66
Logan Chiend7d9ebc2019-11-27 07:25:07 -080067#define __VERSIONER_NO_GUARD
Logan Chien5a750f32019-11-20 10:29:14 -080068#define __VERSIONER_FORTIFY_INLINE
Logan Chiend7d9ebc2019-11-27 07:25:07 -080069
70#endif // defined(__BIONIC_VERSIONER)
Justin Yunced63022024-03-11 08:41:18 +090071
72// Vendor modules do not follow SDK versioning. Ignore NDK guards for vendor modules.
73#if defined(__ANDROID_VENDOR__)
74#undef __BIONIC_AVAILABILITY
Dan Albert398e1aa2024-05-01 22:06:54 +000075#define __BIONIC_AVAILABILITY(api_level, ...)
Justin Yunced63022024-03-11 08:41:18 +090076#endif // defined(__ANDROID_VENDOR__)