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

Support for generating bindings with the C-unwind ABI #2224

Closed
lopopolo opened this issue Jun 12, 2022 · 8 comments · Fixed by #2334
Closed

Support for generating bindings with the C-unwind ABI #2224

lopopolo opened this issue Jun 12, 2022 · 8 comments · Fixed by #2334
Assignees

Comments

@lopopolo
Copy link
Contributor

lopopolo commented Jun 12, 2022

Feature request for generating bindings with the C-unwind ABI for generated functions and function pointers. I'd love for this to be supported both via the bindgen Rust API and CLI.

See:

@CAD97
Copy link

CAD97 commented Jun 28, 2022

extern "system" is also useful.

@lopopolo
Copy link
Contributor Author

rust-lang/rust#101263 was just merged so as of the next nightly, structs with C-unwind fn pointers will be able to implement Debug. I believe this is unblocked.

@pvdrz pvdrz self-assigned this Oct 22, 2022
@pvdrz
Copy link
Contributor

pvdrz commented Oct 24, 2022

@lopopolo @CAD97. When would a function be tagged as extern "C-unwind" instead of extern "C" systematically?

@CAD97
Copy link

CAD97 commented Oct 24, 2022

A function MUST be marked extern "C-unwind" if it uses the C ABI (e.g. because it is linked by name e.g. between Rust and C/C++) and an unwind can ever cross it (e.g. a Rust panic or C++ exception). A function SHOULD be marked extern "C" if it is known that it will never be unwound over. A function MUST be extern "C" to be callable from standard C. (Most platforms offer a way to compile "unwind compatible" C, however, as well as of course extern "system".)

As far as I'm aware, on all current platforms which support extern "C-unwind", the only difference in ABI between "C" and "C-unwind" is out-of-band (i.e. using "C-unwind" where "C" is expected will cause no issues). However, an ABI where this is not the case is simple to imagine (e.g. a reserved exception pointer register rather than out-of-band unwinding).

@pvdrz
Copy link
Contributor

pvdrz commented Oct 24, 2022

ok my question is a bit less broad than that. How can bindgen determine from the headers if a function is C or C-unwind?

@lopopolo
Copy link
Contributor Author

My understanding is the decision to mark a function as C ABI or C-unwind ABI depends on whether the code is compiled with -fexceptions or C++ exceptions enabled.

This is an out of band configuration that is passed to the C/C++ compiler, so I'd expect a configuration option for bindgen to alter its behavior.

@schell
Copy link

schell commented Nov 15, 2024

It would also be nice to be able to specify an ABI override for function pointers stored in structs. Is that on the roadmap?

@pvdrz
Copy link
Contributor

pvdrz commented Nov 15, 2024

There is no roadmap here 🤣 . Jokes aside, if you can create an issue asking for this feature we can discuss its feasibility there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants