[llvm-branch-commits] [llvm-branch] r101630 - in /llvm/branches/Apple/Morbo/lib/ExecutionEngine/JIT: JIT.h JITEmitter.cpp

Eric Christopher echristo at apple.com
Sat Apr 17 00:43:02 PDT 2010


Author: echristo
Date: Sat Apr 17 02:43:02 2010
New Revision: 101630

URL: http://llvm.org/viewvc/llvm-project?rev=101630&view=rev
Log:
Fix a few more issues with dlsym stubs.

Patch from Mon Ping. Fixes rdar://7829563


Modified:
    llvm/branches/Apple/Morbo/lib/ExecutionEngine/JIT/JIT.h
    llvm/branches/Apple/Morbo/lib/ExecutionEngine/JIT/JITEmitter.cpp

Modified: llvm/branches/Apple/Morbo/lib/ExecutionEngine/JIT/JIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/ExecutionEngine/JIT/JIT.h?rev=101630&r1=101629&r2=101630&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/ExecutionEngine/JIT/JIT.h (original)
+++ llvm/branches/Apple/Morbo/lib/ExecutionEngine/JIT/JIT.h Sat Apr 17 02:43:02 2010
@@ -151,6 +151,9 @@
   ///
   void *recompileAndRelinkFunction(Function *F);
 
+  /// clearLazyStubMap - clears the lazy stub map.
+  void clearLazyStubMap();
+
   /// freeMachineCodeForFunction - deallocate memory used to code-generate this
   /// Function.
   ///

Modified: llvm/branches/Apple/Morbo/lib/ExecutionEngine/JIT/JITEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=101630&r1=101629&r2=101630&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/ExecutionEngine/JIT/JITEmitter.cpp (original)
+++ llvm/branches/Apple/Morbo/lib/ExecutionEngine/JIT/JITEmitter.cpp Sat Apr 17 02:43:02 2010
@@ -231,6 +231,9 @@
     /// contents of the slots or the memory associated with the GOT.
     unsigned getGOTIndexForAddr(void *addr);
 
+    /// Clear lazy sub map
+    void clearLazyStubMap();
+
     /// JITCompilerFn - This function is called to resolve a stub to a compiled
     /// address.  If the LLVM Function corresponding to the stub has not yet
     /// been compiled, this function compiles it first.
@@ -461,6 +464,9 @@
     /// function body.
     void deallocateMemForFunction(const Function *F);
 
+    /// clearLazyStubMap - clear the LazyStubMap
+    void clearLazyStubMap() { Resolver.clearLazyStubMap(); }
+
     /// getExternalFnStubs - Accessor for the JIT to find stubs emitted for
     /// MachineRelocations that reference external functions by name.
     const StringMap<void*> &getExternalFnStubs() const { return ExtFnStubs; }
@@ -642,9 +648,13 @@
     // If we are JIT'ing non-lazily but need to call a function that does not
     // exist yet, add it to the JIT's work list so that we can fill in the
     // stub address later.
-    assert(!isNonGhostDeclaration(F) && !F->hasAvailableExternallyLinkage() &&
-           "'Actual' should have been set above.");
-    TheJIT->addPendingFunction(F);
+
+    // We can't assert here with
+    // assert(!isNonGhostDeclaration(F) && !F->hasAvailableExternallyLinkage() &&
+    //       "'Actual' should have been set above.");
+    // because we can enter this case when TheJIT->areDlsymStubsEnabled()
+    if (!isNonGhostDeclaration(F) && !F->hasAvailableExternallyLinkage())
+      TheJIT->addPendingFunction(F);
   }
 
   return Stub;
@@ -697,6 +707,12 @@
   return idx;
 }
 
+void JITResolver::clearLazyStubMap() {
+  MutexGuard locked(TheJIT->lock);
+  FunctionToLazyStubMapTy &FM = state.getFunctionToLazyStubMap(locked);
+  FM.clear();
+}
+
 void JITResolver::getRelocatableGVs(SmallVectorImpl<GlobalValue*> &GVs,
                                     SmallVectorImpl<void*> &Ptrs) {
   MutexGuard locked(TheJIT->lock);
@@ -817,8 +833,8 @@
     // If this is an external function pointer, we can force the JIT to
     // 'compile' it, which really just adds it to the map.  In dlsym mode,
     // external functions are forced through a stub, regardless of reloc type.
-    if (isNonGhostDeclaration(F) || F->hasAvailableExternallyLinkage() &&
-        !TheJIT->areDlsymStubsEnabled())
+    if ((isNonGhostDeclaration(F) || F->hasAvailableExternallyLinkage()) &&
+         !TheJIT->areDlsymStubsEnabled())
       return TheJIT->getPointerToFunction(F);
   }
 
@@ -1154,8 +1170,8 @@
 
           // If the target REALLY wants a stub for this function, emit it now.
           if (MR.mayNeedFarStub() && !TheJIT->areDlsymStubsEnabled()) {
-	    ResultPtr = Resolver.getExternalFunctionStub(ResultPtr);
-	  } else if (TheJIT->areDlsymStubsEnabled()) {
+            ResultPtr = Resolver.getExternalFunctionStub(ResultPtr);
+          } else if (TheJIT->areDlsymStubsEnabled()) {
               void *&Stub = ExtFnStubs[MR.getExternalSymbol()];
               if (!Stub) {
                 Stub = Resolver.getExternalFunctionStub((void *)&Stub);
@@ -1687,6 +1703,13 @@
   JE->getMemMgr()->SetDlsymTable(JE->finishGVStub());
 }
 
+/// clear the lazy stub map.
+void JIT::clearLazyStubMap() {
+  assert(isa<JITEmitter>(JCE) && "Unexpected MCE?");
+  cast<JITEmitter>(JCE)->clearLazyStubMap();
+}
+
+
 /// freeMachineCodeForFunction - release machine code memory for given Function.
 ///
 void JIT::freeMachineCodeForFunction(Function *F) {





More information about the llvm-branch-commits mailing list