From dd2c79d5ac91dc4eea3f03803ded24f52ea7a17f Mon Sep 17 00:00:00 2001 From: Schindler Date: Mon, 16 Nov 2026 07:40:26 -0500 Subject: [PATCH] Android: link every native library for 16 KB pages (#41) libSDL2.so, the four adrenotools hook libraries and a libmain.so linked on a PC had 4 KB LOAD alignment, so Android 15+ showed the "isn't 16 KB compatible" dialog and a 16 KB-page kernel would refuse to load them. The NDK r27 toolchain links with -z max-page-size=16384 when ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES is on (the default only from r28): turn it on for the dependency builds, the core's and the game's toolchain files. The on-device zig link already passed the flag; libc++_shared.so from r27c is already 16 KB aligned. apk_pack.py now warns about any lib/*.so aligned below 16 KB. Tested on the Android 15 16 KB page-size emulator image (x86_64, arm64 apps through translation): the current APK dies with SIGSEGV (SEGV_ACCERR) as its libraries load; with the 16 KB-aligned libraries libSDL2/libmain load, SDL starts and the game window opens. On a 4 KB device (Shield, Android 11) the new libraries load too. Fixes #41 Co-Authored-By: Claude Opus 5.5 --- psprecomp/android/apk_pack.py | 34 +++++++++++++++++++ psprecomp/android/build_deps.py | 10 ++++-- psprecomp/android/build_hello.py | 2 +- psprecomp/docs/android.md | 3 ++ .../games/dissidia/tools/android_build.py | 2 +- 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/psprecomp/android/apk_pack.py b/psprecomp/android/apk_pack.py index 43bd02b..5a389d4 100644 --- a/psprecomp/android/apk_pack.py +++ b/psprecomp/android/apk_pack.py @@ -91,6 +91,39 @@ def sign_apk_bytes(data, key): return entries + block + cd + bytes(eocd) +PAGE_16K = 16384 + + +def elf_load_align(path): + """The smallest p_align of the PT_LOAD segments of a 64-bit little-endian ELF, or None when the file is not one (a zip payload + shipped as lib*.so).""" + with open(path, "rb") as f: + h = f.read(64) + if len(h) < 64 or h[:4] != b"\x7fELF" or h[4] != 2 or h[5] != 1: + return None + phoff, = struct.unpack_from(" classes.dex diff --git a/psprecomp/docs/android.md b/psprecomp/docs/android.md index f984554..5a367ae 100644 --- a/psprecomp/docs/android.md +++ b/psprecomp/docs/android.md @@ -125,6 +125,9 @@ Not yet run: the GitHub workflow, and an update against a real release. See [installer.md](installer.md), "Android progress": the renderer talks OpenGL ES through `runtime/include/psp_gl.h`; the release ships the prebuilt Android core and libraries (SDL2, FreeType, FFmpeg decoders) built with NDK r27c, an unsigned APK skeleton (manifest + SDL's Java activity) and a pure-Python packer/signer (APK Signature Scheme v2, `android/apk_pack.py`, a public debug key), so the player's machine needs only the NDK compiler. +Every native library is linked for 16 KB pages (`ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES`, i.e. `-z max-page-size=16384`; the on-device link +passes it to `ld.lld` directly), so the game loads on devices running a 16 KB-page kernel and debuggable builds show no "isn't 16 KB +compatible" dialog; `apk_pack.py` warns about any `lib/*.so` whose LOAD segments are aligned below 16 KB. ## Keeping the shader list complete diff --git a/psprecomp/games/dissidia/tools/android_build.py b/psprecomp/games/dissidia/tools/android_build.py index 6221ea5..7368133 100644 --- a/psprecomp/games/dissidia/tools/android_build.py +++ b/psprecomp/games/dissidia/tools/android_build.py @@ -131,7 +131,7 @@ def write_toolchain(adir, work): tc = os.path.join(bd, "toolchain.cmake") ndk = os.path.join(adir, "ndk").replace("\\", "/") with open(tc, "w") as f: - f.write('set(ANDROID_ABI %s)\nset(ANDROID_PLATFORM android-%d)\ninclude("%s/build/cmake/android.toolchain.cmake")\n' + f.write('set(ANDROID_ABI %s)\nset(ANDROID_PLATFORM android-%d)\nset(ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES ON)\ninclude("%s/build/cmake/android.toolchain.cmake")\n' 'set(PSPRECOMP_DEPS_CMAKE "%s/deps/deps.cmake")\n' % (v["abi"], v["api"], ndk, adir.replace("\\", "/"))) return bd, tc