Skip to content

[LLD][COFF] Fix handling of invalid ARM64EC function names #116252

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 15, 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
5 changes: 2 additions & 3 deletions lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,8 @@ Symbol *LinkerDriver::addUndefined(StringRef name, bool aliasEC) {
Symbol *t = ctx.symtab.addUndefined(saver().save(*mangledName));
u->setWeakAlias(t, true);
}
} else {
std::optional<std::string> demangledName =
getArm64ECDemangledFunctionName(name);
} else if (std::optional<std::string> demangledName =
getArm64ECDemangledFunctionName(name)) {
Symbol *us = ctx.symtab.addUndefined(saver().save(*demangledName));
auto u = dyn_cast<Undefined>(us);
if (u && !u->weakAlias)
Expand Down
5 changes: 4 additions & 1 deletion lld/COFF/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,11 @@ bool checkLazyECPair(SymbolTable *symtab, StringRef name, InputFile *f) {
if (std::optional<std::string> mangledName =
getArm64ECMangledFunctionName(name))
pairName = std::move(*mangledName);
else if (std::optional<std::string> demangledName =
getArm64ECDemangledFunctionName(name))
pairName = std::move(*demangledName);
else
pairName = *getArm64ECDemangledFunctionName(name);
return true;

Symbol *sym = symtab->find(pairName);
if (!sym)
Expand Down
15 changes: 15 additions & 0 deletions lld/test/COFF/arm64ec-invalid-name.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// REQUIRES: aarch64

// Verify that an error is emitted when attempting to export an invalid function name.
// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %s -o %t.obj
// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o %t-loadconfig.obj
// RUN: not lld-link -machine:arm64ec -dll -noentry "-export:?func" %t-loadconfig.obj %t.obj 2>&1 | FileCheck %s
// CHECK: error: Invalid ARM64EC function name '?func'

// Verify that we can handle an invalid function name in the archive map.
// RUN: llvm-lib -machine:arm64ec -out:%t.lib %t.obj
// RUN: lld-link -machine:arm64ec -dll -noentry %t-loadconfig.obj %t.lib

.globl "?func"
"?func":
ret
Loading