[llvm-branch-commits] [llvm] release/19.x: [PAC][test] Add tests against Linux triples for auth/resign lowering (#100744) (PR #101043)

2024-07-29 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl approved this pull request.


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


[llvm-branch-commits] [clang] release/19.x: [PAC][clang][test] Implement missing tests for some PAuth features (#100206) (PR #101044)

2024-07-29 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl approved this pull request.


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


[llvm-branch-commits] [llvm] release/19.x: [PAC] Sign LR with B key for non-leaf functions with ptrauth-returns attr (#100552) (PR #100716)

2024-07-26 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl approved this pull request.


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


[llvm-branch-commits] [clang] release/19.x: [PAC][clang] Enable `-fptrauth-indirect-gotos` as part of pauthtest ABI (#100480) (PR #100484)

2024-07-24 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl approved this pull request.


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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-20 Thread Anton Korobeynikov via llvm-branch-commits


@@ -296,3 +296,21 @@ 
ConstantAggregateBuilderBase::finishStruct(llvm::StructType *ty) {
   buffer.erase(buffer.begin() + Begin, buffer.end());
   return constant;
 }
+

asl wrote:

Yeah, LGTM!

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-19 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl approved this pull request.

Thanks!

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


[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-14 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl approved this pull request.

+1

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


[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-12 Thread Anton Korobeynikov via llvm-branch-commits

asl wrote:

@kbeyls There are (some) tests in the follow-up commit 
https://github.com/llvm/llvm-project/pull/93902/files#diff-8df159460fc7a128734566054df883f3192b1b261dc8eac667933b4042e9af5f

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


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

2024-06-12 Thread Anton Korobeynikov via llvm-branch-commits

asl wrote:

@ahatanak Looks like there are some conflicts that should be resolved

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


[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-11 Thread Anton Korobeynikov via llvm-branch-commits

asl wrote:

@ahmedbougacha Anything left here? I think it is good to go after the two 
changes mentioned above. We can deal with cross-endian things afterwards as 
soon as we will have tests & buildbots 


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


[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-10 Thread Anton Korobeynikov via llvm-branch-commits


@@ -1,185 +1,149 @@
-/*
-   SipHash reference C implementation
-
-   Copyright (c) 2012-2022 Jean-Philippe Aumasson
-   
-   Copyright (c) 2012-2014 Daniel J. Bernstein 
-
-   To the extent possible under law, the author(s) have dedicated all copyright
-   and related and neighboring rights to this software to the public domain
-   worldwide. This software is distributed without any warranty.
-
-   You should have received a copy of the CC0 Public Domain Dedication along
-   with
-   this software. If not, see
-   .
- */
-
-#include "siphash.h"
-#include 
-#include 
-#include 
-
-/* default: SipHash-2-4 */
-#ifndef cROUNDS
-#define cROUNDS 2
-#endif
-#ifndef dROUNDS
-#define dROUNDS 4
-#endif
+//===--- SipHash.cpp - An ABI-stable string hash 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
 
-#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b
+#include "llvm/Support/Compiler.h"
+#include 
 
-#define U32TO8_LE(p, v)
\
-(p)[0] = (uint8_t)((v));   
\
-(p)[1] = (uint8_t)((v) >> 8);  
\
-(p)[2] = (uint8_t)((v) >> 16); 
\
-(p)[3] = (uint8_t)((v) >> 24);
+// Lightly adapted from the SipHash reference C implementation:
+//   https://github.com/veorq/SipHash
+// by Jean-Philippe Aumasson and Daniel J. Bernstein
 
-#define U64TO8_LE(p, v)
\
-U32TO8_LE((p), (uint32_t)((v)));   
\
-U32TO8_LE((p) + 4, (uint32_t)((v) >> 32));
+#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b
 
 #define U8TO64_LE(p)   
\
-(((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) |
\
- ((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) | 
\
- ((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) | 
\
- ((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56))
+  (((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) |  
\
+   ((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) |   
\
+   ((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) |   
\
+   ((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56))
 
 #define SIPROUND   
\
-do {   
\
-v0 += v1;  
\
-v1 = ROTL(v1, 13); 
\
-v1 ^= v0;  
\
-v0 = ROTL(v0, 32); 
\
-v2 += v3;  
\
-v3 = ROTL(v3, 16); 
\
-v3 ^= v2;  
\
-v0 += v3;  
\
-v3 = ROTL(v3, 21); 
\
-v3 ^= v0;  
\
-v2 += v1;  
\
-v1 = ROTL(v1, 17); 
\
-v1 ^= v2;  
\
-v2 = ROTL(v2, 32); 
\
-} while (0)
-
-#ifdef DEBUG_SIPHASH
-#include 
-
-#define TRACE  
\
-do {   
\
-printf("(%3zu) v0 %016" PRIx64 "\n", inlen, v0);   
\
-printf("(%3zu) v1 %016" PRIx64 "\n", inlen, v1);   
\
-printf("(%3zu) v2 %016" PRIx64 "\n", inlen, v2);   
\
-printf("(%3zu) v3 %016" PRIx64 "\n", inlen, v3);   
\
-} while (0)
-#else
-#define TRACE
-#endif
-
-/*
-Computes a SipHash value
-*in: pointer to input data (read-only)
-inlen: input data length in bytes (any size_t value)
-*k: pointer to the key data (read-only), must be 16 bytes 
-*out: pointer to output data (write-only), outlen bytes must be allocated
-

[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-10 Thread Anton Korobeynikov via llvm-branch-commits


@@ -1,185 +1,149 @@
-/*
-   SipHash reference C implementation
-
-   Copyright (c) 2012-2022 Jean-Philippe Aumasson
-   
-   Copyright (c) 2012-2014 Daniel J. Bernstein 
-
-   To the extent possible under law, the author(s) have dedicated all copyright
-   and related and neighboring rights to this software to the public domain
-   worldwide. This software is distributed without any warranty.
-
-   You should have received a copy of the CC0 Public Domain Dedication along
-   with
-   this software. If not, see
-   .
- */
-
-#include "siphash.h"
-#include 
-#include 
-#include 
-
-/* default: SipHash-2-4 */
-#ifndef cROUNDS
-#define cROUNDS 2
-#endif
-#ifndef dROUNDS
-#define dROUNDS 4
-#endif
+//===--- SipHash.cpp - An ABI-stable string hash 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
 
-#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b
+#include "llvm/Support/Compiler.h"
+#include 
 
-#define U32TO8_LE(p, v)
\
-(p)[0] = (uint8_t)((v));   
\
-(p)[1] = (uint8_t)((v) >> 8);  
\
-(p)[2] = (uint8_t)((v) >> 16); 
\
-(p)[3] = (uint8_t)((v) >> 24);
+// Lightly adapted from the SipHash reference C implementation:
+//   https://github.com/veorq/SipHash
+// by Jean-Philippe Aumasson and Daniel J. Bernstein
 
-#define U64TO8_LE(p, v)
\
-U32TO8_LE((p), (uint32_t)((v)));   
\
-U32TO8_LE((p) + 4, (uint32_t)((v) >> 32));
+#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b
 
 #define U8TO64_LE(p)   
\

asl wrote:

Use `endian::read64le` instead this

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


[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-10 Thread Anton Korobeynikov via llvm-branch-commits


@@ -1,185 +1,149 @@
-/*
-   SipHash reference C implementation
-
-   Copyright (c) 2012-2022 Jean-Philippe Aumasson
-   
-   Copyright (c) 2012-2014 Daniel J. Bernstein 
-
-   To the extent possible under law, the author(s) have dedicated all copyright
-   and related and neighboring rights to this software to the public domain
-   worldwide. This software is distributed without any warranty.
-
-   You should have received a copy of the CC0 Public Domain Dedication along
-   with
-   this software. If not, see
-   .
- */
-
-#include "siphash.h"
-#include 
-#include 
-#include 
-
-/* default: SipHash-2-4 */
-#ifndef cROUNDS
-#define cROUNDS 2
-#endif
-#ifndef dROUNDS
-#define dROUNDS 4
-#endif
+//===--- SipHash.cpp - An ABI-stable string hash 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
 
-#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b
+#include "llvm/Support/Compiler.h"
+#include 
 
-#define U32TO8_LE(p, v)
\
-(p)[0] = (uint8_t)((v));   
\
-(p)[1] = (uint8_t)((v) >> 8);  
\
-(p)[2] = (uint8_t)((v) >> 16); 
\
-(p)[3] = (uint8_t)((v) >> 24);
+// Lightly adapted from the SipHash reference C implementation:
+//   https://github.com/veorq/SipHash
+// by Jean-Philippe Aumasson and Daniel J. Bernstein
 
-#define U64TO8_LE(p, v)
\
-U32TO8_LE((p), (uint32_t)((v)));   
\
-U32TO8_LE((p) + 4, (uint32_t)((v) >> 32));
+#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b

asl wrote:

Maybe we can use function call instead of macros?

E.g. (as in xxhash):
```c++
static uint64_t rotl64(uint64_t X, size_t R) {
  return (X << R) | (X >> (64 - R));
}
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-10 Thread Anton Korobeynikov via llvm-branch-commits

asl wrote:

> @asl It would be nice if you submit the next round of review as a single 
> review, instead of 29 individual comments.

Oh, strange. I thought it was a single review...

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -4406,10 +4416,19 @@ class CodeGenFunction : public CodeGenTypeCache {
   }
 
   bool isPointerKnownNonNull(const Expr *E);
+
+  /// Create the discriminator from the storage address and the entity hash.
+  llvm::Value *EmitPointerAuthBlendDiscriminator(llvm::Value *storageAddress,
+ llvm::Value *discriminator);

asl wrote:

```suggestion
 llvm::Value *Discriminator);
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -4406,10 +4416,19 @@ class CodeGenFunction : public CodeGenTypeCache {
   }
 
   bool isPointerKnownNonNull(const Expr *E);
+
+  /// Create the discriminator from the storage address and the entity hash.
+  llvm::Value *EmitPointerAuthBlendDiscriminator(llvm::Value *storageAddress,

asl wrote:

```suggestion
  llvm::Value *EmitPointerAuthBlendDiscriminator(llvm::Value *StorageAddress,
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2456,10 +2456,20 @@ class CodeGenFunction : public CodeGenTypeCache {
 
   void InitializeVTablePointers(const CXXRecordDecl *ClassDecl);
 
+  // VTableTrapMode - whether we guarantee that loading the
+  // vtable is guaranteed to trap on authentication failure,
+  // even if the resulting vtable pointer is unused.
+  enum class VTableAuthMode {
+Authenticate,
+MustTrap,
+UnsafeUbsanStrip // Should only be used for Vptr UBSan check
+  };
   /// GetVTablePtr - Return the Value of the vtable pointer member pointed
   /// to by This.
-  llvm::Value *GetVTablePtr(Address This, llvm::Type *VTableTy,
-const CXXRecordDecl *VTableClass);
+  llvm::Value *
+  GetVTablePtr(Address This, llvm::Type *VTableTy,
+   const CXXRecordDecl *VTableClass,
+   VTableAuthMode authMode = VTableAuthMode::Authenticate);

asl wrote:

```suggestion
   VTableAuthMode AuthMode = VTableAuthMode::Authenticate);
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -3063,3 +3063,66 @@ void CodeGenFunction::EmitPointerAuthOperandBundle(
   llvm::Value *args[] = {key, discriminator};
   bundles.emplace_back("ptrauth", args);
 }
+
+static llvm::Value *EmitPointerAuthCommon(CodeGenFunction ,

asl wrote:

ditto about code style

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl edited https://github.com/llvm/llvm-project/pull/94056
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -841,6 +866,9 @@ void 
CodeGenVTables::addVTableComponent(ConstantArrayBuilder ,
   if (FnAS != GVAS)
 fnPtr =
 llvm::ConstantExpr::getAddrSpaceCast(fnPtr, CGM.GlobalsInt8PtrTy);
+  if (auto  =
+  CGM.getCodeGenOpts().PointerAuth.CXXVirtualFunctionPointers)
+return builder.addSignedPointer(fnPtr, schema, GD, QualType());

asl wrote:

```suggestion
return builder.addSignedPointer(fnPtr, Schema, GD, QualType());
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -841,6 +866,9 @@ void 
CodeGenVTables::addVTableComponent(ConstantArrayBuilder ,
   if (FnAS != GVAS)
 fnPtr =
 llvm::ConstantExpr::getAddrSpaceCast(fnPtr, CGM.GlobalsInt8PtrTy);
+  if (auto  =

asl wrote:

```suggestion
  if (const auto  =
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -307,10 +309,15 @@ void 
CodeGenFunction::EmitCallAndReturnForThunk(llvm::FunctionCallee Callee,
   const CXXMethodDecl *MD = cast(CurGD.getDecl());
 
   // Adjust the 'this' pointer if necessary
+  const CXXRecordDecl *thisValueClass =
+  MD->getThisType()->getPointeeCXXRecordDecl();
+  if (Thunk)
+thisValueClass = Thunk->ThisType->getPointeeCXXRecordDecl();
+
   llvm::Value *AdjustedThisPtr =
-Thunk ? CGM.getCXXABI().performThisAdjustment(
-  *this, LoadCXXThisAddress(), Thunk->This)
-  : LoadCXXThis();
+  Thunk ? CGM.getCXXABI().performThisAdjustment(*this, 
LoadCXXThisAddress(),
+thisValueClass, *Thunk)

asl wrote:

```suggestion
ThisValueClass, *Thunk)
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -307,10 +309,15 @@ void 
CodeGenFunction::EmitCallAndReturnForThunk(llvm::FunctionCallee Callee,
   const CXXMethodDecl *MD = cast(CurGD.getDecl());
 
   // Adjust the 'this' pointer if necessary
+  const CXXRecordDecl *thisValueClass =
+  MD->getThisType()->getPointeeCXXRecordDecl();
+  if (Thunk)
+thisValueClass = Thunk->ThisType->getPointeeCXXRecordDecl();

asl wrote:

```suggestion
ThisValueClass = Thunk->ThisType->getPointeeCXXRecordDecl();
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -307,10 +309,15 @@ void 
CodeGenFunction::EmitCallAndReturnForThunk(llvm::FunctionCallee Callee,
   const CXXMethodDecl *MD = cast(CurGD.getDecl());
 
   // Adjust the 'this' pointer if necessary
+  const CXXRecordDecl *thisValueClass =

asl wrote:

```suggestion
  const CXXRecordDecl *ThisValueClass =
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -219,8 +219,10 @@ CodeGenFunction::GenerateVarArgsThunk(llvm::Function *Fn,
  "Store of this should be in entry block?");
   // Adjust "this", if necessary.
   Builder.SetInsertPoint(&*ThisStore);
-  llvm::Value *AdjustedThisPtr =
-  CGM.getCXXABI().performThisAdjustment(*this, ThisPtr, Thunk.This);
+
+  const CXXRecordDecl *thisValueClass = 
Thunk.ThisType->getPointeeCXXRecordDecl();
+  llvm::Value *AdjustedThisPtr = CGM.getCXXABI().performThisAdjustment(
+  *this, ThisPtr, thisValueClass, Thunk);

asl wrote:

```suggestion
  *this, ThisPtr, ThisValueClass, Thunk);
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -219,8 +219,10 @@ CodeGenFunction::GenerateVarArgsThunk(llvm::Function *Fn,
  "Store of this should be in entry block?");
   // Adjust "this", if necessary.
   Builder.SetInsertPoint(&*ThisStore);
-  llvm::Value *AdjustedThisPtr =
-  CGM.getCXXABI().performThisAdjustment(*this, ThisPtr, Thunk.This);
+
+  const CXXRecordDecl *thisValueClass = 
Thunk.ThisType->getPointeeCXXRecordDecl();

asl wrote:

```suggestion
  const CXXRecordDecl *ThisValueClass = 
Thunk.ThisType->getPointeeCXXRecordDecl();
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -90,6 +90,11 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,
  llvm::Constant *Init = llvm::ConstantExpr::getGetElementPtr(
  VTable->getValueType(), VTable, Idxs, /*InBounds=*/true, InRange);
 
+ if (auto  =
+ CGM.getCodeGenOpts().PointerAuth.CXXVTTVTablePointers)
+   Init = CGM.getConstantSignedPointer(Init, schema, nullptr, GlobalDecl(),

asl wrote:

```suggestion
   Init = CGM.getConstantSignedPointer(Init, Schema, nullptr, GlobalDecl(),
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -90,6 +90,11 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,
  llvm::Constant *Init = llvm::ConstantExpr::getGetElementPtr(
  VTable->getValueType(), VTable, Idxs, /*InBounds=*/true, InRange);
 
+ if (auto  =

asl wrote:

```suggestion
 if (auto  =
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -23,11 +23,53 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/IR/ValueMap.h"
 #include "llvm/Analysis/ValueTracking.h"
+#include "llvm/Support/SipHash.h"
 #include 
 
 using namespace clang;
 using namespace CodeGen;
 
+/// Given a pointer-authentication schema, return a concrete "other"
+/// discriminator for it.
+llvm::Constant *CodeGenModule::getPointerAuthOtherDiscriminator(

asl wrote:

It would be great to have consistent code style for variable names in this file.

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -803,6 +803,14 @@ bool ConstStructBuilder::Build(const APValue , const 
RecordDecl *RD,
   llvm::Constant *VTableAddressPoint =
   CGM.getCXXABI().getVTableAddressPoint(BaseSubobject(CD, Offset),
 VTableClass);
+  if (auto authentication =
+  CGM.getVTablePointerAuthentication(VTableClass)) {
+VTableAddressPoint = Emitter.tryEmitConstantSignedPointer(
+VTableAddressPoint, *authentication);

asl wrote:

```suggestion
VTableAddressPoint, *Authentication);
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -803,6 +803,14 @@ bool ConstStructBuilder::Build(const APValue , const 
RecordDecl *RD,
   llvm::Constant *VTableAddressPoint =
   CGM.getCXXABI().getVTableAddressPoint(BaseSubobject(CD, Offset),
 VTableClass);
+  if (auto authentication =

asl wrote:

```suggestion
  if (auto *Authentication =
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2681,12 +2687,35 @@ void CodeGenFunction::InitializeVTablePointers(const 
CXXRecordDecl *RD) {
 
 llvm::Value *CodeGenFunction::GetVTablePtr(Address This,
llvm::Type *VTableTy,
-   const CXXRecordDecl *RD) {
+   const CXXRecordDecl *RD,
+   VTableAuthMode authMode) {
   Address VTablePtrSrc = This.withElementType(VTableTy);
   llvm::Instruction *VTable = Builder.CreateLoad(VTablePtrSrc, "vtable");
   TBAAAccessInfo TBAAInfo = CGM.getTBAAVTablePtrAccessInfo(VTableTy);
   CGM.DecorateInstructionWithTBAA(VTable, TBAAInfo);
 
+  if (auto authenticationInfo =
+CGM.getVTablePointerAuthInfo(this, RD, 
This.emitRawPointer(*this))) {
+if (authMode != VTableAuthMode::UnsafeUbsanStrip) {
+  VTable = cast(
+  EmitPointerAuthAuth(*authenticationInfo, VTable));
+  if (authMode == VTableAuthMode::MustTrap) {

asl wrote:

```suggestion
  if (AuthMode == VTableAuthMode::MustTrap) {
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2681,12 +2687,35 @@ void CodeGenFunction::InitializeVTablePointers(const 
CXXRecordDecl *RD) {
 
 llvm::Value *CodeGenFunction::GetVTablePtr(Address This,
llvm::Type *VTableTy,
-   const CXXRecordDecl *RD) {
+   const CXXRecordDecl *RD,
+   VTableAuthMode authMode) {
   Address VTablePtrSrc = This.withElementType(VTableTy);
   llvm::Instruction *VTable = Builder.CreateLoad(VTablePtrSrc, "vtable");
   TBAAAccessInfo TBAAInfo = CGM.getTBAAVTablePtrAccessInfo(VTableTy);
   CGM.DecorateInstructionWithTBAA(VTable, TBAAInfo);
 
+  if (auto authenticationInfo =
+CGM.getVTablePointerAuthInfo(this, RD, 
This.emitRawPointer(*this))) {
+if (authMode != VTableAuthMode::UnsafeUbsanStrip) {
+  VTable = cast(
+  EmitPointerAuthAuth(*authenticationInfo, VTable));

asl wrote:

```suggestion
  EmitPointerAuthAuth(*AuthenticationInfo, VTable));
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2681,12 +2687,35 @@ void CodeGenFunction::InitializeVTablePointers(const 
CXXRecordDecl *RD) {
 
 llvm::Value *CodeGenFunction::GetVTablePtr(Address This,
llvm::Type *VTableTy,
-   const CXXRecordDecl *RD) {
+   const CXXRecordDecl *RD,
+   VTableAuthMode authMode) {
   Address VTablePtrSrc = This.withElementType(VTableTy);
   llvm::Instruction *VTable = Builder.CreateLoad(VTablePtrSrc, "vtable");
   TBAAAccessInfo TBAAInfo = CGM.getTBAAVTablePtrAccessInfo(VTableTy);
   CGM.DecorateInstructionWithTBAA(VTable, TBAAInfo);
 
+  if (auto authenticationInfo =
+CGM.getVTablePointerAuthInfo(this, RD, 
This.emitRawPointer(*this))) {
+if (authMode != VTableAuthMode::UnsafeUbsanStrip) {

asl wrote:

```suggestion
if (AuthMode != VTableAuthMode::UnsafeUbsanStrip) {
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2681,12 +2687,35 @@ void CodeGenFunction::InitializeVTablePointers(const 
CXXRecordDecl *RD) {
 
 llvm::Value *CodeGenFunction::GetVTablePtr(Address This,
llvm::Type *VTableTy,
-   const CXXRecordDecl *RD) {
+   const CXXRecordDecl *RD,
+   VTableAuthMode authMode) {

asl wrote:

```suggestion
   VTableAuthMode AuthMode) {
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2681,12 +2687,35 @@ void CodeGenFunction::InitializeVTablePointers(const 
CXXRecordDecl *RD) {
 
 llvm::Value *CodeGenFunction::GetVTablePtr(Address This,
llvm::Type *VTableTy,
-   const CXXRecordDecl *RD) {
+   const CXXRecordDecl *RD,
+   VTableAuthMode authMode) {
   Address VTablePtrSrc = This.withElementType(VTableTy);
   llvm::Instruction *VTable = Builder.CreateLoad(VTablePtrSrc, "vtable");
   TBAAAccessInfo TBAAInfo = CGM.getTBAAVTablePtrAccessInfo(VTableTy);
   CGM.DecorateInstructionWithTBAA(VTable, TBAAInfo);
 
+  if (auto authenticationInfo =

asl wrote:

```suggestion
  if (auto *AuthenticationInfo =
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2588,6 +2588,12 @@ void CodeGenFunction::InitializeVTablePointer(const VPtr 
) {
   // the same addr space. Note that this might not be LLVM address space 0.
   VTableField = VTableField.withElementType(PtrTy);
 
+  if (auto authenticationInfo = CGM.getVTablePointerAuthInfo(
+  this, Vptr.Base.getBase(), VTableField.emitRawPointer(*this))) {
+VTableAddressPoint =
+EmitPointerAuthSign(*authenticationInfo, VTableAddressPoint);

asl wrote:

```suggestion
EmitPointerAuthSign(*AuthenticationInfo, VTableAddressPoint);
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl edited https://github.com/llvm/llvm-project/pull/94056
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2588,6 +2588,12 @@ void CodeGenFunction::InitializeVTablePointer(const VPtr 
) {
   // the same addr space. Note that this might not be LLVM address space 0.
   VTableField = VTableField.withElementType(PtrTy);
 
+  if (auto authenticationInfo = CGM.getVTablePointerAuthInfo(

asl wrote:

```suggestion
  if (auto AuthenticationInfo = CGM.getVTablePointerAuthInfo(
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -3094,9 +3188,10 @@ void VFTableBuilder::AddMethods(BaseSubobject Base, 
unsigned BaseDepth,
 ReturnAdjustmentOffset.VirtualBase);
   }
 }
-
+auto thisType = (OverriddenMD ? OverriddenMD : 
MD)->getThisType().getTypePtr();
 AddMethod(FinalOverriderMD,
   ThunkInfo(ThisAdjustmentOffset, ReturnAdjustment,
+thisType,

asl wrote:

```suggestion
ThisType,
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -3094,9 +3188,10 @@ void VFTableBuilder::AddMethods(BaseSubobject Base, 
unsigned BaseDepth,
 ReturnAdjustmentOffset.VirtualBase);
   }
 }
-
+auto thisType = (OverriddenMD ? OverriddenMD : 
MD)->getThisType().getTypePtr();

asl wrote:

```suggestion
auto ThisType = (OverriddenMD ? OverriddenMD : 
MD)->getThisType().getTypePtr();
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl edited https://github.com/llvm/llvm-project/pull/94056
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -7064,21 +7119,29 @@ void ItaniumMangleContextImpl::mangleThunk(const 
CXXMethodDecl *MD,
  Thunk.Return.Virtual.Itanium.VBaseOffsetOffset);
 
   Mangler.mangleFunctionEncoding(MD);
+  if (!elideOverrideInfo) {
+mangleOverrideDiscrimination(Mangler, getASTContext(), Thunk);
+  }
 }
 
-void ItaniumMangleContextImpl::mangleCXXDtorThunk(
-const CXXDestructorDecl *DD, CXXDtorType Type,
-const ThisAdjustment , raw_ostream ) {
+void ItaniumMangleContextImpl::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
+  CXXDtorType Type,
+  const ThunkInfo ,
+  bool elideOverrideInfo,
+  raw_ostream ) {
   //   ::= T  
   //  # base is the nominal target function of thunk
   CXXNameMangler Mangler(*this, Out, DD, Type);
   Mangler.getStream() << "_ZT";
 
+  auto  = Thunk.This;
   // Mangle the 'this' pointer adjustment.
   Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
 
   Mangler.mangleFunctionEncoding(GlobalDecl(DD, Type));
+  if (!elideOverrideInfo)

asl wrote:

update comment above with mangling scheme description?

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -7037,8 +7036,64 @@ void ItaniumMangleContextImpl::mangleCXXDtorComdat(const 
CXXDestructorDecl *D,
   Mangler.mangle(GlobalDecl(D, Dtor_Comdat));
 }
 
+static void mangleOverrideDiscrimination(CXXNameMangler ,
+ ASTContext ,
+ const ThunkInfo ) {
+  auto  = context.getLangOpts();
+  auto thisType = thunk.ThisType;
+  auto thisRecord = thisType->getPointeeCXXRecordDecl();
+  auto ptrauthClassRecord = context.baseForVTableAuthentication(thisRecord);
+  unsigned typedDiscriminator =
+  context.getPointerAuthVTablePointerDiscriminator(thisRecord);
+  mangler.mangleVendorQualifier("__vtptrauth");
+  auto  = mangler.getStream();
+  manglerStream << "I";
+  if (auto explicitAuth =
+  ptrauthClassRecord->getAttr()) {
+manglerStream << "Lj" << explicitAuth->getKey();

asl wrote:

Do we have mangling bits documented somewhere?

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -3088,6 +3089,17 @@ QualType ASTContext::removeAddrSpaceQualType(QualType T) 
const {
 return QualType(TypeNode, Quals.getFastQualifiers());
 }
 
+uint16_t ASTContext::getPointerAuthVTablePointerDiscriminator(
+const CXXRecordDecl *record) {
+  assert(record->isPolymorphic() &&
+ "Attempted to get vtable pointer discriminator on a monomorphic 
type");
+  std::unique_ptr MC(createMangleContext());
+  SmallString<256> Str;
+  llvm::raw_svector_ostream Out(Str);
+  MC->mangleCXXVTable(record, Out);
+  return llvm::getPointerAuthStableSipHash16(Str.c_str());

asl wrote:

```suggestion
  return llvm::getPointerAuthStableSipHash16(Str.str());
```

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -162,20 +162,27 @@ struct ThunkInfo {
 
   /// Holds a pointer to the overridden method this thunk is for,
   /// if needed by the ABI to distinguish different thunks with equal
-  /// adjustments. Otherwise, null.
+  /// adjustments.
+  /// In the Itanium ABI, this field can hold the method that created the
+  /// vtable entry for this thunk.
+  /// Otherwise, null.
   /// CAUTION: In the unlikely event you need to sort ThunkInfos, consider 
using
   /// an ABI-specific comparator.
   const CXXMethodDecl *Method;
+  const Type *ThisType { nullptr };
 
   ThunkInfo() : Method(nullptr) {}
 
   ThunkInfo(const ThisAdjustment , const ReturnAdjustment ,
+const Type *thisType,

asl wrote:

nit: consistent naming of parameters

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


[llvm-branch-commits] [clang] [llvm] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl edited https://github.com/llvm/llvm-project/pull/93903
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -47,6 +47,17 @@ void test_blend_discriminator(int *dp, int (*fp)(int), int 
value) {
   float *mismatch = __builtin_ptrauth_blend_discriminator(dp, value); // 
expected-error {{incompatible integer to pointer conversion initializing 'float 
*' with an expression of type}}
 }
 
+void test_string_discriminator(const char *str) {
+  __builtin_ptrauth_string_discriminator(); // expected-error {{too few 
arguments}}
+  __builtin_ptrauth_string_discriminator(str, str); // expected-error {{too 
many arguments}}
+  (void) __builtin_ptrauth_string_discriminator("test string"); // no warning

asl wrote:

Can we have `:"test string"` case here as well? As we're checking on the width 
of the literal character?

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


[llvm-branch-commits] [clang] [llvm] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits


@@ -15,6 +15,29 @@ typedef enum {
   ptrauth_key_asib = 1,
   ptrauth_key_asda = 2,
   ptrauth_key_asdb = 3,
+
+#ifdef __APPLE__

asl wrote:

Looks like this is something from already merged commit. Worth rebasing?

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


[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits

asl wrote:

So, regarding big-endian things. Original siphash is always "little-endian" 
regardless of the host platform. On big endian hosts it essentially does byte 
swap in the end. We do not have it here, so we will end with different hashes 
on platforms with different endianness.

>From the pauth perspective this is not a problem, as we do not do 
>cross-platform hash calculation and further comparison. The hash output 
>(discriminator value) is always compiled on compiler side and left as-is.

So, we can either keep the present code as-is. Or we can just sprinkle few 
calls from `Endian.h` to do byteswap on BE platforms.

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


[llvm-branch-commits] [llvm] [Support] Add SipHash-based 16-bit ptrauth stable hash. (PR #93902)

2024-06-08 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl approved this pull request.


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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-07 Thread Anton Korobeynikov via llvm-branch-commits


@@ -1261,6 +1262,10 @@ class ASTContext : public RefCountedBase {
   /// space.
   QualType removeAddrSpaceQualType(QualType T) const;
 
+  /// Return the "other" type-specific discriminator for the given type.

asl wrote:

@ojhunt This looks much better, thanks!

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-07 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2126,14 +2219,16 @@ static ExprResult PointerAuthSignGenericData(Sema , 
CallExpr *Call) {
 }
 
 static ExprResult PointerAuthSignOrAuth(Sema , CallExpr *Call,
-PointerAuthOpKind OpKind) {
+PointerAuthOpKind OpKind,
+bool RequireConstant) {
   if (S.checkArgCount(Call, 3))
 return ExprError();
   if (checkPointerAuthEnabled(S, Call))
 return ExprError();
-  if (checkPointerAuthValue(S, Call->getArgs()[0], OpKind) ||
+  if (checkPointerAuthValue(S, Call->getArgs()[0], OpKind, RequireConstant) ||

asl wrote:

Yes, `checkAndConvertPointerAuthValue` looks better to me as otherwise it is 
not pretty clear there are side effects.

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl edited https://github.com/llvm/llvm-project/pull/93904
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2126,14 +2219,16 @@ static ExprResult PointerAuthSignGenericData(Sema , 
CallExpr *Call) {
 }
 
 static ExprResult PointerAuthSignOrAuth(Sema , CallExpr *Call,
-PointerAuthOpKind OpKind) {
+PointerAuthOpKind OpKind,
+bool RequireConstant) {
   if (S.checkArgCount(Call, 3))
 return ExprError();
   if (checkPointerAuthEnabled(S, Call))
 return ExprError();
-  if (checkPointerAuthValue(S, Call->getArgs()[0], OpKind) ||
+  if (checkPointerAuthValue(S, Call->getArgs()[0], OpKind, RequireConstant) ||

asl wrote:

Can we check code like `Call->getArgs()[N]` to `Call->getArg(N)` while here? 
Certainly not everywhere, but on changed lines?

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);
+  if (!literal || literal->getCharByteWidth() != 1) {
+S.Diag(arg->getExprLoc(), diag::err_ptrauth_string_not_literal)
+  << (literal ? 1 : 0)
+  << arg->getSourceRange();
+return ExprError();
+  }
+
+  return call;

asl wrote:

```suggestion
  return Call;
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);

asl wrote:

```suggestion
  const auto *Literal = dyn_cast(Arg);
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);
+  if (!literal || literal->getCharByteWidth() != 1) {

asl wrote:

```suggestion
  if (!Literal || Literal->getCharByteWidth() != 1) {
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();

asl wrote:

```suggestion
  if (checkPointerAuthEnabled(S, Call)) return ExprError();
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);
+  if (!literal || literal->getCharByteWidth() != 1) {
+S.Diag(arg->getExprLoc(), diag::err_ptrauth_string_not_literal)
+  << (literal ? 1 : 0)
+  << arg->getSourceRange();

asl wrote:

```suggestion
  << Arg->getSourceRange();
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);
+  if (!literal || literal->getCharByteWidth() != 1) {
+S.Diag(arg->getExprLoc(), diag::err_ptrauth_string_not_literal)
+  << (literal ? 1 : 0)

asl wrote:

```suggestion
  << (Literal ? 1 : 0)
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {

asl wrote:

```suggestion
static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *Call) {
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();

asl wrote:

```suggestion
  Expr *Arg = Call->getArg(0)->IgnoreParenImpCasts();
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl commented:

See mostly code style nits above

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl edited https://github.com/llvm/llvm-project/pull/93903
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s  
-o - | FileCheck %s

asl wrote:

@kovdan01 If you're having a RUN line locally, can you just suggest a change 
here?

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -1261,6 +1262,10 @@ class ASTContext : public RefCountedBase {
   /// space.
   QualType removeAddrSpaceQualType(QualType T) const;
 
+  /// Return the "other" type-specific discriminator for the given type.

asl wrote:

The comment here looks a bit misleading without knowing what function is doing. 
Could it be reformulated in some better way?

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


[llvm-branch-commits] [AArch64] Remove usage of PostRAScheduler (PR #92871)

2024-05-21 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl requested changes to this pull request.

Submit your PRs to `main` branch

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


Re: [llvm-branch-commits] [llvm-branch] r291816 - Creating release_40 branch off revision 291814

2017-01-13 Thread Anton Korobeynikov via llvm-branch-commits
Should appear after first commit.

On Thu, Jan 12, 2017 at 3:22 PM, Anton Korobeynikov
 wrote:
> Sure, will do.
>
> On Thu, Jan 12, 2017 at 3:13 PM, Hans Wennborg  wrote:
>> Hi Anton,
>>
>> On Thu, Jan 12, 2017 at 1:25 PM, Hans Wennborg via llvm-branch-commits
>>  wrote:
>>> Author: hans
>>> Date: Thu Jan 12 15:25:21 2017
>>> New Revision: 291816
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=291816=rev
>>> Log:
>>> Creating release_40 branch off revision 291814
>>>
>>> Added:
>>> llvm/branches/release_40/   (props changed)
>>>   - copied from r291814, llvm/trunk/
>>
>> Can you teach the git mirror about the new branch?
>>
>> Cheers,
>> Hans
>
>
>
> --
> With best regards, Anton Korobeynikov
> Department of Statistical Modelling, Saint Petersburg State University



-- 
With best regards, Anton Korobeynikov
Department of Statistical Modelling, Saint Petersburg State University
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


Re: [llvm-branch-commits] [llvm-branch] r291816 - Creating release_40 branch off revision 291814

2017-01-12 Thread Anton Korobeynikov via llvm-branch-commits
Sure, will do.

On Thu, Jan 12, 2017 at 3:13 PM, Hans Wennborg  wrote:
> Hi Anton,
>
> On Thu, Jan 12, 2017 at 1:25 PM, Hans Wennborg via llvm-branch-commits
>  wrote:
>> Author: hans
>> Date: Thu Jan 12 15:25:21 2017
>> New Revision: 291816
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=291816=rev
>> Log:
>> Creating release_40 branch off revision 291814
>>
>> Added:
>> llvm/branches/release_40/   (props changed)
>>   - copied from r291814, llvm/trunk/
>
> Can you teach the git mirror about the new branch?
>
> Cheers,
> Hans



-- 
With best regards, Anton Korobeynikov
Department of Statistical Modelling, Saint Petersburg State University
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


Re: [llvm-branch-commits] [llvm-branch] r275828 - Creating release_39 branch off revision 275826

2016-08-11 Thread Anton Korobeynikov via llvm-branch-commits
Should be there - I kicked the updates for all the repos.

Note that in general the branches will be created with the first
commit to trunk after the branch point.

On Mon, Jul 18, 2016 at 9:32 PM, Anton Korobeynikov
 wrote:
> Yep, doing this right now :)
>
> On Mon, Jul 18, 2016 at 9:29 PM, Hans Wennborg  wrote:
>> Hi Anton,
>>
>> On Mon, Jul 18, 2016 at 10:52 AM, Hans Wennborg via
>> llvm-branch-commits  wrote:
>>> Author: hans
>>> Date: Mon Jul 18 12:52:41 2016
>>> New Revision: 275828
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=275828=rev
>>> Log:
>>> Creating release_39 branch off revision 275826
>>>
>>> Added:
>>> llvm/branches/release_39/   (props changed)
>>>   - copied from r275826, llvm/trunk/
>>
>> Can you make this 3.9 branch appear on the git mirror?
>>
>> Cheers,
>> Hans
>
>
>
> --
> With best regards, Anton Korobeynikov
> Department of Statistical Modelling, Saint Petersburg State University



-- 
With best regards, Anton Korobeynikov
Department of Statistical Modelling, Saint Petersburg State University
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits