-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[WIP] Linker flavors: next steps #119906
Closed
Closed
[WIP] Linker flavors: next steps #119906
Changes from 1 commit
Commits
Show all changes
3 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 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 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 |
---|---|---|
|
@@ -43,6 +43,7 @@ use rustc_fs_util::try_canonicalize; | |
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; | ||
use rustc_span::symbol::{kw, sym, Symbol}; | ||
use serde_json::Value; | ||
use std::assert_matches::assert_matches; | ||
use std::borrow::Cow; | ||
use std::collections::BTreeMap; | ||
use std::hash::{Hash, Hasher}; | ||
|
@@ -437,6 +438,17 @@ impl LinkerFlavor { | |
| LinkerFlavor::Ptx => false, | ||
} | ||
} | ||
|
||
pub fn uses_clang(self) -> bool { | ||
match self { | ||
LinkerFlavor::Gnu(Cc::Clang, _) | ||
| LinkerFlavor::Darwin(Cc::Clang, _) | ||
| LinkerFlavor::WasmLld(Cc::Clang) | ||
| LinkerFlavor::Unix(Cc::Clang) | ||
| LinkerFlavor::EmCc => true, | ||
_ => false, | ||
} | ||
} | ||
} | ||
|
||
macro_rules! linker_flavor_cli_impls { | ||
|
@@ -2185,21 +2197,34 @@ fn add_link_args_iter( | |
match flavor { | ||
LinkerFlavor::Gnu(cc, lld) => { | ||
assert_eq!(lld, Lld::No); | ||
assert_matches!(cc, Cc::No | Cc::Yes); | ||
insert(LinkerFlavor::Gnu(cc, Lld::Yes)); | ||
if cc == Cc::Yes { | ||
insert(LinkerFlavor::Gnu(Cc::Clang, Lld::No)); | ||
insert(LinkerFlavor::Gnu(Cc::Clang, Lld::Yes)); | ||
} | ||
} | ||
LinkerFlavor::Darwin(cc, lld) => { | ||
assert_eq!(lld, Lld::No); | ||
assert_matches!(cc, Cc::No | Cc::Yes); | ||
insert(LinkerFlavor::Darwin(cc, Lld::Yes)); | ||
if cc == Cc::Yes { | ||
insert(LinkerFlavor::Darwin(Cc::Clang, Lld::No)); | ||
insert(LinkerFlavor::Darwin(Cc::Clang, Lld::Yes)); | ||
} | ||
} | ||
LinkerFlavor::Msvc(lld) => { | ||
assert_eq!(lld, Lld::No); | ||
insert(LinkerFlavor::Msvc(Lld::Yes)); | ||
} | ||
LinkerFlavor::WasmLld(..) | ||
| LinkerFlavor::Unix(..) | ||
| LinkerFlavor::EmCc | ||
| LinkerFlavor::Bpf | ||
| LinkerFlavor::Ptx => {} | ||
LinkerFlavor::WasmLld(cc) | LinkerFlavor::Unix(cc) => { | ||
assert_matches!(cc, Cc::No | Cc::Yes); | ||
if cc == Cc::Yes { | ||
insert(LinkerFlavor::Gnu(Cc::Clang, Lld::No)); | ||
insert(LinkerFlavor::Gnu(Cc::Clang, Lld::Yes)); | ||
Comment on lines
+2247
to
+2248
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly still WIP: these linker args should have a |
||
} | ||
} | ||
LinkerFlavor::EmCc | LinkerFlavor::Bpf | LinkerFlavor::Ptx => {} | ||
} | ||
} | ||
|
||
|
This file contains 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 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 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 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
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.
Is this condition sufficient for the general case of adding
--target
when cross-compiling? The linker flavor doesn't contain any information about the target triple (unless I'm missing something), so I don't see how this can reliably detect cross-compiling.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.
From what I know
--target
only affects which linker is looked up (ld.lld
, orld64.lld
, etc) if clang is used for linking only.So if the required flavor is the same as host, then clang without
--target
will already use the right linker.On the other hand, there are some issues with crt object versions on macOS if
--target
is specified (fixed by #101792), maybe target takes priority over some relevant environment variables.So always passing
--target
leads to issues.We'll likely need to tweak this logic based on reported issues.
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.
For
lld
this may not matter, sincelld
is also a cross-linker.My main concern is if gnu ld is used (linker flavor
(Cc::Clang, Lld::No)
for both host and target), then --target is required for clang to select e.g.aarch64-linux-gnu-ld
instead of justld
.