File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -2601,7 +2601,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
26012601 createECExportThunks ();
26022602
26032603 // Resolve remaining undefined symbols and warn about imported locals.
2604- ctx.symtab .resolveRemainingUndefines ();
2604+ if (ctx.symtab .resolveRemainingUndefines ()) {
2605+ run ();
2606+ ctx.symtab .resolveRemainingUndefines ();
2607+ }
26052608 if (errorCount ())
26062609 return ;
26072610
Original file line number Diff line number Diff line change @@ -479,10 +479,11 @@ void SymbolTable::reportUnresolvable() {
479479 /* localImports */ nullptr , true );
480480}
481481
482- void SymbolTable::resolveRemainingUndefines () {
482+ bool SymbolTable::resolveRemainingUndefines () {
483483 llvm::TimeTraceScope timeScope (" Resolve remaining undefined symbols" );
484484 SmallPtrSet<Symbol *, 8 > undefs;
485485 DenseMap<Symbol *, Symbol *> localImports;
486+ bool foundLazy = false ;
486487
487488 for (auto &i : symMap) {
488489 Symbol *sym = i.second ;
@@ -502,6 +503,11 @@ void SymbolTable::resolveRemainingUndefines() {
502503 // This odd rule is for compatibility with MSVC linker.
503504 if (name.starts_with (" __imp_" )) {
504505 Symbol *imp = find (name.substr (strlen (" __imp_" )));
506+ if (imp && imp->isLazy ()) {
507+ forceLazy (imp);
508+ foundLazy = true ;
509+ continue ;
510+ }
505511 if (imp && isa<Defined>(imp)) {
506512 auto *d = cast<Defined>(imp);
507513 replaceSymbol<DefinedLocalImport>(sym, ctx, name, d);
@@ -529,6 +535,7 @@ void SymbolTable::resolveRemainingUndefines() {
529535 reportProblemSymbols (
530536 ctx, undefs,
531537 ctx.config .warnLocallyDefinedImported ? &localImports : nullptr , false );
538+ return foundLazy;
532539}
533540
534541std::pair<Symbol *, bool > SymbolTable::insert (StringRef name) {
Original file line number Diff line number Diff line change @@ -57,7 +57,10 @@ class SymbolTable {
5757 // Try to resolve any undefined symbols and update the symbol table
5858 // accordingly, then print an error message for any remaining undefined
5959 // symbols and warn about imported local symbols.
60- void resolveRemainingUndefines ();
60+ // Returns whether more files might need to be linked in to resolve lazy
61+ // symbols, in which case the caller is expected to call the function again
62+ // after linking those files.
63+ bool resolveRemainingUndefines ();
6164
6265 // Load lazy objects that are needed for MinGW automatic import and for
6366 // doing stdcall fixups.
You can’t perform that action at this time.
0 commit comments