Skip to content

Commit 72dff4c

Browse files
committed
Update following rebase.
- update ubsan vptr codegen/tests for hash/mixer change - adopt renamed siphash function; pass SmallString as StringRef - bring back removed getConstantSignedPointer declaration - move shouldSignPointer into CGM - remove unneeded addSignedPointer variant - move other addSignedPointer variant back to ConstantInitBuilder
1 parent 8dddcab commit 72dff4c

File tree

6 files changed

+33
-43
lines changed

6 files changed

+33
-43
lines changed

clang/include/clang/CodeGen/ConstantInitBuilder.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,9 @@ class ConstantAggregateBuilderBase {
203203
}
204204

205205
/// Add a signed pointer using the given pointer authentication schema.
206-
void addSignedPointer(llvm::Constant *pointer,
207-
const PointerAuthSchema &schema, GlobalDecl calleeDecl,
208-
QualType calleeType);
209-
210-
/// Add a signed pointer using the given pointer authentication schema.
211-
void addSignedPointer(llvm::Constant *pointer,
212-
unsigned key,
213-
bool useAddressDiscrimination,
214-
llvm::ConstantInt *otherDiscriminator);
206+
void addSignedPointer(llvm::Constant *Pointer,
207+
const PointerAuthSchema &Schema, GlobalDecl CalleeDecl,
208+
QualType CalleeType);
215209

