Aside from using -nostdlib and linking crt1.o -lc -lgcc yourself, is there any easy way to prevent gcc from linking crtbegin[S].o and crtend[S].o? These files are not that large, but I’m playing around with making small binaries, and would like to remove the useless C++ support code that’s not needed for C programs. (Presumably, gcc links them even for C programs in case you’re using a C++ library with global object variables. I’ll spare everyone the rant about how it should be generating safe one-time initialization calls everywhere the global object is referenced in C++ modules rather than initializing global objects prior to main…)
I wouldn’t be opposed to hacking the gcc specs file to make linking of the C++ support files conditional on such-and-such, but I’m not sure how I would do that. Perhaps there’s already a nice way?
1 Answer