Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lld/COFF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions lld/test/COFF/arm64ec-entry-mangle.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Loading