rustc_codegen_cranelift icon indicating copy to clipboard operation
rustc_codegen_cranelift copied to clipboard

Add macOS AArch64 support

Open bjorn3 opened this issue 3 years ago • 5 comments

CirrusCI now has support for running on M1 macs: https://cirrus-ci.org/guide/macOS/

  • [x] Implement Mach-O TLS model for AArch64 in Cranelift (https://github.com/bytecodealliance/wasmtime/pull/5434)
  • [ ] https://github.com/rust-lang/rustc_codegen_cranelift/issues/1451
  • [x] https://github.com/gimli-rs/object/pull/465
  • [x] multiple signatures for objc_msgSend (removed in https://github.com/rust-lang/rust/pull/117910)
  • [x] https://github.com/bytecodealliance/wasmtime/issues/5544
  • [x] https://github.com/bjorn3/rustc_codegen_cranelift/issues/1371

Branch to run on CirrusCI: https://github.com/bjorn3/rustc_codegen_cranelift/tree/macos_m1_ci

bjorn3 avatar Jul 24 '22 09:07 bjorn3

I've been looking into this recently. I currently have the full sysroot compiling and passing most of the tests. I've opened a PR for the first set of changes required (supporting the necessary relocations in the object crate). I'm still working on cleaning up the cranelift changes and debugging a few issues before opening PRs.

nathanwhit avatar Sep 19 '22 04:09 nathanwhit

Thanks a lot for working on this!

bjorn3 avatar Sep 19 '22 05:09 bjorn3

https://github.com/bytecodealliance/wasmtime/pull/5434 has been merged, so tls should work now. Variadic functions like printf will need proper Cranelift support as with the AArch64 macOS ABI variadic arguments are always passed on the stack. The current workaround for missing variadic function support in Cranelift depends on the ABI for variadic arguments being the same as non-variadic arguments, like is the case on most platforms. I will probably also need to hard code support for objc_msgSend as it can have multiple signatures at the same time depending on the passed in message selector.

bjorn3 avatar Mar 25 '23 17:03 bjorn3

I just updated the macos_m1_ci branch to test it on cirrus ci. After disabling all debuginfo generation and skipping the tests that use printf (as it is a variadic function), the rest of the tests pass.

bjorn3 avatar Jan 25 '24 21:01 bjorn3

Turns out there is at least one place in libstd where a variadic function is called: https://cirrus-ci.com/task/4835070486249472?logs=test#L116 This can't work until https://github.com/rust-lang/rustc_codegen_cranelift/issues/1451 is fixed. I could make all these calls abort as workaround, but it doesn't sit right with me to announce that arm64 macOS works with that in place.

Edit: Yeah, just tried with an LLVM sysroot and even that will locally codegen the vararg open() function.

bjorn3 avatar Jan 26 '24 12:01 bjorn3