safer_ffi may randomly generate empty headers
pan93412 opened this issue · 6 comments
Abstract
Sometimes safer_ffi
generates an empty headers like the following screenshot on my Mac:
After setting up the breakpoint and debugging, I found that inventory::iter
ended up really fast – like nothing registered:
As it works on my another Ubuntu machine, I guess it is related to dtolnay/inventory#9? I tried to upgrade Inventory
to 3.0.1; however, the compilation failed:
Not really sure how to fix it.
Expected Behavior (on my Ubuntu machine)
Metadata
- rustc version: rustc 1.65.0-nightly (20ffea693 2022-08-11)
- cargo version cargo 1.65.0-nightly (ce40690a5 2022-08-09)
- OS version macOS Monterey 12.5 (ARM64)
- Reproducible Repo: https://github.com/pan93412/libstock-ffi/tree/e87b04cf6e1bd9394db656315f1dbd2975418c95
Thanks for the very detailed, link-backed, and extended report 🙏
[Continuing from #132]
Maybe we should report it to the upstream? Not sure about it.
Yeah, maybe; although if we do that we'd need to really reduce the example, right now there is too much safer-ffi
glue to report it to inventory.
Until then, you could try to work around the limitation, in and of itself, by making more mod
ules pub
, I guess:
-
e.g., using https://docs.rs/visibility
you could try to slap
#[cfg_attr(feature = "headers", visibility::make(pub))]
on yourmod
ules and see how it goes 🤷
It seems not working. However, the symbols exported from bin gen-headers
are less than those from the static library file – including “last_error_length” and something else:
Although my Ubuntu machine also did not export them, maybe we can find some clues inside these symbol tables?
(Note that I exported them with nc (binfile) > somewhere.txt
)
dtolnay/linkme#31 (comment) seems to suggest the inventory bug is still around 😬
@danielhenrymantilla I resolved it with a weird way – I switched my linker to mold (for macOS), and it seems work now…? 😂
I'll continue observing this issue, but at least it works at this moment 😄
Great news! Having a workaround for this ought to be quite useful, even if it's not an actual solution (e.g., somebody may need to use something different than mold for other reasons on their project 😅).
Let's close this issue since safer-ffi (nor inventory) can't really fix it, it's up to Cargo/rustc to do it.
But further discussion here is still welcome.