diff --git a/llvm/include/llvm/BinaryFormat/MachO.h b/llvm/include/llvm/BinaryFormat/MachO.h --- a/llvm/include/llvm/BinaryFormat/MachO.h +++ b/llvm/include/llvm/BinaryFormat/MachO.h @@ -1492,6 +1492,7 @@ enum CPUSubTypeARM64 { CPU_SUBTYPE_ARM64_ALL = 0, + CPU_SUBTYPE_ARM64_V8 = 1, CPU_SUBTYPE_ARM64E = 2, }; diff --git a/llvm/test/tools/llvm-objdump/MachO/AArch64/macho-arm64-subtypes.test b/llvm/test/tools/llvm-objdump/MachO/AArch64/macho-arm64-subtypes.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/MachO/AArch64/macho-arm64-subtypes.test @@ -0,0 +1,26 @@ +# RUN: yaml2obj %s -o %tarm64-all.o -DSUBTYPE=0x0 +# RUN: llvm-objdump -p %tarm64-all.o | FileCheck --strict-whitespace %s --check-prefixes="COMMON,ALL" + +# RUN: yaml2obj %s -o %tarm64-v8.o -DSUBTYPE=0x1 +# RUN: llvm-objdump -p %tarm64-v8.o | FileCheck --strict-whitespace %s --check-prefixes="COMMON,V8" + +# RUN: yaml2obj %s -o %tarm64e.o -DSUBTYPE=0x2 +# RUN: llvm-objdump -p %tarm64e.o | FileCheck --strict-whitespace %s --check-prefixes="COMMON,E" + +# COMMON: Mach header +# COMMON-NEXT: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags +# ALL-NEXT: MH_MAGIC_64 ARM64 ALL 0x00 OBJECT 0 0 0x00000000 +# V8-NEXT: MH_MAGIC_64 ARM64 V8 0x00 OBJECT 0 0 0x00000000 +# E-NEXT: MH_MAGIC_64 ARM64 E 0x00 OBJECT 0 0 0x00000000 + +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x0100000C + cpusubtype: [[SUBTYPE]] + filetype: 0x00000001 + ncmds: 0 + sizeofcmds: 0 + flags: 0x00000000 + reserved: 0x00000000 +... diff --git a/llvm/test/tools/llvm-objdump/MachO/AArch64/macho-arm64e.test b/llvm/test/tools/llvm-objdump/MachO/AArch64/macho-arm64e.test deleted file mode 100644 --- a/llvm/test/tools/llvm-objdump/MachO/AArch64/macho-arm64e.test +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: yaml2obj %p/Inputs/arm64e.macho.yaml -o %tarm64e.o -// RUN: llvm-objdump -p %tarm64e.o | FileCheck --strict-whitespace %s - -CHECK: Mach header -CHECK-NEXT: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags -CHECK-NEXT: MH_MAGIC_64 ARM64 E 0x00 OBJECT 0 0 0x00000000 diff --git a/llvm/test/tools/llvm-objdump/MachO/universal-arm64.test b/llvm/test/tools/llvm-objdump/MachO/universal-arm64.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/MachO/universal-arm64.test @@ -0,0 +1,85 @@ +## This test checks that the CPUTypes are printed correctly for the subtypes of +## ARM64. + +# RUN: yaml2obj %s -o %tarm.o +# RUN: llvm-objdump %tarm.o --universal-headers --macho | \ +# RUN: FileCheck %s --check-prefix=FAT --match-full-lines + +# FAT: Fat headers +# FAT-NEXT: fat_magic FAT_MAGIC +# FAT-NEXT: nfat_arch 3 +# FAT-NEXT: architecture arm64 +# FAT-NEXT: cputype CPU_TYPE_ARM64 +# FAT-NEXT: cpusubtype CPU_SUBTYPE_ARM64_ALL +# FAT-NEXT: capabilities 0x0 +# FAT-NEXT: offset 4096 +# FAT-NEXT: size 352 +# FAT-NEXT: align 2^12 (4096) +# FAT-NEXT: architecture +# FAT-NEXT: cputype CPU_TYPE_ARM64 +# FAT-NEXT: cpusubtype CPU_SUBTYPE_ARM64_V8 +# FAT-NEXT: capabilities 0x0 +# FAT-NEXT: offset 16384 +# FAT-NEXT: size 384 +# FAT-NEXT: align 2^14 (16384) +# FAT-NEXT: architecture +# FAT-NEXT: cputype CPU_TYPE_ARM64 +# FAT-NEXT: cpusubtype CPU_SUBTYPE_ARM64E +# FAT-NEXT: capabilities 0x0 +# FAT-NEXT: offset 28672 +# FAT-NEXT: size 384 +# FAT-NEXT: align 2^12 (4096) +# FAT-NOT:{{.}} + +--- !fat-mach-o +FatHeader: + magic: 0xCAFEBABE + nfat_arch: 3 +FatArchs: + - cputype: 0x0100000C + cpusubtype: 0x00000000 + offset: 0x0000000000001000 + size: 352 + align: 12 + - cputype: 0x0100000C + cpusubtype: 0x00000001 + offset: 0x0000000000004000 + size: 384 + align: 14 + - cputype: 0x0100000C + cpusubtype: 0x00000002 + offset: 0x0000000000007000 + size: 384 + align: 12 +Slices: + - !mach-o + FileHeader: + magic: 0xFEEDFACF + cputype: 0x0100000C + cpusubtype: 0x00000000 + filetype: 0x00000001 + ncmds: 0 + sizeofcmds: 0 + flags: 0x00000000 + reserved: 0x00000000 + - !mach-o + FileHeader: + magic: 0xFEEDFACF + cputype: 0x0100000C + cpusubtype: 0x00000001 + filetype: 0x00000001 + ncmds: 0 + sizeofcmds: 0 + flags: 0x00000000 + reserved: 0x00000000 + - !mach-o + FileHeader: + magic: 0xFEEDFACF + cputype: 0x0100000C + cpusubtype: 0x00000002 + filetype: 0x00000001 + ncmds: 0 + sizeofcmds: 0 + flags: 0x00000000 + reserved: 0x00000000 +... diff --git a/llvm/test/tools/llvm-readobj/MachO/file-headers-arm64.test b/llvm/test/tools/llvm-readobj/MachO/file-headers-arm64.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-readobj/MachO/file-headers-arm64.test @@ -0,0 +1,43 @@ +## Check subtype Arm64-ALL: +# RUN: yaml2obj %s -o %t.arm64-all -DSUBTYPE=0x0 +# RUN: llvm-readobj -h %t.arm64-all \ +# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.arm64-all --check-prefix=ARM64 -DSUBTYPE="CPU_SUBTYPE_ARM64_ALL (0x0)" + +## Check subtype Arm64-V8: +# RUN: yaml2obj %s -o %t.arm64-v8 -DSUBTYPE=0x1 +# RUN: llvm-readobj -h %t.arm64-v8 \ +# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.arm64-v8 --check-prefix=ARM64 -DSUBTYPE="CPU_SUBTYPE_ARM64_V8 (0x1)" + +## Check subtype Arm64E: +# RUN: yaml2obj %s -o %t.arm64e -DSUBTYPE=0x2 +# RUN: llvm-readobj -h %t.arm64e \ +# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.arm64e --check-prefix=ARM64 -DSUBTYPE="CPU_SUBTYPE_ARM64E (0x2)" + +# ARM64:File: [[FILE]] +# ARM64-NEXT:Format: Mach-O arm64 +# ARM64-NEXT:Arch: aarch64 +# ARM64-NEXT:AddressSize: 64bit +# ARM64-NEXT:MachHeader { +# ARM64-NEXT: Magic: Magic64 (0xFEEDFACF) +# ARM64-NEXT: CpuType: Arm64 (0x100000C) +# ARM64-NEXT: CpuSubType: [[SUBTYPE]] +# ARM64-NEXT: FileType: Relocatable (0x1) +# ARM64-NEXT: NumOfLoadCommands: 0 +# ARM64-NEXT: SizeOfLoadCommands: 0 +# ARM64-NEXT: Flags [ (0x0) +# ARM64-NEXT: ] +# ARM64-NEXT: Reserved: 0x0 +# ARM64-NEXT:} +# ARM64-NOT:{{.}} + +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x0100000C + cpusubtype: [[SUBTYPE]] + filetype: 0x00000001 + ncmds: 0 + sizeofcmds: 0 + flags: 0x00000000 + reserved: 0x00000000 +... diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -2109,6 +2109,10 @@ outs() << " cputype CPU_TYPE_ARM64\n"; outs() << " cpusubtype CPU_SUBTYPE_ARM64_ALL\n"; break; + case MachO::CPU_SUBTYPE_ARM64_V8: + outs() << " cputype CPU_TYPE_ARM64\n"; + outs() << " cpusubtype CPU_SUBTYPE_ARM64_V8\n"; + break; case MachO::CPU_SUBTYPE_ARM64E: outs() << " cputype CPU_TYPE_ARM64\n"; outs() << " cpusubtype CPU_SUBTYPE_ARM64E\n"; @@ -8315,6 +8319,9 @@ case MachO::CPU_SUBTYPE_ARM64_ALL: outs() << " ALL"; break; + case MachO::CPU_SUBTYPE_ARM64_V8: + outs() << " V8"; + break; case MachO::CPU_SUBTYPE_ARM64E: outs() << " E"; break; diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp --- a/llvm/tools/llvm-readobj/MachODumper.cpp +++ b/llvm/tools/llvm-readobj/MachODumper.cpp @@ -161,8 +161,9 @@ }; static const EnumEntry MachOHeaderCpuSubtypesARM64[] = { - LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64_ALL), - LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64E), + LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64_ALL), + LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64_V8), + LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64E), }; static const EnumEntry MachOHeaderCpuSubtypesSPARC[] = {