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

via llvm-commits llvm-commits at lists.llvm.org
Thu May 29 02:35:19 PDT 2025


Author: Jacek Caban
Date: 2025-05-29T11:35:16+02:00
New Revision: 6602bfa721889df597aae046c639e823b1cbb4e7

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

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

Forcing lazy symbols at this point may introduce new entries into the
symbol table. Avoid mutating `symTab` while iterating over it.

Added: 
    lld/test/COFF/stdcall-alias.s

Modified: 
    lld/COFF/SymbolTable.cpp

Removed: 
    


################################################################################
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