Skip to content

build: pack Android relocations by LIBXRAY_ANDROID_API - #172

Merged
yiguodev merged 1 commit into
XTLS:mainfrom
Art34222:claude/libxray-pr-pdhalc
Nov 9, 2026
Merged

yiguodev merged 1 commit into
XTLS:mainfrom
Art34222:claude/libxray-pr-pdhalc

Conversation

@Art34222

@Art34222 Art34222 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Each 64-bit libgojni.so in the AAR carries ~3.6 MiB of plain RELA dynamic relocations. lld can store them packed (--pack-dyn-relocs=android, loaded since Android 6.0 / API 23) or as RELR (DT_ANDROID_RELR, since Android 9 / API 28), but the build targets API 21.

So the default stays as is, and LIBXRAY_ANDROID_API (default 21) sets -androidapi, which is also the AAR's minSdkVersion. From 23 the libraries are linked with --pack-dyn-relocs=android, from 28 with --pack-dyn-relocs=relr --use-android-relr-tags (what NDK r30 already passes there, so a later flag does not override it).

libgojni.so (NDK r30) default (21) LIBXRAY_ANDROID_API=23 LIBXRAY_ANDROID_API=28
arm64-v8a 34,065,456 B −2.93 MiB (−9.0%) −3.53 MiB (−10.9%)
x86_64 36,433,840 B −2.94 MiB (−8.5%) −3.53 MiB (−10.2%)
armeabi-v7a 33,331,992 B −1.01 MiB (−3.2%) −1.09 MiB (−3.4%)
x86 33,338,664 B −1.01 MiB (−3.2%) −1.09 MiB (−3.4%)

Only the relocation table changes; data sections keep their sizes. A build at API 23 without packing is within ~3.5 KB of the default, so the gain comes from packing. Standard DT_RELR (API 30) gives the same bytes as DT_ANDROID_RELR and is not used.

minSdk: the comment next to -androidapi 21 says "keep same with flutter", and Flutter now requires API 24. Raising the default to 23 would give every build the packed sizes while dropping only Android 5.x; this PR leaves that choice to the maintainers.

Tested: python3 build/test_build.py; built at 21, 23 and 28, llvm-readelf -d shows RELA/REL, ANDROID_RELA/ANDROID_REL and ANDROID_RELR. Not run on a device yet.

🤖 Generated with Claude Code

LIBXRAY_ANDROID_API (default 21) selects the -androidapi passed to
gomobile bind, which also becomes the AAR's minSdkVersion. From 23, the
Android libraries are linked with --pack-dyn-relocs=android
(DT_ANDROID_REL/RELA, loaded since API 23), and from 28 with
--pack-dyn-relocs=relr --use-android-relr-tags (DT_ANDROID_RELR, loaded
since API 28). The default build is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yiguodev
yiguodev merged commit 5a0f7d8 into XTLS:main Nov 9, 2026
2 checks passed
@Art34222
Art34222 deleted the claude/libxray-pr-pdhalc branch November 9, 2026 12:33
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.

3 participants