[clang] [Clang][attr] Add 'kcfi_salt' attribute (PR #141846)
Miguel Ojeda via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 17 02:49:04 PDT 2025
================
@@ -3643,6 +3643,64 @@ make the function's CFI jump table canonical. See :ref:`the CFI documentation
}];
}
+def KCFISaltDocs : Documentation {
+ let Category = DocCatFunction;
+ let Content = [{
+Use ``__attribute__((kcfi_salt("<salt>")))`` on a function declaration, function
+definition, or typedef to help distinguish CFI hashes between functions with
+the same type signature.
+
+Example use:
+
+.. code-block:: c
+
+ // .h file:
+ #define __kcfi_salt __attribute__((kcfi_salt("vogon")))
+
+ // Convenient typedefs to avoid nested declarator syntax.
+ typedef int (*fptr_t)(void); // Non-salted function call.
+ typedef int (*fptr_salted_t)(void) __kcfi_salt;
+
+ struct widget_generator {
+ fptr_t init;
+ fptr_salted_t exec;
+ fptr_t teardown;
+ };
+
+ // 1st .c file:
+ static int internal_init(void) { /* ... */ }
+ static int internal_salted_exec(void) __kcfi_salt { /* ... */ }
+ static int internal_teardown(void) { /* ... */ }
+
+ static struct widget_generator _generator = {
+ .init = internal_init,
+ .exec = internal_salted_exec,
+ .teardown = internal_teardown,
+ }
----------------
ojeda wrote:
```suggestion
};
```
https://github.com/llvm/llvm-project/pull/141846
More information about the cfe-commits
mailing list