[JITLink] Update external symbol scopes to reflect scopes of resolved defs.

This is a counterpart to ffe2dda29f, and does for scope what that commit did
for linkage.

Making the scope of external definitions visible to JITLink plugins will
allow us to distinguish hidden weak defs (which do not need to be tracked by
default) from default-scoped weak defs (which need to be updated to point at
a single chosen definition at runtime).
This commit is contained in:
Lang Hames 2022-09-29 19:16:19 -07:00
parent 1cc02b05b7
commit 565f4eb8e6
2 changed files with 13 additions and 1 deletions

View File

@ -599,7 +599,7 @@ public:
void setScope(Scope S) {
assert((!Name.empty() || S == Scope::Local) &&
"Can not set anonymous symbol to non-local scope");
assert((S == Scope::Default || Base->isDefined() || Base->isAbsolute()) &&
assert((S != Scope::Local || Base->isDefined() || Base->isAbsolute()) &&
"Invalid visibility for symbol type");
this->S = static_cast<uint8_t>(S);
}

View File

@ -222,6 +222,8 @@ void JITLinkerBase::applyLookupResult(AsyncLookupResult Result) {
orc::ExecutorAddr(ResultI->second.getAddress()));
Sym->setLinkage(ResultI->second.getFlags().isWeak() ? Linkage::Weak
: Linkage::Strong);
Sym->setScope(ResultI->second.getFlags().isExported() ? Scope::Default
: Scope::Hidden);
} else
assert(Sym->isWeaklyReferenced() &&
"Failed to resolve non-weak reference");
@ -237,6 +239,16 @@ void JITLinkerBase::applyLookupResult(AsyncLookupResult Result) {
break;
case Linkage::Weak:
dbgs() << " (weak)";
break;
}
switch (Sym->getScope()) {
case Scope::Local:
llvm_unreachable("External symbol should not have local linkage");
case Scope::Hidden:
break;
case Scope::Default:
dbgs() << " (exported)";
break;
}
dbgs() << "\n";
}