Skip to content

Allow user-provided llvm_args to override target spec arguments#156554

Open
guybedford wants to merge 1 commit into
rust-lang:mainfrom
guybedford:wasm-use-legacy-eh
Open

Allow user-provided llvm_args to override target spec arguments#156554
guybedford wants to merge 1 commit into
rust-lang:mainfrom
guybedford:wasm-use-legacy-eh

Conversation

@guybedford
Copy link
Copy Markdown

@guybedford guybedford commented May 13, 2026

This switches the order in which -Cllvm-args is applied between target-spec arguments and user-provided LLVM arguments.

This came up in #156061, where the target passing -Cllvm-args=-wasm-use-legacy-eh=false means that a user passing -Cllvm-args=-wasm-use-legacy-eh=true cannot override this value since the LLVM arguments support the last argument overriding the previous, and user arguments were chained first.

With this change, it is possible for Wasm targets to opt into legacy EH for compatibility with runtimes that don't yet implement the modern exnref/try_table instructions, such as Node.js 20 on V8 11.3 and older browsers. While Node.js 20 is formally EOL, many libraries will still need to support this version for a few months yet, so this would ease the transition path to modern exception handling having an opt-out.

Originally this PR added support for a dedicated -Z flag for switching to legacy exception handling, but fine-grained control over the arguments would be a preferable solution provided it does not conflict with other behaviours.

//cc @alexcrichton

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 13, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 13, 2026

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 16 candidates

@alexcrichton
Copy link
Copy Markdown
Member

Oh dear, sorry for the breakage! I mistakenly assumed everything would support the modern instructions, and then I additionally mistakenly assumed that passing -Cllvm-arg=... would override the target-specific default.

Some thoughts on this for me:

  • I'm a bit loathe to add a -Z flag for this, especially when there's a few others similar to wasm/emscripten for exception-stuff, so I'd like to ideally solve the problem at hand without adding a flag there.
  • One option is to switch back the defaults for the wasm32-unknown-unknown target. I'd still like to keep WASI targets as using the standard exceptions proposal in this case.
  • Another option would be to go ahead and swap the order of adding llvm_args from the target spec. Looking through the history it dates to Allow specifying LLVM args in target specifications #68059 with a follow-up in Actually pass target LLVM args to LLVM #68328 and hasn't seen changes since. Given that I'd be relatively confident saying that the current order isn't intentional and swapping them (target-spec args first, then user-supplied args) would make sense. Very few built-in targets use llvm_args in their target specification, so I think the risk of breakage is pretty low.

Personally I feel like leaning toward the last of these options, swapping the order to allow users to pass -Cllvm-arg=... to override the default. If you're ok with that I'll drop a message on Zulip to see if anyone else recoils at the thought of doing so, and that to me feels like the best solution here

This ensures that user arguments can override target arguments without being silently ignored.
@guybedford guybedford force-pushed the wasm-use-legacy-eh branch from a07f363 to 45adab8 Compare May 13, 2026 19:16
@guybedford guybedford changed the title Add -Zwasm-use-legacy-eh to opt into legacy wasm exception handling Allow user-provided llvm_args to override target spec arguments May 13, 2026
@guybedford
Copy link
Copy Markdown
Author

Was really glad to see the modern exception handling land actually - if the ordering is not a concern that is definitely much simpler. I've gone ahead and pushed that change instead without the extra -Z flag, updating the description now.

@alexcrichton
Copy link
Copy Markdown
Member

I've posted on Zulip at #t-compiler > Order of `-Cllvm-arg` and target spec's `llvm_args` and if there's no concerns I'll approve this in a day or so

@JohnTitor
Copy link
Copy Markdown
Member

r? alexcrichton

@rustbot rustbot assigned alexcrichton and unassigned JohnTitor May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants