Skip to content

Commit 645de36

Browse files
committed
[llvm-libtool-darwin] Add constant CPU_SUBTYPE_ARM64_V8
Add support for constant MachO::CPU_SUBTYPE_ARM64_V8. This constant is needed so as to match `llvm-libtool-darwin`'s behavior to that of cctools' libtool when `-arch_only` flag is passed in on command line. Reviewed by jhenderson, alexshap, smeenai Differential Revision: https://reviews.llvm.org/D85041
1 parent 7547508 commit 645de36

File tree

7 files changed

+165
-8
lines changed

7 files changed

+165
-8
lines changed

llvm/include/llvm/BinaryFormat/MachO.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,7 @@ enum CPUSubTypeARM {
14921492

14931493
enum CPUSubTypeARM64 {
14941494
CPU_SUBTYPE_ARM64_ALL = 0,
1495+
CPU_SUBTYPE_ARM64_V8 = 1,
14951496
CPU_SUBTYPE_ARM64E = 2,
14961497
};
14971498

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# RUN: yaml2obj %s -o %tarm64-all.o -DSUBTYPE=0x0
2+
# RUN: llvm-objdump -p %tarm64-all.o | FileCheck --strict-whitespace %s --check-prefixes="COMMON,ALL"
3+
4+
# RUN: yaml2obj %s -o %tarm64-v8.o -DSUBTYPE=0x1
5+
# RUN: llvm-objdump -p %tarm64-v8.o | FileCheck --strict-whitespace %s --check-prefixes="COMMON,V8"
6+
7+
# RUN: yaml2obj %s -o %tarm64e.o -DSUBTYPE=0x2
8+
# RUN: llvm-objdump -p %tarm64e.o | FileCheck --strict-whitespace %s --check-prefixes="COMMON,E"
9+
10+
# COMMON: Mach header
11+
# COMMON-NEXT: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
12+
# ALL-NEXT: MH_MAGIC_64 ARM64 ALL 0x00 OBJECT 0 0 0x00000000
13+
# V8-NEXT: MH_MAGIC_64 ARM64 V8 0x00 OBJECT 0 0 0x00000000
14+
# E-NEXT: MH_MAGIC_64 ARM64 E 0x00 OBJECT 0 0 0x00000000
15+
16+
--- !mach-o
17+
FileHeader:
18+
magic: 0xFEEDFACF
19+
cputype: 0x0100000C
20+
cpusubtype: [[SUBTYPE]]
21+
filetype: 0x00000001
22+
ncmds: 0
23+
sizeofcmds: 0
24+
flags: 0x00000000
25+
reserved: 0x00000000
26+
...

llvm/test/tools/llvm-objdump/MachO/AArch64/macho-arm64e.test

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
## This test checks that the CPUTypes are printed correctly for the subtypes of
2+
## ARM64.
3+
4+
# RUN: yaml2obj %s -o %tarm.o
5+
# RUN: llvm-objdump %tarm.o --universal-headers --macho | \
6+
# RUN: FileCheck %s --match-full-lines
7+
8+
# CHECK: Fat headers
9+
# CHECK-NEXT: fat_magic FAT_MAGIC
10+
# CHECK-NEXT: nfat_arch 3
11+
# CHECK-NEXT: architecture arm64
12+
# CHECK-NEXT: cputype CPU_TYPE_ARM64
13+
# CHECK-NEXT: cpusubtype CPU_SUBTYPE_ARM64_ALL
14+
# CHECK-NEXT: capabilities 0x0
15+
# CHECK-NEXT: offset 4096
16+
# CHECK-NEXT: size 352
17+
# CHECK-NEXT: align 2^12 (4096)
18+
# CHECK-NEXT: architecture
19+
# CHECK-NEXT: cputype CPU_TYPE_ARM64
20+
# CHECK-NEXT: cpusubtype CPU_SUBTYPE_ARM64_V8
21+
# CHECK-NEXT: capabilities 0x0
22+
# CHECK-NEXT: offset 16384
23+
# CHECK-NEXT: size 384
24+
# CHECK-NEXT: align 2^14 (16384)
25+
# CHECK-NEXT: architecture
26+
# CHECK-NEXT: cputype CPU_TYPE_ARM64
27+
# CHECK-NEXT: cpusubtype CPU_SUBTYPE_ARM64E
28+
# CHECK-NEXT: capabilities 0x0
29+
# CHECK-NEXT: offset 28672
30+
# CHECK-NEXT: size 384
31+
# CHECK-NEXT: align 2^12 (4096)
32+
# CHECK-NOT:{{.}}
33+
34+
--- !fat-mach-o
35+
FatHeader:
36+
magic: 0xCAFEBABE
37+
nfat_arch: 3
38+
FatArchs:
39+
- cputype: 0x0100000C
40+
cpusubtype: 0x00000000
41+
offset: 0x0000000000001000
42+
size: 352
43+
align: 12
44+
- cputype: 0x0100000C
45+
cpusubtype: 0x00000001
46+
offset: 0x0000000000004000
47+
size: 384
48+
align: 14
49+
- cputype: 0x0100000C
50+
cpusubtype: 0x00000002
51+
offset: 0x0000000000007000
52+
size: 384
53+
align: 12
54+
Slices:
55+
- !mach-o
56+
FileHeader:
57+
magic: 0xFEEDFACF
58+
cputype: 0x0100000C
59+
cpusubtype: 0x00000000
60+
filetype: 0x00000001
61+
ncmds: 0
62+
sizeofcmds: 0
63+
flags: 0x00000000
64+
reserved: 0x00000000
65+
- !mach-o
66+
FileHeader:
67+
magic: 0xFEEDFACF
68+
cputype: 0x0100000C
69+
cpusubtype: 0x00000001
70+
filetype: 0x00000001
71+
ncmds: 0
72+
sizeofcmds: 0
73+
flags: 0x00000000
74+
reserved: 0x00000000
75+
- !mach-o
76+
FileHeader:
77+
magic: 0xFEEDFACF
78+
cputype: 0x0100000C
79+
cpusubtype: 0x00000002
80+
filetype: 0x00000001
81+
ncmds: 0
82+
sizeofcmds: 0
83+
flags: 0x00000000
84+
reserved: 0x00000000
85+
...
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## Check subtype Arm64-ALL:
2+
# RUN: yaml2obj %s -o %t.arm64-all -DSUBTYPE=0x0
3+
# RUN: llvm-readobj -h %t.arm64-all \
4+
# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.arm64-all --check-prefix=ARM64 -DSUBTYPE="CPU_SUBTYPE_ARM64_ALL (0x0)"
5+
6+
## Check subtype Arm64-V8:
7+
# RUN: yaml2obj %s -o %t.arm64-v8 -DSUBTYPE=0x1
8+
# RUN: llvm-readobj -h %t.arm64-v8 \
9+
# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.arm64-v8 --check-prefix=ARM64 -DSUBTYPE="CPU_SUBTYPE_ARM64_V8 (0x1)"
10+
11+
## Check subtype Arm64E:
12+
# RUN: yaml2obj %s -o %t.arm64e -DSUBTYPE=0x2
13+
# RUN: llvm-readobj -h %t.arm64e \
14+
# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.arm64e --check-prefix=ARM64 -DSUBTYPE="CPU_SUBTYPE_ARM64E (0x2)"
15+
16+
# ARM64:File: [[FILE]]
17+
# ARM64-NEXT:Format: Mach-O arm64
18+
# ARM64-NEXT:Arch: aarch64
19+
# ARM64-NEXT:AddressSize: 64bit
20+
# ARM64-NEXT:MachHeader {
21+
# ARM64-NEXT: Magic: Magic64 (0xFEEDFACF)
22+
# ARM64-NEXT: CpuType: Arm64 (0x100000C)
23+
# ARM64-NEXT: CpuSubType: [[SUBTYPE]]
24+
# ARM64-NEXT: FileType: Relocatable (0x1)
25+
# ARM64-NEXT: NumOfLoadCommands: 0
26+
# ARM64-NEXT: SizeOfLoadCommands: 0
27+
# ARM64-NEXT: Flags [ (0x0)
28+
# ARM64-NEXT: ]
29+
# ARM64-NEXT: Reserved: 0x0
30+
# ARM64-NEXT:}
31+
# ARM64-NOT:{{.}}
32+
33+
--- !mach-o
34+
FileHeader:
35+
magic: 0xFEEDFACF
36+
cputype: 0x0100000C
37+
cpusubtype: [[SUBTYPE]]
38+
filetype: 0x00000001
39+
ncmds: 0
40+
sizeofcmds: 0
41+
flags: 0x00000000
42+
reserved: 0x00000000
43+
...

llvm/tools/llvm-objdump/MachODump.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,10 @@ static void printCPUType(uint32_t cputype, uint32_t cpusubtype) {
21092109
outs() << " cputype CPU_TYPE_ARM64\n";
21102110
outs() << " cpusubtype CPU_SUBTYPE_ARM64_ALL\n";
21112111
break;
2112+
case MachO::CPU_SUBTYPE_ARM64_V8:
2113+
outs() << " cputype CPU_TYPE_ARM64\n";
2114+
outs() << " cpusubtype CPU_SUBTYPE_ARM64_V8\n";
2115+
break;
21122116
case MachO::CPU_SUBTYPE_ARM64E:
21132117
outs() << " cputype CPU_TYPE_ARM64\n";
21142118
outs() << " cpusubtype CPU_SUBTYPE_ARM64E\n";
@@ -8315,6 +8319,9 @@ static void PrintMachHeader(uint32_t magic, uint32_t cputype,
83158319
case MachO::CPU_SUBTYPE_ARM64_ALL:
83168320
outs() << " ALL";
83178321
break;
8322+
case MachO::CPU_SUBTYPE_ARM64_V8:
8323+
outs() << " V8";
8324+
break;
83188325
case MachO::CPU_SUBTYPE_ARM64E:
83198326
outs() << " E";
83208327
break;

llvm/tools/llvm-readobj/MachODumper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ static const EnumEntry<uint32_t> MachOHeaderCpuSubtypesARM[] = {
161161
};
162162

163163
static const EnumEntry<uint32_t> MachOHeaderCpuSubtypesARM64[] = {
164-
LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64_ALL),
165-
LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64E),
164+
LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64_ALL),
165+
LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64_V8),
166+
LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64E),
166167
};
167168

168169
static const EnumEntry<uint32_t> MachOHeaderCpuSubtypesSPARC[] = {

0 commit comments

Comments
 (0)