I decided to compile a very basic C program and take a look at the generated code with objdump -d
.
int main(int argc, char *argv[]) {
exit(0
C program does a lots of stuff before calling the main
function. It has to initialize .data and .bss segments, set the stack, go through the constructors and destructors (yes gcc in C has a special attributes for such a functions) and initializes the library.
gcc destructor and constructor functions:
void __attribute__ ((constructor)) funcname(void);
void __attribute__ ((destructor)) funcname(void);
you may have as many constructors and destructors as you wish.
constructors are called before call to the main
function, destructors on exit from the program (after the main
termination)
https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html#Function-Attributes