From 0fab77e8d72cf232af4977642b52544f0e4ab521 Mon Sep 17 00:00:00 2001 From: Amjad Alsharafi <26300843+Amjad50@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:55:05 +0800 Subject: [PATCH 1/4] Don't include `math` for `unix` and `wasi` targets This fixes such as (https://github.com/rust-lang/rust/issues/128386) where, our implementation is being used on systems where there is already `math` library and its more performant and accurate. So with this change, linux will go back to the previous behavior and not include these functions, windows and apple were generally not affected. Looking at the targets we have builtin now in rust, everything else is probably good to have the math symbols. > A note on the above, the `hermit` os uses `libm` directly for itself, > but I think its Ok to keep providing math in `compiler_builtin` for it, > its technically the same implementation either from `compiler_builtin` > or `hermit-builtins`. Signed-off-by: Amjad Alsharafi <26300843+Amjad50@users.noreply.github.com> --- src/lib.rs | 13 ++++++++++--- src/math.rs | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0d44fdf9..b85f789f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,9 +47,16 @@ mod macros; pub mod float; pub mod int; -// Disabled on x86 without sse2 due to ABI issues -// -#[cfg(not(all(target_arch = "x86", not(target_feature = "sse2"))))] +// Disable for any of the following: +// - x86 without sse2 due to ABI issues +// - +// - All unix targets (linux, macos, freebsd, android, etc) +// - wasm with known target_os +#[cfg(not(any( + all(target_arch = "x86", not(target_feature = "sse2")), + unix, + all(target_family = "wasm", not(target_os = "unknown")) +)))] pub mod math; pub mod mem; diff --git a/src/math.rs b/src/math.rs index 7d4d1787..477dfe36 100644 --- a/src/math.rs +++ b/src/math.rs @@ -17,7 +17,7 @@ macro_rules! no_mangle { } } -#[cfg(all(not(windows), not(target_vendor = "apple")))] +#[cfg(not(windows))] no_mangle! { fn acos(x: f64) -> f64; fn asin(x: f64) -> f64; @@ -92,6 +92,7 @@ no_mangle! { fn fmodf(x: f32, y: f32) -> f32; } +// allow for windows (and other targets) intrinsics! { pub extern "C" fn lgamma_r(x: f64, s: &mut i32) -> f64 { let r = self::libm::lgamma_r(x); From 570faeb067cda4629b012522b8c776c86c6edb8d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 16:15:09 +0000 Subject: [PATCH 2/4] chore: release --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b9de326d..525095b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Jorge Aparicio "] name = "compiler_builtins" -version = "0.1.122" +version = "0.1.123" license = "MIT/Apache-2.0" readme = "README.md" repository = "https://github.com/rust-lang/compiler-builtins" From 95c62361a092e2e7f87c2d929ce23dcf0e4ba434 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Sat, 31 Aug 2024 12:54:21 -0500 Subject: [PATCH 3/4] [hexagon] Remove aliases w/o leading __ These hexagon builtins incorrectly created aliases in the global namespace which can (and in at least one case, did) conflict with symbols defined by other programs. This should address the issue reported as https://github.com/rust-lang/rust/issues/129823: Compiling compiler_builtins v0.1.123 Compiling core v0.0.0 (/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core) Compiling rustc-std-workspace-core v1.99.0 (/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core) Compiling byteorder v1.5.0 Compiling zerocopy v0.7.34 error: symbol 'fma' is already defined error: could not compile `compiler_builtins` (lib) due to 1 previous error Also: some of the symbols defined were not just aliases, so those are now qualified with `__hexagon_`. The compiler does not yet emit calls to these particular ones, but if/when it does, it can use the new names. --- src/hexagon/dffma.s | 2 -- src/hexagon/dfminmax.s | 6 ------ src/hexagon/fastmath2_dlib_asm.s | 30 +++++++++++++++--------------- src/hexagon/fastmath2_ldlib_asm.s | 18 +++++++++--------- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/hexagon/dffma.s b/src/hexagon/dffma.s index 043a1d29..97d05eb1 100644 --- a/src/hexagon/dffma.s +++ b/src/hexagon/dffma.s @@ -3,8 +3,6 @@ .type __hexagon_fmadf4,@function .global __hexagon_fmadf5 .type __hexagon_fmadf5,@function - .global fma - .type fma,@function .global __qdsp_fmadf5 ; .set __qdsp_fmadf5, __hexagon_fmadf5 .p2align 5 __hexagon_fmadf4: diff --git a/src/hexagon/dfminmax.s b/src/hexagon/dfminmax.s index 3337a322..953e773b 100644 --- a/src/hexagon/dfminmax.s +++ b/src/hexagon/dfminmax.s @@ -1,17 +1,12 @@ .text .global __hexagon_mindf3 .global __hexagon_maxdf3 - .global fmin - .type fmin,@function - .global fmax - .type fmax,@function .type __hexagon_mindf3,@function .type __hexagon_maxdf3,@function .global __qdsp_mindf3 ; .set __qdsp_mindf3, __hexagon_mindf3 .global __qdsp_maxdf3 ; .set __qdsp_maxdf3, __hexagon_maxdf3 .p2align 5 __hexagon_mindf3: -fmin: { p0 = dfclass(r1:0,#0x10) p1 = dfcmp.gt(r1:0,r3:2) @@ -31,7 +26,6 @@ fmin: .size __hexagon_mindf3,.-__hexagon_mindf3 .falign __hexagon_maxdf3: -fmax: { p0 = dfclass(r1:0,#0x10) p1 = dfcmp.gt(r3:2,r1:0) diff --git a/src/hexagon/fastmath2_dlib_asm.s b/src/hexagon/fastmath2_dlib_asm.s index 15c38784..e77b7db0 100644 --- a/src/hexagon/fastmath2_dlib_asm.s +++ b/src/hexagon/fastmath2_dlib_asm.s @@ -1,7 +1,7 @@ .text - .global fast2_dadd_asm - .type fast2_dadd_asm, @function -fast2_dadd_asm: + .global __hexagon_fast2_dadd_asm + .type __hexagon_fast2_dadd_asm, @function +__hexagon_fast2_dadd_asm: .falign { R7:6 = VABSDIFFH(R1:0, R3:2) @@ -49,9 +49,9 @@ fast2_dadd_asm: jumpr r31 } .text - .global fast2_dsub_asm - .type fast2_dsub_asm, @function -fast2_dsub_asm: + .global __hexagon_fast2_dsub_asm + .type __hexagon_fast2_dsub_asm, @function +__hexagon_fast2_dsub_asm: .falign { R7:6 = VABSDIFFH(R1:0, R3:2) @@ -99,9 +99,9 @@ fast2_dsub_asm: jumpr r31 } .text - .global fast2_dmpy_asm - .type fast2_dmpy_asm, @function -fast2_dmpy_asm: + .global __hexagon_fast2_dmpy_asm + .type __hexagon_fast2_dmpy_asm, @function +__hexagon_fast2_dmpy_asm: .falign { R13= lsr(R2, #16) @@ -167,9 +167,9 @@ fast2_dmpy_asm: jumpr r31 } .text - .global fast2_qd2f_asm - .type fast2_qd2f_asm, @function -fast2_qd2f_asm: + .global __hexagon_fast2_qd2f_asm + .type __hexagon_fast2_qd2f_asm, @function +__hexagon_fast2_qd2f_asm: .falign { R3 = abs(R1):sat @@ -225,9 +225,9 @@ fast2_qd2f_asm: jumpr r31 } .text - .global fast2_f2qd_asm - .type fast2_f2qd_asm, @function -fast2_f2qd_asm: + .global __hexagon_fast2_f2qd_asm + .type __hexagon_fast2_f2qd_asm, @function +__hexagon_fast2_f2qd_asm: diff --git a/src/hexagon/fastmath2_ldlib_asm.s b/src/hexagon/fastmath2_ldlib_asm.s index b72b7550..3251057d 100644 --- a/src/hexagon/fastmath2_ldlib_asm.s +++ b/src/hexagon/fastmath2_ldlib_asm.s @@ -1,7 +1,7 @@ .text - .global fast2_ldadd_asm - .type fast2_ldadd_asm, @function -fast2_ldadd_asm: + .global __hexagon_fast2ldadd_asm + .type __hexagon_fast2ldadd_asm, @function +__hexagon_fast2ldadd_asm: .falign { R4 = memw(r29+#8) @@ -54,9 +54,9 @@ fast2_ldadd_asm: jumpr r31 } .text - .global fast2_ldsub_asm - .type fast2_ldsub_asm, @function -fast2_ldsub_asm: + .global __hexagon_fast2ldsub_asm + .type __hexagon_fast2ldsub_asm, @function +__hexagon_fast2ldsub_asm: .falign { R4 = memw(r29+#8) @@ -109,9 +109,9 @@ fast2_ldsub_asm: jumpr r31 } .text - .global fast2_ldmpy_asm - .type fast2_ldmpy_asm, @function -fast2_ldmpy_asm: + .global __hexagon_fast2ldmpy_asm + .type __hexagon_fast2ldmpy_asm, @function +__hexagon_fast2ldmpy_asm: .falign { R15:14 = memd(r29+#0) From 3442c02c01d05e406c23330fd66cd5187ffe8a2f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 03:20:30 +0000 Subject: [PATCH 4/4] chore: release --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 525095b1..f5a04747 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Jorge Aparicio "] name = "compiler_builtins" -version = "0.1.123" +version = "0.1.124" license = "MIT/Apache-2.0" readme = "README.md" repository = "https://github.com/rust-lang/compiler-builtins"