profile.c: fix x86 register names leaking onto aarch64 (Linux/Android)#949
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Linux,
get_thread_stackptr()readREG_RIP/REG_RSPfromucontext_t.uc_mcontext.gregs[], which only exist on x86. On AArch64 Linux (including Android),uc_mcontextis astruct sigcontextwith directpc/sp/regs[]fields and nogregs[]member, so the file failed to compile.Two changes:
HL_LINUXbranch is now scoped tox86_64/i386explicitly.HL_LINUX && __aarch64__branch reads.pc/.spdirectly fromuc_mcontext.Independent of any JIT work; unblocks compiling hl/libhl on aarch64 Linux and through the Android NDK. No behaviour change on x86.