什么是ABI(应用程序二进制接口)?

发布于 2024-10-14 16:27:40 字数 503 浏览 7 评论 0原文

维基百科是这样说的:

在计算机软件中,应用程序 二进制接口(ABI)描述了 之间的低级接口 应用程序(或任何类型的)程序 和操作系统或其他 应用程序。

ABI 涵盖数据类型、 尺寸和对齐方式;召唤 约定,它控制如何 函数的参数被传递并且 返回检索到的值;系统 电话号码以及如何申请 应该进行系统调用 操作系统;如果是 完整的操作系统 ABI, 目标文件、程序的二进制格式 图书馆等。完整的 ABI, 例如英特尔二进制兼容性 标准 (iBCS),允许程序 从一个操作系统支持 无需修改即可运行的 ABI 在任何其他此类系统上,前提是 必要的共享库是 目前,类似的先决条件是 实现了。

我猜想 ABI 是一种约定或标准,编译器/链接器使用此约定来生成目标代码。是这样吗?如果是的话,是谁制定了这些公约(公司或某个组织)?没有 ABI 时情况如何?有没有关于这些 ABI 的文档可供我们参考?

This is what wikipedia says:

In computer software, an application
binary interface (ABI) describes the
low-level interface between an
application (or any type of) program
and the operating system or another
application.

ABIs cover details such as data type,
size, and alignment; the calling
convention, which controls how
functions' arguments are passed and
return values retrieved; the system
call numbers and how an application
should make system calls to the
operating system; and in the case of a
complete operating system ABI, the
binary format of object files, program
libraries and so on. A complete ABI,
such as the Intel Binary Compatibility
Standard (iBCS), allows a program
from one operating system supporting
that ABI to run without modifications
on any other such system, provided
that necessary shared libraries are
present, and similar prerequisites are
fulfilled.

I guess that an ABI is a convention or standard, and compilers/linkers use this convention to produce object codes. Is that right? If so who made these conventions(companies or some organization)? What was it like when there was no ABIs? Is there documents about these ABIs that we can refer to?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫烠⑼条掵仅有一顆心 2024-10-21 16:27:40

在某种程度上,您对 ABI 的定义是正确的。典型的例子是 Linux(和其他 UNIX)中的syscall接口。

它们是代码请求操作系统执行某些职责的标准方式。

因此,它们是由编写操作系统的人决定的,或者在稍后添加系统调用的情况下,由添加它们的人决定(在操作系统允许的情况下)。例如,x86 上的 Linux syscall 接口规定您将 syscall 编号加载到 eax 中,其他参数则放置在 ebx< /code>、ecx 等,具体取决于您正在创建的syscall (eax)。

通常,执行接口工作的不是编译器或链接器,而是为您所使用的语言提供的库。

回到 Linux,GNU C 库包含 fopen 的代码(例如),它最终调用相关的 syscall 来执行较低级别的任务(系统调用编号 5,打开)。系统调用列表可以在 此 PDF 文件

You're correct about the definition of an ABI, up to a point. The classic example is the syscall interface in Linux (and other UNIXes).

They are a standard way for code to request the operating system to carry out certain duties.

As such, they're decided by the people that wrote the OS or, in the case where the syscalls have been added later, by whoever added them (in cases where the OS allows this). For example, the Linux syscall interface on x86 states that you load the syscall number into eax, with other parameters placed in ebx, ecx and so on, depending on the syscall you're making (eax).

Typically, it's not the compiler or linker which do the work of interfacing, rather it's the libraries provided for the language you're using.

Returning to Linux, the GNU C libraries contain code for fopen (for example) which eventually call the relevant syscall to perform the lower level tasks (syscall number 5, open). A list of the syscalls can be found in this PDF file.

疧_╮線 2024-10-21 16:27:40

规范是比约定更合适的术语,因为约定是广泛接受的实践的宽松术语,而规范是明确定义的。

你是对的。该规范由标准化机构制定。看一下 Windows 支持的 POSIX 规范,编译器/构建工具链(例如 gcc)假设操作系统遵守它,甚至 Linux 内核部分(几乎完全)遵守它。

在 ABI 之前?即使在今天,随着用于机顶盒和其他具有嵌入式系统的设备的新芯片的出现,固件仍然是手工制作的。

该文档是数据表中的数字逻辑内容,用于通过汇编语言和高级语言进行编程的芯片,交叉编译器工具链文档给出了应成为 ABI 一部分的假设。

Specification is more suitable term than convention, as convention is loose term for widely accepted practice whereas specification is well-defined.

You are right. The specification is made by standardization body. Take a look at POSIX specification which is supported by Windows and compiler/build tool-chains such as gcc assume OS's to adhere by it, and even Linux kernel partially (almost exactly) adheres to it.

Before ABIs? Even today, firmware is hand-crafted as new chips come along for set-top boxes and such other devices having embedded systems.

The documentation is digital logic content in the data-sheet for the chips to be programmed by assembly language and for higher-level language, the cross-compiler tool-chain documentation gives away the assumptions that should be part of ABI.

无敌元气妹 2024-10-21 16:27:40

好吧,ABI 的概念大概是为了支持程序在其他操作系统和机器架构上的二进制兼容性而设计的。因此,假设您在 x86 架构上运行的某些操作系统发行版上编写了一个程序。现在,对于程序员来说,最重要的是,您在机器上编写的程序应该能够在运行相同或不同架构的任何其他机器上完全相同地运行,为了讨论起见,假设另一台机器正在运行在 i386 架构上,这就是 ABI 或应用程序二进制接口的概念出现的地方。由于每个机器架构都定义了自己的操作系统内核与外部世界(即用户空间程序)对话的方式,因此每个架构都定义了不同的集合系统调用、机器寄存器、这些寄存器如何使用、内核如何处理软件中断等等。 ABI 是为你处理这些事情的东西,比如编译、链接、字节排序等等。系统程序员很难为在不同架构上运行的相同操作系统定义统一的 ABI,这就是为什么每个机器架构都有自己的架构,并且您需要编译程序以确认这些机器具有的格式。

Well, the concept of ABI was presumably conceived to support the binary compatibility of your program on other operating systems and machine architectures. So, lets suppose that you wrote a program on some operating system distribution running on x86 architecture. Now, for a programmer the most important thing is that this program that you wrote on your machine should be able to run exactly the same on any other machine running on same or different architecture lets say for the sake of discussion that the other machine is running on i386 architecture and this is where the concept of ABI or Application Binary Interfaces comes in. As every machine architecture defines its own way in which the operating system kernal talks to the outside world i.e user-space programs, hence every architecture defines a different set of system calls, machine registers, how those registers are used, how are software interrupts handled by the kernal and so on. ABI is the thing that handles these things for you like compiling, linking, byte ordering and so on. System programmers have had hard luck defining a uniform ABI for same operating systems running on different architectures and that is why every machine architecture has its own and you need to compile your programs in order to confirm to the format those machines have.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文