linker: More systematic handling of CRT objects#71769
Conversation
|
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
The only case of rustc interpreting user-provided raw linker arguments is removed here.
First, -static wins over -pie so we could still pass -pie if the user passed -static with the same effect.
Second, it was a hack, this static guessing wasn't done consistently in other places, equivalent cases like -Wl,-static weren't recognized, and we shouldn't be interpreting raw linker args in general.
There was a problem hiding this comment.
No idea which libc flavor Fuchsia uses, just kept the status quo behavior.
|
☔ The latest upstream changes (presumably #71807) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@smaeul @shizmob @mixi (people who participated in #40113 and related PRs), which of you I can ping on PRs/issues like this one? I have a question. What would be a good and safe approximation for "musl-aware system gcc is available" that rustc could use to apply the fallback only when it's really necessary?
|
|
Checking to see if |
Clarification: without expensive environment probing like running processes (but checking files is ok). Ideally such check is performed by a build system, and the result is cached, and then passed to the compiler.
Explicitly passed |
|
So, I've measured the slowdown from the No probing (3 runs): Probing (3 runs): That's ~3% slower. Should be pretty acceptable if it only happens in setups in which other heuristics fail. In this PR some FIXMEs and comments need to be updated before it's ready. |
|
r? @cuviper |
|
I don't have deep knowledge of all of these targets, but it looks reasonable to me. @bors r+ |
|
📌 Commit 49eb35c has been approved by |
|
☀️ Test successful - checks-azure |
rustc_target: Remove `pre_link_args_crt` To regain some more control over the definition of `+crt-static` (rust-lang#71586). After rust-lang#71769 this target option wasn't used anywhere except for VxWorks, and I suspect that for VxWorks its use may be redundant as well.
| match kind { | ||
| LinkOutputKind::DynamicPicExe if !pic_exe_supported => LinkOutputKind::DynamicNoPicExe, | ||
| LinkOutputKind::StaticPicExe if !static_pic_exe_supported => LinkOutputKind::StaticNoPicExe, | ||
| LinkOutputKind::StaticDylib if !static_dylib_supported => LinkOutputKind::DynamicDylib, |
There was a problem hiding this comment.
Am I missing something, or is this logic inverted from what it should be? If crt_static() returns true, aren't we only allowed to create a DynamicDylib when crt_static_allows_dylibs is also true?
There was a problem hiding this comment.
This case is here for consistency, but we should never hit it right now because if invalid_output_for_target is true then we skip the crate type and never get to linking.
But if we didn't skip it (like we don't skip PIC executables when +crt-static is enabled but not supported), then we would fall back from StaticDylib to DynamicDylib.
Document which kinds of
crt0.o-like objects we link and in which cases, discovering bugs in process.src/librustc_target/spec/crt_objects.rsis the place to start reading from.This PR also automatically contains half of the
-static-piesupport (#70740), because that's one of the six cases that we need to consider when linking CRT objects.This is a breaking change for custom target specifications that specify CRT objects.
Closes #30868