[opengtl-commits] [626] add a hack that makes OpenShiva and OpenCTL to dynamic load themself, this forces the symbols to be globaly available and therefore alow llvm to find the symbols when OpenCTL /OpenShiva are used in plugins (which are loaded with private linking)

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 626
Author:   cyrille
Date:     2009-03-14 23:00:15 +0100 (Sat, 14 Mar 2009)

Log Message:
-----------
add a hack that makes OpenShiva and OpenCTL to dynamic load themself, this forces the symbols to be globaly available and therefore alow llvm to find the symbols when OpenCTL/OpenShiva are used in plugins (which are loaded with private linking)

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/OpenCTL/CMakeLists.txt
    trunk/OpenGTL/OpenCTL/OpenCTL/Module.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp


Modified: trunk/OpenGTL/OpenCTL/OpenCTL/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/CMakeLists.txt	2009-03-14 16:41:24 UTC (rev 625)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/CMakeLists.txt	2009-03-14 22:00:15 UTC (rev 626)
@@ -23,6 +23,7 @@
 add_definitions( "-D__STDC_LIMIT_MACROS" )
 add_definitions( -DCOUMPONENT_NAME="OpenCTL" )
 
+add_definitions( -D_OPENCTL_LIB_="${CMAKE_INSTALL_PREFIX}/lib/libOpenCTL.so.${OPENGTL_LIB_SOVERSION}")
 add_definitions( -D_OPENCTL_CTL_STD_LIB_SRC_DIR_="${CMAKE_CURRENT_SOURCE_DIR}")
 add_definitions( -D_OPENCTL_CTL_SHARE_DIR_="${SHARE_INSTALL_DIR}/ctl" )
 

Modified: trunk/OpenGTL/OpenCTL/OpenCTL/Module.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/Module.cpp	2009-03-14 16:41:24 UTC (rev 625)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/Module.cpp	2009-03-14 22:00:15 UTC (rev 626)
@@ -39,6 +39,7 @@
 #include <llvm/Bitcode/ReaderWriter.h>
 #include <llvm/System/Path.h>
 #include <llvm/ModuleProvider.h>
+#include <llvm/System/DynamicLibrary.h>
 
 #include <iostream>
 
@@ -131,6 +132,7 @@
   if(result)
   {
     d->compiled = true;
+    llvm::sys::DynamicLibrary::LoadLibraryPermanently( _OPENCTL_LIB_, 0 ); // This needed because when OpenCTL is used in a plugins, OpenCTL symbols aren't loaded globally and then llvm can't find them
     d->moduleData->doLink();
     d->moduleProvider = new llvm::ExistingModuleProvider( d->moduleData->llvmLinkedModule() );
     GTLCore::VirtualMachine::instance()->registerModule( d->moduleProvider );

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.cpp	2009-03-14 16:41:24 UTC (rev 625)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.cpp	2009-03-14 22:00:15 UTC (rev 626)
@@ -106,6 +106,16 @@
   return functions;
 }
 
+void ModuleData::linkWith( const GTLCore::String& _string)
+{
+  foreach( const GTLCore::String& mod, m_linkModuleWithArchives )
+  {
+    if( mod == _string ) return;
+  }
+  m_linkModuleWithArchives.push_back( _string );
+  
+}
+
 void ModuleData::linkWith( const llvm::Module* _module )
 {
   foreach( const llvm::Module* mod, m_linkModuleWith )
@@ -129,6 +139,13 @@
     GTL_DEBUG("Linking error: " << errorMessage );
     delete clone;
   }
+  foreach( const GTLCore::String& mod, m_linkModuleWithArchives )
+  {
+    bool v = false;
+    linker.LinkInArchive( llvm::sys::Path( mod), v);
+  }
+  
   linker.releaseModule();
   GTLCore::Optimiser::instance()->d->passManager()->run( *m_llvmModule );
 }
+

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.h	2009-03-14 16:41:24 UTC (rev 625)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ModuleData_p.h	2009-03-14 22:00:15 UTC (rev 626)
@@ -50,6 +50,7 @@
       {
         m_constants[_scopedName] = _constant;
       }
+      void linkWith( const GTLCore::String& _string);
       void linkWith( const llvm::Module* _module );
       void doLink();
       llvm::Module* llvmModule() { return m_llvmModule; }
@@ -65,6 +66,7 @@
       TypesManager* m_typesManager;
       std::map< ScopedName, llvm::Constant* > m_constants;
       std::list< const llvm::Module* > m_linkModuleWith;
+      std::list< GTLCore::String > m_linkModuleWithArchives;
   };
 }
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2009-03-14 16:41:24 UTC (rev 625)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2009-03-14 22:00:15 UTC (rev 626)
@@ -36,7 +36,7 @@
 add_definitions( "-D__STDC_LIMIT_MACROS" )
 add_definitions( -DCOUMPONENT_NAME="OpenShiva" )
 
-add_definitions( -D_OPENSHIVA_LIB_INSTALL_="${CMAKE_INSTALL_PREFIX}/lib/")
+add_definitions( -D_OPENSHIVA_LIB_="${CMAKE_INSTALL_PREFIX}/lib/libOpenShiva.so.${OPENGTL_VERSION}")
 add_definitions( -D_OPENSHIVA_SHIVA_STD_LIB_SRC_DIR_="${CMAKE_CURRENT_SOURCE_DIR}")
 add_definitions( -D_OPENSHIVA_SHIVA_LIBRARIES_DIR_="${SHARE_INSTALL_DIR}/shiva/libraries" )
 add_definitions( -D_OPENSHIVA_SHIVA_KERNELS_DIR_="${SHARE_INSTALL_DIR}/shiva/kernels" )

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp	2009-03-14 16:41:24 UTC (rev 625)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp	2009-03-14 22:00:15 UTC (rev 626)
@@ -24,6 +24,7 @@
 
 #include <llvm/Module.h>
 #include <llvm/ModuleProvider.h>
+#include <llvm/System/DynamicLibrary.h>
 
 #include "GTLCore/ErrorMessage.h"
 #include "GTLCore/Function.h"
@@ -163,6 +164,7 @@
   {
     d->compiled = true;
     // Register the compiled module in the virtual machine
+    llvm::sys::DynamicLibrary::LoadLibraryPermanently( _OPENSHIVA_LIB_, 0 ); // This needed because when OpenShiva is used in a plugins, OpenShiva symbols aren't loaded globally and then llvm can't find them (FIXME move that somewhere else)
     d->m_moduleData->doLink();
     d->moduleProvider = new llvm::ExistingModuleProvider( d->m_moduleData->llvmModule() );
     GTLCore::VirtualMachine::instance()->registerModule( d->moduleProvider );


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/