[lld] [LLD][COFF] Require explicit specification of ARM64EC target (PR #116281)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 14 13:09:52 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-coff

Author: Jacek Caban (cjacek)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/116281.diff


2 Files Affected:

- (modified) lld/COFF/SymbolTable.cpp (+12-4) 
- (modified) lld/test/COFF/arm64ec.test (+5-1) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/116281


More information about the llvm-commits mailing list