Files
rust/compiler/rustc_codegen_ssa
Jacob Pratt 05cfae5147 Rollup merge of #159666 - r3v5:fix-llvm-ld64-lld-linker-stderr-warnings, r=petrochenkov
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.
2026-07-28 20:09:39 -04:00
..
…

Please read the rustc-dev-guide chapter on Backend Agnostic Codegen.