Repository navigation
snmalloc-rs: keep LTCG library out of the rlib with build_cc on MSVC - #898
Open
Koi (ck0i) wants to merge 1 commit into
Open
Koi (ck0i) wants to merge 1 commit into
Koi (ck0i) wants to merge 1 commit into
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
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).