-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[LLD][COFF] Avoid forcing lazy symbols in loadMinGWSymbols during symbol table enumeration #141593
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
base: main
Are you sure you want to change the base?
Conversation
…bol table enumeration Forcing lazy symbols at this point may introduce new entries into the symbol table.
@llvm/pr-subscribers-platform-windows @llvm/pr-subscribers-lld Author: Jacek Caban (cjacek) ChangesForcing 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:
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@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@4 to _func. Make sure this
+ // scenario is handled properly.
+ .weak_anti_dep _func@5
+ .set _func@5,_func
+
+ .weak_anti_dep _func@3
+ .set _func@3,_func
|
This issue can also be reproduced with ARM64EC DLL imports. Since the problem is reproducible with the attached test case too, I went ahead and fixed it in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -245,14 +245,23 @@ void SymbolTable::reportUndefinedSymbol(const UndefinedDiag &undefDiag) { | |||
} | |||
|
|||
void SymbolTable::loadMinGWSymbols() { | |||
std::vector<Symbol *> undefs; | |||
for (auto &i : symMap) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the problem we're fixing here is that we avoid mutating symMap
while iterating over it?
Forcing lazy symbols at this point may introduce new entries into the symbol table.