I was analyzing C++ constructor/destructor calling code, what I came to know is before main() begins, libc (or glibc) code calls constructors and registers destructors, I see the following stack trace
A::A() at clA.cc:3 0x5555555549a6
__static_initialization_and_destruction_0() at main.cc:4 0x55555555493b
_GLOBAL__sub_I_a() at main.cc:10 0x555555554997
__libc_csu_init() at 0x555555554c1d
__libc_start_main() at libc-start.c:266 0x7ffff7464b28
_start() at 0x5555555547ba
Now I understand that __libc_start_main
comes from libc, which calls the statically linked __libc_csu_init
(reason I don't see it's source) but I found it in glibc/glibc-2.27/csu/elf-init.c but I am unable to find the source of _GLOBAL__sub_I_a()
and __static_initialization_and_destruction_O()
from which library these functions come and get statically linked with our executable, I know these are statically linked but want to see the source to understand them, on what goes behind the scene.
Thanks, Fahad