.bss section cosumes large memory space in template design

I’m using the default template design RISC-V_Renode_Emulator_SoftConsole of FreeRTOS to build with default FreeRTOSConfig.h constants. Here The .bss section consumes 28KBytes of memory. Why is it so?

You can check the map file generated by linker to see what’s inside the bss.
The linker has on option (e.g. -map for GNU linker) to generate it along with the elf file.

If you are using heap_1, heap_2, heap_4 or heap_5 then the heap memory comes from a statically allocated array - so you are probably seeing all the unused heap.

@Hartmut Schaefer thanks for your reply.
I have checked my application map file. I’m using heap_4.c memory management portable layer. Does the uninitialized heap memory size count on .bss section?
Please see my map file for .bss section.

.bss 0x0000000080004f00 0x46130
0x0000000080004f00 __bss_start = .
(.shbss)
(.bss .bss. .gnu.linkonce.b.
)
.bss.ucHeap 0x0000000080004f00 0x46000 ./FreeRTOS_Source/portable/MemMang/heap_4.o
.bss.pxReadyTasksLists
0x000000008004af00 0x64 ./FreeRTOS_Source/tasks.o
.bss.xDelayedTaskList1
0x000000008004af64 0x14 ./FreeRTOS_Source/tasks.o
.bss.xDelayedTaskList2
0x000000008004af78 0x14 ./FreeRTOS_Source/tasks.o
.bss.xPendingReadyList
0x000000008004af8c 0x14 ./FreeRTOS_Source/tasks.o
.bss.xTasksWaitingTermination
0x000000008004afa0 0x14 ./FreeRTOS_Source/tasks.o
.bss.xSuspendedTaskList
0x000000008004afb4 0x14 ./FreeRTOS_Source/tasks.o
.bss.xActiveTimerList1
0x000000008004afc8 0x14 ./FreeRTOS_Source/timers.o
.bss.xActiveTimerList2
0x000000008004afdc 0x14 ./FreeRTOS_Source/timers.o
*(COMMON)
COMMON 0x000000008004aff0 0x40 ./FreeRTOS_Source/queue.o
0x000000008004aff0 xQueueRegistry
0x000000008004b030 . = ALIGN (0x10)
0x000000008004b030 __bss_end = .
0x000000008004b030 _end = .

.heap 0x000000008004b030 0x10
0x000000008004b030 __heap_start = .
0x000000008004b034 . = (. + HEAP_SIZE)
fill 0x000000008004b030 0x4
0x000000008004b034 __heap_end = .
0x000000008004b040 . = ALIGN (0x10)
fill 0x000000008004b034 0xc
0x000000008004b034 _heap_end = __heap_end

.stack 0x000000008004b040 0x800
0x000000008004b040 __stack_bottom = .
0x000000008004b840 . = (. + STACK_SIZE)
fill 0x000000008004b040 0x800
0x000000008004b840 __stack_top = .
0x000000008004b840 _sp = .
0x000000008004b840 __freertos_irq_stack_top = .
OUTPUT(RTOSDemo.elf elf32-littleriscv)

How can reduce .bss section in my design?

That’s the FreeRTOS heap. Therefore bss has its size.
However, bss shouldn’t matter. It’s uninitialized data just zeroed during init of the C-runtime environment. Why do you care ?

Or, if the problem is you are out of memory, make the heap smaller.

As explained by @hs2, it is the FreeRTOS heap which is consuming most of bss. Since you are using heap_4, you can control its size using configTOTAL_HEAP_SIZE in your FreeRTOSConfig.h: FreeRTOS-Kernel/heap_4.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub

You can try to reduce the heap by reducing the value of configTOTAL_HEAP_SIZE.

Thanks.

@Hartmut Schaefer .bss section goes to RAM and this much memory is not available in the target hardware. so that I’m not able to accommodate my code in the target platform. That’s why I’m concern about .bss section.

As I said, make the heap smaller, if you don’t have that much RAM, hopefully your program can live with a smaller heap, or it might not be able to run on this platform.