ELF标签地址

ELF label address

我在 .s 文件中有以下代码:

pushq $afterjmp
    nop
afterjmp:
    movl %eax, %edx

它的目标文件有以下内容:

20: 68 00 00 00 00          pushq  [=11=]x0
25: 90                      nop
0000000000000026 <afterjmp>:
26: 89 c2                   mov    %eax,%edx

链接后变成:

400572: 68 78 05 40 00          pushq  [=12=]x400578
400577: 90                      nop
400578: 89 c2                   mov    %eax,%edx

目标文件的字节 20 中的参数 0x0pushq 如何在最终可执行文件中转换为 0x400578

目标文件的哪个部分包含此信息?

您回答了自己的问题:After linking...

这是一篇好文章:

Linkers and Loaders

请特别注意有关 "symbol relocation" 的部分:

Relocation. Compilers and assemblers generate the object code for each input module with a starting address of zero. Relocation is the process of assigning load addresses to different parts of the program by merging all sections of the same type into one section. The code and data section also are adjusted so they point to the correct runtime addresses.

汇编单个目标文件时,无法知道"afterjmp"的程序地址。只有当所有目标文件都组装成一个可执行映像时,才能计算地址(相对于偏移“0”)。这是链接器的工作之一:跟踪 "symbol references"(如 "afterjmp"),并计算机器地址("symbol relocation")。