Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What data do BSS and data segment have by default?

Tags:

c

linux

unix

I developed a simple C program as shown below..

int main()
{
    return 0;
}

I compiled the program using gcc v5.2.1. When I ran the Unix command 'size' on the executable below are the sizes it displayed..

text = 1131, data = 552, bss = 8

As per my understanding the data section hold initialized global data and BSS holds uninitialized global data. Though there are no global variables why do the 'data' and 'BSS' section show non-zero values?

like image 840
Parth Shah Avatar asked May 28 '26 08:05

Parth Shah


1 Answers

In a nutshell: Because your final program has more code than just the part you write. It must contain some runtime that e.g. does all the setup required before it can call main() (like populating argv, initializing data in .bss to zero, and so on) as well as cleanup after exit. What exactly is done in this code depends entirely on your implementation.