Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/naked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[naked] is now available on stable.

#[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;
Expand All @@ -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),*
);
};
}