Skip to content

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

Closed

Description

@lopopolo

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:

Activity

  1. CAD97 commented on Jun 28, 2022

    @CAD97

    extern "system" is also useful.

  2. lopopolo commented on Oct 22, 2022

    @lopopolo
    ContributorAuthor

    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.

  3. self-assigned this
    on Oct 22, 2022
  4. pvdrz commented on Oct 24, 2022

    @pvdrz
    Contributor

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

  5. CAD97 commented on Oct 24, 2022

    @CAD97

    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).

  6. pvdrz commented on Oct 24, 2022

    @pvdrz
    Contributor

    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?

  7. lopopolo commented on Oct 24, 2022

    @lopopolo
    ContributorAuthor

    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.

  8. schell commented on Nov 15, 2024

    @schell

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

  9. pvdrz commented on Nov 15, 2024

    @pvdrz
    Contributor

    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions