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

fmodf symbol missing on i686-unknown-uefi since nightly-2024-07-30 #128533

Closed
YtvwlD opened this issue Aug 2, 2024 · 19 comments · Fixed by #132206
Closed

fmodf symbol missing on i686-unknown-uefi since nightly-2024-07-30 #128533

YtvwlD opened this issue Aug 2, 2024 · 19 comments · Fixed by #132206
Labels
C-bug Category: This is a bug. O-UEFI UEFI regression-untriaged Untriaged performance or correctness regression.

Comments

@YtvwlD
Copy link

YtvwlD commented Aug 2, 2024

I'm using (a library that uses) floating point math on UEFI targets. For quite some time, fmodf was missing on i686-unknown-uefi (but available on x86_64-unknown-uefi). Since rust-lang/compiler-builtins#490, rust-lang/compiler-builtins#553, #119019, this was available, but it's gone missing a few days ago. I suspect it's due to this update to compiler-builtins, but I have not confirmed it.

Code

This is a minimal (but nonsensical) example code that compiles:

#![no_std]
#![no_main]

extern "C" { fn fmodf(); }

use core::panic::PanicInfo;

#[panic_handler]
fn panic(_: &PanicInfo) -> ! {
        loop {}
}

#[no_mangle]
pub fn efi_main() {
        unsafe { fmodf(); }
}

I expected to see this happen: The code should should compile.

Instead, this happened:

$ cargo build --target i686-unknown-uefi
   Compiling foo v0.1.0 (/tmp/tmp.4CIirv1HGb/foo)
error: linking with `rust-lld` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/niklas/.local/bin:/home/niklas/.cargo/bin:/home/niklas/.gopath/bin:/home/niklas/bin:/snap/bin:/home/niklas/.local/bin:/home/niklas/.cargo/bin:/home/niklas/.gopath/bin:/home/niklas/bin:/snap/bin" VSLANG="1033" "rust-lld" "-flavor" "link" "/NOLOGO" "/entry:efi_main" "/subsystem:efi_application" "/tmp/rustckZUbYQ/symbols.o" "/tmp/tmp.4CIirv1HGb/foo/target/i686-unknown-uefi/debug/deps/foo-b50eac0687aac12d.21wnwtpp1uzembi52ejbydrsb.rcgu.o" "/LIBPATH:/tmp/tmp.4CIirv1HGb/foo/target/i686-unknown-uefi/debug/deps" "/LIBPATH:/tmp/tmp.4CIirv1HGb/foo/target/debug/deps" "/LIBPATH:/home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-uefi/lib" "/home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-uefi/lib/librustc_std_workspace_core-26a6383b0ec19675.rlib" "/home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-uefi/lib/libcore-70427371e67f0ba1.rlib" "/home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-uefi/lib/libcompiler_builtins-f2416250465866e5.rlib" "/NXCOMPAT" "/LIBPATH:/home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-uefi/lib" "/OUT:/tmp/tmp.4CIirv1HGb/foo/target/i686-unknown-uefi/debug/deps/foo-b50eac0687aac12d.efi" "/OPT:REF,NOICF" "/DEBUG" "/PDBALTPATH:%_PDB%" "/NODEFAULTLIB"
  = note: rust-lld: error: undefined symbol: _fmodf
          >>> referenced by /tmp/tmp.4CIirv1HGb/foo/src/main.rs:15
          >>>               /tmp/tmp.4CIirv1HGb/foo/target/i686-unknown-uefi/debug/deps/foo-b50eac0687aac12d.21wnwtpp1uzembi52ejbydrsb.rcgu.o:(_efi_main)
          

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

Version it worked on

It most recently worked on:

$ rustc --version --verbose
rustc 1.82.0-nightly (2cbbe8b8b 2024-07-28)
binary: rustc
commit-hash: 2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b
commit-date: 2024-07-28
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7

Version with regression

$ rustc --version --verbose
rustc 1.82.0-nightly (612a33f20 2024-07-29)
binary: rustc
commit-hash: 612a33f20b9b2c27380edbc4b26a01433ed114bc
commit-date: 2024-07-29
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7

Backtrace

There's no crash.

@YtvwlD YtvwlD added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Aug 2, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 2, 2024
@tgross35
Copy link
Contributor

tgross35 commented Aug 2, 2024

