Skip to content

Simplify LTO flag passing in get_clang_flags#27407

Open
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:simplify_lto_passing
Open

Simplify LTO flag passing in get_clang_flags#27407
sbc100 wants to merge 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.

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.

2 participants