diff options
author | Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> | 2022-11-04 10:19:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-04 10:19:28 -0500 |
commit | 7c26cd218de85dca14a1c81b86e9d143626ce036 (patch) | |
tree | 8443ad2b0fea6c690aa60e09205b9b09b4cf3878 | |
parent | 9c32b460481903d90c6ac5df277bfa853a0558d8 (diff) |
Add support for the `"C-unwind"` ABI (#2334)
* Add support for the `"C-unwind"` ABI
This allows using `"C-unwind"` as an ABI override if the rust target is
nightly.
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | bindgen-cli/options.rs | 2 | ||||
-rw-r--r-- | bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs | 18 | ||||
-rw-r--r-- | bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h | 5 | ||||
-rw-r--r-- | bindgen/codegen/mod.rs | 15 | ||||
-rw-r--r-- | bindgen/features.rs | 5 | ||||
-rw-r--r-- | bindgen/ir/function.rs | 4 |
7 files changed, 49 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index baa5cb20..5f559a3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -150,6 +150,8 @@ ## Added * new feature: `--override-abi` flag to override the ABI used by functions matching a regular expression. + * new feature: allow using the `C-unwind` ABI in `--override-abi` on nightly + rust. ## Changed diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index c186cfd9..90f38cb2 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -570,7 +570,7 @@ where .help("Deduplicates extern blocks."), Arg::new("override-abi") .long("override-abi") - .help("Overrides the ABI of functions matching <regex>. The <override> value must be of the shape <abi>:<regex> where <abi> can be one of C, stdcall, fastcall, thiscall, aapcs or win64.") + .help("Overrides the ABI of functions matching <regex>. The <override> value must be of the shape <regex>=<abi> where <abi> can be one of C, stdcall, fastcall, thiscall, aapcs, win64 or C-unwind.") .value_name("override") .multiple_occurrences(true) .number_of_values(1), diff --git a/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs new file mode 100644 index 00000000..6b34192f --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs @@ -0,0 +1,18 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(feature = "nightly")] +#![feature(abi_thiscall)] + +extern "C-unwind" { + pub fn foo(); +} +extern "C-unwind" { + pub fn bar(); +} +extern "C" { + pub fn baz(); +} diff --git a/bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h b/bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h new file mode 100644 index 00000000..ac79a420 --- /dev/null +++ b/bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h @@ -0,0 +1,5 @@ +// bindgen-flags: --override-abi="foo|bar=C-unwind" --rust-target=nightly --raw-line '#![cfg(feature = "nightly")]' --raw-line '#![feature(abi_thiscall)]' + +void foo(); +void bar(); +void baz(); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 4e90102d..d0c19136 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2483,6 +2483,9 @@ impl MethodCodegen for Method { ClangAbi::Known(Abi::Vectorcall) => { ctx.options().rust_features().vectorcall_abi } + ClangAbi::Known(Abi::CUnwind) => { + ctx.options().rust_features().c_unwind_abi + } _ => true, }; @@ -4009,6 +4012,12 @@ impl TryToRustTy for FunctionSig { warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); Ok(proc_macro2::TokenStream::new()) } + ClangAbi::Known(Abi::CUnwind) + if !ctx.options().rust_features().c_unwind_abi => + { + warn!("Skipping function with C-unwind ABI that isn't supported by the configured Rust target"); + Ok(proc_macro2::TokenStream::new()) + } _ => Ok(quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret }), @@ -4120,6 +4129,12 @@ impl CodeGenerator for Function { warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); return None; } + ClangAbi::Known(Abi::CUnwind) + if !ctx.options().rust_features().c_unwind_abi => + { + warn!("Skipping function with C-unwind ABI that isn't supported by the configured Rust target"); + return None; + } ClangAbi::Known(Abi::Win64) if signature.is_variadic() => { warn!("Skipping variadic function with Win64 ABI that isn't supported"); return None; diff --git a/bindgen/features.rs b/bindgen/features.rs index 4f05b9eb..9f6535aa 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -133,6 +133,7 @@ macro_rules! rust_target_base { /// Nightly rust /// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) /// * `vectorcall` calling convention (no tracking issue) + /// * `c_unwind` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/74990)) => Nightly => nightly; ); } @@ -242,6 +243,7 @@ rust_feature_def!( Nightly { => thiscall_abi; => vectorcall_abi; + => c_unwind_abi; } ); @@ -291,7 +293,8 @@ mod test { f_nightly.maybe_uninit && f_nightly.repr_align && f_nightly.thiscall_abi && - f_nightly.vectorcall_abi + f_nightly.vectorcall_abi && + f_nightly.c_unwind_abi ); } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 8a70d60a..52346f6c 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -188,6 +188,8 @@ pub enum Abi { Aapcs, /// The "win64" ABI. Win64, + /// The "C-unwind" ABI. + CUnwind, } impl FromStr for Abi { @@ -202,6 +204,7 @@ impl FromStr for Abi { "vectorcall" => Ok(Self::Vectorcall), "aapcs" => Ok(Self::Aapcs), "win64" => Ok(Self::Win64), + "C-unwind" => Ok(Self::CUnwind), _ => Err(format!("Invalid or unknown ABI {:?}", s)), } } @@ -217,6 +220,7 @@ impl std::fmt::Display for Abi { Self::Vectorcall => "vectorcall", Self::Aapcs => "aapcs", Self::Win64 => "win64", + Self::CUnwind => "C-unwind", }; s.fmt(f) |