Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

fix(build): link linux-arm64 as static-pie with bionic tls alignment

Samir Hossains36e134a05da1
diff --git a/.cargo/config.toml b/.cargo/config.toml
index 81b00ec..bfcb169 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -3,3 +3,6 @@ rustflags = ["-C", "target-feature=+crt-static"]
[target.aarch64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
+
+[target.aarch64-unknown-linux-musl]
+rustflags = ["-C", "relocation-model=pic", "-C", "link-arg=-pie"]
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 424d4bb..d44b872 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -95,8 +95,9 @@ jobs:
- name: Build Linux binary
if: matrix.os == 'ubuntu-latest'
+ env:
+ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS: "-C relocation-model=pic -C link-arg=-pie"
run: cross build --release --all-features --locked --target ${{ matrix.target }}
-
- name: Build macOS or Windows binary
if: matrix.os != 'ubuntu-latest'
run: cargo build --release --all-features --locked --target ${{ matrix.target }}
@@ -105,6 +106,29 @@ jobs:
if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'x86_64-apple-darwin' || matrix.target == 'aarch64-apple-darwin'
run: target/${{ matrix.target }}/release/moviebox-tui --version
+
+ - name: Validate aarch64 ELF header for Android Termux (ET_DYN & TLS alignment)
+ if: matrix.target == 'aarch64-unknown-linux-musl'
+ run: |
+ BIN="target/${{ matrix.target }}/release/moviebox-tui"
+ ETYPE=$(od -An -tx1 -j16 -N2 "$BIN" | tr -d ' \n')
+ echo "ELF e_type: $ETYPE"
+ if [ "$ETYPE" != "0300" ]; then
+ echo "::error::Expected ELF e_type 0300 (ET_DYN/PIE) for Android compatibility, got $ETYPE"
+ exit 1
+ fi
+
+ if readelf -lW "$BIN" | grep -F 'INTERP' >/dev/null; then
+ echo "::error::Binary contains PT_INTERP; expected static-PIE"
+ exit 1
+ fi
+
+ TLS_ALIGN=$(readelf -lW "$BIN" | awk '$1 == "TLS" {print $NF}')
+ echo "PT_TLS p_align: $TLS_ALIGN"
+ if [ -n "$TLS_ALIGN" ] && [ "$((TLS_ALIGN))" -lt 64 ]; then
+ echo "::error::PT_TLS p_align is $TLS_ALIGN, must be >= 64 for Android Bionic"
+ exit 1
+ fi
- name: Smoke-test produced Windows binary
if: matrix.target == 'x86_64-pc-windows-msvc'
shell: pwsh
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 45e877a..ff706ca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,10 @@
- **Responsive Mobile Installer Headers (`install.sh` & `install.ps1`)**:
- Implemented dynamic terminal column detection (`tput cols`, `stty size`, and `$COLUMNS` in `install.sh`; `$Host.UI.RawUI.WindowSize.Width` in `install.ps1`) with automatic multi-tier banner sizing.
- Eliminated ASCII art banner wrapping and visual corruption on narrow mobile viewports (e.g. Android Termux portrait mode at 40–55 columns) by rendering an adaptive 31-column compact half-block banner (`█▀▄▀█...`) and dynamic horizontal centering.
+- **Android Termux Static-PIE & TLS Alignment**:
+ - Linked `aarch64-unknown-linux-musl` target as static-PIE (`-C relocation-model=pic -C link-arg=-pie`) to produce `ET_DYN` (ELF `e_type: 0x0003`) binaries accepted by Android Bionic's `/system/bin/linker64`, resolving runtime failure (`unexpected e_type: 2`).
+ - Added 64-byte `PT_TLS` alignment anchor in `src/main.rs` to satisfy Android Bionic's ARM64 TLS segment minimum alignment validation.
+ - Added automated ELF `e_type` and `PT_TLS` validation checks to `.github/workflows/release.yml` and a post-installation execution smoke test to `install.sh`.
### Removed
- Removed vestigial `ShowPlaybackPicker` and `ShowPlayerPicker` action variants and playback picker state fields in favor of direct compatible player dispatch.
- **Redundant Slash Commands**:
diff --git a/docs/cross-platform.md b/docs/cross-platform.md
index b852149..2d0939f 100644
--- a/docs/cross-platform.md
+++ b/docs/cross-platform.md
@@ -15,7 +15,7 @@ the release checks in [`release-checklist.md`](release-checklist.md).
| macOS | IINA preferred player (via the installed IINA `iina-cli`); VLC/mpv `.app` paths detected. `process_group(0)` on spawn. |
| Windows | mpv/VLC detected via Program Files + `%LOCALAPPDATA%`; path-safe file stems; static MSVC CRT linking (`+crt-static`) for zero-dependency standalone binaries. |
| Linux | Flatpak mpv/VLC supported (`flatpak run …`); xdg data/cache dirs. |
-| Android (Termux) | Uses the Linux ARM64 binary with a pure-Rust DNS resolver that reads the system configuration when available and otherwise falls back to public resolvers (Cloudflare, Google, Quad9) for zero-config name resolution, and dynamically checks for `termux-open`, `termux-open-url`, `termux-am`, or in-terminal `mpv`; playback strips `LD_LIBRARY_PATH` and `LD_PRELOAD` before launching the chooser. Android intent playback cannot forward stream headers or attach subtitles. Real-device chooser behavior is a release prerequisite; Proot/Termux X11 behavior is unsupported unless separately tested. |
+| Android (Termux) | Uses the Linux ARM64 binary compiled as static-PIE (`ET_DYN`) with 64-byte `PT_TLS` alignment to satisfy Android Bionic (`/system/bin/linker64`) and kernel W^X execution rules without `unexpected e_type: 2` errors. Includes a pure-Rust DNS resolver that reads system configuration and falls back to public resolvers (Cloudflare, Google, Quad9) for zero-config name resolution, and dynamically checks for `termux-open`, `termux-open-url`, `termux-am`, or in-terminal `mpv`; playback strips `LD_LIBRARY_PATH` and `LD_PRELOAD` before launching the chooser. Android intent playback cannot forward stream headers or attach subtitles. Real-device chooser behavior is a release prerequisite; Proot/Termux X11 behavior is unsupported unless separately tested. |
## Terminal capabilities
diff --git a/install.sh b/install.sh
index 2a0b92f..33305d8 100755
--- a/install.sh
+++ b/install.sh
@@ -549,6 +549,13 @@ install_binary() {
run_spinner "[4/4] Installing binary to $INSTALL_DIR" install_binary || exit 1
log_success "[4/4] Binary installed to $APP_PATH"
+if [ "$DRY_RUN" -eq 0 ]; then
+ if ! "$APP_PATH" --version >/dev/null 2>&1; then
+ log_error "Installed binary failed execution smoke test ($APP_PATH)."
+ exit 1
+ fi
+fi
+
SHELL_MODIFIED=""
if [ "$NO_MODIFY_PATH" -eq 0 ]; then
if ! echo "$PATH" | tr ':' '\n' | grep -Fqx "$INSTALL_DIR"; then
diff --git a/src/main.rs b/src/main.rs
index ac97047..d780daf 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,6 +4,14 @@ use moviebox_tui::tui::app::App;
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
+#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
+core::arch::global_asm!(
+ ".pushsection .tbss.bionic_tls_align_anchor,\"awTR\",@nobits",
+ ".balign 64",
+ "bionic_tls_align_anchor:",
+ ".zero 64",
+ ".popsection",
+);
struct TerminalGuard;
fn restore_terminal() {