@@ -23,42 +23,42 @@ using namespace CodeGen;
23
23
// / Given a pointer-authentication schema, return a concrete "other"
24
24
// / discriminator for it.
25
25
llvm::ConstantInt *CodeGenModule::getPointerAuthOtherDiscriminator (
26
- const PointerAuthSchema &schema , GlobalDecl decl , QualType type ) {
27
- switch (schema .getOtherDiscrimination ()) {
26
+ const PointerAuthSchema &Schema , GlobalDecl Decl , QualType Type ) {
27
+ switch (Schema .getOtherDiscrimination ()) {
28
28
case PointerAuthSchema::Discrimination::None:
29
29
return nullptr ;
30
30
31
31
case PointerAuthSchema::Discrimination::Type:
32
32
llvm_unreachable (" type discrimination not implemented yet" );
33
33
34
34
case PointerAuthSchema::Discrimination::Decl:
35
- assert (decl .getDecl () &&
35
+ assert (Decl .getDecl () &&
36
36
" declaration not provided for decl-discriminated schema" );
37
37
return llvm::ConstantInt::get (IntPtrTy,
38
- getPointerAuthDeclDiscriminator (decl ));
38
+ getPointerAuthDeclDiscriminator (Decl ));
39
39
40
40
case PointerAuthSchema::Discrimination::Constant:
41
- return llvm::ConstantInt::get (IntPtrTy, schema .getConstantDiscrimination ());
41
+ return llvm::ConstantInt::get (IntPtrTy, Schema .getConstantDiscrimination ());
42
42
}
43
43
llvm_unreachable (" bad discrimination kind" );
44
44
}
45
45
46
46
uint16_t CodeGen::getPointerAuthDeclDiscriminator (CodeGenModule &CGM,
47
- GlobalDecl declaration ) {
48
- return CGM.getPointerAuthDeclDiscriminator (declaration );
47
+ GlobalDecl Declaration ) {
48
+ return CGM.getPointerAuthDeclDiscriminator (Declaration );
49
49
}
50
50
51
51
// / Return the "other" decl-specific discriminator for the given decl.
52
52
uint16_t
53
- CodeGenModule::getPointerAuthDeclDiscriminator (GlobalDecl declaration ) {
54
- uint16_t &entityHash = PtrAuthDiscriminatorHashes[declaration ];
53
+ CodeGenModule::getPointerAuthDeclDiscriminator (GlobalDecl Declaration ) {
54
+ uint16_t &EntityHash = PtrAuthDiscriminatorHashes[Declaration ];
55
55
56
- if (entityHash == 0 ) {
57
- StringRef name = getMangledName (declaration );
58
- entityHash = llvm::getPointerAuthStableSipHash (name );
56
+ if (EntityHash == 0 ) {
57
+ StringRef Name = getMangledName (Declaration );
58
+ EntityHash = llvm::getPointerAuthStableSipHash (Name );
59
59
}
60
60
61
- return entityHash ;
61
+ return EntityHash ;
62
62
}
63
63
64
64
// / Return the abstract pointer authentication schema for a pointer to the given
@@ -80,38 +80,38 @@ CGPointerAuthInfo CodeGenModule::getFunctionPointerAuthInfo(QualType T) {
80
80
}
81
81
82
82
llvm::Value *
83
- CodeGenFunction::EmitPointerAuthBlendDiscriminator (llvm::Value *storageAddress ,
84
- llvm::Value *discriminator ) {
85
- storageAddress = Builder.CreatePtrToInt (storageAddress , IntPtrTy);
86
- auto intrinsic = CGM.getIntrinsic (llvm::Intrinsic::ptrauth_blend);
87
- return Builder.CreateCall (intrinsic , {storageAddress, discriminator });
83
+ CodeGenFunction::EmitPointerAuthBlendDiscriminator (llvm::Value *StorageAddress ,
84
+ llvm::Value *Discriminator ) {
85
+ StorageAddress = Builder.CreatePtrToInt (StorageAddress , IntPtrTy);
86
+ auto Intrinsic = CGM.getIntrinsic (llvm::Intrinsic::ptrauth_blend);
87
+ return Builder.CreateCall (Intrinsic , {StorageAddress, Discriminator });
88
88
}
89
89
90
90
// / Emit the concrete pointer authentication informaton for the
91
91
// / given authentication schema.
92
92
CGPointerAuthInfo CodeGenFunction::EmitPointerAuthInfo (
93
- const PointerAuthSchema &schema , llvm::Value *storageAddress ,
94
- GlobalDecl schemaDecl , QualType schemaType ) {
95
- if (!schema )
93
+ const PointerAuthSchema &Schema , llvm::Value *StorageAddress ,
94
+ GlobalDecl SchemaDecl , QualType SchemaType ) {
95
+ if (!Schema )
96
96
return CGPointerAuthInfo ();
97
97
98
- llvm::Value *discriminator =
99
- CGM.getPointerAuthOtherDiscriminator (schema, schemaDecl, schemaType );
98
+ llvm::Value *Discriminator =
99
+ CGM.getPointerAuthOtherDiscriminator (Schema, SchemaDecl, SchemaType );
100
100
101
- if (schema .isAddressDiscriminated ()) {
102
- assert (storageAddress &&
101
+ if (Schema .isAddressDiscriminated ()) {
102
+ assert (StorageAddress &&
103
103
" address not provided for address-discriminated schema" );
104
104
105
- if (discriminator )
106
- discriminator =
107
- EmitPointerAuthBlendDiscriminator (storageAddress, discriminator );
105
+ if (Discriminator )
106
+ Discriminator =
107
+ EmitPointerAuthBlendDiscriminator (StorageAddress, Discriminator );
108
108
else
109
- discriminator = Builder.CreatePtrToInt (storageAddress , IntPtrTy);
109
+ Discriminator = Builder.CreatePtrToInt (StorageAddress , IntPtrTy);
110
110
}
111
111
112
- return CGPointerAuthInfo (schema .getKey (), schema .getAuthenticationMode (),
113
- schema .isIsaPointer (),
114
- schema .authenticatesNullValues (), discriminator );
112
+ return CGPointerAuthInfo (Schema .getKey (), Schema .getAuthenticationMode (),
113
+ Schema .isIsaPointer (),
114
+ Schema .authenticatesNullValues (), Discriminator );
115
115
}
116
116
117
117
llvm::Constant *
@@ -140,55 +140,53 @@ CodeGenModule::getConstantSignedPointer(llvm::Constant *Pointer, unsigned Key,
140
140
}
141
141
142
142
// / Does a given PointerAuthScheme require us to sign a value
143
- static bool shouldSignPointer (const PointerAuthSchema &schema ) {
144
- auto authenticationMode = schema .getAuthenticationMode ();
145
- return authenticationMode == PointerAuthenticationMode::SignAndStrip ||
146
- authenticationMode == PointerAuthenticationMode::SignAndAuth;
143
+ static bool shouldSignPointer (const PointerAuthSchema &Schema ) {
144
+ auto AuthenticationMode = Schema .getAuthenticationMode ();
145
+ return AuthenticationMode == PointerAuthenticationMode::SignAndStrip ||
146
+ AuthenticationMode == PointerAuthenticationMode::SignAndAuth;
147
147
}
148
148
149
149
// / Sign a constant pointer using the given scheme, producing a constant
150
150
// / with the same IR type.
151
151
llvm::Constant *CodeGenModule::getConstantSignedPointer (
152
- llvm::Constant *pointer , const PointerAuthSchema &schema ,
153
- llvm::Constant *storageAddress , GlobalDecl schemaDecl ,
154
- QualType schemaType ) {
155
- assert (shouldSignPointer (schema ));
156
- llvm::ConstantInt *otherDiscriminator =
157
- getPointerAuthOtherDiscriminator (schema, schemaDecl, schemaType );
158
-
159
- return getConstantSignedPointer (pointer, schema .getKey (), storageAddress ,
160
- otherDiscriminator );
152
+ llvm::Constant *Pointer , const PointerAuthSchema &Schema ,
153
+ llvm::Constant *StorageAddress , GlobalDecl SchemaDecl ,
154
+ QualType SchemaType ) {
155
+ assert (shouldSignPointer (Schema ));
156
+ llvm::ConstantInt *OtherDiscriminator =
157
+ getPointerAuthOtherDiscriminator (Schema, SchemaDecl, SchemaType );
158
+
159
+ return getConstantSignedPointer (Pointer, Schema .getKey (), StorageAddress ,
160
+ OtherDiscriminator );
161
161
}
162
162
163
163
// / Sign the given pointer and add it to the constant initializer
164
164
// / currently being built.
165
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
-
176
- llvm::Constant *signedPointer = Builder.CGM .getConstantSignedPointer (
177
- pointer, schema, storageAddress, calleeDecl, calleeType);
178
- add (signedPointer);
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);
179
178
}
180
179
181
180
void ConstantAggregateBuilderBase::addSignedPointer (
182
- llvm::Constant *pointer, unsigned key, bool useAddressDiscrimination,
183
- llvm::ConstantInt *otherDiscriminator) {
184
- llvm::Constant *storageAddress = nullptr ;
185
- if (useAddressDiscrimination) {
186
- storageAddress = getAddrOfCurrentPosition (pointer->getType ());
187
- }
188
-
189
- llvm::Constant *signedPointer = Builder.CGM .getConstantSignedPointer (
190
- pointer, key, storageAddress, otherDiscriminator);
191
- add (signedPointer);
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);
192
190
}
193
191
194
192
// / If applicable, sign a given constant function pointer with the ABI rules for
@@ -215,111 +213,112 @@ llvm::Constant *CodeGenModule::getFunctionPointer(GlobalDecl GD,
215
213
}
216
214
217
215
std::optional<PointerAuthQualifier>
218
- CodeGenModule::computeVTPointerAuthentication (const CXXRecordDecl *thisClass ) {
219
- auto defaultAuthentication = getCodeGenOpts ().PointerAuth .CXXVTablePointers ;
220
- if (!defaultAuthentication )
216
+ CodeGenModule::computeVTPointerAuthentication (const CXXRecordDecl *ThisClass ) {
217
+ auto DefaultAuthentication = getCodeGenOpts ().PointerAuth .CXXVTablePointers ;
218
+ if (!DefaultAuthentication )
221
219
return std::nullopt;
222
- const CXXRecordDecl *primaryBase =
223
- Context.baseForVTableAuthentication (thisClass );
224
-
225
- unsigned key = defaultAuthentication .getKey ();
226
- bool addressDiscriminated = defaultAuthentication .isAddressDiscriminated ();
227
- auto defaultDiscrimination = defaultAuthentication .getOtherDiscrimination ();
228
- unsigned typeBasedDiscriminator =
229
- Context.getPointerAuthVTablePointerDiscriminator (primaryBase );
230
- unsigned discriminator ;
231
- if (defaultDiscrimination == PointerAuthSchema::Discrimination::Type) {
232
- discriminator = typeBasedDiscriminator ;
233
- } else if (defaultDiscrimination ==
220
+ const CXXRecordDecl *PrimaryBase =
221
+ Context.baseForVTableAuthentication (ThisClass );
222
+
223
+ unsigned Key = DefaultAuthentication .getKey ();
224
+ bool AddressDiscriminated = DefaultAuthentication .isAddressDiscriminated ();
225
+ auto DefaultDiscrimination = DefaultAuthentication .getOtherDiscrimination ();
226
+ unsigned TypeBasedDiscriminator =
227
+ Context.getPointerAuthVTablePointerDiscriminator (PrimaryBase );
228
+ unsigned Discriminator ;
229
+ if (DefaultDiscrimination == PointerAuthSchema::Discrimination::Type) {
230
+ Discriminator = TypeBasedDiscriminator ;
231
+ } else if (DefaultDiscrimination ==
234
232
PointerAuthSchema::Discrimination::Constant) {
235
- discriminator = defaultAuthentication .getConstantDiscrimination ();
233
+ Discriminator = DefaultAuthentication .getConstantDiscrimination ();
236
234
} else {
237
- assert (defaultDiscrimination == PointerAuthSchema::Discrimination::None);
238
- discriminator = 0 ;
235
+ assert (DefaultDiscrimination == PointerAuthSchema::Discrimination::None);
236
+ Discriminator = 0 ;
239
237
}
240
- if (auto explicitAuthentication =
241
- primaryBase ->getAttr <VTablePointerAuthenticationAttr>()) {
242
- auto explicitKey = explicitAuthentication ->getKey ();
243
- auto explicitAddressDiscrimination =
244
- explicitAuthentication ->getAddressDiscrimination ();
245
- auto explicitDiscriminator =
246
- explicitAuthentication ->getExtraDiscrimination ();
247
- if (explicitKey == VTablePointerAuthenticationAttr::NoKey) {
238
+ if (auto ExplicitAuthentication =
239
+ PrimaryBase ->getAttr <VTablePointerAuthenticationAttr>()) {
240
+ auto ExplicitKey = ExplicitAuthentication ->getKey ();
241
+ auto ExplicitAddressDiscrimination =
242
+ ExplicitAuthentication ->getAddressDiscrimination ();
243
+ auto ExplicitDiscriminator =
244
+ ExplicitAuthentication ->getExtraDiscrimination ();
245
+ if (ExplicitKey == VTablePointerAuthenticationAttr::NoKey) {
248
246
return std::nullopt;
249
247
}
250
- if (explicitKey != VTablePointerAuthenticationAttr::DefaultKey) {
251
- if (explicitKey == VTablePointerAuthenticationAttr::ProcessIndependent)
252
- key = (unsigned )PointerAuthSchema::ARM8_3Key::ASDA;
248
+ if (ExplicitKey != VTablePointerAuthenticationAttr::DefaultKey) {
249
+ if (ExplicitKey == VTablePointerAuthenticationAttr::ProcessIndependent)
250
+ Key = (unsigned )PointerAuthSchema::ARM8_3Key::ASDA;
253
251
else {
254
- assert (explicitKey ==
252
+ assert (ExplicitKey ==
255
253
VTablePointerAuthenticationAttr::ProcessDependent);
256
- key = (unsigned )PointerAuthSchema::ARM8_3Key::ASDB;
254
+ Key = (unsigned )PointerAuthSchema::ARM8_3Key::ASDB;
257
255
}
258
256
}
259
257
260
- if (explicitAddressDiscrimination !=
258
+ if (ExplicitAddressDiscrimination !=
261
259
VTablePointerAuthenticationAttr::DefaultAddressDiscrimination) {
262
- addressDiscriminated =
263
- explicitAddressDiscrimination ==
260
+ AddressDiscriminated =
261
+ ExplicitAddressDiscrimination ==
264
262
VTablePointerAuthenticationAttr::AddressDiscrimination;
265
263
}
266
264
267
- if (explicitDiscriminator ==
265
+ if (ExplicitDiscriminator ==
268
266
VTablePointerAuthenticationAttr::TypeDiscrimination) {
269
- discriminator = typeBasedDiscriminator ;
270
- } else if (explicitDiscriminator ==
267
+ Discriminator = TypeBasedDiscriminator ;
268
+ } else if (ExplicitDiscriminator ==
271
269
VTablePointerAuthenticationAttr::CustomDiscrimination) {
272
- discriminator = explicitAuthentication->getCustomDiscriminationValue ();
273
- } else if (explicitDiscriminator == VTablePointerAuthenticationAttr::NoExtraDiscrimination) {
274
- discriminator = 0 ;
270
+ Discriminator = ExplicitAuthentication->getCustomDiscriminationValue ();
271
+ } else if (ExplicitDiscriminator ==
272
+ VTablePointerAuthenticationAttr::NoExtraDiscrimination) {
273
+ Discriminator = 0 ;
275
274
}
276
275
}
277
- return PointerAuthQualifier::Create (key, addressDiscriminated, discriminator ,
276
+ return PointerAuthQualifier::Create (Key, AddressDiscriminated, Discriminator ,
278
277
PointerAuthenticationMode::SignAndAuth,
279
- /* isIsaPointer */ false ,
280
- /* authenticatesNullValues */ false );
278
+ /* IsIsaPointer */ false ,
279
+ /* AuthenticatesNullValues */ false );
281
280
}
282
281
283
282
std::optional<PointerAuthQualifier>
284
- CodeGenModule::getVTablePointerAuthentication (const CXXRecordDecl *record ) {
285
- if (!record ->getDefinition () || !record ->isPolymorphic ())
283
+ CodeGenModule::getVTablePointerAuthentication (const CXXRecordDecl *Record ) {
284
+ if (!Record ->getDefinition () || !Record ->isPolymorphic ())
286
285
return std::nullopt;
287
286
288
- auto existing = VTablePtrAuthInfos.find (record );
289
- std::optional<PointerAuthQualifier> authentication ;
290
- if (existing != VTablePtrAuthInfos.end ()) {
291
- authentication = existing ->getSecond ();
287
+ auto Existing = VTablePtrAuthInfos.find (Record );
288
+ std::optional<PointerAuthQualifier> Authentication ;
289
+ if (Existing != VTablePtrAuthInfos.end ()) {
290
+ Authentication = Existing ->getSecond ();
292
291
} else {
293
- authentication = computeVTPointerAuthentication (record );
294
- VTablePtrAuthInfos.insert (std::make_pair (record, authentication ));
292
+ Authentication = computeVTPointerAuthentication (Record );
293
+ VTablePtrAuthInfos.insert (std::make_pair (Record, Authentication ));
295
294
}
296
- return authentication ;
295
+ return Authentication ;
297
296
}
298
297
299
298
std::optional<CGPointerAuthInfo>
300
299
CodeGenModule::getVTablePointerAuthInfo (CodeGenFunction *CGF,
301
- const CXXRecordDecl *record ,
302
- llvm::Value *storageAddress ) {
303
- auto authentication = getVTablePointerAuthentication (record );
304
- if (!authentication )
300
+ const CXXRecordDecl *Record ,
301
+ llvm::Value *StorageAddress ) {
302
+ auto Authentication = getVTablePointerAuthentication (Record );
303
+ if (!Authentication )
305
304
return std::nullopt;
306
305
307
- llvm::Value *discriminator = nullptr ;
308
- if (auto extraDiscriminator = authentication ->getExtraDiscriminator ()) {
309
- discriminator = llvm::ConstantInt::get (IntPtrTy, extraDiscriminator );
306
+ llvm::Value *Discriminator = nullptr ;
307
+ if (auto ExtraDiscriminator = Authentication ->getExtraDiscriminator ()) {
308
+ Discriminator = llvm::ConstantInt::get (IntPtrTy, ExtraDiscriminator );
310
309
}
311
- if (authentication ->isAddressDiscriminated ()) {
312
- assert (storageAddress &&
310
+ if (Authentication ->isAddressDiscriminated ()) {
311
+ assert (StorageAddress &&
313
312
" address not provided for address-discriminated schema" );
314
- if (discriminator )
315
- discriminator =
316
- CGF->EmitPointerAuthBlendDiscriminator (storageAddress, discriminator );
313
+ if (Discriminator )
314
+ Discriminator =
315
+ CGF->EmitPointerAuthBlendDiscriminator (StorageAddress, Discriminator );
317
316
else
318
- discriminator = CGF->Builder .CreatePtrToInt (storageAddress , IntPtrTy);
317
+ Discriminator = CGF->Builder .CreatePtrToInt (StorageAddress , IntPtrTy);
319
318
}
320
319
321
- return CGPointerAuthInfo (authentication ->getKey (),
320
+ return CGPointerAuthInfo (Authentication ->getKey (),
322
321
PointerAuthenticationMode::SignAndAuth,
323
322
/* IsIsaPointer */ false ,
324
- /* authenticatesNullValues */ false , discriminator );
323
+ /* AuthenticatesNullValues */ false , Discriminator );
325
324
}
0 commit comments