-
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
try to infer linker flavor from linker name and vice versa #52101
Conversation
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
||
Ok((linker, flavor)) | ||
}, | ||
(None, None) => otherwise(), |
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.
Stylistically I might recommend instead of a cps style to instead do something like:
- Emit only fatal errors here via
sess
(it doesn't look like the error is ever "caught"?) - Return
Option
instead ofResult
- Instead do something like:
if let Some(ret) = locate_linker(&sess.opts) {
return Some(ret)
}
if let Some(ret) = locate_linker(&sess.target.target) {
return Some(ret)
}
sess.fatal("...")
LinkerFlavor::Em => "emcc", | ||
LinkerFlavor::Gcc => "gcc", | ||
LinkerFlavor::Ld => "ld", | ||
LinkerFlavor::Msvc => "link.exe", |
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.
I think this is losing the logic of locating link.exe
on MSVC which may cause issues there?
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.
The logic is in get_linker
which is called with the values this function returns. I think that function will locate link.exe even with these changes.
(Some(linker), Some(flavor)) => Ok((linker, flavor)), | ||
// only the linker flavor is known; use the default linker for the selected flavor | ||
(None, Some(flavor)) => Ok((PathBuf::from(match flavor { | ||
LinkerFlavor::Em => "emcc", |
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.
I think this may have accidentally lost the logic of emcc.bat
on Windows?
LinkerFlavor::Lld(f) => Command::lld(linker, f), | ||
_ => Command::new(linker), | ||
|
||
} | ||
}; | ||
})(); |
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.
You can probably remove the intermediate closure here, I don't think it's serving much purpose any more
sess | ||
.struct_err(&format!("couldn't infer linker flavor from specified linker")) | ||
.emit(); | ||
return Err(()); |
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.
This runs the risk of being a breaking change by accident if someone's passing in a "flavorful" linker because currently we can't error today I think? Perhaps this could fall back to the target spec's linker flavor and if that's not present emit an error?
☔ The latest upstream changes (presumably #52268) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage, @japaric: There are some review comments on your PR. |
It'll take me a while to get back to this so I'm going to close the PR in the meantime. |
re-r? @alexcrichton I believe I have addressed all your comments. |
return ret; | ||
} | ||
|
||
sess.fatal("Not enough information provided to determine how to invoke the linker"); |
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.
I believe, today, this is effectively unreachable because linker flavor is a mandatory field of target specifications. Should this be bug
instead of fatal
?
I realized (too late) that these changes are not enough to use rustc LLD with the What we could do to correctly support |
Ok looks great to me! I agree yeah changing the |
this field defaults to the LD / GNU flavor
@alexcrichton OK, done. r? |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors: r+ 👍 |
📌 Commit 4bbedd7 has been approved by |
@bors r=alexcrichton |
📌 Commit 98e4cd5 has been approved by |
⌛ Testing commit 98e4cd5 with merge 403324fa238c45b1739855f384b945c2c31045e4... |
💔 Test failed - status-travis |
This comment has been minimized.
This comment has been minimized.
expands logs
What? What happened? cc @rust-lang/infra |
⌛ Testing commit 98e4cd5 with merge e2fdc33267255d50a849a7eae7aa87b56f38b6b8... |
💔 Test failed - status-appveyor |
@bors r=alexcrichton |
📌 Commit a6f4ae8 has been approved by |
try to infer linker flavor from linker name and vice versa This is a second take on PR #50359 that implements the logic proposed in #50359 (review) With this change it would become possible to link `thumb*` binaries using GNU's LD on stable as `-C linker=arm-none-eabi-ld` would be enough to change both the linker and the linker flavor from their default values of `arm-none-eabi-gcc` and `gcc`. To link `thumb*` binaries using rustc's LLD on stable `-Z linker-flavor` would need to be stabilized as `-C linker=rust-lld -Z linker-flavor=ld.lld` are both required to change the linker and the linker flavor, but this PR doesn't propose that. We would probably need some sort of stability guarantee around `rust-lld`'s name and availability to make linking with rustc's LLD truly stable. With this change it would also be possible to link `thumb*` binaries using a system installed LLD on stable using the `-C linker=ld.lld` flag (provided that `ld.lld` is a symlink to the system installed LLD). r? @alexcrichton
☀️ Test successful - status-appveyor, status-travis |
This is a second take on PR #50359 that implements the logic proposed in #50359 (review)
With this change it would become possible to link
thumb*
binaries using GNU's LD on stable as-C linker=arm-none-eabi-ld
would be enough to change both the linker and the linker flavor from their default values ofarm-none-eabi-gcc
andgcc
.To link
thumb*
binaries using rustc's LLD on stable-Z linker-flavor
would need to be stabilized as-C linker=rust-lld -Z linker-flavor=ld.lld
are both required to change the linker and the linker flavor, but this PR doesn't propose that. We would probably need some sort of stability guarantee aroundrust-lld
's name and availability to make linking with rustc's LLD truly stable.With this change it would also be possible to link
thumb*
binaries using a system installed LLD on stable using the-C linker=ld.lld
flag (provided thatld.lld
is a symlink to the system installed LLD).r? @alexcrichton