Skip to content

Commit 7c26cd2

Browse files
authored
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.
1 parent 9c32b46 commit 7c26cd2

File tree

7 files changed

+49
-2
lines changed

7 files changed

+49
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@
150150
## Added
151151
* new feature: `--override-abi` flag to override the ABI used by functions
152152
matching a regular expression.
153+
* new feature: allow using the `C-unwind` ABI in `--override-abi` on nightly
154+
rust.
153155

154156
## Changed
155157

bindgen-cli/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ where
570570
.help("Deduplicates extern blocks."),
571571
Arg::new("override-abi")
572572
.long("override-abi")
573-
.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.")
573+
.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.")
574574
.value_name("override")
575575
.multiple_occurrences(true)
576576
.number_of_values(1),

bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// bindgen-flags: --override-abi="foo|bar=C-unwind" --rust-target=nightly --raw-line '#![cfg(feature = "nightly")]' --raw-line '#![feature(abi_thiscall)]'
2+
3+
void foo();
4+
void bar();
5+
void baz();

bindgen/codegen/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,9 @@ impl MethodCodegen for Method {
24832483
ClangAbi::Known(Abi::Vectorcall) => {
24842484
ctx.options().rust_features().vectorcall_abi
24852485
}
2486+
ClangAbi::Known(Abi::CUnwind) => {
2487+
ctx.options().rust_features().c_unwind_abi
2488+
}
24862489
_ => true,
24872490
};
24882491

@@ -4009,6 +4012,12 @@ impl TryToRustTy for FunctionSig {
40094012
warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target");
40104013
Ok(proc_macro2::TokenStream::new())
40114014
}
4015+
ClangAbi::Known(Abi::CUnwind)
4016+
if !ctx.options().rust_features().c_unwind_abi =>
4017+
{
4018+
warn!("Skipping function with C-unwind ABI that isn't supported by the configured Rust target");
4019+
Ok(proc_macro2::TokenStream::new())
4020+
}
40124021
_ => Ok(quote! {
40134022
unsafe extern #abi fn ( #( #arguments ),* ) #ret
40144023
}),
@@ -4120,6 +4129,12 @@ impl CodeGenerator for Function {
41204129
warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target");
41214130
return None;
41224131
}
4132+
ClangAbi::Known(Abi::CUnwind)
4133+
if !ctx.options().rust_features().c_unwind_abi =>
4134+
{
4135+
warn!("Skipping function with C-unwind ABI that isn't supported by the configured Rust target");
4136+
return None;
4137+
}
41234138
ClangAbi::Known(Abi::Win64) if signature.is_variadic() => {
41244139
warn!("Skipping variadic function with Win64 ABI that isn't supported");
41254140
return None;

bindgen/features.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ macro_rules! rust_target_base {
133133
/// Nightly rust
134134
/// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
135135
/// * `vectorcall` calling convention (no tracking issue)
136+
/// * `c_unwind` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/74990))
136137
=> Nightly => nightly;
137138
);
138139
}
@@ -242,6 +243,7 @@ rust_feature_def!(
242243
Nightly {
243244
=> thiscall_abi;
244245
=> vectorcall_abi;
246+
=> c_unwind_abi;
245247
}
246248
);
247249

@@ -291,7 +293,8 @@ mod test {
291293
f_nightly.maybe_uninit &&
292294
f_nightly.repr_align &&
293295
f_nightly.thiscall_abi &&
294-
f_nightly.vectorcall_abi
296+
f_nightly.vectorcall_abi &&
297+
f_nightly.c_unwind_abi
295298
);
296299
}
297300

bindgen/ir/function.rs

+4
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ pub enum Abi {
188188
Aapcs,
189189
/// The "win64" ABI.
190190
Win64,
191+
/// The "C-unwind" ABI.
192+
CUnwind,
191193
}
192194

193195
impl FromStr for Abi {
@@ -202,6 +204,7 @@ impl FromStr for Abi {
202204
"vectorcall" => Ok(Self::Vectorcall),
203205
"aapcs" => Ok(Self::Aapcs),
204206
"win64" => Ok(Self::Win64),
207+
"C-unwind" => Ok(Self::CUnwind),
205208
_ => Err(format!("Invalid or unknown ABI {:?}", s)),
206209
}
207210
}
@@ -217,6 +220,7 @@ impl std::fmt::Display for Abi {
217220
Self::Vectorcall => "vectorcall",
218221
Self::Aapcs => "aapcs",
219222
Self::Win64 => "win64",
223+
Self::CUnwind => "C-unwind",
220224
};
221225

222226
s.fmt(f)

0 commit comments

Comments
 (0)