Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc crtbegin crtend

Tags:

gcc

For what purpose does gcc use crtbegin.o and crtend.o ?

like image 561
Walidix Avatar asked Jun 15 '10 17:06

Walidix


2 Answers

Those files contain the code to handle C++ global constructors and destructors.

like image 144
James Avatar answered Sep 28 '22 10:09

James


You need check the 'nm' output of the crtbegin, crtend and other crtxxx files to understand it properly.

These files contains code for constructors(initialization routines) and destructors(termination routines). These constructors and destructors are not be confused with C++ global Constructors/Destructors. These routines are called before the actual start("main") of the program.

The linker builds 2 list of functions CTOR_LIST(startup-time routines) and DTOR_LIST(exit-time routines) to be executed.

Refer: https://gcc.gnu.org/onlinedocs/gccint/Initialization.html

like image 32
reemuskumar Avatar answered Sep 28 '22 11:09

reemuskumar