The BSS section is a part of the memory where uninitialized global and static variables are stored. During the program's initialization, the BSS section is set to zero. However, it is up to the program to ensure that the BSS section is initialized correctly.
In the linker script file, the BSS section is typically defined using a statement like this:
.bss :
{
__bss_start__ = .;
*(.bss)
*(COMMON)
__bss_end__ = .;
} > RAM
This statement defines the BSS section and places it in the RAM memory region. The *(.bss) directive tells the linker to include all sections with the .bss name in the BSS section. The *(COMMON) directive tells the linker to include any common symbols in the BSS section.
To initialize the BSS section to zero, the program's startup code should set all BSS section memory locations to zero before the program starts executing. This can be achieved by adding code to the startup routine to loop through the BSS section and set each memory location to zero.
If your BSS section is not being initialized to zero, it may be because the startup code is not properly initializing the BSS section. You should check the startup code to ensure that it correctly initializes the BSS section. You may also want to check the linker script to ensure that the BSS section is defined correctly and placed in the correct memory region.
In addition to the above, you should also ensure that your program does not accidentally write to the BSS section before it has been initialized. This can cause unpredictable behavior and should be avoided.
You can also visit : AWS Developer Course