Could you run nm -Cg /home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-uefi/lib/libcompiler_builtins-f2416250465866e5.rlib | grep fmodf and post the output? The symbols should still be available, just as weak, so this should help confirm.

@YtvwlD
Copy link
Author

YtvwlD commented Aug 2, 2024

$ LANG=C nm -Cg /home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-uefi/lib/libcompiler_builtins-f2416250465866e5.rlib | grep fmodf
nm: compiler_builtins-f2416250465866e5.compiler_builtins.326ac9b642684df2-cgu.000.rcgu.o: no symbols
nm: compiler_builtins-f2416250465866e5.compiler_builtins.326ac9b642684df2-cgu.001.rcgu.o: no symbols
...

@tgross35
Copy link
Contributor

tgross35 commented Aug 2, 2024

Does it show up on the working version?

@YtvwlD
Copy link
Author

YtvwlD commented Aug 2, 2024

No, I guess.

$ LANG=C nm -Cg /home/niklas/.rustup/toolchains/nightly-2024-07-29-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-uefi/lib/libcompiler_builtins-b5d296eafb84defb.rlib | grep fmodf
nm: compiler_builtins-b5d296eafb84defb.compiler_builtins.b7ee1e4ea5a8642f-cgu.000.rcgu.o: no symbols
nm: compiler_builtins-b5d296eafb84defb.compiler_builtins.b7ee1e4ea5a8642f-cgu.001.rcgu.o: no symbols
...

@YtvwlD
Copy link
Author

YtvwlD commented Aug 2, 2024

But it seems to be there, somehow:

$ LANG=C grep -r fmodf /home/niklas/.rustup/toolchains/nightly-2024-07-29-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-uefi/lib/
grep: /home/niklas/.rustup/toolchains/nightly-2024-07-29-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-uefi/lib/libcompiler_builtins-b5d296eafb84defb.rlib: binary file matches
$ LANG=C grep -r fmodf /home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-uefi/lib/
$

@tgross35
Copy link
Contributor

tgross35 commented Aug 2, 2024

(edited the above comments to remove output noise)

@tgross35
Copy link
Contributor

tgross35 commented Aug 2, 2024

Thanks for looking into it. compiler_builtins recently had an update that should have made math symbols available on platforms that support it (Linux), but maybe in doing so it disabled the symbols completely on platforms that don't support it.

@YtvwlD
Copy link
Author

YtvwlD commented Aug 15, 2024

It's still available on x86_64-unknown-uefi though:

$ LANG=C grep -r fmodf /home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-uefi/lib/
grep: /home/niklas/.rustup/toolchains/nightly-2024-07-30-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-uefi/lib/libcompiler_builtins-b761541e09399289.rlib: binary file matches
$ LANG=C grep -r fmodf /home/niklas/.rustup/toolchains/nightly-2024-07-29-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-uefi/lib/
grep: /home/niklas/.rustup/toolchains/nightly-2024-07-29-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-uefi/lib/libcompiler_builtins-3c95a63685c02bd4.rlib: binary file matches

@saethlin saethlin added O-UEFI UEFI and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 25, 2024
@apiraino
Copy link
Contributor

apiraino commented Oct 9, 2024

@YtvwlD I'm visiting this issue again. On current stable I cannot reproduce (unless I'm doing it wrong)

$ cargo build --target i686-unknown-uefi
   Compiling issue-128533 v0.1.0 (/home/me/tmp/issue-128533)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.67s

$ rustc --version --verbose
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

can you confirm if it's fixed for you or you can still reproduce?

thanks

@YtvwlD
Copy link
Author

YtvwlD commented Oct 9, 2024

You're right: It compiles on current stable.

> rustc --version --verbose
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

It's still broken on nightly, though:

> rustc --version --verbose
rustc 1.83.0-nightly (6f4ae0f34 2024-10-08)
binary: rustc
commit-hash: 6f4ae0f34503601e54680a137c1db0b81b56cc3d
commit-date: 2024-10-08
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.1

Weird.

@tgross35
Copy link
Contributor

tgross35 commented Oct 9, 2024

We changed compiler_builtins to provide these math symbols weakly on all platforms (including platforms that actually provide them) but wound up changing it back before it hit stable. It wasn’t an exact revert though, the config changed slightly - so my guess is uefi just isn’t getting them enabled still.

I can’t look at this right now but if anyone wants to take a peek, check the config in the math module of the compiler-builtins repo

@YtvwlD
Copy link
Author

