Skip to content

Preserve ARM64 PAC masks in macOS core dumps - #138041

Merged
max-charlamb merged 1 commit into
dotnet:mainfrom
max-charlamb:macos-pac-addrable-bits
Nov 21, 2026
Merged

max-charlamb merged 1 commit into
dotnet:mainfrom
max-charlamb:macos-pac-addrable-bits

Conversation

@max-charlamb

@max-charlamb max-charlamb commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

#137777 added NT_ARM_PAC_MASK support so Linux ARM64 core dumps preserve the PAC (Pointer Authentication Code) address mask, letting debuggers correctly strip signed return addresses when unwinding. That PR also contained a macOS equivalent, but it was reverted (c6d46965dcd56ea37441a826457a5f039370e765) because it hadn't been built or tested on real macOS/PAC hardware.

This PR reapplies that macOS fix (cherry-picked from the reverted commit b4f6b7329b7efa4733918edcae847aa9a911a752) and validates it end-to-end on real Apple Silicon PAC hardware.

What it does

On ARM64 macOS, createdump now emits an LC_NOTE named "addrable bits" in the Mach-O core dump, containing a version-4 {version, lowAddressBits, highAddressBits, reserved} payload sourced from sysctlbyname("machdep.virtual_address_size", ...). This matches the format LLDB/debugserver already expect/produce, so LLDB can correctly determine how many address bits are valid and strip PAC signing bits from return addresses when unwinding arm64e-signed frames.

  • src/coreclr/debug/createdump/shared/dumpwritermacho.cpp: adds BuildAddressableBitsNote(), wires it into WriteDump()/WriteHeader().
  • src/coreclr/debug/createdump/shared/dumpwritermacho.h: adds AddressableBitsPayload struct and related DumpWriter members.

Validation

Performed on a local Apple M3 Pro (confirmed FEAT_PAuth, FEAT_PAuth2, FEAT_FPAC, FEAT_PACIMP all enabled via sysctl hw.optional.arm.*):

  1. Built createdump with the fix (osx.arm64.Debug) and deployed it into a matching testhost's shared framework directory.
  2. Ran a minimal managed app that throws an unhandled exception with DOTNET_DbgEnableMiniDump=1 DOTNET_DbgMiniDumpType=4 to produce a full core dump.
  3. Confirmed via otool -l that an LC_NOTE with data_owner="addrable bits" is present, and manually decoded its 16-byte payload ({version=4, lowAddressBits=47, highAddressBits=47, reserved=0}) — this exactly matches the live sysctl machdep.virtual_address_size value (47) on the machine.
  4. To rule out a regression from this change, reproduced an (unrelated, pre-existing) LLDB crash (Bus error in ObjectFileMachO::ParseSymtab/OSO debug-map parsing on this Xcode LLDB build) identically on dumps produced with and without the fix, confirming it's an environment issue unrelated to this change, not a regression.

Note

This PR description and the investigation behind it were drafted with GitHub Copilot CLI assistance.

Write a version 4 "addrable bits" LC_NOTE to macOS ARM64 Mach-O core
dumps, sourced from the machdep.virtual_address_size sysctl (the same
source debugserver uses). Without this note, LLDB falls back to
stripping only the top address byte and leaves PAC signature bits in
return addresses signed by arm64e system libraries, breaking unwinding
through those frames - the same class of gap fixed for Linux ARM64 in
dotnet#137777.

Validated on an Apple M3 Pro (FEAT_PAuth/FEAT_PAuth2/FEAT_FPAC) by
building createdump from this change, crash-dumping a managed process,
and confirming via otool -l and a manual LC_NOTE payload decode that
the emitted note (version 4, lowAddressBits=47, highAddressBits=47)
exactly matches the live machdep.virtual_address_size sysctl value.

Co-authored-by: Copilot <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

@max-charlamb
max-charlamb marked this pull request as ready for review November 20, 2026 22:02
@steveisok

Copy link
Copy Markdown
Member

Tracking note: the change looks good to land. End-to-end validation will follow in dotnet/diagnostics via dotnet/diagnostics#6256, using the same A/B approach as #137777: run NativeUnwindTests on macOS ARM64 with and without this change. If that test already passes on macOS without this change, it likely isn't reaching a PAC-signed frame and will need a macOS-specific assertion.

Note

This comment was drafted with GitHub Copilot assistance.

@max-charlamb
max-charlamb enabled auto-merge (squash) November 21, 2026 00:15
@max-charlamb
max-charlamb merged commit 749802c into dotnet:main Nov 21, 2026
105 checks passed
@max-charlamb

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@max-charlamb backporting to release/11.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick 749802c992b98ef2e3291999e0b5eb7ddb497fba

Auto-merging src/coreclr/debug/createdump/dumpwritermacho.cpp
CONFLICT (modify/delete): src/coreclr/debug/createdump/shared/dumpwritermacho.h deleted in HEAD and modified in 749802c992b (Preserve ARM64 PAC masks in macOS core dumps (#138041)).  Version 749802c992b (Preserve ARM64 PAC masks in macOS core dumps (#138041)) of src/coreclr/debug/createdump/shared/dumpwritermacho.h left in tree.
error: could not apply 749802c992b... Preserve ARM64 PAC masks in macOS core dumps (#138041)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Add PAC address metadata to macOS ARM64 core dumps
Using index info to reconstruct a base tree...
A	src/coreclr/debug/createdump/shared/dumpwritermacho.cpp
A	src/coreclr/debug/createdump/shared/dumpwritermacho.h
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/debug/createdump/dumpwritermacho.cpp
CONFLICT (modify/delete): src/coreclr/debug/createdump/shared/dumpwritermacho.h deleted in HEAD and modified in Add PAC address metadata to macOS ARM64 core dumps.  Version Add PAC address metadata to macOS ARM64 core dumps of src/coreclr/debug/createdump/shared/dumpwritermacho.h left in tree.
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Add PAC address metadata to macOS ARM64 core dumps
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

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.

2 participants