Meaning
Uninitialized global and static variables in a compiled program occupy a specific region of memory that is cleared before the application starts. The static memory bss represents a portion of the data image that does not take up space in the non-volatile flash but requires room in the ram at runtime. Monitoring this region is essential for understanding the total memory footprint of the software.
Runtime Initialization
Zeroing out the memory at startup ensures that variables start with a known state before the main code begins to execute. The static memory bss is typically handled by the startup script provided by the compiler, which clears the entire region in a single loop. This step is necessary to prevent the application from reading random data that might be left over from a previous power cycle.
Memory Footprint
Calculating the total size of all global variables allows developers to determine if the software will fit on the target hardware. The static memory bss size is a fixed value that is determined at compile time and does not change during the execution of the program. Knowing this value helps in selecting the correct microcontroller and ensures that there is enough ram left for the stack and the heap.
Binary Image
Excluding uninitialized data from the executable file reduces the size of the firmware that must be stored in the flash memory. While the static memory bss does not add to the download time or the storage requirements, it still occupies space in the memory map of the processor. This distinction allows for a more efficient use of the limited non-volatile storage available in embedded devices.
Engineers use the linker map file to analyze the size of the bss and identify any large arrays or buffers that could be optimized to save space. By moving large data structures into the bss instead of initializing them with zeros in the code, the developer can keep the firmware image as small as possible while still having access to the required memory at runtime.