Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downgrade linker-warnings to allow-by-default #136098

Merged
merged 1 commit into from
Jan 27, 2025
Merged
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
18 changes: 13 additions & 5 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4091,6 +4091,7 @@ declare_lint! {
/// ### Example
///
/// ```rust,ignore (needs CLI args, platform-specific)
/// #[warn(linker_messages)]
/// extern "C" {
/// fn foo();
/// }
Expand All @@ -4104,17 +4105,24 @@ declare_lint! {
/// >>> referenced by rust_out.69edbd30df4ae57d-cgu.0
/// >>> rust_out.rust_out.69edbd30df4ae57d-cgu.0.rcgu.o:(rust_out::main::h3a90094b06757803)
/// |
/// = note: `#[warn(linker_messages)]` on by default
///
/// note: the lint level is defined here
/// --> warn.rs:1:9
/// |
/// 1 | #![warn(linker_messages)]
/// | ^^^^^^^^^^^^^^^
/// warning: 1 warning emitted
/// ```
///
/// ### Explanation
///
/// Linkers emit platform-specific and program-specific warnings that cannot be predicted in advance by the rust compiler.
/// They are forwarded by default, but can be disabled by adding `#![allow(linker_messages)]` at the crate root.
/// Linkers emit platform-specific and program-specific warnings that cannot be predicted in
/// advance by the Rust compiler. Such messages are ignored by default for now. While linker
/// warnings could be very useful they have been ignored for many years by essentially all
/// users, so we need to do a bit more work than just surfacing their text to produce a clear
/// and actionable warning of similar quality to our other diagnostics. See this tracking
/// issue for more details: <https://github.com/rust-lang/rust/issues/136096>.
pub LINKER_MESSAGES,
Warn,
Allow,
"warnings emitted at runtime by the target-specific linker program"
}

Expand Down
1 change: 1 addition & 0 deletions tests/run-make/linker-warning/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fn run_rustc() -> Rustc {
// Make sure we use a consistent value.
.arg("-Clink-self-contained=-linker")
.arg("-Zunstable-options")
.arg("-Wlinker-messages")
.output("main")
.linker("./fake-linker");
if run_make_support::target() == "x86_64-unknown-linux-gnu" {
Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/rust-lld-by-default-beta-stable/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use run_make_support::rustc;
fn main() {
// A regular compilation should not use rust-lld by default. We'll check that by asking the
// linker to display its version number with a link-arg.
let output = rustc().link_arg("-Wl,-v").input("main.rs").run();
let output = rustc().arg("-Wlinker-messages").link_arg("-Wl,-v").input("main.rs").run();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @rust-lang/release it continues to make me very uncomfortable to be editing tests that i have no way of running. if this fails in 6 weeks i do not know if i will have time to fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally, you can config [rust] channel = "beta" (or stable). For CI, you could temporarily change src/ci/channel for a @bors try attempt.

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test runs in every merge via the x86_64-gnu-stable job:

https://github.com/rust-lang-ci/rust/actions/runs/12975734650/job/36187153380

2025-01-26T16:46:32.1849227Z test [run-make] tests/run-make/rust-lld-by-default-beta-stable ... ok

assert!(
!find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should not be present in the output logs:\n{}",
Expand Down
9 changes: 7 additions & 2 deletions tests/run-make/rust-lld-by-default-nightly/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ use run_make_support::rustc;
fn main() {
// A regular compilation should use rust-lld by default. We'll check that by asking the linker
// to display its version number with a link-arg.
let output = rustc().link_arg("-Wl,-v").input("main.rs").run();
let output = rustc().arg("-Wlinker-messages").link_arg("-Wl,-v").input("main.rs").run();
assert!(
find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should be present in the output logs:\n{}",
output.stderr_utf8()
);

// But it can still be disabled by turning the linker feature off.
let output = rustc().link_arg("-Wl,-v").arg("-Zlinker-features=-lld").input("main.rs").run();
let output = rustc()
.arg("-Wlinker-messages")
.link_arg("-Wl,-v")
.arg("-Zlinker-features=-lld")
.input("main.rs")
.run();
assert!(
!find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should not be present in the output logs:\n{}",
Expand Down
2 changes: 2 additions & 0 deletions tests/run-make/rust-lld-custom-target/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn main() {
// the linker to display its version number with a link-arg.
let output = rustc()
.crate_type("cdylib")
.arg("-Wlinker-messages")
.target("custom-target.json")
.link_arg("-Wl,-v")
.input("lib.rs")
Expand All @@ -29,6 +30,7 @@ fn main() {
// But it can also be disabled via linker features.
let output = rustc()
.crate_type("cdylib")
.arg("-Wlinker-messages")
.target("custom-target.json")
.arg("-Zlinker-features=-lld")
.link_arg("-Wl,-v")
Expand Down
10 changes: 8 additions & 2 deletions tests/run-make/rust-lld/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn main() {
.arg("-Zlinker-features=+lld")
.arg("-Clink-self-contained=+linker")
.arg("-Zunstable-options")
.arg("-Wlinker-messages")
.link_arg(linker_version_flag)
.input("main.rs")
.run();
Expand All @@ -27,8 +28,12 @@ fn main() {
);

// It should not be used when we explicitly opt-out of lld.
let output =
rustc().link_arg(linker_version_flag).arg("-Zlinker-features=-lld").input("main.rs").run();
let output = rustc()
.link_arg(linker_version_flag)
.arg("-Zlinker-features=-lld")
.arg("-Wlinker-messages")
.input("main.rs")
.run();
assert!(
!find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should not be present in the output logs:\n{}",
Expand All @@ -44,6 +49,7 @@ fn main() {
.arg("-Zlinker-features=-lld")
.arg("-Zlinker-features=+lld")
.arg("-Zlinker-features=-lld,+lld")
.arg("-Wlinker-messages")
.input("main.rs")
.run();
assert!(
Expand Down
Loading