Simplify LTO flag passing in get_clang_flags - #27407
Merged
Merged
Conversation
Previously, `get_clang_flags` in `tools/compile.py` handled LTO and non-LTO modes separately: - In non-LTO mode, `building.llvm_backend_args()` was passed to `clang` via `-mllvm`. - In LTO mode (`settings.LTO`), `building.llvm_backend_args()` was not passed to `clang` (as backend flags are passed to `wasm-ld` at link time). Instead, `-mexception-handling` was explicitly appended when `settings.SUPPORT_LONGJMP == 'wasm'` so that `clang` added `target-features=+exception-handling` to LLVM IR attributes. Also, if `-flto` was not in `user_args`, `-flto=` was appended. This change simplifies `get_clang_flags` by unconditionally passing `building.llvm_backend_args()` to `clang` via `-mllvm` in both LTO and non-LTO modes. Because `building.llvm_backend_args()` includes `-wasm-enable-sjlj` when `settings.SUPPORT_LONGJMP == 'wasm'`, the `clang` driver automatically adds `target-features=+exception-handling` to LLVM IR, removing the need for the special `-mexception-handling` case. It also removes the fallback `-flto=` injection from `get_clang_flags`.
sbc100
commented
Jul 23, 2026
| flags.append('-fvisibility=default') | ||
|
|
||
| if settings.LTO: | ||
| if not any(a.startswith('-flto') for a in user_args): |
Collaborator
Author
There was a problem hiding this comment.
I think this probably dates back to when users could do -sLTO maybe, so the setting might be enabled without -flto being on the command line.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Jul 28, 2026
Followup to emscripten-core#27407 Because `settings.LTO` was an internal setting not used anywhere in JavaScript libraries or runtime code. This change removes `LTO` from `src/settings_internal.js` and stores `-flto` / `-fno-lto` state in `options.lto` on `EmccOptions` instead.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Jul 28, 2026
Followup to emscripten-core#27407 Because `settings.LTO` was an internal setting not used anywhere in JavaScript libraries or runtime code. This change removes `LTO` from `src/settings_internal.js` and stores `-flto` / `-fno-lto` state in `options.lto` on `EmccOptions` instead.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Jul 30, 2026
Followup to emscripten-core#27407 Because `settings.LTO` was an internal setting not used anywhere in JavaScript libraries or runtime code. This change removes `LTO` from `src/settings_internal.js` and stores `-flto` / `-fno-lto` state in `options.lto` on `EmccOptions` instead.
sbc100
added a commit
that referenced
this pull request
Jul 30, 2026
Followup to #27407 Because `settings.LTO` was an internal setting not used anywhere in JavaScript libraries or runtime code. This change removes `LTO` from `src/settings_internal.js` and stores `-flto` / `-fno-lto` state in `options.lto` on `EmccOptions` instead. In the long run I hope to use internal settings only for values that need to flow out the the JS compiler.
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.
Previously,
get_clang_flagsintools/compile.pyhandled LTO and non-LTO modes separately:building.llvm_backend_args()was passed toclangvia-mllvm.settings.LTO),building.llvm_backend_args()was not passed toclang(as backend flags are passed towasm-ldat link time). Instead,-mexception-handlingwas explicitly appended whensettings.SUPPORT_LONGJMP == 'wasm'so thatclangaddedtarget-features=+exception-handlingto LLVM IR attributes. Also, if-fltowas not inuser_args,-flto=was appended.This change simplifies
get_clang_flagsby unconditionally passingbuilding.llvm_backend_args()toclangvia-mllvmin both LTO and non-LTO modes. Becausebuilding.llvm_backend_args()includes-wasm-enable-sjljwhensettings.SUPPORT_LONGJMP == 'wasm', theclangdriver automatically addstarget-features=+exception-handlingto LLVM IR, removing the need for the special-mexception-handlingcase. It also removes the fallback-flto=injection fromget_clang_flags.