From 92400cc783d1437b5ed2ccea29825ddc24746d3e Mon Sep 17 00:00:00 2001 From: Leon Vak Date: Sun, 11 Jan 2026 10:42:12 +0200 Subject: [PATCH] Fix .type directive syntax for ARM targets ARM GNU assembler uses %function instead of @function for the .type directive. This was causing build failures on arm-unknown-linux-gnueabihf. --- src/naked.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/naked.rs b/src/naked.rs index a5f285b..423052f 100644 --- a/src/naked.rs +++ b/src/naked.rs @@ -54,7 +54,10 @@ macro_rules! naked_fn { /// `#[naked]` is nightly-only. We use it when we can, and fall back to /// `global_asm` otherwise. This macro supports a limited subset of the /// features of `#[naked]`. -#[cfg(not(feature = "nightly"))] +/// +/// Note: ARM targets use `%function` syntax for the .type directive, +/// while other targets use `@function`. +#[cfg(all(not(feature = "nightly"), not(target_arch = "arm")))] macro_rules! naked_fn { ( $doc:literal; @@ -76,3 +79,27 @@ macro_rules! naked_fn { ); }; } + +/// ARM variant using `%function` syntax. +#[cfg(all(not(feature = "nightly"), target_arch = "arm"))] +macro_rules! naked_fn { + ( + $doc:literal; + $vis:vis fn $name:ident $args:tt -> $ret:ty; + $($code:literal),*; + $($label:ident = $kind:ident $path:path),* + ) => { + unsafe extern "C" { + #[doc = $doc] + $vis fn $name $args -> $ret; + } + core::arch::global_asm!( + concat!(".global ", stringify!($name)), + concat!(".type ", stringify!($name), ", %function"), + concat!(stringify!($name), ":"), + $($code),*, + concat!(".size ", stringify!($name), ", .-", stringify!($name)), + $($label = $kind $path),* + ); + }; +}