12
12
#include " AArch64InstrInfo.h"
13
13
#include " AArch64MachineFunctionInfo.h"
14
14
#include " AArch64Subtarget.h"
15
+ #include " Utils/AArch64BaseInfo.h"
15
16
#include " llvm/CodeGen/MachineBasicBlock.h"
16
17
#include " llvm/CodeGen/MachineInstrBuilder.h"
17
18
#include " llvm/CodeGen/MachineModuleInfo.h"
@@ -35,7 +36,10 @@ class AArch64PointerAuth : public MachineFunctionPass {
35
36
36
37
private:
37
38
// / An immediate operand passed to BRK instruction, if it is ever emitted.
38
- const unsigned BrkOperand = 0xc471 ;
39
+ static unsigned BrkOperandForKey (AArch64PACKey::ID KeyId) {
40
+ const unsigned BrkOperandBase = 0xc470 ;
41
+ return BrkOperandBase + KeyId;
42
+ }
39
43
40
44
const AArch64Subtarget *Subtarget = nullptr ;
41
45
const AArch64InstrInfo *TII = nullptr ;
@@ -238,7 +242,7 @@ MachineBasicBlock &llvm::AArch64PAuth::checkAuthenticatedRegister(
238
242
return MBB;
239
243
case AuthCheckMethod::DummyLoad:
240
244
BuildMI (MBB, MBBI, DL, TII->get (AArch64::LDRWui), getWRegFromXReg (TmpReg))
241
- .addReg (AArch64::LR )
245
+ .addReg (AuthenticatedReg )
242
246
.addImm (0 )
243
247
.addMemOperand (createCheckMemOperand (MF, Subtarget));
244
248
return MBB;
@@ -314,6 +318,10 @@ unsigned llvm::AArch64PAuth::getCheckerSizeInBytes(AuthCheckMethod Method) {
314
318
315
319
bool AArch64PointerAuth::checkAuthenticatedLR (
316
320
MachineBasicBlock::iterator TI) const {
321
+ const AArch64FunctionInfo *MFnI = TI->getMF ()->getInfo <AArch64FunctionInfo>();
322
+ AArch64PACKey::ID KeyId =
323
+ MFnI->shouldSignWithBKey () ? AArch64PACKey::IB : AArch64PACKey::IA;
324
+
317
325
AuthCheckMethod Method = Subtarget->getAuthenticatedLRCheckMethod ();
318
326
319
327
if (Method == AuthCheckMethod::None)
@@ -354,7 +362,7 @@ bool AArch64PointerAuth::checkAuthenticatedLR(
354
362
" More than a single register is used by TCRETURN" );
355
363
356
364
checkAuthenticatedRegister (TI, Method, AArch64::LR, TmpReg, /* UseIKey=*/ true ,
357
- BrkOperand );
365
+ BrkOperandForKey (KeyId) );
358
366
359
367
return true ;
360
368
}
0 commit comments