[llvm-branch-commits] [llvm-branch] r243655 - Merging r243589 and r243609:

Hans Wennborg hans at hanshq.net
Thu Jul 30 09:31:17 PDT 2015


Author: hans
Date: Thu Jul 30 11:31:16 2015
New Revision: 243655

URL: http://llvm.org/viewvc/llvm-project?rev=243655&view=rev
Log:
Merging r243589 and r243609:
------------------------------------------------------------------------
r243589 | lhames | 2015-07-29 16:12:33 -0700 (Wed, 29 Jul 2015) | 6 lines

[MCJIT] Fix PR20656 by teaching MCJIT to honor ExecutionEngine's global mapping.

This is important for users of the C API who can't supply custom symbol
resolvers yet.
------------------------------------------------------------------------

------------------------------------------------------------------------
r243609 | lhames | 2015-07-29 19:05:37 -0700 (Wed, 29 Jul 2015) | 2 lines

[MCJIT] Fix a memory leak in a unit test that was introduced in r243589.
------------------------------------------------------------------------

Modified:
    llvm/branches/release_37/   (props changed)
    llvm/branches/release_37/lib/ExecutionEngine/ExecutionEngine.cpp
    llvm/branches/release_37/lib/ExecutionEngine/MCJIT/MCJIT.cpp
    llvm/branches/release_37/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp

Propchange: llvm/branches/release_37/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jul 30 11:31:16 2015
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,242236,242239,242281,242288,242296,242331,242341,242410,242412,242433-242434,242442,242543,242673,242680,242706,242721-242722,242733-242735,242742,242869,242919,242993,243001,243116,243263,243294,243361,243469,243485,243500,243519,243531,243636,243638,243640
+/llvm/trunk:155241,242236,242239,242281,242288,242296,242331,242341,242410,242412,242433-242434,242442,242543,242673,242680,242706,242721-242722,242733-242735,242742,242869,242919,242993,243001,243116,243263,243294,243361,243469,243485,243500,243519,243531,243589,243609,243636,243638,243640

Modified: llvm/branches/release_37/lib/ExecutionEngine/ExecutionEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_37/lib/ExecutionEngine/ExecutionEngine.cpp?rev=243655&r1=243654&r2=243655&view=diff
==============================================================================
--- llvm/branches/release_37/lib/ExecutionEngine/ExecutionEngine.cpp (original)
+++ llvm/branches/release_37/lib/ExecutionEngine/ExecutionEngine.cpp Thu Jul 30 11:31:16 2015
@@ -180,10 +180,17 @@ uint64_t ExecutionEngineState::RemoveMap
 }
 
 std::string ExecutionEngine::getMangledName(const GlobalValue *GV) {
+  assert(GV->hasName() && "Global must have name.");
+
   MutexGuard locked(lock);
-  Mangler Mang;
   SmallString<128> FullName;
-  Mang.getNameWithPrefix(FullName, GV, false);
+
+  const DataLayout &DL =
+    GV->getParent()->getDataLayout().isDefault()
+      ? *getDataLayout()
+      : GV->getParent()->getDataLayout();
+
+  Mangler::getNameWithPrefix(FullName, GV->getName(), DL);
   return FullName.str();
 }
 

Modified: llvm/branches/release_37/lib/ExecutionEngine/MCJIT/MCJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_37/lib/ExecutionEngine/MCJIT/MCJIT.cpp?rev=243655&r1=243654&r2=243655&view=diff
==============================================================================
--- llvm/branches/release_37/lib/ExecutionEngine/MCJIT/MCJIT.cpp (original)
+++ llvm/branches/release_37/lib/ExecutionEngine/MCJIT/MCJIT.cpp Thu Jul 30 11:31:16 2015
@@ -266,6 +266,12 @@ void MCJIT::finalizeModule(Module *M) {
 RuntimeDyld::SymbolInfo MCJIT::findExistingSymbol(const std::string &Name) {
   SmallString<128> FullName;
   Mangler::getNameWithPrefix(FullName, Name, *TM->getDataLayout());
+
+  if (void *Addr = getPointerToGlobalIfAvailable(FullName))
+    return RuntimeDyld::SymbolInfo(static_cast<uint64_t>(
+                                     reinterpret_cast<uintptr_t>(Addr)),
+                                   JITSymbolFlags::Exported);
+
   return Dyld.getSymbol(FullName);
 }
 

Modified: llvm/branches/release_37/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_37/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp?rev=243655&r1=243654&r2=243655&view=diff
==============================================================================
--- llvm/branches/release_37/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp (original)
+++ llvm/branches/release_37/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp Thu Jul 30 11:31:16 2015
@@ -488,3 +488,37 @@ TEST_F(MCJITCAPITest, yield) {
   EXPECT_TRUE(didCallYield);
 }
 
+static int localTestFunc() {
+  return 42;
+}
+
+TEST_F(MCJITCAPITest, addGlobalMapping) {
+  SKIP_UNSUPPORTED_PLATFORM;
+
+  Module = LLVMModuleCreateWithName("testModule");
+  LLVMTypeRef FunctionType = LLVMFunctionType(LLVMInt32Type(), NULL, 0, 0);
+  LLVMValueRef MappedFn = LLVMAddFunction(Module, "mapped_fn", FunctionType);
+
+  Function = LLVMAddFunction(Module, "test_fn", FunctionType);
+  LLVMBasicBlockRef Entry = LLVMAppendBasicBlock(Function, "");
+  LLVMBuilderRef Builder = LLVMCreateBuilder();
+  LLVMPositionBuilderAtEnd(Builder, Entry);
+  LLVMValueRef RetVal = LLVMBuildCall(Builder, MappedFn, NULL, 0, "");
+  LLVMBuildRet(Builder, RetVal);
+  LLVMDisposeBuilder(Builder);
+
+  LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error);
+  LLVMDisposeMessage(Error);
+
+  buildMCJITOptions();
+  buildMCJITEngine();
+
+  LLVMAddGlobalMapping(Engine, MappedFn, reinterpret_cast<void*>(&localTestFunc));
+
+  buildAndRunPasses();
+
+  uint64_t raw = LLVMGetFunctionAddress(Engine, "test_fn");
+  int (*usable)() = (int (*)()) raw;
+
+  EXPECT_EQ(42, usable());
+}





More information about the llvm-branch-commits mailing list