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

Peter Zotov whitequark at whitequark.org
Wed Jan 14 10:02:25 PST 2015


On 2015-01-14 20:53, Vasileios Kalintiris wrote:
> 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?

LGTM.

> 
> 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

-- 
Peter Zotov



More information about the llvm-commits mailing list