Skip to content

fix(sdk): preserve intrinsic stubs under LTO#1107

Merged
bitwalker merged 1 commit intonextfrom
i1089-lto-unreach-stubs
May 5, 2026
Merged

fix(sdk): preserve intrinsic stubs under LTO#1107
bitwalker merged 1 commit intonextfrom
i1089-lto-unreach-stubs

Conversation

@greenhat
Copy link
Copy Markdown
Contributor

@greenhat greenhat commented May 4, 2026

Close #1089

LTO can see through the Rust unreachable stubs used to carry Miden intrinsic signatures and rewrite callers as if those stubs were the real implementations. That breaks frontend lowering because the final wasm no longer reliably preserves the call ABI the linker-stub recognizer expects.

Mark SDK intrinsic declarations as weak externs, keep stub bodies uninlined and unoptimized, and force the tiny stub archives into linked wasm with whole-archive. This keeps the stubs available for signature recognition without letting LTO propagate their unreachable bodies into callers.

MAST Sizes

Values are from tests/integration/src/rust_masm_tests/examples.rs.

Package next current Delta Reduction
examples/basic-wallet 35,906 18,893 -17,013 47.38%
examples/basic-wallet-tx-script 56,437 17,475 -38,962 69.04%
examples/p2id-note 53,082 21,396 -31,686 59.69%
examples/p2ide-note 62,672 24,878 -37,794 60.30%
Total 208,097 82,642 -125,455 60.29%

Mockchain Cycle Counts

Values are from the tests/integration-network/src/mockchain expectations.

Test measurement next current Delta Reduction
basic_wallet::test_basic_wallet_p2id mint note cycles 20,072 7,275 -12,797 63.76%
basic_wallet::test_basic_wallet_p2id tx script processing cycles 26,217 6,723 -19,494 74.36%
basic_wallet::test_basic_wallet_p2id Bob note cycles 20,072 7,275 -12,797 63.76%
basic_wallet::test_basic_wallet_p2ide Bob note cycles 21,211 7,721 -13,490 63.60%
basic_wallet::test_basic_wallet_p2ide_reclaim reclaim note cycles 22,871 8,280 -14,591 63.80%
counter_contract::test_counter_contract note cycles 49,505 10,474 -39,031 78.84%
counter_contract_no_auth::test_counter_contract_no_auth auth procedure cycles 1,803 1,778 -25 1.39%
counter_contract_no_auth::test_counter_contract_no_auth note cycles 49,505 10,474 -39,031 78.84%
counter_contract_rust_auth::test_counter_contract_rust_auth_blocks_unauthorized_note_creation auth procedure cycles 86,895 74,561 -12,334 14.19%

@greenhat greenhat force-pushed the i1089-lto-unreach-stubs branch from 9533fd7 to ba5a819 Compare May 4, 2026 10:58
@greenhat greenhat mentioned this pull request May 4, 2026
@greenhat greenhat requested a review from bitwalker May 4, 2026 11:39
@bitwalker
Copy link
Copy Markdown
Collaborator

@greenhat If you rebase this on next, I'll get it merged today

@greenhat greenhat force-pushed the i1089-lto-unreach-stubs branch from ba5a819 to 915000a Compare May 5, 2026 07:22
LTO can see through the Rust unreachable stubs used to carry Miden intrinsic signatures and rewrite callers as if those stubs were the real implementations. That breaks frontend lowering because the final wasm no longer reliably preserves the call ABI the linker-stub recognizer expects.

Mark SDK intrinsic declarations as weak externs, keep stub bodies uninlined and unoptimized, and force the tiny stub archives into linked wasm with whole-archive. This keeps the stubs available for signature recognition without letting LTO propagate their unreachable bodies into callers.
@greenhat greenhat force-pushed the i1089-lto-unreach-stubs branch from 915000a to 9b7579d Compare May 5, 2026 07:30
@greenhat
Copy link
Copy Markdown
Contributor Author

greenhat commented May 5, 2026

@greenhat If you rebase this on next, I'll get it merged today

Rebased.

@bitwalker bitwalker merged commit 6a4265e into next May 5, 2026
15 checks passed
@bitwalker bitwalker deleted the i1089-lto-unreach-stubs branch May 5, 2026 13:04
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.

Fix the generated code when lto=true

2 participants