Conversation
src/os/unix/mod.rs
Outdated
| #[cfg_attr( | ||
| all( | ||
| any(target_os = "linux", target_os = "android"), | ||
| not(target_env = "musl") |
There was a problem hiding this comment.
The link attribute should still be specified, even if the symbols come from a library that's otherwise guaranteed to be linked in order to establish the correct link argument order during linking. See: freebsd/dragonfly below. The exception here is if these symbols get provided by the loader rather than libc, which is also common in bsd types.
Please double-check which approach musl uses.
There was a problem hiding this comment.
Additionally please add a test to gh actions workflow that tests this configuration.
|
I realize now that my initial description lacks any context of what the output I pasted is - I didn't completely understand what the build process in the project i was working on was doing as I was not its author and only knew that changing this line made it build - so I took a bit of time to understand it more. Now I know that the error is caused by my build process doing the wrong thing and not by libloading, but nevertheless the change could still be correct. In short: The Where
|
|
Hm, I'd rather not change anything in that case given that it has been working for a long time, but at the same time the suggested change in your comment above is actually providing the needed information most accurately, so if you want to adjust the PR to use that, it wouldn't be too terrible (and if it makes it link with plain rust-lld, that's just a side bonus.) Do note that |
Previously, -Clinker=rust-lld invoked the clang linker (lld) directly, without providing paths for additional libraries like libdl. -Clinker=clang invokes the clang compiler, which in turn invokes the same clang linker (implicitly clang receives -fuse-ld=lld argument, which is used to select the lld linker, which is the same as rust-lld), but additionally providing the required paths. This change is made to make crates that link to libraries other than just libc, like libdl, build without issues. These libraries are provided by musl libc, so we should be able to link with them properly. Additional details in a [github comment][1]. [1]: nagisa/rust_libloading#195 (comment) How the linker gets invoked can be observed by setting RUSTFLAGS="-Clink-arg=-v -Wlinker-messages" Signed-off-by: Marcel Guzik <marcel.guzik@cumulocity.com>
Provide --sysroot argument to rust-lld linker when compiling with musl, such that crates that wish to link with libraries like libdl (which are empty stubs but provided by musl) are able to do so. This change is made to make crates that link to libraries other than just libc, like libdl, build without issues. These libraries are provided by musl libc, so we should be able to link with them properly. Additional details in a [github comment][1]. [1]: nagisa/rust_libloading#195 (comment) How the linker gets invoked can be observed by setting RUSTFLAGS="-Clink-arg=-v -Wlinker-messages" Signed-off-by: Marcel Guzik <marcel.guzik@cumulocity.com>
On musl dlopen is part of libc and there's no separate libdl. Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
|
Fixed up the link attribute and included a test for the configuration (which should be failing without the link attribute change). Not completely happy though about having to create a somewhat useless example target just for this build test, but I'm not sure if there's a better approach. |
Provide --sysroot argument to rust-lld linker when compiling with musl, such that crates that wish to link with libraries like libdl (which are empty stubs but provided by musl) are able to do so. This change is made to make crates that link to libraries other than just libc, like libdl, build without issues. These libraries are provided by musl libc, so we should be able to link with them properly. Additional details in a [github comment][1]. [1]: nagisa/rust_libloading#195 (comment) How the linker gets invoked can be observed by setting RUSTFLAGS="-Clink-arg=-v -Wlinker-messages" Signed-off-by: Marcel Guzik <marcel.guzik@cumulocity.com>
On musl dlopen is part of libc and there's no separate libdl.
I 'm using cryptoki crate, which uses libloading, and using cargo-zigbuild to compile for
x86_64-unknown-linux-musl.Without the change, I get the following error: