From 051468e3890ae559fd908665d6cff31e52594836 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 4 Feb 2026 17:46:31 +0100 Subject: [PATCH 1/2] handle outer unsafe for whitelisted attributes --- aarch32-rt-macros/src/lib.rs | 15 +++++++++++++++ .../mps3-an536/src/bin/prefetch-exception-a32.rs | 2 ++ 2 files changed, 17 insertions(+) diff --git a/aarch32-rt-macros/src/lib.rs b/aarch32-rt-macros/src/lib.rs index 4feb8ef..e3f3f73 100644 --- a/aarch32-rt-macros/src/lib.rs +++ b/aarch32-rt-macros/src/lib.rs @@ -455,6 +455,21 @@ fn check_attr_whitelist(attrs: &[Attribute], caller: VectorKind) -> Result<(), T ]; 'o: for attr in attrs { + // Also check whatever is wrapped inside `unsafe(...)` + if attr.path().is_ident("unsafe") { + let mut whitelisted = false; + let _ = attr.parse_nested_meta(|meta| { + for val in whitelist { + if meta.path.is_ident(val) { + whitelisted = true; + } + } + Ok(()) + }); + if whitelisted { + continue 'o; + } + } for val in whitelist { if eq(attr, val) { continue 'o; diff --git a/examples/mps3-an536/src/bin/prefetch-exception-a32.rs b/examples/mps3-an536/src/bin/prefetch-exception-a32.rs index 2f3a59d..1425b96 100644 --- a/examples/mps3-an536/src/bin/prefetch-exception-a32.rs +++ b/examples/mps3-an536/src/bin/prefetch-exception-a32.rs @@ -49,7 +49,9 @@ core::arch::global_asm!( "# ); +// Custom link sections are allowed as well. #[exception(Undefined)] +#[unsafe(link_section = ".text._rust_undefined_handler")] fn undefined_handler(_addr: usize) -> ! { panic!("unexpected undefined exception"); } From e23e5750a712fa111dd88fd88ca9400f08d15118 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 4 Feb 2026 17:47:36 +0100 Subject: [PATCH 2/2] changelog --- aarch32-rt-macros/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aarch32-rt-macros/CHANGELOG.md b/aarch32-rt-macros/CHANGELOG.md index 344634a..0956330 100644 --- a/aarch32-rt-macros/CHANGELOG.md +++ b/aarch32-rt-macros/CHANGELOG.md @@ -10,6 +10,9 @@ As of *aarch32-rt-macros v0.1.0*, this project is released in lock-step with ## [Unreleased] +- Handle outer `unsafe` for whitelisted proc macro attributes. For example, this allows + `#[unsafe(link_section="...")]` which previously did not work. + ## [aarch32-rt-macros v0.2.0] - Changed `#[entry]`, `#[exception]` and `#[irq]` to hide the handler function