22#define AARCH64_POINTER_AUTH_NAME "AArch64 Pointer Authentication"
47 Register AddrDisc,
unsigned IntDisc)
const;
61 return new AArch64PointerAuth();
64char AArch64PointerAuth::ID = 0;
96 if (MFnI.branchProtectionPAuthLR() && !Subtarget.hasPAuthLR())
114 unsigned CFIIndex = MF.addFrameInst(CFIInst);
124 bool EmitCFI = MFnI.needsDwarfUnwindInfo(MF);
139 if (MFnI.branchProtectionPAuthLR()) {
141 MFnI.setSigningInstrLabel(PACSym);
146 if (MFnI.branchProtectionPAuthLR() && Subtarget->hasPAuthLR()) {
148 TII->get(MFnI.shouldSignWithBKey() ? AArch64::PACIBSPPC
149 : AArch64::PACIASPPC))
156 TII->get(MFnI.shouldSignWithBKey() ? AArch64::PACIBSP
163 if (!EmitCFI && NeedsWinCFI) {
169void AArch64PointerAuth::authenticateLR(
190 bool TerminatorIsCombinable =
191 TI !=
MBB.
end() && TI->getOpcode() == AArch64::RET;
194 if (Subtarget->hasPAuth() && TerminatorIsCombinable && !NeedsWinCFI &&
197 assert(PACSym &&
"No PAC instruction to refer to");
200 TII->get(UseBKey ? AArch64::RETABSPPCi : AArch64::RETAASPPCi))
206 BuildMI(
MBB, TI,
DL,
TII->get(UseBKey ? AArch64::RETAB : AArch64::RETAA))
213 assert(PACSym &&
"No PAC instruction to refer to");
216 TII->get(UseBKey ? AArch64::AUTIBSPPCi : AArch64::AUTIASPPCi))
224 TII->get(UseBKey ? AArch64::AUTIBSP : AArch64::AUTIASP))
239 case AuthCheckMethod::None:
241 case AuthCheckMethod::DummyLoad:
243 case AuthCheckMethod::HighBitsNoTBI:
245 case AuthCheckMethod::XPACHint:
246 case AuthCheckMethod::XPAC:
254 unsigned IntDisc)
const {
258 if (Result != AddrDisc)
270void AArch64PointerAuth::expandPAuthBlend(
274 unsigned IntDisc =
MBBI->getOperand(2).getImm();
275 emitBlend(
MBBI, ResultReg, AddrDisc, IntDisc);
280 TII = Subtarget->getInstrInfo();
286 for (
auto &
MBB : MF) {
287 for (
auto &
MI :
MBB) {
288 switch (
MI.getOpcode()) {
291 case AArch64::PAUTH_PROLOGUE:
292 case AArch64::PAUTH_EPILOGUE:
293 case AArch64::PAUTH_BLEND:
300 for (
auto It : PAuthPseudoInstrs) {
301 switch (It->getOpcode()) {
302 case AArch64::PAUTH_PROLOGUE:
305 case AArch64::PAUTH_EPILOGUE:
306 authenticateLR(MF, It);
308 case AArch64::PAUTH_BLEND:
309 expandPAuthBlend(It);
314 It->eraseFromParent();
#define AARCH64_POINTER_AUTH_NAME
static void emitPACCFI(const AArch64Subtarget &Subtarget, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, DebugLoc DL, MachineInstr::MIFlag Flags, bool EmitCFI)
static void BuildPACM(const AArch64Subtarget &Subtarget, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, DebugLoc DL, MachineInstr::MIFlag Flags, MCSymbol *PACSym=nullptr)
static void emitPACSymOffsetIntoX16(const TargetInstrInfo &TII, MachineBasicBlock &MBB, MachineBasicBlock::iterator I, DebugLoc DL, MCSymbol *PACSym)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
bool branchProtectionPAuthLR() const
bool needsAsyncDwarfUnwindInfo(const MachineFunction &MF) const
MCSymbol * getSigningInstrLabel() const
bool shouldSignWithBKey() const
const AArch64InstrInfo * getInstrInfo() const override
FunctionPass class - This class is used to implement most global optimizations.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
static MCCFIInstruction createNegateRAStateWithPC(MCSymbol *L, SMLoc Loc={})
.cfi_negate_ra_state_with_pc AArch64 negate RA state with PC.
static MCCFIInstruction createNegateRAState(MCSymbol *L, SMLoc Loc={})
.cfi_negate_ra_state AArch64 negate RA state.
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
instr_iterator getFirstInstrTerminator()
Same getFirstTerminator but it ignores bundles and return an instr_iterator instead.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MCContext & getContext() const
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
void setPreInstrSymbol(MachineFunction &MF, MCSymbol *Symbol)
Set a symbol that will be emitted just prior to the instruction itself.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ MO_NC
MO_NC - Indicates whether the linker is expected to check the symbol reference for overflow.
@ MO_PAGEOFF
MO_PAGEOFF - A symbol operand with this flag represents the offset of that symbol within a 4K page.
@ MO_PAGE
MO_PAGE - A symbol operand with this flag represents the pc-relative offset of the 4K page containing...
unsigned getCheckerSizeInBytes(AuthCheckMethod Method)
Returns the number of bytes added by checkAuthenticatedRegister.
AuthCheckMethod
Variants of check performed on an authenticated pointer.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass * createAArch64PointerAuthPass()