[llvm] 565f4eb - [JITLink] Update external symbol scopes to reflect scopes of resolved defs.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 29 21:02:31 PDT 2022


Author: Lang Hames
Date: 2022-09-29T20:32:46-07:00
New Revision: 565f4eb8e607d8e0fbba00d3bca464c51b02a2b8

URL: https://github.com/llvm/llvm-project/commit/565f4eb8e607d8e0fbba00d3bca464c51b02a2b8
DIFF: https://github.com/llvm/llvm-project/commit/565f4eb8e607d8e0fbba00d3bca464c51b02a2b8.diff

LOG: [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).

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
    llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
index 411817839d908..89644994bc1d8 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
@@ -599,7 +599,7 @@ class Symbol {
   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);
   }

diff  --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp
index 3066afe90f6c7..17de84fa6e115 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";
     }


        


More information about the llvm-commits mailing list