[PATCH] [llvm-c] Expose getFunctionAddress, as a modern alternative
Ramkumar Ramachandra
artagnon at gmail.com
Mon Dec 22 10:17:50 PST 2014
Hi whitequark,
The OCaml bindings use getPointerToGlobal as the primary way to get a
handle on functions to run. This function is broken and deprecated, and
we want to transition to the modern getFunctionAddress alternative. This
is a two step process: first, there needs to be a C wrapper that OCaml
can leverage. So, build LLVMGetFunctionAddress with a test.
Second, there needs to be an OCaml interface to the new
LLVMGetFunctionAddress C function. This will be done in another patch.
http://reviews.llvm.org/D6760
Files:
include/llvm-c/ExecutionEngine.h
lib/ExecutionEngine/ExecutionEngineBindings.cpp
unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
Index: include/llvm-c/ExecutionEngine.h
===================================================================
--- include/llvm-c/ExecutionEngine.h
+++ include/llvm-c/ExecutionEngine.h
@@ -170,6 +170,8 @@
void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
+uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
+
/*===-- Operations on memory managers -------------------------------------===*/
typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
Index: lib/ExecutionEngine/ExecutionEngineBindings.cpp
===================================================================
--- lib/ExecutionEngine/ExecutionEngineBindings.cpp
+++ lib/ExecutionEngine/ExecutionEngineBindings.cpp
@@ -328,6 +328,12 @@
return unwrap(EE)->getPointerToGlobal(unwrap<GlobalValue>(Global));
}
+uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name) {
+ unwrap(EE)->finalizeObject();
+
+ return unwrap(EE)->getFunctionAddress(Name);
+}
+
/*===-- Operations on memory managers -------------------------------------===*/
namespace {
Index: unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
===================================================================
--- unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
+++ unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
@@ -347,6 +347,23 @@
EXPECT_EQ(42, functionPointer.usable());
}
+TEST_F(MCJITCAPITest, new_gfa) {
+ SKIP_UNSUPPORTED_PLATFORM;
+
+ buildSimpleFunction();
+ buildMCJITOptions();
+ buildMCJITEngine();
+ buildAndRunPasses();
+
+ union {
+ uint64_t raw;
+ int (*usable)();
+ } functionPointer;
+ functionPointer.raw = LLVMGetFunctionAddress(Engine, "simple_function");
+
+ EXPECT_EQ(42, functionPointer.usable());
+}
+
TEST_F(MCJITCAPITest, custom_memory_manager) {
SKIP_UNSUPPORTED_PLATFORM;
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6760.17564.patch
Type: text/x-patch
Size: 1857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141222/985b9c41/attachment.bin>
More information about the llvm-commits
mailing list