Index: lld/COFF/SymbolTable.cpp =================================================================== --- lld/COFF/SymbolTable.cpp +++ lld/COFF/SymbolTable.cpp @@ -34,6 +34,21 @@ return s; } +static bool compatibleMachineType(COFFLinkerContext &ctx, MachineTypes mt) { + if (mt == IMAGE_FILE_MACHINE_UNKNOWN) + return true; + switch (ctx.config.machine) { + case ARM64: + return mt == ARM64 || mt == ARM64X; + case ARM64EC: + return COFF::isArm64EC(mt) || mt == AMD64; + case ARM64X: + return COFF::isAnyArm64(mt) || mt == AMD64; + default: + return ctx.config.machine == mt; + } +} + void SymbolTable::addFile(InputFile *file) { log("Reading " + toString(file)); if (file->lazy) { @@ -56,7 +71,7 @@ if (ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN) { ctx.config.machine = mt; ctx.driver.addWinSysRootLibSearchPaths(); - } else if (mt != IMAGE_FILE_MACHINE_UNKNOWN && ctx.config.machine != mt) { + } else if (!compatibleMachineType(ctx, mt)) { error(toString(file) + ": machine type " + machineToStr(mt) + " conflicts with " + machineToStr(ctx.config.machine)); return; Index: lld/test/COFF/arm64ec.test =================================================================== --- lld/test/COFF/arm64ec.test +++ lld/test/COFF/arm64ec.test @@ -1,7 +1,9 @@ REQUIRES: aarch64 RUN: split-file %s %t.dir && cd %t.dir +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-cvtres -machine:arm64x -out:arm64x-resource.obj %S/Inputs/resource.res RUN: lld-link -out:test.dll -machine:arm64ec arm64ec-data-sym.obj -dll -noentry @@ -15,9 +17,40 @@ RUN: llvm-readobj --file-headers test.dll | FileCheck -check-prefix=ARM64X-HEADER %s ARM64X-HEADER: Machine: IMAGE_FILE_MACHINE_ARM64 (0xAA64) +arm64x object files are allowed with -machine:arm64 as well +RUN: lld-link -out:test.dll -machine:arm64 arm64x-resource.obj -dll -noentry + +RUN: lld-link -out:test.dll -machine:arm64ec arm64ec-data-sym.obj x86_64-data-sym.obj \ +RUN: arm64x-resource.obj -dll -noentry +RUN: llvm-readobj --file-headers test.dll | FileCheck -check-prefix=ARM64EC-HEADER %s + +RUN: llvm-readobj --hex-dump=.data test.dll | FileCheck -check-prefix=ARM64EC-DATA %s +ARM64EC-DATA: 02020202 03030303 + +RUN: lld-link -out:test.dll -machine:arm64x x86_64-data-sym.obj arm64-data-sym.obj \ +RUN: arm64ec-data-sym.obj arm64x-resource.obj -dll -noentry +RUN: llvm-readobj --file-headers test.dll | FileCheck -check-prefix=ARM64X-HEADER %s + +RUN: llvm-readobj --hex-dump=.data test.dll | FileCheck -check-prefix=ARM64X-DATA %s +ARM64X-DATA: 03030303 01010101 02020202 + #--- arm64ec-data-sym.s .data .globl arm64ec_data_sym .p2align 2, 0x0 arm64ec_data_sym: .word 0x02020202 + +#--- arm64-data-sym.s + .data + .globl arm64_data_sym + .p2align 2, 0x0 +arm64_data_sym: + .word 0x01010101 + +#--- x86_64-data-sym.s + .data + .globl x86_64_data_sym + .p2align 2, 0x0 +x86_64_data_sym: + .long 0x03030303