Exploring Linux command-line space time
Wow, Collect2 sounds kinda hacky based on the linked documentation¹:<p>- 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.<p>- Therefore Collect2 pretends to be ld; when invoked, it tries to call the real ld and examines its output<p>- It creates a c file with a table containing any constructor symbols it finds, then compiles that<p>- Finally it links the program again, together with the new object file<p>¹: <a href="https://gcc.gnu.org/onlinedocs/gccint/Collect2.html" rel="nofollow noreferrer">https://gcc.gnu.org/onlinedocs/gccint/Collect2.html</a>