我正在开发一个 Arm 裸机应用,并使用 NOLOAD
标记了一些部分。根据在 Understanding linker script NOLOAD sections in embedded software
中的解释,我期望生成的 ELF 文件不会为这些部分生成可加载段(程序头),但实际上会生成。
这是正确的吗?为什么这些部分在 ELF 文件中被标记为可加载?
由于链接器仍将数据放置在 .bss
中,那么加载程序如何知道这些部分不应该被加载?或者我是否误解了 “load” 的意思,即 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
这两个区段?
谢谢!
.noinit
部分时,链接器将其从.bss
移动到.noload
,我期望这里也有类似的操作? - Leonardo