1 //===-- DynamicLinker.cpp - Implement DynamicLinker interface -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Lightweight interface to dynamic library linking and loading, and dynamic
11 // symbol lookup functionality, in whatever form the operating system
14 // Possible future extensions include support for the HPUX shl_load()
15 // interface, the Mac OS X NSLinkModule() interface, and the Windows
16 // LoadLibrary() interface.
18 // Note that we assume that if dlopen() is available, then dlsym() is too.
20 //===----------------------------------------------------------------------===//
22 #include "Support/DynamicLinker.h"
23 #include "Config/dlfcn.h"
26 bool LinkDynamicObject (const char *filename, std::string *ErrorMessage) {
27 #if defined (HAVE_DLOPEN)
28 if (dlopen (filename, RTLD_NOW | RTLD_GLOBAL) == 0) {
29 if (ErrorMessage) *ErrorMessage = dlerror ();
34 assert (0 && "Dynamic object linking not implemented for this platform");
38 void *GetAddressOfSymbol (const char *symbolName) {
39 #if defined (HAVE_DLOPEN)
41 return dlsym (RTLD_DEFAULT, symbolName);
43 static void* CurHandle = dlopen(0, RTLD_LAZY);
44 return dlsym(CurHandle, symbolName);
47 assert (0 && "Dynamic symbol lookup not implemented for this platform");
51 // soft, cushiony C++ interface.
52 void *GetAddressOfSymbol (const std::string &symbolName) {
53 return GetAddressOfSymbol (symbolName.c_str ());