-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
native_libs: More consistent native library search between rustc and linker #138170
Conversation
Some changes occurred in compiler/rustc_codegen_ssa |
I'll post this alternative as well, and do a couple of other experiments, before considering this PR for merging. |
☔ The latest upstream changes (presumably #138202) made this pull request unmergeable. Please resolve the merge conflicts. |
Moving the information about bundled libraries from regular metadata (where it's not necessary) to some kind of rlib digest (#138243) will help to avoid doing any kind of library lookup in |
metadata: Ignore sysroot when doing the manual native lib search in rustc This is the opposite alternative to rust-lang#138170 and another way to make native library search consistent between rustc and linker. This way the directory list searched by rustc is still a prefix of the directory list considered by linker, but it's a shorter prefix than in rust-lang#138170. We can include the sysroot directories into rustc's search again later if the issues with rust-lang#138170 are resolved, it will be a backward compatible change. This may break some code doing weird things on unstable rustc, or tier 2-3 targets, like bundling `libunwind.a` or sanitizers into something. Note that this doesn't affect shipped `libc.a`, because it lives in `self-contained` directories in sysroot, and `self-contained` sysroot is already not included into the rustc's search. All libunwind and sanitizer libs should be moved to `self-contained` sysroot too eventually. With the consistent search directory list between rustc and linker we can make rustc own the native library search (at least for static libs) and use linker search only as a fallback (like in rust-lang#123436). This will allow addressing issues like rust-lang#132394 once and for all on all targets. r? `@bjorn3`
metadata: Ignore sysroot when doing the manual native lib search in rustc This is the opposite alternative to rust-lang#138170 and another way to make native library search consistent between rustc and linker. This way the directory list searched by rustc is still a prefix of the directory list considered by linker, but it's a shorter prefix than in rust-lang#138170. We can include the sysroot directories into rustc's search again later if the issues with rust-lang#138170 are resolved, it will be a backward compatible change. This may break some code doing weird things on unstable rustc, or tier 2-3 targets, like bundling `libunwind.a` or sanitizers into something. Note that this doesn't affect shipped `libc.a`, because it lives in `self-contained` directories in sysroot, and `self-contained` sysroot is already not included into the rustc's search. All libunwind and sanitizer libs should be moved to `self-contained` sysroot too eventually. With the consistent search directory list between rustc and linker we can make rustc own the native library search (at least for static libs) and use linker search only as a fallback (like in rust-lang#123436). This will allow addressing issues like rust-lang#132394 once and for all on all targets. r? ``@bjorn3``
Rollup merge of rust-lang#138273 - petrochenkov:nonatroot, r=bjorn3 metadata: Ignore sysroot when doing the manual native lib search in rustc This is the opposite alternative to rust-lang#138170 and another way to make native library search consistent between rustc and linker. This way the directory list searched by rustc is still a prefix of the directory list considered by linker, but it's a shorter prefix than in rust-lang#138170. We can include the sysroot directories into rustc's search again later if the issues with rust-lang#138170 are resolved, it will be a backward compatible change. This may break some code doing weird things on unstable rustc, or tier 2-3 targets, like bundling `libunwind.a` or sanitizers into something. Note that this doesn't affect shipped `libc.a`, because it lives in `self-contained` directories in sysroot, and `self-contained` sysroot is already not included into the rustc's search. All libunwind and sanitizer libs should be moved to `self-contained` sysroot too eventually. With the consistent search directory list between rustc and linker we can make rustc own the native library search (at least for static libs) and use linker search only as a fallback (like in rust-lang#123436). This will allow addressing issues like rust-lang#132394 once and for all on all targets. r? ``@bjorn3``
Continuation of #129366.
Typically rustc will delegate native library search to linker, by passing to it library search directory options, like
-L
or equivalents.In some cases, however, rustc will search for native libraries "manually", by itself.
-force_load
withld64
, which is required to implement+whole-archive
, and only accepts full paths instead of nameslibfoo.a
on MSVC (linker: Allow MSVC to use import libraries following the Meson/MinGW convention #123436)It is important for the rustc search and for the linker search to give the same result (modulo cases
1.
and3.
, where the difference is intentional).It is not always possible, because linkers may also search for some default system directories that depend on a specific system and are hard to predict in general.
So we can make a weaker requirement (*) - the directory list searched by rustc must be a prefix of the directory list considered by linker.
In this PR I try to use the full list of directories passed as
-L
s to linker for rustc's search as well.Besides directories explicitly provided by user, it also includes sysroot,
self-contained
sysroot and some SDK directories on Apple targets.This is not a full solution, because the library bundling logic in
rustc_metadata
(as opposed torustc_codegen_ssa
) still skipsself-contained
sysroot and the Apple SDK directories.Determining
self_contained_components
andapple_sdk_root
requires a large chunk of linker-probing logic to be available inrustc_metadata
, which generally doesn't do any linking at all.On the other hand, turning
get_self_contained_components()
andget_apple_sdk_root()
into queries to avoid reevaluating them from different places is also pretty annoying, because the logic inrustc_codegen_ssa
cannot use queries, so they would need to be evaluated earlier and the results would need to be stored inCodegenResults
.I'm not yet sure this is the right direction, maybe we should instead exclude all kinds of sysroots from the rustc's "manual" native library search. That would satisfy the requirement (*) as well.
r? @bjorn3