`

【翻译】(7)CPU Arch ABIs

 
阅读更多

-----------------

英文文档见android-ndk-r5b的documentation.html

属于Android Native Development Kit (NDK)的一部分

见http://developer.android.com/sdk/ndk/(需要代理)

翻译仅个人见解

-----------------

 

Android Native CPU ABI Management

 

Android原生CPU ABI 管理

 

Introduction:

 

介绍:

=============

 

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

 

每个用Android NDK生成的原生代码匹配一个给定的“应用程序二进制接口”(ABI),ABI精确地定义了你的应用程序及其代码期待如何在运行时如何和系统交互。

 

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

 

一个典型的ABI用艰涩的细节描述事情,通常包含以下信息:

 

  - the CPU instruction set that the machine code should use

 

  - 机器代码应该使用的CPU指令集

 

  - the endianness of memory stores and loads at runtime

 

  - 运行时的内存存取的排列次序(注:通常分为大端和小端)

 

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

 

  - 可执行二进制文件(动态库,程序,等等)的格式以及它们里面允许和支持的是什么类型的内容。

 

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

 

  - 在你的代码和系统之间传递数据时使用的不同约定(例如,在函数调用时寄存器和/或堆栈如何使用,对齐限制,等等)

 

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

 

  - 枚举类型的对齐和大小限制,结构体字段和数组。

 

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

 

  - 在运行时对你的机器代码可用的函数符号列表,通常来源于一个非常特定的库集合。

 

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

 

这个文档列出Android NDK和官方Android平台发布版支持的精确ABI。

 

I. Supported ABIs:

 

一、支持的ABI:

==================

 

Each supported ABI is identified by a unique name.

 

每个支持的ABI通过一个唯一的名称标识。

 

 I.1. 'armeabi'

 

 一.1. 'armeabi'

 --------------

 

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

 

  这是针对基于ARM CPU的ABI名称,它至少支持ARMv5TE指令集。详细请参考以下文档:

 

   - ARM Architecture Reference manual                (a.k.a  ARMARM)

 

   - ARM架构参考手册(即ARMARM)

 

   - Procedure Call Standard for the ARM Architecture (a.k.a. AAPCS)

 

   - ARM架构的过程调用标准(即AAPCS)

 

   - ELF for the ARM Architecture                     (a.k.a. ARMELF)

 

   - ARM架构的ELF格式(即ARMELF)

 

   - ABI for the ARM Architecture                     (a.k.a. BSABI)

 

   - ARM架构的ABI(即BSABI)

 

   - Base Platform ABI for the ARM Architecture       (a.k.a. BPABI)

 

   - ARM架构的基础平台ABI(即BPABI)

 

   - C Library ABI for the ARM Architecture           (a.k.a. CLIABI)

 

   - ARM架构的C库ABI(即CLIABI)

 

   - C++ ABI for the ARM Architecture                 (a.k.a. CPPABI)

 

   - ARM架构的C++ ABI(即CPPABI)

 

   - Runtime ABI for the ARM Architecture             (a.k.a. RTABI)

 

   - ARM架构的运行时ABI(即RTABI)

 

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

 

   - ELF系统V应用程序二进制接口(DRAFT - 2001年4月24日)

 

   - Generic C++ ABI  (http://www.codesourcery.com/public/cxx-abi/abi.html)

 

   - 泛型C++ ABI(http://www.codesourcery.com/public/cxx-abi/abi.html)

 

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

 

  注意AAPCS标准定义EABI作为一个绰号,用于指定一类相似但不同的ABI。Android允许在以下文档中介绍的小端ARM GNU/Linux ABI:

 

      http://www.codesourcery.com/gnu_toolchains/arm/arm_gnu_linux_abi.pdf

 

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

 

  例外的是wchar_t只有一个字节。实际上没有关系,因为事实上wchar_t直接就不被Android平台支持。

 

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

 

  这种ABI不支持硬件辅助的浮点计算。反之,所有浮点操作由编译器的libgcc.a静态库的软件辅助函数执行。

 

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

 

  支持Thumb(即Thumb-1)指令。注意NDK默认将生成thumb,除非你在你的Android.mk中定义LOCAL_ARM_MODE(所有细节请参考docs/ANDROID-MK.html)

 

 I.2. 'armeabi-v7a'

 

 一.2. armeabi-v7a

 ------------------

 

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

 

  这是另一种基于ARM的CPU ABI,它扩展了armeabi以包含少量在下面的文档中描述的CPU指令集扩展。

 

  - ARM Architecture v7-a Reference Manual

 

  - ARM架构V7-a参考手册

 

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

 

  被这个Android特定的ABI支持的指令扩展有:

 

     - The Thumb-2 instruction set extension.

 

     - Thumb-2指令集扩展。

 

     - The VFP hardware FPU instructions.

 

     - 向量浮点硬件的浮点处理单元指令。

 

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

 

  更特别地,VFPv3-D16使用这种ABI,对应CPU提供的16个专用64位浮点寄存器。

 

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

 

  其它扩展由v7-a ARM描述,像高级SIMD(即NEON),VFPv3-D32或ThumbEE对于这种ABI是可选的,意味着开发者应该在运行期检查扩展是否可用,并且在它们不可用的时候提供可替换的代码路径。

 

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

 

  (就像有些人通常在x86系统上为了检查和使用MMX/SSE2/等等的特殊化指令而做的事情那样)。

 

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

 

  你可以检查docs/CPU-FEATURES.html以查看如何执行这些运行期检查,还可以查看docs/CPU-ARM-NEON.html以知道关于NDK对构建NEON能力机器代码的支持。

 

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

 

  重要注意:这种ABI强制在函数调用中所有double值在“核心”寄存器对中传递。而不是专用的浮点寄存器,所有内部计算可以用浮点寄存器执行而将大大地加快速度。

 

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

 

  这个小限制,当导致轻微的性能下降时,确保对所有现存armeabi二进制文件的二进制兼容性。

 

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

 

  重要注意:armeabi-v7a机器代码将不能运行于基于ARMv5和ARMv6的设备上。

 

 I.3. 'x86'

 

 一.3. x86

 ----------

 

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

 

  这是针对支持一般称为x86或IA-32的指令集的CPU的ABI名称。更特别地,它的目标是在以下文档中通常称为i686或Pentium Pro的指令集:

 

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

 

Intel IA-32 Intel架构软件开发者手册卷2:指令集参考

 

  IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT:

 

  重要:

 

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

 

      x86 ABI是一个实验性质的特性,在这个NDK发布版中尚未完全支持。尝试使用它将导致构建过程错误。

 

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

 

  注意可选特性像MMX/SSE2/SSE3/3DNow!/KVM必须在运行期被生成的机器代码显式地测试,不能假设它在任何地方都存在。

 

II. Generating code for a specific ABI:

 

二、生成特定ABI的代码:

=======================================

 

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

 

默认,NDK将生成armeabi ABI的机器代码。然而你可以改为添加以下行到你的Application.mk以生成ARMv7-a兼容的机器代码。

 

   APP_ABI := armeabi-v7a

 

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

 

还可以通过使用以下方法构建两种不同ABI的机器代码:

 

   APP_ABI := armeabi armeabi-v7a

 

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

 

这将命令NDK构建你的两种版本的机器代码:对应这行中列出的每种ABI。两个库将被复制到你的应用程序工程路径并且最终被打包进你的.apk

 

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

 

这种包用Android的话来说就是“肥胖的二进制库”,因为它包含多于一种CPU架构的机器代码。在安装期,包管理器将只抽取对目标设别最合适的机器代码。详细见下。

 

III. ABI Management on the Android platform:

 

三、Android平台的ABI管理

============================================

 

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

 

这个章节提供关于Android平台管理应用程序包中原生代码的特定细节。

 

  III.1. Native code in Application Packages:

 

  三.1. 应用程序包内的原生代码

  -------------------------------------------

 

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

 

    期望NDK所生成的动态库以这种格式的位置保存在最终的应用程序包(.apk)中:

 

       lib/<abi>/lib<name>.so

 

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

 

这里<abi>是上面第二节列举的ABI名称之一,而<name>是在虚拟机加载动态库时使用的名称,就像这样:

 

        System.loadLibrary("<name>");

 

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

 

因为.apk文件只是zip文件,你可以用这样的命令简单地列出它们的内容:

 

        unzip -l <apk>

 

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

 

以验证你想要的原生动态库确实是在合适的位置。你还可以在.apk中把原生动态库放在其它位置,但它们将被系统忽略,或者更准确地按照下面的描述的步骤做;你将需要在你的应用程序中手工地抽取或安装它们。

 

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

 

对于“肥胖”的二进制库文件,在.apk中放置两种不同的库,例如:

        lib/armeabi/libfoo.so

        lib/armeabi-v7a/libfoo.so

 

  III.2. Android Platform ABI support:

 

  三.2. Android平台ABI支持:

  ------------------------------------

 

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

 

Android系统在运行期知道它支持哪个或哪些ABI。更准确说,使用多达两个的构建特定的系统属性来指出:

 

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

 

- 设备的第一ABI,对应于系统镜像自身使用的机器代码。

 

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

 

- 一个可选的第二ABI,对应系统镜像支持的另一个ABI。

 

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

 

    例如,一个典型的基于ARMv5TE的设备将只把第一ABI定义为armeabi,而不会定义第二ABI。

 

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

 

另一方面,一个典型的基于ARMv7的设备将把第一ABI定义为armeabi-v7a,而把第二ABI定义为armeabi,因为它都可以运行由它们生成的应用程序原生二进制文件。

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

 

  三.3. 安装期本地代码的自动抽取

  -----------------------------------------------------------

 

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

 

    当安装一个应用程序,包管理器服务将扫描.apk并且寻找这种格式的动态库:

 

         lib/<primary-abi>/lib<name>.so

 

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

 

    如果找到一个,那么它被复制到$APPDIR/lib/lib<name>.so,这里$APPDIR对应于应用程序的特定数据目录。

 

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

 

如果什么都没找到,而定义了一个第二ABI,那么服务将继续以这种格式寻找动态库:

 

        lib/<secondary-abi>/lib<name>.so

 

    If anything is found, then it is copied under $APPDIR/lib/lib<name>.so

 

    如果找到文件,那么它被复制到$APPDIR/lib/lib<name>.so。

 

    This mechanism ensures that the best machine code for the target device is automatically extracted from the package at installation time.

 

    这种机制确保对于目标设备最佳的机器代码在安装期被自动从包中抽取出来。

 

 

分享到:
评论

相关推荐

    Arch Wiki离线版

    《Arch Wiki离线版》是针对Arch Linux操作系统爱好者和管理员的一款实用工具,它包含了Arch Wiki网站的完整内容,用户可以在没有网络连接的情况下查阅各种Arch Linux相关的技术文档和指南。Arch Wiki是一个极其丰富...

    Archlinux/Manjaro安装blackarch全套

    1、添加blackarch软件源 sudo gedit /etc/pacman.conf 如果没有gedit命令,运行 sudo pacman -S gedit 也可以用vim 添加以下内容: [blackarch] SigLevel = TrustAll Server = https://mirrors.tuna.tsinghua.e

    rt.arch函数

    股票波动率预测ar-arch模型.#拟合均值方程和方差方程 #拟合AR(4)-GARCH(3,0)模型[AR(4)- ARCH(3)模型]

    python arch 手册

    标题“Python Arch 手册”指的是一个专注于Python编程语言的文档,这个手册重点介绍了“arch”库,而“arch”是一个专门用于金融数据分析的Python库,尤其在时间序列数据的波动性建模方面非常有用。波动性建模是金融...

    变系数ARCH-M模型的ARCH效应检验

    变系数ARCH-M模型是时间序列分析领域的重要研究对象,其核心在于通过截面似然估计来检验模型是否具有条件异方差性(ARCH效应)。首先,我们来探讨一下条件异方差性的概念,它是指在时间序列分析中,随机变量的条件...

    arch4开发指南

    arch4 ins

    数学建模EViews中估计ARCH模型PPT课件.pptx

    "数学建模EViews中估计ARCH模型PPT课件.pptx" 本资源是关于数学建模EViews中估计ARCH模型的PPT课件,主要介绍了ARCH模型的定义、特点和应用,以及GARCH模型的推广和应用。 一、自回归条件异方差模型 ARCH模型是...

    .arch3 STEP 7编程软件使用方法-CPU 315-2 PN DP(组态并PLCSIM模式 21分钟).exe

    .arch3 STEP 7编程软件使用方法-CPU 315-2 PN DP(组态并PLCSIM模式 21分钟).exe

    在SAS中拟合ARCH_GARCH模型.pdf

    ### 在SAS中拟合ARCH_GARCH模型 #### 摘要 在现代时间序列分析领域,各种软件程序发挥着至关重要的作用,其中SAS(Statistical Analysis System)作为统计分析的强大工具,被广泛应用于各个行业中。ARCH ...

    arch与garch模型详细介绍

    ARCH(Autoregressive Conditional Heteroskedasticity)模型与GARCH(Generalized Autoregressive Conditional Heteroskedasticity)模型是统计学和金融计量经济学中用于处理时间序列数据波动性的关键工具。...

    自回归条件异方差模型的构建 EViews软件 ARCH模型 GARCH模型 对道琼斯混合指数日收盘价格的对数数据进行研究

    3、实验9的数据为道琼斯混合指数日收盘价格数据,为方便分析,我们对道琼斯混合指数日收盘价格的对数数据进行研究,发现其对数数据可以构建随机游走模型,请利用Eviews软件对模型的残差序列进行ARCH检验,并分别构建...

    ARCH%2520模型.zip_arch_arch matlab

    **ARCH模型**(Autoregressive Conditional Heteroskedasticity,自回归条件异方差模型)是金融时间序列分析中的一个重要工具,它被用于描述和预测数据的波动性,特别是在股票市场、外汇市场和债券市场等领域。...

    dirs3arch工具

    dirs3arch 是一个命令行工具,设计的目标是暴力破解网站的文件与目录。

    Archway

    标题“Archway”很可能指的是一个特定的字体设计或者字体库,尤其考虑到标签是“字体”。在计算机领域,字体是我们日常看到的文字的样式,包括字母、数字和符号的形状。"Archway"可能是一个设计师或公司创造的独特...

    Arch Linux - 桌面环境

    Arch Linux - 桌面环境 安装完基本系统后已经成功了一半,现在开始安装桌面环境以应用日常。

    Beginners' Guide - ArchWiki.pdf

    本文档是一份针对初学者的《Arch Linux安装指南》,旨在指导用户使用Arch Linux官方提供的安装脚本来安装Arch Linux。为了方便阅读,指南还提供了一个分页版本。在安装之前,建议用户预先浏览FAQ,以便对安装过程有...

    BlackArch Linux 简体中文手册

    BlackArch Linux 简体中文手册 202103 版本

    LwIP的sys_arch说明文档下载

    ### LwIP的sys_arch说明文档解读 #### 一、引言 LwIP(Lightweight IP)是一款轻量级的TCP/IP协议栈,适用于内存有限的嵌入式系统。其设计灵活,易于移植到不同的操作系统和硬件平台上。在LwIP的核心组件中,`sys_...

    ARCH4系统开发指南

    ARCH4系统开发指南 1 ARCH4开发小组 1 1 前言 7 1.1 文档编写目的 7 1.2 文档适用范围 7 1.3 修订历史 8 1.4 参考资料 8 2 常用功能处理方式 9 2.1 如何执行条件查询 9 2.1.1 查询示例 9 2.1.2 查询限制 9 2.1.2.1 ...

    Arch Linux全指南

    本文档将指导您安装 Arch Linux:一个简单、轻量级、适合计算机水平较高用户使用的发行版。本向导写给 Arch 新用户,但是会尽量做到成为所有用户的参考和信息库。

Global site tag (gtag.js) - Google Analytics