[llvm] 2222cfe - [C-API] LLVMOrcCreateObjectLinkingLayerWithInProcessMemoryManager (#169862)

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 3 19:22:11 PST 2025


Author: Thomas Munro
Date: 2025-12-04T14:22:07+11:00
New Revision: 2222cfe7e11ff3e0434bc696856629199ef0da7c

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

LOG: [C-API] LLVMOrcCreateObjectLinkingLayerWithInProcessMemoryManager (#169862)

Allow C programs to use JITLink with trivial new C-API wrapper. Modeled
on `LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager`
except that it has to deal with failure of
`jitlink::InProcessMemoryManager::Create()`. Function name suggested by
@lhames in https://github.com/llvm/llvm-project/issues/106203.

I suppose failure of underlying platform-specific things like
`sysconf(_SC_PAGESIZE)` shouldn't really happen. An alternative error
reporting style might be to follow
`LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess` and return
`LLVMErrorRef` with an output parameter for the `LLVMOrcObjectLayerRef`,
but then it wouldn't be a drop-in replacement for
`LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager`.
Thoughts?

This is wanted by PostgreSQL (branch using this API:
https://github.com/macdice/postgres/tree/llvm-22-proposed-c-api). (We're
also using `LLVMCreatePerfJITEventListener`,
`LLVMCreatePerfJITEventListener`,
`LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener`, so it looks
like we'll need to research `PerfSupportPlugin`,
`DebuggerSupportPlugin`, `ObjectLinkingLayer::addPlugin()`...)

Added: 
    

Modified: 
    llvm/include/llvm-c/OrcEE.h
    llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm-c/OrcEE.h b/llvm/include/llvm-c/OrcEE.h
index fcec3a47186ac..fd044ea659456 100644
--- a/llvm/include/llvm-c/OrcEE.h
+++ b/llvm/include/llvm-c/OrcEE.h
@@ -43,6 +43,14 @@ typedef void (*LLVMMemoryManagerNotifyTerminatingCallback)(void *CtxCtx);
  * @{
  */
 
+/**
+ * Create a ObjectLinkingLayer instance using the standard JITLink
+ * InProcessMemoryManager for memory management.
+ */
+LLVM_C_ABI LLVMErrorRef
+LLVMOrcCreateObjectLinkingLayerWithInProcessMemoryManager(
+    LLVMOrcObjectLayerRef *Result, LLVMOrcExecutionSessionRef ES);
+
 /**
  * Create a RTDyldObjectLinkingLayer instance using the standard
  * SectionMemoryManager for memory management.

diff  --git a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
index cdde733b3a817..b1bc3c14d9c6d 100644
--- a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
@@ -11,9 +11,11 @@
 #include "llvm-c/OrcEE.h"
 #include "llvm-c/TargetMachine.h"
 
+#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
 #include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
 #include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
 #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
@@ -1017,6 +1019,17 @@ LLVMOrcLLJITGetObjTransformLayer(LLVMOrcLLJITRef J) {
   return wrap(&unwrap(J)->getObjTransformLayer());
 }
 
+LLVMErrorRef LLVMOrcCreateObjectLinkingLayerWithInProcessMemoryManager(
+    LLVMOrcObjectLayerRef *Result, LLVMOrcExecutionSessionRef ES) {
+  assert(Result && "Result must not be null");
+  assert(ES && "ES must not be null");
+  auto MM = jitlink::InProcessMemoryManager::Create();
+  if (!MM)
+    return wrap(MM.takeError());
+  *Result = wrap(new ObjectLinkingLayer(*unwrap(ES), std::move(*MM)));
+  return LLVMErrorSuccess;
+}
+
 LLVMOrcObjectLayerRef
 LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager(
     LLVMOrcExecutionSessionRef ES) {


        


More information about the llvm-commits mailing list