Repository navigation
Reduce binary size by removing unused functions even when not using LTO (~200-900kb reduction) - #2068
Merged
Conversation
akien-mga
approved these changes
Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It appears that without LTO, we were only passing the flags for the compiler to remove unused compilation units, not unused functions.
This PR attempts to add those flags for both GCC and Clang (I tried a bunch of stuff with MSVC, but wasn't able to find anything that reduced size at all):
debug_symbols=yes)Re Windows: It seems MingGW can't fully do this optimization without LTO, which is why (a) the change is so small and (b) it doesn't add the
-ffunction-sections -fdata-sectionsflags because that actually makes the size bigger, not smallerRe macOS: We were already using
-Wl,-dead_stripwithdebug_symbols=no, so this only adds it in thedebug_symbols=yescaseWith these changes, the effect of using either LTO or
build_profileis much smaller, which is nice, because LTO is slow and usingbuild_profilerequires extra work