[clang] [Clang][attr] Add 'kcfi_salt' attribute (PR #141846)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 21 07:59:00 PDT 2025


================
@@ -0,0 +1,190 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -x c++ -o - %s | FileCheck %s --check-prefixes=CHECK,MEMBER
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -fpatchable-function-entry-offset=3 -o - %s | FileCheck %s --check-prefixes=CHECK,OFFSET
+
+// Note that the interleving of functions, which normally would be in sequence,
+// is due to the fact that Clang outputs them in a non-sequential order.
+
+#if !__has_feature(kcfi)
----------------
AaronBallman wrote:

> I'm not sure how complex it would be to add checks for this.

I think you'd mostly be updating `ASTContext::mergeFunctionTypes()`; that's where we check things like calling convention mismatches, noreturn mismatches, and other type properties of a function.

I think we also need some logic to handle declaration merging for things like:
```
typedef int foo;
typedef int foo __attribute__((kcfi_salt("pepper"))); // Should this be allowed on a redeclaration?
typedef int foo __attribute__((kcfi_salt("spice"))); // Should be rejected, right?
```
(around `Sema::MergeTypedefNameDecl())`) and similar for tentative variable declarations (around `Sema::MergeVarDecl()` probably)

https://github.com/llvm/llvm-project/pull/141846


More information about the cfe-commits mailing list