Reid Spencer | 0de02a6 | 2004-11-18 04:33:39 +0000 | [diff] [blame^] | 1 | //===- 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 | |
| 16 | namespace llvm { |
| 17 | using namespace sys; |
| 18 | |
| 19 | |
| 20 | DynamicLibrary::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 | |
| 29 | DynamicLibrary::~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 | |
| 38 | void *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 | } |