Skip to content

Commit e086990

Browse files
committed
[LLD][COFF] Fix handling of invalid ARM64EC function names
Since these symbols cannot be mangled or demangled, there is no symbol to check for conflicts in checkLazyECPair, nor is there an alias to create in addUndefined. Attempting to create an import library with such symbols results in an error; the patch includes a test to ensure the error is handled correctly. This is a follow-up to llvm#115567.
1 parent a9d9483 commit e086990

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

lld/COFF/Driver.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,8 @@ Symbol *LinkerDriver::addUndefined(StringRef name, bool aliasEC) {
714714
Symbol *t = ctx.symtab.addUndefined(saver().save(*mangledName));
715715
u->setWeakAlias(t, true);
716716
}
717-
} else {
718-
std::optional<std::string> demangledName =
719-
getArm64ECDemangledFunctionName(name);
717+
} else if (std::optional<std::string> demangledName =
718+
getArm64ECDemangledFunctionName(name)) {
720719
Symbol *us = ctx.symtab.addUndefined(saver().save(*demangledName));
721720
auto u = dyn_cast<Undefined>(us);
722721
if (u && !u->weakAlias)

lld/COFF/SymbolTable.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,11 @@ bool checkLazyECPair(SymbolTable *symtab, StringRef name, InputFile *f) {
669669
if (std::optional<std::string> mangledName =
670670
getArm64ECMangledFunctionName(name))
671671
pairName = std::move(*mangledName);
672+
else if (std::optional<std::string> demangledName =
673+
getArm64ECDemangledFunctionName(name))
674+
pairName = std::move(*demangledName);
672675
else
673-
pairName = *getArm64ECDemangledFunctionName(name);
676+
return true;
674677

675678
Symbol *sym = symtab->find(pairName);
676679
if (!sym)

lld/test/COFF/arm64ec-invalid-name.s

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// REQUIRES: aarch64
2+
3+
// Verify that an error is emitted when attempting to export an invalid function name.
4+
// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %s -o %t.obj
5+
// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o %t-loadconfig.obj
6+
// RUN: not lld-link -machine:arm64ec -dll -noentry "-export:?func" %t-loadconfig.obj %t.obj 2>&1 | FileCheck %s
7+
// CHECK: error: Invalid ARM64EC function name '?func'
8+
9+
// Verify that we can handle an invalid function name in the archive map.
10+
// RUN: llvm-lib -machine:arm64ec -out:%t.lib %t.obj
11+
// RUN: lld-link -machine:arm64ec -dll -noentry %t-loadconfig.obj %t.lib
12+
13+
.globl "?func"
14+
"?func":
15+
ret

0 commit comments

Comments
 (0)