2

I saw this in some website and was surprised with the result:

#include <stdio.h>

int main(void)
{
    return 0;
}

When the above code is checked for memory in each sections using size

$ gcc memory-layout.c -o memory-layout
$ size memory-layout
text       data        bss        dec        hex    filename
960        248          8       1216        4c0    memory-layout

Here, without any global or static variables, the size of bss is shown 8. I didn't get for what this 8 bytes are used?

Mbeginner
  • 41
  • 4

1 Answers1

1

You are looking at the segment sizes for the full executable program: the object module for your source code is linked to the standard library startup code and the necessary library support functions, such as exit. The numbers you see for data and bss are probably due to global objects defined by these modules. Note in particular that your main function hardly justifies 960 bytes of code.

Generate just an object file and run size on that:

$ gcc -c memory-layout.c
$ size memory-layout.o
chqrlie
  • 131,814
  • 10
  • 121
  • 189