ABI

In computer software, an application binary interface (ABI) is an interface between two program modules; often, one of these modules is a library or operating system facility, and the other is a program that is being run by a user.

计算机软件领域,ABI是两个程序模块的接口。这种接口通常一端连接系统底层,另一端连接应用程序。

An ABI defines how data structures or computational routines are accessed in machine code, which is a low-level, hardware-dependent format; in contrast, an API defines this access in source code, which is a relatively high-level, relatively hardware-independent, often human-readable format. A common aspect of an ABI is the calling convention, which determines how data is provided as input to or read as output from computational routines; examples are the x86 calling conventions.

ABI规定了外部如何通过机器码访问数据结构和应用程序。这种访问是基于硬件底层的。相对应的是,API是源码级别的,属于高层的,相对来说硬件无关的,更容易被人们理解的形式。ABI一个常见的表现形式是调用约定。调用约定规定了如何从程序输入和输出数据。

Adhering to an ABI (which may or may not be officially standardized) is usually the job of a compiler, operating system, or library author; however, an application programmer may have to deal with an ABI directly when writing a program in a mix of programming languages, which can be achieved by using foreign function calls.

维护(Adhering to)稳定的ABI(这可能并非标准要求)是编译器、操作系统、程序库等的作者的工作。但是,应用程序开发者一般并不需要直接面对ABI,除非他们需要写一个多语言混编的程序,这个时候他们可以通过外部调用实现。

ABIs cover details such as:

ABI包括了以下场景:

  • a processor instruction set (with details like register file structure, stack organization, memory access types, ...)

  • 处理器指令集,包括寄存器结构,堆栈组织,内存访问类型等。

  • the sizes, layouts, and alignments of basic data types that the processor can directly access

  • 处理器可以直接访问的基本数据类型的大小、布局、对齐方式

  • the calling convention, which controls how functions' arguments are passed and return values are retrieved; for example, whether all parameters are passed on the stack or some are passed in registers, which registers are used for which function parameters, and whether the first function parameter passed on the stack is pushed first or last onto the stack

  • 调用约定控制了函数实参的传递和返回值的取得。比如,是否所有形参都通过堆栈传递,抑或是部分通过寄存器传递?不同寄存器分别存储那些形参?第一个使用堆栈传递的函数形参首先压栈还是最后压栈?

  • how an application should make system calls to the operating system and, if the ABI specifies direct system calls rather than procedure calls to system call stubs, the system call numbers

  • 应用程序该如何向操作系统发起系统调用?是直接调还是通过进程间接口调用,又或者是使用系统调用号?

  • and in the case of a complete operating system ABI, the binary format of object files, program libraries and so on.

  • 对于完整的操作系统ABI,还包括了.o 文件、应用程序可执行文件等的二进制内部格式。

你可能感兴趣的:(ABI)