elf 文件中节的虚拟地址和物理地址
objdump 如何计算 elf 节的物理地址(LMA)?据我所知,elf 节头仅包含节 [1] 的虚拟地址(VMA)。
通常,VMA 和 LMA 是相同的。但对于初始化数据段(.data),VMA 是变量的 RAM 位置,LMA 是初始值所在的 ROM 位置。 Crt0 负责在调用 main() 之前将初始值复制到 RAM 中。例如:
$ objdump -h my.elf
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0003c3d0 00080000 00080000 00010000 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
5 .data 000008d0 40000000 000d08d4 00060000 2**3
CONTENTS, ALLOC, LOAD, DATA
-Tom
How does objdump compute the physical address (LMA) of elf sections? As far as I can tell, elf section headers only contain the virtual address (VMA) of sections [1].
Usually, VMA and LMA are the same. But for initialized data sections (.data), the VMA is the RAM location of the variables and LMA is the ROM location where the initial values are located. Crt0 is responsible for copying the initial values into RAM before main() is called. For example:
$ objdump -h my.elf
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0003c3d0 00080000 00080000 00010000 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
5 .data 000008d0 40000000 000d08d4 00060000 2**3
CONTENTS, ALLOC, LOAD, DATA
-Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查找有关 LMA 的信息:
http://www-zeuthen.desy.de/dv/documentation/unixguide/infohtml/binutils/docs/ld/Basic-Script-Concepts.html#Basic-Script-Concepts
重要的是:
每个可加载或可分配的输出部分都有两个地址。第一个是 VMA,即虚拟内存地址。这是运行输出文件时该节将具有的地址。第二个是 LMA,或加载内存地址。这是该部分将被加载的地址。在大多数情况下,两个地址是相同的。它们可能不同的一个例子是,当程序启动时,数据部分被加载到 ROM 中,然后复制到 RAM 中(此技术通常用于初始化基于 ROM 的系统中的全局变量)。在这种情况下,ROM 地址将是 LMA,RAM 地址将是 VMA
Find this about LMA:
http://www-zeuthen.desy.de/dv/documentation/unixguide/infohtml/binutils/docs/ld/Basic-Script-Concepts.html#Basic-Script-Concepts
The important is following:
Every loadable or allocatable output section has two addresses. The first is the VMA, or virtual memory address. This is the address the section will have when the output file is run. The second is the LMA, or load memory address. This is the address at which the section will be loaded. In most cases the two addresses will be the same. An example of when they might be different is when a data section is loaded into ROM, and then copied into RAM when the program starts up (this technique is often used to initialize global variables in a ROM based system). In this case the ROM address would be the LMA, and the RAM address would be the VMA
节头包含单个地址。在我看来,节头中的地址是 VMA。程序头包含VMA到LMA的映射。
例如,以下是“objdump -x”为我的 elf 文件显示的内容片段:
因此,.bss 的 VMA 为 0x48。如果查看程序头,会发现其中一个条目的“vaddr”为 0x48,paddr 为 0x18c,这就是 LMA。
The section header contains a single address. It looks to me like address in the section header is the VMA. The program headers contain the mapping of VMA to LMA.
For example, here's a snippet of what "objdump -x" shows for my elf file:
So, .bss has a VMA of 0x48. If you look through the program headers, one entry has a "vaddr" of 0x48 and a paddr of 0x18c, which is the LMA.
物理地址是ELF文件段的一个属性。 ELF文件部分没有这样的属性。不过,可以将部分映射到相应段的内存。
物理地址的含义取决于体系结构,并且在不同的操作系统和硬件平台之间可能有所不同。
从这个链接:
看来您的 Crt0 对 ELF 文件中物理地址的含义做出了一些假设。该假设对于特定系统可能是正确的,但在另一个系统上则不能保证。
Physical address is an attribute of ELF file segment. ELF file section does not have such attribute. It is possible though to map sections to corresponding segment's memory.
The meaning of physical address is architecture dependent and may vary between different OSes and hardware platforms.
From this link:
It looks like your Crt0 makes some assumption about meaning of physical address located in ELF file. This assumption may be true for the particular system, but is not garanteed on another.