[llvm-dev] [RFC] Zeroing Caller Saved Regs

Bill Wendling via llvm-dev llvm-dev at lists.llvm.org
Thu Aug 6 16:12:00 PDT 2020

[This feature addresses https://bugs.llvm.org/show_bug.cgi?id=37880
and https://github.com/KSPP/linux/issues/84.]

Clang has been ramping up its support of the Linux kernel. We recently
added "asm goto with outputs", a long requested feature. We want to
continue building our relationship with the Linux community.

KSPP is a project to improve security in the Linux kernel, through
both kernel changes and compiler features. One compiler feature they
want is the ability to zero out caller-saved registers on function
return as a defense against stale register contents being used as a
side-channel or speculation path.

The option will be "opt-in" for each target. Targets that don't
support the flag should probably emit a warning or error.

Our proposal for the feature is modeled off of H. J. Lu's
description[1] (copied with some modifications):

Add -mzero-caller-saved-regs=[skip|used-gpr|all-gpr|used|all]
command-line option and zero_caller_saved_regs function attributes:

* Don't zero caller-saved registers upon function return (default):


* Zero used caller-saved integer registers upon function return:


* Zero all integer registers upon function return:


* Zero used caller-saved integer and vector registers upon function return:


* Zero all caller-saved integer and vector registers upon function return:



[1] https://github.com/clearlinux-pkgs/gcc/blob/master/0001-x86-Add-mzero-caller.patch

More information about the llvm-dev mailing list