Skip to content

Commit 8a298e1

Browse files
committed
[AArch64][PAC] Lower ptrauth constants in code for MachO.
1 parent aa7b282 commit 8a298e1

File tree

5 files changed

+484
-214
lines changed

5 files changed

+484
-214
lines changed

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,16 +1694,29 @@ void AArch64AsmPrinter::LowerLOADauthptrstatic(const MachineInstr &MI) {
16941694
//
16951695
// Where the $auth_ptr$ symbol is the stub slot containing the signed pointer
16961696
// to symbol.
1697-
assert(TM.getTargetTriple().isOSBinFormatELF() &&
1698-
"LOADauthptrstatic is implemented only for ELF");
1699-
const auto &TLOF =
1700-
static_cast<const AArch64_ELFTargetObjectFile &>(getObjFileLowering());
1701-
1702-
assert(GAOp.getOffset() == 0 &&
1703-
"non-zero offset for $auth_ptr$ stub slots is not supported");
1704-
const MCSymbol *GASym = TM.getSymbol(GAOp.getGlobal());
1705-
MCSymbol *AuthPtrStubSym =
1706-
TLOF.getAuthPtrSlotSymbol(TM, &MF->getMMI(), GASym, Key, Disc);
1697+
MCSymbol *AuthPtrStubSym;
1698+
if (TM.getTargetTriple().isOSBinFormatELF()) {
1699+
const auto &TLOF =
1700+
static_cast<const AArch64_ELFTargetObjectFile &>(getObjFileLowering());
1701+
1702+
assert(GAOp.getOffset() == 0 &&
1703+
"non-zero offset for $auth_ptr$ stub slots is not supported");
1704+
const MCSymbol *GASym = TM.getSymbol(GAOp.getGlobal());
1705+
AuthPtrStubSym =
1706+
TLOF.getAuthPtrSlotSymbol(TM, &MF->getMMI(), GASym, Key, Disc);
1707+
} else {
1708+
assert(TM.getTargetTriple().isOSBinFormatMachO() &&
1709+
"LOADauthptrstatic is implemented only for MachO/ELF");
1710+
1711+
const auto &TLOF = static_cast<const AArch64_MachoTargetObjectFile &>(
1712+
getObjFileLowering());
1713+
1714+
assert(GAOp.getOffset() == 0 &&
1715+
"non-zero offset for $auth_ptr$ stub slots is not supported");
1716+
const MCSymbol *GASym = TM.getSymbol(GAOp.getGlobal());
1717+
AuthPtrStubSym =
1718+
TLOF.getAuthPtrSlotSymbol(TM, &MF->getMMI(), GASym, Key, Disc);
1719+
}
17071720

17081721
MachineOperand StubMOHi =
17091722
MachineOperand::CreateMCSymbol(AuthPtrStubSym, AArch64II::MO_PAGE);

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9545,8 +9545,7 @@ SDValue AArch64TargetLowering::LowerGlobalTLSAddress(SDValue Op,
95459545
// Load a signed pointer for symbol 'sym' from a stub slot named
95469546
// 'sym$auth_ptr$key$disc' filled by dynamic linker during relocation
95479547
// resolving. This usually lowers to adrp+ldr, but also emits an entry into
9548-
// .data with an
9549-
// @AUTH relocation. See LowerLOADauthptrstatic.
9548+
// .data with an @AUTH relocation. See LowerLOADauthptrstatic.
95509549
//
95519550
// All 3 are pseudos that are expand late to longer sequences: this lets us
95529551
// provide integrity guarantees on the to-be-signed intermediate values.
@@ -9599,8 +9598,8 @@ AArch64TargetLowering::LowerPtrAuthGlobalAddress(SDValue Op,
95999598
"constant discriminator in ptrauth global out of range [0, 0xffff]");
96009599

96019600
// Choosing between 3 lowering alternatives is target-specific.
9602-
if (!Subtarget->isTargetELF())
9603-
report_fatal_error("ptrauth global lowering is only implemented for ELF");
9601+
if (!Subtarget->isTargetELF() && !Subtarget->isTargetMachO())
9602+
report_fatal_error("ptrauth global lowering only supported on MachO/ELF");
96049603

96059604
int64_t PtrOffsetC = 0;
96069605
if (Ptr.getOpcode() == ISD::ADD) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6636,8 +6636,8 @@ bool AArch64InstructionSelector::selectPtrAuthGlobalValue(
66366636
"constant discriminator in ptrauth global out of range [0, 0xffff]");
66376637

66386638
// Choosing between 3 lowering alternatives is target-specific.
6639-
if (!STI.isTargetELF())
6640-
report_fatal_error("ptrauth global lowering is only implemented for ELF");
6639+
if (!STI.isTargetELF() && !STI.isTargetMachO())
6640+
report_fatal_error("ptrauth global lowering only supported on MachO/ELF");
66416641

66426642
if (!MRI.hasOneDef(Addr))
66436643
return false;

0 commit comments

Comments
 (0)