From bee97d40f3a983cbd2990a7a8c62633bb03f5e53 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Thu, 23 Jul 2026 09:08:33 -0700 Subject: [PATCH] Simplify LTO flag passing in `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`. --- tools/compile.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/tools/compile.py b/tools/compile.py index 9a7bcba68b689..01bc6c83b13f3 100644 --- a/tools/compile.py +++ b/tools/compile.py @@ -61,21 +61,8 @@ def get_clang_flags(user_args): # to be exported to other DSO's by default. flags.append('-fvisibility=default') - if settings.LTO: - if not any(a.startswith('-flto') for a in user_args): - flags.append('-flto=' + settings.LTO) - # setjmp/longjmp handling using Wasm EH - # For non-LTO, '-mllvm -wasm-enable-eh' added in - # building.llvm_backend_args() sets this feature in clang. But in LTO, the - # argument is added to wasm-ld instead, so clang needs to know that EH is - # enabled so that it can be added to the attributes in LLVM IR. - if settings.SUPPORT_LONGJMP == 'wasm': - flags.append('-mexception-handling') - - else: - # In LTO mode these args get passed instead at link time when the backend runs. - for a in building.llvm_backend_args(): - flags += ['-mllvm', a] + for a in building.llvm_backend_args(): + flags += ['-mllvm', a] return flags