Skip to content
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

f128 cmath functions broken in windows #133835

Closed
zinkkkk opened this issue Dec 4, 2024 · 2 comments
Closed

f128 cmath functions broken in windows #133835

zinkkkk opened this issue Dec 4, 2024 · 2 comments
Labels
C-bug Category: This is a bug. F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` O-windows Operating system: Windows requires-incomplete-features This issue requires the use of incomplete features.

Comments

@zinkkkk
Copy link

zinkkkk commented Dec 4, 2024

Under windows using #![feature(f128)] almost all of the f128 math functions cannot be compiled, it appears to be a linking error/missing symbols.

Normal math operations like add, sub, mul ect all compile and run fine but calling anything like .sin() or .gamma() or anything called under cmath will not compile. However, any of the math functions called as part of intrinsics do compile fine. This appears to be windows specific as the identical code compiles fine under wsl, both using latest rust nightly.

I have also tried using normal msvc linker link.exe and rust-lld.exe both with identical results, and also tested with gnu toolchain again with identical results.

#![feature(f128)]

fn main() {
    let a: f128 = 5.7;
    println!("f128 sin = {:#?}", (a.sin()));
}
PS C:\Users\levia\Documents\Code\f128stuff> cargo run --release
   Compiling f128stuff v0.1.0 (C:\Users\levia\Documents\Code\f128stuff)
error: linking with `rust-lld` failed: exit code: 1
  |
  = note: "rust-lld" "-flavor" "link" "/NOLOGO" "C:\\Users\\levia\\AppData\\Local\\Temp\\rustcEK3Fy2\\symbols.o" "C:\\Users\\levia\\Documents\\Code\\f128stuff\\target\\release\\deps\\f128stuff.f128stuff.6f36ac2c2723ffe0-cgu.0.rcgu.o" "C:\\Users\\levia\\Documents\\Code\\f128stuff\\target\\release\\deps\\f128stuff.9j8x1nkqyt711ce2p3mysxkj3.rcgu.o" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-c09b6dac30a2ec7e.rlib" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-f2b3338f491e0297.rlib" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libwindows_targets-650a9189f256d76e.rlib" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-7ce081cb32ea6b96.rlib" 
"C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-f80ba4624fd5706a.rlib" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-6fe121940227f580.rlib" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-316118e870ffb802.rlib" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-af3779e04d2c5b3e.rlib" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-d8b574f6478ea10a.rlib" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-8a746df5f193254d.rlib" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-5a536bba43fbe272.rlib" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-45b7a05b67ddb8c6.rlib" "C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-c25bba97e86b102c.rlib" "kernel32.lib" "kernel32.lib" "advapi32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "dbghelp.lib" "/defaultlib:msvcrt" "/NXCOMPAT" "/OUT:C:\\Users\\levia\\Documents\\Code\\f128stuff\\target\\release\\deps\\f128stuff.exe" "/OPT:REF,ICF" "/DEBUG" "/PDBALTPATH:%_PDB%" "/NATVIS:C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\levia\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"
  = note: rust-lld: error: undefined symbol: sinl␍
          >>> referenced by C:\Users\levia\Documents\Code\f128stuff\target\release\deps\f128stuff.f128stuff.6f36ac2c2723ffe0-cgu.0.rcgu.o:(f128stuff::main::ha078482b952c8e41)␍


error: could not compile `f128stuff` (bin "f128stuff") due to 1 previous error

but exact same code under wsl:

zink@baph:/mnt/c/Users/levia/Documents/Code/f128stuff$ cargo run --release
   Compiling f128stuff v0.1.0 (/mnt/c/Users/levia/Documents/Code/f128stuff)
    Finished `release` profile [optimized] target(s) in 0.64s
     Running `target/release/f128stuff`
f128 sin = 0xbffe19f37497ac7a1a58c25c354ac88a
zink@baph:/mnt/c/Users/levia/Documents/Code/f128stuff$

related to
#128417
#116909

@zinkkkk zinkkkk added the C-bug Category: This is a bug. label Dec 4, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 4, 2024
@jieyouxu jieyouxu added F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` O-windows Operating system: Windows labels Dec 4, 2024
@tgross35
Copy link
Contributor

tgross35 commented Dec 4, 2024

This is more or less expected for the time being. Windows, among other platforms, basically doesn't touch f128 so they don't provide cmath. There is a note about this in the docs, though it isn't very specific:

Note: f128 support is incomplete. Many platforms will not be able to link math functions. On x86 in particular, these functions do link but their results are always incorrect.

The resolution here is for us to add these to our libm and then make them available everywhere. It is in progress but this is something that will take a lot of time.

@tgross35
Copy link
Contributor

tgross35 commented Dec 4, 2024

If you want to experiment with this, -windows-gnu may have the required symbols or you may be able to build a C math library and link that. Note that even if linking succeeds that you will get the wrong results on x86 Windows, LLVM has a lowering bug where functions turn into the long double sinl functions rather than sinf128.

I am going to close this since there isn't really anything actionable, the required changes here are tracked in other places (but most of the updates will be in libm).

@tgross35 tgross35 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 4, 2024
@jieyouxu jieyouxu added requires-incomplete-features This issue requires the use of incomplete features. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` O-windows Operating system: Windows requires-incomplete-features This issue requires the use of incomplete features.
Projects
None yet
Development

No branches or pull requests

4 participants