[llvmlinux] [PATCH] x86/hweight: LLVMLinux: Fix __arch_hweight{32, 64}() for compilation with clang

Sanjoy Das sanjoy at playingwithpointers.com
Sun Sep 13 22:46:07 UTC 2015


PaX Team wrote:
 > On 13 Sep 2015 at 23:45, Jan-Simon Moeller wrote:
 >
 >> Am Sonntag, 13. September 2015, 23:14:22 schrieb PaX Team:
 >>
 >>>> does not specify that the "call __sw_hweight64" instruction may
 >> clobber
 >>>> caller saved registers (like %rcx and %rdx).
 >>> actually, the __sw_hweight* functions may *not* clobber anything. the
 >>> trick is in how lib/hweight.o is compiled: CFLAGS contains a set of
 >>> -fcall-saved-REG switches (cf. ARCH_HWEIGHT_CFLAGS) that effectively
 >>> override the function call ABI for the functions defined in this file
 >>> so there's no need for the callers to specify any extra clobbers. this
 >>> way the fast path execution (inlined popcnt insn) doesn't unnecessarily
 >>> perturb the register allocator in the callers.
 >> The issues is that clang does not support these flags. So exactly the
 >> "do not clobber" trick does not happen.

Interesting, thanks for explaining!

 >
 > i know, that's why my patch removed the fast path which works with clang
 > (but it isn't good for upstream, hence my suggestion to use thunk*.S
 > instead).
 >

LLVM already has a "preserve_allcc" that constrains the callee to not
clobber any registers other than the return value register and %r11.
As an alternative to thunk'ifying the helper routines, you could also
discuss with clang developers if adding a second "preserves_all"
calling convention to LLVM that also preserves %r11 and making it
usable from the clang frontend is reasonable.  If there are many
places in the kernel that require -fcall-saved-REG, then a new calling
convention in clang may make things more scalable.

-- Sanjoy


More information about the LLVMLinux mailing list