Conversation
The LLVM MCJIT backend was crashing with SIGBUS when running DOOM on ARM64 macOS. Root causes and fixes: 1. LLVM struct layout mismatch: The LLVM IR struct definition for riscv_internal had fields in wrong order (io at position 2), not matching the actual C struct layout. Fixed by reordering to match: halt, X[32], PC, timer, data, io. 2. GEP-based io function offset: t2c_gen_call_io_func used GEP with incorrect struct indices. Replaced with manual pointer arithmetic (PtrToInt -> Add -> IntToPtr) using byte offsets from offsetof(). This is robust regardless of SYSTEM mode configuration. 3. Hard-coded ecall/ebreak indices: Call sites used magic numbers that were incorrect. Changed to use offsetof(riscv_t, io) + offsetof(riscv_io_t, on_ecall/on_ebreak) for correctness across all build configurations. 4. Code model on Apple Silicon: LLVMCodeModelLarge generates movz/movk sequences that are problematic on ARM64. Use LLVMCodeModelSmall for Apple Silicon, Large for other platforms. 5. MCJIT initialization: Changed from LLVMCreateExecutionEngineForModule to LLVMCreateMCJITCompilerForModule with explicit options to ensure code model setting is respected.
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.
The LLVM MCJIT backend was crashing with SIGBUS when running DOOM on ARM64 macOS. Root causes and fixes:
Summary by cubic
Fixes a SIGBUS crash on Apple Silicon by aligning LLVM IR with the C struct, correcting io handler address calculation, and using the Small code model on ARM64 macOS. Also switches MCJIT initialization to respect these settings.
Written for commit 7109507. Summary will update on new commits.