From 130180674c493b767373d63f32f660773df75c29 Mon Sep 17 00:00:00 2001 From: Lowie Deferme Date: Wed, 16 Jul 2025 15:13:39 +0200 Subject: [PATCH 1/3] Check for CMSE ABI's as well --- src/bindgen/parser.rs | 2 +- src/bindgen/utilities.rs | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/bindgen/parser.rs b/src/bindgen/parser.rs index 3a00bd90b..bc6eb1935 100644 --- a/src/bindgen/parser.rs +++ b/src/bindgen/parser.rs @@ -728,7 +728,7 @@ impl Parse { items.join("::") }; - let is_extern_c = sig.abi.is_omitted() || sig.abi.is_c(); + let is_extern_c = sig.abi.is_omitted() || sig.abi.is_c() || sig.abi.is_cmse(); let exported_name = named_symbol.exported_name(); match (is_extern_c, exported_name) { diff --git a/src/bindgen/utilities.rs b/src/bindgen/utilities.rs index f40583130..f7ce7b88b 100644 --- a/src/bindgen/utilities.rs +++ b/src/bindgen/utilities.rs @@ -371,24 +371,19 @@ impl_syn_item_helper!(syn::ItemTraitAlias); /// Helper function for accessing Abi information pub trait SynAbiHelpers { fn is_c(&self) -> bool; + fn is_cmse(&self) -> bool; fn is_omitted(&self) -> bool; } impl SynAbiHelpers for Option { fn is_c(&self) -> bool { - if let Some(ref abi) = *self { - if let Some(ref lit_string) = abi.name { - return matches!(lit_string.value().as_str(), "C" | "C-unwind"); - } - } - false + self.as_ref().is_some_and(|abi| abi.is_c()) + } + fn is_cmse(&self) -> bool { + self.as_ref().is_some_and(|abi| abi.is_cmse()) } fn is_omitted(&self) -> bool { - if let Some(ref abi) = *self { - abi.name.is_none() - } else { - false - } + self.as_ref().is_some_and(|abi| abi.is_omitted()) } } @@ -400,6 +395,16 @@ impl SynAbiHelpers for syn::Abi { false } } + fn is_cmse(&self) -> bool { + if let Some(ref lit_string) = self.name { + return matches!( + lit_string.value().as_str(), + "cmse-nonsecure-entry" | "cmse-nonsecure-call" + ); + } else { + false + } + } fn is_omitted(&self) -> bool { self.name.is_none() } From 7fc717c4da2ba27739966a44a7196958ffa1c75c Mon Sep 17 00:00:00 2001 From: Lowie Deferme Date: Thu, 17 Jul 2025 08:15:09 +0200 Subject: [PATCH 2/3] Remove unneeded return statement --- src/bindgen/utilities.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindgen/utilities.rs b/src/bindgen/utilities.rs index f7ce7b88b..b925ceb66 100644 --- a/src/bindgen/utilities.rs +++ b/src/bindgen/utilities.rs @@ -397,10 +397,10 @@ impl SynAbiHelpers for syn::Abi { } fn is_cmse(&self) -> bool { if let Some(ref lit_string) = self.name { - return matches!( + matches!( lit_string.value().as_str(), "cmse-nonsecure-entry" | "cmse-nonsecure-call" - ); + ) } else { false } From 6ebd19f7af1bf6f35acb9d83ded63b359e1a5f4c Mon Sep 17 00:00:00 2001 From: Lowie Deferme Date: Wed, 30 Jul 2025 08:36:28 +0200 Subject: [PATCH 3/3] Add test for CMSE ABIs --- tests/expectations-symbols/cmse.c.sym | 4 ++++ tests/expectations/cmse.c | 8 ++++++++ tests/expectations/cmse.compat.c | 16 ++++++++++++++++ tests/expectations/cmse.cpp | 13 +++++++++++++ tests/expectations/cmse.pyx | 11 +++++++++++ tests/rust/cmse.rs | 5 +++++ 6 files changed, 57 insertions(+) create mode 100644 tests/expectations-symbols/cmse.c.sym create mode 100644 tests/expectations/cmse.c create mode 100644 tests/expectations/cmse.compat.c create mode 100644 tests/expectations/cmse.cpp create mode 100644 tests/expectations/cmse.pyx create mode 100644 tests/rust/cmse.rs diff --git a/tests/expectations-symbols/cmse.c.sym b/tests/expectations-symbols/cmse.c.sym new file mode 100644 index 000000000..5d8dd399d --- /dev/null +++ b/tests/expectations-symbols/cmse.c.sym @@ -0,0 +1,4 @@ +{ +foo; +bar; +}; \ No newline at end of file diff --git a/tests/expectations/cmse.c b/tests/expectations/cmse.c new file mode 100644 index 000000000..12d24d87b --- /dev/null +++ b/tests/expectations/cmse.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include + +void foo(void); + +void bar(void); diff --git a/tests/expectations/cmse.compat.c b/tests/expectations/cmse.compat.c new file mode 100644 index 000000000..f9da63723 --- /dev/null +++ b/tests/expectations/cmse.compat.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +void foo(void); + +void bar(void); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/tests/expectations/cmse.cpp b/tests/expectations/cmse.cpp new file mode 100644 index 000000000..f30259548 --- /dev/null +++ b/tests/expectations/cmse.cpp @@ -0,0 +1,13 @@ +#include +#include +#include +#include +#include + +extern "C" { + +void foo(); + +void bar(); + +} // extern "C" diff --git a/tests/expectations/cmse.pyx b/tests/expectations/cmse.pyx new file mode 100644 index 000000000..51d33db66 --- /dev/null +++ b/tests/expectations/cmse.pyx @@ -0,0 +1,11 @@ +from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t +cdef extern from *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + void foo(); + + void bar(); diff --git a/tests/rust/cmse.rs b/tests/rust/cmse.rs new file mode 100644 index 000000000..e5878f33f --- /dev/null +++ b/tests/rust/cmse.rs @@ -0,0 +1,5 @@ +#[no_mangle] +pub extern "cmse-nonsecure-entry" fn foo() {} + +#[no_mangle] +pub extern "cmse-nonsecure-call" fn bar() {}