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

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 23 14:55:04 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)
----------------
bwendling wrote:

> ```
> typedef int (*foo)(void);
> typedef int (*foo)(void) __attribute__((kcfi_salt("pepper"))); // Should this be allowed on a redeclaration?
> typedef int (*foo)(void) __attribute__((kcfi_salt("spice"))); // Should be rejected, right?
> ```

These are rejected, even if the first one is removed. If the salt strings are the same, then it's accepted. I believe that's the correct behavior. I'll add tests for it.

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


More information about the cfe-commits mailing list