blob: 24d7f5fb8465bb32b407ccfad317c66913c94438 [file] [log] [blame]
Reid Spencer0de02a62004-11-18 04:33:39 +00001//===- Unix/DynamicLibrary.cpp - Generic UNIX Dynamic Library ---*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Reid Spencer and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the generic UNIX variant of DynamicLibrary
11//
12//===----------------------------------------------------------------------===//
13
14#include "Unix.h"
15
16namespace llvm {
17using namespace sys;
18
Reid Spencer441cc2a2004-11-29 10:39:46 +000019DynamicLibrary::DynamicLibrary() : handle(0) {
20#if defined (HAVE_DLOPEN)
21 if ((handle = dlopen(0, RTLD_NOW | RTLD_GLOBAL)) == 0)
22 throw std::string( dlerror() );
23#else
24 assert(!"Dynamic object linking not implemented for this platform");
25#endif
26}
Reid Spencer0de02a62004-11-18 04:33:39 +000027
Reid Spencer441cc2a2004-11-29 10:39:46 +000028DynamicLibrary::DynamicLibrary(const char *filename) : handle(0) {
Reid Spencer0de02a62004-11-18 04:33:39 +000029#if defined (HAVE_DLOPEN)
30 if ((handle = dlopen (filename, RTLD_NOW | RTLD_GLOBAL)) == 0)
31 throw std::string( dlerror() );
32#else
33 assert (!"Dynamic object linking not implemented for this platform");
34#endif
35}
36
37DynamicLibrary::~DynamicLibrary() {
38 assert(handle != 0 && "Invalid DynamicLibrary handle");
39#if defined (HAVE_DLOPEN)
40 dlclose(handle);
41#else
42 assert (!"Dynamic object linking not implemented for this platform");
43#endif
44}
45
46void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) {
47 assert(handle != 0 && "Invalid DynamicLibrary handle");
48#if defined(HAVE_DLOPEN)
49 return dlsym (handle, symbolName);
50#else
51 assert (0 && "Dynamic symbol lookup not implemented for this platform");
52#endif
53}
54
55}