diff --git a/lld/test/COFF/arm64ec.test b/lld/test/COFF/arm64ec.test --- a/lld/test/COFF/arm64ec.test +++ b/lld/test/COFF/arm64ec.test @@ -4,6 +4,9 @@ RUN: llvm-mc -filetype=obj -triple=aarch64-windows arm64-data-sym.s -o arm64-data-sym.obj RUN: llvm-mc -filetype=obj -triple=arm64ec-windows arm64ec-data-sym.s -o arm64ec-data-sym.obj RUN: llvm-mc -filetype=obj -triple=x86_64-windows x86_64-data-sym.s -o x86_64-data-sym.obj +RUN: llvm-mc -filetype=obj -triple=arm64ec-windows arm64ec-func-sym.s -o arm64ec-func-sym.obj +RUN: llvm-mc -filetype=obj -triple=x86_64-windows x86_64-func-sym.s -o x86_64-func-sym.obj +RUN: llvm-mc -filetype=obj -triple=arm64ec-windows arm64ec-loadcfg.s -o arm64ec-loadcfg.obj RUN: lld-link -out:test.dll -machine:arm64ec arm64ec-data-sym.obj -dll -noentry RUN: llvm-readobj --file-headers test.dll | FileCheck -check-prefix=ARM64EC-HEADER %s @@ -28,6 +31,17 @@ RUN: llvm-readobj --hex-dump=.data test.dll | FileCheck -check-prefix=ARM64X-DATA %s ARM64X-DATA: 03030303 01010101 02020202 +RUN: lld-link -out:test.dll -machine:arm64ec arm64ec-func-sym.obj x86_64-func-sym.obj arm64ec-loadcfg.obj -dll -noentry +RUN: llvm-objdump -d test.dll | FileCheck -check-prefix=DISAS %s +DISAS: file format coff-arm64ec +DISAS: 180001000: 52800040 mov w0, #0x2 +DISAS-NEXT: 180001004: d65f03c0 ret +DISAS-NEXT: ... +DISAS: 180005000: 528000a0 mov w0, #0x5 +DISAS-NEXT: 180005004: d65f03c0 ret +DISAS-NEXT: ... + + #--- arm64ec-data-sym.s .data .globl arm64ec_data_sym @@ -48,3 +62,61 @@ .p2align 2, 0x0 x86_64_data_sym: .long 0x03030303 + +#--- arm64ec-func-sym.s + .text + .globl arm64ec_func_sym + .p2align 2, 0x0 +arm64ec_func_sym: + mov w0, #2 + ret + + .section test, "xr" + .globl arm64ec_func_sym2 + .p2align 2, 0x0 +arm64ec_func_sym2: + mov w0, #5 + ret + +#--- x86_64-func-sym.s + .text + .globl x86_64_func_sym + .p2align 12, 0x0 +x86_64_func_sym: + movl $3, %eax + retq + + .section test, "xr" + .globl x86_64_func_sym2 + .p2align 12, 0x0 +x86_64_func_sym2: + movl $6, %eax + retq + +#--- arm64ec-loadcfg.s + .section .rdata,"dr" + .globl _load_config_used + .p2align 3, 0 +_load_config_used: + .word 0x140 + .fill 0xc4, 1, 0 + .xword __chpe_metadata + .fill 0x78, 1, 0 + + .data + .globl __chpe_metadata + .p2align 2, 0 +__chpe_metadata: + .word 1 + .rva __code_map + .word 4 + .fill 0x44, 1, 0 +__code_map: + .rva arm64ec_func_sym + 1 + .word 8 + .rva x86_64_func_sym + 2 + .word 6 + .rva arm64ec_func_sym2 + 1 + .word 8 + .rva x86_64_func_sym2 + 2 + .word 6 diff --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h --- a/llvm/include/llvm/Object/COFF.h +++ b/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!");