-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Deduplicate native libs before they are passed to the linker #84794
Conversation
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
This seems reasonable, but also, I think it's a good motivation to do #76992 as well. With that change, it'd be reasonable to deduplicate libraries even if they're not adjacent. |
@joshtriplett That's why I want to land the linking modifiers infra (#83507) first, and not change or fix any deduplication behavior (including #73319) until a modifier for disabling/enabling deduplication is added. (FWIW, I don't think MSxDOS/ntapi#2 is purely a rustc's issue, with macro expansion you can do a lot of things slowing down you compilation deliberately, not necessarily related to linking.) |
Consider the following linker library order:
As far as I'm aware (please correct me if I'm wrong), this is exactly the same as:
Which is all this PR currently does. However the following is not the same, even if the linker is allowed to circle back to the start:
In the first cases, if a needed symbol is unresolved in
Therefore I think this PR is the most that can be done without potentially breaking some linking strategies. |
Yeah, this PR should be pretty safe (from the description, I didn't check the code), modulo the "mingw linker + mixed import-static library" case linked above. |
I'm definitely not a good reviewer for this. So let's r? @petrochenkov |
In the specific Either way I guess one workaround would be to allow up to one repetition. Perhaps only if the target linker is gcc/windows. Though I am slightly reluctant to introduce too many temporary hacks. |
This is true, @bors r+ , this is the most conservative deduplication strategy, and once the modifiers are implemented we'll probably end up with aggressive deduplication (and opt-out when necessary) which is compatible with what this PR does. |
📌 Commit e40faef has been approved by |
…trochenkov Deduplicate native libs before they are passed to the linker Stop spamming the linker with the same native library over and over again, if they directly follow from each other. This would help prevent [this situation](MSxDOS/ntapi#2). Issue rust-lang#38460 has been open since 2016 so I think it's worth making an incomplete fix that at least addresses the most common symptom and without otherwise changing how Rust handles native libs. This PR is intended to be easy to revert (if necessary) when a more permanent fix is implemented.
Seems unlikely. |
📌 Commit e40faef has been approved by |
⌛ Testing commit e40faef with merge b79abea265ac16320d751e3075208554fae99591... |
A job failed! Check out the build log: (web) (plain) Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
@bors retry network error |
☀️ Test successful - checks-actions |
…rochenkov native lib: defer the duplicate check after relevant_lib check. rust-lang#84794 break code using conditional-compilation with `#[link]` attributes. ```rust #[cfg(target_env = "musl")] cfg_if::cfg_if! { if #[cfg(any(target_feature = "crt-static", feature = "llvm-libunwind"))] { #[link(name = "unwind", kind = "static", modifiers = "-bundle")] extern "C" {} } else { #[link(name = "unwind", cfg(feature = "system-llvm-libunwind"))] #[link(name = "gcc_s", cfg(not(feature = "system-llvm-libunwind")))] extern "C" {} } } ```
Stop spamming the linker with the same native library over and over again, if they directly follow from each other. This would help prevent this situation.
Issue #38460 has been open since 2016 so I think it's worth making an incomplete fix that at least addresses the most common symptom and without otherwise changing how Rust handles native libs. This PR is intended to be easy to revert (if necessary) when a more permanent fix is implemented.