Skip to content

Pass memory buffer to RuntimeDyld::MemoryManager factory #142930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025

Conversation

basioli-k
Copy link
Contributor

@basioli-k basioli-k commented Jun 5, 2025

RTDyldObjectLinkingLayer is currently creating a memory manager without any parameters.

In this PR I am passing the MemoryBuffer that will be emitted to the MemoryManager so that the user can use it to configure the behaviour of the MemoryManager.

Copy link

github-actions bot commented Jun 5, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@basioli-k basioli-k force-pushed the ofile-aware-mmapper branch from 069d089 to 387aac1 Compare June 5, 2025 12:43
@basioli-k basioli-k force-pushed the ofile-aware-mmapper branch from 387aac1 to 8f50006 Compare June 5, 2025 12:56
@basioli-k basioli-k marked this pull request as ready for review June 5, 2025 14:28
@llvmbot
Copy link
Member

llvmbot commented Jun 5, 2025

@llvm/pr-subscribers-mlir-execution-engine

Author: Karlo Basioli (basioli-k)

Changes

RTDyldObjectLinkingLayer is currently creating a memory manager without any parameters.

In this PR I am passing the MemoryBuffer that will be emitted to the MemoryManager so that the user can use it to configure the behaviour of the MemoryManager.


Full diff: https://github.com/llvm/llvm-project/pull/142930.diff

