Skip to content

Commit cdda76a

Browse files
authoredNov 15, 2024
[LLD][COFF] Fix handling of invalid ARM64EC function names (#116252)
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 #115567.
1 parent 1cab8d9 commit cdda76a

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed
 

‎lld/COFF/Driver.cpp

+2-3
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

+4-1
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

+15
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)