Skip to content

Commit 016e991

Browse files
committed
[LLD][COFF] Require explicit specification of ARM64EC target
Inferring the ARM64EC target can lead to errors. The `-machine:arm64ec` option may include x86_64 input files, and any valid ARM64EC input is also valid for `-machine:arm64x`. MSVC requires an explicit `-machine` argument with informative diagnostics; this patch adopts the same behavior.
1 parent 4610e5c commit 016e991

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

lld/COFF/SymbolTable.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ static bool compatibleMachineType(COFFLinkerContext &ctx, MachineTypes mt) {
4646
return COFF::isArm64EC(mt) || mt == AMD64;
4747
case ARM64X:
4848
return COFF::isAnyArm64(mt) || mt == AMD64;
49+
case IMAGE_FILE_MACHINE_UNKNOWN:
50+
// The ARM64EC target must be explicitly specified and cannot be inferred.
51+
return !isArm64EC(mt);
4952
default:
5053
return ctx.config.machine == mt;
5154
}
@@ -74,13 +77,18 @@ void SymbolTable::addFile(InputFile *file) {
7477
}
7578

7679
MachineTypes mt = file->getMachineType();
80+
if (!compatibleMachineType(ctx, mt)) {
81+
if (isArm64EC(mt))
82+
error(toString(file) + ": incompatible machine type " + machineToStr(mt) +
83+
", use /machine:arm64ec or /machine:arm64x");
84+
else
85+
error(toString(file) + ": machine type " + machineToStr(mt) +
86+
" conflicts with " + machineToStr(ctx.config.machine));
87+
return;
88+
}
7789
if (ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN) {
7890
ctx.config.machine = mt;
7991
ctx.driver.addWinSysRootLibSearchPaths();
80-
} else if (!compatibleMachineType(ctx, mt)) {
81-
error(toString(file) + ": machine type " + machineToStr(mt) +
82-
" conflicts with " + machineToStr(ctx.config.machine));
83-
return;
8492
}
8593

8694
ctx.driver.parseDirectives(file);

lld/test/COFF/arm64ec.test

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ARM64X-DATA: 03030303 01010101 02020202
3636

3737
RUN: not lld-link -out:test.dll -machine:arm64 arm64-data-sym.obj arm64ec-data-sym.obj \
3838
RUN: -dll -noentry 2>&1 | FileCheck -check-prefix=INCOMPAT1 %s
39-
INCOMPAT1: lld-link: error: arm64ec-data-sym.obj: machine type arm64ec conflicts with arm64
39+
INCOMPAT1: lld-link: error: arm64ec-data-sym.obj: incompatible machine type arm64ec, use /machine:arm64ec or /machine:arm64x
4040

4141
RUN: not lld-link -out:test.dll -machine:arm64ec arm64ec-data-sym.obj arm64-data-sym.obj \
4242
RUN: -dll -noentry 2>&1 | FileCheck -check-prefix=INCOMPAT2 %s
@@ -46,6 +46,10 @@ RUN: not lld-link -out:test.dll -machine:arm64 arm64-data-sym.obj x86_64-data-sy
4646
RUN: -dll -noentry 2>&1 | FileCheck -check-prefix=INCOMPAT3 %s
4747
INCOMPAT3: lld-link: error: x86_64-data-sym.obj: machine type x64 conflicts with arm64
4848

49+
arm64ec machine type can't be inferred, it must be specified explicitly.
50+
RUN: not lld-link -out:test.dll arm64ec-data-sym.obj \
51+
RUN: -dll -noentry 2>&1 | FileCheck -check-prefix=INCOMPAT1 %s
52+
4953
#--- arm64ec-data-sym.s
5054
.data
5155
.globl arm64ec_data_sym

0 commit comments

Comments
 (0)