LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Unix/DynamicLibrary.cpp

Go to the documentation of this file.
00001 //===- Unix/DynamicLibrary.cpp - Generic UNIX Dynamic Library ---*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by Reid Spencer and is distributed under the 
00006 // University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the generic UNIX variant of DynamicLibrary
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "Unix.h"
00015 
00016 namespace llvm {
00017 using namespace sys;
00018 
00019 DynamicLibrary::DynamicLibrary() : handle(0) {
00020 #if defined (HAVE_DLOPEN)
00021   if ((handle = dlopen(0, RTLD_NOW | RTLD_GLOBAL)) == 0)
00022     throw std::string( dlerror() );
00023 #else
00024   assert(!"Dynamic object linking not implemented for this platform");
00025 #endif
00026 }
00027 
00028 DynamicLibrary::DynamicLibrary(const char *filename) : handle(0) {
00029 #if defined (HAVE_DLOPEN)
00030   if ((handle = dlopen (filename, RTLD_NOW | RTLD_GLOBAL)) == 0)
00031     throw std::string( dlerror() );
00032 #else
00033   assert (!"Dynamic object linking not implemented for this platform");
00034 #endif
00035 }
00036 
00037 DynamicLibrary::~DynamicLibrary() {
00038   assert(handle != 0 && "Invalid DynamicLibrary handle");
00039 #if defined (HAVE_DLOPEN)
00040   dlclose(handle);
00041 #else
00042   assert (!"Dynamic object linking not implemented for this platform");
00043 #endif
00044 }
00045 
00046 void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) {
00047   assert(handle != 0 && "Invalid DynamicLibrary handle");
00048 #if defined(HAVE_DLOPEN)
00049     return dlsym (handle, symbolName);
00050 #else
00051   assert (0 && "Dynamic symbol lookup not implemented for this platform");
00052 #endif
00053 }
00054 
00055 }