[llvm-commits] a windows pass registration patch

hume npx humeafo at gmail.com
Sat Jun 18 09:53:25 PDT 2011


>
> following is a patch that enables shared module pass registration on
> Windows with as little modification as possible, basically the pass can
> work, but other facilities may not because the static libray used in llvm
> and the static (should be global across DLL and exes)variables used in llvm,
> to make shared library fully functional, there are more work to done, but
> basically, the method present here should work.
>

without touch the class template and method definitions, following is the
only reimplementaion of the original passregistry.cpp header lines:

#include "llvm/PassRegistry.h"
#include "llvm/PassSupport.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringMap.h"
#include <vector>

using namespace llvm;

// FIXME: We use ManagedStatic to erase the pass registrar on shutdown.
// Unfortunately, passes are registered with static ctors, and having
// llvm_shutdown clear this map prevents successful ressurection after
// llvm_shutdown is run.  Ideally we should find a solution so that we don't
// leak the map, AND can still resurrect after shutdown.
#if defined(_WIN32)
  typedef PassRegistry* (*getPassRegistryPtr)();
  extern "C" __declspec(dllexport)
#endif
PassRegistry *llvmapi_getPassRegistryAddress() {
  static ManagedStatic<PassRegistry> PassRegistryObj;
  return &*PassRegistryObj;
}

PassRegistry *PassRegistry::getPassRegistry() {
  getPassRegistryPtr Ap = llvmapi_getPassRegistryAddress;
#if defined(_WIN32)
  static void *theAp = 0;
  if (theAp==0) {
    sys::DynamicLibrary::LoadLibraryPermanently(0);
    theAp =
sys::DynamicLibrary::SearchForAddressOfSymbol("llvmapi_getPassRegistryAddress");
    if(!theAp) theAp = (void*)-1;
  }
  if (theAp!=(void*)-1) {
    Ap = (getPassRegistryPtr)theAp;
  }
#endif
  return (*Ap)();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110619/0eee5db6/attachment.html>


More information about the llvm-commits mailing list