[lld] [LLD][COFF] Avoid forcing lazy symbols in loadMinGWSymbols during symbol table enumeration (PR #141593)
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 27 05:51:40 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld
Author: Jacek Caban (cjacek)
<details>
<summary>Changes</summary>
Forcing lazy symbols at this point may introduce new entries into the symbol table.
---
Full diff: https://github.com/llvm/llvm-project/pull/141593.diff
2 Files Affected:
- (modified) lld/COFF/SymbolTable.cpp (+9)
- (added) lld/test/COFF/stdcall-alias.s (+24)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/141593
More information about the llvm-commits
mailing list