1//===-- ArchSpec.cpp ------------------------------------------------------===//
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
9#include "lldb/Utility/ArchSpec.h"
10#include "lldb/Utility/LLDBLog.h"
11
12#include "lldb/Utility/Log.h"
13#include "lldb/Utility/StringList.h"
14#include "lldb/lldb-defines.h"
15#include "llvm/ADT/STLExtras.h"
16#include "llvm/BinaryFormat/COFF.h"
17#include "llvm/BinaryFormat/ELF.h"
18#include "llvm/BinaryFormat/MachO.h"
19#include "llvm/Support/Compiler.h"
20#include "llvm/TargetParser/ARMTargetParser.h"
21
22using namespace lldb;
23using namespace lldb_private;
24
25static bool cores_match(const ArchSpec::Core core1, const ArchSpec::Core core2,
26 bool try_inverse, bool enforce_exact_match);
27
28namespace lldb_private {
29
30struct CoreDefinition {
31 ByteOrder default_byte_order;
32 uint32_t addr_byte_size;
33 uint32_t min_opcode_byte_size;
34 uint32_t max_opcode_byte_size;
35 llvm::Triple::ArchType machine;
36 ArchSpec::Core core;
37 const char *const name;
38};
39
40} // namespace lldb_private
41
42// This core information can be looked using the ArchSpec::Core as the index
43static const CoreDefinition g_core_definitions[] = {
44 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_generic,
45 .name: "arm"},
46 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv4,
47 .name: "armv4"},
48 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv4t,
49 .name: "armv4t"},
50 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv5,
51 .name: "armv5"},
52 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv5e,
53 .name: "armv5e"},
54 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv5t,
55 .name: "armv5t"},
56 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv6,
57 .name: "armv6"},
58 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv6m,
59 .name: "armv6m"},
60 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv7,
61 .name: "armv7"},
62 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv7l,
63 .name: "armv7l"},
64 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv7f,
65 .name: "armv7f"},
66 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv7s,
67 .name: "armv7s"},
68 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv7k,
69 .name: "armv7k"},
70 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv7m,
71 .name: "armv7m"},
72 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv7em,
73 .name: "armv7em"},
74 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_xscale,
75 .name: "xscale"},
76 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumb,
77 .name: "thumb"},
78 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumbv4t,
79 .name: "thumbv4t"},
80 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumbv5,
81 .name: "thumbv5"},
82 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumbv5e,
83 .name: "thumbv5e"},
84 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumbv6,
85 .name: "thumbv6"},
86 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumbv6m,
87 .name: "thumbv6m"},
88 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumbv7,
89 .name: "thumbv7"},
90 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumbv7f,
91 .name: "thumbv7f"},
92 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumbv7s,
93 .name: "thumbv7s"},
94 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumbv7k,
95 .name: "thumbv7k"},
96 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumbv7m,
97 .name: "thumbv7m"},
98 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::thumb, .core: ArchSpec::eCore_thumbv7em,
99 .name: "thumbv7em"},
100 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::aarch64,
101 .core: ArchSpec::eCore_arm_arm64, .name: "arm64"},
102 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::aarch64,
103 .core: ArchSpec::eCore_arm_armv8, .name: "armv8"},
104 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arm, .core: ArchSpec::eCore_arm_armv8l,
105 .name: "armv8l"},
106 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::aarch64,
107 .core: ArchSpec::eCore_arm_arm64e, .name: "arm64e"},
108 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::aarch64_32,
109 .core: ArchSpec::eCore_arm_arm64_32, .name: "arm64_32"},
110 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::aarch64,
111 .core: ArchSpec::eCore_arm_aarch64, .name: "aarch64"},
112
113 // mips32, mips32r2, mips32r3, mips32r5, mips32r6
114 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips, .core: ArchSpec::eCore_mips32,
115 .name: "mips"},
116 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips, .core: ArchSpec::eCore_mips32r2,
117 .name: "mipsr2"},
118 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips, .core: ArchSpec::eCore_mips32r3,
119 .name: "mipsr3"},
120 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips, .core: ArchSpec::eCore_mips32r5,
121 .name: "mipsr5"},
122 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips, .core: ArchSpec::eCore_mips32r6,
123 .name: "mipsr6"},
124 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mipsel, .core: ArchSpec::eCore_mips32el,
125 .name: "mipsel"},
126 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mipsel,
127 .core: ArchSpec::eCore_mips32r2el, .name: "mipsr2el"},
128 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mipsel,
129 .core: ArchSpec::eCore_mips32r3el, .name: "mipsr3el"},
130 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mipsel,
131 .core: ArchSpec::eCore_mips32r5el, .name: "mipsr5el"},
132 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mipsel,
133 .core: ArchSpec::eCore_mips32r6el, .name: "mipsr6el"},
134
135 // mips64, mips64r2, mips64r3, mips64r5, mips64r6
136 {.default_byte_order: eByteOrderBig, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips64, .core: ArchSpec::eCore_mips64,
137 .name: "mips64"},
138 {.default_byte_order: eByteOrderBig, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips64, .core: ArchSpec::eCore_mips64r2,
139 .name: "mips64r2"},
140 {.default_byte_order: eByteOrderBig, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips64, .core: ArchSpec::eCore_mips64r3,
141 .name: "mips64r3"},
142 {.default_byte_order: eByteOrderBig, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips64, .core: ArchSpec::eCore_mips64r5,
143 .name: "mips64r5"},
144 {.default_byte_order: eByteOrderBig, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips64, .core: ArchSpec::eCore_mips64r6,
145 .name: "mips64r6"},
146 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips64el,
147 .core: ArchSpec::eCore_mips64el, .name: "mips64el"},
148 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips64el,
149 .core: ArchSpec::eCore_mips64r2el, .name: "mips64r2el"},
150 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips64el,
151 .core: ArchSpec::eCore_mips64r3el, .name: "mips64r3el"},
152 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips64el,
153 .core: ArchSpec::eCore_mips64r5el, .name: "mips64r5el"},
154 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::mips64el,
155 .core: ArchSpec::eCore_mips64r6el, .name: "mips64r6el"},
156
157 // MSP430
158 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 2, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::msp430, .core: ArchSpec::eCore_msp430,
159 .name: "msp430"},
160
161 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_generic,
162 .name: "powerpc"},
163 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc601,
164 .name: "ppc601"},
165 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc602,
166 .name: "ppc602"},
167 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc603,
168 .name: "ppc603"},
169 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc603e,
170 .name: "ppc603e"},
171 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc603ev,
172 .name: "ppc603ev"},
173 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc604,
174 .name: "ppc604"},
175 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc604e,
176 .name: "ppc604e"},
177 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc620,
178 .name: "ppc620"},
179 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc750,
180 .name: "ppc750"},
181 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc7400,
182 .name: "ppc7400"},
183 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc7450,
184 .name: "ppc7450"},
185 {.default_byte_order: eByteOrderBig, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc, .core: ArchSpec::eCore_ppc_ppc970,
186 .name: "ppc970"},
187
188 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc64le,
189 .core: ArchSpec::eCore_ppc64le_generic, .name: "powerpc64le"},
190 {.default_byte_order: eByteOrderBig, .addr_byte_size: 8, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc64, .core: ArchSpec::eCore_ppc64_generic,
191 .name: "powerpc64"},
192 {.default_byte_order: eByteOrderBig, .addr_byte_size: 8, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::ppc64,
193 .core: ArchSpec::eCore_ppc64_ppc970_64, .name: "ppc970-64"},
194
195 {.default_byte_order: eByteOrderBig, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 6, .machine: llvm::Triple::systemz,
196 .core: ArchSpec::eCore_s390x_generic, .name: "s390x"},
197
198 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::sparc,
199 .core: ArchSpec::eCore_sparc_generic, .name: "sparc"},
200 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::sparcv9,
201 .core: ArchSpec::eCore_sparc9_generic, .name: "sparcv9"},
202
203 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 1, .max_opcode_byte_size: 15, .machine: llvm::Triple::x86, .core: ArchSpec::eCore_x86_32_i386,
204 .name: "i386"},
205 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 1, .max_opcode_byte_size: 15, .machine: llvm::Triple::x86, .core: ArchSpec::eCore_x86_32_i486,
206 .name: "i486"},
207 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 1, .max_opcode_byte_size: 15, .machine: llvm::Triple::x86,
208 .core: ArchSpec::eCore_x86_32_i486sx, .name: "i486sx"},
209 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 1, .max_opcode_byte_size: 15, .machine: llvm::Triple::x86, .core: ArchSpec::eCore_x86_32_i686,
210 .name: "i686"},
211
212 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 1, .max_opcode_byte_size: 15, .machine: llvm::Triple::x86_64,
213 .core: ArchSpec::eCore_x86_64_x86_64, .name: "x86_64"},
214 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 1, .max_opcode_byte_size: 15, .machine: llvm::Triple::x86_64,
215 .core: ArchSpec::eCore_x86_64_x86_64h, .name: "x86_64h"},
216 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::hexagon,
217 .core: ArchSpec::eCore_hexagon_generic, .name: "hexagon"},
218 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::hexagon,
219 .core: ArchSpec::eCore_hexagon_hexagonv4, .name: "hexagonv4"},
220 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::hexagon,
221 .core: ArchSpec::eCore_hexagon_hexagonv5, .name: "hexagonv5"},
222
223 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::riscv32, .core: ArchSpec::eCore_riscv32,
224 .name: "riscv32"},
225 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::riscv64, .core: ArchSpec::eCore_riscv64,
226 .name: "riscv64"},
227
228 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::loongarch32,
229 .core: ArchSpec::eCore_loongarch32, .name: "loongarch32"},
230 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::loongarch64,
231 .core: ArchSpec::eCore_loongarch64, .name: "loongarch64"},
232
233 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::UnknownArch,
234 .core: ArchSpec::eCore_uknownMach32, .name: "unknown-mach-32"},
235 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 8, .min_opcode_byte_size: 4, .max_opcode_byte_size: 4, .machine: llvm::Triple::UnknownArch,
236 .core: ArchSpec::eCore_uknownMach64, .name: "unknown-mach-64"},
237 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::arc, .core: ArchSpec::eCore_arc, .name: "arc"},
238
239 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 2, .min_opcode_byte_size: 2, .max_opcode_byte_size: 4, .machine: llvm::Triple::avr, .core: ArchSpec::eCore_avr, .name: "avr"},
240
241 {.default_byte_order: eByteOrderLittle, .addr_byte_size: 4, .min_opcode_byte_size: 1, .max_opcode_byte_size: 4, .machine: llvm::Triple::wasm32, .core: ArchSpec::eCore_wasm32,
242 .name: "wasm32"},
243};
244
245// Ensure that we have an entry in the g_core_definitions for each core. If you
246// comment out an entry above, you will need to comment out the corresponding
247// ArchSpec::Core enumeration.
248static_assert(sizeof(g_core_definitions) / sizeof(CoreDefinition) ==
249 ArchSpec::kNumCores,
250 "make sure we have one core definition for each core");
251
252struct ArchDefinitionEntry {
253 ArchSpec::Core core;
254 uint32_t cpu;
255 uint32_t sub;
256 uint32_t cpu_mask;
257 uint32_t sub_mask;
258};
259
260struct ArchDefinition {
261 ArchitectureType type;
262 size_t num_entries;
263 const ArchDefinitionEntry *entries;
264 const char *name;
265};
266
267void ArchSpec::ListSupportedArchNames(StringList &list) {
268 for (const auto &def : g_core_definitions)
269 list.AppendString(str: def.name);
270}
271
272void ArchSpec::AutoComplete(CompletionRequest &request) {
273 for (const auto &def : g_core_definitions)
274 request.TryCompleteCurrentArg(completion: def.name);
275}
276
277#define CPU_ANY (UINT32_MAX)
278
279//===----------------------------------------------------------------------===//
280// A table that gets searched linearly for matches. This table is used to
281// convert cpu type and subtypes to architecture names, and to convert
282// architecture names to cpu types and subtypes. The ordering is important and
283// allows the precedence to be set when the table is built.
284#define SUBTYPE_MASK 0x00FFFFFFu
285
286// clang-format off
287static const ArchDefinitionEntry g_macho_arch_entries[] = {
288 {.core: ArchSpec::eCore_arm_generic, .cpu: llvm::MachO::CPU_TYPE_ARM, CPU_ANY, UINT32_MAX, UINT32_MAX},
289 {.core: ArchSpec::eCore_arm_generic, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_ALL, UINT32_MAX, SUBTYPE_MASK},
290 {.core: ArchSpec::eCore_arm_armv4, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V4T, UINT32_MAX, SUBTYPE_MASK},
291 {.core: ArchSpec::eCore_arm_armv4t, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V4T, UINT32_MAX, SUBTYPE_MASK},
292 {.core: ArchSpec::eCore_arm_armv6, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V6, UINT32_MAX, SUBTYPE_MASK},
293 {.core: ArchSpec::eCore_arm_armv6m, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V6M, UINT32_MAX, SUBTYPE_MASK},
294 {.core: ArchSpec::eCore_arm_armv5, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ, UINT32_MAX, SUBTYPE_MASK},
295 {.core: ArchSpec::eCore_arm_armv5e, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ, UINT32_MAX, SUBTYPE_MASK},
296 {.core: ArchSpec::eCore_arm_armv5t, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ, UINT32_MAX, SUBTYPE_MASK},
297 {.core: ArchSpec::eCore_arm_xscale, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_XSCALE, UINT32_MAX, SUBTYPE_MASK},
298 {.core: ArchSpec::eCore_arm_armv7, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V7, UINT32_MAX, SUBTYPE_MASK},
299 {.core: ArchSpec::eCore_arm_armv7f, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: 10, UINT32_MAX, SUBTYPE_MASK},
300 {.core: ArchSpec::eCore_arm_armv7s, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V7S, UINT32_MAX, SUBTYPE_MASK},
301 {.core: ArchSpec::eCore_arm_armv7k, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V7K, UINT32_MAX, SUBTYPE_MASK},
302 {.core: ArchSpec::eCore_arm_armv7m, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V7M, UINT32_MAX, SUBTYPE_MASK},
303 {.core: ArchSpec::eCore_arm_armv7em, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V7EM, UINT32_MAX, SUBTYPE_MASK},
304 {.core: ArchSpec::eCore_arm_arm64e, .cpu: llvm::MachO::CPU_TYPE_ARM64, .sub: llvm::MachO::CPU_SUBTYPE_ARM64E, UINT32_MAX, SUBTYPE_MASK},
305 {.core: ArchSpec::eCore_arm_arm64, .cpu: llvm::MachO::CPU_TYPE_ARM64, .sub: llvm::MachO::CPU_SUBTYPE_ARM64_ALL, UINT32_MAX, SUBTYPE_MASK},
306 {.core: ArchSpec::eCore_arm_arm64, .cpu: llvm::MachO::CPU_TYPE_ARM64, .sub: llvm::MachO::CPU_SUBTYPE_ARM64_V8, UINT32_MAX, SUBTYPE_MASK},
307 {.core: ArchSpec::eCore_arm_arm64, .cpu: llvm::MachO::CPU_TYPE_ARM64, .sub: 13, UINT32_MAX, SUBTYPE_MASK},
308 {.core: ArchSpec::eCore_arm_arm64_32, .cpu: llvm::MachO::CPU_TYPE_ARM64_32, .sub: 0, UINT32_MAX, SUBTYPE_MASK},
309 {.core: ArchSpec::eCore_arm_arm64_32, .cpu: llvm::MachO::CPU_TYPE_ARM64_32, .sub: 1, UINT32_MAX, SUBTYPE_MASK},
310 {.core: ArchSpec::eCore_arm_arm64, .cpu: llvm::MachO::CPU_TYPE_ARM64, CPU_ANY, UINT32_MAX, SUBTYPE_MASK},
311 {.core: ArchSpec::eCore_thumb, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_ALL, UINT32_MAX, SUBTYPE_MASK},
312 {.core: ArchSpec::eCore_thumbv4t, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V4T, UINT32_MAX, SUBTYPE_MASK},
313 {.core: ArchSpec::eCore_thumbv5, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V5, UINT32_MAX, SUBTYPE_MASK},
314 {.core: ArchSpec::eCore_thumbv5e, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V5, UINT32_MAX, SUBTYPE_MASK},
315 {.core: ArchSpec::eCore_thumbv6, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V6, UINT32_MAX, SUBTYPE_MASK},
316 {.core: ArchSpec::eCore_thumbv6m, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V6M, UINT32_MAX, SUBTYPE_MASK},
317 {.core: ArchSpec::eCore_thumbv7, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V7, UINT32_MAX, SUBTYPE_MASK},
318 {.core: ArchSpec::eCore_thumbv7f, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: 10, UINT32_MAX, SUBTYPE_MASK},
319 {.core: ArchSpec::eCore_thumbv7s, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V7S, UINT32_MAX, SUBTYPE_MASK},
320 {.core: ArchSpec::eCore_thumbv7k, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V7K, UINT32_MAX, SUBTYPE_MASK},
321 {.core: ArchSpec::eCore_thumbv7m, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V7M, UINT32_MAX, SUBTYPE_MASK},
322 {.core: ArchSpec::eCore_thumbv7em, .cpu: llvm::MachO::CPU_TYPE_ARM, .sub: llvm::MachO::CPU_SUBTYPE_ARM_V7EM, UINT32_MAX, SUBTYPE_MASK},
323 {.core: ArchSpec::eCore_ppc_generic, .cpu: llvm::MachO::CPU_TYPE_POWERPC, CPU_ANY, UINT32_MAX, UINT32_MAX},
324 {.core: ArchSpec::eCore_ppc_generic, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_ALL, UINT32_MAX, SUBTYPE_MASK},
325 {.core: ArchSpec::eCore_ppc_ppc601, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_601, UINT32_MAX, SUBTYPE_MASK},
326 {.core: ArchSpec::eCore_ppc_ppc602, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_602, UINT32_MAX, SUBTYPE_MASK},
327 {.core: ArchSpec::eCore_ppc_ppc603, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_603, UINT32_MAX, SUBTYPE_MASK},
328 {.core: ArchSpec::eCore_ppc_ppc603e, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_603e, UINT32_MAX, SUBTYPE_MASK},
329 {.core: ArchSpec::eCore_ppc_ppc603ev, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_603ev, UINT32_MAX, SUBTYPE_MASK},
330 {.core: ArchSpec::eCore_ppc_ppc604, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_604, UINT32_MAX, SUBTYPE_MASK},
331 {.core: ArchSpec::eCore_ppc_ppc604e, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_604e, UINT32_MAX, SUBTYPE_MASK},
332 {.core: ArchSpec::eCore_ppc_ppc620, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_620, UINT32_MAX, SUBTYPE_MASK},
333 {.core: ArchSpec::eCore_ppc_ppc750, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_750, UINT32_MAX, SUBTYPE_MASK},
334 {.core: ArchSpec::eCore_ppc_ppc7400, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_7400, UINT32_MAX, SUBTYPE_MASK},
335 {.core: ArchSpec::eCore_ppc_ppc7450, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_7450, UINT32_MAX, SUBTYPE_MASK},
336 {.core: ArchSpec::eCore_ppc_ppc970, .cpu: llvm::MachO::CPU_TYPE_POWERPC, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_970, UINT32_MAX, SUBTYPE_MASK},
337 {.core: ArchSpec::eCore_ppc64_generic, .cpu: llvm::MachO::CPU_TYPE_POWERPC64, .sub: llvm::MachO::CPU_SUBTYPE_POWERPC_ALL, UINT32_MAX, SUBTYPE_MASK},
338 {.core: ArchSpec::eCore_ppc64le_generic, .cpu: llvm::MachO::CPU_TYPE_POWERPC64, CPU_ANY, UINT32_MAX, SUBTYPE_MASK},
339 {.core: ArchSpec::eCore_ppc64_ppc970_64, .cpu: llvm::MachO::CPU_TYPE_POWERPC64, .sub: 100, UINT32_MAX, SUBTYPE_MASK},
340 {.core: ArchSpec::eCore_x86_32_i386, .cpu: llvm::MachO::CPU_TYPE_I386, .sub: llvm::MachO::CPU_SUBTYPE_I386_ALL, UINT32_MAX, SUBTYPE_MASK},
341 {.core: ArchSpec::eCore_x86_32_i486, .cpu: llvm::MachO::CPU_TYPE_I386, .sub: llvm::MachO::CPU_SUBTYPE_486, UINT32_MAX, SUBTYPE_MASK},
342 {.core: ArchSpec::eCore_x86_32_i486sx, .cpu: llvm::MachO::CPU_TYPE_I386, .sub: llvm::MachO::CPU_SUBTYPE_486SX, UINT32_MAX, SUBTYPE_MASK},
343 {.core: ArchSpec::eCore_x86_32_i386, .cpu: llvm::MachO::CPU_TYPE_I386, CPU_ANY, UINT32_MAX, UINT32_MAX},
344 {.core: ArchSpec::eCore_x86_64_x86_64, .cpu: llvm::MachO::CPU_TYPE_X86_64, .sub: llvm::MachO::CPU_SUBTYPE_X86_64_ALL, UINT32_MAX, SUBTYPE_MASK},
345 {.core: ArchSpec::eCore_x86_64_x86_64, .cpu: llvm::MachO::CPU_TYPE_X86_64, .sub: llvm::MachO::CPU_SUBTYPE_X86_ARCH1, UINT32_MAX, SUBTYPE_MASK},
346 {.core: ArchSpec::eCore_x86_64_x86_64h, .cpu: llvm::MachO::CPU_TYPE_X86_64, .sub: llvm::MachO::CPU_SUBTYPE_X86_64_H, UINT32_MAX, SUBTYPE_MASK},
347 {.core: ArchSpec::eCore_x86_64_x86_64, .cpu: llvm::MachO::CPU_TYPE_X86_64, CPU_ANY, UINT32_MAX, UINT32_MAX},
348 // Catch any unknown mach architectures so we can always use the object and symbol mach-o files
349 {.core: ArchSpec::eCore_uknownMach32, .cpu: 0, .sub: 0, .cpu_mask: 0xFF000000u, .sub_mask: 0x00000000u},
350 {.core: ArchSpec::eCore_uknownMach64, .cpu: llvm::MachO::CPU_ARCH_ABI64, .sub: 0, .cpu_mask: 0xFF000000u, .sub_mask: 0x00000000u}};
351// clang-format on
352
353static const ArchDefinition g_macho_arch_def = {.type: eArchTypeMachO,
354 .num_entries: std::size(g_macho_arch_entries),
355 .entries: g_macho_arch_entries, .name: "mach-o"};
356
357//===----------------------------------------------------------------------===//
358// A table that gets searched linearly for matches. This table is used to
359// convert cpu type and subtypes to architecture names, and to convert
360// architecture names to cpu types and subtypes. The ordering is important and
361// allows the precedence to be set when the table is built.
362static const ArchDefinitionEntry g_elf_arch_entries[] = {
363 {.core: ArchSpec::eCore_sparc_generic, .cpu: llvm::ELF::EM_SPARC, LLDB_INVALID_CPUTYPE,
364 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // Sparc
365 {.core: ArchSpec::eCore_x86_32_i386, .cpu: llvm::ELF::EM_386, LLDB_INVALID_CPUTYPE,
366 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // Intel 80386
367 {.core: ArchSpec::eCore_x86_32_i486, .cpu: llvm::ELF::EM_IAMCU, LLDB_INVALID_CPUTYPE,
368 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // Intel MCU // FIXME: is this correct?
369 {.core: ArchSpec::eCore_ppc_generic, .cpu: llvm::ELF::EM_PPC, LLDB_INVALID_CPUTYPE,
370 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // PowerPC
371 {.core: ArchSpec::eCore_ppc64le_generic, .cpu: llvm::ELF::EM_PPC64,
372 .sub: ArchSpec::eCore_ppc64le_generic, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // PowerPC64le
373 {.core: ArchSpec::eCore_ppc64_generic, .cpu: llvm::ELF::EM_PPC64,
374 .sub: ArchSpec::eCore_ppc64_generic, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // PowerPC64
375 {.core: ArchSpec::eCore_arm_generic, .cpu: llvm::ELF::EM_ARM, LLDB_INVALID_CPUTYPE,
376 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // ARM
377 {.core: ArchSpec::eCore_arm_aarch64, .cpu: llvm::ELF::EM_AARCH64, LLDB_INVALID_CPUTYPE,
378 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // ARM64
379 {.core: ArchSpec::eCore_s390x_generic, .cpu: llvm::ELF::EM_S390, LLDB_INVALID_CPUTYPE,
380 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // SystemZ
381 {.core: ArchSpec::eCore_sparc9_generic, .cpu: llvm::ELF::EM_SPARCV9,
382 LLDB_INVALID_CPUTYPE, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // SPARC V9
383 {.core: ArchSpec::eCore_x86_64_x86_64, .cpu: llvm::ELF::EM_X86_64, LLDB_INVALID_CPUTYPE,
384 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // AMD64
385 {.core: ArchSpec::eCore_mips32, .cpu: llvm::ELF::EM_MIPS, .sub: ArchSpec::eMIPSSubType_mips32,
386 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips32
387 {.core: ArchSpec::eCore_mips32r2, .cpu: llvm::ELF::EM_MIPS,
388 .sub: ArchSpec::eMIPSSubType_mips32r2, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips32r2
389 {.core: ArchSpec::eCore_mips32r6, .cpu: llvm::ELF::EM_MIPS,
390 .sub: ArchSpec::eMIPSSubType_mips32r6, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips32r6
391 {.core: ArchSpec::eCore_mips32el, .cpu: llvm::ELF::EM_MIPS,
392 .sub: ArchSpec::eMIPSSubType_mips32el, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips32el
393 {.core: ArchSpec::eCore_mips32r2el, .cpu: llvm::ELF::EM_MIPS,
394 .sub: ArchSpec::eMIPSSubType_mips32r2el, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips32r2el
395 {.core: ArchSpec::eCore_mips32r6el, .cpu: llvm::ELF::EM_MIPS,
396 .sub: ArchSpec::eMIPSSubType_mips32r6el, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips32r6el
397 {.core: ArchSpec::eCore_mips64, .cpu: llvm::ELF::EM_MIPS, .sub: ArchSpec::eMIPSSubType_mips64,
398 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips64
399 {.core: ArchSpec::eCore_mips64r2, .cpu: llvm::ELF::EM_MIPS,
400 .sub: ArchSpec::eMIPSSubType_mips64r2, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips64r2
401 {.core: ArchSpec::eCore_mips64r6, .cpu: llvm::ELF::EM_MIPS,
402 .sub: ArchSpec::eMIPSSubType_mips64r6, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips64r6
403 {.core: ArchSpec::eCore_mips64el, .cpu: llvm::ELF::EM_MIPS,
404 .sub: ArchSpec::eMIPSSubType_mips64el, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips64el
405 {.core: ArchSpec::eCore_mips64r2el, .cpu: llvm::ELF::EM_MIPS,
406 .sub: ArchSpec::eMIPSSubType_mips64r2el, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips64r2el
407 {.core: ArchSpec::eCore_mips64r6el, .cpu: llvm::ELF::EM_MIPS,
408 .sub: ArchSpec::eMIPSSubType_mips64r6el, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // mips64r6el
409 {.core: ArchSpec::eCore_msp430, .cpu: llvm::ELF::EM_MSP430, LLDB_INVALID_CPUTYPE,
410 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // MSP430
411 {.core: ArchSpec::eCore_hexagon_generic, .cpu: llvm::ELF::EM_HEXAGON,
412 LLDB_INVALID_CPUTYPE, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // HEXAGON
413 {.core: ArchSpec::eCore_arc, .cpu: llvm::ELF::EM_ARC_COMPACT2, LLDB_INVALID_CPUTYPE,
414 .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // ARC
415 {.core: ArchSpec::eCore_avr, .cpu: llvm::ELF::EM_AVR, LLDB_INVALID_CPUTYPE, .cpu_mask: 0xFFFFFFFFu,
416 .sub_mask: 0xFFFFFFFFu}, // AVR
417 {.core: ArchSpec::eCore_riscv32, .cpu: llvm::ELF::EM_RISCV,
418 .sub: ArchSpec::eRISCVSubType_riscv32, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // riscv32
419 {.core: ArchSpec::eCore_riscv64, .cpu: llvm::ELF::EM_RISCV,
420 .sub: ArchSpec::eRISCVSubType_riscv64, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // riscv64
421 {.core: ArchSpec::eCore_loongarch32, .cpu: llvm::ELF::EM_LOONGARCH,
422 .sub: ArchSpec::eLoongArchSubType_loongarch32, .cpu_mask: 0xFFFFFFFFu,
423 .sub_mask: 0xFFFFFFFFu}, // loongarch32
424 {.core: ArchSpec::eCore_loongarch64, .cpu: llvm::ELF::EM_LOONGARCH,
425 .sub: ArchSpec::eLoongArchSubType_loongarch64, .cpu_mask: 0xFFFFFFFFu,
426 .sub_mask: 0xFFFFFFFFu}, // loongarch64
427};
428
429static const ArchDefinition g_elf_arch_def = {
430 .type: eArchTypeELF,
431 .num_entries: std::size(g_elf_arch_entries),
432 .entries: g_elf_arch_entries,
433 .name: "elf",
434};
435
436static const ArchDefinitionEntry g_coff_arch_entries[] = {
437 {.core: ArchSpec::eCore_x86_32_i386, .cpu: llvm::COFF::IMAGE_FILE_MACHINE_I386,
438 LLDB_INVALID_CPUTYPE, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // Intel 80x86
439 {.core: ArchSpec::eCore_ppc_generic, .cpu: llvm::COFF::IMAGE_FILE_MACHINE_POWERPC,
440 LLDB_INVALID_CPUTYPE, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // PowerPC
441 {.core: ArchSpec::eCore_ppc_generic, .cpu: llvm::COFF::IMAGE_FILE_MACHINE_POWERPCFP,
442 LLDB_INVALID_CPUTYPE, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // PowerPC (with FPU)
443 {.core: ArchSpec::eCore_arm_generic, .cpu: llvm::COFF::IMAGE_FILE_MACHINE_ARM,
444 LLDB_INVALID_CPUTYPE, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // ARM
445 {.core: ArchSpec::eCore_arm_armv7, .cpu: llvm::COFF::IMAGE_FILE_MACHINE_ARMNT,
446 LLDB_INVALID_CPUTYPE, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // ARMv7
447 {.core: ArchSpec::eCore_thumb, .cpu: llvm::COFF::IMAGE_FILE_MACHINE_THUMB,
448 LLDB_INVALID_CPUTYPE, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // ARMv7
449 {.core: ArchSpec::eCore_x86_64_x86_64, .cpu: llvm::COFF::IMAGE_FILE_MACHINE_AMD64,
450 LLDB_INVALID_CPUTYPE, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu}, // AMD64
451 {.core: ArchSpec::eCore_arm_arm64, .cpu: llvm::COFF::IMAGE_FILE_MACHINE_ARM64,
452 LLDB_INVALID_CPUTYPE, .cpu_mask: 0xFFFFFFFFu, .sub_mask: 0xFFFFFFFFu} // ARM64
453};
454
455static const ArchDefinition g_coff_arch_def = {
456 .type: eArchTypeCOFF,
457 .num_entries: std::size(g_coff_arch_entries),
458 .entries: g_coff_arch_entries,
459 .name: "pe-coff",
460};
461
462//===----------------------------------------------------------------------===//
463// Table of all ArchDefinitions
464static const ArchDefinition *g_arch_definitions[] = {
465 &g_macho_arch_def, &g_elf_arch_def, &g_coff_arch_def};
466
467//===----------------------------------------------------------------------===//
468// Static helper functions.
469
470// Get the architecture definition for a given object type.
471static const ArchDefinition *FindArchDefinition(ArchitectureType arch_type) {
472 for (const ArchDefinition *def : g_arch_definitions) {
473 if (def->type == arch_type)
474 return def;
475 }
476 return nullptr;
477}
478
479// Get an architecture definition by name.
480static const CoreDefinition *FindCoreDefinition(llvm::StringRef name) {
481 for (const auto &def : g_core_definitions) {
482 if (name.equals_insensitive(RHS: def.name))
483 return &def;
484 }
485 return nullptr;
486}
487
488static inline const CoreDefinition *FindCoreDefinition(ArchSpec::Core core) {
489 if (core < std::size(g_core_definitions))
490 return &g_core_definitions[core];
491 return nullptr;
492}
493
494// Get a definition entry by cpu type and subtype.
495static const ArchDefinitionEntry *
496FindArchDefinitionEntry(const ArchDefinition *def, uint32_t cpu, uint32_t sub) {
497 if (def == nullptr)
498 return nullptr;
499
500 const ArchDefinitionEntry *entries = def->entries;
501 for (size_t i = 0; i < def->num_entries; ++i) {
502 if (entries[i].cpu == (cpu & entries[i].cpu_mask))
503 if (entries[i].sub == (sub & entries[i].sub_mask))
504 return &entries[i];
505 }
506 return nullptr;
507}
508
509static const ArchDefinitionEntry *
510FindArchDefinitionEntry(const ArchDefinition *def, ArchSpec::Core core) {
511 if (def == nullptr)
512 return nullptr;
513
514 const ArchDefinitionEntry *entries = def->entries;
515 for (size_t i = 0; i < def->num_entries; ++i) {
516 if (entries[i].core == core)
517 return &entries[i];
518 }
519 return nullptr;
520}
521
522//===----------------------------------------------------------------------===//
523// Constructors and destructors.
524
525ArchSpec::ArchSpec() = default;
526
527ArchSpec::ArchSpec(const char *triple_cstr) {
528 if (triple_cstr)
529 SetTriple(triple_cstr);
530}
531
532ArchSpec::ArchSpec(llvm::StringRef triple_str) { SetTriple(triple_str); }
533
534ArchSpec::ArchSpec(const llvm::Triple &triple) { SetTriple(triple); }
535
536ArchSpec::ArchSpec(ArchitectureType arch_type, uint32_t cpu, uint32_t subtype) {
537 SetArchitecture(arch_type, cpu, sub: subtype);
538}
539
540ArchSpec::~ArchSpec() = default;
541
542void ArchSpec::Clear() {
543 m_triple = llvm::Triple();
544 m_core = kCore_invalid;
545 m_byte_order = eByteOrderInvalid;
546 m_flags = 0;
547}
548
549//===----------------------------------------------------------------------===//
550// Predicates.
551
552const char *ArchSpec::GetArchitectureName() const {
553 const CoreDefinition *core_def = FindCoreDefinition(core: m_core);
554 if (core_def)
555 return core_def->name;
556 return "unknown";
557}
558
559bool ArchSpec::IsMIPS() const { return GetTriple().isMIPS(); }
560
561std::string ArchSpec::GetTargetABI() const {
562
563 std::string abi;
564
565 if (IsMIPS()) {
566 switch (GetFlags() & ArchSpec::eMIPSABI_mask) {
567 case ArchSpec::eMIPSABI_N64:
568 abi = "n64";
569 return abi;
570 case ArchSpec::eMIPSABI_N32:
571 abi = "n32";
572 return abi;
573 case ArchSpec::eMIPSABI_O32:
574 abi = "o32";
575 return abi;
576 default:
577 return abi;
578 }
579 }
580 return abi;
581}
582
583void ArchSpec::SetFlags(const std::string &elf_abi) {
584
585 uint32_t flag = GetFlags();
586 if (IsMIPS()) {
587 if (elf_abi == "n64")
588 flag |= ArchSpec::eMIPSABI_N64;
589 else if (elf_abi == "n32")
590 flag |= ArchSpec::eMIPSABI_N32;
591 else if (elf_abi == "o32")
592 flag |= ArchSpec::eMIPSABI_O32;
593 }
594 SetFlags(flag);
595}
596
597std::string ArchSpec::GetClangTargetCPU() const {
598 std::string cpu;
599 if (IsMIPS()) {
600 switch (m_core) {
601 case ArchSpec::eCore_mips32:
602 case ArchSpec::eCore_mips32el:
603 cpu = "mips32";
604 break;
605 case ArchSpec::eCore_mips32r2:
606 case ArchSpec::eCore_mips32r2el:
607 cpu = "mips32r2";
608 break;
609 case ArchSpec::eCore_mips32r3:
610 case ArchSpec::eCore_mips32r3el:
611 cpu = "mips32r3";
612 break;
613 case ArchSpec::eCore_mips32r5:
614 case ArchSpec::eCore_mips32r5el:
615 cpu = "mips32r5";
616 break;
617 case ArchSpec::eCore_mips32r6:
618 case ArchSpec::eCore_mips32r6el:
619 cpu = "mips32r6";
620 break;
621 case ArchSpec::eCore_mips64:
622 case ArchSpec::eCore_mips64el:
623 cpu = "mips64";
624 break;
625 case ArchSpec::eCore_mips64r2:
626 case ArchSpec::eCore_mips64r2el:
627 cpu = "mips64r2";
628 break;
629 case ArchSpec::eCore_mips64r3:
630 case ArchSpec::eCore_mips64r3el:
631 cpu = "mips64r3";
632 break;
633 case ArchSpec::eCore_mips64r5:
634 case ArchSpec::eCore_mips64r5el:
635 cpu = "mips64r5";
636 break;
637 case ArchSpec::eCore_mips64r6:
638 case ArchSpec::eCore_mips64r6el:
639 cpu = "mips64r6";
640 break;
641 default:
642 break;
643 }
644 }
645
646 if (GetTriple().isARM())
647 cpu = llvm::ARM::getARMCPUForArch(Triple: GetTriple(), MArch: "").str();
648 return cpu;
649}
650
651uint32_t ArchSpec::GetMachOCPUType() const {
652 const CoreDefinition *core_def = FindCoreDefinition(core: m_core);
653 if (core_def) {
654 const ArchDefinitionEntry *arch_def =
655 FindArchDefinitionEntry(def: &g_macho_arch_def, core: core_def->core);
656 if (arch_def) {
657 return arch_def->cpu;
658 }
659 }
660 return LLDB_INVALID_CPUTYPE;
661}
662
663uint32_t ArchSpec::GetMachOCPUSubType() const {
664 const CoreDefinition *core_def = FindCoreDefinition(core: m_core);
665 if (core_def) {
666 const ArchDefinitionEntry *arch_def =
667 FindArchDefinitionEntry(def: &g_macho_arch_def, core: core_def->core);
668 if (arch_def) {
669 return arch_def->sub;
670 }
671 }
672 return LLDB_INVALID_CPUTYPE;
673}
674
675uint32_t ArchSpec::GetDataByteSize() const {
676 return 1;
677}
678
679uint32_t ArchSpec::GetCodeByteSize() const {
680 return 1;
681}
682
683llvm::Triple::ArchType ArchSpec::GetMachine() const {
684 const CoreDefinition *core_def = FindCoreDefinition(core: m_core);
685 if (core_def)
686 return core_def->machine;
687
688 return llvm::Triple::UnknownArch;
689}
690
691uint32_t ArchSpec::GetAddressByteSize() const {
692 const CoreDefinition *core_def = FindCoreDefinition(core: m_core);
693 if (core_def) {
694 if (core_def->machine == llvm::Triple::mips64 ||
695 core_def->machine == llvm::Triple::mips64el) {
696 // For N32/O32 applications Address size is 4 bytes.
697 if (m_flags & (eMIPSABI_N32 | eMIPSABI_O32))
698 return 4;
699 }
700 return core_def->addr_byte_size;
701 }
702 return 0;
703}
704
705ByteOrder ArchSpec::GetDefaultEndian() const {
706 const CoreDefinition *core_def = FindCoreDefinition(core: m_core);
707 if (core_def)
708 return core_def->default_byte_order;
709 return eByteOrderInvalid;
710}
711
712bool ArchSpec::CharIsSignedByDefault() const {
713 switch (m_triple.getArch()) {
714 default:
715 return true;
716
717 case llvm::Triple::aarch64:
718 case llvm::Triple::aarch64_32:
719 case llvm::Triple::aarch64_be:
720 case llvm::Triple::arm:
721 case llvm::Triple::armeb:
722 case llvm::Triple::thumb:
723 case llvm::Triple::thumbeb:
724 return m_triple.isOSDarwin() || m_triple.isOSWindows();
725
726 case llvm::Triple::ppc:
727 case llvm::Triple::ppc64:
728 return m_triple.isOSDarwin();
729
730 case llvm::Triple::ppc64le:
731 case llvm::Triple::systemz:
732 case llvm::Triple::xcore:
733 case llvm::Triple::arc:
734 return false;
735 }
736}
737
738lldb::ByteOrder ArchSpec::GetByteOrder() const {
739 if (m_byte_order == eByteOrderInvalid)
740 return GetDefaultEndian();
741 return m_byte_order;
742}
743
744//===----------------------------------------------------------------------===//
745// Mutators.
746
747bool ArchSpec::SetTriple(const llvm::Triple &triple) {
748 m_triple = triple;
749 UpdateCore();
750 return IsValid();
751}
752
753bool lldb_private::ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str,
754 ArchSpec &arch) {
755 // Accept "12-10" or "12.10" as cpu type/subtype
756 if (triple_str.empty())
757 return false;
758
759 size_t pos = triple_str.find_first_of(Chars: "-.");
760 if (pos == llvm::StringRef::npos)
761 return false;
762
763 llvm::StringRef cpu_str = triple_str.substr(Start: 0, N: pos);
764 llvm::StringRef remainder = triple_str.substr(Start: pos + 1);
765 if (cpu_str.empty() || remainder.empty())
766 return false;
767
768 llvm::StringRef sub_str;
769 llvm::StringRef vendor;
770 llvm::StringRef os;
771 std::tie(args&: sub_str, args&: remainder) = remainder.split(Separator: '-');
772 std::tie(args&: vendor, args&: os) = remainder.split(Separator: '-');
773
774 uint32_t cpu = 0;
775 uint32_t sub = 0;
776 if (cpu_str.getAsInteger(Radix: 10, Result&: cpu) || sub_str.getAsInteger(Radix: 10, Result&: sub))
777 return false;
778
779 if (!arch.SetArchitecture(arch_type: eArchTypeMachO, cpu, sub))
780 return false;
781 if (!vendor.empty() && !os.empty()) {
782 arch.GetTriple().setVendorName(vendor);
783 arch.GetTriple().setOSName(os);
784 }
785
786 return true;
787}
788
789bool ArchSpec::SetTriple(llvm::StringRef triple) {
790 if (triple.empty()) {
791 Clear();
792 return false;
793 }
794
795 if (ParseMachCPUDashSubtypeTriple(triple_str: triple, arch&: *this))
796 return true;
797
798 SetTriple(llvm::Triple(llvm::Triple::normalize(Str: triple)));
799 return IsValid();
800}
801
802bool ArchSpec::ContainsOnlyArch(const llvm::Triple &normalized_triple) {
803 return !normalized_triple.getArchName().empty() &&
804 normalized_triple.getOSName().empty() &&
805 normalized_triple.getVendorName().empty() &&
806 normalized_triple.getEnvironmentName().empty();
807}
808
809void ArchSpec::MergeFrom(const ArchSpec &other) {
810 // ios-macabi always wins over macosx.
811 if ((GetTriple().getOS() == llvm::Triple::MacOSX ||
812 GetTriple().getOS() == llvm::Triple::UnknownOS) &&
813 other.GetTriple().getOS() == llvm::Triple::IOS &&
814 other.GetTriple().getEnvironment() == llvm::Triple::MacABI) {
815 (*this) = other;
816 return;
817 }
818
819 if (!TripleVendorWasSpecified() && other.TripleVendorWasSpecified())
820 GetTriple().setVendor(other.GetTriple().getVendor());
821 if (!TripleOSWasSpecified() && other.TripleOSWasSpecified())
822 GetTriple().setOS(other.GetTriple().getOS());
823 if (GetTriple().getArch() == llvm::Triple::UnknownArch) {
824 GetTriple().setArch(Kind: other.GetTriple().getArch());
825
826 // MachO unknown64 isn't really invalid as the debugger can still obtain
827 // information from the binary, e.g. line tables. As such, we don't update
828 // the core here.
829 if (other.GetCore() != eCore_uknownMach64)
830 UpdateCore();
831 }
832 if (!TripleEnvironmentWasSpecified() &&
833 other.TripleEnvironmentWasSpecified()) {
834 GetTriple().setEnvironment(other.GetTriple().getEnvironment());
835 }
836 // If this and other are both arm ArchSpecs and this ArchSpec is a generic
837 // "some kind of arm" spec but the other ArchSpec is a specific arm core,
838 // adopt the specific arm core.
839 if (GetTriple().getArch() == llvm::Triple::arm &&
840 other.GetTriple().getArch() == llvm::Triple::arm &&
841 IsCompatibleMatch(rhs: other) && GetCore() == ArchSpec::eCore_arm_generic &&
842 other.GetCore() != ArchSpec::eCore_arm_generic) {
843 m_core = other.GetCore();
844 CoreUpdated(update_triple: false);
845 }
846 if (GetFlags() == 0) {
847 SetFlags(other.GetFlags());
848 }
849}
850
851bool ArchSpec::SetArchitecture(ArchitectureType arch_type, uint32_t cpu,
852 uint32_t sub, uint32_t os) {
853 m_core = kCore_invalid;
854 bool update_triple = true;
855 const ArchDefinition *arch_def = FindArchDefinition(arch_type);
856 if (arch_def) {
857 const ArchDefinitionEntry *arch_def_entry =
858 FindArchDefinitionEntry(def: arch_def, cpu, sub);
859 if (arch_def_entry) {
860 const CoreDefinition *core_def = FindCoreDefinition(core: arch_def_entry->core);
861 if (core_def) {
862 m_core = core_def->core;
863 update_triple = false;
864 // Always use the architecture name because it might be more
865 // descriptive than the architecture enum ("armv7" ->
866 // llvm::Triple::arm).
867 m_triple.setArchName(llvm::StringRef(core_def->name));
868 if (arch_type == eArchTypeMachO) {
869 m_triple.setVendor(llvm::Triple::Apple);
870
871 // Don't set the OS. It could be simulator, macosx, ios, watchos,
872 // tvos, bridgeos. We could get close with the cpu type - but we
873 // can't get it right all of the time. Better to leave this unset
874 // so other sections of code will set it when they have more
875 // information. NB: don't call m_triple.setOS
876 // (llvm::Triple::UnknownOS). That sets the OSName to "unknown" and
877 // the ArchSpec::TripleVendorWasSpecified() method says that any
878 // OSName setting means it was specified.
879 } else if (arch_type == eArchTypeELF) {
880 switch (os) {
881 case llvm::ELF::ELFOSABI_AIX:
882 m_triple.setOS(llvm::Triple::OSType::AIX);
883 break;
884 case llvm::ELF::ELFOSABI_FREEBSD:
885 m_triple.setOS(llvm::Triple::OSType::FreeBSD);
886 break;
887 case llvm::ELF::ELFOSABI_GNU:
888 m_triple.setOS(llvm::Triple::OSType::Linux);
889 break;
890 case llvm::ELF::ELFOSABI_NETBSD:
891 m_triple.setOS(llvm::Triple::OSType::NetBSD);
892 break;
893 case llvm::ELF::ELFOSABI_OPENBSD:
894 m_triple.setOS(llvm::Triple::OSType::OpenBSD);
895 break;
896 case llvm::ELF::ELFOSABI_SOLARIS:
897 m_triple.setOS(llvm::Triple::OSType::Solaris);
898 break;
899 case llvm::ELF::ELFOSABI_STANDALONE:
900 m_triple.setOS(llvm::Triple::OSType::UnknownOS);
901 break;
902 }
903 } else if (arch_type == eArchTypeCOFF && os == llvm::Triple::Win32) {
904 m_triple.setVendor(llvm::Triple::PC);
905 m_triple.setOS(llvm::Triple::Win32);
906 } else {
907 m_triple.setVendor(llvm::Triple::UnknownVendor);
908 m_triple.setOS(llvm::Triple::UnknownOS);
909 }
910 // Fall back onto setting the machine type if the arch by name
911 // failed...
912 if (m_triple.getArch() == llvm::Triple::UnknownArch)
913 m_triple.setArch(Kind: core_def->machine);
914 }
915 } else {
916 Log *log(GetLog(mask: LLDBLog::Target | LLDBLog::Process | LLDBLog::Platform));
917 LLDB_LOGF(log,
918 "Unable to find a core definition for cpu 0x%" PRIx32
919 " sub %" PRId32,
920 cpu, sub);
921 }
922 }
923 CoreUpdated(update_triple);
924 return IsValid();
925}
926
927uint32_t ArchSpec::GetMinimumOpcodeByteSize() const {
928 const CoreDefinition *core_def = FindCoreDefinition(core: m_core);
929 if (core_def)
930 return core_def->min_opcode_byte_size;
931 return 0;
932}
933
934uint32_t ArchSpec::GetMaximumOpcodeByteSize() const {
935 const CoreDefinition *core_def = FindCoreDefinition(core: m_core);
936 if (core_def)
937 return core_def->max_opcode_byte_size;
938 return 0;
939}
940
941static bool IsCompatibleEnvironment(llvm::Triple::EnvironmentType lhs,
942 llvm::Triple::EnvironmentType rhs) {
943 if (lhs == rhs)
944 return true;
945
946 // Apple simulators are a different platform than what they simulate.
947 // As the environments are different at this point, if one of them is a
948 // simulator, then they are different.
949 if (lhs == llvm::Triple::Simulator || rhs == llvm::Triple::Simulator)
950 return false;
951
952 // If any of the environment is unknown then they are compatible
953 if (lhs == llvm::Triple::UnknownEnvironment ||
954 rhs == llvm::Triple::UnknownEnvironment)
955 return true;
956
957 // If one of the environment is Android and the other one is EABI then they
958 // are considered to be compatible. This is required as a workaround for
959 // shared libraries compiled for Android without the NOTE section indicating
960 // that they are using the Android ABI.
961 if ((lhs == llvm::Triple::Android && rhs == llvm::Triple::EABI) ||
962 (rhs == llvm::Triple::Android && lhs == llvm::Triple::EABI) ||
963 (lhs == llvm::Triple::GNUEABI && rhs == llvm::Triple::EABI) ||
964 (rhs == llvm::Triple::GNUEABI && lhs == llvm::Triple::EABI) ||
965 (lhs == llvm::Triple::GNUEABIHF && rhs == llvm::Triple::EABIHF) ||
966 (rhs == llvm::Triple::GNUEABIHF && lhs == llvm::Triple::EABIHF))
967 return true;
968
969 return false;
970}
971
972bool ArchSpec::IsMatch(const ArchSpec &rhs, MatchType match) const {
973 if (GetByteOrder() != rhs.GetByteOrder() ||
974 !cores_match(core1: GetCore(), core2: rhs.GetCore(), try_inverse: true, enforce_exact_match: match == ExactMatch))
975 return false;
976
977 const llvm::Triple &lhs_triple = GetTriple();
978 const llvm::Triple &rhs_triple = rhs.GetTriple();
979
980 const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
981 const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
982
983 const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
984 const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
985
986 bool both_windows = lhs_triple.isOSWindows() && rhs_triple.isOSWindows();
987
988 // On Windows, the vendor field doesn't have any practical effect, but
989 // it is often set to either "pc" or "w64".
990 if ((lhs_triple_vendor != rhs_triple_vendor) &&
991 (match == ExactMatch || !both_windows)) {
992 const bool rhs_vendor_specified = rhs.TripleVendorWasSpecified();
993 const bool lhs_vendor_specified = TripleVendorWasSpecified();
994 // Both architectures had the vendor specified, so if they aren't equal
995 // then we return false
996 if (rhs_vendor_specified && lhs_vendor_specified)
997 return false;
998
999 // Only fail if both vendor types are not unknown
1000 if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
1001 rhs_triple_vendor != llvm::Triple::UnknownVendor)
1002 return false;
1003 }
1004
1005 const llvm::Triple::EnvironmentType lhs_triple_env =
1006 lhs_triple.getEnvironment();
1007 const llvm::Triple::EnvironmentType rhs_triple_env =
1008 rhs_triple.getEnvironment();
1009
1010 if (match == CompatibleMatch) {
1011 // x86_64-apple-ios-macabi, x86_64-apple-macosx are compatible, no match.
1012 if ((lhs_triple_os == llvm::Triple::IOS &&
1013 lhs_triple_env == llvm::Triple::MacABI &&
1014 rhs_triple_os == llvm::Triple::MacOSX) ||
1015 (lhs_triple_os == llvm::Triple::MacOSX &&
1016 rhs_triple_os == llvm::Triple::IOS &&
1017 rhs_triple_env == llvm::Triple::MacABI))
1018 return true;
1019 }
1020
1021 // x86_64-apple-ios-macabi and x86_64-apple-ios are not compatible.
1022 if (lhs_triple_os == llvm::Triple::IOS &&
1023 rhs_triple_os == llvm::Triple::IOS &&
1024 (lhs_triple_env == llvm::Triple::MacABI ||
1025 rhs_triple_env == llvm::Triple::MacABI) &&
1026 lhs_triple_env != rhs_triple_env)
1027 return false;
1028
1029 if (lhs_triple_os != rhs_triple_os) {
1030 const bool lhs_os_specified = TripleOSWasSpecified();
1031 const bool rhs_os_specified = rhs.TripleOSWasSpecified();
1032 // If both OS types are specified and different, fail.
1033 if (lhs_os_specified && rhs_os_specified)
1034 return false;
1035
1036 // If the pair of os+env is both unspecified, match any other os+env combo.
1037 if (match == CompatibleMatch &&
1038 ((!lhs_os_specified && !lhs_triple.hasEnvironment()) ||
1039 (!rhs_os_specified && !rhs_triple.hasEnvironment())))
1040 return true;
1041 }
1042
1043 if (match == CompatibleMatch && both_windows)
1044 return true; // The Windows environments (MSVC vs GNU) are compatible
1045
1046 return IsCompatibleEnvironment(lhs: lhs_triple_env, rhs: rhs_triple_env);
1047}
1048
1049void ArchSpec::UpdateCore() {
1050 llvm::StringRef arch_name(m_triple.getArchName());
1051 const CoreDefinition *core_def = FindCoreDefinition(name: arch_name);
1052 if (core_def) {
1053 m_core = core_def->core;
1054 // Set the byte order to the default byte order for an architecture. This
1055 // can be modified if needed for cases when cores handle both big and
1056 // little endian
1057 m_byte_order = core_def->default_byte_order;
1058 } else {
1059 Clear();
1060 }
1061}
1062
1063//===----------------------------------------------------------------------===//
1064// Helper methods.
1065
1066void ArchSpec::CoreUpdated(bool update_triple) {
1067 const CoreDefinition *core_def = FindCoreDefinition(core: m_core);
1068 if (core_def) {
1069 if (update_triple)
1070 m_triple = llvm::Triple(core_def->name, "unknown", "unknown");
1071 m_byte_order = core_def->default_byte_order;
1072 } else {
1073 if (update_triple)
1074 m_triple = llvm::Triple();
1075 m_byte_order = eByteOrderInvalid;
1076 }
1077}
1078
1079//===----------------------------------------------------------------------===//
1080// Operators.
1081
1082static bool cores_match(const ArchSpec::Core core1, const ArchSpec::Core core2,
1083 bool try_inverse, bool enforce_exact_match) {
1084 if (core1 == core2)
1085 return true;
1086
1087 switch (core1) {
1088 case ArchSpec::kCore_any:
1089 return true;
1090
1091 case ArchSpec::eCore_arm_generic:
1092 if (enforce_exact_match)
1093 break;
1094 [[fallthrough]];
1095 case ArchSpec::kCore_arm_any:
1096 if (core2 >= ArchSpec::kCore_arm_first && core2 <= ArchSpec::kCore_arm_last)
1097 return true;
1098 if (core2 >= ArchSpec::kCore_thumb_first &&
1099 core2 <= ArchSpec::kCore_thumb_last)
1100 return true;
1101 if (core2 == ArchSpec::kCore_arm_any)
1102 return true;
1103 break;
1104
1105 case ArchSpec::kCore_x86_32_any:
1106 if ((core2 >= ArchSpec::kCore_x86_32_first &&
1107 core2 <= ArchSpec::kCore_x86_32_last) ||
1108 (core2 == ArchSpec::kCore_x86_32_any))
1109 return true;
1110 break;
1111
1112 case ArchSpec::kCore_x86_64_any:
1113 if ((core2 >= ArchSpec::kCore_x86_64_first &&
1114 core2 <= ArchSpec::kCore_x86_64_last) ||
1115 (core2 == ArchSpec::kCore_x86_64_any))
1116 return true;
1117 break;
1118
1119 case ArchSpec::kCore_ppc_any:
1120 if ((core2 >= ArchSpec::kCore_ppc_first &&
1121 core2 <= ArchSpec::kCore_ppc_last) ||
1122 (core2 == ArchSpec::kCore_ppc_any))
1123 return true;
1124 break;
1125
1126 case ArchSpec::kCore_ppc64_any:
1127 if ((core2 >= ArchSpec::kCore_ppc64_first &&
1128 core2 <= ArchSpec::kCore_ppc64_last) ||
1129 (core2 == ArchSpec::kCore_ppc64_any))
1130 return true;
1131 break;
1132
1133 case ArchSpec::kCore_hexagon_any:
1134 if ((core2 >= ArchSpec::kCore_hexagon_first &&
1135 core2 <= ArchSpec::kCore_hexagon_last) ||
1136 (core2 == ArchSpec::kCore_hexagon_any))
1137 return true;
1138 break;
1139
1140 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M#Silicon_customization
1141 // Cortex-M0 - ARMv6-M - armv6m
1142 // Cortex-M3 - ARMv7-M - armv7m
1143 // Cortex-M4 - ARMv7E-M - armv7em
1144 case ArchSpec::eCore_arm_armv7em:
1145 if (!enforce_exact_match) {
1146 if (core2 == ArchSpec::eCore_arm_generic)
1147 return true;
1148 if (core2 == ArchSpec::eCore_arm_armv7m)
1149 return true;
1150 if (core2 == ArchSpec::eCore_arm_armv6m)
1151 return true;
1152 if (core2 == ArchSpec::eCore_arm_armv7)
1153 return true;
1154 try_inverse = true;
1155 }
1156 break;
1157
1158 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M#Silicon_customization
1159 // Cortex-M0 - ARMv6-M - armv6m
1160 // Cortex-M3 - ARMv7-M - armv7m
1161 // Cortex-M4 - ARMv7E-M - armv7em
1162 case ArchSpec::eCore_arm_armv7m:
1163 if (!enforce_exact_match) {
1164 if (core2 == ArchSpec::eCore_arm_generic)
1165 return true;
1166 if (core2 == ArchSpec::eCore_arm_armv6m)
1167 return true;
1168 if (core2 == ArchSpec::eCore_arm_armv7)
1169 return true;
1170 if (core2 == ArchSpec::eCore_arm_armv7em)
1171 return true;
1172 try_inverse = true;
1173 }
1174 break;
1175
1176 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M#Silicon_customization
1177 // Cortex-M0 - ARMv6-M - armv6m
1178 // Cortex-M3 - ARMv7-M - armv7m
1179 // Cortex-M4 - ARMv7E-M - armv7em
1180 case ArchSpec::eCore_arm_armv6m:
1181 if (!enforce_exact_match) {
1182 if (core2 == ArchSpec::eCore_arm_generic)
1183 return true;
1184 if (core2 == ArchSpec::eCore_arm_armv7em)
1185 return true;
1186 if (core2 == ArchSpec::eCore_arm_armv7)
1187 return true;
1188 if (core2 == ArchSpec::eCore_arm_armv6m)
1189 return true;
1190 try_inverse = false;
1191 }
1192 break;
1193
1194 case ArchSpec::eCore_arm_armv7f:
1195 case ArchSpec::eCore_arm_armv7k:
1196 case ArchSpec::eCore_arm_armv7s:
1197 case ArchSpec::eCore_arm_armv7l:
1198 case ArchSpec::eCore_arm_armv8l:
1199 if (!enforce_exact_match) {
1200 if (core2 == ArchSpec::eCore_arm_generic)
1201 return true;
1202 if (core2 == ArchSpec::eCore_arm_armv7)
1203 return true;
1204 try_inverse = false;
1205 }
1206 break;
1207
1208 case ArchSpec::eCore_x86_64_x86_64h:
1209 if (!enforce_exact_match) {
1210 try_inverse = false;
1211 if (core2 == ArchSpec::eCore_x86_64_x86_64)
1212 return true;
1213 }
1214 break;
1215
1216 case ArchSpec::eCore_arm_armv8:
1217 if (!enforce_exact_match) {
1218 if (core2 == ArchSpec::eCore_arm_arm64)
1219 return true;
1220 if (core2 == ArchSpec::eCore_arm_aarch64)
1221 return true;
1222 if (core2 == ArchSpec::eCore_arm_arm64e)
1223 return true;
1224 try_inverse = false;
1225 }
1226 break;
1227
1228 case ArchSpec::eCore_arm_arm64e:
1229 if (!enforce_exact_match) {
1230 if (core2 == ArchSpec::eCore_arm_arm64)
1231 return true;
1232 if (core2 == ArchSpec::eCore_arm_aarch64)
1233 return true;
1234 if (core2 == ArchSpec::eCore_arm_armv8)
1235 return true;
1236 try_inverse = false;
1237 }
1238 break;
1239 case ArchSpec::eCore_arm_aarch64:
1240 if (!enforce_exact_match) {
1241 if (core2 == ArchSpec::eCore_arm_arm64)
1242 return true;
1243 if (core2 == ArchSpec::eCore_arm_armv8)
1244 return true;
1245 if (core2 == ArchSpec::eCore_arm_arm64e)
1246 return true;
1247 try_inverse = false;
1248 }
1249 break;
1250
1251 case ArchSpec::eCore_arm_arm64:
1252 if (!enforce_exact_match) {
1253 if (core2 == ArchSpec::eCore_arm_aarch64)
1254 return true;
1255 if (core2 == ArchSpec::eCore_arm_armv8)
1256 return true;
1257 if (core2 == ArchSpec::eCore_arm_arm64e)
1258 return true;
1259 try_inverse = false;
1260 }
1261 break;
1262
1263 case ArchSpec::eCore_arm_arm64_32:
1264 if (!enforce_exact_match) {
1265 if (core2 == ArchSpec::eCore_arm_generic)
1266 return true;
1267 try_inverse = false;
1268 }
1269 break;
1270
1271 case ArchSpec::eCore_mips32:
1272 if (!enforce_exact_match) {
1273 if (core2 >= ArchSpec::kCore_mips32_first &&
1274 core2 <= ArchSpec::kCore_mips32_last)
1275 return true;
1276 try_inverse = false;
1277 }
1278 break;
1279
1280 case ArchSpec::eCore_mips32el:
1281 if (!enforce_exact_match) {
1282 if (core2 >= ArchSpec::kCore_mips32el_first &&
1283 core2 <= ArchSpec::kCore_mips32el_last)
1284 return true;
1285 try_inverse = true;
1286 }
1287 break;
1288
1289 case ArchSpec::eCore_mips64:
1290 if (!enforce_exact_match) {
1291 if (core2 >= ArchSpec::kCore_mips32_first &&
1292 core2 <= ArchSpec::kCore_mips32_last)
1293 return true;
1294 if (core2 >= ArchSpec::kCore_mips64_first &&
1295 core2 <= ArchSpec::kCore_mips64_last)
1296 return true;
1297 try_inverse = false;
1298 }
1299 break;
1300
1301 case ArchSpec::eCore_mips64el:
1302 if (!enforce_exact_match) {
1303 if (core2 >= ArchSpec::kCore_mips32el_first &&
1304 core2 <= ArchSpec::kCore_mips32el_last)
1305 return true;
1306 if (core2 >= ArchSpec::kCore_mips64el_first &&
1307 core2 <= ArchSpec::kCore_mips64el_last)
1308 return true;
1309 try_inverse = false;
1310 }
1311 break;
1312
1313 case ArchSpec::eCore_mips64r2:
1314 case ArchSpec::eCore_mips64r3:
1315 case ArchSpec::eCore_mips64r5:
1316 if (!enforce_exact_match) {
1317 if (core2 >= ArchSpec::kCore_mips32_first && core2 <= (core1 - 10))
1318 return true;
1319 if (core2 >= ArchSpec::kCore_mips64_first && core2 <= (core1 - 1))
1320 return true;
1321 try_inverse = false;
1322 }
1323 break;
1324
1325 case ArchSpec::eCore_mips64r2el:
1326 case ArchSpec::eCore_mips64r3el:
1327 case ArchSpec::eCore_mips64r5el:
1328 if (!enforce_exact_match) {
1329 if (core2 >= ArchSpec::kCore_mips32el_first && core2 <= (core1 - 10))
1330 return true;
1331 if (core2 >= ArchSpec::kCore_mips64el_first && core2 <= (core1 - 1))
1332 return true;
1333 try_inverse = false;
1334 }
1335 break;
1336
1337 case ArchSpec::eCore_mips32r2:
1338 case ArchSpec::eCore_mips32r3:
1339 case ArchSpec::eCore_mips32r5:
1340 if (!enforce_exact_match) {
1341 if (core2 >= ArchSpec::kCore_mips32_first && core2 <= core1)
1342 return true;
1343 }
1344 break;
1345
1346 case ArchSpec::eCore_mips32r2el:
1347 case ArchSpec::eCore_mips32r3el:
1348 case ArchSpec::eCore_mips32r5el:
1349 if (!enforce_exact_match) {
1350 if (core2 >= ArchSpec::kCore_mips32el_first && core2 <= core1)
1351 return true;
1352 }
1353 break;
1354
1355 case ArchSpec::eCore_mips32r6:
1356 if (!enforce_exact_match) {
1357 if (core2 == ArchSpec::eCore_mips32 || core2 == ArchSpec::eCore_mips32r6)
1358 return true;
1359 }
1360 break;
1361
1362 case ArchSpec::eCore_mips32r6el:
1363 if (!enforce_exact_match) {
1364 if (core2 == ArchSpec::eCore_mips32el ||
1365 core2 == ArchSpec::eCore_mips32r6el)
1366 return true;
1367 }
1368 break;
1369
1370 case ArchSpec::eCore_mips64r6:
1371 if (!enforce_exact_match) {
1372 if (core2 == ArchSpec::eCore_mips32 || core2 == ArchSpec::eCore_mips32r6)
1373 return true;
1374 if (core2 == ArchSpec::eCore_mips64 || core2 == ArchSpec::eCore_mips64r6)
1375 return true;
1376 }
1377 break;
1378
1379 case ArchSpec::eCore_mips64r6el:
1380 if (!enforce_exact_match) {
1381 if (core2 == ArchSpec::eCore_mips32el ||
1382 core2 == ArchSpec::eCore_mips32r6el)
1383 return true;
1384 if (core2 == ArchSpec::eCore_mips64el ||
1385 core2 == ArchSpec::eCore_mips64r6el)
1386 return true;
1387 }
1388 break;
1389
1390 default:
1391 break;
1392 }
1393 if (try_inverse)
1394 return cores_match(core1: core2, core2: core1, try_inverse: false, enforce_exact_match);
1395 return false;
1396}
1397
1398bool lldb_private::operator<(const ArchSpec &lhs, const ArchSpec &rhs) {
1399 const ArchSpec::Core lhs_core = lhs.GetCore();
1400 const ArchSpec::Core rhs_core = rhs.GetCore();
1401 return lhs_core < rhs_core;
1402}
1403
1404
1405bool lldb_private::operator==(const ArchSpec &lhs, const ArchSpec &rhs) {
1406 return lhs.GetCore() == rhs.GetCore();
1407}
1408
1409bool ArchSpec::IsFullySpecifiedTriple() const {
1410 if (!TripleOSWasSpecified())
1411 return false;
1412
1413 if (!TripleVendorWasSpecified())
1414 return false;
1415
1416 const unsigned unspecified = 0;
1417 const llvm::Triple &triple = GetTriple();
1418 if (triple.isOSDarwin() && triple.getOSMajorVersion() == unspecified)
1419 return false;
1420
1421 return true;
1422}
1423
1424bool ArchSpec::IsAlwaysThumbInstructions() const {
1425 std::string Status;
1426 if (GetTriple().getArch() == llvm::Triple::arm ||
1427 GetTriple().getArch() == llvm::Triple::thumb) {
1428 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M
1429 //
1430 // Cortex-M0 through Cortex-M7 are ARM processor cores which can only
1431 // execute thumb instructions. We map the cores to arch names like this:
1432 //
1433 // Cortex-M0, Cortex-M0+, Cortex-M1: armv6m Cortex-M3: armv7m Cortex-M4,
1434 // Cortex-M7: armv7em
1435
1436 if (GetCore() == ArchSpec::Core::eCore_arm_armv7m ||
1437 GetCore() == ArchSpec::Core::eCore_arm_armv7em ||
1438 GetCore() == ArchSpec::Core::eCore_arm_armv6m ||
1439 GetCore() == ArchSpec::Core::eCore_thumbv7m ||
1440 GetCore() == ArchSpec::Core::eCore_thumbv7em ||
1441 GetCore() == ArchSpec::Core::eCore_thumbv6m) {
1442 return true;
1443 }
1444 // Windows on ARM is always thumb.
1445 if (GetTriple().isOSWindows())
1446 return true;
1447 }
1448 return false;
1449}
1450
1451void ArchSpec::DumpTriple(llvm::raw_ostream &s) const {
1452 const llvm::Triple &triple = GetTriple();
1453 llvm::StringRef arch_str = triple.getArchName();
1454 llvm::StringRef vendor_str = triple.getVendorName();
1455 llvm::StringRef os_str = triple.getOSName();
1456 llvm::StringRef environ_str = triple.getEnvironmentName();
1457
1458 s << llvm::formatv(Fmt: "{0}-{1}-{2}", Vals: arch_str.empty() ? "*" : arch_str,
1459 Vals: vendor_str.empty() ? "*" : vendor_str,
1460 Vals: os_str.empty() ? "*" : os_str);
1461
1462 if (!environ_str.empty())
1463 s << "-" << environ_str;
1464}
1465

source code of lldb/source/Utility/ArchSpec.cpp