gpt4 book ai didi

linux - 如何获取 ELF 文件的 A 值?

转载 作者:太空狗 更新时间:2023-10-29 12:14:59 26 4
gpt4 key购买 nike

我是 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加数,根据Elf32_RelElf32_Rela 计算结构
  • B基址,由p_vaddr 计算得出。具体计算取决于架构。

您可以使用 readelf -r 观察一些二进制/库文件的重定位部分。

关于linux - 如何获取 ELF 文件的 A 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28805940/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com