rust-lang / rustc_codegen_cranelift

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

Miscompilation of `std::thread::scope` on x86_64 with llvm sysroot #1395

Closed bjorn3 closed 8 months ago

bjorn3 commented 9 months ago
fn main() {
    std::thread::scope(|s| {
        s.spawn(|| {});
    });
}
$ ./y.sh build --sysroot llvm
$ dist/bin/rustc-clif foo.rs
$ RUST_BACKTRACE=1 ./foo
thread 'main' panicked at foo.rs:2:5:
a scoped thread panicked
stack backtrace:
   0: rust_begin_unwind
             at /rustc/65ea825f4021eaf77f1b25139969712d65b435a4/library/std/src/panicking.rs:619:5
   1: core::panicking::panic_fmt
             at /rustc/65ea825f4021eaf77f1b25139969712d65b435a4/library/core/src/panicking.rs:72:14
   2: std::thread::scoped::scope
   3: foo::main
   4: core::ops::function::FnOnce::call_once
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Aborted (core dumped)
bjorn3 commented 9 months ago

This blocks an update of the regex version we test.

bjorn3 commented 8 months ago

Somewhat reduced version:

fn main() {
    std::thread::scope(|s| {
        std::thread::Builder::new().spawn_scoped(s, || {}).expect("failed to spawn thread");
    });
}
bjorn3 commented 8 months ago

https://github.com/bytecodealliance/wasmtime/issues/7210 seems to be the root cause of this. This issue doesn't show up when only using functions compiled with Cranelift as Cranelift doesn't ever take advantage of the uext and sext argument flags.