-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always have math functions but with weak
linking attribute if we can
#577
Conversation
537e8cd
to
7b161ab
Compare
For some reason, windows building fails, and the error is confusing, it can't find some symbols that are unrelated to what have changed. |
Can you check this @Amanieu? Thanks |
We're currently waiting for fixes on the rustc side before work on compiler-builtins can continue: rust-lang/rust#121552 |
Ah, thanks for the info. |
CI should be fixed now, can you rebase? |
Thanks, Builds now |
src/math.rs
Outdated
all(target_arch = "xtensa", target_os = "none"), | ||
all(target_vendor = "fortanix", target_env = "sgx") | ||
))] | ||
#[cfg(not(target_os = "windows"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[cfg(not(target_os = "windows"))] | |
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), weak)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have this already inside no_mangle
, so probably just remove the cfg
completely is a better choice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we shouldn't provide the math intrinsics at all on windows/apple targets since weak linkage doesn't work properly. On those target we should always be getting these symbols from libc. The only exception is lgamma_r
and lgammaf_r
which are missing on MSVC targets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then you probably mean to use cfg
and not cfg_attr
? The suggested change is to use cfg_attr(weak)
for non windows/apple
This is a replacement for rust-lang/libm#290 This fixes crashes during compilations for targets that don't have math symbols by default. So, we will provide them libm symbols, but mark it as `weak` (if its supported), so that the linker will choose the system builtin functions, since those are sometimes more optimized. If the linker couldn't find those, it will go with `libm` implementation.
``` error[E0658]: use of unstable library feature 'proc_macro_byte_character' --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.80/src/wrapper.rs:871:21 | 871 | proc_macro::Literal::byte_character(byte) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #115268 <rust-lang/rust#115268> for more information = help: add `#![feature(proc_macro_byte_character)]` to the crate attributes to enable = note: this compiler was built on 2024-03-21; consider upgrading it if it is out of date error[E0658]: use of unstable library feature 'proc_macro_c_str_literals' --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.80/src/wrapper.rs:898:21 | 898 | proc_macro::Literal::c_string(string) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #119750 <rust-lang/rust#119750> for more information = help: add `#![feature(proc_macro_c_str_literals)]` to the crate attributes to enable = note: this compiler was built on 2024-03-21; consider upgrading it if it is out of date ``` Also, the latest nightly cannot be used due to rust-lang/compiler-builtins#577. ``` = note: /usr/lib/gcc/avr/5.4.0/../../../avr/lib/avr6/libm.a(addsf3.o): In function `__addsf3': (.text.avr-libc.fplib+0x2): multiple definition of `__addsf3' /home/runner/work/portable-atomic/portable-atomic/target/no-std-test/avr-unknown-gnu-atmega2560/debug/deps/libcompiler_builtins-81c93cbf49042e5b.rlib(compiler_builtins-81c93cbf49042e5b.compiler_builtins.3808c58458fddf11-cgu.07.rcgu.o):/home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.109/src/macros.rs:500: first defined here ```
rust-lang/compiler-builtins#577 caused regression on no-std hexagon: ``` error: symbol 'fma' is already defined error: symbol 'fmax' is already defined ```
This is a replacement for rust-lang/libm#290
This fixes crashes during compilations for targets that don't have math symbols by default.
So, we will provide them libm symbols, but mark it as
weak
(if its supported), so that the linker will choose the system builtin functions, since those are sometimes more optimized.If the linker couldn't find those, it will go with
libm
implementation.