为什么要解决PIC功能地址需要.rela.plt?
在探索ELF结构时,我看到了这一点(这是objdump -d
和readelf -r
the二进制的linked linked linked linked link link in pic .so conc.so包含ml_func
):
0000000000400480 <_Z7ml_funcii@plt>:
400480: ff 25 92 0b 20 00 jmpq *0x200b92(%rip) # 601018 <_Z7ml_funcii>
Relocation section '.rela.plt' at offset 0x438 contains 1 entry:
Offset Info Type Sym. Value Sym. Name + Addend
000000601018 000100000007 R_X86_64_JUMP_SLO 0000000000000000 _Z7ml_funcii + 0
不是.rela.plt冗余吗?它似乎存储了相同的偏移601018,该偏移量已经在ml_func@plt
上计算出来。
还是对于某些更复杂的案例(例如不同的搬迁类型)有用吗?或者只是某种形式的优化(例如,我想从ml_func@plt
...)中获得601018可能并不小
。 为什么链接器会在中链接产生看似无用的无用重新定位。 rela.plt?,他们在哪里写
.rela.plt也用于解析功能地址,即使在懒惰链接期间。
我想我想知道为什么如果没有.rela.plt,为什么架空架无法完成工作。
While exploring ELF structure, I see this (this is objdump -d
and readelf -r
of the binary linked with a PIC .so containing ml_func
):
0000000000400480 <_Z7ml_funcii@plt>:
400480: ff 25 92 0b 20 00 jmpq *0x200b92(%rip) # 601018 <_Z7ml_funcii>
Relocation section '.rela.plt' at offset 0x438 contains 1 entry:
Offset Info Type Sym. Value Sym. Name + Addend
000000601018 000100000007 R_X86_64_JUMP_SLO 0000000000000000 _Z7ml_funcii + 0
Isn't .rela.plt redundant? It seems to store the same offset 601018 which is already calculated at ml_func@plt
.
Or is it useful for some more complex cases like different relocation types? Or is it just an optimization of some sort (like, I guess it might be not trivial to get the 601018 from outside the ml_func@plt
...)?..
I guess this question is similar to Why does the linker generate seemingly useless relocations in .rela.plt?, where they write that
.rela.plt is used to resolve function addresses, even during lazy linking.
I guess I wonder why the resolver couldn't do its work without the .rela.plt.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在
.plt
中看到的601018实际上并非来自该部分。这只是阅读提供给您的有用注释。阅读本身通过查看.rela.plt
来发现此信息。当您的程序启动时,全局偏移表(GOT)需要在过程链接表(PLT)中包含一个地址,以引导动态链接逻辑。但是,当您编译程序时,编译器尚不知道PLT的绝对地址。这就是为什么存在
.rela.plt
存在的原因。动态链接器使用此信息在程序启动时修补了GOT。The 601018 you see in
.plt
is not actually coming from that section. This is merely a helpful annotation which readelf is providing to you. readelf itself discovered this information by looking at.rela.plt
.When your program starts up, the global offset table (GOT) needs to contain an address inside the procedure linkage table (PLT) in order to bootstrap the dynamic linking logic. However, when your program is compiled, the compiler doesn't know yet know the absolute address of the PLT. That's why the
.rela.plt
section exists. The dynamic linker uses this information to patch the GOT when your program starts.