From e73bc98c1bd7f61b7c80b9e9cfc587a9ac316666 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 10 Jul 2024 04:20:23 -0400 Subject: [PATCH 1/4] Revert "Add Apple visionOS support" This reverts commit f35530f8f6e3debeed8383943de1b506501302ec. --- build.rs | 13 +++++++++++-- src/arm.rs | 30 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/build.rs b/build.rs index 34467d8f5..f0b46828b 100644 --- a/build.rs +++ b/build.rs @@ -378,7 +378,11 @@ mod c { // On iOS and 32-bit OSX these are all just empty intrinsics, no need to // include them. - if target_vendor != "apple" || target_arch != "x86" { + if target_os != "ios" + && target_os != "watchos" + && target_os != "tvos" + && (target_vendor != "apple" || target_arch != "x86") + { sources.extend(&[ ("__absvti2", "absvti2.c"), ("__addvti3", "addvti3.c"), @@ -428,7 +432,12 @@ mod c { } } - if target_arch == "arm" && target_vendor != "apple" && target_env != "msvc" { + if target_arch == "arm" + && target_os != "ios" + && target_os != "watchos" + && target_os != "tvos" + && target_env != "msvc" + { sources.extend(&[ ("__aeabi_div0", "arm/aeabi_div0.c"), ("__aeabi_drsub", "arm/aeabi_drsub.c"), diff --git a/src/arm.rs b/src/arm.rs index 55cdda1f3..dcae22b73 100644 --- a/src/arm.rs +++ b/src/arm.rs @@ -3,14 +3,14 @@ use core::intrinsics; -// Apple symbols have a leading underscore. -#[cfg(target_vendor = "apple")] +// iOS symbols have a leading underscore. +#[cfg(target_os = "ios")] macro_rules! bl { ($func:literal) => { concat!("bl _", $func) }; } -#[cfg(not(target_vendor = "apple"))] +#[cfg(not(target_os = "ios"))] macro_rules! bl { ($func:literal) => { concat!("bl ", $func) @@ -82,12 +82,12 @@ intrinsics! { // FIXME: The `*4` and `*8` variants should be defined as aliases. - #[cfg(not(target_vendor = "apple"))] + #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: usize) { crate::mem::memcpy(dest, src, n); } - #[cfg(not(target_vendor = "apple"))] + #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memcpy4(dest: *mut u8, src: *const u8, n: usize) { // We are guaranteed 4-alignment, so accessing at u32 is okay. let mut dest = dest as *mut u32; @@ -104,33 +104,33 @@ intrinsics! { __aeabi_memcpy(dest as *mut u8, src as *const u8, n); } - #[cfg(not(target_vendor = "apple"))] + #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memcpy8(dest: *mut u8, src: *const u8, n: usize) { __aeabi_memcpy4(dest, src, n); } - #[cfg(not(target_vendor = "apple"))] + #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memmove(dest: *mut u8, src: *const u8, n: usize) { crate::mem::memmove(dest, src, n); } - #[cfg(not(any(target_vendor = "apple", target_env = "msvc")))] + #[cfg(not(any(target_os = "ios", target_env = "msvc")))] pub unsafe extern "aapcs" fn __aeabi_memmove4(dest: *mut u8, src: *const u8, n: usize) { __aeabi_memmove(dest, src, n); } - #[cfg(not(any(target_vendor = "apple", target_env = "msvc")))] + #[cfg(not(any(target_os = "ios", target_env = "msvc")))] pub unsafe extern "aapcs" fn __aeabi_memmove8(dest: *mut u8, src: *const u8, n: usize) { __aeabi_memmove(dest, src, n); } - #[cfg(not(target_vendor = "apple"))] + #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memset(dest: *mut u8, n: usize, c: i32) { // Note the different argument order crate::mem::memset(dest, c, n); } - #[cfg(not(target_vendor = "apple"))] + #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memset4(dest: *mut u8, n: usize, c: i32) { let mut dest = dest as *mut u32; let mut n = n; @@ -147,22 +147,22 @@ intrinsics! { __aeabi_memset(dest as *mut u8, n, byte as i32); } - #[cfg(not(target_vendor = "apple"))] + #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memset8(dest: *mut u8, n: usize, c: i32) { __aeabi_memset4(dest, n, c); } - #[cfg(not(target_vendor = "apple"))] + #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memclr(dest: *mut u8, n: usize) { __aeabi_memset(dest, n, 0); } - #[cfg(not(any(target_vendor = "apple", target_env = "msvc")))] + #[cfg(not(any(target_os = "ios", target_env = "msvc")))] pub unsafe extern "aapcs" fn __aeabi_memclr4(dest: *mut u8, n: usize) { __aeabi_memset4(dest, n, 0); } - #[cfg(not(any(target_vendor = "apple", target_env = "msvc")))] + #[cfg(not(any(target_os = "ios", target_env = "msvc")))] pub unsafe extern "aapcs" fn __aeabi_memclr8(dest: *mut u8, n: usize) { __aeabi_memset4(dest, n, 0); } From d2d7b333676f6c1022590cf7095b247d7a0a8362 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 10 Jul 2024 04:20:36 -0400 Subject: [PATCH 2/4] Revert "Cleanup `manged-names` macro" This reverts commit 8a7ba9ab5fe0b1e44c30ad9771e2e7ac9dd42555. --- src/macros.rs | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index f537c1a96..c8f3bd240 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -253,11 +253,11 @@ macro_rules! intrinsics { $($body)* } - #[cfg(all(any(windows, target_os = "uefi"), target_arch = "x86_64", not(feature = "mangled-names")))] - mod $name { - #[no_mangle] + #[cfg(all(any(windows, target_os = "uefi"), target_arch = "x86_64"))] + pub mod $name { + #[cfg_attr(not(feature = "mangled-names"), no_mangle)] #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] - extern $abi fn $name( $($argname: $ty),* ) + pub extern $abi fn $name( $($argname: $ty),* ) -> $crate::macros::win64_128bit_abi_hack::U64x2 { let e: $($ret)? = super::$name($($argname),*); @@ -294,20 +294,20 @@ macro_rules! intrinsics { $($body)* } - #[cfg(all(target_arch = "arm", not(feature = "mangled-names")))] - mod $name { - #[no_mangle] + #[cfg(target_arch = "arm")] + pub mod $name { + #[cfg_attr(not(feature = "mangled-names"), no_mangle)] #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] - extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { + pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { super::$name($($argname),*) } } - #[cfg(all(target_arch = "arm", not(feature = "mangled-names")))] - mod $alias { - #[no_mangle] + #[cfg(target_arch = "arm")] + pub mod $alias { + #[cfg_attr(not(feature = "mangled-names"), no_mangle)] #[cfg_attr(all(not(windows), not(target_vendor="apple")), linkage = "weak")] - extern "aapcs" fn $alias( $($argname: $ty),* ) $(-> $ret)? { + pub extern "aapcs" fn $alias( $($argname: $ty),* ) $(-> $ret)? { super::$name($($argname),*) } } @@ -368,12 +368,12 @@ macro_rules! intrinsics { $($body)* } - #[cfg(all(feature = "mem", not(feature = "mangled-names")))] - mod $name { + #[cfg(feature = "mem")] + pub mod $name { $(#[$($attr)*])* - #[no_mangle] + #[cfg_attr(not(feature = "mangled-names"), no_mangle)] #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] - unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { + pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { super::$name($($argname),*) } } @@ -392,7 +392,6 @@ 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)*])* @@ -460,12 +459,11 @@ macro_rules! intrinsics { $($body)* } - #[cfg(not(feature = "mangled-names"))] - mod $name { + pub mod $name { $(#[$($attr)*])* - #[no_mangle] + #[cfg_attr(not(feature = "mangled-names"), no_mangle)] #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] - extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { + pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { super::$name($($argname),*) } } @@ -487,12 +485,11 @@ macro_rules! intrinsics { $($body)* } - #[cfg(not(feature = "mangled-names"))] - mod $name { + pub mod $name { $(#[$($attr)*])* - #[no_mangle] + #[cfg_attr(not(feature = "mangled-names"), no_mangle)] #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] - unsafe fn $name( $($argname: $ty),* ) $(-> $ret)? { + pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { super::$name($($argname),*) } } From 6de6be7a4e2854c5df221f13e9172096ed7684a9 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 10 Jul 2024 04:20:49 -0400 Subject: [PATCH 3/4] Revert "Remove unneeded `weak` for `optimized-c` function" This reverts commit 16c9ca927cb1767c2285e89b481ff0e97026c072. --- src/macros.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/macros.rs b/src/macros.rs index c8f3bd240..c8db42f0f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -150,6 +150,7 @@ macro_rules! intrinsics { $($rest:tt)* ) => ( #[cfg($name = "optimized-c")] + #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] pub $(unsafe $($empty)? )? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { extern $abi { fn $name($($argname: $ty),*) $(-> $ret)?; From 42538d8077cb3e2e86ccd4b73266b8f352af3f77 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 10 Jul 2024 04:20:59 -0400 Subject: [PATCH 4/4] Revert "Apply `weak` attributes to all intrinsics" This reverts commit 7f9c937d136751ebf9876858da62fbc5b92e610e. --- Cargo.toml | 11 ++++++ src/arm.rs | 18 ++++++++++ src/macros.rs | 93 ++++++++++++++++++++++++++++++++++++++++++-------- src/math.rs | 3 ++ src/mem/mod.rs | 6 ++++ 5 files changed, 117 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c8d78ec3e..3a53a3d88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,6 +70,17 @@ rustc-dep-of-std = ['compiler-builtins', 'core'] # are not normally public but are required by the `testcrate` public-test-deps = [] +# Marks all intrinsics functions with weak linkage so that they can be +# replaced at link time by another implementation. This is particularly useful +# for mixed Rust/C++ binaries that want to use the C++ intrinsics, otherwise +# linking against the Rust stdlib will replace those from the compiler-rt +# library. +# +# Unlike the "c" feature, the intrinsics are still provided by the Rust +# implementations and each will be used unless a stronger symbol replaces +# it during linking. +weak-intrinsics = [] + [[example]] name = "intrinsics" required-features = ["compiler-builtins"] diff --git a/src/arm.rs b/src/arm.rs index dcae22b73..cc67642e1 100644 --- a/src/arm.rs +++ b/src/arm.rs @@ -20,6 +20,7 @@ macro_rules! bl { intrinsics! { // NOTE This function and the ones below are implemented using assembly because they are using a // custom calling convention which can't be implemented using a normal Rust function. + #[cfg_attr(all(not(windows), not(target_vendor="apple")), weak)] #[naked] #[cfg(not(target_env = "msvc"))] pub unsafe extern "C" fn __aeabi_uidivmod() { @@ -35,6 +36,7 @@ intrinsics! { ); } + #[cfg_attr(all(not(windows), not(target_vendor="apple")), weak)] #[naked] pub unsafe extern "C" fn __aeabi_uldivmod() { core::arch::asm!( @@ -51,6 +53,7 @@ intrinsics! { ); } + #[cfg_attr(all(not(windows), not(target_vendor="apple")), weak)] #[naked] pub unsafe extern "C" fn __aeabi_idivmod() { core::arch::asm!( @@ -64,6 +67,7 @@ intrinsics! { ); } + #[cfg_attr(all(not(windows), not(target_vendor="apple")), weak)] #[naked] pub unsafe extern "C" fn __aeabi_ldivmod() { core::arch::asm!( @@ -80,13 +84,17 @@ intrinsics! { ); } + // The following functions use weak linkage to allow users to override + // with custom implementation. // FIXME: The `*4` and `*8` variants should be defined as aliases. + #[weak] #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: usize) { crate::mem::memcpy(dest, src, n); } + #[weak] #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memcpy4(dest: *mut u8, src: *const u8, n: usize) { // We are guaranteed 4-alignment, so accessing at u32 is okay. @@ -104,32 +112,38 @@ intrinsics! { __aeabi_memcpy(dest as *mut u8, src as *const u8, n); } + #[weak] #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memcpy8(dest: *mut u8, src: *const u8, n: usize) { __aeabi_memcpy4(dest, src, n); } + #[weak] #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memmove(dest: *mut u8, src: *const u8, n: usize) { crate::mem::memmove(dest, src, n); } + #[weak] #[cfg(not(any(target_os = "ios", target_env = "msvc")))] pub unsafe extern "aapcs" fn __aeabi_memmove4(dest: *mut u8, src: *const u8, n: usize) { __aeabi_memmove(dest, src, n); } + #[weak] #[cfg(not(any(target_os = "ios", target_env = "msvc")))] pub unsafe extern "aapcs" fn __aeabi_memmove8(dest: *mut u8, src: *const u8, n: usize) { __aeabi_memmove(dest, src, n); } + #[weak] #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memset(dest: *mut u8, n: usize, c: i32) { // Note the different argument order crate::mem::memset(dest, c, n); } + #[weak] #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memset4(dest: *mut u8, n: usize, c: i32) { let mut dest = dest as *mut u32; @@ -147,21 +161,25 @@ intrinsics! { __aeabi_memset(dest as *mut u8, n, byte as i32); } + #[weak] #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memset8(dest: *mut u8, n: usize, c: i32) { __aeabi_memset4(dest, n, c); } + #[weak] #[cfg(not(target_os = "ios"))] pub unsafe extern "aapcs" fn __aeabi_memclr(dest: *mut u8, n: usize) { __aeabi_memset(dest, n, 0); } + #[weak] #[cfg(not(any(target_os = "ios", target_env = "msvc")))] pub unsafe extern "aapcs" fn __aeabi_memclr4(dest: *mut u8, n: usize) { __aeabi_memset4(dest, n, 0); } + #[weak] #[cfg(not(any(target_os = "ios", target_env = "msvc")))] pub unsafe extern "aapcs" fn __aeabi_memclr8(dest: *mut u8, n: usize) { __aeabi_memset4(dest, n, 0); diff --git a/src/macros.rs b/src/macros.rs index c8db42f0f..da454074e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -25,12 +25,11 @@ macro_rules! public_test_dep { /// platforms need and elsewhere in this library it just looks like normal Rust /// code. /// -/// All intrinsics functions are marked with #[linkage = "weak"] when -/// `not(windows) and not(target_vendor = "apple")`. -/// `weak` linkage attribute is used so that these functions can be replaced -/// by another implementation at link time. This is particularly useful for mixed -/// Rust/C++ binaries that want to use the C++ intrinsics, otherwise linking against -/// the Rust stdlib will replace those from the compiler-rt library. +/// When the weak-intrinsics feature is enabled, all intrinsics functions are +/// marked with #[linkage = "weak"] so that they can be replaced by another +/// implementation at link time. This is particularly useful for mixed Rust/C++ +/// binaries that want to use the C++ intrinsics, otherwise linking against the +/// Rust stdlib will replace those from the compiler-rt library. /// /// This macro is structured to be invoked with a bunch of functions that looks /// like: @@ -54,6 +53,10 @@ macro_rules! public_test_dep { /// /// A quick overview of attributes supported right now are: /// +/// * `weak` - indicates that the function should always be given weak linkage. +/// This attribute must come before other attributes, as the other attributes +/// will generate the final output function and need to have `weak` modify +/// them. /// * `maybe_use_optimized_c_shim` - indicates that the Rust implementation is /// ignored if an optimized C version was compiled. /// * `aapcs_on_arm` - forces the ABI of the function to be `"aapcs"` on ARM and @@ -128,6 +131,67 @@ macro_rules! intrinsics { intrinsics!($($rest)*); ); + // Explicit weak linkage gets dropped when weak-intrinsics is on since it + // will be added unconditionally to all intrinsics and would conflict + // otherwise. + ( + #[weak] + $(#[$($attr:tt)*])* + pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? { + $($body:tt)* + } + + $($rest:tt)* + ) => ( + #[cfg(feature = "weak-intrinsics")] + intrinsics! { + $(#[$($attr)*])* + pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { + $($body)* + } + } + + #[cfg(not(feature = "weak-intrinsics"))] + intrinsics! { + $(#[$($attr)*])* + #[linkage = "weak"] + pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { + $($body)* + } + } + + intrinsics!($($rest)*); + ); + // Same as above but for unsafe. + ( + #[weak] + $(#[$($attr:tt)*])* + pub unsafe extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? { + $($body:tt)* + } + + $($rest:tt)* + ) => ( + #[cfg(feature = "weak-intrinsics")] + intrinsics! { + $(#[$($attr)*])* + pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { + $($body)* + } + } + + #[cfg(not(feature = "weak-intrinsics"))] + intrinsics! { + $(#[$($attr)*])* + #[linkage = "weak"] + pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { + $($body)* + } + } + + intrinsics!($($rest)*); + ); + // Right now there's a bunch of architecture-optimized intrinsics in the // stock compiler-rt implementation. Not all of these have been ported over // to Rust yet so when the `c` feature of this crate is enabled we fall back @@ -150,7 +214,7 @@ macro_rules! intrinsics { $($rest:tt)* ) => ( #[cfg($name = "optimized-c")] - #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] + #[cfg_attr(feature = "weak-intrinsics", linkage = "weak")] pub $(unsafe $($empty)? )? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { extern $abi { fn $name($($argname: $ty),*) $(-> $ret)?; @@ -250,6 +314,7 @@ macro_rules! intrinsics { ) => ( #[cfg(all(any(windows, target_os = "uefi"), target_arch = "x86_64"))] $(#[$($attr)*])* + #[cfg_attr(feature = "weak-intrinsics", linkage = "weak")] pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { $($body)* } @@ -257,7 +322,7 @@ macro_rules! intrinsics { #[cfg(all(any(windows, target_os = "uefi"), target_arch = "x86_64"))] pub mod $name { #[cfg_attr(not(feature = "mangled-names"), no_mangle)] - #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] + #[cfg_attr(feature = "weak-intrinsics", linkage = "weak")] pub extern $abi fn $name( $($argname: $ty),* ) -> $crate::macros::win64_128bit_abi_hack::U64x2 { @@ -298,7 +363,7 @@ macro_rules! intrinsics { #[cfg(target_arch = "arm")] pub mod $name { #[cfg_attr(not(feature = "mangled-names"), no_mangle)] - #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] + #[cfg_attr(feature = "weak-intrinsics", linkage = "weak")] pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { super::$name($($argname),*) } @@ -307,7 +372,7 @@ macro_rules! intrinsics { #[cfg(target_arch = "arm")] pub mod $alias { #[cfg_attr(not(feature = "mangled-names"), no_mangle)] - #[cfg_attr(all(not(windows), not(target_vendor="apple")), linkage = "weak")] + #[cfg_attr(any(all(not(windows), not(target_vendor="apple")), feature = "weak-intrinsics"), linkage = "weak")] pub extern "aapcs" fn $alias( $($argname: $ty),* ) $(-> $ret)? { super::$name($($argname),*) } @@ -373,7 +438,7 @@ macro_rules! intrinsics { pub mod $name { $(#[$($attr)*])* #[cfg_attr(not(feature = "mangled-names"), no_mangle)] - #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] + #[cfg_attr(feature = "weak-intrinsics", linkage = "weak")] pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { super::$name($($argname),*) } @@ -397,7 +462,7 @@ macro_rules! intrinsics { #[naked] $(#[$($attr)*])* #[cfg_attr(not(feature = "mangled-names"), no_mangle)] - #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] + #[cfg_attr(feature = "weak-intrinsics", linkage = "weak")] pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { $($body)* } @@ -463,7 +528,7 @@ macro_rules! intrinsics { pub mod $name { $(#[$($attr)*])* #[cfg_attr(not(feature = "mangled-names"), no_mangle)] - #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] + #[cfg_attr(feature = "weak-intrinsics", linkage = "weak")] pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { super::$name($($argname),*) } @@ -489,7 +554,7 @@ macro_rules! intrinsics { pub mod $name { $(#[$($attr)*])* #[cfg_attr(not(feature = "mangled-names"), no_mangle)] - #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")] + #[cfg_attr(feature = "weak-intrinsics", linkage = "weak")] pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { super::$name($($argname),*) } diff --git a/src/math.rs b/src/math.rs index 7d4d17876..e47b834e4 100644 --- a/src/math.rs +++ b/src/math.rs @@ -9,6 +9,7 @@ macro_rules! no_mangle { ($(fn $fun:ident($($iid:ident : $ity:ty),+) -> $oty:ty;)+) => { intrinsics! { $( + #[cfg_attr(all(not(windows), not(target_vendor = "apple")), weak)] pub extern "C" fn $fun($($iid: $ity),+) -> $oty { self::libm::$fun($($iid),+) } @@ -93,12 +94,14 @@ no_mangle! { } intrinsics! { + #[cfg_attr(all(not(windows), not(target_vendor = "apple")), weak)] pub extern "C" fn lgamma_r(x: f64, s: &mut i32) -> f64 { let r = self::libm::lgamma_r(x); *s = r.1; r.0 } + #[cfg_attr(all(not(windows), not(target_vendor = "apple")), weak)] pub extern "C" fn lgammaf_r(x: f32, s: &mut i32) -> f32 { let r = self::libm::lgammaf_r(x); *s = r.1; diff --git a/src/mem/mod.rs b/src/mem/mod.rs index d0ff50158..ccf191779 100644 --- a/src/mem/mod.rs +++ b/src/mem/mod.rs @@ -20,12 +20,14 @@ use core::ops::{BitOr, Shl}; mod impls; intrinsics! { + #[cfg_attr(not(all(target_os = "windows", target_env = "gnu")), weak)] #[mem_builtin] pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 { impls::copy_forward(dest, src, n); dest } + #[cfg_attr(not(all(target_os = "windows", target_env = "gnu")), weak)] #[mem_builtin] pub unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 { let delta = (dest as usize).wrapping_sub(src as usize); @@ -39,22 +41,26 @@ intrinsics! { dest } + #[cfg_attr(not(all(target_os = "windows", target_env = "gnu")), weak)] #[mem_builtin] pub unsafe extern "C" fn memset(s: *mut u8, c: crate::mem::c_int, n: usize) -> *mut u8 { impls::set_bytes(s, c as u8, n); s } + #[cfg_attr(not(all(target_os = "windows", target_env = "gnu")), weak)] #[mem_builtin] pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 { impls::compare_bytes(s1, s2, n) } + #[cfg_attr(not(all(target_os = "windows", target_env = "gnu")), weak)] #[mem_builtin] pub unsafe extern "C" fn bcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 { memcmp(s1, s2, n) } + #[cfg_attr(not(all(target_os = "windows", target_env = "gnu")), weak)] #[mem_builtin] pub unsafe extern "C" fn strlen(s: *const core::ffi::c_char) -> usize { impls::c_string_length(s)