getditto/safer_ffi

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:

截圖 2022-08-13 下午7 44 03

After setting up the breakpoint and debugging, I found that inventory::iter ended up really fast – like nothing registered:

image

image

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:

截圖 2022-08-13 下午7 57 16

Not really sure how to fix it.

Expected Behavior (on my Ubuntu machine)

截圖 2022-08-13 下午7 59 25

Metadata

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 modules pub, I guess:

  • e.g., using https://docs.rs/visibility

    you could try to slap #[cfg_attr(feature = "headers", visibility::make(pub))] on your modules and see how it goes 🤷

image

image

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…? 😂

Switch zld to mold, and header generation works 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.