Consider the following program:
#include <stdio.h>
int main(void)
{
return 0;
}
When i run the following commands:
gcc memory-layout.c -o memory-layout size memory-layout
I get the output as:
text data bss dec hex filename 960 248 8 1216 4c0 memory-layout
As text area contains the executable instructions of a program, why the output is showing size of text area as 960, which is too big with respect to the size of the instructions, as far as I can count.
The reason is probably because the actual start of a program isn't really the main
function, but a piece of code added in the linking stage. This code setup the libraries, clears the BSS
segment, and other initialization before calling your main
function. There is also code to make sure that everything is cleaned up properly when you return from main
.