[PATCH] D149091: [Object] Recognize ARM64EC binaries in COFFObjectFile::getMachine.
Jacek Caban via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 25 06:31:46 PDT 2023
jacek updated this revision to Diff 516771.
jacek added a comment.
Herald added a subscriber: MaskRay.
Herald added a reviewer: MaskRay.
Thanks for reviews. The new version uses yaml2obj instead of lld-link. Previous tests will be useful for testing lld-link itself, but I will send it later, probably together with code range generation support.
yaml-based test is a bit less similar to real-world binaries. Linker should align code boundaries to page size, but doing that with yaml SectionData makes it hard to follow. I just used much smaller alignment, it shouldn't matter for disassembler anyway.
CHPE and load config are quite hard to read. I guess we could have some helper syntax for that in yaml2obj, but it's not clear to me how it should look like. Unlike other things like PE headers, load config and CHPE metadata are part of .data/.rdata sections (so it would need to alter SectionData content) and we'd need some way of referencing it (unless we'd still hard-code RVAs). I will investigate if further if you prefer.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149091/new/
https://reviews.llvm.org/D149091
Files:
llvm/include/llvm/Object/COFF.h
llvm/test/tools/llvm-objdump/arm64ec.yaml
Index: llvm/test/tools/llvm-objdump/arm64ec.yaml
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/arm64ec.yaml
@@ -0,0 +1,45 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-objdump -d %t | FileCheck -check-prefix=DISAS %s
+
+# DISAS: file format coff-arm64ec
+# DISAS: 180001000: 52800040 mov w0, #0x2
+# DISAS-NEXT: 180001004: d65f03c0 ret
+# DISAS-NEXT: ...
+# DISAS: 180002020: 528000a0 mov w0, #0x5
+# DISAS-NEXT: 180002024: d65f03c0 ret
+
+--- !COFF
+OptionalHeader:
+ ImageBase: 0x180000000
+ SectionAlignment: 4096
+ FileAlignment: 512
+ DLLCharacteristics: [ ]
+ LoadConfigTable:
+ RelativeVirtualAddress: 0x3000
+ Size: 320
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ 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
+ SectionData: '40010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040008001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ VirtualAddress: 0x4000
+ VirtualSize: 112
+ SectionData: '0100000050400000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011000000800000022100000e70f00002120000008000000'
+symbols: []
+...
Index: llvm/include/llvm/Object/COFF.h
===================================================================
--- llvm/include/llvm/Object/COFF.h
+++ llvm/include/llvm/Object/COFF.h
@@ -888,8 +888,17 @@
}
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!");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149091.516771.patch
Type: text/x-patch
Size: 3464 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230425/1689cae2/attachment.bin>
More information about the llvm-commits
mailing list