警告:可加载部分 "my_section" 在 ELF 段之外

Warning: Loadable section "my_section" outside of ELF segments

我已经使用 Arm Compiler v6.9 为 Cortex-R4 构建了一个 axf (elf) 文件。但是,当我使用 Arm MCU Eclipse J-link GDB 插件将其加载到目标时,它无法为我的段加载初始化数据。如果我使用 Segger Ozone 和 J-Link 加载 axf,它会正确加载初始化数据。

如果我 运行 axf 文件上的 arm-none-eabi-gdb.exe 我得到 "Warning: Loadable section "my_section“在 ELF 段之外”对于我所有的初始化段。

查看图像,初始化数据应该在图像之后加载到 Region$$Table$$Base.

中 table 指定的地址

如果我们 link 使用 gcc 就不会遇到这个问题,因为初始化数据的方式不同。

有什么想法吗?

我今天遇到了同样的问题,并观察到与您描述的相同的问题:

"Looking at the image the initialisation data should be loaded after the image to the addresses specified by the table in Region$$Table$$Base."

看来虽然很像,但是armlink生成的ELF文件和GCC生成的ELF还是有点区别的。 不管怎样,我已经找到了解决方法。

检查我的 main.elf,我注意到 armlinker 将初始化数据存储到 ER_RW 部分:

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 )

解决方法是:

1- 使用 fromelf 将所有部分转储到二进制文件中 main.bin。 Fromelf 将在 ER_RO 之后附加 ER_RW,因为它应该是:

fromelf.exe --bin -o main.bin main.elf

2- 使用 objcopy 将 ER_RO 部分的内容替换为来自 main.bin 的数据。 请注意,我们现在可以删除 ER_RW 部分,因为它已经与 ER_RO 合并为 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 文件

这是它的样子:

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 调试愉快!! ;-)