Skip to content

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

fix(build): align arm64 musl page size to 64kb and harden installer

Samir Hossains2a50b3840481
diff --git a/.cargo/config.toml b/.cargo/config.toml
index bfcb169..6801272 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -5,4 +5,4 @@ rustflags = ["-C", "target-feature=+crt-static"]
rustflags = ["-C", "target-feature=+crt-static"]
[target.aarch64-unknown-linux-musl]
-rustflags = ["-C", "relocation-model=pic", "-C", "link-arg=-pie"]
+rustflags = ["-C", "link-arg=-Wl,-z,max-page-size=65536"]
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 4e3b7fc..1cd9579 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -98,62 +98,34 @@ 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"
+ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS: "-C link-arg=-Wl,-z,max-page-size=65536"
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 }}
+ - name: Install QEMU for AArch64 smoke test
+ if: matrix.target == 'aarch64-unknown-linux-musl'
+ run: sudo apt-get update && sudo apt-get install -y qemu-user-static
+
- name: Smoke-test produced Unix binary
- if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'x86_64-apple-darwin' || matrix.target == 'aarch64-apple-darwin'
+ if: matrix.os != 'windows-latest'
run: target/${{ matrix.target }}/release/moviebox-tui --version
- - name: Align aarch64 ELF PT_TLS for Android Termux
- if: matrix.target == 'aarch64-unknown-linux-musl'
- run: |
- python3 - << 'EOF'
- import struct
-
- path = "target/aarch64-unknown-linux-musl/release/moviebox-tui"
- with open(path, "r+b") as f:
- data = f.read()
- fmt = "<HHIQQQIHHH"
- e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags, e_ehsize, e_phentsize, e_phnum = struct.unpack(
- fmt, data[16 : 16 + struct.calcsize(fmt)]
- )
- for i in range(e_phnum):
- off = e_phoff + i * e_phentsize
- ptype, pflags, poff, pvaddr, ppaddr, pfilesz, pmemsz, palign = struct.unpack(
- "<IIQQQQQQ", data[off : off + 56]
- )
- if ptype == 7 and palign < 64:
- f.seek(off + 48)
- f.write(struct.pack("<Q", 64))
- print(f"Patched PT_TLS p_align from {hex(palign)} to 0x40 (64 bytes)")
- EOF
-
- - name: Validate aarch64 ELF header for Android Termux (ET_DYN & TLS alignment)
+ - name: Validate aarch64 ELF segment page 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
+ python3 -c '
+ import subprocess, sys
+ out = subprocess.check_output(["readelf", "-lW", sys.argv[1]], text=True)
+ for line in out.splitlines():
+ if line.strip().startswith("LOAD"):
+ align = int(line.split()[-1], 16)
+ if align < 65536:
+ sys.exit(f"PT_LOAD alignment {hex(align)} is less than 64KB (0x10000)")
+ print("Verified PT_LOAD segments aligned to >= 64KB")
+ ' "$BIN"
- name: Smoke-test produced Windows binary
if: matrix.target == 'x86_64-pc-windows-msvc'
shell: pwsh
diff --git a/README.md b/README.md
index 3e4ba2d..b9d6755 100644
--- a/README.md
+++ b/README.md
@@ -36,6 +36,8 @@ Install via the automated script:
curl -fsSL https://raw.githubusercontent.com/mesamirh/MovieBox-Tui/main/install.sh | bash
```
+> **Raspberry Pi & Linux ARM64**: Prebuilt Linux ARM64 binaries (`MovieBox_Linux_arm64.tar.gz`) are statically linked musl executables with 64KB page alignment, supporting Raspberry Pi 4B (4KB pages), Raspberry Pi 5 (16KB pages), and ARM cloud servers. Prebuilt binaries require a 64-bit userland (`aarch64`). On 32-bit Raspberry Pi OS (`armhf`), install via Cargo (`cargo install moviebox-tui --locked`).
+
*macOS users can also install via Homebrew:*
```bash
brew tap mesamirh/moviebox-tui https://github.com/mesamirh/MovieBox-Tui
diff --git a/docs/cross-platform.md b/docs/cross-platform.md
index d08f663..df1ef82 100644
--- a/docs/cross-platform.md
+++ b/docs/cross-platform.md
@@ -14,7 +14,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; handle-safe atomic download replacement (dropping file handles before renames); background process spawning (registry queries, yt-dlp downloader, and update helper) hardened with canonical `CREATE_NO_WINDOW` (`0x08000000`). |
-| Linux | Flatpak mpv/VLC supported (`flatpak run …`); xdg data/cache dirs. |
+| Linux | Flatpak mpv/VLC supported (`flatpak run …`); xdg data/cache dirs. Linux ARM64 binaries (`MovieBox_Linux_arm64.tar.gz`) are fully static musl executables linked with 64KB ELF segment alignment (`-Wl,-z,max-page-size=65536`) for seamless compatibility across 4KB kernels (Raspberry Pi 4B), 16KB kernels (Raspberry Pi 5 / BCM2712), and 64KB kernels (AWS Graviton, RHEL/Fedora ARM). |
| Android (Termux) | Targets `aarch64-linux-android` linked against the Android NDK (Clang API 24+) and system Bionic `libc.so`, producing a native ELF executable with a valid `PT_PHDR` program header table and `/system/bin/linker64` dynamic loader. This eliminates `Could not find a PHDR: broken executable?` crashes and executes natively without on-device compilation. Includes a pure-Rust DNS resolver that reads system configuration and falls back to public resolvers (Cloudflare, Google, Quad9) for zero-config name resolution. Android playback delegates to external video players (VLC for Android, Just Player, MX Player, MPV Android) via Termux intent dispatchers (`termux-open`, `termux-open-url`, `termux-am`), requiring `pkg install -y termux-tools termux-am`. To protect against Android 10+ SELinux execute restrictions (exit code 126), system `/system/bin/am` fallbacks are strictly avoided in Termux; `LD_PRELOAD` is preserved for Termux applets while `PATH` is sanitized for system calls. Android intent playback supports unauthenticated streams (CircleFTP, DhakaFlix, IPTV) and standard CDN streams (4KHDHub). Real-device chooser behavior is a release prerequisite. |
## Terminal capabilities
diff --git a/docs/installation.md b/docs/installation.md
index 54a7d48..ef26519 100644
--- a/docs/installation.md
+++ b/docs/installation.md
@@ -12,6 +12,8 @@ Install via the automated script:
curl -fsSL https://raw.githubusercontent.com/mesamirh/MovieBox-Tui/main/install.sh | bash
```
+> **Raspberry Pi & Linux ARM64**: Prebuilt Linux ARM64 binaries (`MovieBox_Linux_arm64.tar.gz`) are statically linked musl executables with 64KB page alignment, supporting Raspberry Pi 4B (4KB pages), Raspberry Pi 5 (16KB pages), and ARM cloud servers. Prebuilt binaries require a 64-bit userland (`aarch64`). On 32-bit Raspberry Pi OS (`armhf`), install via Cargo (`cargo install moviebox-tui --locked`).
+
### macOS via Homebrew
```bash
diff --git a/docs/release-checklist.md b/docs/release-checklist.md
index 32c1530..0f445b3 100644
--- a/docs/release-checklist.md
+++ b/docs/release-checklist.md
@@ -98,7 +98,7 @@ This remains mandatory because chooser behavior is device/environment dependent.
Verify the published release contains:
-- expected archives for macOS, Linux x64, Linux arm64, Windows x64, and Windows arm64
+- expected archives for macOS, Linux x64, Linux arm64, Android arm64, Windows x64, and Windows arm64
- `SHA256SUMS`
- working install scripts / formula references
diff --git a/install.sh b/install.sh
index fa6a920..d17e915 100755
--- a/install.sh
+++ b/install.sh
@@ -396,6 +396,14 @@ elif [ "$OS" = "Linux" ]; then
FILE="MovieBox_Linux_x64.tar.gz"
PLATFORM_NAME="Linux (x86_64)"
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
+ if command -v getconf >/dev/null 2>&1 && [ "$(getconf LONG_BIT 2>/dev/null)" = "32" ]; then
+ log_error "Detected 32-bit userland on 64-bit ARM hardware ($ARCH kernel with 32-bit armhf OS)."
+ log_error "Prebuilt Linux ARM64 binaries require 64-bit userland (aarch64)."
+ printf "\n %bℹ%b To run on 32-bit Raspberry Pi OS, compile natively via cargo:\n" "$C_SAPPHIRE" "$C_RESET" >&2
+ printf " %bsudo apt update && sudo apt install -y pkg-config libssl-dev%b\n" "$C_BOLD" "$C_RESET" >&2
+ printf " %bcargo install moviebox-tui --locked%b\n\n" "$C_BOLD" "$C_RESET" >&2
+ exit 1
+ fi
FILE="MovieBox_Linux_arm64.tar.gz"
PLATFORM_NAME="Linux (arm64)"
else
@@ -414,6 +422,10 @@ resolve_version() {
printf "%s" "$VERSION" > "$TMP_VER_FILE"
return 0
fi
+ if [ -n "${MOVIEBOX_RELEASE_URL:-}" ]; then
+ printf "%s" "local-test" > "$TMP_VER_FILE"
+ return 0
+ fi
local release_header
release_header=$(curl -fsSI "https://github.com/$REPO/releases/latest" 2>/dev/null || true)
@@ -495,8 +507,13 @@ fi
TMP_DIR=$(mktemp -d)
-URL="https://github.com/$REPO/releases/download/$TARGET_VERSION/$FILE"
-CHECKSUM_URL="https://github.com/$REPO/releases/download/$TARGET_VERSION/SHA256SUMS"
+if [ -n "${MOVIEBOX_RELEASE_URL:-}" ]; then
+ URL="${MOVIEBOX_RELEASE_URL%/}/$FILE"
+ CHECKSUM_URL="${MOVIEBOX_RELEASE_URL%/}/SHA256SUMS"
+else
+ URL="https://github.com/$REPO/releases/download/$TARGET_VERSION/$FILE"
+ CHECKSUM_URL="https://github.com/$REPO/releases/download/$TARGET_VERSION/SHA256SUMS"
+fi
download_files() {
if ! curl -fsSL "$URL" -o "$TMP_DIR/$FILE"; then
@@ -561,12 +578,23 @@ 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 ! smoke_output=$("$APP_PATH" --version 2>&1); then
- log_error "Installed binary failed execution smoke test ($APP_PATH):"
- printf " %s\n" "$smoke_output" >&2
+ set +e
+ smoke_output=$("$APP_PATH" --version 2>&1)
+ smoke_status=$?
+ set -e
+ if [ "$smoke_status" -ne 0 ]; then
+ log_error "Installed binary failed execution smoke test ($APP_PATH, exit code $smoke_status):"
+ if [ -n "$smoke_output" ]; then
+ printf " %s\n" "$smoke_output" >&2
+ else
+ printf " (Process terminated with exit status %d without output)\n" "$smoke_status" >&2
+ fi
if [ "$IS_TERMUX" -eq 1 ]; then
printf "\n %bℹ%b If Termux rejects the binary, install via cargo:\n" "$C_SAPPHIRE" "$C_RESET" >&2
printf " %bpkg install -y rust clang && cargo install moviebox-tui --locked%b\n\n" "$C_BOLD" "$C_RESET" >&2
+ elif [ "$OS" = "Linux" ] && { [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; }; then
+ printf "\n %bℹ%b If your Linux distribution kernel or environment rejects the binary, install via cargo:\n" "$C_SAPPHIRE" "$C_RESET" >&2
+ printf " %bcargo install moviebox-tui --locked%b\n\n" "$C_BOLD" "$C_RESET" >&2
fi
exit 1
fi
diff --git a/src/main.rs b/src/main.rs
index 1a49a00..ac97047 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,25 +4,6 @@ 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!(
- ".section .tdata,\"awT\",@progbits",
- ".p2align 6",
- ".globl __bionic_tls_align_anchor",
- "__bionic_tls_align_anchor:",
- ".text",
- ".globl __bionic_tls_align_reference",
- ".type __bionic_tls_align_reference,%function",
- "__bionic_tls_align_reference:",
- "add x0, x0, :tprel_lo12_nc:__bionic_tls_align_anchor",
- "ret",
- ".size __bionic_tls_align_reference, .-__bionic_tls_align_reference",
-);
-
-#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
-unsafe extern "C" {
- fn __bionic_tls_align_reference();
-}
struct TerminalGuard;
fn restore_terminal() {
@@ -86,10 +67,6 @@ impl Drop for TerminalGuard {
#[tokio::main]
async fn main() -> std::io::Result<()> {
- #[cfg(all(target_arch = "aarch64", target_os = "linux"))]
- {
- core::hint::black_box(__bionic_tls_align_reference as *const ());
- }
let args: Vec<String> = std::env::args().collect();
if args.iter().any(|arg| arg == "--help" || arg == "-h") {
println!("moviebox-tui {}", env!("CARGO_PKG_VERSION"));