What's the cause of the increase in unportable assembly code which targets the 64-bit ARM ISA in Apple’s ARM-based computers?

Writing portable ARM64 assembly
Apr 13, 2023
An unfortunate side effect of the rising popularity of Apple’s ARM-based computers is an increase in unportable assembly code which targets the 64-bit ARM ISA. This is because developers are writing these bits of assembly code to speed up their programs when run on Apple’s ARM-based computers, without considering the other 64-bit ARM devices out there, such as SBCs and servers running Linux or BSD.

The good news is that it is very easy to write assembly which targets Apple’s computers as well as the other 64-bit ARM devices running operating systems other than Darwin. It just requires being aware of a few differences between the Mach-O and ELF ABIs, as well as knowing what Apple-specific syntax extensions to avoid. By following the guidance in this blog, you will be able to write assembly code which is portable between Apple’s toolchain, the official ARM assembly toolchain, and the GNU toolchain.
The increase in unportable assembly code targeting the 64-bit ARM ISA in Apple's ARM-based computers can be attributed to the following reasons:

1. Optimization for Apple Silicon: Developers are writing assembly code specifically optimized for Apple's ARM-based processors, such as the M1, M2, and other Apple Silicon chips. This assembly code takes advantage of the specific features and instruction set extensions available in these processors, leading to improved performance on Apple's devices.

2. Vendor-specific Extensions: Apple's toolchain and assembly syntax may include vendor-specific extensions or features that are not part of the standard ARM64 ISA. These extensions can provide additional functionality or optimizations specific to Apple's ecosystem, but they may not be supported on other ARM64 platforms or toolchains.

3. Ecosystem Lock-in: Developers targeting Apple's ecosystem may prioritize optimizations and performance on Apple's platforms over portability to other ARM64 devices. This can lead to the creation of assembly code that is tightly coupled with Apple's toolchain and architecture, making it less portable to other ARM64 environments.

4. Lack of Consideration for Portability: Some developers may not prioritize portability when writing assembly code for Apple's ARM-based computers. They may focus solely on optimizing for Apple's platforms, without considering the potential need for the code to run on other ARM64 devices or operating systems.

5. Toolchain Differences: The Mach-O object file format used by Apple's toolchain and the ELF format used by other ARM64 platforms have differences in their Application Binary Interfaces (ABIs). These differences can lead to incompatibilities when attempting to run assembly code written for one ABI on another platform with a different ABI.

To address this issue and improve portability, developers should follow best practices and guidelines for writing portable ARM64 assembly code. This includes avoiding vendor-specific extensions, adhering to the standard ARM64 ISA, and considering the differences between the Mach-O and ELF ABIs. By doing so, developers can create assembly code that can run efficiently on Apple's ARM-based computers while maintaining compatibility with other ARM64 platforms and toolchains.