Repository navigation
snmalloc-rs: keep LTCG library out of the rlib with build_cc on MSVC - #898
Merged
Matthew Parkinson (mjp41) merged 1 commit intoNov 8, 2026
Merged
Conversation
With build_cc and lto on MSVC the library is compiled with /GL and cc bundles it into the snmalloc-sys rlib. rustc cannot read the symbol table of LTCG objects, so the bundled copy exports nothing and the final link fails with unresolved sn_rust_* symbols. Mark the library -bundle so it is passed to link.exe directly, as the CMake build does, and skip the duplicate link-lib line that rustc would reject. Add a build_cc lto job to the Rust CI matrix. Fixes microsoft#889
Schrodinger ZHU Yifan (SchrodingerZhu)
self-requested a review
November 2, 2026 21:53
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the MSVC LTO linking changes.
No open issues 🎉
What changed in this PR
Fixes #889 by keeping MSVC link-time-optimized native libraries outside the Rust archive when build_cc and lto are enabled, allowing the final linker to resolve the sn_rust_* symbols.
Changes:
- Disables native-library bundling for this configuration and avoids duplicate MSVC link-library directives.
- Raises the minimum
ccversion to 1.0.74 forlink_lib_modifiersupport. - Adds
build_ccwithltoto the Rust CI matrix.
| File | Description |
|---|---|
snmalloc-rs/snmalloc-sys/Cargo.toml |
Raises the minimum supported cc version. |
snmalloc-rs/snmalloc-sys/build.rs |
Adjusts MSVC library bundling and link directives. |
.github/workflows/rust.yml |
Adds CI coverage for combined build_cc and lto features. |
Review effort: Balanced
Matthew Parkinson (mjp41)
merged commit Nov 8, 2026
a1c7a13
into
microsoft:main
342 of 343 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #889
Root cause
With the
build_ccandltofeatures on MSVC, snmalloc is compiled with /GL and cc bundles the static library into the snmalloc-sys rlib. rustc can't read symbols from LTCG objects (rust-lang/rust#26003), so the bundled copy exports nothing and the final link fails with LNK2019 on thesn_rust_*symbols. The CMake build doesn't run into this. It emits a plainrustc-link-libline, the library isn't bundled, and link.exe gets the original .lib and restarts with /LTCG.Fix
ltois on with MSVC and the library is built with cc, setlink_lib_modifier("-bundle")so the .lib goes to link.exe directly.rustc-link-libline inmain()forbuild_ccon MSVC, since rustc rejects a duplicate entry for the same library when one of them carries modifiers.link_lib_modifierneeds cc 1.0.74, so the minimum cc version is bumped to that.build_cc-ltoentry (--features "build_cc lto") to the Rust CI matrix.Testing
Windows 11, MSVC 14.51 (Visual Studio 2026), Rust 1.98.1, rebased on current main.
cargo test --allinsnmalloc-rs, debug and release.--features "build_cc lto", the snmalloc-rs lib tests andmemory_statsfail to link with LNK2019 onsn_rust_*symbols such assn_rust_statistics, in both debug and release.--features "build_cc lto"passes in debug and release, and so do the other feature sets in the CI matrix (default,debug,check,build_cc usecxx17,native-cpu,local_dynamic_tls,lto).