I wrote a simple C program (test.c) below: -
#include<stdio.h> int main() { return 0; }
and performed the following procedure to understand resizing in the .bss segment.
gcc test.c -o test size test
The output came out as: -
text data bss dec hex filename 1115 552 8 1675 68b test
I did not declare anything globally or static. Therefore, please explain why the bss segment size is 8 bytes.
I made the following change: -
#include<stdio.h> int x; //declared global variable int main() { return 0; }
But, to my surprise, the result was the same as the previous one: -
text data bss dec hex filename 1115 552 8 1675 68b test
Please explain. Then I initialized global: -
#include<stdio.h> int x=67; //initialized global variable int main() { return 0; }
The data segment size increased as expected, but I did not expect the bss segment size to decrease to 4 (as opposed to 8 when nothing was announced). Please explain.
text data bss dec hex filename 1115 556 4 1675 68b test
I also tried the objdump and nm commands, but they also showed the x variable occupying .bss (in the second case). However, no changes to the bss size are displayed in the size command.
I followed the procedure as per: http://codingfox.com/10-7-memory-segments-code-data-bss/ where the outputs are going fine as expected.