Skip to content

Simplify LTO flag passing in get_clang_flags - #27407

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:simplify_lto_passing
Jul 23, 2026
Merged

Simplify LTO flag passing in get_clang_flags#27407
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:simplify_lto_passing

Conversation

@sbc100

@sbc100 sbc100 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

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.

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
sbc100 requested a review from dschuff July 23, 2026 16:24
Comment thread tools/compile.py
flags.append('-fvisibility=default')

if settings.LTO:
if not any(a.startswith('-flto') for a in user_args):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dschuff dschuff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This... looks right? I suspect only @aheejin really understands the EH flags though.

@aheejin aheejin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This... looks right? I suspect only @aheejin really understands the EH flags though.

I think @aheejin-circa-2021 would have known that but @aheejin-now doesn't remember much... But it looks right to me too

@sbc100
sbc100 merged commit 466e11d into emscripten-core:main Jul 23, 2026
40 checks passed
@sbc100
sbc100 deleted the simplify_lto_passing branch July 23, 2026 21:12
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants