Skip to content

Conversation

@teamchong
Copy link

Problem

Apple reserves CPU register x18 for TLS on ARM64. When generating AOT code for aarch64 on macOS, LLVM may use x18, causing crashes when the AOT code runs on macOS ARM64 (M1/M2/M3).

Solution

This patch makes three changes to properly handle macOS ARM64:

  1. Detect darwin/macho ABI - When explicit ABI is specified as "darwin" or "macho", use -apple- vendor string
  2. Detect darwin/apple in default triple - When auto-detecting platform, check for "darwin" or "apple" in the triple
  3. Add +reserve-x18 feature - Tell LLVM to reserve x18 register when targeting aarch64 on macOS hosts
#if (defined(__APPLE__) || defined(__MACH__)) && defined(BUILD_TARGET_AARCH64)
    if (is_aarch64) {
        // Append +reserve-x18 to features
    }
#endif

Testing

  • AOT compilation and execution on macOS ARM64 (M1/M2/M3) works correctly
  • No crashes from x18 register conflicts

Related

Apple reserves CPU register x18 for TLS on ARM64. When generating AOT
code for aarch64 on macOS, LLVM may use x18, causing crashes when the
AOT code runs on macOS ARM64 (M1/M2/M3).

This patch:
1. Detects darwin/macho ABI and sets correct vendor string
2. Detects darwin/apple in default triple for platform detection
3. Adds +reserve-x18 to LLVM target features for aarch64 on macOS

The fix only applies when compiling on macOS ARM64 hosts, ensuring
generated AOT code is compatible with Apple's platform requirements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant