3 ms·
Is there any difference between "-ffunction-sections -fdata-sections -Wl,--gc-sections" and gcc's -fwhole-program?
by stabbles 3y ago
Is there any difference between "-ffunction-sections -fdata-sections -Wl,--gc-sections" and gcc's -fwhole-program?
- mgaunard 3y agoYes, they do completely different things. The first affects the layout of object files. The second affects the optimizations done when linking.
- 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.