3 ms·
> The flip side of this technique is to be careful about blowing up the size of the final executable since everything gets included. Yeah, the 1970s linker mod
by psykotic 6y ago
> The flip side of this technique is to be careful about blowing up the size of the final executable since everything gets included.
Yeah, the 1970s linker model is very silly like this. The good news is that link-time optimization will handle this for you nowadays without any special per-symbol mark-up. As an experiment, put an unused 'deadfunc' function definition in a file called ltotest.c and then compare
gcc -O2 ltotest.c -o ltotest && (objdump -D ltotest | grep deadfunc)
and
gcc -O2 -flto ltotest.c -o ltotest && (objdump -D ltotest | grep deadfunc)
- rramadass 6y agohttps://tetzank.github.io/posts/removing-unused-code/ https://tetzank.github.io/posts/removing-unused-code/
- psykotic 6y agoNeat, I didn't know about -fwhole-program as an alternative to -flto for single-file builds. It should help with compile times a little bit (though I normally only use LTO for release builds, rarely during development, so it's not a big deal either way). With MSVC I think you still have to use LTO (or LTCG as it's called there) to get this effect.