From 565f4eb8e607d8e0fbba00d3bca464c51b02a2b8 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 29 Sep 2022 19:16:19 -0700 Subject: [PATCH] [JITLink] Update external symbol scopes to reflect scopes of resolved defs. This is a counterpart to ffe2dda29f3, 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). --- llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h | 2 +- llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h index 4118178..8964499 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h @@ -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(S); } diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp index 3066afe..17de84f 100644 --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp @@ -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"; } -- 2.7.4