fix(ld64.lld): route version mismatch warnings to linker_info on macOS#159666
fix(ld64.lld): route version mismatch warnings to linker_info on macOS#159666r3v5 wants to merge 1 commit into
Conversation
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @petrochenkov (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? jyn514 |
|
Failed to set assignee to
|
1 similar comment
|
Failed to set assignee to
|
|
r? @jyn514 |
|
Failed to set assignee to
|
cb63076 to
3705b3e
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
There was a problem hiding this comment.
this looks good to me. the bug itself is a clear oversight from when i added this lint, the fix is simple, the test uses a real LLD run to make sure the warning matches.
there's one thing in the PR description that doesn't look quite right:
Issue: When use ld64.lld linker, dependencies (e.g. C libraries) inside .o objects 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.
this is not specific to LLD, it would happen with any linker. the thing that causes this is actually flags passed by cc-rs when used in a build.rs; see #136113:
However, this does not match the default behavior for clang, which defaults to the selected SDK versions; unless changed otherwise, a C program built with clang uses the macOS host version as deployment target. The cc-rs crate also defaults to this behavior.
please update the PR description. other than that everything looks good to me.
I have updated PR description, thanks! |
|
the CI failure looks like just a flake. @petrochenkov i'm happy with this PR, would you mind taking a look? @rustbot ready (@r3v5 note that you can also run |
|
r=me after squashing commits. |
|
Reminder, once the PR becomes ready for a review, use |
3705b3e to
5ad773b
Compare
|
@rustbot review |
|
@bors r+ rollup |
…rr-warnings, r=petrochenkov fix(ld64.lld): route version mismatch warnings to linker_info on macOS r? jyn514 Fixes rust-lang#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)`](https://github.com/rust-lang/rust/blob/f65b272fc92b1e7527dea4a224430a249ab25c2d/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#136113). **Root cause:** I believe that the current function `is_macos_ld()` in [compiler/rustc_codegen_ssa/src/back/link.rs](https://github.com/rust-lang/rust/blob/730a6b5dce9477b819de0ba79d6e7945e1248e3d/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.
…rr-warnings, r=petrochenkov fix(ld64.lld): route version mismatch warnings to linker_info on macOS r? jyn514 Fixes rust-lang#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)`](https://github.com/rust-lang/rust/blob/f65b272fc92b1e7527dea4a224430a249ab25c2d/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#136113). **Root cause:** I believe that the current function `is_macos_ld()` in [compiler/rustc_codegen_ssa/src/back/link.rs](https://github.com/rust-lang/rust/blob/730a6b5dce9477b819de0ba79d6e7945e1248e3d/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.
…rr-warnings, r=petrochenkov fix(ld64.lld): route version mismatch warnings to linker_info on macOS r? jyn514 Fixes rust-lang#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)`](https://github.com/rust-lang/rust/blob/f65b272fc92b1e7527dea4a224430a249ab25c2d/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#136113). **Root cause:** I believe that the current function `is_macos_ld()` in [compiler/rustc_codegen_ssa/src/back/link.rs](https://github.com/rust-lang/rust/blob/730a6b5dce9477b819de0ba79d6e7945e1248e3d/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.
…rr-warnings, r=petrochenkov fix(ld64.lld): route version mismatch warnings to linker_info on macOS r? jyn514 Fixes rust-lang#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)`](https://github.com/rust-lang/rust/blob/f65b272fc92b1e7527dea4a224430a249ab25c2d/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#136113). **Root cause:** I believe that the current function `is_macos_ld()` in [compiler/rustc_codegen_ssa/src/back/link.rs](https://github.com/rust-lang/rust/blob/730a6b5dce9477b819de0ba79d6e7945e1248e3d/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.
Rollup of 12 pull requests Successful merges: - #159765 (Avoid spurious rebuilds of JSON docs in bootstrap) - #159781 (Update bootstrap to use -Zembed-metadata=no instead of -Zno-embed-metadata) - #158362 (trait solver: account for universes from replace_bound_vars) - #159173 (Add allowed list check on EII implementations attributes) - #159718 (Make `DocLinkResMap` an `FxIndexMap`) - #159722 ( [rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature) - #155795 (constify `vec![1, 2, 3]` macro) - #157776 (ci: Enable autodiff tests on x86_64 linux) - #158766 (Promote riscv64-unknown-linux-musl to tier 2 with host tools) - #159271 (str: add ASCII fast path to word_to_titlecase) - #159666 (fix(ld64.lld): route version mismatch warnings to linker_info on macOS) - #159667 (Make some parser structured suggestions verbose and tweak their wording)
|
|
This pull request was unapproved. |
Broaden `is_macos_ld` to `is_macos_linker` by matching `Darwin(..)` instead of `Darwin(_, Lld::No)`, so the linker output filtering also runs when lld is used. Add lld-specific version mismatch pattern to `deployment_mismatch` closure, routing these warnings to `linker_info` (default Allow) instead of `linker_messages` (default Warn). Add a real-lld sub-test to `macos-deployment-target-warning` that exercises the `ld64.lld` path via `-fuse-ld=`, verifying lld warnings are normalized and routed to `linker_info`. Signed-off-by: Ian Miller <milleryan2003@gmail.com>
5ad773b to
ebec21d
Compare
|
@rustbot review |
|
@bors try jobs=aarch64-apple |
This comment has been minimized.
This comment has been minimized.
…, r=<try> fix(ld64.lld): route version mismatch warnings to linker_info on macOS try-job: aarch64-apple
|
💔 Test for 806738b failed: CI. Failed job:
|
|
The job Click to see the possible cause of the failure (guessed by this bot) |
View all comments
r? jyn514
Fixes #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)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 #136113).Root cause: I believe that the current function
is_macos_ld()in compiler/rustc_codegen_ssa/src/back/link.rs 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:So,
Lld::Nomeans using native macOS linker, so when lld is used viaLld::Yes, the match fails and the function returnsfalsehence 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.