Skip to content

Clobber vector registers and do not use preserves_flags in riscv64 syscalls#1570

Open
taiki-e wants to merge 1 commit intobytecodealliance:mainfrom
taiki-e:riscv64
Open

Clobber vector registers and do not use preserves_flags in riscv64 syscalls#1570
taiki-e wants to merge 1 commit intobytecodealliance:mainfrom
taiki-e:riscv64

Conversation

@taiki-e
Copy link
Contributor

@taiki-e taiki-e commented Jan 7, 2026

From kernel docs: https://docs.kernel.org/arch/riscv/vector.html#vector-register-state-across-system-calls

3. Vector Register State Across System Calls

As indicated by version 1.0 of the V extension [1], vector registers are clobbered by system calls.

1: https://github.com/riscv/riscv-v-spec/blob/master/calling-convention.adoc

And the linked docs says:

Executing a system call causes all caller-saved vector registers (v0-v31, vl, vtype) and vstart to become unspecified.

See also this glibc bugfix: https://patchwork.sourceware.org/project/glibc/patch/18a15d9d-e3d0-4625-a49e-03e3ecddf011@tenstorrent.com/
(Probably musl (riscv64, riscv32) also has the same bug. cc @Amanieu @kraj as target maintainers of corresponding Rust targets)

Unlike the above glibc patch which clobbers them depending on whether the vector ISA is enabled, this patch always clobbers them. (cfg(target_feature = “vector”) does not work except on nightly because the vector target feature is unstable. And, in Rust, always marking them as clobbered works fine (as clobber_abi does).

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