[lld] [LLD][COFF] Add EC alias symbols for undefined x86_64 symbols on ARM64EC target (PR #114466)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 31 14:17:12 PDT 2024


https://github.com/cjacek created https://github.com/llvm/llvm-project/pull/114466

None

>From 0a230053f7a91676a0d4f51f8b58d6800a34a807 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Mon, 20 May 2024 21:00:31 +0200
Subject: [PATCH] [LLD][COFF] Add EC alias symbols for undefined x86_64 symbols
 on ARM64EC target

---
 lld/COFF/InputFiles.cpp                 | 17 ++++++++++++++++-
 lld/test/COFF/arm64ec-entry-mangle.test |  9 +++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index b2ea4bdfe64e3c..b84ead61e25585 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -534,7 +534,22 @@ void ObjFile::initializeSymbols() {
 
 Symbol *ObjFile::createUndefined(COFFSymbolRef sym, bool overrideLazy) {
   StringRef name = check(coffObj->getSymbolName(sym));
-  return ctx.symtab.addUndefined(name, this, overrideLazy);
+  Symbol *s = ctx.symtab.addUndefined(name, this, overrideLazy);
+
+  // Add an anti-dependency alias for undefined AMD64 symbols on the ARM64EC
+  // target.
+  if (isArm64EC(ctx.config.machine) && getMachineType() == AMD64) {
+    auto u = dyn_cast<Undefined>(s);
+    if (u && !u->weakAlias) {
+      if (std::optional<std::string> mangledName =
+              getArm64ECMangledFunctionName(name)) {
+        Symbol *m =
+            ctx.symtab.addUndefined(saver().save(*mangledName), this, false);
+        u->setWeakAlias(m, true);
+      }
+    }
+  }
+  return s;
 }
 
 static const coff_aux_section_definition *findSectionDef(COFFObjectFile *obj,
diff --git a/lld/test/COFF/arm64ec-entry-mangle.test b/lld/test/COFF/arm64ec-entry-mangle.test
index 65283f16d02fa9..6db16ef218dc8b 100644
--- a/lld/test/COFF/arm64ec-entry-mangle.test
+++ b/lld/test/COFF/arm64ec-entry-mangle.test
@@ -8,6 +8,7 @@ RUN: llvm-mc -filetype=obj -triple=arm64ec-windows mangled-func.s -o mangled-fun
 RUN: llvm-mc -filetype=obj -triple=arm64ec-windows ref-demangled.s -o ref-demangled.obj
 RUN: llvm-mc -filetype=obj -triple=arm64ec-windows demangled-entry-drectve.s -o demangled-entry-drectve.obj
 RUN: llvm-mc -filetype=obj -triple=x86_64-windows demangled-dll-main.s -o x64-dll-main.obj
+RUN: llvm-mc -filetype=obj -triple=x86_64-windows ref-demangled.s -o ref-x64.obj
 RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o loadconfig-arm64ec.obj
 
 RUN: llvm-lib -machine:arm64ec -out:func.lib mangled-func.obj
@@ -80,6 +81,14 @@ RUN: lld-link -machine:arm64ec -dll -noentry -out:demangled-export-ref.dll mangl
 RUN:          ref-demangled.obj loadconfig-arm64ec.obj "-export:#func"
 RUN: llvm-objdump -d demangled-export-ref.dll | FileCheck -check-prefix=DISASM %s
 
+Verify that an x86_64 object file can reference ARM64EC mangled functions without requiring an explicit alias.
+RUN: lld-link -machine:arm64ec -dll -noentry -out:x64-ref.dll mangled-func.obj ref-x64.obj loadconfig-arm64ec.obj
+RUN: llvm-objdump -d x64-ref.dll | FileCheck -check-prefix=DISASM2 %s
+
+Verify that an x86_64 object file can reference ARM64EC mangled functions provided by a library.
+RUN: lld-link -machine:arm64ec -dll -noentry -out:x64-lib-ref.dll func.lib ref-x64.obj loadconfig-arm64ec.obj
+RUN: llvm-objdump -d x64-lib-ref.dll | FileCheck -check-prefix=DISASM2 %s
+
 DISASM2:      0000000180001000 <.text>:
 DISASM2-NEXT: 180001000: d65f03c0     ret
 



More information about the llvm-commits mailing list