Hi! I’m encountering an issue with my minimal RTEMS application using the official STM32F4 BSP, where the .bss
section scales to nearly fill the entire RAM size defined in the linker script, regardless of the actual memory needs. The project contains only init.c
with no large arrays, and all unnecessary drivers and components are disabled (e.g., console, filesystem). The linker script is based on linkcmds.armv7m
, with a custom memory definition. Below are three configurations with different RAM sizes and their size
outputs, showing .bss
consistently occupying almost all available RAM.
Linker Script Configurations:
-
RAM = 384 KB:
MEMORY { RAM_INT : ORIGIN = 0x20000000, LENGTH = 384K ROM_INT : ORIGIN = 0x08000000, LENGTH = 1M } . . . . . . INCLUDE linkcmds.armv7m
Size Output:
text data bss dec hex filename 70864 1244 392004 464112 714f0 app.elf
.bss
= ~383 KB (almost entire RAM).
-
RAM = 128 KB:
MEMORY { RAM_INT : ORIGIN = 0x20000000, LENGTH = 128K ROM_INT : ORIGIN = 0x08000000, LENGTH = 1M } . . . . . . INCLUDE linkcmds.armv7m
Size Output:
text data bss dec hex filename 70796 1244 129860 201900 314ac app.elf
.bss
= ~126.8 KB (almost entire RAM).
-
RAM = 5000 KB:
MEMORY { RAM_INT : ORIGIN = 0x20000000, LENGTH = 5000K ROM_INT : ORIGIN = 0x08000000, LENGTH = 1M } . . . . . . INCLUDE linkcmds.armv7m
Size Output:
text data bss dec hex filename 47776 856 5119172 5167804 4edabc app.elf
.bss
= ~5000 KB (almost entire RAM).
Questions:
- Why does
.bss
scale to match theRAM_INT
size, and how can I prevent this to ensure.bss
only includes actual variables? - How does the stack behave in this scenario? Specifically, with
.bss
consuming almost allRAM_INT
, is the stack (defined in.stack
withbsp_stack_main_size = 4096
) properly allocated, or is it being overwritten or truncated? How can I verify stack integrity? - Are there known issues with the STM32F4 BSP or
linkcmds.armv7m
that could cause this behavior?
Any insights or suggestions on debugging this issue and ensuring proper stack allocation would be greatly appreciated!
UPD:
The arm-rtems7-size command in Berkeley format (text, data, bss) incorrectly aggregates all NOBITS sections in RAM_INT (.bss, .rtemsstack, .noinit, .work) into the reported .bss size. The .work section, which reserves nearly all remaining RAM_INT space (e.g., 5105472 bytes for 5000K), dominates this aggregated size.
arm-rtems7-size --format=SysV app.elf
app.elf :
section size addr
.start 784 134217728
.xbarrier 0 536870912
.text 39756 134218560
.init 12 134258316
.fini 12 134258328
.robarrier 0 134258340
.rodata 7088 134258344
.ARM.exidx 8 134265432
.eh_frame 4 134265440
.tbss 24 134265444
.init_array 4 134265444
.fini_array 4 134265448
.rtemsroset 112 134265452
.rwbarrier 0 536870912
.vector 524 536870912
.data 848 536871440
.bss 5408 536872288
.rtemsstack 4096 536877696
.noinit 3648 536881792
.work 5105472 536885440
.stack 0 541990912
.nocachenoload 0 541990912
.comment 108 0
.debug_aranges 11120 0
.debug_info 942888 0
.debug_abbrev 136143 0
.debug_line 264976 0
.debug_frame 21932 0
.debug_str 84276 0
.debug_line_str 442 0
.debug_loclists 172861 0
.debug_rnglists 22774 0
.ARM.attributes 48 0
.debug_gdb_scripts 135 0
Total 6825507