1212#include " AArch64InstrInfo.h"
1313#include " AArch64MachineFunctionInfo.h"
1414#include " AArch64Subtarget.h"
15+ #include " Utils/AArch64BaseInfo.h"
1516#include " llvm/CodeGen/MachineBasicBlock.h"
1617#include " llvm/CodeGen/MachineInstrBuilder.h"
1718#include " llvm/CodeGen/MachineModuleInfo.h"
@@ -35,7 +36,10 @@ class AArch64PointerAuth : public MachineFunctionPass {
3536
3637private:
3738 // / 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+ }
3943
4044 const AArch64Subtarget *Subtarget = nullptr ;
4145 const AArch64InstrInfo *TII = nullptr ;
@@ -245,7 +249,7 @@ MachineBasicBlock &llvm::AArch64PAuth::checkAuthenticatedRegister(
245249 return MBB;
246250 case AuthCheckMethod::DummyLoad:
247251 BuildMI (MBB, MBBI, DL, TII->get (AArch64::LDRWui), getWRegFromXReg (TmpReg))
248- .addReg (AArch64::LR )
252+ .addReg (AuthenticatedReg )
249253 .addImm (0 )
250254 .addMemOperand (createCheckMemOperand (MF, Subtarget));
251255 return MBB;
@@ -321,6 +325,10 @@ unsigned llvm::AArch64PAuth::getCheckerSizeInBytes(AuthCheckMethod Method) {
321325
322326bool AArch64PointerAuth::checkAuthenticatedLR (
323327 MachineBasicBlock::iterator TI) const {
328+ const AArch64FunctionInfo *MFnI = TI->getMF ()->getInfo <AArch64FunctionInfo>();
329+ AArch64PACKey::ID KeyId =
330+ MFnI->shouldSignWithBKey () ? AArch64PACKey::IB : AArch64PACKey::IA;
331+
324332 AuthCheckMethod Method = Subtarget->getAuthenticatedLRCheckMethod ();
325333
326334 if (Method == AuthCheckMethod::None)
@@ -361,7 +369,7 @@ bool AArch64PointerAuth::checkAuthenticatedLR(
361369 " More than a single register is used by TCRETURN" );
362370
363371 checkAuthenticatedRegister (TI, Method, AArch64::LR, TmpReg, /* UseIKey=*/ true ,
364- BrkOperand );
372+ BrkOperandForKey (KeyId) );
365373
366374 return true ;
367375}
0 commit comments