diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 105093e37b237..0a9af492b1f45 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -884,9 +884,9 @@ fn is_msvc_link_exe(sess: &Session) -> bool { && linker_path.to_str() == Some("link.exe") } -fn is_macos_ld(sess: &Session) -> bool { +fn is_macos_linker(sess: &Session) -> bool { let (_, flavor) = linker_and_flavor(sess); - sess.target.is_like_darwin && matches!(flavor, LinkerFlavor::Darwin(_, Lld::No)) + sess.target.is_like_darwin && matches!(flavor, LinkerFlavor::Darwin(..)) } fn is_windows_gnu_ld(sess: &Session) -> bool { @@ -953,8 +953,8 @@ fn report_linker_output( *output += "\r\n" } }); - } else if is_macos_ld(sess) { - info!("inferred macOS LD"); + } else if is_macos_linker(sess) { + info!("inferred macOS linker"); // FIXME: Tracked by https://github.com/rust-lang/rust/issues/136113 let deployment_mismatch = |line: &str| { @@ -967,6 +967,8 @@ fn report_linker_output( && line.contains("building for") && line.contains("but linking with") && line.contains("which was built for newer version")) + // lld (ld64.lld / rust-lld): + || line.contains("which is newer than target minimum of") }; // FIXME: This is a real warning we would like to show, but it hits too many crates // to want to turn it on immediately. diff --git a/tests/run-make/macos-deployment-target-warning/rmake.rs b/tests/run-make/macos-deployment-target-warning/rmake.rs index 6aab525a7c8a4..5fed700ce64f4 100644 --- a/tests/run-make/macos-deployment-target-warning/rmake.rs +++ b/tests/run-make/macos-deployment-target-warning/rmake.rs @@ -13,6 +13,7 @@ fn main() { let ld_prime_obj = r"ld: warning: object file \(.*\) was built for newer '.+' version \(\d+\.\d+\) than being linked \(\d+\.\d+\)"; let ld64_dylib = r"ld: warning: dylib \(.*\) was built for newer .+ version \(\d+\.\d+\) than being linked \(\d+\.\d+\)"; let ld_prime_dylib = r"ld: warning: building for [^ ,]+, but linking with dylib '[^']*' which was built for newer version [0-9.]+"; + let lld_obj = r"ld64\.lld: warning: .+ has version \d+\.\d+(\.\d+)?, which is newer than target minimum of \d+\.\d+(\.\d+)?"; // Test 1: static archive (object file mismatch) cc().arg("-c").arg("-mmacosx-version-min=15.5").output("foo.o").input("foo.c").run(); @@ -54,4 +55,26 @@ fn main() { .normalize(ld64_dylib, "NORMALIZED_DYLIB_DEPLOYMENT_MISMATCH_LINKER_WARNING") .normalize(ld_prime_dylib, "NORMALIZED_DYLIB_DEPLOYMENT_MISMATCH_LINKER_WARNING") .run(); + + // Test 3: static archive with lld (object file mismatch) + let lld_path = std::path::PathBuf::from(std::env::var("LLVM_BIN_DIR").unwrap()).join("lld"); + let ld64_lld = std::env::current_dir().unwrap().join("ld64.lld"); + std::os::unix::fs::symlink(&lld_path, &ld64_lld).expect("failed to create ld64.lld symlink"); + + let lld_warnings = rustc() + .arg("-lstatic=foo") + .arg("-Clink-self-contained=-linker") + .arg("-Zunstable-options") + .arg("-Clinker-flavor=darwin-lld") + .linker(&ld64_lld.to_str().unwrap()) + .input("main.rs") + .crate_type("bin") + .run() + .stderr_utf8(); + + diff() + .expected_file("warnings.txt") + .actual_text("(rustc -W linker-info with lld)", &lld_warnings) + .normalize(lld_obj, "NORMALIZED_OBJECT_DEPLOYMENT_MISMATCH_LINKER_WARNING") + .run(); }