Skip to content

Commit eb8a955

Browse files
committed
[AArch64] Add isAuthenticated predicate to MCInstDesc
Add a predicate to MCInstDesc that allows tools to determine whether an instruction authenticates a pointer. This can be used by diagnostic tools to hint at pointer authentication failures. Differential Revision: https://reviews.llvm.org/D70329 rdar://55089604 (cherry picked from commit a9052b4)
1 parent 4f65b63 commit eb8a955

File tree

9 files changed

+61
-6
lines changed

9 files changed

+61
-6
lines changed

llvm/include/llvm/MC/MCInstrDesc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ enum Flag {
168168
Add,
169169
Trap,
170170
VariadicOpsAreDefs,
171+
Authenticated,
171172
};
172173
}
173174

@@ -408,6 +409,15 @@ class MCInstrDesc {
408409
return Flags & (1ULL << MCID::VariadicOpsAreDefs);
409410
}
410411

412+
/// Return true if this instruction authenticates a pointer (e.g. LDRAx/BRAx
413+
/// from ARMv8.3, which perform loads/branches with authentication).
414+
///
415+
/// An authenticated instruction may fail in an ABI-defined manner when
416+
/// operating on an invalid signed pointer.
417+
bool isAuthenticated() const {
418+
return Flags & (1ULL << MCID::Authenticated);
419+
}
420+
411421
//===--------------------------------------------------------------------===//
412422
// Side Effect Analysis
413423
//===--------------------------------------------------------------------===//

