rust-lang / rustc_codegen_cranelift

Cranelift based backend for rustc
Apache License 2.0
1.59k stars 100 forks source link

Failed to compile rustc with cranelift backend on m2 with 128bit atomics not yet supported #1402

Closed Alvenix closed 11 months ago

Alvenix commented 11 months ago

I am not sure If I should open this issue here.

Adding cranelift backend to config and building the stage2 compiler fails.

cat > config.toml <<EOF
[rust]
codegen-backends = ["cranelift"]
EOF

Here is the error:

error: 128bit atomics not yet supported
    --> library/core/src/sync/atomic.rs:3250:24
     |
3250 |             Relaxed => intrinsics::atomic_load_relaxed(dst),
     |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

terminator _0 = intrinsics::atomic_load_relaxed::<T>(move _1) -> [return: bb7, unwind unreachable]                                                                                                        
fn sync::atomic::atomic_load(_1: *const T, _2: sync::atomic::Ordering) -> T {
    debug dst => _1;
    debug order => _2;
    let mut _0: T;
    let mut _3: isize;
    let _4: !;
    let mut _5: fmt::Arguments<'_>;
    let mut _6: &[&str];
    let _7: !;
    let mut _8: fmt::Arguments<'_>;
    let mut _9: &[&str];
    scope 1 {
        let mut _10: &[&str; 1];
        let mut _11: &[&str; 1];
        scope 2 (inlined fmt::Arguments::<'_>::new_const) {
            debug pieces => _9;
            let mut _12: bool;
            let mut _13: usize;
            let _14: !;
            let mut _15: fmt::Arguments<'_>;
            let mut _16: &[&str];
            let mut _17: option::Option<&[fmt::rt::Placeholder]>;
            let mut _18: &[fmt::rt::Argument<'_>];
            let mut _19: &[&str; 1];
            let mut _20: &[fmt::rt::Argument<'_>; 0];
        }
        scope 3 (inlined fmt::Arguments::<'_>::new_const) {
            debug pieces => _6;
            let mut _21: bool;
            let mut _22: usize;
            let _23: !;
            let mut _24: fmt::Arguments<'_>;
            let mut _25: &[&str];
            let mut _26: option::Option<&[fmt::rt::Placeholder]>;
            let mut _27: &[fmt::rt::Argument<'_>];
            let mut _28: &[&str; 1];
            let mut _29: &[fmt::rt::Argument<'_>; 0];
        }
    }

    bb0: {
        _3 = discriminant(_2);
        switchInt(move _3) -> [0: bb3, 1: bb6, 2: bb4, 3: bb1, 4: bb5, otherwise: bb2];
    }

    bb1: {
        StorageLive(_8);
        StorageLive(_9);
        _10 = const _;
        _9 = _10 as &[&str] (PointerCoercion(Unsize));
        StorageLive(_19);
        StorageLive(_20);
    Building         StorageLive(_12);
        StorageLive(_13);   ] 12/37: libc, core, compiler_builtins                                                                                                                           
        _13 = Len((*_9));
        _12 = Gt(move _13, const 1_usize);
        switchInt(move _12) -> [0: bb10, otherwise: bb8];
    }

    bb2: {
        unreachable;
    }

    bb3: {
        _0 = intrinsics::atomic_load_relaxed::<T>(move _1) -> [return: bb7, unwind unreachable];
    }

    bb4: {
        _0 = intrinsics::atomic_load_acquire::<T>(move _1) -> [return: bb7, unwind unreachable];
    }

    bb5: {
        _0 = intrinsics::atomic_load_seqcst::<T>(move _1) -> [return: bb7, unwind unreachable];
    }

    bb6: {
        StorageLive(_5);
        StorageLive(_6);
        _11 = const _;
        _6 = _11 as &[&str] (PointerCoercion(Unsize));
        StorageLive(_28);
        StorageLive(_29);
        StorageLive(_21);
        StorageLive(_22);
        _22 = Len((*_6));
        _21 = Gt(move _22, const 1_usize);
        switchInt(move _21) -> [0: bb13, otherwise: bb11];
    }

    bb7: {
        return;
    }

    bb8: {
        StorageDead(_13);
        StorageLive(_15);
        StorageLive(_16);
        _19 = const _;
        _16 = _19 as &[&str] (PointerCoercion(Unsize));
        _15 = fmt::Arguments::<'_>::new_const(move _16) -> [return: bb9, unwind continue];
    }

    bb9: {
        StorageDead(_16);
        _14 = panicking::panic_fmt(move _15) -> unwind continue;
    }

    bb10: {
        StorageDead(_13);
        StorageDead(_12);
        StorageLive(_17);
        _17 = option::Option::<&[fmt::rt::Placeholder]>::None;
        StorageLive(_18);
        _20 = const _;
        _18 = _20 as &[fmt::rt::Argument<'_>] (PointerCoercion(Unsize));
        _8 = fmt::Arguments::<'_> { pieces: _9, fmt: move _17, args: move _18 };
        StorageDead(_18);
        StorageDead(_17);
        StorageDead(_20);
        StorageDead(_19);
        StorageDead(_9);
        _7 = panicking::panic_fmt(move _8) -> unwind continue;
    }

    bb11: {
        StorageDead(_22);
        StorageLive(_24);
        StorageLive(_25);
        _28 = const _;
        _25 = _28 as &[&str] (PointerCoercion(Unsize));
        _24 = fmt::Arguments::<'_>::new_const(move _25) -> [return: bb12, unwind continue];
    }

    bb12: {
        StorageDead(_25);
        _23 = panicking::panic_fmt(move _24) -> unwind continue;
    }

    bb13: {
        StorageDead(_22);
        StorageDead(_21);
        StorageLive(_26);
        _26 = option::Option::<&[fmt::rt::Placeholder]>::None;
        StorageLive(_27);
        _29 = const _;
        _27 = _29 as &[fmt::rt::Argument<'_>] (PointerCoercion(Unsize));
        _5 = fmt::Arguments::<'_> { pieces: _6, fmt: move _26, args: move _27 };
        StorageDead(_27);
        StorageDead(_26);
        StorageDead(_29);
        StorageDead(_28);
        StorageDead(_6);
        _4 = panicking::panic_fmt(move _5) -> unwind continue;
    }
}

error: could not compile `core` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
error: error writing object file: unimplemented relocation Relocation { offset: 32, size: 32, kind: Relative, encoding: Generic, symbol: SymbolId(64), addend: -4 }

error: could not compile `compiler_builtins` (lib) due to previous error
Build completed unsuccessfully in 0:04:04
bjorn3 commented 11 months ago

Arm64 macOS is not yet supported: https://github.com/rust-lang/rustc_codegen_cranelift/issues/1248 In any case I recommend putting llvm first in the codegen-backends array. This avoid rustc itself and the standard library getting compiled by cg_clif. As cg_clif barely does any optimizations the resulting rustc is very slow. Eg building the standard library takes almost 7min compared to the 40s which an LLVM compiled rustc takes for that. This also avoids this particular error as LLVM would compile the 128bit atomic functions in the standard library and almost nobody actually uses 128bit atomics due to them still being unstable. You would still hit the other issues in the linked issue though.

Alvenix commented 11 months ago

Thank you for your response. This explain the strange errors I used to have. I keep trying cg_cliff from time to time to check for improved compilation time. Closing this issue.