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

Document unwinding ABI extern "C" #672

Open
gnzlbg opened this issue Sep 6, 2019 · 3 comments
Open

Document unwinding ABI extern "C" #672

gnzlbg opened this issue Sep 6, 2019 · 3 comments
Labels
A-abi Area: ABI

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Sep 6, 2019

The current documentation of the extern "C" ABI in the reference says:

extern "C" -- This is the same as extern fn foo(); whatever the default your C compiler supports.

When it comes to whether C functions can unwind, the C compiler defaults on most platforms is that these cannot unwind. An exception is MSVC, where AFAICT all functions can always unwind (e.g. even C++ noexcept functions are allowed to be unwound by specific exceptions like, e.g., the one thrown by longjmp).

If this is actually the intended behavior we probably should not emit nounwind for extern "C" functions on Windows. That would have fixed rust-lang/rust#48251 in a different way since that would have allowed longjmps from C into Rust. In the LLVM issue different strategies to allowing nounwind there but fixing things at the LLVM level are being discussed: https://bugs.llvm.org/show_bug.cgi?id=36508.

So as written, whether extern "C" functions can unwind is platform dependent. Is this the intended behavior ? If so, we should clarify this. The earliest I can trace this documentation is 3461ff1

cc @Centril @nagisa @eddyb

@Centril
Copy link
Contributor

Centril commented Sep 7, 2019

That's an awfully vague description in the reference....

I don't think emitting nounwind should be platform dependent.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 7, 2019

So I just checked and MSVC does enable unwinding by default for C code: https://gcc.godbolt.org/z/-1Yu7T

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 30, 2019

I don't think emitting nounwind should be platform dependent.

Note that emitting nounwind might not need to be platform dependent to support what the reference currently says. Apparently, nounwind does not mean "does not unwind", but rather "does not unwind in certain specific ways that are platform dependent". So for MSVC targets, nounwind functions can actually unwind in some ways, and that's ok according to LLVM.

@ehuss ehuss added the A-abi Area: ABI label Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-abi Area: ABI
Projects
None yet
Development

No branches or pull requests

3 participants