elf 文件中节的虚拟地址和物理地址

发布于 2024-11-13 18:08:51 字数 662 浏览 3 评论 0原文

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

[1] http://www.ouah.org/RevEng/x430.htm

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

[1] http://www.ouah.org/RevEng/x430.htm

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余生再见 2024-11-20 18:08:51

查找有关 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

眼中杀气 2024-11-20 18:08:51

节头包含单个地址。在我看来,节头中的地址是 VMA。程序头包含VMA到LMA的映射。

例如,以下是“objdump -x”为我的 elf 文件显示的内容片段:

Program Header:
<a few lines removed>
    LOAD off    0x00000240 vaddr 0x00000048 paddr 0x0000018c align 2**0
         filesz 0x00000000 memsz 0x00000004 flags rw-

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
<a few lines removed>
  3 .bss          00000004  00000048  0000018c  00000240  2**1
                  ALLOC

因此,.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:

Program Header:
<a few lines removed>
    LOAD off    0x00000240 vaddr 0x00000048 paddr 0x0000018c align 2**0
         filesz 0x00000000 memsz 0x00000004 flags rw-

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
<a few lines removed>
  3 .bss          00000004  00000048  0000018c  00000240  2**1
                  ALLOC

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.

巨坚强 2024-11-20 18:08:51

物理地址是ELF文件段的一个属性。 ELF文件部分没有这样的属性。不过,可以将部分映射到相应段的内存。

物理地址的含义取决于体系结构,并且在不同的操作系统和硬件平台之间可能有所不同。

从这个链接

p_paddr - 在系统上
物理寻址是相关的,这
成员是为该段保留的
物理地址。因为系统V
忽略物理寻址
应用程序,该成员有
可执行文件的未指定内容
文件和共享对象。

看来您的 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:

p_paddr - On systems for which
physical addressing is relevant, this
member is reserved for the segment’s
physical address. Because System V
ignores physical addressing for
application programs, this member has
unspecified contents for executable
files and shared objects.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文