-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Linking to a static library does not always include exported symbols #99721
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
That's the nature of static library; there's not much we can do about it unless we squeeze everything into one single object file or reference all object files from every single one of them. |
That makes sense. I just found that you can force link the symbol with I'll resort to using the |
You need |
That won't work either. Object file inside static libs will not participate in linker if it does not provide any undefined symbol. SHF_GNU_RETAIN are not special in this regard. |
Yeah, that does not work unfortunately. |
There's a similar issue that can be fixed. You link a staticlib (written in C, or Rust, or whatever) to a binary, and you want to preserve some symbol from it. // bin.rs
#[link(name = "my_staticlib")]
extern "C" {
#[used(linker)]
fn some_symbol_from_my_staticlib_that_needs_to_be_kept();
#[used(linker)]
static SAME_BUT_STATIC: u8;
} Unfortunately, If it worked it would refer to the symbol in question from |
Interesting! Since in our use case we want to distribute the static library, this won't work. It's great that you can use |
For pulling in the right object files, |
I don't see how the linked PR would fix this issue. See #99721 (comment) |
As I said, because we reference |
This is a staticlib, |
Similarly to #47384, statics in a static library that are marked as
used
are not included in the resulting binary if a non-inlined function is used in the same module.Example
This code can be found at
mkroening/rust-issue-99721
.staticlib.rs
:bin.rs
:Build using:
Display static library notes:
Display binary notes:
If
note::dummy
is madeinline(never)
, the symbol is included in the resulting binary:The text was updated successfully, but these errors were encountered: