rust-lang / rustc_codegen_cranelift

Cranelift based backend for rustc
Apache License 2.0
1.52k stars 94 forks source link

Panic at llvm.x86.sha1rnds4 #1453

Closed lukaskund closed 3 months ago

lukaskund commented 5 months ago

Error:

trap at Instance { def: Item(DefId(1:15432 ~ core[fb63]::core_arch::x86::sha::_mm_sha1rnds4_epu32)), args: [0_i32] } (_ZN4core9core_arch3x863sha19_mm_sha1rnds4_epu3217hded8966227fb8788E): llvm.x86.sha1rnds4

looks like due sha2 crate usage. Should be related to https://github.com/rust-lang/rustc_codegen_cranelift/issues/1173 and https://github.com/rust-lang/rustc_codegen_cranelift/issues/1427.

Let me know if any additional info is required, cheers

bjorn3 commented 5 months ago

This comes from using SHA-1. The SHA-256 intrinsics are already implemented. I will implement the SHA-1 intrinsics, but be aware that SHA-1 hash collisions have been demonstrated.

bjorn3 commented 5 months ago

Could you test the sha1 branch? Prebuilt artifacts should be available at https://github.com/rust-lang/rustc_codegen_cranelift/actions/runs/7716798292 in a couple of minutes. The machine I'm testing on doesn't seem to have support for the sha1 instructions.

lukaskund commented 5 months ago

This comes from using SHA-1. The SHA-256 intrinsics are already implemented. I will implement the SHA-1 intrinsics, but be aware that SHA-1 hash collisions have been demonstrated.

Indeed, I see sha-1 is transitive dependency in latest version of web3 crate that we use.

Could you test the sha1 branch? Prebuilt artifacts should be available at https://github.com/rust-lang/rustc_codegen_cranelift/actions/runs/7716798292 in a couple of minutes. The machine I'm testing on doesn't seem to have support for the sha1 instructions.

