Repository navigation
fix: [SDK-5059] stop dropping iOS crashes we cannot attribute - #1811
Merged
Merged
Conversation
At -O2 a method whose last act is a system call that raises compiles to a bare b, tearing the frame down before the throw. The frame never reaches callStackReturnAddresses, so a crash in SDK code arrives with only host frames and the uncaught-exception handler declines it. Compile the shipping targets with -fno-optimize-sibling-calls, which restores the bl and the frame. This is ObjC only; swiftc accepts -Xllvm -disable-tail-calls but emits identical code, so it is not worth shipping. Co-authored-by: Cursor <cursoragent@cursor.com>
The handler only kept a crash when a frame named OneSignal, and treated every other stack as the host's. Three gaps made that unsafe: Most of the ObjC surface uses the OS prefix, not OneSignal, and swizzled categories land on system classes where only the selector names us. Match both halves of an -[Class selector] symbol instead. dladdr cannot see us at all once the SDK is linked into the host executable: release builds strip the local symbols that name our ObjC methods and Swift functions, and a non-nil dli_sname is the nearest exported symbol, which can belong to someone else. Resolve our own image through dladdr at startup and treat attribution as unreliable when it is the main executable, capturing those crashes rather than discarding them. Matching that image also covers wrappers that repackage or rename the frameworks. Record the verdict on CrashData so a crash we could not attribute is visible as ossdk.crash.attributed=false rather than absent, and filter server-side. Tests now drive the installed handler with the addresses a real throw captured, which is the seam the injected-frame tests fell through. Co-authored-by: Cursor <cursoragent@cursor.com>
Picks up the ossdk.crash.attributed flag on CrashData. Repoint to the release tag once the KMP change lands. Co-authored-by: Cursor <cursoragent@cursor.com>
fadi-george
reviewed
Nov 17, 2026
Review of the first pass found the image match and the shared-image gate undoing each other. Statically linked, ownImage.path is the host binary, so every host frame matched it and the crash saved as attributed=true, which is exactly the signal the tag exists to carry. Also: image 0 is not the main executable. Inserted libraries take the low indices, so on a real app launch the executable sits behind libRPAC, libXCTestBundleInject and libMainThreadChecker, and sharesHostExecutable read false. Find it by MH_EXECUTE filetype instead. Restrict the bare OS class prefix to the image we share with the host. Our own frameworks are already covered by the module list and the image path, and dladdr resolves ObjC names in unstripped third-party frameworks, where OS would claim unrelated classes such as Aliyun's -[OSSClient ...]. Tests now model static and dynamic linkage explicitly rather than passing a nil image path, which hid the first bug, and assert the tag through a recording reporter instead of counting files. Co-authored-by: Cursor <cursoragent@cursor.com>
fadi-george
approved these changes
Nov 17, 2026
fadi-george
left a comment
Contributor
There was a problem hiding this comment.
Thanks, all four look good.
Keeps the pin in step with the PR branch; the change is the exported @Property doc and extra test coverage, no behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Stops the crash handler silently discarding OneSignal crashes whose stack cannot name us, and keeps our frames out of tail calls so they reach the handler in the first place.
Details
Motivation
Resolves SDK-5059.
OSLogCrashHandleronly persisted a crash when a stack frame named OneSignal, and forwarded everything else to the previous handler. Three separate things made that unsafe, each verified rather than theorized.Tail calls erase the frame. At
-O2, a method whose last act is a system call that raises compiles to a barebwith no frame setup, so it never enterscallStackReturnAddresses. Reproduced on a minimal+[OSThing boom]ending in[NSException raise:format:]:The dangerous real shape is any SDK method whose final act is a system call that raises:
objectAtIndex:out of range,setValue:forUndefinedKey:,NSJSONSerialization. The system frame is skipped as a system image, the elided OneSignal caller is gone, and the surviving frames belong to the app.The symbol rules missed most of the SDK. They matched only
-[OneSignal/+[OneSignal, but the source declares 112 distinctOS-prefixed ObjC classes against 46OneSignal-prefixed ones. Swizzled categories matched nothing at all, because they land on system classes and name us only in the selector:-[UIApplication setOneSignalDelegate:],-[UNUserNotificationCenter onesignalRequestAuthorizationWithOptions:completionHandler:].The symbol fallback cannot fire where it was needed. This is the finding that reshaped the fix.
dladdronly reports symbols that survive linking, and release builds strip the local symbols naming our ObjC methods and Swift functions, sodli_snamecomes backnil. Confirmed three ways:nilwhile system frames resolved.+[OSProbe probe]untilstrip -x, then returnednil.STRIP_INSTALLED_PRODUCT = YESwithSTRIP_STYLE = all.A non-
nilresult is not trustworthy either, sincedladdrreports the nearest preceding exported symbol. In the captured stack it labelled a-[NSException raise]frame as-[NSException initWithCoder:].So image matching is the only reliable signal, and it only holds while we ship as separate frameworks. Where it does not hold, dropping turns real crashes into silence indistinguishable from no crashes at all.
Scope
Three changes.
-fno-optimize-sibling-callson the 11 shipping framework targets and theOneSignalstatic library, across Debug/Release/Test. Each target's existingOTHER_CFLAGSis preserved rather than switched to$(inherited), which would have newly pulled the project-level-all_loadinto targets that currently override it. ObjC only:swiftc -Xllvm -disable-tail-callsis accepted silently but emits byte-identical assembly, so it is not worth shipping.Symbol matching now reads both halves of an
-[Class selector]symbol. Anonesignal-named selector counts anywhere, covering swizzled categories on system classes. The bareOSclass prefix counts only inside the image we share with the host, since our own frameworks are already identified by the module list and the image path, anddladdrdoes resolve ObjC names in unstripped third-party frameworks whereOSwould claim unrelated classes such as Aliyun's-[OSSClient ...].OSOwnImageresolves where our own code lives throughdladdrat startup, once, not on the crash path. A frame matching that image counts as ours, which also covers wrappers that repackage or rename the frameworks and that the fixed module list cannot see. When that image is the host's main executable,sharesHostExecutableis true: the crash is captured instead of discarded and taggedossdk.crash.attributed = falsefor server-side filtering, and the image match is switched off, because every host frame would otherwise match it and read as ours.The executable is found by
MH_EXECUTEfiletype rather than image index 0. Inserted libraries take the low indices, so on a real app launch the executable sits behindlibRPAC,libXCTestBundleInjectandlibMainThreadChecker; reproduced on the iOS 18.6 and 26.2 simulators, where it is at index 3.Behavior that does not change. Every integration shipping today uses vendored xcframeworks, so
sharesHostExecutableis false and the drop behaves exactly as before. The widened capture only applies where attribution is provably impossible.What this costs. In the static-link case the SDK now persists and uploads crashes originating entirely in host app code, including their stack traces. That is deliberate, per the discussion on the ticket: the alternative is dropping our own crashes with no signal that anything was missed. Volume is filtered server-side on
ossdk.crash.attributed.Not covered. In a statically linked app, a host or third-party class named
OS…compiled into the host binary would still be read as ours. Accepted: over-capturing is recoverable server-side, silently dropping our own crashes is not.Dependency
Requires OneSignal-KMP-SDK#34, which adds
attributedtoCrashData. Android lands in lockstep, and the submodule gets repointed to the release tag before merge.The submodule cannot point at that PR's branch in the meantime.
mainhere pins KMP atb5c7bbea, which is on KMP's unmergednew-session-eventsbranch rather than KMPmain, andOSSessionServiceneeds it forFeatureFlag.sdkSessionsV2ApiCutover. PR #34 is correctly based on KMPmain, so it does not carry that commit. The pin therefore points atar/sdk-5059-on-new-session-events, which is the same change applied on top ofb5c7bbea. Both go away once #34 merges and is tagged.Testing
Unit testing
812 tests on
UnitTestApp_TestPlan_Reduced. All crash-attribution tests pass. Two unrelated user-module tests (testBasicCombiningUserUpdateDeltas_resultsInOneRequest,testLoggingInAgainAsTheSameUserStoresTheNewToken, "A Request was still in flight at teardown") flake on the iOS 26.2 simulator and pass on 18.6 and on re-run.Previous tests drove attribution with hand-written frames, which is the seam this bug fell through. New tests raise a real
NSExceptionthrough a small ObjC@trytrampoline and run the installed handler against the addresses the runtime captured, socallStackReturnAddresses,dladdrand attribution all execute for real:testCapturesExceptionThrownThroughOneSignalFrameandtestIgnoresExceptionThrownEntirelyInHostFramesguard the real resolution path in both directions.testCapturesHostFramesUnattributedWhenSdkSharesTheHostImageandtestCapturesExceptionThroughOneSignalFrameAsAttributedassert the tag itself through a recording reporter, not just that a file was written.testIgnoresHostFramesWhenSdkSharesTheHostImage,testIgnoresThirdPartyOSPrefixedClassandtestIgnoresOSPrefixedClassOutsideTheSharedHostImagepin the boundaries of the two rules.testRecognizesStaticOSPrefixedObjCClass,testRecognizesStaticSwizzledCategoryOnSystemClassandtestRecognizesRepackagedFrameworkByOwnImagecover the widened matching.The attribution tests now pass an explicit
OSOwnImagemodelling static or dynamic linkage instead of relying on a default, so a test can no longer pass by supplying a nil image path.Reverting the two attribution fixes turns seven tests red, including three that predate this PR. The two real-throw tests listed first pass in both states by design; they are regression guards for the
dladdrpath, not proof of the fix. TheMH_EXECUTEchange is verified by the simulator measurement above rather than by a test, since faking dyld's image list is not worth the machinery.Manual testing
Not performed. The tail-call behavior was verified by reading compiler output directly rather than on device, and the
dladdrbehavior by running a stripped and unstripped probe binary on the iOS 18.6 simulator. Worth an on-device pass against a release build before release.Affected code checklist
Checklist
Overview
Testing
Final pass