-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rustc tries to link the Linux ASAN runtime when linker flavour is MSVC+LLD #131363
Comments
I am not sure what the actual library name should be here. It's possible it should be nothing at all. In Chromium we are using the clang runtime libraries, and we just build a stub library in the Rust sysroot for ASAN to satisfy rustc. When targeting Linux instead of Windows, everything links.
But note that the
We get this rustc invocation:
And when we inject an invalid
Which is specifying this ASAN library path: There is, however, no ASAN runtime built by |
Maybe the sysroot thing is unrelated and it's just searching for and failing to find the ASAN library, then falling back to the default sysroot. And on Windows, which is where I noticed this, it's because it's looking for a Linux library, so it always falls back. In our Chromium build which uses Edit: Ah yes, indeed: rust/compiler/rustc_codegen_ssa/src/back/link.rs Lines 1318 to 1327 in 0b16baa
|
I think that the branches here need to do something for MSVC+LLD that isn't "link the Linux library". Don't know if that is just doing nothing, or generating an error that sanitizers with MSVC+LLD is only supported with -Zexternal-clang-rt, or something else? |
cc: #39699 |
This prevents rustc from trying to link sanitizer runtimes, so we don't need to make fake ones in our sysroot anymore. And this avoids rustc trying to link the Linux runtime when we're targeting Windows due to rust-lang/rust#131363. When this flag is specified, rustc avoids adding sanitizer libraries here: https://github.com/rust-lang/rust/blob/7caad6925314911eefe54b040d4bc5be940e8f92/compiler/rustc_codegen_ssa/src/back/link.rs#L1263-L1267 R=hans@chromium.org Bug: 371512562 Cq-Include-Trybots: luci.chromium.try:win-asan,android-rust-arm32-rel,android-rust-arm64-dbg,android-rust-arm64-rel,linux-rust-x64-rel,linux-rust-x64-dbg,mac-rust-x64-dbg,win-rust-x64-dbg,win-rust-x64-rel,mac_chromium_asan_rel_ng,linux_chromium_asan_rel_ng Change-Id: Ifcc6cb841af2697c6ca5ab3b64adcc995683fbc6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5913992 Commit-Queue: danakj <danakj@chromium.org> Reviewed-by: Arthur Eubanks <aeubanks@google.com> Cr-Commit-Position: refs/heads/main@{#1365077}
This prevents rustc from trying to link sanitizer runtimes, so we don't need to make fake ones in our sysroot anymore. And this avoids rustc trying to link the Linux runtime when we're targeting Windows due to rust-lang/rust#131363. When this flag is specified, rustc avoids adding sanitizer libraries here: https://github.com/rust-lang/rust/blob/7caad6925314911eefe54b040d4bc5be940e8f92/compiler/rustc_codegen_ssa/src/back/link.rs#L1263-L1267 R=hans@chromium.org Bug: 371512562 Cq-Include-Trybots: luci.chromium.try:win-asan,android-rust-arm32-rel,android-rust-arm64-dbg,android-rust-arm64-rel,linux-rust-x64-rel,linux-rust-x64-dbg,mac-rust-x64-dbg,win-rust-x64-dbg,win-rust-x64-rel,mac_chromium_asan_rel_ng,linux_chromium_asan_rel_ng Change-Id: Ifcc6cb841af2697c6ca5ab3b64adcc995683fbc6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5913992 Commit-Queue: danakj <danakj@chromium.org> Reviewed-by: Arthur Eubanks <aeubanks@google.com> Cr-Commit-Position: refs/heads/main@{#1365077} NOKEYCHECK=True GitOrigin-RevId: 7d029cad43d3bf03b0464d9e3c55cc0f8b5474e2
When linking with
lld-link
, which provides the MSVC flavour linker with LLD subtype, the ASAN runtime selection falls through to the Linux branch and tries to link the non-existentlibrustc-dev_rt.asan.a
library while targeting Windows.A repro can be seen on Linux, cross-compiling for Windows. It needs a Windows sysroot and a clang/lld build:
The relevant parts of the command line are:
-Zsanitizer=address -Clinker=../c/src/third_party/llvm-build/Release+Asserts/bin/lld-link"
--target x86_64-pc-windows-msvc
The library choice is made here:
rust/compiler/rustc_codegen_ssa/src/back/link.rs
Lines 1349 to 1351 in 0b16baa
The branch above would normally be used for MSVC flavour, but it's not used for LLD, so it falls down to the else branch which is for Linux.
Edited to hide the sysroot stuff, this seems okay and unrelated:
The code here is also ignoring
--sysroot
. If we include a bogus but relative path--sysroot=a/b/c
inRUSTFLAGS
, the ASAN library should be specified asa/b/c/lib/rustlib/x86_64-pc-windows-msvc/lib/
but it is always using the absolute path to the default sysroot.Chromium tracking issue: crbug.com/371512562
cc: @rcvalle
The text was updated successfully, but these errors were encountered: