Skip to content

profile.c: fix x86 register names leaking onto aarch64 (Linux/Android)#949

Merged
yuxiaomao merged 1 commit into
HaxeFoundation:masterfrom
Pign:up/profile-aarch64
Jun 22, 2026
Merged

profile.c: fix x86 register names leaking onto aarch64 (Linux/Android)#949
yuxiaomao merged 1 commit into
HaxeFoundation:masterfrom
Pign:up/profile-aarch64

Conversation

@Pign

@Pign Pign commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

On Linux, get_thread_stackptr() read REG_RIP / REG_RSP from ucontext_t.uc_mcontext.gregs[], which only exist on x86. On AArch64 Linux (including Android), uc_mcontext is a struct sigcontext with direct pc / sp / regs[] fields and no gregs[] member, so the file failed to compile.

Two changes:

  • The existing HL_LINUX branch is now scoped to x86_64 / i386 explicitly.
  • A new HL_LINUX && __aarch64__ branch reads .pc / .sp directly from uc_mcontext.

Independent of any JIT work; unblocks compiling hl/libhl on aarch64 Linux and through the Android NDK. No behaviour change on x86.

The Linux branch of get_thread_stackptr() pulled REG_RIP / REG_RSP from
ucontext_t.uc_mcontext.gregs[], which only exist on x86. On AArch64
Linux (including Android), uc_mcontext is a struct sigcontext with
direct pc / sp / regs[] fields and no gregs[] member, so the file
failed to compile.

Two changes:

- The existing HL_LINUX branch is now scoped to x86_64/i386 explicitly.
- A new HL_LINUX + __aarch64__ branch reads .pc and .sp directly from
  uc_mcontext, matching the struct layout in linux/arch/arm64.

This unblocks building hl + libhl + the AArch64 JIT backend through
the Android NDK (CMake -DCMAKE_TOOLCHAIN_FILE=$NDK/.../android.toolchain.cmake
-DANDROID_ABI=arm64-v8a). Verified end-to-end on an arm64-v8a Android
emulator (uname -m = aarch64): adb push of hl + libhl.so + a .hl
bytecode file, then `LD_LIBRARY_PATH=. ./hl calc.hl` returns
fib(20) % 256 = 109 via Sys.exit, proving recursion + the rest of the
JIT path execute correctly inside Android's process model.

Sys.println output is silent under `adb shell` (Android stdout
buffering / _exit without fflush) — that's an HL runtime issue
unrelated to the JIT, since stderr writes and file I/O work as
expected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@yuxiaomao yuxiaomao merged commit f12731f into HaxeFoundation:master Jun 22, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants