Skip to content

GitHub Actions: Use Android packed relocations for Android builds - #7343

Merged
RPRX merged 2 commits into
XTLS:mainfrom
Art34222:ci/android-packed-relocs
Nov 8, 2026
Merged

RPRX merged 2 commits into
XTLS:mainfrom
Art34222:ci/android-packed-relocs

Conversation

@Art34222

@Art34222 Art34222 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Android builds are PIE, and a Go PIE binary carries ~155k R_*_RELATIVE dynamic relocations (pointers in type descriptors, itabs, static string/slice headers, etc.). Stored as plain RELA (24 bytes each) they take 3.56 MiB of every Android binary.

This PR passes -Wl,--pack-dyn-relocs=android to lld (NDK r28b, already used by the Android jobs), so the table is stored in Android's packed format (APS2) instead.

Result (NDK r28b, same command line as release.yml)

before after diff
android-arm64-v8a 36,447,032 B 33,380,312 B −2.92 MiB (−8.4%)
android-amd64 39,053,016 B 35,980,920 B −2.93 MiB (−7.9%)
relocation table (arm64) 3,738,216 B (RELA) 671,475 B (ANDROID_RELA)

The download (zip) shrinks less (~0.3 MiB) because RELA compresses well; the gain is mostly on-disk / installed size. Code and data are unchanged: only the encoding of the relocation table differs (e.g. .data.rel.ro has the same size in both builds).

Compatibility

  • DT_ANDROID_RELA is supported by the bionic loader since Android 6.0 (API 23). The Android jobs already target API 24 (*-linux-android24-clang, "Android 7+" since Workflows: Build Android(7+) using NDK; Add Android(7+) amd64 build #4664), so the supported range does not change.
  • Binaries would fail to load on Android 5.x (API 21–22), which is already below the build target.
  • RELR (--pack-dyn-relocs=relr) would save ~0.6 MiB more, but needs Android 9 (API 28, DT_ANDROID_RELR) or Android 11 (API 30, DT_RELR), so it is intentionally not used here.

Testing

On a physical device (Android 16 / API 36, arm64), comparing the unchanged build with the packed one:

  • xray version, xray x25519, xray run -test: OK
  • end-to-end traffic inside the device: dokodemo-door → VLESS outbound → VLESS inbound → freedom → metrics HTTP endpoint: 200 OK
  • unit tests cross-compiled with the same flags and run on the device (common/buf, common/crypto, common/protocol, common/serial, common/net, infra/conf, proxy/vless/encoding, app/router): identical results for both builds, all PASS (geosite-dependent router tests skipped: no geosite.dat on the device)

Not tested on Android 6–8 hardware; compatibility there is based on the dynamic tags (llvm-readelf -d shows ANDROID_RELA/ANDROID_RELASZ) and bionic's documented support.

🤖 Generated with Claude Code

@KobeArthurScofield

Copy link
Copy Markdown
Collaborator

@j2rong4cn

@RPRX

RPRX commented Nov 8, 2026

Copy link
Copy Markdown
Member

@Art34222 rebase

@KobeArthurScofield

Copy link
Copy Markdown
Collaborator

暂时没什么意见,要么看看反应,炸了再回滚

@RPRX

RPRX commented Nov 8, 2026

Copy link
Copy Markdown
Member

@KobeArthurScofield 那你在这个 PR 内改下 README.md 吧

@KobeArthurScofield

Copy link
Copy Markdown
Collaborator

那你在这个 PR 内改下 README.md 吧

done

Art34222 and others added 2 commits November 8, 2026 14:09
Pass -Wl,--pack-dyn-relocs=android to lld when building for Android.
Go PIE binaries carry ~155k R_*_RELATIVE relocations (3.56 MiB as RELA);
APS2 packing shrinks the table to ~0.64 MiB, making the binary ~2.9 MiB
(~8%) smaller on both arm64 and amd64. Supported by bionic since
Android 6.0 (API 23), below the current API 24 target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Art34222
Art34222 force-pushed the ci/android-packed-relocs branch from 6236f7c to 1f874cf Compare November 8, 2026 11:09
@RPRX
RPRX merged commit 3a88ccb into XTLS:main Nov 8, 2026
39 checks passed
@Art34222
Art34222 deleted the ci/android-packed-relocs branch November 9, 2026 08:34
@KobeArthurScofield

Copy link
Copy Markdown
Collaborator

标一下 todo,后续升级最低支持版本的时候可以调新的参数

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