fix(android): the SDK linked static bionic, so openWire segfaults at dlopen and the app dies after the passphrase #123

Merged
sirius merged 1 commit from wt/android-sdk-libc-link into main 2026-09-19 04:40:48 +00:00
Owner

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> → JNA dlopen → a C++ static initializer segfaults, so the process dies the instant the passphrase is submitted.

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0000000000000000
Cause: null pointer dereference
      #00 pc 00000000022dc6b5  libonionwire_sdk.so (getauxval+21)
      #01 pc 00000000022be5ac  libonionwire_sdk.so (__cxa_atexit+604)
      #02 pc 0000000001f822fb  libonionwire_sdk.so (_GLOBAL__sub_I_superscalar.cpp+891)
      #03 pc 00000000000eee6e  linker64 (__dl__ZN6soinfo17call_constructorsEv+622)
      #06 pc 0000000000008304  libjnidispatch.so (Java_com_sun_jna_Native_open+68)
      #31 pc 00000000000151b4  uniffi.onionwire_sdk.UniffiLib.<clinit>+0
      #42 pc 0000000000011594  uniffi.onionwire_sdk.Onionwire_sdkKt.openWire+0
      #48 pc 0000000000002430  com.siriusdevops.onionwire.keepalive.NodeHost$open$job$1.invokeSuspend+0

_GLOBAL__sub_I_superscalar.cpp is RandomX's, and RandomX only exists in the Android build since cuprate-daemon (#113, e6b6bc8).

Cause

That initializer calls getauxval, and libonionwire_sdk.so had linked bionic statically, so getauxval read an auxv vector that only the dynamic linker fills in. Null deref inside dlopen, before any Rust code runs, on both ABIs.

v0.9.0 shipped arm64-v8a/libonionwire_sdk.so
  NEEDED: liblog.so                                    <- no libc, no libdl, no libm
  t __cxa_atexit   t getauxval                         <- its own static bionic
  t _GLOBAL__sub_I_superscalar.cpp                     <- RandomX static init
pre-regression (the last build that ran, 09-15)
  NEEDED: libdl.so liblog.so libm.so libc.so

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 static libc.a, while the dynamic libc.so stub 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 -lc resolved to libc.a. Reproduced with the NDK alone:

-L<arch>/26 -L<arch> …  -> NEEDED libc++_shared.so, libm.so, libdl.so, libc.so
-L<arch>        …       -> libc.a(libc_init_common.o): non-PIC relocation errors / static bionic

Fix

android/sdk/build.gradle.kts: pass the per-API stub directory first, and verifyDynamicLibc (a preBuild dependency) fails the build if libc.so ever leaves DT_NEEDED again. -Wl,--as-needed is set for hygiene; libstdc++.so stays 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.startKeepAlive re-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):

$ readelf -dW sdk/build/rustJniLibs/arm64-v8a/libonionwire_sdk.so | grep NEEDED
  NEEDED  libstdc++.so, libdl.so, liblog.so, libm.so, libc.so
$ nm --defined-only ... | grep -cE ' (getauxval|__cxa_atexit)$'
  0
$ ./gradlew :sdk:verifyDynamicLibc
> Task :sdk:verifyDynamicLibc
BUILD SUCCESSFUL

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):

pid=4473   SIGSEGV|FATAL|has died lines: 0
t=30s  notification: "OnionWire is starting" / "Bootstrapping Tor. This can take minutes — keep the device awake."
       roster: i2mkeacc665i2nnhalzvvi5bkejhydfrxvd5luzrodgzxbtes4mvuaid.onion
t=60s  notification: "OnionWire is reachable" / "Tor and the outbox are running so peers can reach i2mkeacc66…"
       roster: i2mkeacc665i2nnhalzvvi5bkejhydfrxvd5luzrodgzxbtes4mvuaid.onion
$ adb shell dumpsys activity services com.siriusdevops.onionwire.debug
  isForeground=true foregroundId=1 types=0x40000000 startCommandResult=2

POST_NOTIFICATIONS was granted with pm grant before 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

  • No arm64 device run. The shipped ABI was checked statically (NEEDED + the same static-initializer shape: bl <__cxa_atexit> inside _GLOBAL__sub_I_superscalar.cpp), not executed.
  • Not an overnight idle/Doze measurement, and no OEM battery manager was involved.
