Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .github/workflows/release-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 81 additions & 0 deletions scripts/check-elf-page-size.py
Original file line number Diff line number Diff line change
@@ -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)
Loading