Repository navigation
Conversation
Linux syscall 0 on loongarch64 does not preserve caller-saved temporary registers ($t0-$t8). Without clobber declarations, rustc keeps live values across syscall 0 (observed on __NR_sysinfo overwriting a cached &str pointer in $t1 with 0x30 and crashing in memcpy with SIGSEGV).
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.
Why
On
loongarch64-linux,syscall 0does not preserve caller-saved registers ($t0–$t8). Without clobber declarations,rustccan keep live values in$t0/$t1across a syscall.On a Loongson-3A6000 host (Linux 7.3.6),
microfetch1.2.0 (from nixpkgs) consistently crashed withSIGSEGV(BADV = 0x30) inmemcpyduring output formatting:sys_sysinfo(syscall 0):$t1held the cached&strpointer (0x120019a3b)sys_sysinfo:$t1was overwritten to0x30, which was then spilled to the stack and later passed tomemcpyNote
This might be a conservative fix here since it also marks
$ra, argument registers, and FP temporaries as clobbered. Followingmicrofetch's style inx86_64/mips64/powerpc64, we may want to replace it with explicitlateout("$t0") _..lateout("$t8") _clobbers (plus any other syscall-clobbered registers). Let me know if you'd like me to narrow this down or keepclobber_abi("C")for safety!