[llvm] 158a600 - [llvm-jitlink] Wait for reachable files to link before running checks.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 22 21:56:49 PST 2024


Author: Lang Hames
Date: 2024-12-23T05:56:42Z
New Revision: 158a60051d2d41bc255224ccb57d076efb75822e

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

LOG: [llvm-jitlink] Wait for reachable files to link before running checks.

ORC dependence tracking is fine-grained (i.e. per-symbol), however when running
-check mode we want to wait for all links triggered by the entry point lookup
to complete, regardless of whether the code / data in them is actually
reachable from the entry point. This simplifies test-cases, since authors don't
need to reason about per-symbol dependencies to know that additional files will
be linked (if referenced transitively in any way from the test-case).

The new Session::waitForFilesLinkedFromEntryPointFile utility does _not_ wait
for lazily linked (-lazy) files.

This will be used to fix buildbot errors caused by edca1d9bad2.

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 e3ed2b624b06a8..96a3e5b2acdf42 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -1230,6 +1230,11 @@ void Session::modifyPassConfig(LinkGraph &G, PassConfiguration &PassConfig) {
       return Error::success();
     });
 
+  PassConfig.PrePrunePasses.push_back([this](LinkGraph &G) {
+    std::lock_guard<std::mutex> Lock(M);
+    ++ActiveLinks;
+    return Error::success();
+  });
   PassConfig.PrePrunePasses.push_back(
       [this](LinkGraph &G) { return applyHarnessPromotions(*this, G); });
 
@@ -1242,6 +1247,13 @@ void Session::modifyPassConfig(LinkGraph &G, PassConfiguration &PassConfig) {
 
   if (AddSelfRelocations)
     PassConfig.PostPrunePasses.push_back(addSelfRelocations);
+
+  PassConfig.PostFixupPasses.push_back([this](LinkGraph &G) {
+    std::lock_guard<std::mutex> Lock(M);
+    if (--ActiveLinks == 0)
+      ActiveLinksCV.notify_all();
+    return Error::success();
+  });
 }
 
 Expected<JITDylib *> Session::getOrLoadDynamicLibrary(StringRef LibPath) {
@@ -2314,6 +2326,8 @@ static Error runChecks(Session &S, Triple TT, SubtargetFeatures Features) {
   if (CheckFiles.empty())
     return Error::success();
 
+  S.waitForFilesLinkedFromEntryPointFile();
+
   LLVM_DEBUG(dbgs() << "Running checks...\n");
 
   auto IsSymbolValid = [&S](StringRef Symbol) {

diff  --git a/llvm/tools/llvm-jitlink/llvm-jitlink.h b/llvm/tools/llvm-jitlink/llvm-jitlink.h
index bfad5211c21766..be3710971729a4 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.h
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.h
@@ -61,6 +61,16 @@ struct Session {
   void modifyPassConfig(jitlink::LinkGraph &G,
                         jitlink::PassConfiguration &PassConfig);
 
+  /// For -check: wait for all files that are referenced (transitively) from
+  /// the entry point *file* to be linked. (ORC's usual dependence tracking is
+  /// to fine-grained here: a lookup of the main symbol will return as soon as
+  /// all reachable symbols have been linked, but testcases may want to
+  /// inspect side-effects in unreachable symbols)..
+  void waitForFilesLinkedFromEntryPointFile() {
+    std::unique_lock<std::mutex> Lock(M);
+    return ActiveLinksCV.wait(Lock, [this]() { return ActiveLinks == 0; });
+  }
+
   using MemoryRegionInfo = RuntimeDyldChecker::MemoryRegionInfo;
 
   struct FileInfo {
@@ -110,6 +120,9 @@ struct Session {
 
   DynLibJDMap DynLibJDs;
 
+  std::mutex M;
+  std::condition_variable ActiveLinksCV;
+  size_t ActiveLinks = 0;
   SymbolInfoMap SymbolInfos;
   FileInfoMap FileInfos;
 


        


More information about the llvm-commits mailing list