[lld] cdda76a - [LLD][COFF] Fix handling of invalid ARM64EC function names (#116252)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 07:42:39 PST 2024


Author: Jacek Caban
Date: 2024-11-15T16:42:36+01:00
New Revision: cdda76a8cfc3b0c5def836f68f6f58efba03e01c

URL: https://github.com/llvm/llvm-project/commit/cdda76a8cfc3b0c5def836f68f6f58efba03e01c
DIFF: https://github.com/llvm/llvm-project/commit/cdda76a8cfc3b0c5def836f68f6f58efba03e01c.diff

LOG: [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.

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

Modified: 
    lld/COFF/Driver.cpp
    lld/COFF/SymbolTable.cpp

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index ec8ac814d31562..d6d6cc8f394f0c 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -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)

diff  --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 35d54d4945f7f4..df3c5a176b52e0 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -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)

diff  --git a/lld/test/COFF/arm64ec-invalid-name.s b/lld/test/COFF/arm64ec-invalid-name.s
new file mode 100644
index 00000000000000..043d39e0c8089c
--- /dev/null
+++ b/lld/test/COFF/arm64ec-invalid-name.s
@@ -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


        


More information about the llvm-commits mailing list