[llvm] r224720 - [C API] Expose LLVMGetGlobalValueAddress and LLVMGetFunctionAddress.

Vasileios Kalintiris Vasileios.Kalintiris at imgtec.com
Wed Jan 14 09:53:31 PST 2015


Hi,

The tests that were added with this commit broke the MIPS buildbots.

The problem is that on a 32-bit Big Endian machine, the "usable" union field holds the upper part of the address
that we get from LLVMGetGlobalValueAddress or LLVMGetFunctionAddress in tests gva and gfa respectively.

I've attached a patch that fixes the problem and I plan on committing. Does it look good to you?

Thanks,
Vasileios

________________________________________
From: llvm-commits-bounces at cs.uiuc.edu [llvm-commits-bounces at cs.uiuc.edu] on behalf of Peter Zotov [whitequark at whitequark.org]
Sent: 22 December 2014 18:53
To: llvm-commits at cs.uiuc.edu
Subject: [llvm] r224720 - [C API] Expose LLVMGetGlobalValueAddress and  LLVMGetFunctionAddress.

Author: whitequark
Date: Mon Dec 22 12:53:11 2014
New Revision: 224720

URL: http://llvm.org/viewvc/llvm-project?rev=224720&view=rev
Log:
[C API] Expose LLVMGetGlobalValueAddress and LLVMGetFunctionAddress.

Patch by Ramkumar Ramachandra <artagnon at gmail.com>

Modified:
    llvm/trunk/include/llvm-c/ExecutionEngine.h
    llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp
    llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp

Modified: llvm/trunk/include/llvm-c/ExecutionEngine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/ExecutionEngine.h?rev=224720&r1=224719&r2=224720&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/ExecutionEngine.h (original)
+++ llvm/trunk/include/llvm-c/ExecutionEngine.h Mon Dec 22 12:53:11 2014
@@ -170,6 +170,10 @@ void LLVMAddGlobalMapping(LLVMExecutionE

 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);

+uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);
+
+uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
+
 /*===-- Operations on memory managers -------------------------------------===*/

 typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(

Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp?rev=224720&r1=224719&r2=224720&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp Mon Dec 22 12:53:11 2014
@@ -328,6 +328,14 @@ void *LLVMGetPointerToGlobal(LLVMExecuti
   return unwrap(EE)->getPointerToGlobal(unwrap<GlobalValue>(Global));
 }

+uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name) {
+  return unwrap(EE)->getGlobalValueAddress(Name);
+}
+
+uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name) {
+  return unwrap(EE)->getFunctionAddress(Name);
+}
+
 /*===-- Operations on memory managers -------------------------------------===*/

 namespace {

Modified: llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp?rev=224720&r1=224719&r2=224720&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp Mon Dec 22 12:53:11 2014
@@ -347,6 +347,44 @@ TEST_F(MCJITCAPITest, simple_function) {
   EXPECT_EQ(42, functionPointer.usable());
 }

+TEST_F(MCJITCAPITest, gva) {
+  SKIP_UNSUPPORTED_PLATFORM;
+
+  Module = LLVMModuleCreateWithName("simple_module");
+  LLVMSetTarget(Module, HostTriple.c_str());
+  LLVMValueRef GlobalVar = LLVMAddGlobal(Module, LLVMInt32Type(), "simple_value");
+  LLVMSetInitializer(GlobalVar, LLVMConstInt(LLVMInt32Type(), 42, 0));
+
+  buildMCJITOptions();
+  buildMCJITEngine();
+  buildAndRunPasses();
+
+  union {
+    uint64_t raw;
+    int32_t *usable;
+  } valuePointer;
+  valuePointer.raw = LLVMGetGlobalValueAddress(Engine, "simple_value");
+
+  EXPECT_EQ(42, *valuePointer.usable);
+}
+
+TEST_F(MCJITCAPITest, 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;



_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Endianness-fix-for-C-API-MCJIT-test.patch
Type: text/x-patch
Size: 1561 bytes
Desc: 0001-Endianness-fix-for-C-API-MCJIT-test.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150114/833103ab/attachment.bin>


More information about the llvm-commits mailing list