Writing Portable ARM64 Assembly
3 days ago
- #ABI Differences
- #ARM64 Assembly
- #Portability
- The rise of Apple's ARM-based computers has led to an increase in non-portable ARM64 assembly code, as developers optimize for Apple devices without considering other ARM64 systems like Linux or BSD servers.
- Writing portable ARM64 assembly requires awareness of differences between Mach-O (used by Darwin) and ELF (common in Linux) ABIs, such as symbol prefixes (underscores on Darwin) and the lack of symbol type directives like .type in Mach-O.
- Platform-specific ABI differences exist, for example, the x18 register is reserved in Darwin and Android but not in GNU/Linux or Alpine.
- Apple-specific NEON vector mnemonics (e.g., eor.16b) should be avoided; instead, use the standard ARM assembly syntax (e.g., eor v2.16b, v2.16b, v0.16b) for portability.
- ABI details can be abstracted with macros: PROC_NAME handles symbol naming with underscores for Darwin, and TYPE manages symbol type directives for ELF targets, enabling assembly code that works across toolchains like Apple's, ARM's, and GNU's.