blob: 05a63f3d76216145fed229e40813edc6aabdc524 [file] [log] [blame]
Brian Gaekef212e472003-10-10 16:55:42 +00001//===-- DynamicLinker.cpp - Implement DynamicLinker interface -------------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
3// The LLVM Compiler Infrastructure
4//
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.
7//
8//===----------------------------------------------------------------------===//
Brian Gaekef212e472003-10-10 16:55:42 +00009//
10// Lightweight interface to dynamic library linking and loading, and dynamic
11// symbol lookup functionality, in whatever form the operating system
12// provides it.
13//
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.
17//
18// Note that we assume that if dlopen() is available, then dlsym() is too.
19//
20//===----------------------------------------------------------------------===//
21
22#include "Support/DynamicLinker.h"
23#include "Config/dlfcn.h"
24#include <cassert>
25
26bool 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 ();
30 return true;
31 }
32 return false;
33#else
34 assert (0 && "Dynamic object linking not implemented for this platform");
35#endif
36}
37
38void *GetAddressOfSymbol (const char *symbolName) {
39#if defined (HAVE_DLOPEN)
40 return dlsym (RTLD_DEFAULT, symbolName);
41#else
42 assert (0 && "Dynamic symbol lookup not implemented for this platform");
43#endif
44}
45
46// soft, cushiony C++ interface.
47void *GetAddressOfSymbol (const std::string &symbolName) {
48 return GetAddressOfSymbol (symbolName.c_str ());
49}