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

WIP: Stable rust support #19

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft

Conversation

whentze
Copy link

@whentze whentze commented Oct 10, 2023

This is my attempt at making this crate (at least with default features) work on stable rust.
Mostly just putting this up to see what you think, so it's a draft PR for now.

It adds a proc macro dependency and makes the code uglier, so I understand if you think this is not worth the trouble.

The `extern "c-unwind"` ABI was stabilized in 1.71:
https://blog.rust-lang.org/2023/07/13/Rust-1.71.0.html#c-unwind-abi

There is still a nightly feature flag for this which covers the rest of that feature,
that being the guarantee that unwinding out of an `extern "C"` function safely aborts.
But this crate does not need that, so it's fine to remove the feature flag.
…` crate instead.

That crate provides an implementation of naked functions using `global_asm!` that works on stable.
It has a couple of limitations, which means a few changes to the code are required to make it work:
- The naked functions have to be `unsafe`, which `save_context` wasn't.
  I marked it unsafe and from looking at it that looks like the right idea to me anyway.
  After all, it takes a raw pointer and will write to it.
- The proc macro does not work well with interior `#[cfg]` attrs, so I had to put those on the entire items.
  This duplicates the functions signature and admittedly makes the code slightly uglier.
- Since `global_asm` doesn't support options(noreturn), I had to delete it.
  This could be a slight pessimization for codegen.
@nbdd0121
Copy link
Owner

The c_unwind shouldn't be removed until the final c_unwind stabilisation completes.

One issue with the naked function macro is that it will export additional symbols, where built-in naked function will not.

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 this pull request may close these issues.

2 participants