[lld] [LLD][COFF] Require explicit specification of ARM64EC target (PR #116281)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 14 13:09:18 PST 2024
https://github.com/cjacek created https://github.com/llvm/llvm-project/pull/116281
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.
>From 016e991cd67e2018caaa21450fe19211925dc8f1 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Thu, 14 Nov 2024 22:00:18 +0100
Subject: [PATCH] [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.
---
lld/COFF/SymbolTable.cpp | 16 ++++++++++++----
lld/test/COFF/arm64ec.test | 6 +++++-
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 35d54d4945f7f4..db265e2bb37a04 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -46,6 +46,9 @@ static bool compatibleMachineType(COFFLinkerContext &ctx, MachineTypes mt) {
return COFF::isArm64EC(mt) || mt == AMD64;
case ARM64X:
return COFF::isAnyArm64(mt) || mt == AMD64;
+ case IMAGE_FILE_MACHINE_UNKNOWN:
+ // The ARM64EC target must be explicitly specified and cannot be inferred.
+ return !isArm64EC(mt);
default:
return ctx.config.machine == mt;
}
@@ -74,13 +77,18 @@ void SymbolTable::addFile(InputFile *file) {
}
MachineTypes mt = file->getMachineType();
+ if (!compatibleMachineType(ctx, mt)) {
+ if (isArm64EC(mt))
+ error(toString(file) + ": incompatible machine type " + machineToStr(mt) +
+ ", use /machine:arm64ec or /machine:arm64x");
+ else
+ error(toString(file) + ": machine type " + machineToStr(mt) +
+ " conflicts with " + machineToStr(ctx.config.machine));
+ return;
+ }
if (ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN) {
ctx.config.machine = mt;
ctx.driver.addWinSysRootLibSearchPaths();
- } else if (!compatibleMachineType(ctx, mt)) {
- error(toString(file) + ": machine type " + machineToStr(mt) +
- " conflicts with " + machineToStr(ctx.config.machine));
- return;
}
ctx.driver.parseDirectives(file);
diff --git a/lld/test/COFF/arm64ec.test b/lld/test/COFF/arm64ec.test
index e50b14ce0184c8..16b596b432b12f 100644
--- a/lld/test/COFF/arm64ec.test
+++ b/lld/test/COFF/arm64ec.test
@@ -36,7 +36,7 @@ ARM64X-DATA: 03030303 01010101 02020202
RUN: not lld-link -out:test.dll -machine:arm64 arm64-data-sym.obj arm64ec-data-sym.obj \
RUN: -dll -noentry 2>&1 | FileCheck -check-prefix=INCOMPAT1 %s
-INCOMPAT1: lld-link: error: arm64ec-data-sym.obj: machine type arm64ec conflicts with arm64
+INCOMPAT1: lld-link: error: arm64ec-data-sym.obj: incompatible machine type arm64ec, use /machine:arm64ec or /machine:arm64x
RUN: not lld-link -out:test.dll -machine:arm64ec arm64ec-data-sym.obj arm64-data-sym.obj \
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
RUN: -dll -noentry 2>&1 | FileCheck -check-prefix=INCOMPAT3 %s
INCOMPAT3: lld-link: error: x86_64-data-sym.obj: machine type x64 conflicts with arm64
+arm64ec machine type can't be inferred, it must be specified explicitly.
+RUN: not lld-link -out:test.dll arm64ec-data-sym.obj \
+RUN: -dll -noentry 2>&1 | FileCheck -check-prefix=INCOMPAT1 %s
+
#--- arm64ec-data-sym.s
.data
.globl arm64ec_data_sym
More information about the llvm-commits
mailing list