Skip to content

[lld][MachO] Add ARM64e pointer authentication linking support#188378

Open
oskarwirga wants to merge 22 commits intollvm:mainfrom
oskarwirga:arm64e_lld
Open

[lld][MachO] Add ARM64e pointer authentication linking support#188378
oskarwirga wants to merge 22 commits intollvm:mainfrom
oskarwirga:arm64e_lld

Conversation

@oskarwirga
Copy link
Copy Markdown
Contributor

This PR implements ARM64e linking support in lld's Mach-O backend. This is a continuation of work discussed in #79543 and I included @BertalanD's suggestion to keep the Relocation object size small, thanks! This PR is part of several I have planned, but contains everything needed to link arm64e Mach-Os with LLD.

What this PR adds

  • Chained fixup pointer structures: Adds bitfield definitions covering both legacy (16-bit ordinal) and USERLAND24 (24-bit ordinal) formats.
  • AUTH relocation parsing: Extends lld's Relocation struct with auth metadata (diversity, key, address-diversity) parsed from ARM64_RELOC_AUTHENTICATED_POINTER relocations. Auth fields are packed in a union with the 64-bit addend to keep sizeof(Relocation) at 24 bytes.
  • Authenticated stubs
  • Set default CPU_SUBTYPE_ARM64E with ptrauth ABI version 0, I got that from Apple's LD
  • Dual GOT: Separate __auth_got section for signed function pointers alongside the existing unsigned __got. Stubs load from __auth_got; address-taken data references use __got.
  • Symbol routing: Stub creation targets __auth_got; personality pointers in unwind info route to __auth_got; ObjC message send fast stubs use __auth_got for objc_msgSend lookup with braa authentication
  • Chained fixup encoding: Encodes auth-rebase, auth-bind, plain-rebase, and plain-bind entries. Automatically selects DYLD_CHAINED_PTR_ARM64E_USERLAND24 format based on deployment target (macOS 12.0+, iOS 15.0+, watchOS 8.0+, tvOS 15.0+)

Testing

  • arm64e-stubs.s — Verifies authenticated stub code sequence
  • arm64e-auth-got.s — Verifies dual GOT (__auth_got + __got) creation and routing
  • arm64e-auth-reloc.s — Verifies ARM64_RELOC_AUTHENTICATED_POINTER parsing and chained fixup encoding
  • arm64e-auth-data.s — Verifies auth metadata (key, diversity, addrDiv) flows through the Relocation union into chained fixups
  • arm64e-chained-fixups.s — Verifies chained fixup format selection and encoding
  • arm64e-reject-mixed.s — Verifies arm64/arm64e object mixing rejection
  • arm64e-no-fixup-chains.s — Verifies -no_fixup_chains is rejected for arm64e
  • End-to-end tested with iOS/macOS apps

AI Disclosure

I used Claude heavily throughout development, primarily to iterate through linker errors. All generated code was manually reviewed and tested on ARM64e hardware. I feel very confident in these changes being functionally correct because I tested on hardware extensively, architecturally they may be lacking!

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants