Skip to content

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

fix(build): align linux-arm64 pt_tls segment for android bionic compatibility

Samir Hossainsec6674e735b1
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index f4a8150..2fbec66 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -108,6 +108,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: 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)
if: matrix.target == 'aarch64-unknown-linux-musl'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 301bddd..aa160ba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -153,7 +153,7 @@
- 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 64-byte `PT_TLS` alignment anchor in `src/main.rs` and post-build ELF program header alignment in `.github/workflows/release.yml` 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
- Pruned unused legacy type aliases (`SeasonInfo`, `EpisodeInfo`, `StreamResource`, `StreamMirror`) in `src/models.rs`.
diff --git a/src/main.rs b/src/main.rs
index d780daf..1a49a00 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,12 +6,23 @@ 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",
+ ".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() {
@@ -75,6 +86,10 @@ 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"));