Skip to content

bazel: re-land wasmtime 42 upgrade with LTO fix#30390

Merged
travisdowns merged 2 commits intoredpanda-data:devfrom
travisdowns:td-fix-wasmtime42-lto
May 7, 2026
Merged

bazel: re-land wasmtime 42 upgrade with LTO fix#30390
travisdowns merged 2 commits intoredpanda-data:devfrom
travisdowns:td-fix-wasmtime42-lto

Conversation

@travisdowns
Copy link
Copy Markdown
Member

Re-lands the wasmtime 32 → 42 upgrade (#30263), which was reverted in
#30387 because it broke --config=lto / --config=pgo-instrument
builds with:

ld.lld: error: undefined symbol: __rustc::__rust_no_alloc_shim_is_unstable_v2

Two commits:

  1. bazel: switch rust LTO from fat to thin — fixes the link failure.
    The empty allocator_library staticlib used by rules_rust's
    experimental_use_allocator_libraries_with_mangled_symbols exists
    only so rustc auto-injects the __rustc::__rust_* allocator shim
    symbols with GLOBAL binding, satisfying the rust stdlib's GLOBAL
    undefined refs to those symbols. With -Clto=fat, rustc runs LLVM's
    Internalize pass over the staticlib before emitting it; nothing
    inside the empty crate references those shims, so they get
    downgraded GLOBAL → LOCAL. ELF then refuses to bind the stdlib's
    GLOBAL refs to LOCAL defs across object files, and the link fails.
    Thin LTO doesn't run that whole-crate internalization step, so the
    symbols stay GLOBAL and the link succeeds.

    Verified bit-identical (md5sum) //:redpanda output before and
    after this change under --config=pgo-instrument. Every wasmtime
    crate is a rust_library (rlib), and for rlibs rules_rust emits
    -Clinker-plugin-lto regardless of the -Clto mode — so the rlib
    bitcode is the same either way. The actual cross-language LTO
    happens later at the C++ thin-LTO link step.

  2. bazel/wasm: upgrade wasmtime from 32.0.0 to 42.0.2 — identical
    to the original PR bazel/wasm: upgrade wasmtime from 32.0.0 to 42.0.2 #30263 commit (08fc3c5), re-applied on top of
    the LTO fix.

Verified end-to-end with a full bazel build --config=pgo-instrument //:redpanda on this branch.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v25.3.x
  • v25.2.x
  • v25.1.x

Release Notes

  • none

Fixes the `--config=lto` / `--config=pgo-instrument` link, which
started failing with the wasmtime 42 upgrade (rust 1.91) with errors
like:

  ld.lld: error: undefined symbol: __rustc::__rust_no_alloc_shim_is_unstable_v2

The empty `allocator_library` staticlib used by rules_rust's
`experimental_use_allocator_libraries_with_mangled_symbols` exists
only so rustc auto-injects the `__rustc::__rust_*` allocator shims
with GLOBAL binding, satisfying the rust stdlib's GLOBAL undefined
refs to those symbols. Under fat LTO, rustc runs LLVM's Internalize
pass over the staticlib before emitting it; nothing inside the empty
crate references the shims, so they get downgraded GLOBAL -> LOCAL
and ELF then refuses to bind the stdlib's GLOBAL refs to LOCAL defs
across object files. Thin LTO doesn't run that whole-crate
internalization, so the symbols stay GLOBAL and the link succeeds.

No measurable cost: with --config=pgo-instrument the resulting
//:redpanda binary is bit-identical (md5) before and after this
change. Every wasmtime crate is a `rust_library` (rlib), and for
rlibs rules_rust emits `-Clinker-plugin-lto` regardless of the
-Clto mode, so the rlib bitcode is the same either way -- the actual
cross-language LTO happens later at the C++ thin-LTO link step.
Re-land of 08fc3c5, which was reverted
in 6116d3a (PR redpanda-data#30387) because the
upgrade broke the `--config=lto` / `--config=pgo-instrument` link with:

  ld.lld: error: undefined symbol: __rustc::__rust_no_alloc_shim_is_unstable_v2

That LTO failure is fixed by the preceding commit switching the rust
LTO mode from fat to thin; this commit re-introduces the upgrade
unchanged.

Additional changes required by the upgrade:

- Bump Rust toolchain from 1.86.0 to 1.91.0 (wasmtime 42 MSRV)
- Add PULLEY and ALL_ARCH feature flags to wasmtime.BUILD conf.h
  template substitutions (new in wasmtime 42)
- Remove wasmtime_config_async_support_set() call: async support is
  now implicit, the separate toggle was deprecated and removed from
  the C API (bytecodealliance/wasmtime#12371)
- Bump rules_rust 0.60.0 -> 0.70.0 and opt in to
  experimental_use_allocator_libraries_with_mangled_symbols so the
  mangled __rustc::* allocator shim symbols (introduced in rustc
  1.87+) are provided when a Rust staticlib is linked into a
  cc_binary via cc_common.link. Without this flag the link fails
  with undefined references to __rustc::__rust_alloc,
  __rustc::__rust_dealloc, etc. Background:
    - Issue:   bazelbuild/rules_rust#3459
    - Fix PR:  bazelbuild/rules_rust#3403
    - Landed in rules_rust 0.63.0 as an opt-in setting.
- Mirror the rustc tarball through vectorized-public to reduce
  dependence on static.rust-lang.org.
- Incidental: bump bazel_skylib 1.8.1 -> 1.8.2 and rules_shell
  0.4.1 -> 0.6.1 to silence direct-dependency version warnings
  pulled in by the new rules_rust.
Copilot AI review requested due to automatic review settings May 6, 2026 21:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Re-lands the Bazel-based wasmtime upgrade (32.0.0 → 42.0.2) and adjusts the Bazel Rust LTO configuration to avoid allocator shim symbol resolution failures when building with LTO/PGO instrumentation.

Changes:

  • Switch Rust LTO in the lto Bazel config from fat LTO to thin LTO, and enable rules_rust’s mangled allocator shim libraries to satisfy __rustc::* allocator shim references.
  • Upgrade wasmtime (Rust crates + lockfile) to 42.0.2 and update the Rust toolchain version to meet the new MSRV.
  • Update wasmtime C/C++ integration points: drop the removed async-support config call and extend the generated conf.h substitutions for new feature macros.

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/v/wasm/wasmtime.cc Removes the deprecated/removed wasmtime C-API async-support toggle call during engine configuration.
MODULE.bazel Bumps the Rust toolchain version used by Bazel to match the new wasmtime MSRV.
bazel/thirdparty/wasmtime.BUILD Extends conf.h.in template substitutions to handle additional wasmtime feature macros introduced in newer versions.
bazel/thirdparty/Cargo.toml Upgrades wasmtime crate dependencies to 42.0.2.
bazel/thirdparty/Cargo.lock Refreshes the Rust dependency lockfile to match the wasmtime 42.0.2 upgrade.
.bazelrc Enables mangled allocator shim libraries and switches Rust LTO to thin LTO under --config=lto to fix LTO link failures.

@vbotbuildovich
Copy link
Copy Markdown
Collaborator

CI test results

test results on build#84117
test_status test_class test_method test_arguments test_kind job_url passed reason test_history
FLAKY(PASS) ShadowLinkingReplicationTests test_with_restart {"storage_mode": "cloud"} integration https://buildkite.com/redpanda/redpanda/builds/84117#019dff3e-e365-49a5-9f3f-48744a0fbbd0 10/11 Test PASSES after retries.No significant increase in flaky rate(baseline=0.0311, p0=1.0000, reject_threshold=0.0100. adj_baseline=0.1000, p1=0.3487, trust_threshold=0.5000) https://redpanda.metabaseapp.com/dashboard/87-tests?tab=142-dt-individual-test-history&test_class=ShadowLinkingReplicationTests&test_method=test_with_restart
FLAKY(PASS) SIPartitionMovementTest test_cross_shard {"cloud_storage_type": 1, "num_to_upgrade": 0, "with_cloud_topics": false} integration https://buildkite.com/redpanda/redpanda/builds/84117#019dff3e-e364-42bf-82d1-0bc91ea80ae0 10/11 Test PASSES after retries.No significant increase in flaky rate(baseline=0.0011, p0=1.0000, reject_threshold=0.0100. adj_baseline=0.1000, p1=0.3487, trust_threshold=0.5000) https://redpanda.metabaseapp.com/dashboard/87-tests?tab=142-dt-individual-test-history&test_class=SIPartitionMovementTest&test_method=test_cross_shard

@travisdowns travisdowns merged commit 8d48fff into redpanda-data:dev May 7, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants