• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 by an APEX rather than the
74NDK. For APIs exposed by the platform *for* APEX, use `systemapi`.
75
76May be used in combination with `llndk` if the symbol is exposed to both APEX
77and the LL-NDK.
78
79### future
80
81Indicates that the version or symbol is first introduced in the "future" API
82level. This is an arbitrarily high API level used to define APIs that have not
83yet been added to a specific release.
84
85Warning: APIs marked `future` will be usable in any module with `sdk: "current"`
86but **will not be included in the NDK**. `future` should generally not be used,
87but is useful when developing APIs for an unknown future release.
88
89### introduced
90
91Indicates the version in which an API was first introduced. For example,
92`introduced=21` specifies that the API was first added (or first made public) in
93API level 21. This tag can be applied to either a version definition or an
94individual symbol. If applied to a version, all symbols contained in the version
95will have the tag applied. An `introduced` tag on a symbol overrides the value
96set for the version, if both are defined.
97
98Note: The map file alone does not contain all the information needed to
99determine which API level an API was added in. The `first_version` property of
100`ndk_library` will dictate which API levels stubs are generated for. If the
101module sets `first_version: "21"`, no symbols were introduced before API 21.
102**Symbol names for which no other rule applies will implicitly be introduced in
103`first_version`.**
104
105Code names can (and typically should) be used when defining new APIs. This
106allows the actual number of the API level to remain vague during development of
107that release. For example, `introduced=S` can be used to define APIs added in S.
108Any code name known to the build system can be used. For a list of versions
109known to the build system, see `out/soong/api_levels.json` (if not present, run
110`m out/soong/api_levels.json` to generate it).
111
112Architecture-specific variants of this tag exist:
113
114* `introduced-arm=VERSION`
115* `introduced-arm64=VERSION`
116* `introduced-x86=VERSION`
117* `introduced-x86_64=VERSION`
118
119The architecture-specific tag will take precedence over the architecture-generic
120tag when generating stubs for that architecture if both are present. If the
121symbol is defined with only architecture-specific tags, it will not be present
122for architectures that are not named.
123
124Note: The architecture-specific tags should, in general, not be used. These are
125primarily needed for APIs that were wrongly inconsistently exposed by libc/libm
126in old versions of Android before the stubs were well maintained. Think hard
127before using an architecture-specific tag for a new API.
128
129### llndk
130
131Indicates that the version or symbol is to be exposed in the LL-NDK stubs rather
132than the NDK. May be used in combination with `apex` if the symbol is exposed to
133both APEX and the LL-NDK.
134
135Historically this annotation was spelled `vndk`, but it has always meant LL-NDK.
136
137### platform-only
138
139Indicates that the version or symbol is public in the implementation library but
140should not be exposed in the stub library. Developers can still access them via
141`dlsym`, but they will not be exposed in the stubs so it should at least be
142clear to the developer that they are up to no good.
143
144The typical use for this tag is for exposing an API to the platform that is not
145for use by the NDK, LL-NDK, or APEX (similar to Java's `@SystemAPI`). It is
146preferable to keep such APIs in an entirely separate library to protect them
147from access via `dlsym`, but this is not always possible.
148
149### systemapi
150
151This is a synonym of the `apex` tag. It should be used to clarify that the API
152is an API exposed by the system for an APEX, whereas `apex` should be used for
153APIs exposed by an APEX to the platform or another APEX.
154
155### var
156
157Used to define a public global variable. By default all symbols are exposed as
158functions. In the uncommon situation of exposing a global variable, the `var`
159tag may be used.
160
161### versioned=VERSION
162
163Behaves similarly to `introduced` but defines the first version that the stub
164library should apply symbol versioning. For example:
165
166```txt
167R { # introduced=R
168  global:
169    foo;
170    bar; # versioned=S
171  local:
172    *;
173};
174```
175
176The stub library for R will contain symbols for both `foo` and `bar`, but only
177`foo` will include a versioned symbol `foo@R`. The stub library for S will
178contain both symbols, as well as the versioned symbols `foo@R` and `bar@R`.
179
180This tag is not commonly needed and is only used to hide symbol versioning
181mistakes that shipped as part of the platform.
182
183Note: Like `introduced`, the map file does not tell the whole story. The
184`ndk_library` Soong module may define a `unversioned_until` property that sets
185the default for the entire map file.
186
187### weak
188
189Indicates that the symbol should be [weak] in the stub library.
190
191[weak]: https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attributes.html
192