[llvm] c33397f - Recognize ARM64EC binaries in COFFObjectFile::getMachine.
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 24 11:42:12 PDT 2023
Author: Jacek Caban
Date: 2023-07-24T20:41:20+02:00
New Revision: c33397f7127d2d192ee4f005d8bb373a10ec6206
URL: https://github.com/llvm/llvm-project/commit/c33397f7127d2d192ee4f005d8bb373a10ec6206
DIFF: https://github.com/llvm/llvm-project/commit/c33397f7127d2d192ee4f005d8bb373a10ec6206.diff
LOG: Recognize ARM64EC binaries in COFFObjectFile::getMachine.
ARM64EC/ARM64X binaries use ARM64 or AMD64 machine types, but provide
additional CHPE metadata that may be used to distinguish them from
pure ARM64/AMD64 binaries.
Reviewed By: jhenderson, MaskRay, mstorsjo
Differential Revision: https://reviews.llvm.org/D149091
Added:
llvm/test/tools/llvm-objdump/COFF/arm64ec.yaml
Modified:
llvm/include/llvm/Object/COFF.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h
index e6a607921da0ef..4bad7f10323c20 100644
--- a/llvm/include/llvm/Object/COFF.h
+++ b/llvm/include/llvm/Object/COFF.h
@@ -888,8 +888,17 @@ class COFFObjectFile : public ObjectFile {
}
uint16_t getMachine() const {
- if (COFFHeader)
+ if (COFFHeader) {
+ if (CHPEMetadata) {
+ switch (COFFHeader->Machine) {
+ case COFF::IMAGE_FILE_MACHINE_AMD64:
+ return COFF::IMAGE_FILE_MACHINE_ARM64EC;
+ case COFF::IMAGE_FILE_MACHINE_ARM64:
+ return COFF::IMAGE_FILE_MACHINE_ARM64X;
+ }
+ }
return COFFHeader->Machine;
+ }
if (COFFBigObjHeader)
return COFFBigObjHeader->Machine;
llvm_unreachable("no COFF header!");
diff --git a/llvm/test/tools/llvm-objdump/COFF/arm64ec.yaml b/llvm/test/tools/llvm-objdump/COFF/arm64ec.yaml
new file mode 100644
index 00000000000000..5c58ae6c2c732c
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/COFF/arm64ec.yaml
@@ -0,0 +1,88 @@
+## Check that AMD64 image file with CHPE data is recognized as ARM64EC.
+# RUN: yaml2obj %s -o %t -DMACHINE=IMAGE_FILE_MACHINE_AMD64
+# RUN: llvm-objdump -d %t | FileCheck --check-prefixes=DISASM,ARM64EC %s
+# RUN: llvm-readobj --coff-load-config %t | FileCheck --check-prefix=CODEMAP %s
+
+## Check that ARM64 image file with CHPE data is recognized as ARM64X.
+# RUN: yaml2obj %s -o %t -DMACHINE=IMAGE_FILE_MACHINE_ARM64
+# RUN: llvm-objdump -d %t | FileCheck --check-prefixes=DISASM,ARM64X %s
+# RUN: llvm-readobj --coff-load-config %t | FileCheck --check-prefix=CODEMAP %s
+
+# ARM64EC: file format coff-arm64ec
+# ARM64X: file format coff-arm64x
+
+# DISASM: 180001000: 52800040 mov w0, #0x2
+# DISASM-NEXT: 180001004: d65f03c0 ret
+# DISASM-NEXT: ...
+# DISASM: 180002020: 528000a0 mov w0, #0x5
+# DISASM-NEXT: 180002024: d65f03c0 ret
+
+# CODEMAP: CodeMap [
+# CODEMAP-NEXT: 0x1000 - 0x1008 ARM64EC
+# CODEMAP-NEXT: 0x1020 - 0x2007 X64
+# CODEMAP-NEXT: 0x2020 - 0x2028 ARM64EC
+# CODEMAP-NEXT: ]
+
+--- !COFF
+OptionalHeader:
+ ImageBase: 0x180000000
+ SectionAlignment: 4096
+ FileAlignment: 512
+ DLLCharacteristics: [ ]
+ LoadConfigTable:
+ RelativeVirtualAddress: 0x3000
+ Size: 320
+header:
+ Machine: [[MACHINE]]
+ Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE, IMAGE_FILE_DLL ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ VirtualAddress: 0x1000
+ VirtualSize: 38
+ SectionData: 40008052C0035FD6000000000000000000000000000000000000000000000000B803000000C3
+ - Name: .test
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ VirtualAddress: 0x2000
+ VirtualSize: 40
+ SectionData: B806000000C3CC00000000000000000000000000000000000000000000000000A0008052C0035FD6
+ - Name: .rdata
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+ VirtualAddress: 0x3000
+ VirtualSize: 328
+ StructuredData:
+ - LoadConfig:
+ CHPEMetadataPointer: 0x180004000
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ VirtualAddress: 0x4000
+ VirtualSize: 112
+ StructuredData:
+ - UInt32: 1 # Version
+ - UInt32: 0x4050 # CodeMap
+ - UInt32: 3 # CodeMapCount
+ - UInt32: 0 # CodeRangesToEntryPoints
+ - UInt32: 0 # RedirectionMetadata
+ - UInt32: 0
+ - UInt32: 0
+ - UInt32: 0
+ - UInt32: 0
+ - UInt32: 0
+ - UInt32: 0
+ - UInt32: 0
+ - UInt32: 0 # CodeRangesToEntryPointsCount
+ - UInt32: 0 # RedirectionMetadataCount
+ - UInt32: 0
+ - UInt32: 0
+ - UInt32: 0
+ - UInt32: 0
+ - UInt32: 0
+ - UInt32: 0
+ - UInt32: 0x1001 # CodeMap[0]
+ - UInt32: 0x8
+ - UInt32: 0x1022 # CodeMap[1]
+ - UInt32: 0x0fe7
+ - UInt32: 0x2021 # CodeMap[2]
+ - UInt32: 0x8
+symbols: []
+...
More information about the llvm-commits
mailing list