rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
94.87k stars 12.23k forks source link

rustc SIGSEGV compiling rug 1.24.1 crate on RISC-V Armbian 24.5.0 #127180

Open mathsDOTearth opened 1 week ago

mathsDOTearth commented 1 week ago

Code

[package]
name = "precisionTest"
version = "0.1.0"
edition = "2021"

[dependencies]
rug = "1.24.1"

use rug::{Assign, Float};

fn main() {
    // rust does not support 128-bit or larger floating point numbers natively
    // so we use the rug crate to simulate 128-bit and 256-bit floating point numbers
    // Define the precision for rug floating point vars
    let precision_128 = 128;
    let precision_256 = 256;

    let initial_value = 2.0 / 3.0;
    // Initialize floating point numbers

    let mut s23: f32 = initial_value; // Single precision (32-bit)
    let mut d23: f64 = initial_value as f64; // Double precision (64-bit)
    let mut q23 = Float::with_val(precision_128, initial_value);
    let mut e23 = Float::with_val(precision_256, initial_value);

    // Perform the first series of operations
    println!("Performing operations with initial values of 2/3");
    println!("{:<15} {:<20} {:<42} {:<20}", "s23 (f32)", "d23 (f64)", "q23 (rug float 128)", "e23 (rug float 256)");
    println!("{:<15} {:<20} {:<42} {:<20}", "---------", "---------", "---------", "---------");
    for _ in 1..=18 {
        s23 = s23 / 10.0 + 1.0;
        d23 = d23 / 10.0 + 1.0;
        q23 = q23 / 10.0 + 1.0;
        e23 = e23 / 10.0 + 1.0;
        println!("{:<15} {:<20} {:<42} {:<20}", s23, d23, q23, e23);
    }

    for _ in 1..=17 {
        s23 = (s23 - 1.0) * 10.0;
        d23 = (d23 - 1.0) * 10.0;
        q23 = (q23 - 1.0) * 10.0;
        e23 = (e23 - 1.0) * 10.0;
        println!("{:<15} {:<20} {:<42} {:<20}", s23, d23, q23, e23);
    }
}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (ba1d7f4a0 2024-06-29)
binary: rustc
commit-hash: ba1d7f4a083e6402679105115ded645512a7aea8
commit-date: 2024-06-29
host: riscv64gc-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

rich@bananapif3:~/rust/precisionTest$ cargo run
    Updating crates.io index
     Locking 16 packages to latest compatible versions
   Compiling gmp-mpfr-sys v1.6.4
   Compiling libc v0.2.155
   Compiling az v1.2.1
   Compiling libm v0.2.8
   Compiling rug v1.24.1
error: rustc interrupted by SIGSEGV, printing backtrace

/home/rich/.rustup/toolchains/nightly-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-b89e8be1f02fc7e1.so(+0xc5ce7c)[0x3f918eee7c]
linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x3f9989c800]
/lib/riscv64-linux-gnu/libc.so.6(syscall+0x1c)[0x3f90aaae80]
/home/rich/.rustup/toolchains/nightly-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-c9884c552aa40c8c.so(_ZN3std3sys4sync5mutex5futex5Mutex14lock_contended17ha8e3960d4d6da7beE+0x98)[0x3f90bbb342]
/home/rich/.rustup/toolchains/nightly-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-c9884c552aa40c8c.so(_ZN3std3sys4sync7condvar5futex7Condvar4wait17h70cf2c3a001d1809E+0xaa)[0x3f90bfe9f6]
/home/rich/.rustup/toolchains/nightly-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-b89e8be1f02fc7e1.so(+0x5cf4dee)[0x3f96986dee]
/home/rich/.rustup/toolchains/nightly-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-b89e8be1f02fc7e1.so(+0x5cf5ba8)[0x3f96987ba8]
/home/rich/.rustup/toolchains/nightly-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-b89e8be1f02fc7e1.so(+0x5cf5bf8)[0x3f96987bf8]
/home/rich/.rustup/toolchains/nightly-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-b89e8be1f02fc7e1.so(+0x5cf62ba)[0x3f969882ba]
/home/rich/.rustup/toolchains/nightly-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-b89e8be1f02fc7e1.so(+0x5cf6c14)[0x3f96988c14]
/home/rich/.rustup/toolchains/nightly-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-c9884c552aa40c8c.so(rust_metadata_std_7312307a1d21ac33+0x8623a)[0x3f90bfb23a]
/lib/riscv64-linux-gnu/libc.so.6(+0x710f4)[0x3f90a5a0f4]
/lib/riscv64-linux-gnu/libc.so.6(+0xc3908)[0x3f90aac908]
Backtrace

``` ```

saethlin commented 6 days ago

I think you are running into the kernel bug linked from here: https://github.com/rust-lang/rust/issues/117022#issuecomment-1841043719

bjorn3 commented 6 days ago

Can we detect the kernel version in libstd's initialization code when on riscv and print a warning if the kernel is too old? That would save us from getting bugs reported every once in a while.