Skip to content

fix(ios): patch nitro so Xcode 27 builds launch on iOS below 18 - #409

Merged
catch-21 merged 2 commits into
mainfrom
fix/nitro-ios17-launch-crash
Nov 19, 2026
Merged

catch-21 merged 2 commits into
mainfrom
fix/nitro-ios17-launch-crash

Conversation

@coreyphillips

@coreyphillips coreyphillips commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Problem

The v2.1 RC (#408) built with Xcode 27 crashes immediately on launch on older iPhones. On an iOS 17.4 simulator, dyld kills the app before any app code runs:

OS_REASON_DYLD | Symbol not found: __ZNSt13exception_ptr31__from_native_exception_pointerEPv
  Referenced from: pubkyring.app/pubkyring
  Expected in:     /usr/lib/libc++.1.dylib

The reference comes from libNitroModules.a (RuntimeError.o). Nitro's Swift Error.toCpp() calls the inline C++ helper margelo::nitro::makeException, which uses std::make_exception_ptr. Emitted through Swift C++ interop with Xcode 27, that path references std::exception_ptr::__from_native_exception_pointer and __cxa_init_primary_exception, which only exist in the iOS 18+ libc++.

The Promise<T> destructor in Promise.hpp uses the same pattern and is also visible to Swift. Nothing in the app reaches it from Swift today, so it is not part of the current crash. But any Nitro module with a Promise-returning Swift method would bring the crash back, so it is patched too.

Our deployment target is iOS 15.1, so every device on iOS 15.1 to 17.x is affected. CI still builds with Xcode 26, which is why it was not caught there.

Fix

In both places, replace std::make_exception_ptr with a throw plus catch (...) that uses std::current_exception(), which is available on every supported iOS version. This matches the upstream change.

Testing

Release build for the iOS simulator with Xcode 27.2 (27B52), launched on fresh simulators:

Runtime Before After
iOS 17.4 dyld crash on launch Launches to the Terms screen
iOS 18.5 Launches Launches
iOS 26.2 Launches Launches
iOS 27.2 Launches Launches
  • Compared every libc++ and libc++abi symbol the app binary imports against the iOS 17.4 runtime exports. Before: 2 missing (the two above). After: none.
  • After adding the Promise.hpp change, rebuilt and confirmed again: no missing symbols, and the app launches on iOS 17.4 and 27.2.
  • patch-package applies cleanly on install.
  • Not yet tested on a physical device below iOS 18.

Follow ups

  • Rebuild the 2.1 RC after this merges.
  • Drop this patch when upgrading to react-native-nitro-modules 0.37.2 or later.
  • Consider adding an Xcode 27 build and an iOS 17 simulator to iOS CI so this kind of issue gets caught.

iOS builds made with Xcode 27 crash at launch on iOS 15.1 to 17.x with a
dyld error: Symbol not found std::exception_ptr::__from_native_exception_pointer.

react-native-nitro-modules 0.37.1 calls std::make_exception_ptr in the inline
makeException helper, which is emitted through Swift C++ interop. With Xcode 27
that path references libc++ symbols that only exist on iOS 18 and later.

Patch the helper to throw and catch, returning std::current_exception(). This
matches the upstream fix shipped in react-native-nitro-modules 0.37.2
(margelo/nitro#1652).
@coreyphillips

Copy link
Copy Markdown
Collaborator Author

@catch-21, this is just a small patch to prevent the crash and get things running. We could upgrade react-native-nitro-modules entirely, but that may require more testing/troubleshooting.

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Two independent reviews, nothing blocking a merge.

worth doing, does not block

  • Patch omits upstream 0.37.2's matching fix in Promise::~Promise() (patches/react-native-nitro-modules+0.37.1.patch:1)
  • Backport omits the Swift Promise part of the upstream fix (patches/react-native-nitro-modules+0.37.1.patch:14)

@@ -0,0 +1,22 @@
diff --git a/node_modules/react-native-nitro-modules/ios/utils/RuntimeError.hpp b/node_modules/react-native-nitro-modules/ios/utils/RuntimeError.hpp

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

worth doing, does not block: Patch omits upstream 0.37.2's matching fix in Promise::~Promise()

The PR describes this as the same change upstream shipped in 0.37.2, but upstream changed two places and this patch only covers makeException. 0.37.2 also rewrote the destructor in cpp/core/Promise.hpp, which in 0.37.1 still calls std::make_exception_ptr: diff ~Promise() { if (isPending()) [[unlikely]] { auto message = ...; - reject(std::make_exception_ptr(std::runtime_error(message))); + try { + throw std::runtime_error(message); + } catch (...) { + reject(std::current_exception()); + } } } Promise.hpp and PromiseHolder.hpp are public headers exposed to Swift. I built a repro with Xcode 27.2 (swiftc -target arm64-apple-ios15.1-simulator -cxx-interoperability-mode=default -explicit-module-build). A Swift caller that creates and drops a template with this destructor pattern references both __ZNSt13exception_ptr31__from_native_exception_pointerEPv and ___cxa_init_primary_exception. The patched makeException form references neither. It is latent today. No Swift code in nitro 0.37.1 or react-native-mmkv 4.3.2 uses PromiseHolder or the C++ Promise, which fits the author's finding that the patched binary is missing no symbols. But any nitro-based module with a Promise-returning Swift method, added before the upgrade to 0.37.2, would bring the iOS 15.1 to 17.x launch crash back. CI builds with Xcode 26, so it would not catch that. Adding the second hunk makes the patch match upstream and closes the gap.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in 30f31f5. Added the upstream Promise<T> destructor change from margelo/nitro#1824, so the patch now matches 0.37.2. Rebuilt with Xcode 27.2: no libc++ imports missing against iOS 17.4, and the app launches on iOS 17.4 and 27.2 simulators.

+ // interop with Xcode 27, it references std::exception_ptr::__from_native_exception_pointer and
+ // __cxa_init_primary_exception, which only exist in the iOS 18+ libc++. Apps that support older
+ // iOS versions then fail to launch with a dyld "Symbol not found" error.
+ // Upstream fix (react-native-nitro-modules 0.37.2): https://github.com/margelo/nitro/issues/1652

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

worth doing, does not block: Backport omits the Swift Promise part of the upstream fix

The backport leaves both iOS 18-only imports in Nitro's Swift Promise bridge. I confirmed this by compiling a Swift caller of PromiseHolder<int>::create() against the patched package with Xcode 27.2 and an iOS 15.1 target. Ring's current MMKV bindings are synchronous, so this does not block the release. Describe the patch as the RuntimeError workaround or include the upstream Promise<T> destructor change. Upstream fix

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in 30f31f5. The patch now includes the upstream Promise<T> destructor change as well, and I updated the PR description to cover both parts of the upstream fix.

The upstream 0.37.2 fix (margelo/nitro#1824) changed two Swift-visible
helpers: makeException in RuntimeError.hpp and the Promise<T> destructor in
Promise.hpp. The previous commit only covered makeException.

No Swift code in the app reaches the Promise destructor today, but any Nitro
module with a Promise-returning Swift method would bring back the launch crash
on iOS below 18. Apply the same throw and catch change there so the patch
matches upstream.
@catch-21

Copy link
Copy Markdown
Collaborator

This is the right fix and looks safe to merge.

The crash is real. With Xcode 27, std::make_exception_ptr in ios/utils/RuntimeError.hpp is emitted through Swift C++ interop and references std::exception_ptr::__from_native_exception_pointer, which only exists in the iOS 18+ libc++. Availability gating is bypassed only on that Swift interop path, so builds abort at launch on every iOS below 18. The app's deployment target is 15.1, so it is in the affected range. This matches upstream margelo/nitro#1652.

The patch matches the upstream 0.37.2 fix. Both makeException in RuntimeError.hpp and the Promise<T> destructor in Promise.hpp now use try { throw ... } catch (...) { std::current_exception() } instead of std::make_exception_ptr. That is a drop-in replacement, and the throw in the destructor is caught immediately.

  • Remaining make_exception_ptr uses (Promise.cpp, JSIConverter+Exception.hpp, Android headers) are plain C++ translation units, where availability gating works, so they do not need patching.
  • react-native-nitro-modules is pinned to 0.37.1 and postinstall runs patch-package, so fresh installs pick the patch up. It applies cleanly.
  • The Promise.hpp change is defensive (no Swift code reaches that destructor today) and matches upstream exactly.

When react-native-nitro-modules is upgraded to 0.37.2 or later, this patch should be removed. One launch check on iOS 17.x from a clean install would confirm it before merge.

@catch-21
catch-21 merged commit 7f47b65 into main Nov 19, 2026
4 checks passed
@catch-21
catch-21 deleted the fix/nitro-ios17-launch-crash branch November 19, 2026 11:38
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.

2 participants