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 main cause of the increase in unportable assembly code targeting the 64-bit ARM ISA on Apple's ARM-based computers is the developers' focus on optimizing their programs specifically for Apple's hardware and software ecosystem, without considering cross-platform compatibility with other 64-bit ARM devices.

Some key reasons for this trend include:

1. Performance optimization: Developers often write assembly code to optimize performance-critical sections of their programs for Apple's ARM-based CPUs, such as the M1 and M2 chips. This assembly code is tailored to take advantage of specific hardware features and instruction set extensions available on Apple's ARM processors.

2. Apple's ecosystem lock-in: Apple's ARM-based computers run on the Darwin operating system, which is based on macOS and shares similarities with iOS and iPadOS. Developers may prioritize optimizing their code for Apple's ecosystem, as it represents a significant market share, especially in the consumer and creative professional segments.

3. Toolchain differences: Apple's toolchain, including the assembler and linker, has some differences and extensions compared to the standard ARM toolchains used for other platforms. Developers may inadvertently use Apple-specific syntax or ABI features, making their assembly code non-portable.

4. Lack of cross-platform testing: Some developers may not have the resources or motivation to test their assembly code on other 64-bit ARM platforms, such as single-board computers (SBCs) or servers running Linux or BSD. This leads to a narrower focus on Apple's hardware and software ecosystem.

While this trend of unportable assembly code is understandable from a performance optimization perspective, it can create challenges for cross-platform development and software portability. Writing portable ARM64 assembly code that works across Apple's ecosystem and other ARM platforms requires adhering to established standards, avoiding vendor-specific extensions, and considering the differences in ABIs and toolchains.