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 ;
@@ -174,7 +178,7 @@ MachineBasicBlock &llvm::AArch64PAuth::checkAuthenticatedRegister(
174
178
return MBB;
175
179
case AuthCheckMethod::DummyLoad:
176
180
BuildMI (MBB, MBBI, DL, TII->get (AArch64::LDRWui), getWRegFromXReg (TmpReg))
177
- .addReg (AArch64::LR )
181
+ .addReg (AuthenticatedReg )
178
182
.addImm (0 )
179
183
.addMemOperand (createCheckMemOperand (MF, Subtarget));
180
184
return MBB;
@@ -250,6 +254,10 @@ unsigned llvm::AArch64PAuth::getCheckerSizeInBytes(AuthCheckMethod Method) {
250
254
251
255
bool AArch64PointerAuth::checkAuthenticatedLR (
252
256
MachineBasicBlock::iterator TI) const {
257
+ const AArch64FunctionInfo *MFnI = TI->getMF ()->getInfo <AArch64FunctionInfo>();
258
+ AArch64PACKey::ID KeyId =
259
+ MFnI->shouldSignWithBKey () ? AArch64PACKey::IB : AArch64PACKey::IA;
260
+
253
261
AuthCheckMethod Method = Subtarget->getAuthenticatedLRCheckMethod ();
254
262
255
263
if (Method == AuthCheckMethod::None)
@@ -290,7 +298,7 @@ bool AArch64PointerAuth::checkAuthenticatedLR(
290
298
" More than a single register is used by TCRETURN" );
291
299
292
300
checkAuthenticatedRegister (TI, Method, AArch64::LR, TmpReg, /* UseIKey=*/ true ,
293
- BrkOperand );
301
+ BrkOperandForKey (KeyId) );
294
302
295
303
return true ;
296
304
}
0 commit comments