Skip to content

[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

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lld/COFF/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,23 @@ 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);
if (!undef)
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) {
Expand Down
24 changes: 24 additions & 0 deletions lld/test/COFF/stdcall-alias.s
Original file line number Diff line number Diff line change
@@ -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