blob: 7c52d3bb5b1eef45e9b2a26d7fe6fc956fbfc60f [file] [log] [blame]
Brian Gaekef212e472003-10-10 16:55:42 +00001//===-- DynamicLinker.cpp - Implement DynamicLinker interface -------------===//
2//
3// Lightweight interface to dynamic library linking and loading, and dynamic
4// symbol lookup functionality, in whatever form the operating system
5// provides it.
6//
7// Possible future extensions include support for the HPUX shl_load()
8// interface, the Mac OS X NSLinkModule() interface, and the Windows
9// LoadLibrary() interface.
10//
11// Note that we assume that if dlopen() is available, then dlsym() is too.
12//
13//===----------------------------------------------------------------------===//
14
15#include "Support/DynamicLinker.h"
16#include "Config/dlfcn.h"
17#include <cassert>
18
19bool LinkDynamicObject (const char *filename, std::string *ErrorMessage) {
20#if defined (HAVE_DLOPEN)
21 if (dlopen (filename, RTLD_NOW | RTLD_GLOBAL) == 0) {
22 if (ErrorMessage) *ErrorMessage = dlerror ();
23 return true;
24 }
25 return false;
26#else
27 assert (0 && "Dynamic object linking not implemented for this platform");
28#endif
29}
30
31void *GetAddressOfSymbol (const char *symbolName) {
32#if defined (HAVE_DLOPEN)
33 return dlsym (RTLD_DEFAULT, symbolName);
34#else
35 assert (0 && "Dynamic symbol lookup not implemented for this platform");
36#endif
37}
38
39// soft, cushiony C++ interface.
40void *GetAddressOfSymbol (const std::string &symbolName) {
41 return GetAddressOfSymbol (symbolName.c_str ());
42}