[llvm] e3c8408 - [llvm-jitlink] Apply symbol scope modifiers explicitly for -hidden-lx.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 20 21:55:55 PST 2025


Author: Lang Hames
Date: 2025-02-21T16:55:49+11:00
New Revision: e3c8408593f8edbf1a627969346f03268abb1ced

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

LOG: [llvm-jitlink] Apply symbol scope modifiers explicitly for -hidden-lx.

We had been abusing the setOverrideObjectFlagsWithResponsibilityFlags method to
do this. Handling it explicitly ensures that flags are only modified on the
intended files, and not accedintally modified elsewhere.

Added: 
    

Modified: 
    llvm/tools/llvm-jitlink/llvm-jitlink.cpp
    llvm/tools/llvm-jitlink/llvm-jitlink.h

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 9e6d3df297fc7..d6fd06c52c212 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -427,6 +427,23 @@ bool lazyLinkingRequested() {
   return false;
 }
 
+static Error applyLibraryLinkModifiers(Session &S, LinkGraph &G) {
+  // If there are hidden archives and this graph is an archive
+  // member then apply hidden modifier.
+  if (!S.HiddenArchives.empty()) {
+    StringRef ObjName(G.getName());
+    if (ObjName.ends_with(')')) {
+      auto LibName = ObjName.split('(').first;
+      if (S.HiddenArchives.count(LibName)) {
+        for (auto *Sym : G.defined_symbols())
+          Sym->setScope(std::max(Sym->getScope(), Scope::Hidden));
+      }
+    }
+  }
+
+  return Error::success();
+}
+
 static Error applyHarnessPromotions(Session &S, LinkGraph &G) {
   std::lock_guard<std::mutex> Lock(S.M);
 
@@ -1328,6 +1345,8 @@ void Session::modifyPassConfig(LinkGraph &G, PassConfiguration &PassConfig) {
     ++ActiveLinks;
     return Error::success();
   });
+  PassConfig.PrePrunePasses.push_back(
+      [this](LinkGraph &G) { return applyLibraryLinkModifiers(*this, G); });
   PassConfig.PrePrunePasses.push_back(
       [this](LinkGraph &G) { return applyHarnessPromotions(*this, G); });
 
@@ -2182,11 +2201,6 @@ static Error addLibraries(Session &S,
     LibraryLoadQueue.push_back(std::move(LL));
   }
 
-  // If there are any load-<modified> options then turn on flag overrides
-  // to avoid flag mismatch errors.
-  if (!LibrariesHidden.empty() || !LoadHidden.empty())
-    S.ObjLayer.setOverrideObjectFlagsWithResponsibilityFlags(true);
-
   // Sort library loads by position in the argument list.
   llvm::sort(LibraryLoadQueue,
              [](const LibraryLoad &LHS, const LibraryLoad &RHS) {
@@ -2204,6 +2218,7 @@ static Error addLibraries(Session &S,
       break;
     case LibraryLoad::Hidden:
       GetObjFileInterface = getObjectFileInterfaceHidden;
+      S.HiddenArchives.insert(Path);
       break;
     }
 

diff  --git a/llvm/tools/llvm-jitlink/llvm-jitlink.h b/llvm/tools/llvm-jitlink/llvm-jitlink.h
index 92d667e797b88..ca5162f1a2d52 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.h
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.h
@@ -136,6 +136,8 @@ struct Session {
   StringSet<> HarnessDefinitions;
   DenseMap<StringRef, StringRef> CanonicalWeakDefs;
 
+  StringSet<> HiddenArchives;
+
   std::optional<Regex> ShowGraphsRegex;
 
 private:


        


More information about the llvm-commits mailing list