Skip to content

Commit e8e6722

Browse files
committed
Cleanup manged-names macro
Don't generate the whole function if we are not going to use `no_mangle`, there is no point
1 parent bf0617b commit e8e6722

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

src/macros.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ macro_rules! intrinsics {
250250
$($body)*
251251
}
252252

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

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

303-
#[cfg(target_arch = "arm")]
304-
pub mod $alias {
305-
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
303+
#[cfg(all(target_arch = "arm", not(feature = "mangled-names")))]
304+
mod $alias {
305+
#[no_mangle]
306306
#[cfg_attr(all(not(windows), not(target_vendor="apple")), linkage = "weak")]
307-
pub extern "aapcs" fn $alias( $($argname: $ty),* ) $(-> $ret)? {
307+
extern "aapcs" fn $alias( $($argname: $ty),* ) $(-> $ret)? {
308308
super::$name($($argname),*)
309309
}
310310
}
@@ -335,12 +335,12 @@ macro_rules! intrinsics {
335335
$($body)*
336336
}
337337

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

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

429-
pub mod $name {
430+
#[cfg(not(feature = "mangled-names"))]
431+
mod $name {
430432
$(#[$($attr)*])*
431-
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
433+
#[no_mangle]
432434
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
433-
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
435+
extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
434436
super::$name($($argname),*)
435437
}
436438
}
@@ -452,11 +454,12 @@ macro_rules! intrinsics {
452454
$($body)*
453455
}
454456

455-
pub mod $name {
457+
#[cfg(not(feature = "mangled-names"))]
458+
mod $name {
456459
$(#[$($attr)*])*
457-
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
460+
#[no_mangle]
458461
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
459-
pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
462+
unsafe fn $name( $($argname: $ty),* ) $(-> $ret)? {
460463
super::$name($($argname),*)
461464
}
462465
}

0 commit comments

Comments
 (0)