Skip to content
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

safer_ffi may randomly generate empty headers #131

Closed
pan93412 opened this issue Aug 13, 2022 · 6 comments
Closed

safer_ffi may randomly generate empty headers #131

pan93412 opened this issue Aug 13, 2022 · 6 comments
Labels
K-bug Kind: existing code isn’t behaving as expected M-wontfix-out-of-scope Marker: genuine issues which, alas, are beyond the scope of safer-ffi

Comments

@pan93412
Copy link

pan93412 commented Aug 13, 2022

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

@danielhenrymantilla danielhenrymantilla added the K-bug Kind: existing code isn’t behaving as expected label Aug 15, 2022
@danielhenrymantilla
Copy link
Collaborator

Thanks for the very detailed, link-backed, and extended report 🙏

@danielhenrymantilla
Copy link
Collaborator

danielhenrymantilla commented Aug 17, 2022

[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 🤷

@pan93412
Copy link
Author

pan93412 commented Aug 17, 2022

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)

@danielhenrymantilla
Copy link
Collaborator

danielhenrymantilla commented Aug 19, 2022

dtolnay/linkme#31 (comment) seems to suggest the inventory bug is still around 😬

@pan93412
Copy link
Author

@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 😄

@danielhenrymantilla
Copy link
Collaborator

danielhenrymantilla commented Aug 29, 2022

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.

@danielhenrymantilla danielhenrymantilla added the M-wontfix-out-of-scope Marker: genuine issues which, alas, are beyond the scope of safer-ffi label Aug 29, 2022
@danielhenrymantilla danielhenrymantilla closed this as not planned Won't fix, can't repro, duplicate, stale Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
K-bug Kind: existing code isn’t behaving as expected M-wontfix-out-of-scope Marker: genuine issues which, alas, are beyond the scope of safer-ffi
Projects
None yet
Development

No branches or pull requests

3 participants