Merge pull request #487 from mayerwin/patch-1
[mono.git] / mono / mini / mini-llvm-cpp.cpp
index 626c7dab8c85da5e00c206425461f8ca036dcb56..2b90cd692daac6ad903e56bbb23cbbb5ff4cc6e2 100644 (file)
 // possible
 //
 
+#include "config.h"
+//undef those as llvm defines them on its own config.h as well.
+#undef PACKAGE_BUGREPORT
+#undef PACKAGE_NAME
+#undef PACKAGE_STRING
+#undef PACKAGE_TARNAME
+#undef PACKAGE_VERSION
+
 #include <stdint.h>
 
 #include <llvm/Support/raw_ostream.h>
        ((LLVM_MAJOR_VERSION > (major)) ||                                                                      \
         ((LLVM_MAJOR_VERSION == (major)) && (LLVM_MINOR_VERSION >= (minor))))
 
+// extern "C" void LLVMInitializeARMTargetInfo();
+// extern "C" void LLVMInitializeARMTarget ();
+// extern "C" void LLVMInitializeARMTargetMC ();
+
 using namespace llvm;
 
 class MonoJITMemoryManager : public JITMemoryManager
@@ -61,6 +73,7 @@ private:
 public:
        /* Callbacks installed by mono */
        AllocCodeMemoryCb *alloc_cb;
+       DlSymCb *dlsym_cb;
 
        MonoJITMemoryManager ();
        ~MonoJITMemoryManager ();
@@ -121,13 +134,16 @@ public:
        }
 
        virtual void* getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure) {
-               if (!strcmp (Name.c_str (), "__bzero")) {
-                       return (void*)bzero;
-               } else {
-                       outs () << "Unable to resolve: " << Name << "\n";
+               void *res;
+               char *err;
+
+               err = dlsym_cb (Name.c_str (), &res);
+               if (err) {
+                       outs () << "Unable to resolve: " << Name << ": " << err << "\n";
                        assert(0);
                        return NULL;
                }
+               return res;
        }
 };
 
@@ -496,18 +512,25 @@ force_pass_linking (void)
 }
 
 LLVMExecutionEngineRef
-mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, FunctionEmittedCb *emitted_cb, ExceptionTableCb *exception_cb)
+mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, FunctionEmittedCb *emitted_cb, ExceptionTableCb *exception_cb, DlSymCb *dlsym_cb)
 {
   std::string Error;
 
   force_pass_linking ();
 
+#ifdef TARGET_ARM
+  LLVMInitializeARMTarget ();
+  LLVMInitializeARMTargetInfo ();
+  LLVMInitializeARMTargetMC ();
+#else
   LLVMInitializeX86Target ();
   LLVMInitializeX86TargetInfo ();
   LLVMInitializeX86TargetMC ();
+#endif
 
   mono_mm = new MonoJITMemoryManager ();
   mono_mm->alloc_cb = alloc_cb;
+  mono_mm->dlsym_cb = dlsym_cb;
 
   //JITExceptionHandling = true;
   // PrettyStackTrace installs signal handlers which trip up libgc