链接器是否生成带有 no-pie 标志的最终虚拟内存地址?

Does a linker generate final virtual memory addresses with no-pie flag?

假设我们用gcc -no-pie test.c编译这段代码。 ASLR 现在已禁用。

test.c

int main(){
 int a = 5;
 return a;
}

main分配的初始内存地址可以使用objdump查看:

0000000000401106 <main>:
  401106:   f3 0f 1e fa             endbr64 

使用gdb,我可以在加载后在运行时看到相同的地址:

(gdb)  b main
Breakpoint 1 at 0x401106

可以安全地说,当可执行文件不是 position independent 那么地址 在 link 时间内生成的是最终虚拟内存地址吗?如果将二进制文件移动到具有相同 OS 的另一台主机,它将加载到相同的虚拟地址?

Is it safe to say, when executable is not position independent then the addresses generated during link time are final virtual memory addresses?

是的。

if binary is moved to another host with the same OS it will be loaded at the same virtual address?

是的。

链接到特定地址的非 PIE 二进制文件将 运行 正确地 只有 如果它被加载到链接地址。在任何其他地址加载它都会导致它崩溃。