3 ms·
-fwhole-program is a compile-time optimization, not link-time. You shouldn't link anything to a translation unit compiled with -fwhole-program, as the whole poi
by leni536 3y ago
-fwhole-program is a compile-time optimization, not link-time. You shouldn't link anything to a translation unit compiled with -fwhole-program, as the whole point of it is to compile the whole application in a single translation unit and tell the compiler to optimize accordingly.
It can also eliminate unused data and functions, as it basically treats most entites as internal linkage, and that's one of the optimisations applied there. The mechanism is rather different to GCing sections at link time though. I assume LTO has something similar.
It's useful to combine it with unity builds. It's poor man's LTO in a way.
- mgaunard 3y agowhole-program only makes sense when you're building and linking at the same time, so it is typically used together with LTO. But you're right, it's also possible to use it for single-translation-unit build-and-link.