-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Add linker_static_archive_order lint for -Clink-arg archives placed before referenced dynamic libs
#160201
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
Open
cezarbbb
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
cezarbbb:link-arg-static-archive-lint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add linker_static_archive_order lint for -Clink-arg archives placed before referenced dynamic libs
#160201
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // Tests for the `linker_static_archive_order` lint. | ||
| // See <https://github.com/rust-lang/rust/issues/154975>. | ||
|
|
||
| //@ only-linux | ||
| // The lint applies to GNU `ld`-family linkers (including `lld`) on non-Windows, non-Darwin. | ||
|
|
||
| use run_make_support::{cwd, is_darwin, is_windows, rustc}; | ||
|
|
||
| fn main() { | ||
| // The diagnostic carries the full archive path, so assert on the stable filename substring. | ||
| let archive = cwd().join("libdoesnotexist.a"); | ||
| let archive_str = archive.to_str().unwrap(); | ||
|
|
||
| // 1. A `.a` path via `-Clink-arg` on a bare `ld` flavor fires the lint. | ||
| rustc() | ||
| .input("empty.rs") | ||
| .linker_flavor("ld") | ||
| .link_arg(archive_str) | ||
| .arg("-Wlinker-static-archive-order") | ||
| .print("link-args") | ||
| .run_unchecked() | ||
| .assert_stderr_contains("warning: static archive") | ||
| .assert_stderr_contains("libdoesnotexist.a"); | ||
|
|
||
| // 2. A `.o` path is flagged the same way. | ||
| let object = cwd().join("doesnotexist.o"); | ||
| rustc() | ||
| .input("empty.rs") | ||
| .linker_flavor("ld") | ||
| .link_arg(object.to_str().unwrap()) | ||
| .arg("-Wlinker-static-archive-order") | ||
| .print("link-args") | ||
| .run_unchecked() | ||
| .assert_stderr_contains("warning: static archive") | ||
| .assert_stderr_contains("doesnotexist.o"); | ||
|
|
||
| // 3. A non-archive arg like `-lm` does not fire. | ||
| rustc() | ||
| .input("empty.rs") | ||
| .linker_flavor("ld") | ||
| .link_arg("-lm") | ||
| .arg("-Wlinker-static-archive-order") | ||
| .print("link-args") | ||
| .run_unchecked() | ||
| .assert_stderr_not_contains("linker_static_archive_order"); | ||
|
|
||
| // 4. `Allow` by default: no `-W`, no output. | ||
| rustc() | ||
| .input("empty.rs") | ||
| .linker_flavor("ld") | ||
| .link_arg(archive_str) | ||
| .print("link-args") | ||
| .run_unchecked() | ||
| .assert_stderr_not_contains("linker_static_archive_order"); | ||
|
|
||
| // 5. `ignore_deny_warnings`: `-Dwarnings` does not promote the `-W` to an error. | ||
| rustc() | ||
| .input("empty.rs") | ||
| .linker_flavor("ld") | ||
| .link_arg(archive_str) | ||
| .arg("-Wlinker-static-archive-order") | ||
| .arg("-Dwarnings") | ||
| .print("link-args") | ||
| .run_unchecked() | ||
| .assert_stderr_contains("warning: static archive") | ||
| .assert_stderr_contains("the `linker_static_archive_order` lint ignores `-D warnings`"); | ||
|
|
||
| // 6. `-Dlinker-static-archive-order` (specific) does promote to an error. | ||
| rustc() | ||
| .input("empty.rs") | ||
| .linker_flavor("ld") | ||
| .link_arg(archive_str) | ||
| .arg("-Dlinker-static-archive-order") | ||
| .print("link-args") | ||
| .run_fail() | ||
| .assert_stderr_contains("error: static archive") | ||
| .assert_stderr_contains("libdoesnotexist.a"); | ||
|
|
||
| // 7. `#![allow]` suppresses even an explicit `-W`. | ||
| rustc() | ||
| .input("-") | ||
| .linker_flavor("ld") | ||
| .link_arg(archive_str) | ||
| .arg("-Wlinker-static-archive-order") | ||
| .arg("--crate-type=lib") | ||
| .stdin_buf("#![allow(linker_static_archive_order)] fn main() {}") | ||
| .print("link-args") | ||
| .run_unchecked() | ||
| .assert_stderr_not_contains("static archive"); | ||
|
|
||
| // 8. The `gnu-cc` flavor (cc-driven, `Gnu(Cc::Yes, Lld::No)`) also fires: it uses real `ld` | ||
| // behind `cc` and the same `--as-needed` + left-to-right interaction applies. | ||
| rustc() | ||
| .input("empty.rs") | ||
| .arg("-Zunstable-options") | ||
| .linker_flavor("gnu-cc") | ||
| .link_arg(archive_str) | ||
| .arg("-Wlinker-static-archive-order") | ||
| .print("link-args") | ||
| .run_unchecked() | ||
| .assert_stderr_contains("warning: static archive") | ||
| .assert_stderr_contains("libdoesnotexist.a"); | ||
|
|
||
| // 9. The lint also fires with `lld` (`Gnu(.., Lld::Yes)`): the risky ordering is the same, so | ||
| // the latent issue surfaces before a switch back to `ld.bfd`. | ||
| rustc() | ||
| .input("empty.rs") | ||
| .linker_flavor("ld.lld") | ||
| .link_arg(archive_str) | ||
| .arg("-Wlinker-static-archive-order") | ||
| .print("link-args") | ||
| .run_unchecked() | ||
| .assert_stderr_contains("warning: static archive") | ||
| .assert_stderr_contains("libdoesnotexist.a"); | ||
|
|
||
| assert!(!is_windows() && !is_darwin()); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if it isn't strictly needed, I think the lint should still fire.
View changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.