@@ -507,6 +507,15 @@ static void setImportAttributes(T *existing,
507
507
}
508
508
}
509
509
510
+ static void traceImport (std::optional<StringRef> importName, InputFile *file) {
511
+ if (importName.has_value ()) {
512
+ auto name = importName.value ();
513
+ if (symtab->isTraced (name)) {
514
+ printTraceSymbolUndefined (name, file);
515
+ }
516
+ }
517
+ }
518
+
510
519
Symbol *SymbolTable::addUndefinedFunction (StringRef name,
511
520
std::optional<StringRef> importName,
512
521
std::optional<StringRef> importModule,
@@ -526,6 +535,7 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef name,
526
535
printTraceSymbolUndefined (name, file);
527
536
528
537
auto replaceSym = [&]() {
538
+ traceImport (importName, file);
529
539
replaceSymbol<UndefinedFunction>(s, name, importName, importModule, flags,
530
540
file, sig, isCalledDirectly);
531
541
};
@@ -560,6 +570,7 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef name,
560
570
replaceSym ();
561
571
}
562
572
if (existingUndefined) {
573
+ traceImport (importName, file);
563
574
setImportAttributes (existingUndefined, importName, importModule, flags,
564
575
file);
565
576
if (isCalledDirectly)
@@ -612,10 +623,11 @@ Symbol *SymbolTable::addUndefinedGlobal(StringRef name,
612
623
if (s->traced )
613
624
printTraceSymbolUndefined (name, file);
614
625
615
- if (wasInserted)
626
+ if (wasInserted) {
627
+ traceImport (importName, file);
616
628
replaceSymbol<UndefinedGlobal>(s, name, importName, importModule, flags,
617
629
file, type);
618
- else if (auto *lazy = dyn_cast<LazySymbol>(s))
630
+ } else if (auto *lazy = dyn_cast<LazySymbol>(s))
619
631
lazy->extract ();
620
632
else if (s->isDefined ())
621
633
checkGlobalType (s, file, type);
@@ -638,10 +650,11 @@ Symbol *SymbolTable::addUndefinedTable(StringRef name,
638
650
if (s->traced )
639
651
printTraceSymbolUndefined (name, file);
640
652
641
- if (wasInserted)
653
+ if (wasInserted) {
654
+ traceImport (importName, file);
642
655
replaceSymbol<UndefinedTable>(s, name, importName, importModule, flags,
643
656
file, type);
644
- else if (auto *lazy = dyn_cast<LazySymbol>(s))
657
+ } else if (auto *lazy = dyn_cast<LazySymbol>(s))
645
658
lazy->extract ();
646
659
else if (s->isDefined ())
647
660
checkTableType (s, file, type);
@@ -664,10 +677,11 @@ Symbol *SymbolTable::addUndefinedTag(StringRef name,
664
677
if (s->traced )
665
678
printTraceSymbolUndefined (name, file);
666
679
667
- if (wasInserted)
680
+ if (wasInserted) {
681
+ traceImport (importName, file);
668
682
replaceSymbol<UndefinedTag>(s, name, importName, importModule, flags, file,
669
683
sig);
670
- else if (auto *lazy = dyn_cast<LazySymbol>(s))
684
+ } else if (auto *lazy = dyn_cast<LazySymbol>(s))
671
685
lazy->extract ();
672
686
else if (s->isDefined ())
673
687
checkTagType (s, file, sig);
@@ -831,6 +845,13 @@ void SymbolTable::trace(StringRef name) {
831
845
symMap.insert ({CachedHashStringRef (name), -1 });
832
846
}
833
847
848
+ bool SymbolTable::isTraced (StringRef name) {
849
+ auto it = symMap.find (CachedHashStringRef (name));
850
+ if (it == symMap.end ())
851
+ return false ;
852
+ return it->second == -1 || symVector[it->second ]->traced ;
853
+ }
854
+
834
855
void SymbolTable::wrap (Symbol *sym, Symbol *real, Symbol *wrap) {
835
856
// Swap symbols as instructed by -wrap.
836
857
int &origIdx = symMap[CachedHashStringRef (sym->getName ())];
0 commit comments