1# Native API Map Files 2 3Native APIs such as those exposed by the NDK, LL-NDK, or APEX are described by 4map.txt files. These files are [linker version scripts] with comments that are 5semantically meaningful to [gen_stub_libs.py]. For an example of a map file, see 6[libc.map.txt]. 7 8[gen_stub_libs.py]: https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/gen_stub_libs.py 9[libc.map.txt]: https://cs.android.com/android/platform/superproject/+/master:bionic/libc/libc.map.txt 10[linker version scripts]: https://www.gnu.org/software/gnulib/manual/html_node/LD-Version-Scripts.html 11 12## Basic format 13 14A linker version script defines at least one alphanumeric "version" definition, 15each of which contain a list of symbols. For example: 16 17```txt 18MY_API_R { # introduced=R 19 global: 20 api_foo; 21 api_bar; 22 local: 23 *; 24}; 25 26MY_API_S { # introduced=S 27 global: 28 api_baz; 29} MY_API_R; 30``` 31 32Comments on the same line as either a version definition or a symbol name have 33meaning. If you need to add any comments that should not be interpreted by the 34stub generator, keep them on their own line. For a list of supported comments, 35see the "Tags" section. 36 37Here, `api_foo` and `api_bar` are exposed in the generated stubs with the 38`MY_API_R` version and `api_baz` is exposed with the `MY_API_S` version. No 39other symbols are defined as public by this API. `MY_API_S` inherits all symbols 40defined by `MY_API_R`. 41 42When generating NDK API stubs from this version script, the stub library for R 43will define `api_foo` and `api_bar`. The stub library for S will define all 44three APIs. 45 46Note that, with few exceptions (see "Special version names" below), the name of 47the version has no inherent meaning. 48 49These map files can (and should) also be used as version scripts for building 50the implementation library rather than just defining the stub interface by using 51the `version_script` property of `cc_library`. This has the effect of limiting 52symbol visibility of the library to expose only the interface named by the map 53file. Without this, APIs that you have not explicitly exposed will still be 54available to users via `dlsym`. Note: All comments are ignored in this case. Any 55symbol named in any `global:` group will be visible in the implementation 56library. Annotations in comments only affect what is exposed by the stubs. 57 58## Special version names 59 60Version names that end with `_PRIVATE` or `_PLATFORM` will not be exposed in any 61stubs, but will be exposed in the implementation library. Using either of these 62naming schemes is equivalent to marking the version with the `platform-only` 63tag. See the docs for `platform-only` for more information. 64 65## Tags 66 67Comments on the same line as a version definition or a symbol name are 68interpreted by the stub generator. Multiple space-delimited tags may be used on 69the same line. The supported tags are: 70 71### apex 72 73Indicates that the version or symbol is to be exposed in the APEX stubs rather 74than the NDK. May be used in combination with `llndk` if the symbol is exposed 75to both APEX and the LL-NDK. 76 77### future 78 79Indicates that the version or symbol is first introduced in the "future" API 80level. This is an arbitrarily high API level used to define APIs that have not 81yet been added to a specific release. 82 83Warning: APIs marked `future` will be usable in any module with `sdk: "current"` 84but **will not be included in the NDK**. `future` should generally not be used, 85but is useful when developing APIs for an unknown future release. 86 87### introduced 88 89Indicates the version in which an API was first introduced. For example, 90`introduced=21` specifies that the API was first added (or first made public) in 91API level 21. This tag can be applied to either a version definition or an 92individual symbol. If applied to a version, all symbols contained in the version 93will have the tag applied. An `introduced` tag on a symbol overrides the value 94set for the version, if both are defined. 95 96Note: The map file alone does not contain all the information needed to 97determine which API level an API was added in. The `first_version` property of 98`ndk_library` will dictate which API levels stubs are generated for. If the 99module sets `first_version: "21"`, no symbols were introduced before API 21. 100**Symbol names for which no other rule applies will implicitly be introduced in 101`first_version`.** 102 103Code names can (and typically should) be used when defining new APIs. This 104allows the actual number of the API level to remain vague during development of 105that release. For example, `introduced=S` can be used to define APIs added in S. 106Any code name known to the build system can be used. For a list of versions 107known to the build system, see `out/soong/api_levels.json` (if not present, run 108`m out/soong/api_levels.json` to generate it). 109 110Architecture-specific variants of this tag exist: 111 112* `introduced-arm=VERSION` 113* `introduced-arm64=VERSION` 114* `introduced-x86=VERSION` 115* `introduced-x86_64=VERSION` 116 117The architecture-specific tag will take precedence over the architecture-generic 118tag when generating stubs for that architecture if both are present. If the 119symbol is defined with only architecture-specific tags, it will not be present 120for architectures that are not named. 121 122Note: The architecture-specific tags should, in general, not be used. These are 123primarily needed for APIs that were wrongly inconsistently exposed by libc/libm 124in old versions of Android before the stubs were well maintained. Think hard 125before using an architecture-specific tag for a new API. 126 127### llndk 128 129Indicates that the version or symbol is to be exposed in the LL-NDK stubs rather 130than the NDK. May be used in combination with `apex` if the symbol is exposed to 131both APEX and the LL-NDK. 132 133Historically this annotation was spelled `vndk`, but it has always meant LL-NDK. 134 135### platform-only 136 137Indicates that the version or symbol is public in the implementation library but 138should not be exposed in the stub library. Developers can still access them via 139`dlsym`, but they will not be exposed in the stubs so it should at least be 140clear to the developer that they are up to no good. 141 142The typical use for this tag is for exposing an API to the platform that is not 143for use by the NDK, LL-NDK, or APEX (similar to Java's `@SystemAPI`). It is 144preferable to keep such APIs in an entirely separate library to protect them 145from access via `dlsym`, but this is not always possible. 146 147### var 148 149Used to define a public global variable. By default all symbols are exposed as 150functions. In the uncommon situation of exposing a global variable, the `var` 151tag may be used. 152 153### versioned=VERSION 154 155Behaves similarly to `introduced` but defines the first version that the stub 156library should apply symbol versioning. For example: 157 158```txt 159R { # introduced=R 160 global: 161 foo; 162 bar; # versioned=S 163 local: 164 *; 165}; 166``` 167 168The stub library for R will contain symbols for both `foo` and `bar`, but only 169`foo` will include a versioned symbol `foo@R`. The stub library for S will 170contain both symbols, as well as the versioned symbols `foo@R` and `bar@R`. 171 172This tag is not commonly needed and is only used to hide symbol versioning 173mistakes that shipped as part of the platform. 174 175Note: Like `introduced`, the map file does not tell the whole story. The 176`ndk_library` Soong module may define a `unversioned_until` property that sets 177the default for the entire map file. 178 179### weak 180 181Indicates that the symbol should be [weak] in the stub library. 182 183[weak]: https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attributes.html 184