You copied the Doc URL to your clipboard.

Arm Compiler Arm C and C++ Libraries and Floating-Point Support User Guide : C++ initialization, construction and destruction

C++ initialization, construction and destruction

The C++ standard places certain requirements on the construction and destruction of objects with static storage duration. The static constructors are executed before main(), the destructors are called after the program exits.

The library must ensure that all the static constructors within a translation unit are called in the order of declaration, and the static destructors are called in reverse order of declaration. There is no way to determine the initialization order between translation units.

Each translation unit containing static constructors has an initialization function. This function calls the static constructors for the translation unit, and registers the static destructors with a call to __aeabi_atexit(). Function-local static objects with destructors also register their destructors using __aeabi_atexit().

The location of the per translation unit initialization function is stored in an .init_array section. At link time the .init_array sections must be collated together into a single contiguous .init_array section. The linker will generate an error if this is not possible.

The library routine __cpp_initialize_aeabi_ is called from the C library startup code __rt_lib_init(), before main(). __cpp_initialize_aeabi_ walks through the .init_array, calling each function in turn.

On exit __rt_lib_shutdown() calls cxa_finalize() which calls the static destructors registered with __aeabi_atexit().


The __aeabi_atexit() function calls malloc().