Skip to content

asm: declare C ABI clobbers on loongarch64 syscalls - #132

Open
Moraxyc wants to merge 1 commit into
NotAShelf:mainfrom
Moraxyc:fix/loongarch64-syscall-clobbers
Open

Moraxyc wants to merge 1 commit into
NotAShelf:mainfrom
Moraxyc:fix/loongarch64-syscall-clobbers

Conversation

@Moraxyc

@Moraxyc Moraxyc commented Dec 4, 2026 •

Copy link
Copy Markdown

Why

On loongarch64-linux, syscall 0 does not preserve caller-saved registers ($t0–$t8). Without clobber declarations, rustc can keep live values in $t0/$t1 across a syscall.

On a Loongson-3A6000 host (Linux 7.3.6), microfetch 1.2.0 (from nixpkgs) consistently crashed with SIGSEGV (BADV = 0x30) in memcpy during output formatting:

  • Before sys_sysinfo (syscall 0): $t1 held the cached &str pointer (0x120019a3b)
  • After sys_sysinfo: $t1 was overwritten to 0x30, which was then spilled to the stack and later passed to memcpy

Note

This might be a conservative fix here since it also marks $ra, argument registers, and FP temporaries as clobbered. Following microfetch's style in x86_64/mips64/powerpc64, we may want to replace it with explicit lateout("$t0") _..lateout("$t8") _ clobbers (plus any other syscall-clobbered registers). Let me know if you'd like me to narrow this down or keep clobber_abi("C") for safety!

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).
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.

1 participant