Chinaunix首页 | 论坛 | 博客
  • 博客访问: 700805
  • 博文数量: 112
  • 博客积分: 2486
  • 博客等级: 大尉
  • 技术积分: 1541
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-14 18:30
文章分类

全部博文(112)

文章存档

2012年(5)

2011年(48)

2010年(26)

2009年(33)

我的朋友

分类: LINUX

2011-08-30 17:09:39

  1. Android Native CPU ABI Management


  2. Introduction:
  3. =============

  4. Every piece of native code generated with the Android NDK matches a given
  5. "Application Binary Interface" (ABI) that defines exactly how your
  6. application's machine code is expected to interact with the system at
  7. runtime.

  8. A typical ABI describes things in *excruciating* details, and will typically
  9. include the following information:

  10. - the CPU instruction set that the machine code should use

  11. - the endianness of memory stores and loads at runtime

  12. - the format of executable binaries (shared libraries, programs, etc...)
  13. and what type of content is allowed/supported in them.

  14. - various conventions used to pass data between your code and
  15. the system (e.g. how registers and/or the stack are used when functions
  16. are called, alignment constraints, etc...)

  17. - alignment and size constraints for enum types, structure fields and
  18. arrays.

  19. - the list of function symbols available to your machine code at runtime,
  20. generally from a very specific selected set of libraries.

  21. This document lists the exact ABIs supported by the Android NDK and the
  22. official Android platform releases.


  23. I. Supported ABIs:
  24. ==================

  25. Each supported ABI is identified by a unique name.


  26. I.1. 'armeabi'
  27. --------------

  28. This is the name of an ABI for ARM-based CPUs that support *at* *least*
  29. the ARMv5TE instruction set. Please refer to following documentation for
  30. more details:

  31. - ARM Architecture Reference manual (a.k.a ARMARM)
  32. - Procedure Call Standard for the ARM Architecture (a.k.a. AAPCS)
  33. - ELF for the ARM Architecture (a.k.a. ARMELF)
  34. - ABI for the ARM Architecture (a.k.a. BSABI)
  35. - Base Platform ABI for the ARM Architecture (a.k.a. BPABI)
  36. - C Library ABI for the ARM Architecture (a.k.a. CLIABI)
  37. - C++ ABI for the ARM Architecture (a.k.a. CPPABI)
  38. - Runtime ABI for the ARM Architecture (a.k.a. RTABI)

  39. - ELF System V Application Binary Interface
  40. (DRAFT - 24 April 2001)

  41. - Generic C++ ABI ()

  42. Note that the AAPCS standard defines 'EABI' as a moniker used to specify
  43. a _family_ of similar but distinct ABIs. Android follows the little-endian
  44. ARM GNU/Linux ABI as documented in the following document:


  45. With the exception that wchar_t is only one byte. This should not matter
  46. in practice since wchar_t is simply *not* really supported by the Android
  47. platform anyway.

  48. This ABI does *not* support hardware-assisted floating point computations.
  49. Instead, all FP operations are performed through software helper functions
  50. that come from the compiler's libgcc.a static library.

  51. Thumb (a.k.a. Thumb-1) instructions are supported. Note that the NDK
  52. will generate thumb code by default, unless you define LOCAL_ARM_MODE
  53. in your Android.mk (see docs/ANDROID-MK.html for all details).


  54. I.2. 'armeabi-v7a'
  55. ------------------

  56. This is the name of another ARM-based CPU ABI that *extends* 'armeabi' to
  57. include a few CPU instruction set extensions as described in the following
  58. document:

  59. - ARM Architecture v7-a Reference Manual

  60. The instruction extensions supported by this Android-specific ABI are:

  61. - The Thumb-2 instruction set extension.
  62. - The VFP hardware FPU instructions.

  63. More specifically, VFPv3-D16 is being used, which corresponds to 16
  64. dedicated 64-bit floating point registers provided by the CPU.

  65. Other extensions described by the v7-a ARM like Advanced SIMD (a.k.a. NEON),
  66. VFPv3-D32 or ThumbEE are optional to this ABI, which means that developers
  67. should check *at* *runtime* whether the extensions are available and provide
  68. alternative code paths if this is not the case.

  69. (Just like one typically does on x86 systems to check/use MMX/SSE2/etc...
  70. specialized instructions).

  71. You can check docs/CPU-FEATURES.html to see how to perform these runtime
  72. checks, and docs/CPU-ARM-NEON.html to learn about the NDK's support for
  73. building NEON-capable machine code too.

  74. IMPORTANT NOTE: This ABI enforces that all double values are passed during
  75. function calls in 'core' register pairs, instead of dedicated FP ones.
  76. However, all internal computations can be performed with the FP registers
  77. and will be greatly sped up.

  78. This little constraint, while resulting in a slight decrease of
  79. performance, ensures binary compatibility with all existing 'armeabi'
  80. binaries.

  81. IMPORTANT NOTE: The 'armeabi-v7a' machine code will *not* run on ARMv5 or
  82. ARMv6 based devices.


  83. I.3. 'x86'
  84. ----------

  85. This is the name of an ABI for CPUs supporting the instruction set
  86. commonly named 'x86' or 'IA-32'. More specifically, this targets the
  87. instruction set commonly referenced as 'i686' or 'Pentium Pro' in
  88. documents such as:

  89. Intel IA-32 Intel Architecture Software Developer's Manual
  90. volume 2: Instruction Set Reference


  91. IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT:

  92. THE 'x86' ABI IS AN EXPERIMENTAL FEATURE THAT IS NOT FULLY
  93. SUPPORTED YET BY THIS NDK RELEASE. TRYING TO USE IT WILL RESULT
  94. IN AN ERROR DURING THE BUILD PROCESS.

  95. Note that optional features like MMX/SSE2/SSE3/3DNow!/KVM must be
  96. explicitly tested at runtime by the generated machine code and
  97. cannot be assumed to be everywhere.


  98. II. Generating code for a specific ABI:
  99. =======================================

  100. By default, the NDK will generate machine code for the 'armeabi' ABI.
  101. You can however add the following line to your Application.mk to generate
  102. ARMv7-a compatible machine code instead:

  103. APP_ABI := armeabi-v7a

  104. It is also possible to build machine code for *two* distinct ABIs by using:

  105. APP_ABI := armeabi armeabi-v7a

  106. This will instruct the NDK to build two versions of your machine code: one for
  107. each ABI listed on this line. Both libraries will be copied to your application
  108. project path and will be ultimately packaged into your .apk.

  109. Such a package is called a "fat binary" in Android speak since it contains
  110. machine code for more than one CPU architecture. At installation time, the
  111. package manager will only unpack the most appropriate machine code for the
  112. target device. See below for details.



  113. III. ABI Management on the Android platform:
  114. ============================================

  115. This section provides specific details about how the Android platform manages
  116. native code in application packages.


  117. III.1. Native code in Application Packages:
  118. -------------------------------------------

  119. It is expected that shared libraries generated with the NDK are stored in
  120. the final application package (.apk) at locations of the form:

  121. lib//lib.so

  122. Where is one of the ABI names listed in section II above, and
  123. is a name that can be used when loading the shared library from the VM
  124. as in:

  125. System.loadLibrary("");

  126. Since .apk files are just zip files, you can trivially list their content
  127. with a command like:

  128. unzip -l

  129. to verify that the native shared libraries you want are indeed at the
  130. proper location. You can also place native shared libraries at other
  131. locations within the .apk, but they will be ignored by the system, or more
  132. precisely by the steps described below; you will need to extract/install
  133. them manually in your application.

  134. In the case of a "fat" binary, two distinct libraries are thus placed in
  135. the .apk, for example at:

  136. lib/armeabi/libfoo.so
  137. lib/armeabi-v7a/libfoo.so


  138. III.2. Android Platform ABI support:
  139. ------------------------------------

  140. The Android system knows at runtime which ABI(s) it supports. More
  141. precisely, up to two build-specific system properties are used to
  142. indicate:

  143. - the 'primary' ABI for the device, corresponding to the machine
  144. code used in the system image itself.

  145. - an optional 'secondary' ABI, corresponding to another ABI that
  146. is also supported by the system image.

  147. For example, a typical ARMv5TE-based device would only define
  148. the primary ABI as 'armeabi' and not define a secondary one.

  149. On the other hand, a typical ARMv7-based device would define the
  150. primary ABI to 'armeabi-v7a' and the secondary one to 'armeabi'
  151. since it can run application native binaries generated for both
  152. of them.


  153. III.3. Automatic extraction of native code at install time:
  154. -----------------------------------------------------------

  155. When installing an application, the package manager service will scan
  156. the .apk and look for any shared library of the form:

  157. lib//lib.so

  158. If one is found, then it is copied under $APPDIR/lib/lib.so,
  159. where $APPDIR corresponds to the application's specific data directory.

  160. If none is found, and a secondary ABI is defined, the service will
  161. then scan for shared libraries of the form:

  162. lib//lib.so

  163. If anything is found, then it is copied under $APPDIR/lib/lib.so

  164. This mechanism ensures that the best machine code for the target
  165. device is automatically extracted from the package at installation
  166. time.
阅读(2972) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~