gpt4 book ai didi

abi - IA-64 中的 "a GP/function address pair"是什么意思?

转载 作者:行者123 更新时间:2023-12-05 01:07:12 26 4
gpt4 key购买 nike

Itanium C++ ABI中的“GP/函数地址对”是什么意思? GP代表什么?

最佳答案

简短说明:gp对于所有实际方法来说,它是所有符合 Itanium ABI 的函数的隐藏参数。这是一种this指向函数使用的全局变量的指针。据我所知,没有主流操作系统再这样做了。
GP 代表“全局指针”。它是由可执行文件静态分配的数据的基地址,安腾架构有一个专门用于它的寄存器。
例如,如果你的程序中有这些全局变量和这个函数:

int foo;
int bar;
int baz;

int func()
{
foo++;
bar += foo;
baz *= bar / foo;
return foo + bar + baz;
}
gp/函数对在概念上是 &foo, &func .为 func 生成的代码将引用 gp找到全局变量所在的位置。编译器知道 foo可以在 gp 找到, bar可以在 gp + 4 找到和 baz可以在 gp + 8 找到.
假设 func在外部库中定义,如果从程序中调用它,编译器将使用如下指令序列:
  • 将当前的 gp 值保存到堆栈中;
  • 从对中加载 func 的代码地址进入某个寄存器;
  • 将同一对中的 gp 值加载到 GP 中;
  • 对存储代码地址的寄存器进行间接调用;
  • 恢复我们之前保存在堆栈中的旧 gp 值,继续调用函数。

  • 这使得可执行文件完全与位置无关,因为它们从不存储数据符号的绝对地址,因此可以在内存中仅维护任何可执行文件的一个实例,无论有多少进程使用它(您甚至可以加载在单个进程中多次执行相同的可执行文件,并且在系统范围内仍然只有一份可执行代码的副本),代价是使函数指针有点奇怪。对于 Itanium ABI,函数指针不是代码地址(就像“常规”x86 ABI 一样):它是 gp 值和代码地址的地址,因为如果可以的话,该代码地址可能不值多少钱' t 访问它的全局变量,就像一个方法如果没有 this 可能无法做很多事情一样。指针。
    我所知道的唯一使用此概念的其他 ABI 是 Mac OS Classic PowerPC ABI。他们称这些对为“过渡向量”。
    由于 x86_64 支持 RIP 相对寻址(x86 没有等效的 EIP 相对寻址),现在创建与位置无关的代码非常容易,而无需使用额外的寄存器或使用“增强型”函数指针。代码和数据必须保持恒定的偏移量。因此,这部分 Itanium ABI 可能在 Intel 平台上一去不复返了。
    来自 Itanium Register Conventions :

    8.2 The gp Register

    Every procedure that references statically-allocated data or calls another procedure requires a pointer to its data segment in the gp register, so that it can access its static data and its linkage tables. Each load module has its own data segment, and the gp register must be set correctly prior to calling any entry point within that load module.

    The linkage conventions require that each load module define exactly one gp value to refer to a location within its short data segment. It is expected that this location will be chosen to maximize the usefulness of short-displacement immediate instructions for addressing scalars and linkage table entries. The DLL loader will determine the absolute value of the gp register for each load module after loading its data segment into memory.

    For calls within a load module, the gp register will remain unchanged, so calls known to be local can be optimized accordingly.

    For calls between load modules, the gp register must be initialized with the correct gp value for the new load module, and the calling function must ensure that its own gp value is saved and restored.

    关于abi - IA-64 中的 "a GP/function address pair"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18907934/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com