mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
fix(ld64.lld): route version mismatch warnings to linker_info on macOS r? jyn514 Fixes rust-lang/rust#159227 **Issue:** .o objects (e.g. precompiled stdlib .rlib files, C libraries compiled via cc-rs) receive MacOS version of the machine they were compiled on and that version is much higher than Rust's default deployment target for aarch64-apple-darwin which is macOS 11.0.0. [`(Os::MacOs, crate::spec::Arch::AArch64, _) => (11, 0, 0)`](f65b272fc9/compiler/rustc_target/src/spec/base/apple/mod.rs (L332)) That’s why hundreds of warning logs appear such as warning: `linker stderr: rust-lld: /path/file.rlib(file.o) has version 26.4.1, which is newer than target minimum of 11.0.0`. These warnings were already filtered for ld64 and ld_prime but not for lld (see rust-lang/rust#136113). **Root cause:** I believe that the current function `is_macos_ld()` in [compiler/rustc_codegen_ssa/src/back/link.rs](730a6b5dce/compiler/rustc_codegen_ssa/src/back/link.rs (L874)) handles the case when we use native macOS linker so the entire filtering chain in linker output is skipped when using ld64.lld. Relevant code: ``` fn is_macos_ld(sess: &Session) -> bool { let (_, flavor) = linker_and_flavor(sess); sess.target.is_like_darwin && matches!(flavor, LinkerFlavor::Darwin(_, Lld::No)) } ``` So, `Lld::No` means using native macOS linker, so when lld is used via `Lld::Yes`, the match fails and the function returns `false` hence all warnings come from stderr to linker_messages which are visible. **My proposed solution:** modify filtering such that it runs for lld too and add a new specific ld64.lld warning pattern routing warnings to linker_info to make them invisible by default.
Please read the rustc-dev-guide chapter on Backend Agnostic Codegen.