Skip to content

Commit da083e3

Browse files
authored
[PAC][CodeGen][ELF][AArch64] Support signed GOT (#113811)
This re-applies #96164 after revert in #102434. Support the following relocations and assembly operators: - `R_AARCH64_AUTH_ADR_GOT_PAGE` (`:got_auth:` for `adrp`) - `R_AARCH64_AUTH_LD64_GOT_LO12_NC` (`:got_auth_lo12:` for `ldr`) - `R_AARCH64_AUTH_GOT_ADD_LO12_NC` (`:got_auth_lo12:` for `add`) `LOADgotAUTH` pseudo-instruction is introduced which is later expanded to actual instruction sequence like the following. ``` adrp x16, :got_auth:sym add x16, x16, :got_auth_lo12:sym ldr x0, [x16] autia x0, x16 ``` If a resign is requested, like below, `LOADgotPAC` pseudo is used, and GOT load is lowered similarly to `LOADgotAUTH`. ``` @var = global i32 0 define ptr @resign_globalvar() { ret ptr ptrauth (ptr @var, i32 3, i64 43) } ``` If FPAC bit is not set and auth instruction is emitted, a check+trap sequence similar to one used for `AUT` pseudo is emitted to ensure auth success. Both SelectionDAG and GlobalISel are suppported. For FastISel, we fall back to SelectionDAG. Tests starting with 'ptrauth-' have corresponding variants w/o this prefix. See also specification https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#appendix-signed-got
1 parent 2337990 commit da083e3

21 files changed

+777
-35
lines changed

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 143 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ class AArch64AsmPrinter : public AsmPrinter {
169169
// adrp-add followed by PAC sign)
170170
void LowerMOVaddrPAC(const MachineInstr &MI);
171171

172+
// Emit the sequence for LOADgotAUTH (load signed pointer from signed ELF GOT
173+
// and authenticate it with, if FPAC bit is not set, check+trap sequence after
174+
// authenticating)
175+
void LowerLOADgotAUTH(const MachineInstr &MI);
176+
172177
/// tblgen'erated driver function for lowering simple MI->MC
173178
/// pseudo instructions.
174179
bool lowerPseudoInstExpansion(const MachineInstr *MI, MCInst &Inst);
@@ -873,6 +878,22 @@ void AArch64AsmPrinter::emitEndOfAsmFile(Module &M) {
873878

874879
OutStreamer->addBlankLine();
875880
}
881+
882+
// With signed ELF GOT enabled, the linker looks at the symbol type to
883+
// choose between keys IA (for STT_FUNC) and DA (for other types). Symbols
884+
// for functions not defined in the module have STT_NOTYPE type by default.
885+
// This makes linker to emit signing schema with DA key (instead of IA) for
886+
// corresponding R_AARCH64_AUTH_GLOB_DAT dynamic reloc. To avoid that, force
887+
// all function symbols used in the module to have STT_FUNC type. See
888+
// https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#default-signing-schema
889+
const auto *PtrAuthELFGOTFlag = mdconst::extract_or_null<ConstantInt>(
890+
M.getModuleFlag("ptrauth-elf-got"));
891+
if (PtrAuthELFGOTFlag && PtrAuthELFGOTFlag->getZExtValue() == 1)
892+
for (const GlobalValue &GV : M.global_values())
893+
if (!GV.use_empty() && isa<Function>(GV) &&
894+
!GV.getName().starts_with("llvm."))
895+
OutStreamer->emitSymbolAttribute(getSymbol(&GV),
896+
MCSA_ELF_TypeFunction);
876897
}
877898

878899
// Emit stack and fault map information.
@@ -2068,6 +2089,10 @@ void AArch64AsmPrinter::LowerLOADauthptrstatic(const MachineInstr &MI) {
20682089

20692090
void AArch64AsmPrinter::LowerMOVaddrPAC(const MachineInstr &MI) {
20702091
const bool IsGOTLoad = MI.getOpcode() == AArch64::LOADgotPAC;
2092+
const bool IsELFSignedGOT = MI.getParent()
2093+
->getParent()
2094+
->getInfo<AArch64FunctionInfo>()
2095+
->hasELFSignedGOT();
20712096
MachineOperand GAOp = MI.getOperand(0);
20722097
const uint64_t KeyC = MI.getOperand(1).getImm();
20732098
assert(KeyC <= AArch64PACKey::LAST &&
@@ -2084,9 +2109,17 @@ void AArch64AsmPrinter::LowerMOVaddrPAC(const MachineInstr &MI) {
20842109
// Emit:
20852110
// target materialization:
20862111
// - via GOT:
2087-
// adrp x16, :got:target
2088-
// ldr x16, [x16, :got_lo12:target]
2089-
// add offset to x16 if offset != 0
2112+
// - unsigned GOT:
2113+
// adrp x16, :got:target
2114+
// ldr x16, [x16, :got_lo12:target]
2115+
// add offset to x16 if offset != 0
2116+
// - ELF signed GOT:
2117+
// adrp x17, :got:target
2118+
// add x17, x17, :got_auth_lo12:target
2119+
// ldr x16, [x17]
2120+
// aut{i|d}a x16, x17
2121+
// check+trap sequence (if no FPAC)
2122+
// add offset to x16 if offset != 0
20902123
//
20912124
// - direct:
20922125
// adrp x16, target
@@ -2129,13 +2162,48 @@ void AArch64AsmPrinter::LowerMOVaddrPAC(const MachineInstr &MI) {
21292162
MCInstLowering.lowerOperand(GAMOLo, GAMCLo);
21302163

21312164
EmitToStreamer(
2132-
MCInstBuilder(AArch64::ADRP).addReg(AArch64::X16).addOperand(GAMCHi));
2165+
MCInstBuilder(AArch64::ADRP)
2166+
.addReg(IsGOTLoad && IsELFSignedGOT ? AArch64::X17 : AArch64::X16)
2167+
.addOperand(GAMCHi));
21332168

21342169
if (IsGOTLoad) {
2135-
EmitToStreamer(MCInstBuilder(AArch64::LDRXui)
2136-
.addReg(AArch64::X16)
2137-
.addReg(AArch64::X16)
2138-
.addOperand(GAMCLo));
2170+
if (IsELFSignedGOT) {
2171+
EmitToStreamer(MCInstBuilder(AArch64::ADDXri)
2172+
.addReg(AArch64::X17)
2173+
.addReg(AArch64::X17)
2174+
.addOperand(GAMCLo)
2175+
.addImm(0));
2176+
2177+
EmitToStreamer(MCInstBuilder(AArch64::LDRXui)
2178+
.addReg(AArch64::X16)
2179+
.addReg(AArch64::X17)
2180+
.addImm(0));
2181+
2182+
assert(GAOp.isGlobal());
2183+
assert(GAOp.getGlobal()->getValueType() != nullptr);
2184+
unsigned AuthOpcode = GAOp.getGlobal()->getValueType()->isFunctionTy()
2185+
? AArch64::AUTIA
2186+
: AArch64::AUTDA;
2187+
2188+
EmitToStreamer(MCInstBuilder(AuthOpcode)
2189+
.addReg(AArch64::X16)
2190+
.addReg(AArch64::X16)
2191+
.addReg(AArch64::X17));
2192+
2193+
if (!STI->hasFPAC()) {
2194+
auto AuthKey = (AuthOpcode == AArch64::AUTIA ? AArch64PACKey::IA
2195+
: AArch64PACKey::DA);
2196+
2197+
emitPtrauthCheckAuthenticatedValue(AArch64::X16, AArch64::X17, AuthKey,
2198+
/*ShouldTrap=*/true,
2199+
/*OnFailure=*/nullptr);
2200+
}
2201+
} else {
2202+
EmitToStreamer(MCInstBuilder(AArch64::LDRXui)
2203+
.addReg(AArch64::X16)
2204+
.addReg(AArch64::X16)
2205+
.addOperand(GAMCLo));
2206+
}
21392207
} else {
21402208
EmitToStreamer(MCInstBuilder(AArch64::ADDXri)
21412209
.addReg(AArch64::X16)
@@ -2203,6 +2271,69 @@ void AArch64AsmPrinter::LowerMOVaddrPAC(const MachineInstr &MI) {
22032271
EmitToStreamer(MIB);
22042272
}
22052273

2274+
void AArch64AsmPrinter::LowerLOADgotAUTH(const MachineInstr &MI) {
2275+
Register DstReg = MI.getOperand(0).getReg();
2276+
Register AuthResultReg = STI->hasFPAC() ? DstReg : AArch64::X16;
2277+
const MachineOperand &GAMO = MI.getOperand(1);
2278+
assert(GAMO.getOffset() == 0);
2279+
2280+
MachineOperand GAHiOp(GAMO);
2281+
MachineOperand GALoOp(GAMO);
2282+
GAHiOp.addTargetFlag(AArch64II::MO_PAGE);
2283+
GALoOp.addTargetFlag(AArch64II::MO_PAGEOFF | AArch64II::MO_NC);
2284+
2285+
MCOperand GAMCHi, GAMCLo;
2286+
MCInstLowering.lowerOperand(GAHiOp, GAMCHi);
2287+
MCInstLowering.lowerOperand(GALoOp, GAMCLo);
2288+
2289+
EmitToStreamer(
2290+
MCInstBuilder(AArch64::ADRP).addReg(AArch64::X17).addOperand(GAMCHi));
2291+
2292+
EmitToStreamer(MCInstBuilder(AArch64::ADDXri)
2293+
.addReg(AArch64::X17)
2294+
.addReg(AArch64::X17)
2295+
.addOperand(GAMCLo)
2296+
.addImm(0));
2297+
2298+
EmitToStreamer(MCInstBuilder(AArch64::LDRXui)
2299+
.addReg(AuthResultReg)
2300+
.addReg(AArch64::X17)
2301+
.addImm(0));
2302+
2303+
assert(GAMO.isGlobal());
2304+
MCSymbol *UndefWeakSym;
2305+
if (GAMO.getGlobal()->hasExternalWeakLinkage()) {
2306+
UndefWeakSym = createTempSymbol("undef_weak");
2307+
EmitToStreamer(
2308+
MCInstBuilder(AArch64::CBZX)
2309+
.addReg(AuthResultReg)
2310+
.addExpr(MCSymbolRefExpr::create(UndefWeakSym, OutContext)));
2311+
}
2312+
2313+
assert(GAMO.getGlobal()->getValueType() != nullptr);
2314+
unsigned AuthOpcode = GAMO.getGlobal()->getValueType()->isFunctionTy()
2315+
? AArch64::AUTIA
2316+
: AArch64::AUTDA;
2317+
EmitToStreamer(MCInstBuilder(AuthOpcode)
2318+
.addReg(AuthResultReg)
2319+
.addReg(AuthResultReg)
2320+
.addReg(AArch64::X17));
2321+
2322+
if (GAMO.getGlobal()->hasExternalWeakLinkage())
2323+
OutStreamer->emitLabel(UndefWeakSym);
2324+
2325+
if (!STI->hasFPAC()) {
2326+
auto AuthKey =
2327+
(AuthOpcode == AArch64::AUTIA ? AArch64PACKey::IA : AArch64PACKey::DA);
2328+
2329+
emitPtrauthCheckAuthenticatedValue(AuthResultReg, AArch64::X17, AuthKey,
2330+
/*ShouldTrap=*/true,
2331+
/*OnFailure=*/nullptr);
2332+
2333+
emitMovXReg(DstReg, AuthResultReg);
2334+
}
2335+
}
2336+
22062337
const MCExpr *
22072338
AArch64AsmPrinter::lowerBlockAddressConstant(const BlockAddress &BA) {
22082339
const MCExpr *BAE = AsmPrinter::lowerBlockAddressConstant(BA);
@@ -2381,6 +2512,10 @@ void AArch64AsmPrinter::emitInstruction(const MachineInstr *MI) {
23812512
LowerMOVaddrPAC(*MI);
23822513
return;
23832514

2515+
case AArch64::LOADgotAUTH:
2516+
LowerLOADgotAUTH(*MI);
2517+
return;
2518+
23842519
case AArch64::BRA:
23852520
case AArch64::BLRA:
23862521
emitPtrauthBranch(MI);

llvm/lib/Target/AArch64/AArch64FastISel.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ unsigned AArch64FastISel::materializeGV(const GlobalValue *GV) {
454454
if (!Subtarget->useSmallAddressing() && !Subtarget->isTargetMachO())
455455
return 0;
456456

457+
if (FuncInfo.MF->getInfo<AArch64FunctionInfo>()->hasELFSignedGOT())
458+
return 0;
459+
457460
unsigned OpFlags = Subtarget->ClassifyGlobalReference(GV, TM);
458461

459462
EVT DestEVT = TLI.getValueType(DL, GV->getType(), true);

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9599,6 +9599,11 @@ SDValue AArch64TargetLowering::getGOT(NodeTy *N, SelectionDAG &DAG,
95999599
SDValue GotAddr = getTargetNode(N, Ty, DAG, AArch64II::MO_GOT | Flags);
96009600
// FIXME: Once remat is capable of dealing with instructions with register
96019601
// operands, expand this into two nodes instead of using a wrapper node.
9602+
if (DAG.getMachineFunction()
9603+
.getInfo<AArch64FunctionInfo>()
9604+
->hasELFSignedGOT())
9605+
return SDValue(DAG.getMachineNode(AArch64::LOADgotAUTH, DL, Ty, GotAddr),
9606+
0);
96029607
return DAG.getNode(AArch64ISD::LOADgot, DL, Ty, GotAddr);
96039608
}
96049609

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,8 +1942,15 @@ let Predicates = [HasPAuth] in {
19421942
Sched<[WriteI, ReadI]> {
19431943
let isReMaterializable = 1;
19441944
let isCodeGenOnly = 1;
1945-
let Size = 40; // 12 fixed + 28 variable, for pointer offset, and discriminator
1946-
let Defs = [X16,X17];
1945+
let Size = 68; // 12 fixed + 56 variable, for pointer offset, discriminator and
1946+
// ELF signed GOT signed pointer authentication (if no FPAC)
1947+
let Defs = [X16,X17,NZCV];
1948+
}
1949+
1950+
def LOADgotAUTH : Pseudo<(outs GPR64common:$dst), (ins i64imm:$addr), []>,
1951+
Sched<[WriteI, ReadI]> {
1952+
let Defs = [X16,X17,NZCV];
1953+
let Size = 44;
19471954
}
19481955

19491956
// Load a signed global address from a special $auth_ptr$ stub slot.

llvm/lib/Target/AArch64/AArch64MCInstLower.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "AArch64MCInstLower.h"
15+
#include "AArch64MachineFunctionInfo.h"
1516
#include "MCTargetDesc/AArch64MCExpr.h"
1617
#include "Utils/AArch64BaseInfo.h"
1718
#include "llvm/CodeGen/AsmPrinter.h"
@@ -185,9 +186,12 @@ MCOperand AArch64MCInstLower::lowerSymbolOperandELF(const MachineOperand &MO,
185186
MCSymbol *Sym) const {
186187
uint32_t RefFlags = 0;
187188

188-
if (MO.getTargetFlags() & AArch64II::MO_GOT)
189-
RefFlags |= AArch64MCExpr::VK_GOT;
190-
else if (MO.getTargetFlags() & AArch64II::MO_TLS) {
189+
if (MO.getTargetFlags() & AArch64II::MO_GOT) {
190+
const MachineFunction *MF = MO.getParent()->getParent()->getParent();
191+
RefFlags |= (MF->getInfo<AArch64FunctionInfo>()->hasELFSignedGOT()
192+
? AArch64MCExpr::VK_GOT_AUTH
193+
: AArch64MCExpr::VK_GOT);
194+
} else if (MO.getTargetFlags() & AArch64II::MO_TLS) {
191195
TLSModel::Model Model;
192196
if (MO.isGlobal()) {
193197
const GlobalValue *GV = MO.getGlobal();

llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ static bool ShouldSignWithBKey(const Function &F, const AArch64Subtarget &STI) {
7272
return Key == "b_key";
7373
}
7474

75+
static bool hasELFSignedGOTHelper(const Function &F,
76+
const AArch64Subtarget *STI) {
77+
if (!Triple(STI->getTargetTriple()).isOSBinFormatELF())
78+
return false;
79+
const Module *M = F.getParent();
80+
const auto *Flag = mdconst::extract_or_null<ConstantInt>(
81+
M->getModuleFlag("ptrauth-elf-got"));
82+
if (Flag && Flag->getZExtValue() == 1)
83+
return true;
84+
return false;
85+
}
86+
7587
AArch64FunctionInfo::AArch64FunctionInfo(const Function &F,
7688
const AArch64Subtarget *STI) {
7789
// If we already know that the function doesn't have a redzone, set
@@ -80,6 +92,7 @@ AArch64FunctionInfo::AArch64FunctionInfo(const Function &F,
8092
HasRedZone = false;
8193
std::tie(SignReturnAddress, SignReturnAddressAll) = GetSignReturnAddress(F);
8294
SignWithBKey = ShouldSignWithBKey(F, *STI);
95+
HasELFSignedGOT = hasELFSignedGOTHelper(F, STI);
8396
// TODO: skip functions that have no instrumented allocas for optimization
8497
IsMTETagged = F.hasFnAttribute(Attribute::SanitizeMemTag);
8598

llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
177177
/// SignWithBKey modifies the default PAC-RET mode to signing with the B key.
178178
bool SignWithBKey = false;
179179

180+
/// HasELFSignedGOT is true if the target binary format is ELF and the IR
181+
/// module containing the corresponding function has "ptrauth-elf-got" flag
182+
/// set to 1.
183+
bool HasELFSignedGOT = false;
184+
180185
/// SigningInstrOffset captures the offset of the PAC-RET signing instruction
181186
/// within the prologue, so it can be re-used for authentication in the
182187
/// epilogue when using PC as a second salt (FEAT_PAuth_LR)
@@ -509,6 +514,8 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
509514

510515
bool shouldSignWithBKey() const { return SignWithBKey; }
511516

517+
bool hasELFSignedGOT() const { return HasELFSignedGOT; }
518+
512519
MCSymbol *getSigningInstrLabel() const { return SignInstrLabel; }
513520
void setSigningInstrLabel(MCSymbol *Label) { SignInstrLabel = Label; }
514521

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ class AArch64Operand : public MCParsedAsmOperand {
897897
if (DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF ||
898898
ELFRefKind == AArch64MCExpr::VK_LO12 ||
899899
ELFRefKind == AArch64MCExpr::VK_GOT_LO12 ||
900+
ELFRefKind == AArch64MCExpr::VK_GOT_AUTH_LO12 ||
900901
ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12 ||
901902
ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12_NC ||
902903
ELFRefKind == AArch64MCExpr::VK_TPREL_LO12 ||
@@ -1008,19 +1009,20 @@ class AArch64Operand : public MCParsedAsmOperand {
10081009
int64_t Addend;
10091010
if (AArch64AsmParser::classifySymbolRef(Expr, ELFRefKind,
10101011
DarwinRefKind, Addend)) {
1011-
return DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF
1012-
|| DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGEOFF
1013-
|| (DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGEOFF && Addend == 0)
1014-
|| ELFRefKind == AArch64MCExpr::VK_LO12
1015-
|| ELFRefKind == AArch64MCExpr::VK_DTPREL_HI12
1016-
|| ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12
1017-
|| ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12_NC
1018-
|| ELFRefKind == AArch64MCExpr::VK_TPREL_HI12
1019-
|| ELFRefKind == AArch64MCExpr::VK_TPREL_LO12
1020-
|| ELFRefKind == AArch64MCExpr::VK_TPREL_LO12_NC
1021-
|| ELFRefKind == AArch64MCExpr::VK_TLSDESC_LO12
1022-
|| ELFRefKind == AArch64MCExpr::VK_SECREL_HI12
1023-
|| ELFRefKind == AArch64MCExpr::VK_SECREL_LO12;
1012+
return DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF ||
1013+
DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGEOFF ||
1014+
(DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGEOFF && Addend == 0) ||
1015+
ELFRefKind == AArch64MCExpr::VK_LO12 ||
1016+
ELFRefKind == AArch64MCExpr::VK_GOT_AUTH_LO12 ||
1017+
ELFRefKind == AArch64MCExpr::VK_DTPREL_HI12 ||
1018+
ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12 ||
1019+
ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12_NC ||
1020+
ELFRefKind == AArch64MCExpr::VK_TPREL_HI12 ||
1021+
ELFRefKind == AArch64MCExpr::VK_TPREL_LO12 ||
1022+
ELFRefKind == AArch64MCExpr::VK_TPREL_LO12_NC ||
1023+
ELFRefKind == AArch64MCExpr::VK_TLSDESC_LO12 ||
1024+
ELFRefKind == AArch64MCExpr::VK_SECREL_HI12 ||
1025+
ELFRefKind == AArch64MCExpr::VK_SECREL_LO12;
10241026
}
10251027

10261028
// If it's a constant, it should be a real immediate in range.
@@ -3309,6 +3311,7 @@ ParseStatus AArch64AsmParser::tryParseAdrpLabel(OperandVector &Operands) {
33093311
DarwinRefKind != MCSymbolRefExpr::VK_TLVPPAGE &&
33103312
ELFRefKind != AArch64MCExpr::VK_ABS_PAGE_NC &&
33113313
ELFRefKind != AArch64MCExpr::VK_GOT_PAGE &&
3314+
ELFRefKind != AArch64MCExpr::VK_GOT_AUTH_PAGE &&
33123315
ELFRefKind != AArch64MCExpr::VK_GOT_PAGE_LO15 &&
33133316
ELFRefKind != AArch64MCExpr::VK_GOTTPREL_PAGE &&
33143317
ELFRefKind != AArch64MCExpr::VK_TLSDESC_PAGE) {
@@ -4428,6 +4431,8 @@ bool AArch64AsmParser::parseSymbolicImmVal(const MCExpr *&ImmVal) {
44284431
.Case("got", AArch64MCExpr::VK_GOT_PAGE)
44294432
.Case("gotpage_lo15", AArch64MCExpr::VK_GOT_PAGE_LO15)
44304433
.Case("got_lo12", AArch64MCExpr::VK_GOT_LO12)
4434+
.Case("got_auth", AArch64MCExpr::VK_GOT_AUTH_PAGE)
4435+
.Case("got_auth_lo12", AArch64MCExpr::VK_GOT_AUTH_LO12)
44314436
.Case("gottprel", AArch64MCExpr::VK_GOTTPREL_PAGE)
44324437
.Case("gottprel_lo12", AArch64MCExpr::VK_GOTTPREL_LO12_NC)
44334438
.Case("gottprel_g1", AArch64MCExpr::VK_GOTTPREL_G1)
@@ -5801,6 +5806,7 @@ bool AArch64AsmParser::validateInstruction(MCInst &Inst, SMLoc &IDLoc,
58015806

58025807
// Only allow these with ADDXri/ADDWri
58035808
if ((ELFRefKind == AArch64MCExpr::VK_LO12 ||
5809+
ELFRefKind == AArch64MCExpr::VK_GOT_AUTH_LO12 ||
58045810
ELFRefKind == AArch64MCExpr::VK_DTPREL_HI12 ||
58055811
ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12 ||
58065812
ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12_NC ||

llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2967,7 +2967,9 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
29672967
}
29682968

29692969
if (OpFlags & AArch64II::MO_GOT) {
2970-
I.setDesc(TII.get(AArch64::LOADgot));
2970+
I.setDesc(TII.get(MF.getInfo<AArch64FunctionInfo>()->hasELFSignedGOT()
2971+
? AArch64::LOADgotAUTH
2972+
: AArch64::LOADgot));
29712973
I.getOperand(1).setTargetFlags(OpFlags);
29722974
} else if (TM.getCodeModel() == CodeModel::Large &&
29732975
!TM.isPositionIndependent()) {

0 commit comments

Comments
 (0)