Fix handling of asm specifiers for external globals. This unbreaks many programs
authorChris Lattner <sabre@nondot.org>
Fri, 28 Jul 2006 21:11:31 +0000 (21:11 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 28 Jul 2006 21:11:31 +0000 (21:11 +0000)
on leopard in the jit.

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

lib/ExecutionEngine/JIT/Intercept.cpp

index 43298d6349f15bff967caff02cc3e6437635c1eb..db6165f78183e72bcaec4df473799ab3bc5a0790 100644 (file)
@@ -100,9 +100,20 @@ void *JIT::getPointerToNamedFunction(const std::string &Name) {
   // but print a warning.
   if (Name == "__main") return (void*)(intptr_t)&__mainFunc;
 
+  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(Name);
+  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);
+    if (Ptr) return Ptr;
+  }
 
   std::cerr << "ERROR: Program used external function '" << Name
             << "' which could not be resolved!\n";