rust-lang / rustc_codegen_cranelift

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

Add AArch64 Windows Support #1288

Open afonso360 opened 1 year ago

afonso360 commented 1 year ago

👋 Hey, There has been some discussion about support for aarch64-pc-windows-msvc on wasmtime and cranelift.

As a curiosity I tried to build cg_clif on this target. It fails when building sysroot due to object not being able to handle these kinds of relocations.

y.exe build output: ``` PS C:\Users\WOA\git\rustc_codegen_cranelift> .\y.exe build [BUILD] rustc_codegen_cranelift Updating git repository `https://github.com/bjorn3/rust-ar.git` Downloaded once_cell v1.13.0 Downloaded smallvec v1.9.0 Downloaded cranelift-module v0.88.1 Downloaded anyhow v1.0.60 Downloaded cranelift-bforest v0.88.1 Downloaded cranelift-object v0.88.1 Downloaded target-lexicon v0.12.4 Downloaded gimli v0.26.2 Downloaded cranelift-jit v0.88.1 Downloaded cranelift-codegen-shared v0.88.1 Downloaded cranelift-isle v0.88.1 Downloaded regalloc2 v0.3.2 Downloaded cranelift-native v0.88.1 Downloaded cranelift-codegen-meta v0.88.1 Downloaded cranelift-frontend v0.88.1 Downloaded bumpalo v3.11.0 Downloaded cranelift-entity v0.88.1 Downloaded cranelift-codegen v0.88.1 Downloaded libc v0.2.127 Downloaded 19 crates (2.7 MB) in 19.50s Compiling cfg-if v1.0.0 Compiling version_check v0.9.4 Compiling once_cell v1.13.0 Compiling autocfg v1.1.0 Compiling getrandom v0.2.7 Compiling cranelift-isle v0.88.1 Compiling log v0.4.17 Compiling ahash v0.7.6 Compiling indexmap v1.9.1 Compiling cranelift-codegen-shared v0.88.1 Compiling cranelift-codegen-meta v0.88.1 Compiling target-lexicon v0.12.4 Compiling hashbrown v0.12.3 Compiling byteorder v1.4.3 Compiling fxhash v0.2.1 Compiling cranelift-entity v0.88.1 Compiling smallvec v1.9.0 Compiling slice-group-by v0.3.0 Compiling cranelift-bforest v0.88.1 Compiling gimli v0.26.2 Compiling regalloc2 v0.3.2 Compiling cranelift-codegen v0.88.1 Compiling arrayvec v0.7.2 Compiling bumpalo v3.11.0 Compiling winapi v0.3.9 Compiling anyhow v1.0.60 Compiling memchr v2.5.0 Compiling windows_aarch64_msvc v0.36.1 Compiling crc32fast v1.3.2 Compiling libc v0.2.127 Compiling bitflags v1.3.2 Compiling object v0.29.0 Compiling region v2.2.0 Compiling windows-sys v0.36.1 Compiling libloading v0.7.3 Compiling ar v0.8.0 (https://github.com/bjorn3/rust-ar.git?branch=do_not_remove_cg_clif_ranlib#de9ab0e5) Compiling cranelift-module v0.88.1 Compiling cranelift-native v0.88.1 Compiling cranelift-frontend v0.88.1 Compiling cranelift-jit v0.88.1 Compiling cranelift-object v0.88.1 Compiling rustc_codegen_cranelift v0.1.0 (C:\Users\WOA\git\rustc_codegen_cranelift) Finished release [optimized] target(s) in 11m 15s [BUILD] sysroot Clif Downloaded cfg-if v0.1.10 Downloaded unicode-width v0.1.10 Downloaded miniz_oxide v0.4.4 Downloaded libc v0.2.132 Downloaded object v0.26.2 Downloaded getopts v0.2.21 Downloaded addr2line v0.16.0 Downloaded compiler_builtins v0.1.80 Downloaded gimli v0.25.0 Downloaded 9 crates (1.8 MB) in 14.14s Compiling compiler_builtins v0.1.80 Compiling core v0.0.0 (C:\Users\WOA\git\rustc_codegen_cranelift\build_sysroot\sysroot_src\library\core) Compiling libc v0.2.132 Compiling cc v1.0.73 Compiling memchr v2.5.0 Compiling autocfg v1.1.0 Compiling miniz_oxide v0.4.4 Compiling std v0.0.0 (C:\Users\WOA\git\rustc_codegen_cranelift\build_sysroot\sysroot_src\library\std) Compiling unwind v0.0.0 (C:\Users\WOA\git\rustc_codegen_cranelift\build_sysroot\sysroot_src\library\unwind) Compiling rustc-std-workspace-core v1.99.0 (C:\Users\WOA\git\rustc_codegen_cranelift\build_sysroot\sysroot_src\library\rustc-std-workspace-core) [rustc_std_workspace_core : codegen mono items] start [rustc_std_workspace_core : codegen mono items] end time: 851.334µs [libc : codegen mono items] start [libc : codegen mono items] end time: 4.8135ms [core : codegen mono items] start thread '' panicked at 'called `Result::unwrap()` on an `Err` value: Error("unimplemented relocation addend Relocation { offset: 516, size: 26, kind: Relative, encoding: AArch64Call, symbol: SymbolId(2), addend: -4 }")', C:\Users\WOA\.cargo\registry\src\github.com-1ecc6299db9ec823\cranelift-object-0.88.1\src\backend.rs:507:22 stack backtrace: thread '' panicked at 'called `Result::unwrap()` on an `Err` value: Error("unimplemented relocation addend Relocation { offset: 240, size: 26, kind: Relative, encoding: AArch64Call, symbol: SymbolId(5), addend: -4 }")', C:\Users\WOA\.cargo\registry\src\github.com-1ecc6299db9ec823\cranelift-object-0.88.1\src\backend.rs:507:22 0: 0x7ffb93134b0c - ::fmt::hc12026921a310f1e 1: 0x7ffb9316931c - core::fmt::write::h1ffda2629489e6ee 2: 0x7ffb9312840c - ::fmt::h0b1acfb3887697cb 3: 0x7ffb93137b90 - std::panicking::default_hook::h63bdbdd98a4f5e77 4: 0x7ffb931377d8 - std::panicking::default_hook::h63bdbdd98a4f5e77 5: 0x7ffb54382450 - rustc_driver[cce79c4000d792dd]::handle_options 6: 0x7ffb931384ac - std::panicking::rust_panic_with_hook::haac9afee0d188cce 7: 0x7ffb9313824c - ::get::h87bf73ab2d673366 8: 0x7ffb931355b8 - ::fmt::hc12026921a310f1e 9: 0x7ffb93137f5c - rust_begin_unwind 10: 0x7ffb9319c848 - core::panicking::panic_fmt::h33c44874b4c71580 11: 0x7ffb9319c93c - core::result::unwrap_failed::hd9b8249dba637cdb [compiler_builtins : codegen mono items] start 12: 0x7ffb80a0765c - cranelift_object::backend::ObjectModule::finish::h7fd2105290803c25 13: 0x7ffb809d0b80 - rustc_codegen_cranelift::driver::aot::emit_cgu::h311753540ecff6ea 14: 0x7ffb809617f4 - std::sys_common::backtrace::__rust_begin_short_backtrace::he74958252f404ebf 15: 0x7ffb8091324c - std::thread::spawn::hd01f2d45e4227ae0 16: 0x7ffb93146ef8 - std::sys::windows::thread::Thread::new::h69222c6a51c02136 thread '' panicked at 'called `Result::unwrap()` on an `Err` value: Error("unimplemented relocation addend Relocation { offset: 12, size: 26, kind: Relative, encoding: AArch64Call, symbol: SymbolId(1), addend: -4 }")', C:\Users\WOA\.cargo\registry\src\github.com-1ecc6299db9ec823\cranelift-object-0.88.1\src\backend.rs:507:22 stack backtrace: 17: 0x7ffbb3b32020 - BaseThreadInitThunk 18: 0x7ffbb56e2d8c - RtlUserThreadStart stack backtrace: error: internal compiler error: unexpected panic note: 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: rustc 1.66.0-nightly (3f83906b3 2022-09-24) running on aarch64-pc-windows-msvc note: compiler flags: --crate-type lib -C opt-level=3 -C lto=off -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -Z force-unstable-if-unmarked -C panic=abort -Z codegen-backend=C:\Users\WOA\git\rustc_codegen_cranelift\build\bin\rustc_codegen_cranelift.dll -Z mir-opt-level=3 note: some of the compiler flags provided by cargo are hidden query stack during panic: end of query stack thread '' panicked at 'called `Result::unwrap()` on an `Err` value: Error("unimplemented relocation addend Relocation { offset: 260, size: 26, kind: Relative, encoding: AArch64Call, symbol: SymbolId(3), addend: -4 }")', C:\Users\WOA\.cargo\registry\src\github.com-1ecc6299db9ec823\cranelift-object-0.88.1\src\backend.rs:507:22 0: 0x7ffb93134b0c - ::fmt::hc12026921a310f1e 1: 0x7ffb9316931c - core::fmt::write::h1ffda2629489e6ee 2: 0x7ffb9312840c - ::fmt::h0b1acfb3887697cb 3: 0x7ffb93137b90 - std::panicking::default_hook::h63bdbdd98a4f5e77 4: 0x7ffb931377d8 - std::panicking::default_hook::h63bdbdd98a4f5e77 thread '' panicked at 'called `Result::unwrap()` on an `Err` value: Error("unimplemented relocation addend Relocation { offset: 224, size: 26, kind: Relative, encoding: AArch64Call, symbol: SymbolId(11), addend: -4 }")', C:\Users\WOA\.cargo\registry\src\github.com-1ecc6299db9ec823\cranelift-object-0.88.1\src\backend.rs:507:22 5: 0x7ffb54382450 - rustc_driver[cce79c4000d792dd]::handle_options 6: 0x7ffb931384ac - std::panicking::rust_panic_with_hook::haac9afee0d188cce 7: 0x7ffb9313824c - ::get::h87bf73ab2d673366 8: 0x7ffb931355b8 - ::fmt::hc12026921a310f1e 9: 0x7ffb93137f5c - rust_begin_unwind 10: 0x7ffb9319c848 - core::panicking::panic_fmt::h33c44874b4c71580 11: 0x7ffb9319c93c - core::result::unwrap_failed::hd9b8249dba637cdb 12: 0x7ffb80a0765c - cranelift_object::backend::ObjectModule::finish::h7fd2105290803c25 13: 0x7ffb809d0b80 - rustc_codegen_cranelift::driver::aot::emit_cgu::h311753540ecff6ea 14: 0x7ffb809617f4 - std::sys_common::backtrace::__rust_begin_short_backtrace::he74958252f404ebf 15: 0x7ffb8091324c - std::thread::spawn::hd01f2d45e4227ae0 16: 0x7ffb93146ef8 - std::sys::windows::thread::Thread::new::h69222c6a51c02136 17: 0x7ffbb3b32020 - BaseThreadInitThunk 18: 0x7ffbb56e2d8c - RtlUserThreadStart 0: 0x7ffb93134b0c - ::fmt::hc12026921a310f1e error: internal compiler error: unexpected panic note: 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: rustc 1.66.0-nightly (3f83906b3 2022-09-24) running on aarch64-pc-windows-msvc note: compiler flags: --crate-type lib -C opt-level=3 -C lto=off -C embed-bitcode=no -C codegen-units=10000 -C debuginfo=2 -Z force-unstable-if-unmarked -C panic=abort -Z codegen-backend=C:\Users\WOA\git\rustc_codegen_cranelift\build\bin\rustc_codegen_cranelift.dll -Z mir-opt-level=3 note: some of the compiler flags provided by cargo are hidden query stack during panic: end of query stack 1: 0x7ffb9316931c - core::fmt::write::h1ffda2629489e6ee 2: 0x7ffb9312840c - ::fmt::h0b1acfb3887697cb 3: 0x7ffb93137b90 - std::panicking::default_hook::h63bdbdd98a4f5e77 4: 0x7ffb931377d8 - std::panicking::default_hook::h63bdbdd98a4f5e77 5: 0x7ffb54382450 - rustc_driver[cce79c4000d792dd]::handle_options 6: 0x7ffb931384ac - std::panicking::rust_panic_with_hook::haac9afee0d188cce 7: 0x7ffb9313824c - ::get::h87bf73ab2d673366 8: 0x7ffb931355b8 - ::fmt::hc12026921a310f1e 9: 0x7ffb93137f5c - rust_begin_unwind 10: 0x7ffb9319c848 - core::panicking::panic_fmt::h33c44874b4c71580 11: 0x7ffb9319c93c - core::result::unwrap_failed::hd9b8249dba637cdb 12: 0x7ffb80a0765c - cranelift_object::backend::ObjectModule::finish::h7fd2105290803c25 13: 0x7ffb809d0b80 - rustc_codegen_cranelift::driver::aot::emit_cgu::h311753540ecff6ea 14: 0x7ffb809617f4 - std::sys_common::backtrace::__rust_begin_short_backtrace::he74958252f404ebf 15: 0x7ffb8091324c - std::thread::spawn::hd01f2d45e4227ae0 16: 0x7ffb93146ef8 - std::sys::windows::thread::Thread::new::h69222c6a51c02136 17: 0x7ffbb3b32020 - BaseThreadInitThunk 18: 0x7ffbb56e2d8c - RtlUserThreadStart stack backtrace: 0: 0x7ffb93134b0c - error: internal compiler error: unexpected panic::fmt::hc12026921a310f1e note: the compiler unexpectedly panicked. this is a bug. 1: 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 0x7ffb9316931c - core::fmt::notewrite: rustc 1.66.0-nightly (3f83906b3 2022-09-24) running on aarch64-pc-windows-msvc:: h1ffda2629489e6ee 2: note: compiler flags: --crate-type lib -C opt-level=3 -C lto=off -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -Z force-unstable-if-unmarked -C panic=abort -Z codegen-backend=C:\Users\WOA\git\rustc_codegen_cranelift\build\bin\rustc_codegen_cranelift.dll -Z mir-opt-level=3 note0x: some of the compiler flags provided by cargo are hidden7ffb9312840c - < std::query stack during panic: end of query stack io::IoSliceMut as core::fmt::Debug>::fmt::h0b1acfb3887697cb 3: 0x7ffb93137b90 - std::panicking::default_hook::h63bdbdd98a4f5e77 4: 0x7ffb931377d8 - std::panicking::default_hook::h63bdbdd98a4f5e77 5: 0x7ffb54382450 - rustc_driver[cce79c4000d792dd]::handle_options 6: 0x7ffb931384ac - std::panicking::rust_panic_with_hook::haac9afee0d188cce 7: 0x7ffb9313824c - ::get::h87bf73ab2d673366 8: 0x7ffb931355b8 - ::fmt::hc12026921a310f1e 9: 0x7ffb93137f5c - rust_begin_unwind 10: 0x7ffb9319c848 - core::panicking::panic_fmt::h33c44874b4c71580 11: 0x7ffb9319c93c - core::result::unwrap_failed::hd9b8249dba637cdb 12: 0x7ffb80a0765c - cranelift_object::backend::ObjectModule::finish::h7fd2105290803c25 13: 0x7ffb809d0b80 - rustc_codegen_cranelift::driver::aot::emit_cgu::h311753540ecff6ea 14: 0x7ffb809617f4 - std::sys_common::backtrace::__rust_begin_short_backtrace::he74958252f404ebf 15: 0x7ffb8091324c - std::thread::spawn::hd01f2d45e4227ae0 16: 0x7ffb93146ef8 - std::sys::windows::thread::Thread::new::h69222c6a51c02136 17: 0x7ffbb3b32020 - BaseThreadInitThunk 18: 0x7ffbb56e2d8c - RtlUserThreadStart stack backtrace: 0: error: internal compiler error0x: unexpected panic7ffb93134b0c - ::fmt::hc12026921a310f1e note: the compiler unexpectedly panicked. this is a bug. 1: 0x7ffb9316931c - notecore: 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:: fmt:: write::h1ffda2629489e6ee note: rustc 1.66.0-nightly (3f83906b3 2022-09-24) running on aarch64-pc-windows-msvc 2: 0x7ffb9312840c - ::fmt::h0b1acfb3887697cb note: some of the compiler flags provided by cargo are hidden query stack during panic: end of query stack 3: 0x7ffb93137b90 - std::panicking::default_hook::h63bdbdd98a4f5e77 4: 0x7ffb931377d8 - std::panicking::default_hook::h63bdbdd98a4f5e77 5: 0x7ffb54382450 - rustc_driver[cce79c4000d792dd]::handle_options 6: 0x7ffb931384ac - std::panicking::rust_panic_with_hook::haac9afee0d188cce 7: 0x7ffb9313824c - ::get::h87bf73ab2d673366 8: 0x7ffb931355b8 - ::fmt::hc12026921a310f1e 9: 0x7ffb93137f5c - rust_begin_unwind 10: 0x7ffb9319c848 - core::panicking::panic_fmt::h33c44874b4c71580 11: 0x7ffb9319c93c - core::result::unwrap_failed::hd9b8249dba637cdb 12: 0x7ffb80a0765c - cranelift_object::backend::ObjectModule::finish::h7fd2105290803c25 13: 0x7ffb809d0b80 - rustc_codegen_cranelift::driver::aot::emit_cgu::h311753540ecff6ea 14: 0x7ffb809617f4 - std::sys_common::backtrace::__rust_begin_short_backtrace::he74958252f404ebf 15: 0x7ffb8091324c - std::thread::spawn::hd01f2d45e4227ae0 16: 0x7ffb93146ef8 - std::sys::windows::thread::Thread::new::h69222c6a51c02136 17: 0x7ffbb3b32020 - BaseThreadInitThunk 18: 0x7ffbb56e2d8c - RtlUserThreadStart error: internal compiler error: unexpected panic note: 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: rustc 1.66.0-nightly (3f83906b3 2022-09-24) running on aarch64-pc-windows-msvc note: compiler flags: --crate-type lib -C opt-level=3 -C lto=off -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -Z force-unstable-if-unmarked -C panic=abort -Z codegen-backend=C:\Users\WOA\git\rustc_codegen_cranelift\build\bin\rustc_codegen_cranelift.dll -Z mir-opt-level=3 note: some of the compiler flags provided by cargo are hidden query stack during panic: end of query stack .... # There is a buch more output, but its all the same. ```

Additionally to get this target working we also need stack probing support. And maybe some ABI support on cranelift? Not sure.

I'm a little bit more focused on getting x86_64-pc-windows-msvc working properly, so I'm not planning on working on this right now.

Erithax commented 2 weeks ago

A plethora of system integrators (Microsoft, HP, Dell, Samsung, Lenovo, Acer, ...) have announced Windows ARM laptops based on Snapdragon's new Elite processors. They will start shipping in a couple days. It seems like this target will be a lot more important soon.

bjorn3 commented 2 weeks ago

I don't have a Windows ARM laptop, nor any other way to test any support I add. As such it is basically impossible for me to add this support. If someone who is in a position to test it were to work on getting it supported, I did welcome any PR(s) however.