Fix a thinko in the JIT where the address of a GV was only recorded in the map
authorNate Begeman <natebegeman@mac.com>
Wed, 4 Mar 2009 19:10:38 +0000 (19:10 +0000)
committerNate Begeman <natebegeman@mac.com>
Wed, 4 Mar 2009 19:10:38 +0000 (19:10 +0000)
  on failure to resolve it.
Do not abort on failure to resolve an external symbol when using dlsym stubs,
  since the symbol may not be in the JIT's address space.  Just use 0.
Allow dlsym stubs to differentiate between GlobalVars and Functions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66050 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/JIT/JIT.cpp
lib/ExecutionEngine/JIT/JITEmitter.cpp

index 3fd5be7d16ed7ce49d28a48175a213fca6d1b220..633a75ed61c5fa41bb9ef480dd1d338acc059447 100644 (file)
@@ -609,12 +609,12 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
       return (void*)&__dso_handle;
 #endif
     Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(GV->getName().c_str());
-    if (Ptr == 0) {
+    if (Ptr == 0 && !areDlsymStubsEnabled()) {
       cerr << "Could not resolve external global address: "
            << GV->getName() << "\n";
       abort();
-    addGlobalMapping(GV, Ptr);
     }
+    addGlobalMapping(GV, Ptr);
   } else {
     // GlobalVariable's which are not "constant" will cause trouble in a server
     // situation. It's returned in the same block of memory as code which may
index 5c6236dcaebbe7570003efdfe28509a3d5cb6434..22515f3a82c18b55cb127f35dc1d869fac566828 100644 (file)
@@ -1348,12 +1348,22 @@ void JIT::updateDlsymStubTable() {
   for (unsigned i = 0; i != GVs.size(); ++i)
     MCE->emitInt32(Offsets[i]);
   
-  // Emit the pointers
-  for (unsigned i = 0; i != GVs.size(); ++i)
+  // Emit the pointers.  Verify that they are at least 2-byte aligned, and set
+  // the low bit to 0 == GV, 1 == Function, so that the client code doing the
+  // relocation can write the relocated pointer at the appropriate place in
+  // the stub.
+  for (unsigned i = 0; i != GVs.size(); ++i) {
+    intptr_t Ptr = (intptr_t)Ptrs[i];
+    assert((Ptr & 1) == 0 && "Stub pointers must be at least 2-byte aligned!");
+    
+    if (isa<Function>(GVs[i]))
+      Ptr |= (intptr_t)1;
+           
     if (sizeof(void *) == 8)
-      MCE->emitInt64((intptr_t)Ptrs[i]);
+      MCE->emitInt64(Ptr);
     else
-      MCE->emitInt32((intptr_t)Ptrs[i]);
+      MCE->emitInt32(Ptr);
+  }
   
   // Emit the strings
   for (unsigned i = 0; i != GVs.size(); ++i)