-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[lld][WebAssembly] Allow --trace-symbol
to work with symbols with custom import names
#96119
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -605,6 +605,15 @@ static void setImportAttributes(T *existing, | |
} | ||
} | ||
|
||
static void traceImport(std::optional<StringRef> importName, InputFile *file) { | ||
if (importName.has_value()) { | ||
auto name = importName.value(); | ||
if (symtab->isTraced(name)) { | ||
printTraceSymbolUndefined(name, file); | ||
} | ||
} | ||
} | ||
|
||
Symbol *SymbolTable::addUndefinedFunction(StringRef name, | ||
std::optional<StringRef> importName, | ||
std::optional<StringRef> importModule, | ||
|
@@ -624,6 +633,7 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef name, | |
printTraceSymbolUndefined(name, file); | ||
|
||
auto replaceSym = [&]() { | ||
traceImport(importName, file); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This // If the existing undefined functions is not called directly then let
// this one take precedence. Otherwise the existing function is either
// directly called or defined, in which case we need a function variant.
if (existingUndefined && !existingUndefined->isCalledDirectly)
replaceSym();
else if (getFunctionVariant(s, sig, file, &s))
replaceSym(); Is that OK to run this again in this case? |
||
replaceSymbol<UndefinedFunction>(s, name, importName, importModule, flags, | ||
file, sig, isCalledDirectly); | ||
}; | ||
|
@@ -666,6 +676,7 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef name, | |
replaceSym(); | ||
} | ||
if (existingUndefined) { | ||
traceImport(importName, file); | ||
setImportAttributes(existingUndefined, importName, importModule, flags, | ||
file); | ||
if (isCalledDirectly) | ||
|
@@ -718,10 +729,11 @@ Symbol *SymbolTable::addUndefinedGlobal(StringRef name, | |
if (s->traced) | ||
printTraceSymbolUndefined(name, file); | ||
|
||
if (wasInserted) | ||
if (wasInserted) { | ||
traceImport(importName, file); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
By the way, I'm not very familiar with the code structure here so I might be missing something, but should we call |
||
replaceSymbol<UndefinedGlobal>(s, name, importName, importModule, flags, | ||
file, type); | ||
else if (auto *lazy = dyn_cast<LazySymbol>(s)) | ||
} else if (auto *lazy = dyn_cast<LazySymbol>(s)) | ||
lazy->extract(); | ||
else if (s->isDefined()) | ||
checkGlobalType(s, file, type); | ||
|
@@ -744,10 +756,11 @@ Symbol *SymbolTable::addUndefinedTable(StringRef name, | |
if (s->traced) | ||
printTraceSymbolUndefined(name, file); | ||
|
||
if (wasInserted) | ||
if (wasInserted) { | ||
traceImport(importName, file); | ||
replaceSymbol<UndefinedTable>(s, name, importName, importModule, flags, | ||
file, type); | ||
else if (auto *lazy = dyn_cast<LazySymbol>(s)) | ||
} else if (auto *lazy = dyn_cast<LazySymbol>(s)) | ||
lazy->extract(); | ||
else if (s->isDefined()) | ||
checkTableType(s, file, type); | ||
|
@@ -770,10 +783,11 @@ Symbol *SymbolTable::addUndefinedTag(StringRef name, | |
if (s->traced) | ||
printTraceSymbolUndefined(name, file); | ||
|
||
if (wasInserted) | ||
if (wasInserted) { | ||
traceImport(importName, file); | ||
replaceSymbol<UndefinedTag>(s, name, importName, importModule, flags, file, | ||
sig); | ||
else if (auto *lazy = dyn_cast<LazySymbol>(s)) | ||
} else if (auto *lazy = dyn_cast<LazySymbol>(s)) | ||
lazy->extract(); | ||
else if (s->isDefined()) | ||
checkTagType(s, file, sig); | ||
|
@@ -937,9 +951,20 @@ bool SymbolTable::getFunctionVariant(Symbol* sym, const WasmSignature *sig, | |
// Set a flag for --trace-symbol so that we can print out a log message | ||
// if a new symbol with the same name is inserted into the symbol table. | ||
void SymbolTable::trace(StringRef name) { | ||
tracingEnabled = true; | ||
symMap.insert({CachedHashStringRef(name), -1}); | ||
} | ||
|
||
bool SymbolTable::isTraced(StringRef name) { | ||
// Early exit in the default case to avoid symbol hashmap lookup. | ||
if (!tracingEnabled) | ||
return false; | ||
auto it = symMap.find(CachedHashStringRef(name)); | ||
if (it == symMap.end()) | ||
return false; | ||
return it->second == -1 || symVector[it->second]->traced; | ||
sbc100 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
void SymbolTable::wrap(Symbol *sym, Symbol *real, Symbol *wrap) { | ||
// Swap symbols as instructed by -wrap. | ||
int &origIdx = symMap[CachedHashStringRef(sym->getName())]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We run
printTraceSymbolUndefined
here and possibly again whenwasInserted
is true below. Does this means->traced
andwasInserted
are never true at the same time?Would it be clear if we check two conditions at a single place to run this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No,
s->traced
depends only on the command line flags and will be true if and only if--trace-symbol=foo
is passed for a given symbolfoo
. It can be true or false independently of everything else going on here.I'm not sure what you mean by "and then again". I only see a single call to
printTraceSymbolUndefined
in this function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function contains a call to
traceImport
which callsprintTraceSymbolUndefined
. So I guess ifs->traced
andwasInserted
are both true it can be called twice?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes in that case you potentially see a trace entry for the "name" and the "import name". Not that those are normally different but if you happened to trace both then I would expect two trace entires in the log yes.