how to find code-functions that is called before c++ main? I am trying to locate which functions are called in order to initialize static variables by functions and thus executed before main.
In GCCs case you have:
__CTOR_LIST__ (list of initialization functions called - pointers)
__DTOR_LIST__ (list of functions called for cleanup)
They are automatically generated by the compiler for each translation unit (C/C++ file).
You can find more information about this here. For other compilers this must be similar but you can "guess" it by using utilities like objdump or nm (for your compiler suite, of course).
We called those pointer functions ( void (*func)(void) ) manually on a custom embedded platform on which we used g++.
I saw that you are interested in finding the static/global variables.
For this task you can really use some tools like objdump and nm (previously mentioned). First create 2-3 test files (and compile them to obtain the .o/.obj) and see how the static/global variables are seen by those tools (in the .obj/.o files. Once you see that, you can go through all the .obj/.o files with a script and make a list of the static/global variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With