216210
/// Add a null pointer of a specific type.
217211
void addNullPointer(llvm::PointerType *ptrTy) {

clang/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3112,7 +3112,7 @@ uint16_t ASTContext::getPointerAuthVTablePointerDiscriminator(
31123112
SmallString<256> Str;
31133113
llvm::raw_svector_ostream Out(Str);
31143114
MC->mangleCXXVTable(record, Out);
3115-
return llvm::getPointerAuthStableSipHash(Str.c_str());
3115+
return llvm::getPointerAuthStableSipHash(Str);
31163116
}
31173117

31183118
QualType ASTContext::getObjCGCQualType(QualType T,

clang/lib/CodeGen/CGPointerAuth.cpp

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ CodeGenModule::getConstantSignedPointer(llvm::Constant *Pointer, unsigned Key,
140140
}
141141

142142
/// Does a given PointerAuthScheme require us to sign a value
143-
static bool shouldSignPointer(const PointerAuthSchema &Schema) {
143+
bool CodeGenModule::shouldSignPointer(const PointerAuthSchema &Schema) {
144144
auto AuthenticationMode = Schema.getAuthenticationMode();
145145
return AuthenticationMode == PointerAuthenticationMode::SignAndStrip ||
146146
AuthenticationMode == PointerAuthenticationMode::SignAndAuth;
@@ -160,35 +160,6 @@ llvm::Constant *CodeGenModule::getConstantSignedPointer(
160160
OtherDiscriminator);
161161
}
162162

163-
/// Sign the given pointer and add it to the constant initializer
164-
/// currently being built.
165-
void ConstantAggregateBuilderBase::addSignedPointer(
166-
llvm::Constant *Pointer, const PointerAuthSchema &Schema,
167-
GlobalDecl CalleeDecl, QualType CalleeType) {
168-
if (!Schema || !shouldSignPointer(Schema))
169-
return add(Pointer);
170-
171-
llvm::Constant *StorageAddress = nullptr;
172-
if (Schema.isAddressDiscriminated())
173-
StorageAddress = getAddrOfCurrentPosition(Pointer->getType());
174-
175-
llvm::Constant *SignedPointer = Builder.CGM.getConstantSignedPointer(
176-
Pointer, Schema, StorageAddress, CalleeDecl, CalleeType);
177-
add(SignedPointer);
178-
}
179-
180-
void ConstantAggregateBuilderBase::addSignedPointer(
181-
llvm::Constant *Pointer, unsigned Key, bool UseAddressDiscrimination,
182-
llvm::ConstantInt *OtherDiscriminator) {
183-
llvm::Constant *StorageAddress = nullptr;
184-
if (UseAddressDiscrimination)
185-
StorageAddress = getAddrOfCurrentPosition(Pointer->getType());
186-
187-
llvm::Constant *SignedPointer = Builder.CGM.getConstantSignedPointer(
188-
Pointer, Key, StorageAddress, OtherDiscriminator);
189-
add(SignedPointer);
190-
}
191-
192163
/// If applicable, sign a given constant function pointer with the ABI rules for
193164
/// functionType.
194165
llvm::Constant *CodeGenModule::getFunctionPointer(llvm::Constant *Pointer,

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,13 @@ class CodeGenModule : public CodeGenTypeCache {
964964

965965
CGPointerAuthInfo getFunctionPointerAuthInfo(QualType T);
966966

967+
bool shouldSignPointer(const PointerAuthSchema &Schema);
968+
llvm::Constant *getConstantSignedPointer(llvm::Constant *Pointer,
969+
const PointerAuthSchema &Schema,
970+
llvm::Constant *StorageAddress,
971+
GlobalDecl SchemaDecl,
972+
QualType SchemaType);
973+
967974
llvm::Constant *
968975
getConstantSignedPointer(llvm::Constant *Pointer, unsigned Key,
969976
llvm::Constant *StorageAddress,

clang/lib/CodeGen/ConstantInitBuilder.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,21 @@ ConstantAggregateBuilderBase::finishStruct(llvm::StructType *ty) {
296296
buffer.erase(buffer.begin() + Begin, buffer.end());
297297
return constant;
298298
}
299+
300+
/// Sign the given pointer and add it to the constant initializer
301+
/// currently being built.
302+
void ConstantAggregateBuilderBase::addSignedPointer(
303+
llvm::Constant *Pointer, const PointerAuthSchema &Schema,
304+
GlobalDecl CalleeDecl, QualType CalleeType) {
305+
if (!Schema || !Builder.CGM.shouldSignPointer(Schema))
306+
return add(Pointer);
307+
308+
llvm::Constant *StorageAddress = nullptr;
309+
if (Schema.isAddressDiscriminated()) {
310+
StorageAddress = getAddrOfCurrentPosition(Pointer->getType());
311+
}
312+
313+
llvm::Constant *SignedPointer = Builder.CGM.getConstantSignedPointer(
314+
Pointer, Schema, StorageAddress, CalleeDecl, CalleeType);
315+
add(SignedPointer);
316+
}

clang/test/CodeGenCXX/ubsan-vtable-checks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int get_v(T* t) {
3333
// CHECK-PTRAUTH: [[STRIPPED_PTR:%.*]] = inttoptr i64 [[STRIPPED_VTABLE]] to ptr
3434
// CHECK-PTRAUTH: [[STRIPPED_INT:%.*]] = ptrtoint ptr [[STRIPPED_PTR]] to i64
3535
// Make sure authed vtable pointer feeds into hashing
36-
// CHECK-PTRAUTH: {{%.*}} = xor i64 {{.*}}, [[STRIPPED_INT]]
36+
// CHECK-PTRAUTH: {{%.*}} = mul i64 [[STRIPPED_INT]], {{.*}}
3737

3838
// Verify that we authenticate for the actual vcall
3939
// CHECK-PTRAUTH: [[BLENDED:%.*]] = call i64 @llvm.ptrauth.blend(i64 {{%.*}}, i64 17113)
@@ -59,7 +59,7 @@ void delete_it(T *t) {
5959
// CHECK-PTRAUTH: [[STRIPPED_VTABLE:%.*]] = call i64 @llvm.ptrauth.strip(i64 [[CAST_VTABLE]], i32 0)
6060
// CHECK-PTRAUTH: [[STRIPPED_PTR:%.*]] = inttoptr i64 [[STRIPPED_VTABLE]] to ptr
6161
// CHECK-PTRAUTH: [[STRIPPED_INT:%.*]] = ptrtoint ptr [[STRIPPED_PTR]] to i64
62-
// CHECK-PTRAUTH: {{%.*}} = xor i64 {{.*}}, [[STRIPPED_INT]]
62+
// CHECK-PTRAUTH: {{%.*}} = mul i64 [[STRIPPED_INT]], {{.*}}
6363
// CHECK-PTRAUTH: call void @__ubsan_handle_dynamic_type_cache_miss_abort(
6464
// Second, we check that vtable is actually loaded once the type check is done.
6565
// ptrauth for the virtual function load
@@ -85,7 +85,7 @@ U* dyncast(T *t) {
8585
// CHECK-PTRAUTH: [[STRIPPED_VTABLE:%.*]] = call i64 @llvm.ptrauth.strip(i64 [[CAST_VTABLE]], i32 0)
8686
// CHECK-PTRAUTH: [[STRIPPED_PTR:%.*]] = inttoptr i64 [[STRIPPED_VTABLE]] to ptr
8787
// CHECK-PTRAUTH: [[STRIPPED_INT:%.*]] = ptrtoint ptr [[STRIPPED_PTR]] to i64
88-
// CHECK-PTRAUTH: {{%.*}} = xor i64 {{.*}}, [[STRIPPED_INT]]
88+
// CHECK-PTRAUTH: {{%.*}} = mul i64 [[STRIPPED_INT]], {{.*}}
8989
// CHECK-VPTR: call void @__ubsan_handle_dynamic_type_cache_miss_abort
9090
// CHECK-PTRAUTH: [[BLENDED:%.*]] = call i64 @llvm.ptrauth.blend(i64 {{%.*}}, i64 17113)
9191
// CHECK-PTRAUTH: [[CAST_VTABLE:%.*]] = ptrtoint ptr %vtable1 to i64

0 commit comments

Comments
 (0)