LLVM 20.0.0git
MachO.cpp
Go to the documentation of this file.
1//===-- llvm/BinaryFormat/MachO.cpp - The MachO file format -----*- C++/-*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
12
13using namespace llvm;
14
16 assert(T.isX86());
17 if (T.isArch32Bit())
19
20 assert(T.isArch64Bit());
21 if (T.getArchName() == "x86_64h")
24}
25
27 assert(T.isARM() || T.isThumb());
28 StringRef Arch = T.getArchName();
30 switch (AK) {
31 default:
33 case ARM::ArchKind::ARMV4T:
35 case ARM::ArchKind::ARMV5T:
36 case ARM::ArchKind::ARMV5TE:
37 case ARM::ArchKind::ARMV5TEJ:
39 case ARM::ArchKind::ARMV6:
40 case ARM::ArchKind::ARMV6K:
42 case ARM::ArchKind::ARMV7A:
44 case ARM::ArchKind::ARMV7S:
46 case ARM::ArchKind::ARMV7K:
48 case ARM::ArchKind::ARMV6M:
50 case ARM::ArchKind::ARMV7M:
52 case ARM::ArchKind::ARMV7EM:
54 }
55}
56
58 assert(T.isAArch64());
59 if (T.isArch32Bit())
61 if (T.isArm64e())
63
65}
66
69}
70
71static Error unsupported(const char *Str, const Triple &T) {
72 return createStringError(std::errc::invalid_argument,
73 "Unsupported triple for mach-o cpu %s: %s", Str,
74 T.str().c_str());
75}
76
78 if (!T.isOSBinFormatMachO())
79 return unsupported("type", T);
80 if (T.isX86() && T.isArch32Bit())
82 if (T.isX86() && T.isArch64Bit())
84 if (T.isARM() || T.isThumb())
86 if (T.isAArch64())
87 return T.isArch32Bit() ? MachO::CPU_TYPE_ARM64_32 : MachO::CPU_TYPE_ARM64;
88 if (T.getArch() == Triple::ppc)
90 if (T.getArch() == Triple::ppc64)
92 return unsupported("type", T);
93}
94
96 if (!T.isOSBinFormatMachO())
97 return unsupported("subtype", T);
98 if (T.isX86())
99 return getX86SubType(T);
100 if (T.isARM() || T.isThumb())
101 return getARMSubType(T);
102 if (T.isAArch64() || T.getArch() == Triple::aarch64_32)
103 return getARM64SubType(T);
104 if (T.getArch() == Triple::ppc || T.getArch() == Triple::ppc64)
105 return getPowerPCSubType(T);
106 return unsupported("subtype", T);
107}
108
110 unsigned PtrAuthABIVersion,
111 bool PtrAuthKernelABIVersion) {
113 if (!Result)
114 return Result.takeError();
115 if (*Result != MachO::CPU_SUBTYPE_ARM64E)
116 return createStringError(
117 std::errc::invalid_argument,
118 "ptrauth ABI version is only supported on arm64e.");
119 if (PtrAuthABIVersion > 0xF)
120 return createStringError(
121 std::errc::invalid_argument,
122 "The ptrauth ABI version needs to fit within 4 bits.");
123 return CPU_SUBTYPE_ARM64E_WITH_PTRAUTH_VERSION(PtrAuthABIVersion,
124 PtrAuthKernelABIVersion);
125}
static Error unsupported(const char *Str, const Triple &T)
Definition: MachO.cpp:71
static MachO::CPUSubTypeX86 getX86SubType(const Triple &T)
Definition: MachO.cpp:15
static MachO::CPUSubTypeARM64 getARM64SubType(const Triple &T)
Definition: MachO.cpp:57
static MachO::CPUSubTypePowerPC getPowerPCSubType(const Triple &T)
Definition: MachO.cpp:67
static MachO::CPUSubTypeARM getARMSubType(const Triple &T)
Definition: MachO.cpp:26
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
@ aarch64_32
Definition: Triple.h:53
ArchKind parseArch(StringRef Arch)
Expected< uint32_t > getCPUSubType(const Triple &T)
Definition: MachO.cpp:95
CPUSubTypePowerPC
Definition: MachO.h:1682
@ CPU_SUBTYPE_POWERPC_ALL
Definition: MachO.h:1683
@ CPU_SUBTYPE_ARM_V7
Definition: MachO.h:1631
@ CPU_SUBTYPE_ARM_V7M
Definition: MachO.h:1636
@ CPU_SUBTYPE_ARM_V6
Definition: MachO.h:1627
@ CPU_SUBTYPE_ARM_V7K
Definition: MachO.h:1634
@ CPU_SUBTYPE_ARM_V6M
Definition: MachO.h:1635
@ CPU_SUBTYPE_ARM_V5
Definition: MachO.h:1628
@ CPU_SUBTYPE_ARM_V7EM
Definition: MachO.h:1637
@ CPU_SUBTYPE_ARM_V7S
Definition: MachO.h:1633
@ CPU_SUBTYPE_ARM_V4T
Definition: MachO.h:1626
CPUSubTypeARM64
Definition: MachO.h:1640
@ CPU_SUBTYPE_ARM64E
Definition: MachO.h:1643
@ CPU_SUBTYPE_ARM64_ALL
Definition: MachO.h:1641
@ CPU_SUBTYPE_ARM64_32_V8
Definition: MachO.h:1678
uint32_t CPU_SUBTYPE_ARM64E_WITH_PTRAUTH_VERSION(unsigned PtrAuthABIVersion, bool PtrAuthKernelABIVersion)
Definition: MachO.h:1659
Expected< uint32_t > getCPUType(const Triple &T)
Definition: MachO.cpp:77
@ CPU_SUBTYPE_I386_ALL
Definition: MachO.h:1588
@ CPU_SUBTYPE_X86_64_H
Definition: MachO.h:1613
@ CPU_SUBTYPE_X86_64_ALL
Definition: MachO.h:1611
@ CPU_TYPE_ARM64_32
Definition: MachO.h:1571
@ CPU_TYPE_ARM64
Definition: MachO.h:1570
@ CPU_TYPE_POWERPC
Definition: MachO.h:1573
@ CPU_TYPE_X86_64
Definition: MachO.h:1566
@ CPU_TYPE_POWERPC64
Definition: MachO.h:1574
@ CPU_TYPE_X86
Definition: MachO.h:1564
@ CPU_TYPE_ARM
Definition: MachO.h:1569
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1291