Exploring Linux command-line space time
Wow, Collect2 sounds kinda hacky based on the linked documentation¹:- There is user code that needs to run before main. With C/C++ allowing separate compilation, the compiler invocation that creates the entrypoint doesn't know about all of these static constructors.- Therefore Collect2 pretends to be ld; when invoked, it tries to call the real ld and examines its output- It creates a c file with a table containing any constructor symbols it finds, then compiles that- Finally it links the program again, together with the new object file¹: https://gcc.gnu.org/onlinedocs/gccint/Collect2.html