[llvm-branch-commits] [clang] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

Daniil Kovalev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jun 7 01:42:11 PDT 2024


================
@@ -14,10 +14,146 @@
 #ifndef LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
 #define LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
 
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Target/TargetOptions.h"
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
 namespace clang {
 
 constexpr unsigned PointerAuthKeyNone = -1;
 
+class PointerAuthSchema {
+public:
+  enum class Kind : unsigned {
+    None,
+    ARM8_3,
+  };
+
+  /// Hardware pointer-signing keys in ARM8.3.
+  ///
+  /// These values are the same used in ptrauth.h.
+  enum class ARM8_3Key : unsigned {
+    ASIA = 0,
+    ASIB = 1,
+    ASDA = 2,
+    ASDB = 3
+  };
+
+  /// Forms of extra discrimination.
+  enum class Discrimination : unsigned {
+    /// No additional discrimination.
+    None,
+
+    /// Discriminate using a constant value.
+    Constant,
+  };
+
+private:
+  Kind TheKind : 2;
+  unsigned IsAddressDiscriminated : 1;
----------------
kovdan01 wrote:

Do I get it correct that you use `unsigned` for all bit fields instead of `bool IsXXX : 1` for flags and just `uint16_t ConstantDiscriminator` because you rely on some implementation-defined behavior which makes packing fields of the same types more efficient? If you do not rely on that, having more specific types looks more appropriate.

In `class CGPointerAuthInfo` you use different types for bit fields (e.g. `bool IsXXX : 1` is used for flags). So, it's better to keep things consistent and also use such convention here (or, alternatively, use `unsigned` everywhere if there is a strong reason for this)

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


More information about the llvm-branch-commits mailing list