Skip to content

fix(native): resolve symbol names in crash stacktraces on macOS - #1856

Merged
tustanivsky merged 6 commits into
masterfrom
fix/native-stacktrace-macos
Jul 13, 2026
Merged

tustanivsky merged 6 commits into
masterfrom
fix/native-stacktrace-macos

Conversation

@tustanivsky

Copy link
Copy Markdown
Collaborator

This PR fixes address-only crash callstacks produced by the native backend on macOS - frames carried bare instruction_addrs with no function names, so the Sentry's external crash reporter (and any consumer of the client-side event) displayed unreadable stacks.

Problem

The crash daemon has no symbol resolution on macOS. enrich_frame_with_symbol is compiled for Linux/Android only (ELF, #1836) and the Windows path resolves names through dbghelp (#1811). On macOS the daemon's frame-pointer walk only attached the containing module to each frame and never set function.

Proposed fix

Implement the macOS counterpart of the ELF resolver in the daemon:

  • Resolve names from the Mach-O symbol table (LC_SYMTAB/nlist_64) of the containing module, read from disk out-of-process. Universal (fat) binaries are resolved to the slice matching the daemon's architecture. Tables are scanned in fixed-size chunks with only the winning name read from the string table, and the resolved source is cached per module - large tables are never loaded wholesale.
  • Bound matches with LC_FUNCTION_STARTS: nlist entries carry no size (unlike ELF st_size), so a name is only accepted when a symbol sits exactly at the entry of the function containing the address. The payload survives strip, so addresses in symbol-table gaps stay unresolved instead of being attributed to unrelated neighboring functions - an unresolved frame beats a wrong name.
  • Validate files by LC_UUID equality with the loaded image (the Mach-O analog of the GNU build-id check). This also correctly rejects on-disk stubs of system dylibs that don't match the dyld-shared-cache images actually loaded; those frames are left for server-side symbolication.
  • Follow the dSYM companion (<X>.dSYM/Contents/Resources/DWARF/<binary>) when the module's own table misses (stripped local symbols), checked both next to the binary and next to the enclosing .app bundle (the UE packaged-game layout), UUID-validated.

Testing

Checked manually against a UE 5.8 sample project (packaged Development build, macOS) by capturing a null-pointer crash:

Screenshot 2026-07-10 at 14 27 34

Related items

The crash daemon had no symbol resolution on macOS: the ELF resolver
covers Linux/Android only and the dbghelp path is Windows-only, so
frames carried bare instruction addresses and the external crash
reporter displayed unreadable stacks.

Resolve names from the Mach-O symbol table of the containing module
(fat/universal-aware, scanned in fixed-size chunks and cached per
module). Since nlist entries carry no size, matches are bounded by
LC_FUNCTION_STARTS - only a symbol placed exactly at the containing
function's entry is accepted, so addresses in symbol-table gaps stay
unresolved instead of being attributed to neighboring functions. Files
are validated by LC_UUID equality with the loaded image, and stripped
modules fall back to the dSYM companion (checked both next to the
binary and next to the enclosing .app bundle), validated the same way.
@tustanivsky
tustanivsky marked this pull request as ready for review July 10, 2026 13:49
macho_locate_symtab zeroes the whole macho_sym_info_t, so the state set
at function entry was wiped by the first candidate probe. When no usable
companion was found the slot stayed at 0 ("unresolved") and the dSYM
search re-ran for every frame in the module instead of once.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 443094a. Configure here.

@jpnurmi jpnurmi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that all integration-tested desktop platforms are covered, we could drop the "win32 or linux" conditions in test_integration_native.py:

if sys.platform == "win32" or sys.platform == "linux":
# At least some frames should have symbolicated function names
assert any(
frame.get("function") is not None for frame in exc["stacktrace"]["frames"]
)

if sys.platform == "win32" or sys.platform == "linux":
# At least some frames should have symbolicated function names
assert any(
frame.get("function") is not None for frame in exc["stacktrace"]["frames"]
)

On arm64e the kernel signs the pointer registers in the delivered thread state and return addresses on the stack are signed by pacibsp. The signature bits sit above the 47-bit macOS user address space, so signed addresses failed the module bounds check and no frame could be matched to a module or resolved to a symbol name.

Strip the non-address bits from ip/fp/sp taken from the thread state and from values read off the stack during the frame-pointer walk. On plain arm64 user-space addresses fit in 47 bits, so the mask is a no-op.
@tustanivsky
tustanivsky merged commit 8c10a35 into master Jul 13, 2026
97 of 98 checks passed
@tustanivsky
tustanivsky deleted the fix/native-stacktrace-macos branch July 13, 2026 12:08
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
sentry-native 0.15.4

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.

- [ ] `resource` blocks have been checked for updates.
<details>
  <summary>release notes</summary>
  <pre>**Features**:

- Add reusable, user-owned scopes. `sentry_scope_new` creates a scope that `sentry_capture_event_with_scope` applies without consuming, so you can configure it once and reuse it across many captures instead of building a new local scope each time. `sentry_scope_clone` copies a scope, and `sentry_scope_free` releases it. ([#1855](getsentry/sentry-native#1855))
- Android: Expose setting the environment on the scope through the NDK bindings via `NativeScope.setEnvironment()`, so head SDKs can sync the environment at runtime. ([#1874](getsentry/sentry-native#1874))
- Embed the crash event's breadcrumbs into session replay recordings, so breadcrumbs from the replay window show up on the replay timeline. ([#1875](getsentry/sentry-native#1875))
- Add `sentry_transaction_discard` and `sentry_span_discard` for releasing unfinished transactions and spans without sending them. ([#1858](getsentry/sentry-native#1858))
- Add scope attributes. `sentry_scope_set_attribute` / `_n` set an attribute on a scope and `sentry_scope_remove_attribute` / `_n` remove one, while the new `sentry_scope_capture_log` and `sentry_scope_capture_metric` capture a log or metric against a given scope. Scope attributes and trace are applied to logs and metrics captured against it, resolving most-specific-first: per-call data, then the scope, then the global scope. ([#1861](getsentry/sentry-native#1861))
- Add `sentry_scope_clear` to reset a scope's data. ([#1881](getsentry/sentry-native#1881))

**Deprecations**:

- Deprecate `sentry_capture_event_with_scope` in favor of `sentry_scope_capture_event` (scope first), which matches `sentry_scope_capture_log` / `sentry_scope_capture_metric`. ([#1882](getsentry/sentry-native#1882))

**Fixes**:

- Apply the propagation context to events that already have contexts set, so that events captured with a local scope or with event-level contexts keep their trace. ([#1843](getsentry/sentry-native#1843))
- Crashpad: reject runtime control IPC from processes other than the one that started the handler. ([#1853](getsentry/sentry-native#1853))
- Native/macOS: resolve symbol names for crash stacktraces from Mach-O symbol tables and dSYM companions. ([#1856](getsentry/sentry-native#1856))
- Route libcurl debug output through the Sentry logger (`SENTRY_TRACE`) instead of writing to `stderr`. ([#1854](getsentry/sentry-native#1854))
  - NOTE: `sentry_options_set_debug(options, true)` no longer displays verbose libcurl debug output by default. To restore it, call `sentry_options_set_logger_level(options, SENTRY_LEVEL_TRACE)`.
- Crashpad: route client logs through the Sentry logger to make actionable handler startup errors visible. ([#1859](getsentry/sentry-native#1859))
- Windows: fix symlink detection used to prevent database cleanup from following symlinks in run and cache directories. ([#1857](getsentry/sentry-native#1857))
- Linux: avoid unsafe `copy_file_range` at crash time. ([#1868](getsentry/sentry-native#1868))
- Increase the default telemetry batcher capacity from 2x100 to 3x100 items, and add `SENTRY_BATCHER_BUFFER_COUNT` to configure the number of rotating buffers used by log and metric batchers. ([#1867](getsentry/sentry-native#1867))
- Fix a lifetime issue when reading `sample_rand` from the scope propagation context. ([#1869](getsentry/sentry-native#1869))
- Linux: silence harmless compilation warnings in `sentry_modulefinder_linux.c` and `sentry_backend_inproc.c`. ([#1871](getsentry/sentry-native#1871))
- Fix per-call log and metric attributes to override same-named global attributes atomically, preventing fields such as `unit` from leaking from the global attribute when the per-call attribute does not define them. ([#1879](getsentry/sentry-native#1879))
- Prefix vendored mpack symbols to avoid symbol conflicts. ([#1880](https://github.com/getsentry/sentry-native/pull/1880))</pre>
  <p>View the full release notes at <a href="https://github.com/getsentry/sentry-native/releases/tag/0.15.4">https://github.com/getsentry/sentry-native/releases/tag/0.15.4</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!14800
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.

3 participants