Skip to content

Commit b36c1d0

Browse files
cjaceksvkeerthy
authored andcommitted
[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.
1 parent a2f48b0 commit b36c1d0

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lld/COFF/SymbolTable.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,23 @@ void SymbolTable::reportUndefinedSymbol(const UndefinedDiag &undefDiag) {
245245
}
246246

247247
void SymbolTable::loadMinGWSymbols() {
248+
std::vector<Symbol *> undefs;
248249
for (auto &i : symMap) {
249250
Symbol *sym = i.second;
250251
auto *undef = dyn_cast<Undefined>(sym);
251252
if (!undef)
252253
continue;
253254
if (undef->getWeakAlias())
254255
continue;
256+
undefs.push_back(sym);
257+
}
255258

259+
for (auto sym : undefs) {
260+
auto *undef = dyn_cast<Undefined>(sym);
261+
if (!undef)
262+
continue;
263+
if (undef->getWeakAlias())
264+
continue;
256265
StringRef name = undef->getName();
257266

258267
if (machine == I386 && ctx.config.stdcallFixup) {

lld/test/COFF/stdcall-alias.s

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// REQUIRES: x86
2+
// RUN: split-file %s %t.dir && cd %t.dir
3+
4+
// RUN: llvm-mc -filetype=obj -triple=i686-windows test.s -o test.obj
5+
// RUN: llvm-mc -filetype=obj -triple=i686-windows lib.s -o lib.obj
6+
// RUN: lld-link -dll -noentry -out:out.dll test.obj -start-lib lib.obj -end-lib -lldmingw
7+
8+
#--- test.s
9+
.section .test,"dr"
10+
.rva _func@4
11+
12+
#--- lib.s
13+
.globl _func
14+
_func:
15+
ret
16+
17+
// These symbols don't have lazy entries in the symbol table initially,
18+
// but will be added during resolution from _func@4 to _func. Make sure this
19+
// scenario is handled properly.
20+
.weak_anti_dep _func@5
21+
.set _func@5,_func
22+
23+
.weak_anti_dep _func@3
24+
.set _func@3,_func

0 commit comments

Comments
 (0)