armgdbarmv7armclang

Warning: Loadable section "my_section" outside of ELF segments


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.

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.

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

We don't have this problem if we link with gcc as the initialised data is done differently.

Any ideas?


Solution

  • I've faced the same issue today and observed the same problem that you described:

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

    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.

    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
             ...
    

    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)

    The workaround for that is:

    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- 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
    

    The new main.gdb.elf file can now be loaded by arm-none-eabi-gdb.exe

    This is how it looks:

    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
           ...
    

    Happy debugging with GDB!! ;-)