11 Files Affected:

  • (modified) llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h (+3-1)
  • (modified) llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h (+3-1)
  • (modified) llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h (+3-1)
  • (modified) llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h (+3-1)
  • (modified) llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h (+3-1)
  • (modified) llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h (+2-1)
  • (modified) llvm/lib/ExecutionEngine/Orc/LLJIT.cpp (+7-6)
  • (modified) llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp (+8-5)
  • (modified) llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp (+3-2)
  • (modified) llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp (+69-7)
  • (modified) mlir/lib/ExecutionEngine/ExecutionEngine.cpp (+2-1)
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
index bb9e6b8c99d28..73a7b5b38a385 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
@@ -47,7 +47,9 @@ class KaleidoscopeJIT {
                   JITTargetMachineBuilder JTMB, DataLayout DL)
       : ES(std::move(ES)), DL(std::move(DL)), Mangle(*this->ES, this->DL),
         ObjectLayer(*this->ES,
-                    []() { return std::make_unique<SectionMemoryManager>(); }),
+                    [](const MemoryBuffer &) {
+                      return std::make_unique<SectionMemoryManager>();
+                    }),
         CompileLayer(*this->ES, ObjectLayer,
                      std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
         MainJD(this->ES->createBareJITDylib("<main>")) {
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
index 2f7846e7ee2cb..d2bedd2c7270f 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
@@ -53,7 +53,9 @@ class KaleidoscopeJIT {
                   JITTargetMachineBuilder JTMB, DataLayout DL)
       : ES(std::move(ES)), DL(std::move(DL)), Mangle(*this->ES, this->DL),
         ObjectLayer(*this->ES,
-                    []() { return std::make_unique<SectionMemoryManager>(); }),
+                    [](const MemoryBuffer &) {
+                      return std::make_unique<SectionMemoryManager>();
+                    }),
         CompileLayer(*this->ES, ObjectLayer,
                      std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
         OptimizeLayer(*this->ES, CompileLayer, optimizeModule),
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
index fee2d26e5d925..09b87b0181f92 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
@@ -66,7 +66,9 @@ class KaleidoscopeJIT {
       : ES(std::move(ES)), EPCIU(std::move(EPCIU)), DL(std::move(DL)),
         Mangle(*this->ES, this->DL),
         ObjectLayer(*this->ES,
-                    []() { return std::make_unique<SectionMemoryManager>(); }),
+                    [](const MemoryBuffer &) {
+                      return std::make_unique<SectionMemoryManager>();
+                    }),
         CompileLayer(*this->ES, ObjectLayer,
                      std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
         OptimizeLayer(*this->ES, CompileLayer, optimizeModule),
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
index 136e88505a1d3..30c0e239a6cb4 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
@@ -151,7 +151,9 @@ class KaleidoscopeJIT {
       : ES(std::move(ES)), EPCIU(std::move(EPCIU)), DL(std::move(DL)),
         Mangle(*this->ES, this->DL),
         ObjectLayer(*this->ES,
-                    []() { return std::make_unique<SectionMemoryManager>(); }),
+                    [](const MemoryBuffer &) {
+                      return std::make_unique<SectionMemoryManager>();
+                    }),
         CompileLayer(*this->ES, ObjectLayer,
                      std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
         OptimizeLayer(*this->ES, CompileLayer, optimizeModule),
diff --git a/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h
index 778437cd8a3d6..65f94ed7a80d6 100644
--- a/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h
@@ -48,7 +48,9 @@ class KaleidoscopeJIT {
                   JITTargetMachineBuilder JTMB, DataLayout DL)
       : ES(std::move(ES)), DL(std::move(DL)), Mangle(*this->ES, this->DL),
         ObjectLayer(*this->ES,
-                    []() { return std::make_unique<SectionMemoryManager>(); }),
+                    [](const MemoryBuffer &) {
+                      return std::make_unique<SectionMemoryManager>();
+                    }),
         CompileLayer(*this->ES, ObjectLayer,
                      std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
         MainJD(this->ES->createBareJITDylib("<main>")) {
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
index 05c9b574aa0f0..1fb472a177d6d 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
@@ -50,7 +50,8 @@ class LLVM_ABI RTDyldObjectLinkingLayer
       MaterializationResponsibility &R, std::unique_ptr<MemoryBuffer>)>;
 
   using GetMemoryManagerFunction =
-      unique_function<std::unique_ptr<RuntimeDyld::MemoryManager>()>;
+      unique_function<std::unique_ptr<RuntimeDyld::MemoryManager>(
+          const MemoryBuffer &)>;
 
   /// Construct an ObjectLinkingLayer with the given NotifyLoaded,
   ///        and NotifyEmitted functors.
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 21ebe82c8a71a..f1a71e4acb46d 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -269,9 +269,8 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
   }
 
   void registerInitFunc(JITDylib &JD, SymbolStringPtr InitName) {
-    getExecutionSession().runSessionLocked([&]() {
-        InitFunctions[&JD].add(InitName);
-      });
+    getExecutionSession().runSessionLocked(
+        [&]() { InitFunctions[&JD].add(InitName); });
   }
 
   void registerDeInitFunc(JITDylib &JD, SymbolStringPtr DeInitName) {
@@ -935,8 +934,8 @@ Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
 Expected<ExecutorAddr> LLJIT::lookupLinkerMangled(JITDylib &JD,
                                                   SymbolStringPtr Name) {
   if (auto Sym = ES->lookup(
-        makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols),
-        Name))
+          makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols),
+          Name))
     return Sym->getAddress();
   else
     return Sym.takeError();
@@ -951,7 +950,9 @@ LLJIT::createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES) {
 
   // Otherwise default to creating an RTDyldObjectLinkingLayer that constructs
   // a new SectionMemoryManager for each object.
-  auto GetMemMgr = []() { return std::make_unique<SectionMemoryManager>(); };
+  auto GetMemMgr = [](const MemoryBuffer &) {
+    return std::make_unique<SectionMemoryManager>();
+  };
   auto Layer =
       std::make_unique<RTDyldObjectLinkingLayer>(ES, std::move(GetMemMgr));
 
diff --git a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
index d44199f1698e9..9999e1ff3bf00 100644
--- a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
@@ -1021,8 +1021,10 @@ LLVMOrcObjectLayerRef
 LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager(
     LLVMOrcExecutionSessionRef ES) {
   assert(ES && "ES must not be null");
-  return wrap(new RTDyldObjectLinkingLayer(
-      *unwrap(ES), [] { return std::make_unique<SectionMemoryManager>(); }));
+  return wrap(
+      new RTDyldObjectLinkingLayer(*unwrap(ES), [](const MemoryBuffer &) {
+        return std::make_unique<SectionMemoryManager>();
+      }));
 }
 
 LLVMOrcObjectLayerRef
@@ -1128,9 +1130,10 @@ LLVMOrcCreateRTDyldObjectLinkingLayerWithMCJITMemoryManagerLikeCallbacks(
       CreateContextCtx, CreateContext, NotifyTerminating, AllocateCodeSection,
       AllocateDataSection, FinalizeMemory, Destroy);
 
-  return wrap(new RTDyldObjectLinkingLayer(*unwrap(ES), [CBs = std::move(CBs)] {
-    return std::make_unique<MCJITMemoryManagerLikeCallbacksMemMgr>(CBs);
-  }));
+  return wrap(new RTDyldObjectLinkingLayer(
+      *unwrap(ES), [CBs = std::move(CBs)](const MemoryBuffer &) {
+        return std::make_unique<MCJITMemoryManagerLikeCallbacksMemMgr>(CBs);
+      }));
 
   return nullptr;
 }
diff --git a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
index 88cceacb71184..4d4a705ced64e 100644
--- a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
@@ -22,7 +22,8 @@ class JITDylibSearchOrderResolver : public JITSymbolResolver {
                               SymbolDependenceMap &Deps)
       : MR(MR), Deps(Deps) {}
 
