Repository navigation
libm 0.2.12 breaks rust-gpu #242
Copy link
Copy link
Labels
bugSomething isn't workingSomething isn't working
Description
Summary
libm 0.2.12+ breaks rust-gpu due to introducing new intrinsics that interact with rustc. We have a bit of a weird way to process these intrinsics and emit the corresponding SPIR-V (potentially with GLSL extensions) that needs to be updated to understand these new intrinsics. For now, we're locking libm to 0.2.11 to prevent new projects or cargo update from picking up newer broken versions.
Expected Behaviour
Successful compilation
Example & Steps To Reproduce
- clone repository https://github.com/simensgreen/rust_gpu_union_issue
cargo build
System Info
- Rust: rustc 1.84.0-nightly (b19329a37 2024-11-21)
- OS: MacOS 15.3.2
- GPU: M2 Max
Backtrace
Backtrace
thread 'rustc' panicked at compiler/rustc_middle/src/ty/mod.rs:1676:13:
Box<dyn Any>
stack backtrace:
0: 0x1129ed7b0 - std::backtrace::Backtrace::create::hf5e5ba1728bb8de7
1: 0x110844da8 - <alloc[e2e5e8515d00274d]::boxed::Box<rustc_driver_impl[c6ade677a6b0e20c]::install_ice_hook::{closure#0}> as core[924c651d484e1a25]::ops::function::Fn<(&dyn for<'a, 'b> core[924c651d484e1a25]::ops::function::Fn<(&'a std[fc297465fa958267]::panic::PanicHookInfo<'b>,), Output = ()> + core[924c651d484e1a25]::marker::Send + core[924c651d484e1a25]::marker::Sync, &std[fc297465fa958267]::panic::PanicHookInfo)>>::call
2: 0x110844bb0 - <alloc[e2e5e8515d00274d]::boxed::Box<rustc_driver_impl[c6ade677a6b0e20c]::install_ice_hook::{closure#0}> as core[924c651d484e1a25]::ops::function::Fn<(&dyn for<'a, 'b> core[924c651d484e1a25]::ops::function::Fn<(&'a std[fc297465fa958267]::panic::PanicHookInfo<'b>,), Output = ()> + core[924c651d484e1a25]::marker::Send + core[924c651d484e1a25]::marker::Sync, &std[fc297465fa958267]::panic::PanicHookInfo)>>::call
3: 0x112a07edc - std::panicking::rust_panic_with_hook::heb73fc7746f92ba7
4: 0x1108e9718 - std[fc297465fa958267]::panicking::begin_panic::<rustc_errors[caf545eadef7fdd]::ExplicitBug>::{closure#0}
5: 0x1108e94d0 - std[fc297465fa958267]::sys::backtrace::__rust_end_short_backtrace::<std[fc297465fa958267]::panicking::begin_panic<rustc_errors[caf545eadef7fdd]::ExplicitBug>::{closure#0}, !>
6: 0x11516c04c - std[fc297465fa958267]::panicking::begin_panic::<rustc_errors[caf545eadef7fdd]::ExplicitBug>
7: 0x1108efad4 - <rustc_errors[caf545eadef7fdd]::diagnostic::BugAbort as rustc_errors[caf545eadef7fdd]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
8: 0x111590098 - rustc_middle[dc5a577fd6f5eb51]::util::bug::opt_span_bug_fmt::<rustc_span[60df94d8028129a3]::span_encoding::Span>::{closure#0}
9: 0x11158eb1c - rustc_middle[dc5a577fd6f5eb51]::ty::context::tls::with_opt::<rustc_middle[dc5a577fd6f5eb51]::util::bug::opt_span_bug_fmt<rustc_span[60df94d8028129a3]::span_encoding::Span>::{closure#0}, !>::{closure#0}
10: 0x11158eae8 - rustc_middle[dc5a577fd6f5eb51]::ty::context::tls::with_context_opt::<rustc_middle[dc5a577fd6f5eb51]::ty::context::tls::with_opt<rustc_middle[dc5a577fd6f5eb51]::util::bug::opt_span_bug_fmt<rustc_span[60df94d8028129a3]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
11: 0x115218d90 - rustc_middle[dc5a577fd6f5eb51]::util::bug::bug_fmt
12: 0x11154678c - <rustc_middle[dc5a577fd6f5eb51]::ty::context::TyCtxt>::item_name
13: 0x10a88e08c - rustc_codegen_spirv::codegen_cx::declare::<impl rustc_codegen_spirv::codegen_cx::CodegenCx>::declare_fn_ext::h62af5aed91b065ab
14: 0x10a88f6bc - rustc_codegen_spirv::codegen_cx::declare::<impl rustc_codegen_spirv::maybe_pqp_cg_ssa::traits::declare::PreDefineCodegenMethods for rustc_codegen_spirv::codegen_cx::CodegenCx>::predefine_fn::hb68792579dcb451d
15: 0x10a81f738 - <rustc_middle::mir::mono::MonoItem as rustc_codegen_spirv::maybe_pqp_cg_ssa::mono_item::MonoItemExt>::predefine::h9fc0a1eadbbb089b
16: 0x10a803d74 - <rustc_codegen_spirv::SpirvCodegenBackend as rustc_codegen_spirv::maybe_pqp_cg_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit::{{closure}}::h0debe4e59a7b21f1
17: 0x10a803820 - <rustc_codegen_spirv::SpirvCodegenBackend as rustc_codegen_spirv::maybe_pqp_cg_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit::h1919ebc51166cdfc
18: 0x10a8a55e0 - rustc_codegen_spirv::maybe_pqp_cg_ssa::base::codegen_crate::hef28e44872569f65
19: 0x10a8024f8 - <rustc_codegen_spirv::SpirvCodegenBackend as rustc_codegen_spirv::maybe_pqp_cg_ssa::traits::backend::CodegenBackend>::codegen_crate::hffbf186d2f0b9484
20: 0x1110dbad8 - <rustc_session[3e2f7db2cc04b493]::session::Session>::time::<alloc[e2e5e8515d00274d]::boxed::Box<dyn core[924c651d484e1a25]::any::Any>, rustc_interface[fb6f1569d3f1850c]::passes::start_codegen::{closure#0}>
21: 0x11120add4 - rustc_interface[fb6f1569d3f1850c]::passes::start_codegen
22: 0x1111985f0 - <rustc_interface[fb6f1569d3f1850c]::queries::Linker>::codegen_and_build_linker
23: 0x11082dd20 - <rustc_middle[dc5a577fd6f5eb51]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[c6ade677a6b0e20c]::run_compiler::{closure#0}::{closure#1}::{closure#7}, core[924c651d484e1a25]::result::Result<core[924c651d484e1a25]::option::Option<rustc_interface[fb6f1569d3f1850c]::queries::Linker>, rustc_span[60df94d8028129a3]::ErrorGuaranteed>>
24: 0x1107f51b0 - <rustc_interface[fb6f1569d3f1850c]::interface::Compiler>::enter::<rustc_driver_impl[c6ade677a6b0e20c]::run_compiler::{closure#0}::{closure#1}, core[924c651d484e1a25]::result::Result<core[924c651d484e1a25]::option::Option<rustc_interface[fb6f1569d3f1850c]::queries::Linker>, rustc_span[60df94d8028129a3]::ErrorGuaranteed>>
25: 0x110837588 - rustc_span[60df94d8028129a3]::create_session_globals_then::<core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>, rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_with_globals<rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_pool_with_globals<rustc_interface[fb6f1569d3f1850c]::interface::run_compiler<core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>, rustc_driver_impl[c6ade677a6b0e20c]::run_compiler::{closure#0}>::{closure#1}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}>
26: 0x11081f588 - std[fc297465fa958267]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_with_globals<rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_pool_with_globals<rustc_interface[fb6f1569d3f1850c]::interface::run_compiler<core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>, rustc_driver_impl[c6ade677a6b0e20c]::run_compiler::{closure#0}>::{closure#1}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>
27: 0x110822b54 - <<std[fc297465fa958267]::thread::Builder>::spawn_unchecked_<rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_with_globals<rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_pool_with_globals<rustc_interface[fb6f1569d3f1850c]::interface::run_compiler<core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>, rustc_driver_impl[c6ade677a6b0e20c]::run_compiler::{closure#0}>::{closure#1}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#1} as core[924c651d484e1a25]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
28: 0x112a11fe8 - std::sys::pal::unix::thread::Thread::new::thread_start::h5a3f92a0fdbf8eb0
29: 0x1978002e4 - __pthread_deallocate
rustc version: 1.84.0-nightly (b19329a37 2024-11-21)
platform: aarch64-apple-darwin
query stack during panic:
end of query stack
thread 'rustc' panicked at compiler/rustc_middle/src/ty/mod.rs:1676:13:
Box<dyn Any>
stack backtrace:
0: 0x1129ed7b0 - std::backtrace::Backtrace::create::hf5e5ba1728bb8de7
1: 0x110844da8 - <alloc[e2e5e8515d00274d]::boxed::Box<rustc_driver_impl[c6ade677a6b0e20c]::install_ice_hook::{closure#0}> as core[924c651d484e1a25]::ops::function::Fn<(&dyn for<'a, 'b> core[924c651d484e1a25]::ops::function::Fn<(&'a std[fc297465fa958267]::panic::PanicHookInfo<'b>,), Output = ()> + core[924c651d484e1a25]::marker::Send + core[924c651d484e1a25]::marker::Sync, &std[fc297465fa958267]::panic::PanicHookInfo)>>::call
2: 0x112a07edc - std::panicking::rust_panic_with_hook::heb73fc7746f92ba7
3: 0x1108e9718 - std[fc297465fa958267]::panicking::begin_panic::<rustc_errors[caf545eadef7fdd]::ExplicitBug>::{closure#0}
4: 0x1108e94d0 - std[fc297465fa958267]::sys::backtrace::__rust_end_short_backtrace::<std[fc297465fa958267]::panicking::begin_panic<rustc_errors[caf545eadef7fdd]::ExplicitBug>::{closure#0}, !>
5: 0x11516c04c - std[fc297465fa958267]::panicking::begin_panic::<rustc_errors[caf545eadef7fdd]::ExplicitBug>
6: 0x1108efad4 - <rustc_errors[caf545eadef7fdd]::diagnostic::BugAbort as rustc_errors[caf545eadef7fdd]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
7: 0x111590098 - rustc_middle[dc5a577fd6f5eb51]::util::bug::opt_span_bug_fmt::<rustc_span[60df94d8028129a3]::span_encoding::Span>::{closure#0}
8: 0x11158eb1c - rustc_middle[dc5a577fd6f5eb51]::ty::context::tls::with_opt::<rustc_middle[dc5a577fd6f5eb51]::util::bug::opt_span_bug_fmt<rustc_span[60df94d8028129a3]::span_encoding::Span>::{closure#0}, !>::{closure#0}
9: 0x11158eae8 - rustc_middle[dc5a577fd6f5eb51]::ty::context::tls::with_context_opt::<rustc_middle[dc5a577fd6f5eb51]::ty::context::tls::with_opt<rustc_middle[dc5a577fd6f5eb51]::util::bug::opt_span_bug_fmt<rustc_span[60df94d8028129a3]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
10: 0x115218d90 - rustc_middle[dc5a577fd6f5eb51]::util::bug::bug_fmt
11: 0x11154678c - <rustc_middle[dc5a577fd6f5eb51]::ty::context::TyCtxt>::item_name
12: 0x10a88e08c - rustc_codegen_spirv::codegen_cx::declare::<impl rustc_codegen_spirv::codegen_cx::CodegenCx>::declare_fn_ext::h62af5aed91b065ab
13: 0x10a88f6bc - rustc_codegen_spirv::codegen_cx::declare::<impl rustc_codegen_spirv::maybe_pqp_cg_ssa::traits::declare::PreDefineCodegenMethods for rustc_codegen_spirv::codegen_cx::CodegenCx>::predefine_fn::hb68792579dcb451d
14: 0x10a81f738 - <rustc_middle::mir::mono::MonoItem as rustc_codegen_spirv::maybe_pqp_cg_ssa::mono_item::MonoItemExt>::predefine::h9fc0a1eadbbb089b
15: 0x10a803d74 - <rustc_codegen_spirv::SpirvCodegenBackend as rustc_codegen_spirv::maybe_pqp_cg_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit::{{closure}}::h0debe4e59a7b21f1
16: 0x10a803820 - <rustc_codegen_spirv::SpirvCodegenBackend as rustc_codegen_spirv::maybe_pqp_cg_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit::h1919ebc51166cdfc
17: 0x10a8a55e0 - rustc_codegen_spirv::maybe_pqp_cg_ssa::base::codegen_crate::hef28e44872569f65
18: 0x10a8024f8 - <rustc_codegen_spirv::SpirvCodegenBackend as rustc_codegen_spirv::maybe_pqp_cg_ssa::traits::backend::CodegenBackend>::codegen_crate::hffbf186d2f0b9484
19: 0x1110dbad8 - <rustc_session[3e2f7db2cc04b493]::session::Session>::time::<alloc[e2e5e8515d00274d]::boxed::Box<dyn core[924c651d484e1a25]::any::Any>, rustc_interface[fb6f1569d3f1850c]::passes::start_codegen::{closure#0}>
20: 0x11120add4 - rustc_interface[fb6f1569d3f1850c]::passes::start_codegen
21: 0x1111985f0 - <rustc_interface[fb6f1569d3f1850c]::queries::Linker>::codegen_and_build_linker
22: 0x11082dd20 - <rustc_middle[dc5a577fd6f5eb51]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[c6ade677a6b0e20c]::run_compiler::{closure#0}::{closure#1}::{closure#7}, core[924c651d484e1a25]::result::Result<core[924c651d484e1a25]::option::Option<rustc_interface[fb6f1569d3f1850c]::queries::Linker>, rustc_span[60df94d8028129a3]::ErrorGuaranteed>>
23: 0x1107f51b0 - <rustc_interface[fb6f1569d3f1850c]::interface::Compiler>::enter::<rustc_driver_impl[c6ade677a6b0e20c]::run_compiler::{closure#0}::{closure#1}, core[924c651d484e1a25]::result::Result<core[924c651d484e1a25]::option::Option<rustc_interface[fb6f1569d3f1850c]::queries::Linker>, rustc_span[60df94d8028129a3]::ErrorGuaranteed>>
24: 0x110837588 - rustc_span[60df94d8028129a3]::create_session_globals_then::<core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>, rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_with_globals<rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_pool_with_globals<rustc_interface[fb6f1569d3f1850c]::interface::run_compiler<core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>, rustc_driver_impl[c6ade677a6b0e20c]::run_compiler::{closure#0}>::{closure#1}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}>
25: 0x11081f588 - std[fc297465fa958267]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_with_globals<rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_pool_with_globals<rustc_interface[fb6f1569d3f1850c]::interface::run_compiler<core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>, rustc_driver_impl[c6ade677a6b0e20c]::run_compiler::{closure#0}>::{closure#1}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>
26: 0x110822b54 - <<std[fc297465fa958267]::thread::Builder>::spawn_unchecked_<rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_with_globals<rustc_interface[fb6f1569d3f1850c]::util::run_in_thread_pool_with_globals<rustc_interface[fb6f1569d3f1850c]::interface::run_compiler<core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>, rustc_driver_impl[c6ade677a6b0e20c]::run_compiler::{closure#0}>::{closure#1}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[924c651d484e1a25]::result::Result<(), rustc_span[60df94d8028129a3]::ErrorGuaranteed>>::{closure#1} as core[924c651d484e1a25]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
27: 0x112a11fe8 - std::sys::pal::unix::thread::Thread::new::thread_start::h5a3f92a0fdbf8eb0
28: 0x1978002e4 - __pthread_deallocate
query stack during panic:
end of query stack
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
[-](my bug report)[/-][+]Rust-gpu main fails to build[/+]LegNeato commentedon Apr 24, 2025
LegNeato commentedon Apr 24, 2025
I am getting a panic here:
rust-gpu/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs
Line 174 in 6bbbfe4
LegNeato commentedon Apr 24, 2025
LegNeato commentedon Apr 24, 2025
Ok, looks like updating the lockfile causes issues:
https://github.com/Rust-GPU/rust-gpu/actions/runs/14645774261/job/41099428403?pr=243
So it is in one of those.
LegNeato commentedon Apr 24, 2025
This was probably caused by libm releasing 0.2.13 2 days ago. Can't find the issue right now, will look later if someone hasn't beaten me to it.
simensgreen commentedon Apr 24, 2025
Yeah, if force libm to 0.2.11 this error disappears. Check out https://github.com/simensgreen/rust_gpu_union_issue/tree/libm-fixed
LegNeato commentedon Apr 25, 2025
Ok, so something about our symbol resolution when swapping out libm intrinsics is messing up with the new versions.
LegNeato commentedon Apr 25, 2025
I don't have time to bisect, but a good candidate is rust-lang/compiler-builtins@161036a. My hunch is because these are inlined, we can't replace the symbol because the symbol doesn't exist because they're inlined.
LegNeato commentedon Apr 25, 2025
To work around this for now you can use patch in your Cargo.toml for crates.io to set libm for all deps.
tgross35 commentedon Apr 25, 2025
Coming here from the libm side. is this crate looking for global symbols from a libm rlib? If so this isn't reliable, we don't provide
#[no_mangle]symbols. If this is needed then you may need to provide a wrapper shim that exports what you expect, unless the symbols can come from compiler-builtins somehow (c-b reexports the libm functions asextern c).LegNeato commentedon Apr 26, 2025
Ok thanks. I am unfamiliar with this portion of the project so I'll take a this week if someone doesn't get to it before me, thanks for chiming in.
LegNeato commentedon Apr 29, 2025
Just an update on this, we landed a temporary fix to lock
libmto a specific version without this issue, but we have not delved into the root cause yet.tgross35 commentedon Apr 29, 2025
Do you happen to know what this error actually prints? Might narrow things down.
There is also a chance this is related to f16 or f128 if those aren't well supported in the cg backend yet. As of very recently, the backends can say whether or not they support them rust-lang/rust#140323, I'll be switching libm and compiler-builtins to use this after the beta branch and bootstrap bump (~2 weeks).
LegNeato commentedon Apr 29, 2025
We're on an old version of rustc that doesn't include those changes I think (nightly-2024-11-22). I'll get the messages later today. Thanks for following up!
Firestar99 commentedon Jun 29, 2025
should have been closed by #244
[-]Rust-gpu main fails to build[/-][+]libm `0.2.12` breaks rust-gpu[/+]tuguzT commentedon Aug 15, 2025
I'm trying to delve into the root cause as a contributor.
By the output below (when compiling
glamcrate) I guess thatrust-gpubackend tries to use alllibmpublic functions (with or without actuallibmintrinsics, IDK for sure):...with lots of similar errors, and at the end it outputs this:
Currently I'm trying to find out if
libmprovided extern symbols for intrinsics before 0.2.11 or not, and if it provides them now...U.P.D.: I noticed that filtering out by "math::" substring does not work, because in either case output contains this:
What does
crate0even mean?Maybe it is just inlining after all...
Here is another interesting part of the output (look at 21-23):
I have a theory that backend tries to replace all the public functions usages inside of
libmitself, which causes such an issue.I think so because via experimenting a bit I got this result:
libm:glam(which haslibmas dependency):Another proof is that local
DefIdhaskratefield defined asLOCAL_CRATE, orCrateNum::ZERO, which I guess iscrate0Honestly, this feels like "suffering from success" energy