当 VMA != LMA 时加载 ELF [英] ELF loading when VMA != LMA

查看:31
本文介绍了当 VMA != LMA 时加载 ELF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题.我使用 ARM Cortex-A9 和 DS-5 来创建裸机固件.我修改了我的链接器文件,故意将 .data 部分 LMA 与 text 和 Rodata 部分相邻,因为它的默认运行时 VMA 位于 1MB 之外,而 .bin 图像大约为 1MB,但包含 90% 的零.所以我特意制作了 LMA != VMA 以节省空间.我还在 start.S 中添加了一段代码,用于将 .data 部分从 lma 重定位到 vma.

I have a problem on this one. I am using ARM Cortex-A9 with DS-5 to create baremetal firmware. I modified my linker file to intentionally put the .data section LMA adjacent to the text and rodata sections, because its default run-time VMA is located 1MB away and the .bin image is around 1MB but containing 90% zeroes. And so I intentionally made LMA != VMA to save space. I also added a code in start.S that relocates the .data section from its lma to vma.

然而,在 DS-5 中加载生成的 elf 文件时,它已经将所有部分加载到他们的 VMA.结果,我的 start.S 代码本应重新定位数据,从带有垃圾内容的 LMA 复制到已经正确的 VMA,不久之后这些垃圾导致故障.

However on loading the resulting elf file in DS-5, it already loads all section to their VMA. As a result, my start.S code that is supposed to relocate data, copied from the LMA with garbage content to the already correct VMA, and soon afterwards those garbage resulted to fault.

我在 Cortex-M4 中使用过二进制不相等的 VMA 和 LMA,并使用 gdb 进行精灵调试,那里没有问题,但它是微控制器.在我当前的 arm 处理器应用程序中,我将如何在 elf 中模拟将数据从 LMA 正确复制到 VMA 的场景.很可能在使用二进制格式独立启动时不会出现问题,但现在我们仍在 elf 调试中,所以我必须解决这个问题.

I've had experience with unequal VMA and LMA in binary in Cortex-M4 and used gdb for its elf debugging, and there were no problems there, but it was microcontroller. In my current arm processor application, how would I then simulate in elf debugging the scenario of correctly copying data from its LMA to VMA. Most likely when booting standalone using the binary format there will be no problems, but right now we're still in elf debugging so I have to fix this.

推荐答案

问题解决了...我想分享给我的解决方案:

Problem solved... I'd like to share the solution given to me:

认识到VMA"和LMA"是 GNU 实用程序术语而不是 ELF 规范中的术语会有所帮助.一旦你开始通过解释一个 ELF 可执行文件来查看它,你会发现有一个名为p_paddr"的程序头字段和另一个名为p_vaddr"的字段——这使得搜索更容易!在 DS-5 中使用 p_paddr 所需的选项是:

It helps to realize that "VMA" and "LMA" are GNU utility terminology and not in the ELF specification. Once you get down to looking at it from interpreting an ELF executable file, you will find that there is a program header field called "p_paddr" and another called "p_vaddr" - that makes it easier to search for! The option you need in DS-5 to use p_paddr is:

ARM DS-5 调试器命令参考:1.3.138 set elf load-segments-at-p_paddr

ARM DS-5 Debugger Command Reference : 1.3.138 set elf load-segments-at-p_paddr

默认情况下,DS-5 使用 p_vaddr,这是标准.p_paddr 的使用是一种实现质量,并且在规范中非常松散地定义.ARM 编译器、链接器和 C 库不会生成此信息,因为重定位过程是在内部处理的(分散加载).有些环境使用 p_paddr 不是物理地址,而是加载地址(因此称为LMA"),有些环境使用它作为地址来解析启用 MMU 前后的符号..

By default, DS-5 uses p_vaddr, which is the standard. Usage of p_paddr is a quality of implementation, and is left very loosely defined in the specification. The ARM Compiler, Linker and C Library doesn't generate this information since the relocation process is handled internally (scatter loading). Some environments use p_paddr not as a physical address, but the load address (hence "LMA"), and some use it as an address to resolve symbols before and after MMU is enabled..

这篇关于当 VMA != LMA 时加载 ELF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