llvm/include/llvm/Target/Target.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ class Instruction : InstructionEncoding {
530530
bit hasCtrlDep = 0; // Does this instruction r/w ctrl-flow chains?
531531
bit isNotDuplicable = 0; // Is it unsafe to duplicate this instruction?
532532
bit isConvergent = 0; // Is this instruction convergent?
533+
bit isAuthenticated = 0; // Does this instruction authenticate a pointer?
533534
bit isAsCheapAsAMove = 0; // As cheap (or cheaper) than a move instruction.
534535
bit hasExtraSrcRegAllocReq = 0; // Sources have special regalloc requirement?
535536
bit hasExtraDefRegAllocReq = 0; // Defs have special regalloc requirement?

llvm/lib/Target/AArch64/AArch64InstrFormats.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ class RCPCLoad<bits<2> sz, string asm, RegisterClass RC>
14901490
class AuthBase<bits<1> M, dag oops, dag iops, string asm, string operands,
14911491
list<dag> pattern>
14921492
: I<oops, iops, asm, operands, "", pattern>, Sched<[]> {
1493+
let isAuthenticated = 1;
14931494
let Inst{31-25} = 0b1101011;
14941495
let Inst{20-11} = 0b1111100001;
14951496
let Inst{10} = M;
@@ -1529,6 +1530,7 @@ class BaseAuthLoad<bit M, bit W, dag oops, dag iops, string asm,
15291530
bits<10> offset;
15301531
bits<5> Rn;
15311532
bits<5> Rt;
1533+
let isAuthenticated = 1;
15321534
let Inst{31-24} = 0b11111000;
15331535
let Inst{23} = M;
15341536
let Inst{22} = offset{9};

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -841,20 +841,26 @@ def AArch64authtcret: SDNode<"AArch64ISD::AUTH_TC_RETURN",
841841
let Uses = [LR], Defs = [LR] in {
842842
def PACIAZ : SystemNoOperands<0b000, "paciaz">;
843843
def PACIBZ : SystemNoOperands<0b010, "pacibz">;
844-
def AUTIAZ : SystemNoOperands<0b100, "autiaz">;
845-
def AUTIBZ : SystemNoOperands<0b110, "autibz">;
844+
let isAuthenticated = 1 in {
845+
def AUTIAZ : SystemNoOperands<0b100, "autiaz">;
846+
def AUTIBZ : SystemNoOperands<0b110, "autibz">;
847+
}
846848
}
847849
let Uses = [LR, SP], Defs = [LR] in {
848850
def PACIASP : SystemNoOperands<0b001, "paciasp">;
849851
def PACIBSP : SystemNoOperands<0b011, "pacibsp">;
850-
def AUTIASP : SystemNoOperands<0b101, "autiasp">;
851-
def AUTIBSP : SystemNoOperands<0b111, "autibsp">;
852+
let isAuthenticated = 1 in {
853+
def AUTIASP : SystemNoOperands<0b101, "autiasp">;
854+
def AUTIBSP : SystemNoOperands<0b111, "autibsp">;
855+
}
852856
}
853857
let Uses = [X16, X17], Defs = [X17], CRm = 0b0001 in {
854858
def PACIA1716 : SystemNoOperands<0b000, "pacia1716">;
855859
def PACIB1716 : SystemNoOperands<0b010, "pacib1716">;
856-
def AUTIA1716 : SystemNoOperands<0b100, "autia1716">;
857-
def AUTIB1716 : SystemNoOperands<0b110, "autib1716">;
860+
let isAuthenticated = 1 in {
861+
def AUTIA1716 : SystemNoOperands<0b100, "autia1716">;
862+
def AUTIB1716 : SystemNoOperands<0b110, "autib1716">;
863+
}
858864
}
859865

860866
let Uses = [LR], Defs = [LR], CRm = 0b0000 in {

llvm/unittests/Target/AArch64/InstSizes.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,38 @@ void runChecks(
7878

7979
} // anonymous namespace
8080

81+
TEST(InstSizes, Authenticated) {
82+
std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
83+
ASSERT_TRUE(TM);
84+
std::unique_ptr<AArch64InstrInfo> II = createInstrInfo(TM.get());
85+
86+
auto isAuthInst = [](AArch64InstrInfo &II, MachineFunction &MF) {
87+
auto I = MF.begin()->begin();
88+
EXPECT_EQ(4u, II.getInstSizeInBytes(*I));
89+
EXPECT_TRUE(I->getDesc().isAuthenticated());
90+
};
91+
92+
runChecks(TM.get(), II.get(), "",
93+
" \n"
94+
" BLRAA $x10, $x9\n",
95+
isAuthInst);
96+
97+
runChecks(TM.get(), II.get(), "",
98+
" \n"
99+
" RETAB implicit $lr, implicit $sp, implicit killed $x0\n",
100+
isAuthInst);
101+
102+
runChecks(TM.get(), II.get(), "",
103+
" \n"
104+
" frame-destroy AUTIASP implicit-def $lr, implicit killed $lr, implicit $sp\n",
105+
isAuthInst);
106+
107+
runChecks(TM.get(), II.get(), "",
108+
" \n"
109+
" frame-destroy AUTIBSP implicit-def $lr, implicit killed $lr, implicit $sp\n",
110+
isAuthInst);
111+
}
112+
81113
TEST(InstSizes, STACKMAP) {
82114
std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
83115
ASSERT_TRUE(TM);

llvm/utils/TableGen/CodeGenInstruction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ CodeGenInstruction::CodeGenInstruction(Record *R)
396396
hasNoSchedulingInfo = R->getValueAsBit("hasNoSchedulingInfo");
397397
FastISelShouldIgnore = R->getValueAsBit("FastISelShouldIgnore");
398398
variadicOpsAreDefs = R->getValueAsBit("variadicOpsAreDefs");
399+
isAuthenticated = R->getValueAsBit("isAuthenticated");
399400

400401
bool Unset;
401402
mayLoad = R->getValueAsBitOrUnset("mayLoad", Unset);

llvm/utils/TableGen/CodeGenInstruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ template <typename T> class ArrayRef;
278278
bool hasChain : 1;
279279
bool hasChain_Inferred : 1;
280280
bool variadicOpsAreDefs : 1;
281+
bool isAuthenticated : 1;
281282

282283
std::string DeprecatedReason;
283284
bool HasComplexDeprecationPredicate;

llvm/utils/TableGen/InstrDocsEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS) {
138138
FLAG(isConvergent)
139139
FLAG(hasNoSchedulingInfo)
140140
FLAG(variadicOpsAreDefs)
141+
FLAG(isAuthenticated)
141142
if (!FlagStrings.empty()) {
142143
OS << "Flags: ";
143144
bool IsFirst = true;

llvm/utils/TableGen/InstrInfoEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
703703
if (Inst.isInsertSubreg) OS << "|(1ULL<<MCID::InsertSubreg)";
704704
if (Inst.isConvergent) OS << "|(1ULL<<MCID::Convergent)";
705705
if (Inst.variadicOpsAreDefs) OS << "|(1ULL<<MCID::VariadicOpsAreDefs)";
706+
if (Inst.isAuthenticated) OS << "|(1ULL<<MCID::Authenticated)";
706707

707708
// Emit all of the target-specific flags...
708709
BitsInit *TSF = Inst.TheDef->getValueAsBitsInit("TSFlags");

0 commit comments

Comments
 (0)