Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/auto-sync-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ jobs:
env:
AGY_VERSION: ${{ steps.check_version.outputs.version }}
run: |
if ! command -v patchelf >/dev/null 2>&1; then
sudo apt-get update && sudo apt-get install -y patchelf
fi
./build.sh

- name: Package Standalone Archive
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ jobs:
jq
tar
python
patchelf
clang
glibc
glibc-runner
Expand Down
14 changes: 12 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Environment:
Required if that binary cannot run on this host.

Requirements:
- curl, jq, tar, python3
- curl, jq, tar, python3, patchelf
- native aarch64 Termux clang, or \$ANDROID_NDK_HOME with an aarch64 Android clang
EOF
}
Expand All @@ -66,7 +66,7 @@ trap cleanup EXIT
check_prereqs() {
info "Checking build prerequisites..."
local missing=()
for cmd in curl jq tar python3; do
for cmd in curl jq tar python3 patchelf; do
if ! command -v "$cmd" &>/dev/null; then
missing+=("$cmd")
fi
Expand Down Expand Up @@ -230,6 +230,16 @@ print(f"Patched parameters: ubfx={ubfx_count}, lsl={lsl_count}, mask={mask_count
PY
ok "Patched binary generated: bin/agy.va39"

# Patch ELF interpreter and RUNPATH so agy.va39 can be executed directly under
# standard Termux PREFIX (ensuring /proc/self/exe resolves to agy.va39 for plugin shims).
termux_prefix="${PREFIX:-/data/data/com.termux/files/usr}"
info "Patching ELF interpreter and RUNPATH on bin/agy.va39..."
patchelf \
--set-interpreter "${termux_prefix}/glibc/lib/ld-linux-aarch64.so.1" \
--set-rpath "${termux_prefix}/glibc/lib" \
bin/agy.va39
ok "ELF interpreter and RUNPATH patched."

# Compile the native Termux C bootstrapper.
info "Compiling native Termux C bootstrapper..."
if ! "$local_cc" -O2 -DAGY_TERMUX_VERSION="\"$latest_version\"" -o bin/agy lib/agy_helper.c; then
Expand Down
14 changes: 11 additions & 3 deletions lib/agy_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,10 @@ int main(int argc, char **argv) {
return 1;
}

// Execute agy.va39 directly under standard Termux PREFIX so /proc/self/exe
// resolves to agy.va39 rather than ld-linux-aarch64.so.1 (needed by plugin shims).
int direct_exec = strcmp(prefix_path, "/data/data/com.termux/files/usr") == 0;

// We allocate enough space for: qemu + loader + "--library-path" + lib_path
// + patched_bin + user args + NULL
int new_argc = argc + 6;
Expand All @@ -747,10 +751,14 @@ int main(int argc, char **argv) {
new_argv[arg_idx++] = (char *)qemu;
exec_target = qemu;
exec_error = "[agy-termux] execv (qemu) failed";
} else if (direct_exec) {
exec_target = patched_bin;
}
if (!direct_exec) {
new_argv[arg_idx++] = (char *)loader;
new_argv[arg_idx++] = "--library-path";
new_argv[arg_idx++] = lib_path;
}
new_argv[arg_idx++] = (char *)loader;
new_argv[arg_idx++] = "--library-path";
new_argv[arg_idx++] = lib_path;
new_argv[arg_idx++] = patched_bin;

for (int i = 1; i < argc; i++) {
Expand Down