警告:可加载部分“my_section"在 ELF 段之外 [英] Warning: Loadable section "my_section" outside of ELF segments
问题描述
我使用 Arm Compiler v6.9 for Cortex-R4 构建了一个 axf(elf)文件.但是,当我使用 Arm MCU Eclipse J-link GDB 插件将它加载到目标时,它无法加载我的段的初始化数据.如果我使用 Segger Ozone 和 J-Link 加载 axf,它会正确加载初始化数据.
I have built a axf (elf) file using Arm Compiler v6.9 for Cortex-R4. However when I load this to the target using Arm MCU Eclipse J-link GDB plugins it fails to load the initialisation data for my segments. If I load the axf using Segger Ozone and J-Link it loads the init data correctly.
如果我在 axf 文件上运行 arm-none-eabi-gdb.exe,我会收到所有初始化段的警告:ELF 段之外的可加载段my_section"".
If I run the arm-none-eabi-gdb.exe on the axf file I get "Warning: Loadable section "my_section" outside of ELF segments" for all my initialised segments.
看图片初始化数据应该在图片之后加载到Region$$Table$$Base表指定的地址.
Looking at the image the initialisation data should be loaded after the image to the addresses specified by the table in Region$$Table$$Base.
如果我们与 gcc 链接,我们就不会有这个问题,因为初始化数据的处理方式不同.
We don't have this problem if we link with gcc as the initialised data is done differently.
有什么想法吗?
推荐答案
我今天遇到了同样的问题,并发现了您描述的同样问题:
I've faced the same issue today and observed the same problem that you described:
查看图像,初始化数据应该在图像之后加载到 Region$$Table$$Base 中表指定的地址."
看起来虽然很相似,但是armlink生成的ELF文件和GCC生成的ELF有点不同.无论如何,我已经找到了解决方法.
It seems that although very similar, the ELF file generated by armlink is a bit different than the ELF generated by GCC. Anyway, I've found a workaround for that.
检查我的 main.elf,我注意到 armlinker 将初始化数据存储到 ER_RW 部分:
Checking my main.elf, I noticed that armlinker stored the initialization data into the ER_RW section:
arm-none-eabi-readelf.exe" -S main.elf
There are 16 section headers, starting at offset 0x122b0:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] ER_RO PROGBITS 20000000 000034 001358 00 AX 0 0 4
[ 2] ER_RW PROGBITS 20002000 00138c 0000cc 00 WA 0 0 4
[ 3] ER_ZI NOBITS 200020cc 001458 0004e8 00 WA 0 0 4
[ 4] .debug_abbrev PROGBITS 00000000 001458 0005c4 00 0 0 1
[ 5] .debug_frame PROGBITS 00000000 001a1c 000dc4 00 0 0 1
...
我注意到这个问题的发生是因为 GDB 在 addr=0x20002000 加载了 ER_RW 但事实上,我需要它在 ER_RO 部分之后加载(即在 addr=0x20001358)
I noticed that the issue happens because GDB loaded ER_RW at addr=0x20002000 but, in fact, I needed it to be loaded just after the of ER_RO section (i.e. at addr=0x20001358)
解决方法是:
1- 使用 fromelf 将所有部分转储到二进制文件 main.bin 中.Fromelf 将在 ER_RO 之后附加 ER_RW,因为它应该是:
1- Use fromelf to dump all sections into a binary file main.bin. Fromelf will append ER_RW just after ER_RO, as it is supposed to be:
fromelf.exe --bin -o main.bin main.elf
2- 使用 objcopy 将 ER_RO 部分的内容替换为 main.bin 中的数据.请注意,我们现在可以删除 ER_RW 部分,因为它已经与 ER_RO 合并到 main.bin 中:
2- Use objcopy to replace the contents of the ER_RO section with the data from main.bin. Please notice that we can remove the ER_RW section now since it was already merged with ER_RO into main.bin:
arm-none-eabi-objcopy.exe main.elf --update-section ER_RO=main.bin --remove-section=ER_RW main.gdb.elf
现在可以通过 arm-none-eabi-gdb.exe 加载新的 main.gdb.elf 文件
The new main.gdb.elf file can now be loaded by arm-none-eabi-gdb.exe
这是它的样子:
arm-none-eabi-readelf.exe" -S main.gdb2.elf
There are 15 section headers, starting at offset 0x11c0c:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] ER_RO PROGBITS 20000000 000054 001424 00 AX 0 0 4
[ 2] ER_ZI NOBITS 200020cc 000000 0004e8 00 WA 0 0 4
[ 3] .debug_abbrev PROGBITS 00000000 001478 0005c4 00 0 0 1
...
使用 GDB 调试愉快!!;-)
Happy debugging with GDB!! ;-)
这篇关于警告:可加载部分“my_section"在 ELF 段之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!