如何获取 ELF 文件的 A 值?
How can I get A value of ELF file?
我是 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 a PT_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 the p_vaddr
values.
所以归结为下一个:
- A 是 addend 并从
Elf32_Rel
或 Elf32_Rela
结构
- B是基地址,由
p_vaddr
计算而来。具体计算取决于体系结构。
您可以使用 readelf -r
.
观察某些 binary/library 文件的重定位部分
我是 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.
所以归结为下一个:
- A 是 addend 并从
Elf32_Rel
或Elf32_Rela
结构 - B是基地址,由
p_vaddr
计算而来。具体计算取决于体系结构。
您可以使用 readelf -r
.