1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.

This also teaches MachO writers/readers about the MachO cpu subtype,
beyond the minimal subtype reader support present at the moment.

This also defines a preprocessor macro to allow users to distinguish
__arm64__ from __arm64e__.

arm64e defaults to an "apple-a12" CPU, which supports v8.3a, allowing
pointer-authentication codegen.
It also currently defaults to ios14 and macos11.

Differential Revision: https://reviews.llvm.org/D87095
This commit is contained in:
Ahmed Bougacha 2020-09-03 08:43:21 -07:00
parent e737a423ce
commit fe6a3c2668
17 changed files with 146 additions and 9 deletions

View File

@ -129,6 +129,8 @@ public:
ARMSubArch_v5te, ARMSubArch_v5te,
ARMSubArch_v4t, ARMSubArch_v4t,
AArch64SubArch_arm64e,
KalimbaSubArch_v3, KalimbaSubArch_v3,
KalimbaSubArch_v4, KalimbaSubArch_v4,
KalimbaSubArch_v5, KalimbaSubArch_v5,
@ -777,6 +779,12 @@ public:
return getArch() == Triple::csky; return getArch() == Triple::csky;
} }
/// Tests whether the target is the Apple "arm64e" AArch64 subarch.
bool isArm64e() const {
return getArch() == Triple::aarch64 &&
getSubArch() == Triple::AArch64SubArch_arm64e;
}
/// Tests whether the target supports comdat /// Tests whether the target supports comdat
bool supportsCOMDAT() const { bool supportsCOMDAT() const {
return !(isOSBinFormatMachO() || isOSBinFormatXCOFF()); return !(isOSBinFormatMachO() || isOSBinFormatXCOFF());

View File

@ -58,7 +58,7 @@ static MachO::CPUSubTypeARM64 getARM64SubType(const Triple &T) {
assert(T.isAArch64()); assert(T.isAArch64());
if (T.isArch32Bit()) if (T.isArch32Bit())
return (MachO::CPUSubTypeARM64)MachO::CPU_SUBTYPE_ARM64_32_V8; return (MachO::CPUSubTypeARM64)MachO::CPU_SUBTYPE_ARM64_32_V8;
if (T.getArchName() == "arm64e") if (T.isArm64e())
return MachO::CPU_SUBTYPE_ARM64E; return MachO::CPU_SUBTYPE_ARM64E;
return MachO::CPU_SUBTYPE_ARM64_ALL; return MachO::CPU_SUBTYPE_ARM64_ALL;

View File

@ -377,6 +377,8 @@ bool LTOCodeGenerator::determineTarget() {
MCpu = "core2"; MCpu = "core2";
else if (Triple.getArch() == llvm::Triple::x86) else if (Triple.getArch() == llvm::Triple::x86)
MCpu = "yonah"; MCpu = "yonah";
else if (Triple.isArm64e())
MCpu = "apple-a12";
else if (Triple.getArch() == llvm::Triple::aarch64 || else if (Triple.getArch() == llvm::Triple::aarch64 ||
Triple.getArch() == llvm::Triple::aarch64_32) Triple.getArch() == llvm::Triple::aarch64_32)
MCpu = "cyclone"; MCpu = "cyclone";

View File

@ -222,6 +222,8 @@ LTOModule::makeLTOModule(MemoryBufferRef Buffer, const TargetOptions &options,
CPU = "core2"; CPU = "core2";
else if (Triple.getArch() == llvm::Triple::x86) else if (Triple.getArch() == llvm::Triple::x86)
CPU = "yonah"; CPU = "yonah";
else if (Triple.isArm64e())
CPU = "apple-a12";
else if (Triple.getArch() == llvm::Triple::aarch64 || else if (Triple.getArch() == llvm::Triple::aarch64 ||
Triple.getArch() == llvm::Triple::aarch64_32) Triple.getArch() == llvm::Triple::aarch64_32)
CPU = "cyclone"; CPU = "cyclone";

View File

@ -2694,6 +2694,12 @@ Triple MachOObjectFile::getArchTriple(uint32_t CPUType, uint32_t CPUSubType,
if (ArchFlag) if (ArchFlag)
*ArchFlag = "arm64"; *ArchFlag = "arm64";
return Triple("arm64-apple-darwin"); return Triple("arm64-apple-darwin");
case MachO::CPU_SUBTYPE_ARM64E:
if (McpuDefault)
*McpuDefault = "apple-a12";
if (ArchFlag)
*ArchFlag = "arm64e";
return Triple("arm64e-apple-darwin");
default: default:
return Triple(); return Triple();
} }
@ -2741,13 +2747,28 @@ bool MachOObjectFile::isValidArch(StringRef ArchFlag) {
} }
ArrayRef<StringRef> MachOObjectFile::getValidArchs() { ArrayRef<StringRef> MachOObjectFile::getValidArchs() {
static const std::array<StringRef, 17> validArchs = {{ static const std::array<StringRef, 18> ValidArchs = {{
"i386", "x86_64", "x86_64h", "armv4t", "arm", "armv5e", "i386",
"armv6", "armv6m", "armv7", "armv7em", "armv7k", "armv7m", "x86_64",
"armv7s", "arm64", "arm64_32", "ppc", "ppc64", "x86_64h",
"armv4t",
"arm",
"armv5e",
"armv6",
"armv6m",
"armv7",
"armv7em",
"armv7k",
"armv7m",
"armv7s",
"arm64",
"arm64e",
"arm64_32",
"ppc",
"ppc64",
}}; }};
return validArchs; return ValidArchs;
} }
Triple::ArchType MachOObjectFile::getArch() const { Triple::ArchType MachOObjectFile::getArch() const {

View File

@ -280,6 +280,8 @@ StringRef ARM::getCanonicalArchName(StringRef Arch) {
// Begins with "arm" / "thumb", move past it. // Begins with "arm" / "thumb", move past it.
if (A.startswith("arm64_32")) if (A.startswith("arm64_32"))
offset = 8; offset = 8;
else if (A.startswith("arm64e"))
offset = 6;
else if (A.startswith("arm64")) else if (A.startswith("arm64"))
offset = 5; offset = 5;
else if (A.startswith("aarch64_32")) else if (A.startswith("aarch64_32"))

View File

@ -407,6 +407,7 @@ static Triple::ArchType parseArch(StringRef ArchName) {
.Case("arc", Triple::arc) .Case("arc", Triple::arc)
.Case("arm64", Triple::aarch64) .Case("arm64", Triple::aarch64)
.Case("arm64_32", Triple::aarch64_32) .Case("arm64_32", Triple::aarch64_32)
.Case("arm64e", Triple::aarch64)
.Case("arm", Triple::arm) .Case("arm", Triple::arm)
.Case("armeb", Triple::armeb) .Case("armeb", Triple::armeb)
.Case("thumb", Triple::thumb) .Case("thumb", Triple::thumb)
@ -572,6 +573,9 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) {
if (SubArchName == "powerpcspe") if (SubArchName == "powerpcspe")
return Triple::PPCSubArch_spe; return Triple::PPCSubArch_spe;
if (SubArchName == "arm64e")
return Triple::AArch64SubArch_arm64e;
StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName); StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
// For now, this is the small part. Early return. // For now, this is the small part. Early return.
@ -1648,6 +1652,9 @@ VersionTuple Triple::getMinimumSupportedOSVersion() const {
// ARM64 simulators are supported for iOS 14+. // ARM64 simulators are supported for iOS 14+.
if (isMacCatalystEnvironment() || isSimulatorEnvironment()) if (isMacCatalystEnvironment() || isSimulatorEnvironment())
return VersionTuple(14, 0, 0); return VersionTuple(14, 0, 0);
// ARM64e slice is supported starting from iOS 14.
if (isArm64e())
return VersionTuple(14, 0, 0);
break; break;
case Triple::TvOS: case Triple::TvOS:
// ARM64 simulators are supported for tvOS 14+. // ARM64 simulators are supported for tvOS 14+.

View File

@ -229,6 +229,12 @@ static std::string computeDataLayout(const Triple &TT,
return "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"; return "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128";
} }
static StringRef computeDefaultCPU(const Triple &TT, StringRef CPU) {
if (CPU.empty() && TT.isArm64e())
return "apple-a12";
return CPU;
}
static Reloc::Model getEffectiveRelocModel(const Triple &TT, static Reloc::Model getEffectiveRelocModel(const Triple &TT,
Optional<Reloc::Model> RM) { Optional<Reloc::Model> RM) {
// AArch64 Darwin and Windows are always PIC. // AArch64 Darwin and Windows are always PIC.
@ -276,7 +282,8 @@ AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT,
bool LittleEndian) bool LittleEndian)
: LLVMTargetMachine(T, : LLVMTargetMachine(T,
computeDataLayout(TT, Options.MCOptions, LittleEndian), computeDataLayout(TT, Options.MCOptions, LittleEndian),
TT, CPU, FS, Options, getEffectiveRelocModel(TT, RM), TT, computeDefaultCPU(TT, CPU), FS, Options,
getEffectiveRelocModel(TT, RM),
getEffectiveAArch64CodeModel(TT, CM, JIT), OL), getEffectiveAArch64CodeModel(TT, CM, JIT), OL),
TLOF(createTLOF(getTargetTriple())), isLittle(LittleEndian) { TLOF(createTLOF(getTargetTriple())), isLittle(LittleEndian) {
initAsmInfo(); initAsmInfo();

View File

@ -50,9 +50,13 @@ static MCInstrInfo *createAArch64MCInstrInfo() {
static MCSubtargetInfo * static MCSubtargetInfo *
createAArch64MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) { createAArch64MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
if (CPU.empty()) if (CPU.empty()) {
CPU = "generic"; CPU = "generic";
if (TT.isArm64e())
CPU = "apple-a12";
}
return createAArch64MCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS); return createAArch64MCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
} }

View File

@ -0,0 +1,12 @@
; RUN: llvm-mc -triple=arm64e-apple-ios -filetype=obj %s -o - | llvm-objdump --macho -d -p - | FileCheck %s
; CHECK: _foo:
; CHECK: 0: c0 03 5f d6 ret
; CHECK: Mach header
; CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
; CHECK: MH_MAGIC_64 ARM64 E 0x00 OBJECT 3 256 0x00000000
.globl _foo
_foo:
ret

9
test/MC/AArch64/arm64e.s Normal file
View File

@ -0,0 +1,9 @@
// RUN: not llvm-mc -triple arm64-- -show-encoding < %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-GENERIC < %t %s
// RUN: llvm-mc -triple arm64e-- -show-encoding < %s |\
// RUN: FileCheck %s --check-prefix=CHECK-ARM64E
// CHECK-GENERIC: error: instruction requires: pa
// CHECK-ARM64E: pacia x0, x1 // encoding: [0x20,0x00,0xc1,0xda]
pacia x0, x1

View File

@ -1,16 +1,39 @@
// RUN: llvm-mc -triple arm64-apple-macos10.10.2 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-MACOS-ARM64 // RUN: llvm-mc -triple arm64-apple-macos10.10.2 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-MACOS-ARM64
// RUN: llvm-mc -triple arm64e-apple-macos10.10 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-MACOS-ARM64
// RUN: llvm-mc -triple arm64-apple-macos11 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-MACOS-ARM64 // RUN: llvm-mc -triple arm64-apple-macos11 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-MACOS-ARM64
// RUN: llvm-mc -triple arm64-apple-macos11.1 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-MACOS-ARM64_1 // RUN: llvm-mc -triple arm64-apple-macos11.1 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-MACOS-ARM64_1
// RUN: llvm-mc -triple arm64-apple-ios13.0-macabi %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-MACCATALYST-ARM64 // RUN: llvm-mc -triple arm64-apple-ios13.0-macabi %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-MACCATALYST-ARM64
// RUN: llvm-mc -triple arm64e-apple-ios13.0-macabi %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-MACCATALYST-ARM64
// RUN: llvm-mc -triple arm64-apple-ios14.1-macabi %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-MACCATALYST-ARM64_1 // RUN: llvm-mc -triple arm64-apple-ios14.1-macabi %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-MACCATALYST-ARM64_1
// RUN: llvm-mc -triple arm64e-apple-ios10.3 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOS-ARM64E
// RUN: llvm-mc -triple arm64e-apple-ios13 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOS-ARM64E
// RUN: llvm-mc -triple arm64e-apple-ios14.1 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOS-ARM64E3
// RUN: llvm-mc -triple arm64-apple-ios10-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOSSIM2 // RUN: llvm-mc -triple arm64-apple-ios10-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOSSIM2
// RUN: llvm-mc -triple arm64e-apple-ios10-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOSSIM2
// RUN: llvm-mc -triple arm64-apple-ios13-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOSSIM2 // RUN: llvm-mc -triple arm64-apple-ios13-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOSSIM2
// RUN: llvm-mc -triple arm64-apple-ios14-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOSSIM2 // RUN: llvm-mc -triple arm64-apple-ios14-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOSSIM2
// RUN: llvm-mc -triple arm64-apple-ios14.1-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOSSIM3 // RUN: llvm-mc -triple arm64-apple-ios14.1-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-IOSSIM3
// RUN: llvm-mc -triple arm64-apple-tvos10-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-TVOSSIM2 // RUN: llvm-mc -triple arm64-apple-tvos10-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-TVOSSIM2
// RUN: llvm-mc -triple arm64-apple-watchos3-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-WATCHOSSIM2 // RUN: llvm-mc -triple arm64-apple-watchos3-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-WATCHOSSIM2
// CHECK-BUILD-IOS-ARM64E: cmd LC_BUILD_VERSION
// CHECK-BUILD-IOS-ARM64E-NEXT: cmdsize 24
// CHECK-BUILD-IOS-ARM64E-NEXT: platform ios
// CHECK-BUILD-IOS-ARM64E-NEXT: sdk n/a
// CHECK-BUILD-IOS-ARM64E-NEXT: minos 14.0
// CHECK-BUILD-IOS-ARM64E-NEXT: ntools 0
// CHECK-BUILD-IOS-ARM64E-NOT: LC_VERSION_MIN
// CHECK-BUILD-IOS-ARM64E3: cmd LC_BUILD_VERSION
// CHECK-BUILD-IOS-ARM64E3-NEXT: cmdsize 24
// CHECK-BUILD-IOS-ARM64E3-NEXT: platform ios
// CHECK-BUILD-IOS-ARM64E3-NEXT: sdk n/a
// CHECK-BUILD-IOS-ARM64E3-NEXT: minos 14.1
// CHECK-BUILD-IOS-ARM64E3-NEXT: ntools 0
// CHECK-BUILD-IOS-ARM64E3-NOT: LC_VERSION_MIN
// CHECK-BUILD-IOSSIM2: cmd LC_BUILD_VERSION // CHECK-BUILD-IOSSIM2: cmd LC_BUILD_VERSION
// CHECK-BUILD-IOSSIM2-NEXT: cmdsize 24 // CHECK-BUILD-IOSSIM2-NEXT: cmdsize 24
// CHECK-BUILD-IOSSIM2-NEXT: platform iossim // CHECK-BUILD-IOSSIM2-NEXT: platform iossim

View File

@ -0,0 +1,17 @@
; RUN: llc -O0 %s -filetype=obj -o - \
; RUN: | llvm-dwarfdump -arch arm64e - | FileCheck %s
; CHECK: file format Mach-O arm64
source_filename = "/tmp/empty.c"
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
target triple = "arm64e-apple-ios"
!llvm.module.flags = !{!1, !2, !3, !4}
!llvm.dbg.cu = !{!5}
!1 = !{i32 2, !"Dwarf Version", i32 4}
!2 = !{i32 2, !"Debug Info Version", i32 3}
!3 = !{i32 1, !"wchar_size", i32 4}
!4 = !{i32 7, !"PIC Level", i32 2}
!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "Apple clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
!6 = !DIFile(filename: "/tmp/empty.c", directory: "/Volumes/Data/llvm-project")

View File

@ -22,7 +22,7 @@
# CHECK-NEXT: offset 16384 # CHECK-NEXT: offset 16384
# CHECK-NEXT: size 384 # CHECK-NEXT: size 384
# CHECK-NEXT: align 2^14 (16384) # CHECK-NEXT: align 2^14 (16384)
# CHECK-NEXT: architecture # CHECK-NEXT: architecture arm64e
# CHECK-NEXT: cputype CPU_TYPE_ARM64 # CHECK-NEXT: cputype CPU_TYPE_ARM64
# CHECK-NEXT: cpusubtype CPU_SUBTYPE_ARM64E # CHECK-NEXT: cpusubtype CPU_SUBTYPE_ARM64E
# CHECK-NEXT: capabilities 0x0 # CHECK-NEXT: capabilities 0x0

View File

@ -0,0 +1,17 @@
# RUN: yaml2obj %s -o %t.o
# RUN: llvm-readobj -h %t.o | FileCheck %s
# CHECK: Magic: Magic64 (0xFEEDFACF)
# CHECK: CpuType: Arm64 (0x100000C)
# CHECK: CpuSubType: CPU_SUBTYPE_ARM64E (0x2)
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x0100000C
cpusubtype: 0x00000002
filetype: 0x00000001
ncmds: 0
sizeofcmds: 0
flags: 0x00000000
reserved: 0x00000000

View File

@ -1590,5 +1590,10 @@ TEST(TripleTest, ParseARMArch) {
Triple T = Triple("aarch64_be"); Triple T = Triple("aarch64_be");
EXPECT_EQ(Triple::aarch64_be, T.getArch()); EXPECT_EQ(Triple::aarch64_be, T.getArch());
} }
{
Triple T = Triple("arm64e");
EXPECT_EQ(Triple::aarch64, T.getArch());
EXPECT_EQ(Triple::AArch64SubArch_arm64e, T.getSubArch());
}
} }
} // end anonymous namespace } // end anonymous namespace

View File

@ -336,6 +336,7 @@ def build_function_body_dictionary_for_triple(args, raw_tool_output, triple,
'amdgcn': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE), 'amdgcn': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE),
'arm': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), 'arm': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE),
'arm64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE), 'arm64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE),
'arm64e': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
'arm64-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE), 'arm64-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
'armv7-apple-ios' : (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE), 'armv7-apple-ios' : (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE),
'armv7-apple-darwin': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_DARWIN_RE), 'armv7-apple-darwin': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_DARWIN_RE),