hex/android/app/src/main/cpp/.gitattributes
Ryan Vogel 2aa3b1e5d7
Android: the speech library carries no debugger, exec or plugin-loader code (#2610)
Why: Google Play Protect blocks Hex Preview 2332 as a harmful app. libhexspeech.so linked
stock ggml code Hex never runs: ggml_abort's backtrace reads /proc/self/status for TracerPid,
forks, and execs gdb or lldb after prctl(PR_SET_PTRACER); ggml's backend registry can scan for
libggml-*.so (GGML_BACKEND_PATH, /proc/self/exe) and dlopen them. A keyboard's process should
not carry code that forks, executes programs, sets a ptracer or loads shared objects from a path.

What changed (android/app/src/main/cpp):
- ggml-no-debugger.patch, applied when CMake fetches whisper.cpp d1be6fd (patch -p1 -N -t -F0):
  on Android, ggml_print_backtrace() prints only ggml's in-process unwinder backtrace.
  Removed behaviour: the TracerPid check, pipe, fork, execlp of gdb/lldb, prctl(PR_SET_PTRACER)
  and waitpid. A whisper.cpp bump the patch no longer fits fails configure, so the code can't
  return silently.
- Hidden visibility, function and data sections, --gc-sections and --exclude-libs,ALL: only the
  JNIEXPORT entry points are exported, so ggml's unused backend loader and the libc++
  filesystem code it pulled in are dropped at link time. Removed: the 3,717 other exported
  whisper/ggml/libc++ symbols, which nothing outside the library uses.
- check-imports.cmake (POST_BUILD) fails the build if libhexspeech.so imports fork, execlp,
  execve, prctl, dlopen or system.
- .gitattributes: the patch's blank context lines are not whitespace errors.
- Debug, release (Play) and preview build the same project; Play and preview libraries are
  byte-identical.

Verified (stripped arm64 release/preview libraries, dev f35d90471 vs this):
- llvm-nm -D: exports 3,721 -> 4 (Java_ly_anoma_hex_speech_Whisper_abort, _decode, _free,
  _load; also in the debug library); imports 212 -> 127, none added; fork, execlp, pipe, prctl,
  waitpid, readlink, dlopen, dlsym, dlerror gone; dladdr (names backtrace frames) and dlclose
  (registry handle deleter) remain.
- strings: TracerPid, gdb, lldb, "attach %d", --batch, /proc/self/status, libggml-,
  GGML_BACKEND_PATH, /proc/self/exe, /data/local/tmp all gone.
- Size 2,667,376 -> 1,524,216 bytes; LOAD segments still 16 KB aligned.
- The check fails on dev's library ("imports fork") and passes on this one; a patch whose
  context no longer matches fails configure.
- Dictation harness on dev's decode and MicCapture trim, stock vs this patch and flags, small and
  tiny models, 40 short + 15 long clips: texts identical on Android arm64 (emulator-5740) and
  macOS.
- A deliberate GGML_ABORT in a throwaway debug build on an Android 16 emulator ends in a normal
  SIGABRT tombstone (abort <- ggml_abort <- ggml_new_object), and the in-process backtrace
  printed to the app's stderr.
- ./gradlew :app:testDebugUnitTest (136 tests, 0 failures), :app:assembleDebug,
  :app:stripPreviewDebugSymbols and :app:stripReleaseDebugSymbols green.
2026-11-23 19:41:27 -05:00

2 lines
95 B
Text

# A unified diff's context line for a blank source line is a single space.
*.patch -whitespace