-
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
Repeated #[link] attributes for the same library cause it to be passed as many times to the linker. #38460
Comments
As I mentioned on IRC, we could probably safely collapse repetitions of the same library. Beyond that, there's a risk of breaking someone. cc @retep998, @dgrunwald, @alexcrichton. |
While we can de-dupe libraries passed to the msvc linker, we should still be careful to preserve the order of the first mention of any given library, because if a symbol can come from several libraries, |
Item order is generally not something important in Rust. I hope with lld we can both deduplicate and ignore source order so only the set of names, and association between extern blocks and names, matter. Can lld be used for windows too any time soon, because simply picking the first provider of a symbol would seem to to violate the mapping of extern blocks and lib names, unless I am missing something. |
@Ericson2314 LLD has the same behavior as |
@retep998 So currently in all cases we cannot enforce that the symbol is linked from the requested block (except maybe macos where I hear unresolved symbols can mention a library name)? Bummer. IIRC the plan is to link lld into rustc. Perhaps that would make adding new functionality to lld to fix this issue more worthwhile. If what I said about macos is true, then perhaps lld already has some functionality for this under the hood as IIRC lld has mainly been used for that platform. |
@Ericson2314 At the moment there is no way to choose which library a symbol gets resolved from except to make sure that library comes first. The only way you'd be able to have full explicit control is if LLD one day adds that feature. |
@Ericson2314 When #58713 is implemented you will be able to guarantee a symbol comes from a certain library for a specific subset of cases. |
A more extreme case of this issue found in the wild: MSxDOS/ntapi#2 |
Information on how linker order matters for msvc: https://docs.microsoft.com/en-us/cpp/build/reference/link-input-files?view=vs-2019
|
This can cause linkage to fail entirely as described in #65847 |
…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.
…ochenkov 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.
In extreme cases this may cause trouble on Windows, where the maximum length of the command line is 32000 bytes. Also, may slow down linking.
The text was updated successfully, but these errors were encountered: