Repository navigation
Conversation
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.
Fixes #614.
A function with a large local buffer and stack-passed arguments can crash with SIGBUS in its prologue on AArch64 macOS. The reproducer calls a nine-argument function from a function containing a 12,000-byte volatile buffer.
The stack layout in
aarch64/Stacklayout.vrounds the total frame size (sz) to 16 bytes, but rounds the back-link offset (linkofs) to only 8 bytes.Pallocframeinaarch64/Asmexpand.mlcurrently allocates the frame in two parts:sz - linkofsfrom SP and store the saved SP and return address at that intermediate SP.linkofsbytes to reach the final SP.When
linkofsis 8 modulo 16, the intermediate SP is misaligned. In the large-frame path, the separatestpinstruction then accesses memory through that misaligned SP, which traps on macOS. The final frame size is already correct; execution faults before the second adjustment can restore alignment.For the reproducer,
sz = 12032andlinkofs = 8. The original sequence is:The fix calculates:
Since the frame size is 16-aligned, both allocation sizes are now multiples of 16. The saved pair is stored at
SP + linkdisp, wherelinkdispis either 0 or 8. Its address remains exactly the same:The patched compiler emits the following for the reproducer:
This changes only the pseudo-instruction expansion. The frame layout and total allocation are unchanged, so outgoing arguments, locals, saved-register loads, and frame deallocation keep their existing offsets. The CFI adjustments continue to describe the actual allocation at each stage and sum to the same frame size. The existing AAPCS64 variadic register-save area is also unchanged.
The pre-indexed
stpoptimization remains available whenlinkdispis zero and the first allocation fits its immediate range. Whenlinkdispis 8, use a separate aligned SP adjustment followed by an offset store, including for small frames. This avoids introducing a misaligned intermediate SP in either path.Validation:
aarch64-macoswith OCaml 4.14.5, Coq 8.20.1, and Menhir 20260209.34and exits 0.make -C test -j8 allandmake -C test testpass. The harness skipsstruct.cc2compcertandstruct.compcert2cc.git diff --checkpasses.The build emits linker warnings about absent OCaml
str/unixsearch directories but links successfully. The upstream tests live in the separateCompCert-small-testssubmodule; this change does not update that submodule or add a permanent regression test there.