Skip to content

Commit

Permalink
Cleanup manged-names macro
Browse files Browse the repository at this point in the history
Don't generate the whole function if we are not going to use `no_mangle`, there is no point
  • Loading branch information
Amjad50 authored and Amanieu committed May 3, 2024
1 parent 16c9ca9 commit 8a7ba9a
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ macro_rules! intrinsics {
$($body)*
}

#[cfg(all(any(windows, target_os = "uefi"), target_arch = "x86_64"))]
pub mod $name {
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
#[cfg(all(any(windows, target_os = "uefi"), target_arch = "x86_64", not(feature = "mangled-names")))]
mod $name {
#[no_mangle]
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
pub extern $abi fn $name( $($argname: $ty),* )
extern $abi fn $name( $($argname: $ty),* )
-> $crate::macros::win64_128bit_abi_hack::U64x2
{
let e: $($ret)? = super::$name($($argname),*);
Expand Down Expand Up @@ -291,20 +291,20 @@ macro_rules! intrinsics {
$($body)*
}

#[cfg(target_arch = "arm")]
pub mod $name {
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
#[cfg(all(target_arch = "arm", not(feature = "mangled-names")))]
mod $name {
#[no_mangle]
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
super::$name($($argname),*)
}
}

#[cfg(target_arch = "arm")]
pub mod $alias {
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
#[cfg(all(target_arch = "arm", not(feature = "mangled-names")))]
mod $alias {
#[no_mangle]
#[cfg_attr(all(not(windows), not(target_vendor="apple")), linkage = "weak")]
pub extern "aapcs" fn $alias( $($argname: $ty),* ) $(-> $ret)? {
extern "aapcs" fn $alias( $($argname: $ty),* ) $(-> $ret)? {
super::$name($($argname),*)
}
}
Expand Down Expand Up @@ -335,12 +335,12 @@ macro_rules! intrinsics {
$($body)*
}

#[cfg(feature = "mem")]
pub mod $name {
#[cfg(all(feature = "mem", not(feature = "mangled-names")))]
mod $name {
$(#[$($attr)*])*
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
#[no_mangle]
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
super::$name($($argname),*)
}
}
Expand All @@ -359,6 +359,7 @@ macro_rules! intrinsics {

$($rest:tt)*
) => (
// `#[naked]` definitions are referenced by other places, so we can't use `cfg` like the others
pub mod $name {
#[naked]
$(#[$($attr)*])*
Expand Down Expand Up @@ -426,11 +427,12 @@ macro_rules! intrinsics {
$($body)*
}

pub mod $name {
#[cfg(not(feature = "mangled-names"))]
mod $name {
$(#[$($attr)*])*
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
#[no_mangle]
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
super::$name($($argname),*)
}
}
Expand All @@ -452,11 +454,12 @@ macro_rules! intrinsics {
$($body)*
}

pub mod $name {
#[cfg(not(feature = "mangled-names"))]
mod $name {
$(#[$($attr)*])*
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
#[no_mangle]
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
unsafe fn $name( $($argname: $ty),* ) $(-> $ret)? {
super::$name($($argname),*)
}
}
Expand Down

0 comments on commit 8a7ba9a

Please sign in to comment.