- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我是 Linux 系统的初学者,我正在阅读这份文档 ( http://www.skyfree.org/linux/references/ELF_Format.pdf ) 来研究 ELF 文件格式。但是当我看到有关搬迁的相关文档时,搬迁计算中有奇怪的事情。我知道根据搬迁类型,它采用不同的方式来计算。但是看看这个。
当R-type为R_386_RELATIVE时,本文档说的是“B+A”的计算方式。但是“A”到底是什么意思?以及如何在 ELF 文件中获取此“A”值?
请给我你仁慈的回答.......;
最佳答案
来自您提到的文档:
R_386_RELATIVE
The link editor creates this relocation type for dynamic linking. Its offset member gives a location within a shared object that contains a value representing a relative address. The dynamic linker computes the corresponding virtual address by adding the virtual address at which the shared object was loaded to the relative address. Relocation entries for this type must specify 0 for the symbol table index.
A
This means the addend used to compute the value of the relocatable field.
B
This means the base address at which a shared object has been loaded into memory during execution. Generally, a shared object file is built with a 0 base virtual address, but the execution address will be different.
Addend
As shown above, only
Elf32_Rela
entries contain an explicit addend. Entries of type `Elf32_Rel store an implicit addend in the location to be modified. Depending on the processor architecture, one form or the other might be necessary or more convenient. Consequently, an implementation for a particular machine may use one form exclusively or either form depending on context.Base Address
To compute the base address, one determines the memory address associated with the lowest
p_vaddr
value for aPT_LOAD
segment. One then obtains the base address by truncating the memory address to the nearest multiple of the maximum page size. Depending on the kind of file being loaded into memory, the memory address might or might not match thep_vaddr
values.
所以归结为下一个:
Elf32_Rel
或Elf32_Rela
计算结构p_vaddr
计算得出。具体计算取决于架构。您可以使用 readelf -r
观察一些二进制/库文件的重定位部分。
关于linux - 如何获取 ELF 文件的 A 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28805940/
我是一名优秀的程序员,十分优秀!