GCC LD NOLOAD 链接器部分生成可加载段

问题描述

我正在开发一个 Arm 裸机应用程序,我用 NOLOAD 标记了一些部分。根据 Understanding linker script NOLOAD sections in embedded software 中的解释,我希望生成的 ELF 文件没有这些部分的可加载段(程序头),但确实如此。

这是正确的吗?为什么这些部分在 ELF 文件标记为可加载?

由于链接器仍在将数据放置在 .bss 中,加载器如何知道不应加载这些部分?还是我错过了“加载”的含义,因为 NOLOAD 仅对 初始化 符号(通常会放入 .data)有意义?

这是我的链接器脚本的一部分:

    .bss (NOLOAD) :
    {
        . = ALIGN(4);
        __bss_start__ = .;
        *(.bss_begin .bss_begin.*)

        *(.bss .bss.*)
        *(COMMON)

        *(.bss_end .bss_end.*)
        . = ALIGN(4);
        __bss_end__ = .;
    } >DRAM

    .noinit (NOLOAD) :
    {
        . = ALIGN(4);
        __noinit_start__ = .;

        *(.noinit .noinit.*)

         . = ALIGN(4) ;
        __noinit_end__ = .;
    } > DRAM
    
    /* Check if there is enough space to allocate the main stack */
    ._stack (NOLOAD) :
    {
        . = ALIGN(4);
        
        . = . + __Main_Stack_Size ;
        
        . = ALIGN(4);
    } >DRAM

这是输出的 ELF 文件

arm-none-eabi-readelf.exe -l test.elf

Elf file type is EXEC (Executable file)
Entry point 0x601b9
There are 2 program headers,starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x010000 0x00060000 0x00060000 0x06840 0x06840 RWE 0x10000
  LOAD           0x020000 0x20010000 0x20010000 0x00000 0x06084 RW  0x10000

 Section to Segment mapping:
  Segment Sections...
   00     .text .ARM.exidx.reset .data
   01     .systemclock .bss ._stack

为什么会有 .bss._stack 部分?

谢谢!!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)