在编译期间,编译器对于不确定的变量或函数的地址用特殊值先代替着:变量用 0,函数用 -4 (我编译出来是 0)

objdump -d <file> 查看情况

再链接截断 ld 通过 重定位表 重新调整符号

readelf -r <file> 查看符号表

在编译阶段,每个编译单元的未解析的符号都当做潜在的全局变量;在链接阶段,在链接器扫描完所有的输入目标文件之后,所有这些未定义的符号都能够在全局符号表中找到,否则就报未定义错误

c objdump -r a.o

a.o:     file format elf64-x86-64

RELOCATION RECORDS FOR [.text]:
OFFSET           TYPE              VALUE
0000000000000015 R_X86_64_PLT32    Other-0x0000000000000004
000000000000001f R_X86_64_PLT32    Other-0x0000000000000004
0000000000000029 R_X86_64_PLT32    Other-0x0000000000000004


RELOCATION RECORDS FOR [.eh_frame]:
OFFSET           TYPE              VALUE
0000000000000020 R_X86_64_PC32     .text
0000000000000040 R_X86_64_PC32     .text+0x000000000000000b


c objdump -d a.o

a.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <Other>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   b8 01 00 00 00          mov    $0x1,%eax
   9:   5d                      pop    %rbp
   a:   c3                      ret

000000000000000b <SomeFunction>:
   b:   55                      push   %rbp
   c:   48 89 e5                mov    %rsp,%rbp
   f:   b8 00 00 00 00          mov    $0x0,%eax
  14:   e8 00 00 00 00          call   19 <SomeFunction+0xe>
  19:   b8 00 00 00 00          mov    $0x0,%eax
  1e:   e8 00 00 00 00          call   23 <SomeFunction+0x18>
  23:   b8 00 00 00 00          mov    $0x0,%eax
  28:   e8 00 00 00 00          call   2d <SomeFunction+0x22>
  2d:   b8 00 00 00 00          mov    $0x0,%eax
  32:   5d                      pop    %rbp
  33:   c3                      ret

好像这里没有给到 -4 的偏移(P)??

https://stackoverflow.com/questions/64424692/how-does-the-address-of-r-x86-64-plt32-computed

COMMON块