fix(android): the SDK linked static bionic, so openWire segfaults at dlopen and the app dies after the passphrase #123
Loading…
Reference in a new issue
No description provided.
Delete branch "wt/android-sdk-libc-link"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
On device: open the app, type the passphrase, press Open / the IME action — the app closes and the onion never publishes. No Kotlin exception anywhere, no
AndroidRuntime: FATAL, and the process is gone:ActivityManager: Process com.siriusdevops.onionwire.debug (pid 3177) has died: fg +50 FGS.It is not the unlock path (#116), it is the first SDK call.
openWire→UniffiLib.<clinit>→ JNAdlopen→ a C++ static initializer segfaults, so the process dies the instant the passphrase is submitted._GLOBAL__sub_I_superscalar.cppis RandomX's, and RandomX only exists in the Android build sincecuprate-daemon(#113,e6b6bc8).Cause
That initializer calls
getauxval, andlibonionwire_sdk.sohad linked bionic statically, sogetauxvalread an auxv vector that only the dynamic linker fills in. Null deref insidedlopen, before any Rust code runs, on both ABIs.The static libc arrived with the same commit that added the C++ link flags.
linkFlags()passes-L<ndk>/sysroot/usr/lib/<triple>so the libc++ archives resolve; that directory also holds the staticlibc.a, while the dynamiclibc.sostub lives in the per-API subdirectory (.../usr/lib/<triple>/26/libc.so) that cargo-ndk's linker wrapper normally supplies — and that wrapper is deliberately bypassed here, so the per-API directory was not on the search path at all and-lcresolved tolibc.a. Reproduced with the NDK alone:Fix
android/sdk/build.gradle.kts: pass the per-API stub directory first, andverifyDynamicLibc(apreBuilddependency) fails the build iflibc.soever leaves DT_NEEDED again.-Wl,--as-neededis set for hygiene;libstdc++.sostays in DT_NEEDED because randomx-rs's cmake half asks for it and it satisfies symbols the static libc++ archives were already scanned for — that shim is present on every Android release to date and resolves in the run below.WireViewModel.startKeepAlivere-announces the keep-alive with the locator once the node publishes. The notice is anchored at the Open tap with an empty onion so the shade does not claim a reachable node during bootstrap, and only the POST_NOTIFICATIONS callback ever replaced it — on a device that already granted notifications there is no callback, so the shade said "OnionWire is starting" forever.Evidence
Build (this branch, both ABIs):
Device run — emulator
ow35(x86_64,ro.build.version.sdk=35), fresh install, passphrase typed, submitted with the IME action (the flow that used to kill the process):POST_NOTIFICATIONSwas granted withpm grantbefore launch, so no permission dialog and no callback fired: the "reachable" notice at t=60s is the re-announce in this PR, not the callback.:app:testDebugUnitTest— BUILD SUCCESSFUL.Not verified
bl <__cxa_atexit>inside_GLOBAL__sub_I_superscalar.cpp), not executed.`openWire` segfaults at `dlopen` on every ABI, so the app dies the moment the passphrase is submitted and the onion never publishes. The tombstone: signal 11 (SIGSEGV), fault addr 0x0 #00 libonionwire_sdk.so (getauxval+21) #01 libonionwire_sdk.so (__cxa_atexit+604) #02 libonionwire_sdk.so (_GLOBAL__sub_I_superscalar.cpp+891) #06 libjnidispatch.so (Java_com_sun_jna_Native_open+68) #42 uniffi.onionwire_sdk.Onionwire_sdkKt.openWire+0 `_GLOBAL__sub_I_superscalar.cpp` is RandomX's, and RandomX arrived with the `cuprate-daemon` feature (#113). It calls `getauxval` from a static initializer — and `libonionwire_sdk.so` had linked bionic **statically**, so that `getauxval` read an auxv vector only the dynamic linker ever fills in. The first SDK call is the first `dlopen`, which is the first time anything touches the library: the crash lands exactly on "user typed the password". The static libc came in with the same commit that added the C++ link flags. `linkFlags()` passes `-L<ndk>/sysroot/usr/lib/<triple>` for the libc++ archives; that directory also holds the static `libc.a`, while the dynamic `libc.so` stub lives in the per-API subdirectory that cargo-ndk's linker wrapper normally supplies — and that wrapper is bypassed on purpose here, so the per-API directory was no longer on the search path at all and `-lc` resolved to `libc.a`. Both directories are now passed, the per-API one first, and `verifyDynamicLibc` fails the build if `libc.so` ever leaves DT_NEEDED again. before (v0.9.0 arm64): NEEDED liblog.so only, local getauxval/__cxa_atexit after: NEEDED libstdc++.so, libdl, liblog, libm, libc.so, no local libc Also: the keep-alive notice is re-announced with the locator once the node publishes. It is anchored at the Open tap with an empty onion (so the shade does not claim a reachable node while Tor bootstraps), and only the POST_NOTIFICATIONS callback ever replaced it — on a device that already granted notifications there is no callback at all, so the notice claimed "OnionWire is starting" forever.