## 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>` → JNA `dlopen` → a C++ static initializer segfaults, so the process dies the instant the passphrase is submitted. ``` signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0000000000000000 Cause: null pointer dereference #00 pc 00000000022dc6b5 libonionwire_sdk.so (getauxval+21) #01 pc 00000000022be5ac libonionwire_sdk.so (__cxa_atexit+604) #02 pc 0000000001f822fb libonionwire_sdk.so (_GLOBAL__sub_I_superscalar.cpp+891) #03 pc 00000000000eee6e linker64 (__dl__ZN6soinfo17call_constructorsEv+622) #06 pc 0000000000008304 libjnidispatch.so (Java_com_sun_jna_Native_open+68) #31 pc 00000000000151b4 uniffi.onionwire_sdk.UniffiLib.<clinit>+0 #42 pc 0000000000011594 uniffi.onionwire_sdk.Onionwire_sdkKt.openWire+0 #48 pc 0000000000002430 com.siriusdevops.onionwire.keepalive.NodeHost$open$job$1.invokeSuspend+0 ``` `_GLOBAL__sub_I_superscalar.cpp` is RandomX's, and RandomX only exists in the Android build since `cuprate-daemon` (#113, `e6b6bc8`). ## Cause That initializer calls `getauxval`, and `libonionwire_sdk.so` had **linked bionic statically**, so `getauxval` read an auxv vector that only the dynamic linker fills in. Null deref inside `dlopen`, before any Rust code runs, on both ABIs. ``` v0.9.0 shipped arm64-v8a/libonionwire_sdk.so NEEDED: liblog.so <- no libc, no libdl, no libm t __cxa_atexit t getauxval <- its own static bionic t _GLOBAL__sub_I_superscalar.cpp <- RandomX static init pre-regression (the last build that ran, 09-15) NEEDED: libdl.so liblog.so libm.so libc.so ``` 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 static `libc.a`, while the dynamic `libc.so` stub 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 `-lc` resolved to `libc.a`. Reproduced with the NDK alone: ``` -L<arch>/26 -L<arch> … -> NEEDED libc++_shared.so, libm.so, libdl.so, libc.so -L<arch> … -> libc.a(libc_init_common.o): non-PIC relocation errors / static bionic ``` ## Fix `android/sdk/build.gradle.kts`: pass the per-API stub directory first, and `verifyDynamicLibc` (a `preBuild` dependency) fails the build if `libc.so` ever leaves DT_NEEDED again. `-Wl,--as-needed` is set for hygiene; `libstdc++.so` stays 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.startKeepAlive` re-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): ``` $ readelf -dW sdk/build/rustJniLibs/arm64-v8a/libonionwire_sdk.so | grep NEEDED NEEDED libstdc++.so, libdl.so, liblog.so, libm.so, libc.so $ nm --defined-only ... | grep -cE ' (getauxval|__cxa_atexit)$' 0 $ ./gradlew :sdk:verifyDynamicLibc > Task :sdk:verifyDynamicLibc BUILD SUCCESSFUL ``` 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): ``` pid=4473 SIGSEGV|FATAL|has died lines: 0 t=30s notification: "OnionWire is starting" / "Bootstrapping Tor. This can take minutes — keep the device awake." roster: i2mkeacc665i2nnhalzvvi5bkejhydfrxvd5luzrodgzxbtes4mvuaid.onion t=60s notification: "OnionWire is reachable" / "Tor and the outbox are running so peers can reach i2mkeacc66…" roster: i2mkeacc665i2nnhalzvvi5bkejhydfrxvd5luzrodgzxbtes4mvuaid.onion $ adb shell dumpsys activity services com.siriusdevops.onionwire.debug isForeground=true foregroundId=1 types=0x40000000 startCommandResult=2 ``` `POST_NOTIFICATIONS` was granted with `pm grant` *before* 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 - **No arm64 device run.** The shipped ABI was checked statically (NEEDED + the same static-initializer shape: `bl <__cxa_atexit>` inside `_GLOBAL__sub_I_superscalar.cpp`), not executed. - Not an overnight idle/Doze measurement, and no OEM battery manager was involved.
fix(android): link the SDK against the dynamic libc, not static bionic
All checks were successful
android-ci / android (pull_request) Successful in 30m59s
519f0e66c3
`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.
sirius merged commit ca4c2c4562 into main 2026-09-19 04:40:48 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!123
No description provided.