@@ -605,6 +605,15 @@ static void setImportAttributes(T *existing,
605
605
}
606
606
}
607
607
608
+ static void traceImport (std::optional<StringRef> importName, InputFile *file) {
609
+ if (importName.has_value ()) {
610
+ auto name = importName.value ();
611
+ if (symtab->isTraced (name)) {
612
+ printTraceSymbolUndefined (name, file);
613
+ }
614
+ }
615
+ }
616
+
608
617
Symbol *SymbolTable::addUndefinedFunction (StringRef name,
609
618
std::optional<StringRef> importName,
610
619
std::optional<StringRef> importModule,
@@ -624,6 +633,7 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef name,
624
633
printTraceSymbolUndefined (name, file);
625
634
626
635
auto replaceSym = [&]() {
636
+ traceImport (importName, file);
627
637
replaceSymbol<UndefinedFunction>(s, name, importName, importModule, flags,
628
638
file, sig, isCalledDirectly);
629
639
};
@@ -666,6 +676,7 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef name,
666
676
replaceSym ();
667
677
}
668
678
if (existingUndefined) {
679
+ traceImport (importName, file);
669
680
setImportAttributes (existingUndefined, importName, importModule, flags,
670
681
file);
671
682
if (isCalledDirectly)
@@ -718,10 +729,11 @@ Symbol *SymbolTable::addUndefinedGlobal(StringRef name,
718
729
if (s->traced )
719
730
printTraceSymbolUndefined (name, file);
720
731
721
- if (wasInserted)
732
+ if (wasInserted) {
733
+ traceImport (importName, file);
722
734
replaceSymbol<UndefinedGlobal>(s, name, importName, importModule, flags,
723
735
file, type);
724
- else if (auto *lazy = dyn_cast<LazySymbol>(s))
736
+ } else if (auto *lazy = dyn_cast<LazySymbol>(s))
725
737
lazy->extract ();
726
738
else if (s->isDefined ())
727
739
checkGlobalType (s, file, type);
@@ -744,10 +756,11 @@ Symbol *SymbolTable::addUndefinedTable(StringRef name,
744
756
if (s->traced )
745
757
printTraceSymbolUndefined (name, file);
746
758
747
- if (wasInserted)
759
+ if (wasInserted) {
760
+ traceImport (importName, file);
748
761
replaceSymbol<UndefinedTable>(s, name, importName, importModule, flags,
749
762
file, type);
750
- else if (auto *lazy = dyn_cast<LazySymbol>(s))
763
+ } else if (auto *lazy = dyn_cast<LazySymbol>(s))
751
764
lazy->extract ();
752
765
else if (s->isDefined ())
753
766
checkTableType (s, file, type);
@@ -770,10 +783,11 @@ Symbol *SymbolTable::addUndefinedTag(StringRef name,
770
783
if (s->traced )
771
784
printTraceSymbolUndefined (name, file);
772
785
773
- if (wasInserted)
786
+ if (wasInserted) {
787
+ traceImport (importName, file);
774
788
replaceSymbol<UndefinedTag>(s, name, importName, importModule, flags, file,
775
789
sig);
776
- else if (auto *lazy = dyn_cast<LazySymbol>(s))
790
+ } else if (auto *lazy = dyn_cast<LazySymbol>(s))
777
791
lazy->extract ();
778
792
else if (s->isDefined ())
779
793
checkTagType (s, file, sig);
@@ -937,9 +951,20 @@ bool SymbolTable::getFunctionVariant(Symbol* sym, const WasmSignature *sig,
937
951
// Set a flag for --trace-symbol so that we can print out a log message
938
952
// if a new symbol with the same name is inserted into the symbol table.
939
953
void SymbolTable::trace (StringRef name) {
954
+ tracingEnabled = true ;
940
955
symMap.insert ({CachedHashStringRef (name), -1 });
941
956
}
942
957
958
+ bool SymbolTable::isTraced (StringRef name) {
959
+ // Early exit in the default case to avoid symbol hashmap lookup.
960
+ if (!tracingEnabled)
961
+ return false ;
962
+ auto it = symMap.find (CachedHashStringRef (name));
963
+ if (it == symMap.end ())
964
+ return false ;
965
+ return it->second == -1 || symVector[it->second ]->traced ;
966
+ }
967
+
943
968
void SymbolTable::wrap (Symbol *sym, Symbol *real, Symbol *wrap) {
944
969
// Swap symbols as instructed by -wrap.
945
970
int &origIdx = symMap[CachedHashStringRef (sym->getName ())];
0 commit comments