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 ;
@@ -245,7 +249,7 @@ MachineBasicBlock &llvm::AArch64PAuth::checkAuthenticatedRegister(
245
249
return MBB;
246
250
case AuthCheckMethod::DummyLoad:
247
251
BuildMI (MBB, MBBI, DL, TII->get (AArch64::LDRWui), getWRegFromXReg (TmpReg))
248
- .addReg (AArch64::LR )
252
+ .addReg (AuthenticatedReg )
249
253
.addImm (0 )
250
254
.addMemOperand (createCheckMemOperand (MF, Subtarget));
251
255
return MBB;
@@ -321,6 +325,10 @@ unsigned llvm::AArch64PAuth::getCheckerSizeInBytes(AuthCheckMethod Method) {
321
325
322
326
bool AArch64PointerAuth::checkAuthenticatedLR (
323
327
MachineBasicBlock::iterator TI) const {
328
+ const AArch64FunctionInfo *MFnI = TI->getMF ()->getInfo <AArch64FunctionInfo>();
329
+ AArch64PACKey::ID KeyId =
330
+ MFnI->shouldSignWithBKey () ? AArch64PACKey::IB : AArch64PACKey::IA;
331
+
324
332
AuthCheckMethod Method = Subtarget->getAuthenticatedLRCheckMethod ();
325
333
326
334
if (Method == AuthCheckMethod::None)
@@ -361,7 +369,7 @@ bool AArch64PointerAuth::checkAuthenticatedLR(
361
369
" More than a single register is used by TCRETURN" );
362
370
363
371
checkAuthenticatedRegister (TI, Method, AArch64::LR, TmpReg, /* UseIKey=*/ true ,
364
- BrkOperand );
372
+ BrkOperandForKey (KeyId) );
365
373
366
374
return true ;
367
375
}
0 commit comments