I need to do analysis of memory requirements of one library written in C++, because HW engineers need get some idea about memory requirements of our hardware, there are working on. I can measure heapsize peak, I can measure stack size, but I don't know how to estimate/measure data segment size and Bss size. Is there any method in Visual Studio or GCC? I assume it will differs from compiler to compiler and from platform to platform, but an estimation is fine for me.
3 Answers
There is a size utility.
E.g. for ARM MCU project it can be something like:
arm-none-eabi-size --format=sysv "program_name.elf"
Example output:
program_name.elf :
section size addr
.text 14516 0
.data 160 268435456
.bss 1328 268435616
.stack 2528 268436944
.debug_aranges 2384 0
.debug_info 40951 0
.debug_abbrev 8870 0
.debug_line 27790 0
.debug_frame 6664 0
.debug_str 42157 0
.debug_loc 7074 0
.debug_macinfo 426030 0
.ARM.attributes 47 0
.debug_ranges 1760 0
.comment 96 0
.debug_macro 9236 0
Total 591591
Comments
During the build:
For VC++ run
link.exe /map.For GCC run
ld -Map.
Both options generate a map file which will contain the segment sizes.
Comments
You can use objdump to get the size of the text, data and bss segments on Linux systems. You can examine the output for the .bss and .text sections.
See here for a more detailed explanation.
sizefor this.