Compiling indexmap v1.9.3
thread 'rustc' panicked at src/intrinsics/llvm_x86.rs:1087:61:
kind not scalar: 0x01
stack backtrace:
   0:     0x7f13c43b1f86 - std::backtrace_rs::backtrace::libunwind::trace::h514ead2753e1782f
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f13c43b1f86 - std::backtrace_rs::backtrace::trace_unsynchronized::hbc462e8372651887
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f13c43b1f86 - std::sys_common::backtrace::_print_fmt::he3092ef183bdd613
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f13c43b1f86 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h908f80a389799910
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f13c4404880 - core::fmt::rt::Argument::fmt::ha9f3d8b02e25296c
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/core/src/fmt/rt.rs:142:9
   5:     0x7f13c4404880 - core::fmt::write::hef880bc86bd63d4b
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f13c43a594f - std::io::Write::write_fmt::h780869503f755b5a
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/io/mod.rs:1810:15
   7:     0x7f13c43b1d64 - std::sys_common::backtrace::_print::h52cc78326ec17ac5
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f13c43b1d64 - std::sys_common::backtrace::print::h44b4c057fd1c7c3f
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f13c43b4af7 - std::panicking::default_hook::{{closure}}::h99cbf699c09f8685
  10:     0x7f13c43b4859 - std::panicking::default_hook::hbc89d54398681576
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/panicking.rs:292:9
  11:     0x7f13c114acec - std[1d0ea5b5e602c844]::panicking::update_hook::<alloc[d84df3010862da1b]::boxed::Box<rustc_driver_impl[2078f68ece4ea2b8]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f13c43b5246 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h99950b3f8a1ddee8
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/alloc/src/boxed.rs:2029:9
  13:     0x7f13c43b5246 - std::panicking::rust_panic_with_hook::he160495ec53b11e6
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/panicking.rs:785:13
  14:     0x7f13c43b4f92 - std::panicking::begin_panic_handler::{{closure}}::ha86f6320ad4cac49
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/panicking.rs:659:13
  15:     0x7f13c43b2486 - std::sys_common::backtrace::__rust_end_short_backtrace::h19c3911246e5b7ea
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f13c43b4ce4 - rust_begin_unwind
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/panicking.rs:647:5
  17:     0x7f13c4400f85 - core::panicking::panic_fmt::hd869deda4756f0c1
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/core/src/panicking.rs:72:14
  18:     0x7f13b475df5e - rustc_codegen_cranelift::intrinsics::llvm_x86::codegen_x86_llvm_intrinsic_call::h4b12c8c8f8401386
  19:     0x7f13b470c6bf - rustc_codegen_cranelift::abi::codegen_terminator_call::hbbd9658b5f270f7a
  20:     0x7f13b472752f - rustc_codegen_cranelift::base::codegen_fn_body::hf0b55fd71e5a3f07
  21:     0x7f13b472268e - rustc_codegen_cranelift::base::codegen_fn::hec6ed580dd26ebca
  22:     0x7f13b4791c0c - rustc_codegen_cranelift::driver::aot::module_codegen::h7860ff434796f381
  23:     0x7f13b479ad72 - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::h0d7af58436aff739
  24:     0x7f13b47f0f29 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::hdfb2596f63dc02f2
  25:     0x7f13b471991e - rustc_session::utils::<impl rustc_session::session::Session>::time::hbd8cd645561bb280
  26:     0x7f13b4792941 - rustc_codegen_cranelift::driver::aot::run_aot::h4b3638e5cafa5197
  27:     0x7f13b47a9d9e - <rustc_codegen_cranelift::CraneliftCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::h28cb8d46ca47e793
  28:     0x7f13c30a7df0 - rustc_interface[567ccd780f164b19]::passes::start_codegen
  29:     0x7f13c30a755c - <rustc_interface[567ccd780f164b19]::queries::Queries>::codegen_and_build_linker
  30:     0x7f13c314168a - rustc_interface[567ccd780f164b19]::interface::run_compiler::<core[1eaf6a36b93e3ccb]::result::Result<(), rustc_span[950276472281dfd0]::ErrorGuaranteed>, rustc_driver_impl[2078f68ece4ea2b8]::run_compiler::{closure#0}>::{closure#0}
  31:     0x7f13c33cf306 - std[1d0ea5b5e602c844]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[567ccd780f164b19]::util::run_in_thread_with_globals<rustc_interface[567ccd780f164b19]::util::run_in_thread_pool_with_globals<rustc_interface[567ccd780f164b19]::interface::run_compiler<core[1eaf6a36b93e3ccb]::result::Result<(), rustc_span[950276472281dfd0]::ErrorGuaranteed>, rustc_driver_impl[2078f68ece4ea2b8]::run_compiler::{closure#0}>::{closure#0}, core[1eaf6a36b93e3ccb]::result::Result<(), rustc_span[950276472281dfd0]::ErrorGuaranteed>>::{closure#0}, core[1eaf6a36b93e3ccb]::result::Result<(), rustc_span[950276472281dfd0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1eaf6a36b93e3ccb]::result::Result<(), rustc_span[950276472281dfd0]::ErrorGuaranteed>>
  32:     0x7f13c33cf133 - <<std[1d0ea5b5e602c844]::thread::Builder>::spawn_unchecked_<rustc_interface[567ccd780f164b19]::util::run_in_thread_with_globals<rustc_interface[567ccd780f164b19]::util::run_in_thread_pool_with_globals<rustc_interface[567ccd780f164b19]::interface::run_compiler<core[1eaf6a36b93e3ccb]::result::Result<(), rustc_span[950276472281dfd0]::ErrorGuaranteed>, rustc_driver_impl[2078f68ece4ea2b8]::run_compiler::{closure#0}>::{closure#0}, core[1eaf6a36b93e3ccb]::result::Result<(), rustc_span[950276472281dfd0]::ErrorGuaranteed>>::{closure#0}, core[1eaf6a36b93e3ccb]::result::Result<(), rustc_span[950276472281dfd0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1eaf6a36b93e3ccb]::result::Result<(), rustc_span[950276472281dfd0]::ErrorGuaranteed>>::{closure#1} as core[1eaf6a36b93e3ccb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7f13c43be835 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hba0b80fd74ce5417
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/alloc/src/boxed.rs:2015:9
  34:     0x7f13c43be835 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h0ab2d213dcdff51c
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/alloc/src/boxed.rs:2015:9
  35:     0x7f13c43be835 - std::sys::pal::unix::thread::Thread::new::thread_start::h7eeca5a8e186b7ad
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys/pal/unix/thread.rs:108:17
   Compiling num-traits v0.2.17
  36:     0x7f13be094ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  37:     0x7f13be126850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  38:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please attach the file at `/home/lukas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sha1-0.10.6/rustc-ice-2024-01-30T22_12_32-1988632.txt` to your bug report

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C panic=abort -Z panic-abort-tests -Z codegen-backend=/home/lukas/Downloads/dist/lib/librustc_codegen_cranelift.so

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
terminator _3 = core::core_arch::x86::sha::sha1rnds4(move _4, move _5, move _6) -> [return: bb3, unwind unreachable]
fn core::arch::x86_64::_mm_sha1rnds4_epu32(_1: core::arch::x86_64::__m128i, _2: core::arch::x86_64::__m128i) -> core::arch::x86_64::__m128i {
    debug a => _1;
    debug b => _2;
    let mut _0: core::arch::x86_64::__m128i;
    let mut _3: core::core_arch::simd::i32x4;
    let mut _4: core::core_arch::simd::i32x4;
    let mut _5: core::core_arch::simd::i32x4;
    let mut _6: i8;
    scope 1 {
    }

    bb0: {
        StorageLive(_3);
        StorageLive(_4);
        _4 = <core::arch::x86_64::__m128i as core::core_arch::x86::m128iExt>::as_i32x4(move _1) -> [return: bb1, unwind unreachable];
    }

    bb1: {
        StorageLive(_5);
        _5 = <core::arch::x86_64::__m128i as core::core_arch::x86::m128iExt>::as_i32x4(move _2) -> [return: bb2, unwind unreachable];
    }

    bb2: {
        StorageLive(_6);
        _6 = const FUNC as i8 (IntToInt);
        _3 = core::core_arch::x86::sha::sha1rnds4(move _4, move _5, move _6) -> [return: bb3, unwind unreachable];
    }

    bb3: {
        StorageDead(_6);
        StorageDead(_5);
        StorageDead(_4);
        _0 = move _3 as core::arch::x86_64::__m128i (Transmute);
        StorageDead(_3);
        return;
    }
}

error: could not compile `sha1` (lib)
warning: build failed, waiting for other jobs to finish...

Thanks for such quick response and let me know if there's anything else I can help with.


BTW I see your bootstrap_rustc job failed in Test step on the same line as mine

bjorn3 commented 5 months ago

Should be fixed now. Precompiled artifacts available at https://github.com/rust-lang/rustc_codegen_cranelift/actions/runs/7739824014

lukaskund commented 5 months ago

Should be fixed now. Precompiled artifacts available at https://github.com/rust-lang/rustc_codegen_cranelift/actions/runs/7739824014

It works, thanks! Any ETA when we could expect this in nightly?

bjorn3 commented 5 months ago

Thanks for confirming it works! I've merged that branch into the master branch of this repo. I don't have an ETA for when I will do the next sync into the rust repo yet. It will be available on the next nightly after I've done a sync. I will let you know when that happens.

bjorn3 commented 3 months ago

The sync was done earlier today. It will be in the next nightly.