Skip to content

OpenCode binary fails to run natively on Termux / Android aarch64 (wrong interpreter + non‑PIE executable) #10504

@ivannin

Description

@ivannin

Description

Environment

  • Device: Android smartphone/tablet, HUAWEI PaperMate 11.5
  • OS: Android (5.0+), HarmionyOS 4.2.0
  • Terminal: Termux
  • Arch: aarch64 (uname -maarch64)
  • Install method: official install script (curl ... | sh, binary ends up in ~/.opencode/bin/opencode)

Summary

After installing OpenCode on Termux using the official script, the Linux/aarch64 opencode binary does not start as a native Android executable.

  1. The binary requests a dynamic linker at /lib/ld-linux-aarch64.so.1, which does not exist on Android/Termux.
  2. After manually changing the interpreter to the correct Android linker, the binary fails with Android 5.0 and later only support position-independent executables (-fPIE), which means it was not compiled as PIE and cannot be run on modern Android at all.

Steps to reproduce

  1. Install Termux from F‑Droid / Play Store.
  2. Update packages and install diagnostic tools:
    pkg update -y
    pkg install -y file binutils patchelf
  3. Install OpenCode using the official method, for example:
    curl -fsSL https://opencode.ai/install.sh | sh
  4. Try to run the binary:
    /data/data/com.termux/files/home/.opencode/bin/opencode
  5. Observe the shell error:
    bash: /data/data/com.termux/files/home/.opencode/bin/opencode: cannot execute: required file not found

Diagnostics

  1. Check the file type:

    file /data/data/com.termux/files/home/.opencode/bin/opencode

    The output shows a 64‑bit ELF for aarch64, with the program interpreter set to /lib/ld-linux-aarch64.so.1 (standard on many Linux distros, but not on Android/Termux).

  2. On Termux/Android, /lib/ld-linux-aarch64.so.1 does not exist.
    To find the correct interpreter, I inspected a working Termux binary (bash):

    readelf -l "$(which bash)" | grep "Requesting program interpreter"

    This reports /system/bin/linker64 as the requested program interpreter.

  3. I tried to “fix” the opencode binary by changing its interpreter:

    patchelf --set-interpreter /system/bin/linker64 \
      /data/data/com.termux/files/home/.opencode/bin/opencode

    This successfully changes the interpreter to the Android linker used by Termux.

  4. Running opencode again:

    /data/data/com.termux/files/home/.opencode/bin/opencode

    Now I get a different error:

    "/data/data/com.termux/files/home/.opencode/bin/opencode": error: Android 5.0 and later only support position-independent executables (-fPIE).
    

    This is the typical Android error when the ELF binary is not built as PIE. Since Android 5.0, only position‑independent executables (built with -fPIE / -pie) are allowed to run.

What I expected

I expected the official Linux/aarch64 OpenCode binary to either:

  • run natively under Termux on Android (with a correct interpreter and PIE build), or
  • clearly be documented as not supported for native Termux/Android, with guidance to use a different build or a proot‑based Linux environment instead.

What actually happens

  • With the unmodified binary: bash: cannot execute: required file not found due to the non‑existent /lib/ld-linux-aarch64.so.1.
  • After setting the interpreter to /system/bin/linker64: the binary exits with Android 5.0 and later only support position-independent executables (-fPIE) and cannot be started at all.
  • This cannot be fixed on the user side by patching the existing ELF; it requires recompiling OpenCode with the correct flags and target.

Analysis / root cause

  • The binary shipped by the installer appears to be a regular Linux ELF for aarch64 with glibc, requesting /lib/ld-linux-aarch64.so.1 as interpreter.
  • Termux runs on Android, using /system/bin/linker64 and a different ABI, and Android ≥ 5.0 rejects non‑PIE executables.
  • Even after manually fixing the interpreter path, the OpenCode binary still cannot run, because it does not satisfy Android’s requirement for position‑independent executables.

Why this deserves a dedicated fix

  • There are already reports about OpenCode issues on Termux (usually when running inside a proot‑distro like Ubuntu/Debian, with freezes, TUI issues, crashes on the second run, etc.), but those are runtime problems inside a Linux userland.
  • In this case, the problem is more fundamental: the official Linux/aarch64 binary is simply incompatible with the native Android ABI (wrong interpreter and non‑PIE), so it is impossible to run it directly in Termux without a full Linux environment in proot.

Suggested fix

  1. Provide an official Android/Termux build for aarch64 that:

    • is built as PIE (-fPIE / -pie),
    • uses the correct interpreter for Android (for example /system/bin/linker64, depending on the target ABI),
    • is tested in a real Termux environment, not only on standard Linux.
  2. Alternatively (until such a build exists), update the documentation and installer to:

    • explicitly state that the current Linux/aarch64 binary is not intended to run natively on Termux/Android,
    • recommend using OpenCode via a proot‑distro (Ubuntu/Debian) or a remote Linux server when working from Android.

Additional info

  • I can attach exact outputs of file, readelf -l, and patchelf --print-interpreter if needed.
  • I’m happy to test any experimental Android/Termux builds (aarch64) and provide feedback.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions