From 711d602fde86328f9ec8b3567d4d3be8805e91fc Mon Sep 17 00:00:00 2001 From: Arun Kumar Thiagarajan <222980227+HMAKT99@users.noreply.github.com> Date: Thu, 19 Nov 2026 19:23:38 +0530 Subject: [PATCH] Linux ARM64: check that every shipped binary loads on 16 KB-page kernels Asahi Linux (Apple silicon Macs, including Omarchy Mac) uses 16 KB pages. An ELF whose LOAD segments are aligned for 4 KB pages cannot be mapped there and fails at start. scripts/check-elf-page-size.py reads each ELF's program headers (no external tools) and fails if any LOAD segment is aligned below 16 KB. The ARM64 release job and the PR release check run it on the AppImage (its runtime and every bundled library), the desktop binary and the CLI. Checked by hand on v0.1.10: the ARM64 CLI and the desktop binary from the .deb are aligned to 64 KB. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release-check.yml | 5 ++ .github/workflows/release.yml | 8 +++ scripts/check-elf-page-size.py | 81 +++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100755 scripts/check-elf-page-size.py diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml index de5dae6..94a8f9b 100644 --- a/.github/workflows/release-check.yml +++ b/.github/workflows/release-check.yml @@ -45,3 +45,8 @@ jobs: cargo build --release -p agasthy-cli ./target/release/agasthy --version file target/release/agasthy | grep -i aarch64 + - name: Loads on 16 KB-page kernels (Asahi Linux, Omarchy Mac) + run: | + img=$(ls target/release/bundle/appimage/*.AppImage | head -1) + (cd "$RUNNER_TEMP" && "$GITHUB_WORKSPACE/$img" --appimage-extract >/dev/null) + python3 scripts/check-elf-page-size.py "$img" "$RUNNER_TEMP/squashfs-root" target/release/agasthy target/release/agasthy-desktop diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6a51fb4..5d54bc5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -292,6 +292,14 @@ jobs: (cd dist && sha256sum agasthy-cli-linux-aarch64.tar.gz > agasthy-cli-linux-aarch64.tar.gz.sha256) mkdir -p check && tar -C check -xzf dist/agasthy-cli-linux-aarch64.tar.gz && ./check/agasthy --version + # Asahi Linux (Apple silicon, including Omarchy Mac) runs 16 KB pages; a + # binary aligned for 4 KB pages cannot load there. + - name: Loads on 16 KB-page kernels (Asahi Linux, Omarchy Mac) + run: | + img=$(ls dist/*_aarch64.AppImage | head -1) + (cd "$RUNNER_TEMP" && "$GITHUB_WORKSPACE/$img" --appimage-extract >/dev/null) + python3 scripts/check-elf-page-size.py "$img" "$RUNNER_TEMP/squashfs-root" check/agasthy + - uses: actions/upload-artifact@v4 with: name: linux-arm diff --git a/scripts/check-elf-page-size.py b/scripts/check-elf-page-size.py new file mode 100755 index 0000000..7c52f0e --- /dev/null +++ b/scripts/check-elf-page-size.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +"""Check that ELF files can load on Linux kernels with 16 KB (or 64 KB) pages. + +Usage: scripts/check-elf-page-size.py [--min BYTES] PATH... + +Each PATH is an ELF file or a directory searched recursively. Asahi Linux +(Apple silicon, including Omarchy Mac) runs 16 KB pages; an ELF whose LOAD +segments are aligned to less than that cannot be mapped there and fails at +start. Exits 1 if any ELF is aligned below --min (default 16384). +""" +import os +import struct +import sys + +args = sys.argv[1:] +minimum = 16384 +if args[:1] == ["--min"]: + minimum = int(args[1]) + args = args[2:] +if not args: + sys.exit(__doc__) + + +def load_alignments(path): + with open(path, "rb") as f: + head = f.read(64) + if len(head) < 52 or head[:4] != b"\x7fELF": + return None + is64 = head[4] == 2 + end = "<" if head[5] == 1 else ">" + if is64: + phoff, = struct.unpack_from(end + "Q", head, 32) + phentsize, phnum = struct.unpack_from(end + "HH", head, 54) + else: + phoff, = struct.unpack_from(end + "I", head, 28) + phentsize, phnum = struct.unpack_from(end + "HH", head, 42) + f.seek(phoff) + table = f.read(phentsize * phnum) + aligns = [] + for i in range(phnum): + off = i * phentsize + p_type, = struct.unpack_from(end + "I", table, off) + if p_type != 1: # PT_LOAD + continue + if is64: + p_align, = struct.unpack_from(end + "Q", table, off + 48) + else: + p_align, = struct.unpack_from(end + "I", table, off + 28) + aligns.append(p_align) + return aligns + + +def files(paths): + for p in paths: + if os.path.isdir(p): + for root, _, names in os.walk(p): + for n in names: + full = os.path.join(root, n) + if os.path.isfile(full) and not os.path.islink(full): + yield full + else: + yield p + + +checked, bad = 0, [] +for path in files(args): + try: + aligns = load_alignments(path) + except OSError: + continue + if not aligns: + continue + checked += 1 + low = min(aligns) + if low < minimum: + bad.append((path, low)) + +for path, low in bad: + print(f"too small for {minimum // 1024} KB pages: {path} (LOAD aligned to {low} bytes)") +print(f"{checked} ELF files checked, {len(bad)} aligned below {minimum} bytes") +sys.exit(1 if bad else 0)