-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Support -Clink-self-contained=+linker
for ld.lld
linker flavor
#140813
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// We're just trying to launch the linker to see which one rustc picks between system lld and | ||
// rust-lld. We don't need to link anything successfully though, so this is just a stub. | ||
|
||
#![feature(no_core)] | ||
#![no_core] | ||
#![no_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,57 @@ | ||
// When using an `ld.lld` linker flavor, rustc will invoke lld directly. This test ensures that | ||
// turning on the self-contained linker will result in rustc choosing `rust-lld` instead of the | ||
// system lld. | ||
// | ||
// This is not straigthforward to test, so we make linking fail and look for the linker name | ||
// appearing in the failure. | ||
|
||
//@ needs-rust-lld | ||
//@ only-x86_64-unknown-linux-gnu | ||
|
||
use run_make_support::{Rustc, rustc}; | ||
|
||
// Make linking fail because of an incorrect flag. In case there's an issue on CI or locally, we | ||
// also ask for rustc's linking debug logging, in order to have more information in the test logs. | ||
fn make_linking_fail(linker_flavor: &str) -> Rustc { | ||
let mut rustc = rustc(); | ||
rustc | ||
.env("RUSTC_LOG", "rustc_codegen_ssa::back::link") // ask for linking debug logs | ||
.linker_flavor(linker_flavor) | ||
.link_arg("--baguette") // ensures linking failure | ||
.input("main.rs"); | ||
rustc | ||
} | ||
|
||
fn main() { | ||
// 1. Using `ld` directly via the linker flavor. | ||
make_linking_fail("ld").run_fail().assert_stderr_contains("error: linking with `ld` failed"); | ||
|
||
// 2. Using `lld` via the linker flavor. We ensure the self-contained linker is disabled to use | ||
// the system lld. | ||
// | ||
// This could fail in two ways: | ||
// - the most likely case: `lld` rejects our incorrect link arg | ||
// - or there may not be an `lld` on the $PATH. The testing/run-make infrastructure runs tests | ||
// with llvm tools in the path and there is an `lld` executable there most of the time (via | ||
// `ci-llvm`). But since one can turn that off in the config, we also look for the usual | ||
// "-fuse-ld=lld" failure. | ||
let system_lld_failure = make_linking_fail("ld.lld") | ||
.arg("-Clink-self-contained=-linker") | ||
.arg("-Zunstable-options") | ||
.run_fail(); | ||
let lld_stderr = system_lld_failure.stderr_utf8(); | ||
assert!( | ||
lld_stderr.contains("error: linking with `lld` failed") | ||
|| lld_stderr.contains("error: linker `lld` not found"), | ||
"couldn't find `lld` failure in stderr: {}", | ||
lld_stderr, | ||
); | ||
|
||
// 3. Using the same lld linker flavor and enabling the self-contained linker should use | ||
// `rust-lld`. | ||
make_linking_fail("ld.lld") | ||
.arg("-Clink-self-contained=+linker") | ||
.arg("-Zunstable-options") | ||
.run_fail() | ||
.assert_stderr_contains("error: linking with `rust-lld` failed"); | ||
} |
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.
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.
With mingw in particular this logic + logic in
detect_self_contained_mingw
mean thatself-contained=+linker
always turns intoself-contained=yes
:D