YtvwlD commented Oct 10, 2024

Could you point me to the changed configuration? I've tried git log -p origin/master..origin/stable but I didn't see any change to compiler-builtins?

@tgross35
Copy link
Contributor

This is where we control whether math symbols are available https://github.com/Amjad50/compiler-builtins/blob/0fab77e8d72cf232af4977642b52544f0e4ab521/src/lib.rs#L50-L61, I think something around https://github.com/Amjad50/compiler-builtins/blob/127bbc53b5a8986abff28b3af1524342427bf38f/src/lib.rs#L48-L56 would have been the state before the mentioned nightly (2024-07-30). Does our i686 UEFI target not require sse2 or something? I'm not sure why it would not be getting the symbols in the current config.

@tgross35
Copy link
Contributor

tgross35 commented Oct 11, 2024

Ah, no sse2 is indeed the case

$ rustc --print cfg --target i686-unknown-uefi | grep sse
debug_assertions
$ rustc --print cfg --target i686-unknown-linux-gnu | grep sse
debug_assertions
target_feature="sse"
target_feature="sse2"

Were you using fmodf symbols successfully before 2024-07-30, i.e. with correct results? Because of #114479 (linked in the module config) the results are probably unreliable.

I think maybe what we should do here is provide fallback math symbols on non-unix x86 platforms that don't have SSE and just call unimplemented!, so we avoid linking errors but don't give useless results.

@beetrees
Copy link
Contributor

The math symbols should work fine on i686-unknown-uefi as it's a soft-float target (the miscompilations only affect hard-float targets). Although there's no cfg for soft-float, as there's no hard-float i686 UEFI target always enabling the math symbols when target_os = "uefi" should work fine.

@YtvwlD
Copy link
Author

YtvwlD commented Oct 13, 2024

I haven't actually used the float functions, no. As far as I'm aware they're being pulled in because I'm reading a configuration file and it could contain floats, but it doesn't.

@tgross35
Copy link
Contributor

I think the cfg that I linked in compiler-builtins just needs to update all(target_arch = "x86", not(target_feature = "sse2")), to all(target_arch = "x86", not(target_feature = "sse2"), not(target_os = "uefi")), to be in line with what beetrees said. Would you be able to put up a PR @YtvwlD?

YtvwlD added a commit to YtvwlD/compiler-builtins that referenced this issue Oct 21, 2024
In 9ba77d1, this was disabled for x86
without sse2. It should be fine to re-enable it for UEFI, as explained at
<rust-lang/rust#128533 (comment)>.
YtvwlD added a commit to YtvwlD/compiler-builtins that referenced this issue Oct 21, 2024
In 9ba77d1, this was disabled for x86
without sse2. It should be fine to re-enable it for UEFI, as explained at
<rust-lang/rust#128533 (comment)>.
YtvwlD added a commit to YtvwlD/compiler-builtins that referenced this issue Oct 23, 2024
In 9ba77d1, this was disabled for x86
without sse2. It should be fine to re-enable it for UEFI, as explained at
<rust-lang/rust#128533 (comment)>.
@bors bors closed this as completed in 24254ef Nov 1, 2024
@tgross35
Copy link
Contributor

tgross35 commented Nov 1, 2024

@YtvwlD when the next nigtly releases, would you be able to verify this is fixed?

@jieyouxu jieyouxu removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 1, 2024
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Nov 1, 2024
Update compiler-builtins to 0.1.136

This includes:

* The license change rust-lang/compiler-builtins#717
* The `libm` submodule update, which also has a license change rust-lang/libm#317
* Re-enabling `math` on i686 UEFI rust-lang/compiler-builtins#715

Fixes: rust-lang/rust#128533
RalfJung pushed a commit to RalfJung/miri that referenced this issue Nov 2, 2024
Update compiler-builtins to 0.1.136

This includes:

* The license change rust-lang/compiler-builtins#717
* The `libm` submodule update, which also has a license change rust-lang/libm#317
* Re-enabling `math` on i686 UEFI rust-lang/compiler-builtins#715

Fixes: rust-lang/rust#128533
@YtvwlD
Copy link
Author

YtvwlD commented Nov 25, 2024

On, 1.85.0-nightly (28fc2ba71 2024-11-24) both the example and my larger project compile. Thanks!
(Sorry for taking that long.)

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. O-UEFI UEFI regression-untriaged Untriaged performance or correctness regression.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants