[lld] [LLD][COFF] Avoid forcing lazy symbols in loadMinGWSymbols during symbol table enumeration (PR #141593)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Tue May 27 05:51:07 PDT 2025


https://github.com/cjacek created https://github.com/llvm/llvm-project/pull/141593

Forcing lazy symbols at this point may introduce new entries into the symbol table.

>From 98e71c1ad9c6287c487e070654ee8ceb5c0349d4 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Tue, 27 May 2025 14:39:36 +0200
Subject: [PATCH] [LLD][COFF] Avoid forcing lazy symbols in loadMinGWSymbols
 during symbol table enumeration

Forcing lazy symbols at this point may introduce new entries into the symbol table.
---
 lld/COFF/SymbolTable.cpp      |  9 +++++++++
 lld/test/COFF/stdcall-alias.s | 24 ++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 lld/test/COFF/stdcall-alias.s

diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index d6f771284aa83..979acd2ef5975 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -245,6 +245,7 @@ void SymbolTable::reportUndefinedSymbol(const UndefinedDiag &undefDiag) {
 }
 
 void SymbolTable::loadMinGWSymbols() {
+  std::vector<Symbol *> undefs;
   for (auto &i : symMap) {
     Symbol *sym = i.second;
     auto *undef = dyn_cast<Undefined>(sym);
@@ -252,7 +253,15 @@ void SymbolTable::loadMinGWSymbols() {
       continue;
     if (undef->getWeakAlias())
       continue;
+    undefs.push_back(sym);
+  }
 
+  for (auto sym : undefs) {
+    auto *undef = dyn_cast<Undefined>(sym);
+    if (!undef)
+      continue;
+    if (undef->getWeakAlias())
+      continue;
     StringRef name = undef->getName();
 
     if (machine == I386 && ctx.config.stdcallFixup) {
diff --git a/lld/test/COFF/stdcall-alias.s b/lld/test/COFF/stdcall-alias.s
new file mode 100644
index 0000000000000..546aace9f1dfa
--- /dev/null
+++ b/lld/test/COFF/stdcall-alias.s
@@ -0,0 +1,24 @@
+// REQUIRES: x86
+// RUN: split-file %s %t.dir && cd %t.dir
+
+// RUN: llvm-mc -filetype=obj -triple=i686-windows test.s -o test.obj
+// RUN: llvm-mc -filetype=obj -triple=i686-windows lib.s -o lib.obj
+// RUN: lld-link -dll -noentry -out:out.dll test.obj -start-lib lib.obj -end-lib -lldmingw
+
+#--- test.s
+     .section .test,"dr"
+     .rva _func at 4
+
+#--- lib.s
+     .globl _func
+_func:
+     ret
+
+     // These symbols don't have lazy entries in the symbol table initially,
+     // but will be added during resolution from _func at 4 to _func. Make sure this
+     // scenario is handled properly.
+     .weak_anti_dep _func at 5
+     .set _func at 5,_func
+
+     .weak_anti_dep _func at 3
+     .set _func at 3,_func



More information about the llvm-commits mailing list