-  void lookup(const LookupSet &Symbols, OnResolvedFunction OnResolved) override {
+  void lookup(const LookupSet &Symbols,
+              OnResolvedFunction OnResolved) override {
     auto &ES = MR.getTargetJITDylib().getExecutionSession();
     SymbolLookupSet InternedSymbols;
 
@@ -181,7 +182,7 @@ void RTDyldObjectLinkingLayer::emit(
     }
   }
 
-  auto MemMgr = GetMemoryManager();
+  auto MemMgr = GetMemoryManager(*O);
   auto &MemMgrRef = *MemMgr;
 
   // Switch to shared ownership of MR so that it can be captured by both
diff --git a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
index ed1feed6a5a9e..a0ae9308d33ab 100644
--- a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
@@ -50,9 +50,10 @@ static bool testSetProcessAllSections(std::unique_ptr<MemoryBuffer> Obj,
   auto &JD = ES.createBareJITDylib("main");
   auto Foo = ES.intern("foo");
 
-  RTDyldObjectLinkingLayer ObjLayer(ES, [&NonAllocSectionSeen]() {
-    return std::make_unique<MemoryManagerWrapper>(NonAllocSectionSeen);
-  });
+  RTDyldObjectLinkingLayer ObjLayer(
+      ES, [&NonAllocSectionSeen](const MemoryBuffer &) {
+        return std::make_unique<MemoryManagerWrapper>(NonAllocSectionSeen);
+      });
 
   auto OnResolveDoNothing = [](Expected<SymbolMap> R) {
     cantFail(std::move(R));
@@ -156,8 +157,9 @@ TEST(RTDyldObjectLinkingLayerTest, TestOverrideObjectFlags) {
   ExecutionSession ES{std::make_unique<UnsupportedExecutorProcessControl>()};
   auto &JD = ES.createBareJITDylib("main");
   auto Foo = ES.intern("foo");
-  RTDyldObjectLinkingLayer ObjLayer(
-      ES, []() { return std::make_unique<SectionMemoryManager>(); });
+  RTDyldObjectLinkingLayer ObjLayer(ES, [](const MemoryBuffer &) {
+    return std::make_unique<SectionMemoryManager>();
+  });
   IRCompileLayer CompileLayer(ES, ObjLayer,
                               std::make_unique<FunkySimpleCompiler>(*TM));
 
@@ -226,8 +228,9 @@ TEST(RTDyldObjectLinkingLayerTest, TestAutoClaimResponsibilityForSymbols) {
   ExecutionSession ES{std::make_unique<UnsupportedExecutorProcessControl>()};
   auto &JD = ES.createBareJITDylib("main");
   auto Foo = ES.intern("foo");
-  RTDyldObjectLinkingLayer ObjLayer(
-      ES, []() { return std::make_unique<SectionMemoryManager>(); });
+  RTDyldObjectLinkingLayer ObjLayer(ES, [](const MemoryBuffer &) {
+    return std::make_unique<SectionMemoryManager>();
+  });
   IRCompileLayer CompileLayer(ES, ObjLayer,
                               std::make_unique<FunkySimpleCompiler>(*TM));
 
@@ -244,4 +247,63 @@ TEST(RTDyldObjectLinkingLayerTest, TestAutoClaimResponsibilityForSymbols) {
     ES.reportError(std::move(Err));
 }
 
+TEST(RTDyldObjectLinkingLayerTest, TestMemoryBufferNamePropagation) {
+  OrcNativeTarget::initialize();
+
+  std::unique_ptr<TargetMachine> TM(
+      EngineBuilder().selectTarget(Triple("x86_64-unknown-linux-gnu"), "", "",
+                                   SmallVector<std::string, 1>()));
+
+  if (!TM)
+    GTEST_SKIP();
+
+  // Create a module with two void() functions: foo and bar.
+  ThreadSafeContext TSCtx(std::make_unique<LLVMContext>());
+  ThreadSafeModule M;
+  {
+    ModuleBuilder MB(*TSCtx.getContext(), TM->getTargetTriple().str(), "dummy");
+    MB.getModule()->setDataLayout(TM->createDataLayout());
+
+    Function *FooImpl = MB.createFunctionDecl(
+        FunctionType::get(Type::getVoidTy(*TSCtx.getContext()), {}, false),
+        "foo");
+    BasicBlock *FooEntry =
+        BasicBlock::Create(*TSCtx.getContext(), "entry", FooImpl);
+    IRBuilder<> B1(FooEntry);
+    B1.CreateRetVoid();
+
+    M = ThreadSafeModule(MB.takeModule(), std::move(TSCtx));
+  }
+
+  ExecutionSession ES{std::make_unique<UnsupportedExecutorProcessControl>()};
+  auto &JD = ES.createBareJITDylib("main");
+  auto Foo = ES.intern("foo");
+  std::string ObjectIdentifer;
+
+  RTDyldObjectLinkingLayer ObjLayer(
+      ES, [&ObjectIdentifer](const MemoryBuffer &Obj) {
+        // Capture the name of the object so that we can confirm that it
+        // contains the module name.
+        ObjectIdentifer = Obj.getBufferIdentifier().str();
+        return std::make_unique<SectionMemoryManager>();
+      });
+  IRCompileLayer CompileLayer(ES, ObjLayer,
+                              std::make_unique<SimpleCompiler>(*TM));
+
+  // Capture the module name before we move the module.
+  std::string ModuleName = M.getModuleUnlocked()->getName().str();
+
+  cantFail(CompileLayer.add(JD, std::move(M)));
+  ES.lookup(
+      LookupKind::Static, makeJITDylibSearchOrder(&JD), SymbolLookupSet(Foo),
+      SymbolState::Resolved,
+      [](Expected<SymbolMap> R) { cantFail(std::move(R)); },
+      NoDependenciesToRegister);
+
+  if (auto Err = ES.endSession())
+    ES.reportError(std::move(Err));
+
+  EXPECT_TRUE(ObjectIdentifer.find(ModuleName) != std::string::npos);
+}
+
 } // end anonymous namespace
diff --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
index 39f5c003320da..f704fbfbe8fff 100644
--- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -315,7 +315,8 @@ ExecutionEngine::create(Operation *m, const ExecutionEngineOptions &options,
   // process and dynamically linked libraries.
   auto objectLinkingLayerCreator = [&](ExecutionSession &session) {
     auto objectLayer = std::make_unique<RTDyldObjectLinkingLayer>(
-        session, [sectionMemoryMapper = options.sectionMemoryMapper]() {
+        session, [sectionMemoryMapper =
+                      options.sectionMemoryMapper](const MemoryBuffer &) {
           return std::make_unique<SectionMemoryManager>(sectionMemoryMapper);
         });
 

@llvmbot
Copy link
Member

llvmbot commented Jun 5, 2025

@llvm/pr-subscribers-mlir

Author: Karlo Basioli (basioli-k)

Changes

RTDyldObjectLinkingLayer is currently creating a memory manager without any parameters.

In this PR I am passing the MemoryBuffer that will be emitted to the MemoryManager so that the user can use it to configure the behaviour of the MemoryManager.


Full diff: https://github.com/llvm/llvm-project/pull/142930.diff

11 Files Affected:

  • (modified) llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h (+3-1)
  • (modified) llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h (+3-1)
  • (modified) llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h (+3-1)
  • (modified) llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h (+3-1)
  • (modified) llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h (+3-1)
  • (modified) llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h (+2-1)
  • (modified) llvm/lib/ExecutionEngine/Orc/LLJIT.cpp (+7-6)
  • (modified) llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp (+8-5)
  • (modified) llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp (+3-2)
  • (modified) llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp (+69-7)
  • (modified) mlir/lib/ExecutionEngine/ExecutionEngine.cpp (+2-1)
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
index bb9e6b8c99d28..73a7b5b38a385 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
@@ -47,7 +47,9 @@ class KaleidoscopeJIT {
                   JITTargetMachineBuilder JTMB, DataLayout DL)
       : ES(std::move(ES)), DL(std::move(DL)), Mangle(*this->ES, this->DL),
         ObjectLayer(*this->ES,
-                    []() { return std::make_unique<SectionMemoryManager>(); }),
+                    [](const MemoryBuffer &) {
+                      return std::make_unique<SectionMemoryManager>();
+                    }),
         CompileLayer(*this->ES, ObjectLayer,
                      std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
         MainJD(this->ES->createBareJITDylib("<main>")) {
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
index 2f7846e7ee2cb..d2bedd2c7270f 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
@@ -53,7 +53,9 @@ class KaleidoscopeJIT {
                   JITTargetMachineBuilder JTMB, DataLayout DL)
       : ES(std::move(ES)), DL(std::move(DL)), Mangle(*this->ES, this->DL),
         ObjectLayer(*this->ES,
-                    []() { return std::make_unique<SectionMemoryManager>(); }),
+                    [](const MemoryBuffer &) {
+                      return std::make_unique<SectionMemoryManager>();
+                    }),
         CompileLayer(*this->ES, ObjectLayer,
                      std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
         OptimizeLayer(*this->ES, CompileLayer, optimizeModule),
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
index fee2d26e5d925..09b87b0181f92 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
@@ -66,7 +66,9 @@ class KaleidoscopeJIT {
       : ES(std::move(ES)), EPCIU(std::move(EPCIU)), DL(std::move(DL)),
         Mangle(*this->ES, this->DL),
         ObjectLayer(*this->ES,
-                    []() { return std::make_unique<SectionMemoryManager>(); }),
+                    [](const MemoryBuffer &) {
+                      return std::make_unique<SectionMemoryManager>();
+                    }),
         CompileLayer(*this->ES, ObjectLayer,
                      std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
         OptimizeLayer(*this->ES, CompileLayer, optimizeModule),
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
index 136e88505a1d3..30c0e239a6cb4 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
@@ -151,7 +151,9 @@ class KaleidoscopeJIT {
       : ES(std::move(ES)), EPCIU(std::move(EPCIU)), DL(std::move(DL)),
         Mangle(*this->ES, this->DL),
         ObjectLayer(*this->ES,
-                    []() { return std::make_unique<SectionMemoryManager>(); }),
+                    [](const MemoryBuffer &) {
+                      return std::make_unique<SectionMemoryManager>();
+                    }),
         CompileLayer(*this->ES, ObjectLayer,
                      std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
         OptimizeLayer(*this->ES, CompileLayer, optimizeModule),
diff --git a/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h
index 778437cd8a3d6..65f94ed7a80d6 100644
--- a/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h
@@ -48,7 +48,9 @@ class KaleidoscopeJIT {
                   JITTargetMachineBuilder JTMB, DataLayout DL)
       : ES(std::move(ES)), DL(std::move(DL)), Mangle(*this->ES, this->DL),
         ObjectLayer(*this->ES,
-                    []() { return std::make_unique<SectionMemoryManager>(); }),
+                    [](const MemoryBuffer &) {
+                      return std::make_unique<SectionMemoryManager>();
+                    }),
         CompileLayer(*this->ES, ObjectLayer,
                      std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
         MainJD(this->ES->createBareJITDylib("<main>")) {
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
index 05c9b574aa0f0..1fb472a177d6d 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
@@ -50,7 +50,8 @@ class LLVM_ABI RTDyldObjectLinkingLayer
       MaterializationResponsibility &R, std::unique_ptr<MemoryBuffer>)>;
 
   using GetMemoryManagerFunction =
-      unique_function<std::unique_ptr<RuntimeDyld::MemoryManager>()>;
+      unique_function<std::unique_ptr<RuntimeDyld::MemoryManager>(
+          const MemoryBuffer &)>;
 
   /// Construct an ObjectLinkingLayer with the given NotifyLoaded,
   ///        and NotifyEmitted functors.
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 21ebe82c8a71a..f1a71e4acb46d 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -269,9 +269,8 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
   }
 
   void registerInitFunc(JITDylib &JD, SymbolStringPtr InitName) {
-    getExecutionSession().runSessionLocked([&]() {
-        InitFunctions[&JD].add(InitName);
-      });
+    getExecutionSession().runSessionLocked(
+        [&]() { InitFunctions[&JD].add(InitName); });
   }
 
   void registerDeInitFunc(JITDylib &JD, SymbolStringPtr DeInitName) {
@@ -935,8 +934,8 @@ Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
 Expected<ExecutorAddr> LLJIT::lookupLinkerMangled(JITDylib &JD,
                                                   SymbolStringPtr Name) {
   if (auto Sym = ES->lookup(
-        makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols),
-        Name))
+          makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols),
+          Name))
     return Sym->getAddress();
   else
     return Sym.takeError();
@@ -951,7 +950,9 @@ LLJIT::createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES) {
 
   // Otherwise default to creating an RTDyldObjectLinkingLayer that constructs
   // a new SectionMemoryManager for each object.
-  auto GetMemMgr = []() { return std::make_unique<SectionMemoryManager>(); };
+  auto GetMemMgr = [](const MemoryBuffer &) {
+    return std::make_unique<SectionMemoryManager>();
+  };
   auto Layer =
       std::make_unique<RTDyldObjectLinkingLayer>(ES, std::move(GetMemMgr));
 
diff --git a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
index d44199f1698e9..9999e1ff3bf00 100644
--- a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
@@ -1021,8 +1021,10 @@ LLVMOrcObjectLayerRef
 LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager(
     LLVMOrcExecutionSessionRef ES) {
   assert(ES && "ES must not be null");
-  return wrap(new RTDyldObjectLinkingLayer(
-      *unwrap(ES), [] { return std::make_unique<SectionMemoryManager>(); }));
+  return wrap(
+      new RTDyldObjectLinkingLayer(*unwrap(ES), [](const MemoryBuffer &) {
+        return std::make_unique<SectionMemoryManager>();
+      }));
 }
 
 LLVMOrcObjectLayerRef
@@ -1128,9 +1130,10 @@ LLVMOrcCreateRTDyldObjectLinkingLayerWithMCJITMemoryManagerLikeCallbacks(
       CreateContextCtx, CreateContext, NotifyTerminating, AllocateCodeSection,
       AllocateDataSection, FinalizeMemory, Destroy);
 
-  return wrap(new RTDyldObjectLinkingLayer(*unwrap(ES), [CBs = std::move(CBs)] {
-    return std::make_unique<MCJITMemoryManagerLikeCallbacksMemMgr>(CBs);
-  }));
+  return wrap(new RTDyldObjectLinkingLayer(
+      *unwrap(ES), [CBs = std::move(CBs)](const MemoryBuffer &) {
+        return std::make_unique<MCJITMemoryManagerLikeCallbacksMemMgr>(CBs);
+      }));
 
   return nullptr;
 }
diff --git a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
index 88cceacb71184..4d4a705ced64e 100644
--- a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
@@ -22,7 +22,8 @@ class JITDylibSearchOrderResolver : public JITSymbolResolver {
                               SymbolDependenceMap &Deps)
       : MR(MR), Deps(Deps) {}
 
-  void lookup(const LookupSet &Symbols, OnResolvedFunction OnResolved) override {
+  void lookup(const LookupSet &Symbols,
+              OnResolvedFunction OnResolved) override {
     auto &ES = MR.getTargetJITDylib().getExecutionSession();
     SymbolLookupSet InternedSymbols;
 
@@ -181,7 +182,7 @@ void RTDyldObjectLinkingLayer::emit(
     }
   }
 
-  auto MemMgr = GetMemoryManager();
+  auto MemMgr = GetMemoryManager(*O);
   auto &MemMgrRef = *MemMgr;
 
   // Switch to shared ownership of MR so that it can be captured by both
diff --git a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
index ed1feed6a5a9e..a0ae9308d33ab 100644
--- a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
@@ -50,9 +50,10 @@ static bool testSetProcessAllSections(std::unique_ptr<MemoryBuffer> Obj,
   auto &JD = ES.createBareJITDylib("main");
   auto Foo = ES.intern("foo");
 
-  RTDyldObjectLinkingLayer ObjLayer(ES, [&NonAllocSectionSeen]() {
-    return std::make_unique<MemoryManagerWrapper>(NonAllocSectionSeen);
-  });
+  RTDyldObjectLinkingLayer ObjLayer(
+      ES, [&NonAllocSectionSeen](const MemoryBuffer &) {
+        return std::make_unique<MemoryManagerWrapper>(NonAllocSectionSeen);
+      });
 
   auto OnResolveDoNothing = [](Expected<SymbolMap> R) {
     cantFail(std::move(R));
@@ -156,8 +157,9 @@ TEST(RTDyldObjectLinkingLayerTest, TestOverrideObjectFlags) {
   ExecutionSession ES{std::make_unique<UnsupportedExecutorProcessControl>()};
   auto &JD = ES.createBareJITDylib("main");
   auto Foo = ES.intern("foo");
-  RTDyldObjectLinkingLayer ObjLayer(
-      ES, []() { return std::make_unique<SectionMemoryManager>(); });
+  RTDyldObjectLinkingLayer ObjLayer(ES, [](const MemoryBuffer &) {
+    return std::make_unique<SectionMemoryManager>();
+  });
   IRCompileLayer CompileLayer(ES, ObjLayer,
                               std::make_unique<FunkySimpleCompiler>(*TM));
 
@@ -226,8 +228,9 @@ TEST(RTDyldObjectLinkingLayerTest, TestAutoClaimResponsibilityForSymbols) {
   ExecutionSession ES{std::make_unique<UnsupportedExecutorProcessControl>()};
   auto &JD = ES.createBareJITDylib("main");
   auto Foo = ES.intern("foo");
-  RTDyldObjectLinkingLayer ObjLayer(
-      ES, []() { return std::make_unique<SectionMemoryManager>(); });
+  RTDyldObjectLinkingLayer ObjLayer(ES, [](const MemoryBuffer &) {
+    return std::make_unique<SectionMemoryManager>();
+  });
   IRCompileLayer CompileLayer(ES, ObjLayer,
                               std::make_unique<FunkySimpleCompiler>(*TM));
 
@@ -244,4 +247,63 @@ TEST(RTDyldObjectLinkingLayerTest, TestAutoClaimResponsibilityForSymbols) {
     ES.reportError(std::move(Err));
 }
 
+TEST(RTDyldObjectLinkingLayerTest, TestMemoryBufferNamePropagation) {
+  OrcNativeTarget::initialize();
+
+  std::unique_ptr<TargetMachine> TM(
+      EngineBuilder().selectTarget(Triple("x86_64-unknown-linux-gnu"), "", "",
+                                   SmallVector<std::string, 1>()));
+
+  if (!TM)
+    GTEST_SKIP();
+
+  // Create a module with two void() functions: foo and bar.
+  ThreadSafeContext TSCtx(std::make_unique<LLVMContext>());
+  ThreadSafeModule M;
+  {
+    ModuleBuilder MB(*TSCtx.getContext(), TM->getTargetTriple().str(), "dummy");
+    MB.getModule()->setDataLayout(TM->createDataLayout());
+
+    Function *FooImpl = MB.createFunctionDecl(
+        FunctionType::get(Type::getVoidTy(*TSCtx.getContext()), {}, false),
+        "foo");
+    BasicBlock *FooEntry =
+        BasicBlock::Create(*TSCtx.getContext(), "entry", FooImpl);
+    IRBuilder<> B1(FooEntry);
+    B1.CreateRetVoid();
+
+    M = ThreadSafeModule(MB.takeModule(), std::move(TSCtx));
+  }
+
+  ExecutionSession ES{std::make_unique<UnsupportedExecutorProcessControl>()};
+  auto &JD = ES.createBareJITDylib("main");
+  auto Foo = ES.intern("foo");
+  std::string ObjectIdentifer;
+
+  RTDyldObjectLinkingLayer ObjLayer(
+      ES, [&ObjectIdentifer](const MemoryBuffer &Obj) {
+        // Capture the name of the object so that we can confirm that it
+        // contains the module name.
+        ObjectIdentifer = Obj.getBufferIdentifier().str();
+        return std::make_unique<SectionMemoryManager>();
+      });
+  IRCompileLayer CompileLayer(ES, ObjLayer,
+                              std::make_unique<SimpleCompiler>(*TM));
+
+  // Capture the module name before we move the module.
+  std::string ModuleName = M.getModuleUnlocked()->getName().str();
+
+  cantFail(CompileLayer.add(JD, std::move(M)));
+  ES.lookup(
+      LookupKind::Static, makeJITDylibSearchOrder(&JD), SymbolLookupSet(Foo),
+      SymbolState::Resolved,
+      [](Expected<SymbolMap> R) { cantFail(std::move(R)); },
+      NoDependenciesToRegister);
+
+  if (auto Err = ES.endSession())
+    ES.reportError(std::move(Err));
+
+  EXPECT_TRUE(ObjectIdentifer.find(ModuleName) != std::string::npos);
+}
+
 } // end anonymous namespace
diff --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
index 39f5c003320da..f704fbfbe8fff 100644
--- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -315,7 +315,8 @@ ExecutionEngine::create(Operation *m, const ExecutionEngineOptions &options,
   // process and dynamically linked libraries.
   auto objectLinkingLayerCreator = [&](ExecutionSession &session) {
     auto objectLayer = std::make_unique<RTDyldObjectLinkingLayer>(
-        session, [sectionMemoryMapper = options.sectionMemoryMapper]() {
+        session, [sectionMemoryMapper =
+                      options.sectionMemoryMapper](const MemoryBuffer &) {
           return std::make_unique<SectionMemoryManager>(sectionMemoryMapper);
         });
 

@basioli-k basioli-k requested a review from lhames June 5, 2025 14:35
Copy link
Contributor

@lhames lhames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though please note that RTDyldObjectLinkingLayer will be deprecated soon in favor of ObjectLinkingLayer.

@basioli-k basioli-k merged commit cd58586 into llvm:main Jun 5, 2025
15 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 6, 2025

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building llvm,mlir at step 6 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/33974

Here is the relevant piece of the build log for the reference
Step 6 (build-unified-tree) failure: build (failure)
...
5.352 [4484/28/137] Linking CXX executable bin/clang-reorder-fields
5.431 [4484/27/138] Linking CXX executable bin/clang-query
5.475 [4484/26/139] Linking CXX executable bin/pp-trace
5.480 [4484/25/140] Linking CXX executable bin/clang-include-cleaner
5.503 [4484/24/141] Linking CXX executable bin/tool-template
5.904 [4484/23/142] Linking CXX executable bin/clangd-indexer
5.928 [4484/22/143] Linking CXX executable bin/clangd-fuzzer
5.986 [4484/21/144] Linking CXX executable bin/clang-tidy
6.024 [4484/20/145] Linking CXX executable bin/clangd
6.050 [4484/19/146] Building CXX object examples/SpeculativeJIT/CMakeFiles/SpeculativeJIT.dir/SpeculativeJIT.cpp.o
FAILED: examples/SpeculativeJIT/CMakeFiles/SpeculativeJIT.dir/SpeculativeJIT.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros /usr/bin/ccache /usr/bin/clang++ -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_STATIC -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/build/buildbot/premerge-monolithic-linux/build/examples/SpeculativeJIT -I/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/examples/SpeculativeJIT -I/build/buildbot/premerge-monolithic-linux/build/include -I/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include -gmlt -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT examples/SpeculativeJIT/CMakeFiles/SpeculativeJIT.dir/SpeculativeJIT.cpp.o -MF examples/SpeculativeJIT/CMakeFiles/SpeculativeJIT.dir/SpeculativeJIT.cpp.o.d -o examples/SpeculativeJIT/CMakeFiles/SpeculativeJIT.dir/SpeculativeJIT.cpp.o -c /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/examples/SpeculativeJIT/SpeculativeJIT.cpp
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/examples/SpeculativeJIT/SpeculativeJIT.cpp:144:36: error: no matching constructor for initialization of 'RTDyldObjectLinkingLayer'
  RTDyldObjectLinkingLayer ObjLayer{*ES, createMemMgr};
                                   ^~~~~~~~~~~~~~~~~~~
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h:58:3: note: candidate constructor not viable: no known conversion from 'std::unique_ptr<SectionMemoryManager> ()' to 'GetMemoryManagerFunction' (aka 'unique_function<std::unique_ptr<RuntimeDyld::MemoryManager> (const MemoryBuffer &)>') for 2nd argument
  RTDyldObjectLinkingLayer(ExecutionSession &ES,
  ^
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h:37:16: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
class LLVM_ABI RTDyldObjectLinkingLayer
               ^
1 error generated.
6.231 [4484/18/147] Building CXX object examples/OrcV2Examples/LLJITWithGDBRegistrationListener/CMakeFiles/LLJITWithGDBRegistrationListener.dir/LLJITWithGDBRegistrationListener.cpp.o
FAILED: examples/OrcV2Examples/LLJITWithGDBRegistrationListener/CMakeFiles/LLJITWithGDBRegistrationListener.dir/LLJITWithGDBRegistrationListener.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros /usr/bin/ccache /usr/bin/clang++ -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_STATIC -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/build/buildbot/premerge-monolithic-linux/build/examples/OrcV2Examples/LLJITWithGDBRegistrationListener -I/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener -I/build/buildbot/premerge-monolithic-linux/build/include -I/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include -gmlt -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT examples/OrcV2Examples/LLJITWithGDBRegistrationListener/CMakeFiles/LLJITWithGDBRegistrationListener.dir/LLJITWithGDBRegistrationListener.cpp.o -MF examples/OrcV2Examples/LLJITWithGDBRegistrationListener/CMakeFiles/LLJITWithGDBRegistrationListener.dir/LLJITWithGDBRegistrationListener.cpp.o.d -o examples/OrcV2Examples/LLJITWithGDBRegistrationListener/CMakeFiles/LLJITWithGDBRegistrationListener.dir/LLJITWithGDBRegistrationListener.cpp.o -c /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp
In file included from /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp:15:
In file included from /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include/llvm/ExecutionEngine/JITEventListener.h:19:
In file included from /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include/llvm/ExecutionEngine/RuntimeDyld.h:16:
In file included from /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:36:
In file included from /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include/llvm/ADT/PointerUnion.h:20:
In file included from /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include/llvm/ADT/STLExtras.h:37:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/memory:76:
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/unique_ptr.h:962:34: error: no matching constructor for initialization of 'llvm::orc::RTDyldObjectLinkingLayer'
    { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
                                 ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp:70:32: note: in instantiation of function template specialization 'std::make_unique<llvm::orc::RTDyldObjectLinkingLayer, llvm::orc::ExecutionSession &, (lambda at /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp:66:40)>' requested here
                          std::make_unique<RTDyldObjectLinkingLayer>(
                               ^
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h:58:3: note: candidate constructor not viable: no known conversion from '(lambda at /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp:66:40)' to 'GetMemoryManagerFunction' (aka 'unique_function<std::unique_ptr<RuntimeDyld::MemoryManager> (const MemoryBuffer &)>') for 2nd argument
  RTDyldObjectLinkingLayer(ExecutionSession &ES,
  ^
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h:37:16: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
class LLVM_ABI RTDyldObjectLinkingLayer
               ^
1 error generated.
6.290 [4484/17/148] Building CXX object lib/ExecutionEngine/Orc/CMakeFiles/LLVMOrcJIT.dir/RTDyldObjectLinkingLayer.cpp.o
7.009 [4484/16/149] Building CXX object tools/clang/lib/Interpreter/CMakeFiles/obj.clangInterpreter.dir/IncrementalExecutor.cpp.o
7.845 [4484/15/150] Building CXX object examples/Kaleidoscope/BuildingAJIT/Chapter1/CMakeFiles/BuildingAJIT-Ch1.dir/toy.cpp.o
8.135 [4484/14/151] Building CXX object examples/Kaleidoscope/BuildingAJIT/Chapter2/CMakeFiles/BuildingAJIT-Ch2.dir/toy.cpp.o

rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
`RTDyldObjectLinkingLayer` is currently creating a memory manager
without any parameters.

In this PR I am passing the MemoryBuffer that will be emitted to the
MemoryManager so that the user can use it to configure the behaviour of
the MemoryManager.
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
`RTDyldObjectLinkingLayer` is currently creating a memory manager
without any parameters.

In this PR I am passing the MemoryBuffer that will be emitted to the
MemoryManager so that the user can use it to configure the behaviour of
the MemoryManager.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants