Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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| {
Expand All @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions tests/run-make/macos-deployment-target-warning/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Loading