• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html><body><pre>Android Native CPU ABI Management
2
3
4Introduction:
5=============
6
7Every piece of native code generated with the Android NDK matches a given
8"Application Binary Interface" (ABI) that defines exactly how your
9application's machine code is expected to interact with the system at
10runtime.
11
12A typical ABI describes things in *excruciating* details, and will typically
13include the following information:
14
15  - the CPU instruction set that the machine code should use
16
17  - the endianness of memory stores and loads at runtime
18
19  - the format of executable binaries (shared libraries, programs, etc...)
20    and what type of content is allowed/supported in them.
21
22  - various conventions used to pass data between your code and
23    the system (e.g. how registers and/or the stack are used when functions
24    are called, alignment constraints, etc...)
25
26  - alignment and size constraints for enum types, structure fields and
27    arrays.
28
29  - the list of function symbols available to your machine code at runtime,
30    generally from a very specific selected set of libraries.
31
32This document lists the exact ABIs supported by the Android NDK and the
33official Android platform releases.
34
35
36I. Supported ABIs:
37==================
38
39Each supported ABI is identified by a unique name.
40
41
42 I.1. 'armeabi'
43 --------------
44
45  This is the name of an ABI for ARM-based CPUs that support *at* *least*
46  the ARMv5TE instruction set. Please refer to following documentation for
47  more details:
48
49   - ARM Architecture Reference manual                (a.k.a  ARMARM)
50   - Procedure Call Standard for the ARM Architecture (a.k.a. AAPCS)
51   - ELF for the ARM Architecture                     (a.k.a. ARMELF)
52   - ABI for the ARM Architecture                     (a.k.a. BSABI)
53   - Base Platform ABI for the ARM Architecture       (a.k.a. BPABI)
54   - C Library ABI for the ARM Architecture           (a.k.a. CLIABI)
55   - C++ ABI for the ARM Architecture                 (a.k.a. CPPABI)
56   - Runtime ABI for the ARM Architecture             (a.k.a. RTABI)
57
58   - ELF System V Application Binary Interface
59     (DRAFT - 24 April 2001)
60
61   - Generic C++ ABI  (http://www.codesourcery.com/public/cxx-abi/abi.html)
62
63  Note that the AAPCS standard defines 'EABI' as a moniker used to specify
64  a _family_ of similar but distinct ABIs. Android follows the little-endian
65  ARM GNU/Linux ABI as documented in the following document:
66
67      http://www.codesourcery.com/gnu_toolchains/arm/arm_gnu_linux_abi.pdf
68
69  With the exception that wchar_t is only one byte. This should not matter
70  in practice since wchar_t is simply *not* really supported by the Android
71  platform anyway.
72
73  This ABI does *not* support hardware-assisted floating point computations.
74  Instead, all FP operations are performed through software helper functions
75  that come from the compiler's libgcc.a static library.
76
77  Thumb (a.k.a. Thumb-1) instructions are supported. Note that the NDK
78  will generate thumb code by default, unless you define LOCAL_ARM_MODE
79  in your Android.mk (see docs/ANDROID-MK.html for all details).
80
81
82 I.2. 'armeabi-v7a'
83 ------------------
84
85  This is the name of another ARM-based CPU ABI that *extends* 'armeabi' to
86  include a few CPU instruction set extensions as described in the following
87  document:
88
89  - ARM Architecture v7-a Reference Manual
90
91  The instruction extensions supported by this Android-specific ABI are:
92
93     - The Thumb-2 instruction set extension.
94     - The VFP hardware FPU instructions.
95
96  More specifically, VFPv3-D16 is being used, which corresponds to 16
97  dedicated 64-bit floating point registers provided by the CPU.
98
99  Other extensions described by the v7-a ARM like Advanced SIMD (a.k.a. NEON),
100  VFPv3-D32 or ThumbEE are optional to this ABI, which means that developers
101  should check *at* *runtime* whether the extensions are available and provide
102  alternative code paths if this is not the case.
103
104  (Just like one typically does on x86 systems to check/use MMX/SSE2/etc...
105   specialized instructions).
106
107  You can check docs/CPU-FEATURES.html to see how to perform these runtime
108  checks, and docs/CPU-ARM-NEON.html to learn about the NDK's support for
109  building NEON-capable machine code too.
110
111  IMPORTANT NOTE: This ABI enforces that all double values are passed during
112  function calls in 'core' register pairs, instead of dedicated FP ones.
113  However, all internal computations can be performed with the FP registers
114  and will be greatly sped up.
115
116  This little constraint, while resulting in a slight decrease of
117  performance, ensures binary compatibility with all existing 'armeabi'
118  binaries.
119
120  IMPORTANT NOTE: The 'armeabi-v7a' machine code will *not* run on ARMv5 or
121                  ARMv6 based devices.
122
123
124 I.3. 'x86'
125 ----------
126
127  This is the name of an ABI for CPUs supporting the instruction set
128  commonly named 'x86' or 'IA-32'. More specifically, this ABI corresponds
129  to the following:
130
131  - instructions normally generated by GCC with the following compiler
132    flags:
133
134      -march=i686 -msse3 -mstackrealign -mfpmath=sse
135
136    which targets Pentium Pro instruction set, according to the GCC
137    documentation, plus the MMX, SSE, SSE2 and SSE3 instruction set
138    extensions.
139
140  - using the standard Linux x86 32-bit calling convention (e.g. section 6,
141    "Register Usage" of the "Calling conventions..." document below), not
142    the SVR4 one.
143
144  The ABI does *not* include any other optional IA-32 instruction set
145  extension, including, but not limited to:
146
147  - the MOVBE instruction
148  - the SSSE3 "supplemental SSE3" extension
149  - any variant of "SSE4"
150
151  You can still use these, as long as you use runtime feature probing to
152  enable them, and provide fallbacks for devices that do not support them.
153
154  Please refer to the following documents for more details:
155
156    http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html
157
158    Calling conventions for different C++ compilers and operating systems
159      http://www.agner.org/optimize/calling_conventions.pdf
160
161    Intel IA-32 Intel Architecture Software Developer's Manual
162      volume 2: Instruction Set Reference
163
164    Intel IA-32 Intel Architecture Software Developer's Manual
165      volume 3: System Programming
166
167    Amendment to System V Application Binary Interface
168      Intel386 Processor Architecture Supplement
169
170
171 I.4. 'mips'
172 -----------
173
174  This is the name of an ABI for MIPS-based CPUs that support *at* *least*
175  the MIPS32r1 instruction set. The ABI includes the following features:
176
177   - MIPS32 revision 1 ISA
178   - Little-Endian
179   - O32
180   - Hard-Float
181   - no DSP application specific extensions
182
183  Please refer to following documentation for more details:
184
185   - ELF for the MIPS Architecture                    (a.k.a. MIPSELF)
186   - FAQ for MIPS Toolchains                          (a.k.a. MIPSFAQ)
187   - Toolchain Specifics                              (a.k.a. MIPSTOOL)
188   - SDE Library                                      (a.k.a. MIPSSDE)
189   - Instruction Set Quick Reference                  (a.k.a. MIPSISA)
190   - Architecture for Programmers                     (a.k.a. MIPSARCH)
191
192   - ELF System V Application Binary Interface
193     (DRAFT - 24 April 2001)
194   - Generic C++ ABI  (http://sourcery.mentor.com/public/cxx-abi/abi.html)
195
196  The MIPS specific documentation is available at:
197  http://www.mips.com/products/product-materials/processor/mips-architecture/
198  https://sourcery.mentor.com/sgpp/lite/mips/portal/target_arch?@action=faq&target_arch=MIPS
199
200  Note: This ABI assumes a CPU:FPU clock ratio of 2:1 for maximum
201  compatability.
202
203  Note: that MIPS16 support is not provided, nor is micromips.
204
205
206II. Generating code for a specific ABI:
207=======================================
208
209By default, the NDK will generate machine code for the 'armeabi' ABI.
210You can however add the following line to your Application.mk to generate
211ARMv7-a compatible machine code instead:
212
213   APP_ABI := armeabi-v7a
214
215It is also possible to build machine code for *two* distinct ABIs by using:
216
217   APP_ABI := armeabi armeabi-v7a
218
219This will instruct the NDK to build two versions of your machine code: one for
220each ABI listed on this line. Both libraries will be copied to your application
221project path and will be ultimately packaged into your .apk.
222
223Such a package is called a "fat binary" in Android speak since it contains
224machine code for more than one CPU architecture. At installation time, the
225package manager will only unpack the most appropriate machine code for the
226target device. See below for details.
227
228
229
230III. ABI Management on the Android platform:
231============================================
232
233This section provides specific details about how the Android platform manages
234native code in application packages.
235
236
237  III.1. Native code in Application Packages:
238  -------------------------------------------
239
240    It is expected that shared libraries generated with the NDK are stored in
241    the final application package (.apk) at locations of the form:
242
243       lib/&lt;abi&gt;/lib&lt;name&gt;.so
244
245    Where &lt;abi&gt; is one of the ABI names listed in section II above, and &lt;name&gt;
246    is a name that can be used when loading the shared library from the VM
247    as in:
248
249        System.loadLibrary("&lt;name&gt;");
250
251    Since .apk files are just zip files, you can trivially list their content
252    with a command like:
253
254        unzip -l &lt;apk&gt;
255
256    to verify that the native shared libraries you want are indeed at the
257    proper location. You can also place native shared libraries at other
258    locations within the .apk, but they will be ignored by the system, or more
259    precisely by the steps described below; you will need to extract/install
260    them manually in your application.
261
262    In the case of a "fat" binary, up to four distinct libraries can be placed
263    in the  .apk, for example at:
264
265        lib/armeabi/libfoo.so
266        lib/armeabi-v7a/libfoo.so
267        lib/x86/libfoo.so
268        lib/mips/libfoo.so
269
270
271  III.2. Android Platform ABI support:
272  ------------------------------------
273
274    The Android system knows at runtime which ABI(s) it supports. More
275    precisely, up to two build-specific system properties are used to
276    indicate:
277
278    - the 'primary' ABI for the device, corresponding to the machine
279      code used in the system image itself.
280
281    - an optional 'secondary' ABI, corresponding to another ABI that
282      is also supported by the system image.
283
284    For example, a typical ARMv5TE-based device would only define
285    the primary ABI as 'armeabi' and not define a secondary one.
286
287    On the other hand, a typical ARMv7-based device would define the
288    primary ABI to 'armeabi-v7a' and the secondary one to 'armeabi'
289    since it can run application native binaries generated for both
290    of them.
291
292    A typical x86-based device only defines a primary abi named 'x86'.
293
294    A typical MIPS-based device only defines a primary abi named 'mips'.
295
296  III.3. Automatic extraction of native code at install time:
297  -----------------------------------------------------------
298
299    When installing an application, the package manager service will scan
300    the .apk and look for any shared library of the form:
301
302         lib/&lt;primary-abi&gt;/lib&lt;name&gt;.so
303
304    If one is found, then it is copied under $APPDIR/lib/lib&lt;name&gt;.so,
305    where $APPDIR corresponds to the application's specific data directory.
306
307    If none is found, and a secondary ABI is defined, the service will
308    then scan for shared libraries of the form:
309
310        lib/&lt;secondary-abi&gt;/lib&lt;name&gt;.so
311
312    If anything is found, then it is copied under $APPDIR/lib/lib&lt;name&gt;.so
313
314    This mechanism ensures that the best machine code for the target
315    device is automatically extracted from the package at installation
316    time.
317</pre></body></html>
318