[clang] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-21 Thread Sebastian Österlund via cfe-commits


@@ -2196,8 +2197,32 @@ llvm::ConstantInt 
*CodeGenModule::CreateKCFITypeId(QualType T) {
   if (getCodeGenOpts().SanitizeCfiICallNormalizeIntegers)
 Out << ".normalized";
 
-  return llvm::ConstantInt::get(Int32Ty,
-
static_cast(llvm::xxHash64(OutName)));
+  uint32_t OutHash = static_cast(llvm::xxHash64(OutName));
+  const auto &Triple = getTarget().getTriple();
+  if (Triple.isX86() && Triple.isArch64Bit() && Triple.isOSLinux()) {

sirmc wrote:

-> `if (FnType && Triple.isX86() && Triple.isArch64Bit() && Triple.isOSLinux())`

Just to make sure that FnType isn't a null pointer.

https://github.com/llvm/llvm-project/pull/117121
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [X86] Extend kCFI with a 3-bit arity indicator (PR #121070)

2025-01-22 Thread Sebastian Österlund via cfe-commits

sirmc wrote:

I had a quick look (sorry for not getting to this earlier, was traveling around 
Vietnam for a few weeks). Looks good to me. Especially the trick of encoding 
the arity into the MOV32ri register seems very neat from a compatibility 
standpoint.

So if I understand this correctly, the only compatibility conflict this 
introduces is with the kernel's handling of rewriting the kCFI function 
prologue, which can be checked with `__has_feature`. Enabling this arity 
hardening in Rust, if desired, seems straight-forward to me.

My only concern for the current PR was that the change might be incompatible 
with the handling on the kernel side (i.e., that the kernel's rewrite code 
assumed EAX rather than any other value in the reg field), which could fail 
older kernel builds with a newer toolchain. But after a quick look it seems 
like the decoding doesn't create conflict (see 
https://github.com/torvalds/linux/blob/c4b9570cfb63501638db720f3bee9f6dfd044b82/arch/x86/kernel/alternative.c#L1112).
 And AFAIK there's no other users of kCFI besides the Linux kernel (but please 
correct me if I'm wrong). I do see some initial work on supporting kCFI in 
FreeBSD https://reviews.freebsd.org/D46193, but this also seems compatible to 
me too. 

So in short, all seems ok to me.

https://github.com/llvm/llvm-project/pull/121070
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits