HACKER Q&A
📣 tinkerdaemon

What is the process to port system software or languages to Apple's M1?


Hi there,

I searched around but could not find any documentation how to port software to Apple M1 systems.

For example: How did Golang got ported? As far as I know Golang is implemented in Golang and just until some months ago it could not create M1 executables. If Golang would be language implemented in C or C++ I could somewhat guess that you need "just" run the sources through the Apple M1 clang/llvm compiler and patch the errors/warnings until it works.

Or another example: How do they port Linux to M1? I mean you need binutils-glibc-gcc to get Linux and other neccessary tools like grub running. Does binutils have a port to M1? Does gcc create M1 executables? Or does this project not only port the kernel but also the toolchain?

On one hand I look forward to the possibility to start one of the very long discussions you can find in the HN community - these are fun to read -. On the other hand I would also be thankful to get a link to a document I was not able to find.


  👤 wmf Accepted Answer ✓
M1 uses the ARM64[1] instruction set and a lot of compilers started working on ARM64 years ago so in many cases compilers were already ready before M1 was announced. Creating a macOS/ARM64 toolchain is mostly a combination of existing features from Linux/ARM64 and macOS/x86-64. For example, Linux uses ELF but macOS needs a Mach-O linker but most languages already had Mach-O support anyway. Once you have the toolchain it's a matter of recompiling and fixing any non-portable assumptions in the code. Fortunately x86-64 and ARM64 are both 64-bit little-endian so porting is fairly easy but the memory consistency models are different which can expose bugs in poorly-written code.

[1] The official name is something else but it's dumb