[llvm-commits] [llvm] r52335 - in /llvm/trunk: include/llvm/ExecutionEngine/ExecutionEngine.h lib/ExecutionEngine/JIT/Intercept.cpp

Chris Lattner sabre at nondot.org
Mon Jun 16 10:44:14 PDT 2008


Author: lattner
Date: Mon Jun 16 12:44:14 2008
New Revision: 52335

URL: http://llvm.org/viewvc/llvm-project?rev=52335&view=rev
Log:
Add a new flag that disables symbol lookup with dlsym when set.  This allows
a JIT client to completely control symbol lookup with the LazyFunctionCreator
interface.

Modified:
    llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
    llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp

Modified: llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h?rev=52335&r1=52334&r2=52335&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h Mon Jun 16 12:44:14 2008
@@ -65,6 +65,7 @@
   const TargetData *TD;
   ExecutionEngineState state;
   bool LazyCompilationDisabled;
+  bool SymbolSearchingDisabled;
 
 protected:
   /// Modules - This is a list of ModuleProvider's that we are JIT'ing from.  We
@@ -243,13 +244,22 @@
   }
   
   /// DisableLazyCompilation - If called, the JIT will abort if lazy compilation
-  // is ever attempted.
-  void DisableLazyCompilation() {
-    LazyCompilationDisabled = true;
+  /// is ever attempted.
+  void DisableLazyCompilation(bool Disabled = true) {
+    LazyCompilationDisabled = Disabled;
   }
   bool isLazyCompilationDisabled() const {
     return LazyCompilationDisabled;
   }
+  /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
+  /// symbols with dlsym.  A client can still use InstallLazyFunctionCreator to
+  /// resolve symbols in a custom way.
+  void DisableSymbolSearching(bool Disabled = true) {
+    SymbolSearchingDisabled = Disabled;
+  }
+  bool isSymbolSearchingDisabled() const {
+    return SymbolSearchingDisabled;
+  }
   
   
   /// InstallLazyFunctionCreator - If an unknown function is needed, the

Modified: llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp?rev=52335&r1=52334&r2=52335&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp Mon Jun 16 12:44:14 2008
@@ -91,44 +91,46 @@
 /// for resolving library symbols, not code generated symbols.
 ///
 void *JIT::getPointerToNamedFunction(const std::string &Name) {
-  // Check to see if this is one of the functions we want to intercept.  Note,
-  // we cast to intptr_t here to silence a -pedantic warning that complains
-  // about casting a function pointer to a normal pointer.
-  if (Name == "exit") return (void*)(intptr_t)&jit_exit;
-  if (Name == "atexit") return (void*)(intptr_t)&jit_atexit;
+  if (!isSymbolSearchingDisabled()) {
+    // Check to see if this is one of the functions we want to intercept.  Note,
+    // we cast to intptr_t here to silence a -pedantic warning that complains
+    // about casting a function pointer to a normal pointer.
+    if (Name == "exit") return (void*)(intptr_t)&jit_exit;
+    if (Name == "atexit") return (void*)(intptr_t)&jit_atexit;
 
-  const char *NameStr = Name.c_str();
-  // If this is an asm specifier, skip the sentinal.
-  if (NameStr[0] == 1) ++NameStr;
-  
-  // If it's an external function, look it up in the process image...
-  void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
-  if (Ptr) return Ptr;
-  
-  // If it wasn't found and if it starts with an underscore ('_') character, and
-  // has an asm specifier, try again without the underscore.
-  if (Name[0] == 1 && NameStr[0] == '_') {
-    Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1);
+    const char *NameStr = Name.c_str();
+    // If this is an asm specifier, skip the sentinal.
+    if (NameStr[0] == 1) ++NameStr;
+    
+    // If it's an external function, look it up in the process image...
+    void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
     if (Ptr) return Ptr;
-  }
-  
-  // darwin/ppc adds $LDBLStub suffixes to various symbols like printf.  These
-  // are references to hidden visibility symbols that dlsym cannot resolve.  If
-  // we have one of these, strip off $LDBLStub and try again.
+    
+    // If it wasn't found and if it starts with an underscore ('_') character,
+    // and has an asm specifier, try again without the underscore.
+    if (Name[0] == 1 && NameStr[0] == '_') {
+      Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1);
+      if (Ptr) return Ptr;
+    }
+    
+    // Darwin/PPC adds $LDBLStub suffixes to various symbols like printf.  These
+    // are references to hidden visibility symbols that dlsym cannot resolve.
+    // If we have one of these, strip off $LDBLStub and try again.
 #if defined(__APPLE__) && defined(__ppc__)
-  if (Name.size() > 9 && Name[Name.size()-9] == '$' &&
-      memcmp(&Name[Name.size()-8], "LDBLStub", 8) == 0) {
-    // First try turning $LDBLStub into $LDBL128.  If that fails, strip it off.
-    // This mirrors logic in libSystemStubs.a.
-    std::string Prefix = std::string(Name.begin(), Name.end()-9);
-    if (void *Ptr = getPointerToNamedFunction(Prefix+"$LDBL128"))
-      return Ptr;
-    if (void *Ptr = getPointerToNamedFunction(Prefix))
-      return Ptr;
-  }
+    if (Name.size() > 9 && Name[Name.size()-9] == '$' &&
+        memcmp(&Name[Name.size()-8], "LDBLStub", 8) == 0) {
+      // First try turning $LDBLStub into $LDBL128. If that fails, strip it off.
+      // This mirrors logic in libSystemStubs.a.
+      std::string Prefix = std::string(Name.begin(), Name.end()-9);
+      if (void *Ptr = getPointerToNamedFunction(Prefix+"$LDBL128"))
+        return Ptr;
+      if (void *Ptr = getPointerToNamedFunction(Prefix))
+        return Ptr;
+    }
 #endif
+  }
   
-  /// If a LazyFunctionCreator is installed, use it to get/create the function. 
+  /// If a LazyFunctionCreator is installed, use it to get/create the function.
   if (LazyFunctionCreator)
     if (void *RP = LazyFunctionCreator(Name))
       return RP;





More information about the llvm-commits mailing list