This may be an older query but I could not find any satisfactory answer so far.
To check the memory map of a file I wrote a small hello program.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("Hello\n");
return 0;
}
Now after compilation, when I use command size on its object file I get:
# size hello
text data bss dec hex filename
1133 492 16 1641 669 hello
I checked the size for other files too. I always get bss as 16. Is bss fixed? Is this included in data or it is out of it. I mean is this 16 is included in 492 or not. As far as I understand, bss is uninitialized data segment.
The size of the BSS section varies between programs. It describes the amount of data that is initialized with ‘all bytes zero’. The zeroes are not actually stored in the object file, but the size of the BSS section is stored.
The data section contains the initial values of all data structures that are not initialized to ‘all bytes zero’; it too varies between programs. It does not include the space included in the BSS section.
You’d get a bigger BSS section with a program like this:
The code shuffles the numbers from 0 to 99, with some bias in the random number generation (so it isn’t a perfect shuffle, but that really isn’t the point of the exercise — it is just non-trivial code that uses a static array, even though a local variable would be sufficient). When I run
size(on Ubuntu 13.10), I get:For comparison, on the ‘hello’ program in the question, I get:
The main difference is that the array
aoccupies 400 bytes; the other 24 bytes of BSS belong to other code.