blob: c513f51f95ca4b0de8bfe1d97f0bd66af4b412d2 [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
19
20DynamicLibrary::DynamicLibrary(const char *filename) {
21#if defined (HAVE_DLOPEN)
22 if ((handle = dlopen (filename, RTLD_NOW | RTLD_GLOBAL)) == 0)
23 throw std::string( dlerror() );
24#else
25 assert (!"Dynamic object linking not implemented for this platform");
26#endif
27}
28
29DynamicLibrary::~DynamicLibrary() {
30 assert(handle != 0 && "Invalid DynamicLibrary handle");
31#if defined (HAVE_DLOPEN)
32 dlclose(handle);
33#else
34 assert (!"Dynamic object linking not implemented for this platform");
35#endif
36}
37
38void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) {
39 assert(handle != 0 && "Invalid DynamicLibrary handle");
40#if defined(HAVE_DLOPEN)
41 return dlsym (handle, symbolName);
42#else
43 assert (0 && "Dynamic symbol lookup not implemented for this platform");
44#endif
45}
46
47}