[lld] 5d7afd3 - [LLD][COFF] Add EC alias symbols for undefined x86_64 symbols on ARM64EC target (#114466)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 4 07:26:38 PST 2024
Author: Jacek Caban
Date: 2024-11-04T16:26:33+01:00
New Revision: 5d7afd324ad23e7b44ba82dbf38287e02002ceec
URL: https://github.com/llvm/llvm-project/commit/5d7afd324ad23e7b44ba82dbf38287e02002ceec
DIFF: https://github.com/llvm/llvm-project/commit/5d7afd324ad23e7b44ba82dbf38287e02002ceec.diff
LOG: [LLD][COFF] Add EC alias symbols for undefined x86_64 symbols on ARM64EC target (#114466)
Added:
Modified:
lld/COFF/InputFiles.cpp
lld/test/COFF/arm64ec-entry-mangle.test
Removed:
################################################################################
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index b2ea4bdfe64e3c..4b2d6e511df1a1 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,
+ /*overrideLazy=*/false);
+ u->setWeakAlias(m, /*antiDep=*/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