-
Notifications
You must be signed in to change notification settings - Fork 13k
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
dylib
shared libraries will not make public symbols that may be necessary to link inlined code
#65610
Comments
Yeah, I can imagine that that doesn't work. Maybe #59752 is related? |
cc @Zoxc |
You haven't told rustc where that symbol comes from. Try adding |
Adding the attribute helped, however these symbols are originally linked via command line arguments that |
When you link the library on the command line, rustc doesn't know which symbols are in it, so it won't export any. |
Okay, that’s somewhat bad, then, because libraries that rely exclusively on arguments emitted by We should look at updating the |
We could perhaps just consider all reachable extern fns to have static linkage and export them. I'm not sure if there's any problems with that though... |
I don't think you need the |
As of recently it is no longer sufficient to just build the `libX.a` with the cc crate in build.rs. Due to rust-lang/rust#65610 it is also necessary to specify the fact of linkage in the source for it to work in all scenarios. The most frustrating part is that it only fails when shared libraries are in the equation, which is a comparatively rare use-case in Rust-land.
As of recently it is no longer sufficient to just build the `libX.a` with the cc crate in build.rs. Due to rust-lang/rust#65610 it is also necessary to specify the fact of linkage in the source for it to work in all scenarios. The most frustrating part is that it only fails when shared libraries are in the equation, which is a comparatively rare use-case in Rust-land.
@rustbot modify labels to +I-prioritize |
Summary of current situation: In order for a symbol pulled in from a native library to be exported from a
Therefore to solve this problem we need to:
|
I’ve seen this mistake one too many times. And it tends to remain that way because just
possibly could be a clippy lint too. |
Note that if symbols are spread across multiple extern blocks, having to annotate each of them with the appropriate Also note that on Windows it is possible for a library to have both static and dynamic symbols. Perhaps it may be worthwhile to allow us to specify whether a symbol comes from a static library or a dynamic library without having to name it. Allowing |
Assigning |
When a
dylib
crate has a publicinline(always)
functions in it that use, as an implementation, other, private functions, using these public functions from other crates will fail with linkage errors because we fail to "export" the private functions.An example project can be seen here. In this example the
driver
dylib crate privatelyextern
s a symbol from a static C library and uses it to implement aninline(always)
interface/wrapper. Theuser
crate then attempts to use theinline(always)
wrapper, but linking fails with an error such as this:When inspecting the
libdriver.so
we can see that the extern symbol does indeed exist but is "private":I think we might be un-exporting items too aggressively here. cc @michaelwoerister @oli-obk
Blocks #55617
Regression from 1.36.0 (example builds successfully) to 1.37 (example fails to build).
The text was updated successfully, but these errors were encountered: