Skip to content

Build with NDK 28 or newer for 16KB page alignment #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 3, 2025
Merged

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Jul 2, 2025

Starting this November, virtually all Android apps are required to support running with 16KB page sizes enabled.

At the moment, the library we build for Android is 4KB-aligned.

$ ~/Library/Android/sdk/ndk/28.1.13356709/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-objdump -p libpowersync.so | grep LOAD
    LOAD off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**12
    LOAD off    0x000000000001c78c vaddr 0x000000000001d78c paddr 0x000000000001d78c align 2**12
    LOAD off    0x0000000000050c00 vaddr 0x0000000000052c00 paddr 0x0000000000052c00 align 2**12
    LOAD off    0x0000000000052698 vaddr 0x0000000000055698 paddr 0x0000000000055698 align 2**12

When using cargo-ndk with NDK 28 or above, it generates 16KB-aligned libraries by default:

$ ~/Library/Android/sdk/ndk/28.1.13356709/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-objdump -p build/intermediates/jniLibs/arm64-v8a/libpowersync.so | grep LOAD
    LOAD off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**14
    LOAD off    0x000000000001d004 vaddr 0x0000000000021004 paddr 0x0000000000021004 align 2**14
    LOAD off    0x0000000000050f10 vaddr 0x0000000000058f10 paddr 0x0000000000058f10 align 2**14
    LOAD off    0x00000000000529e8 vaddr 0x000000000005e9e8 paddr 0x000000000005e9e8 align 2**14

This can also be achieved with a linker option we could set in cargo, but updating the NDK and then relying on the default options sounds easier.

I've validated these changes by running a Flutter demo app on a 16KB emulator.

@simolus3 simolus3 requested a review from rkistner July 2, 2025 18:36
@simolus3 simolus3 merged commit 67cba11 into main Jul 3, 2025
21 checks passed
@simolus3 simolus3 deleted the ndk-experiments branch July 3, 2025 18:47
@simolus3 simolus3 mentioned this pull request Jul 8, 2025
10 tasks
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