llvm.org GIT mirror llvm / 72501b4
remove dead code, noone creates instances of "DynamicLibrary", so the ctor and dtor are dead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74926 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
2 changed file(s) with 31 addition(s) and 67 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_SYSTEM_DYNAMIC_LIBRARY_H
1414 #define LLVM_SYSTEM_DYNAMIC_LIBRARY_H
1515
16 #include "llvm/System/Path.h"
1716 #include
1817
1918 namespace llvm {
2928 /// but rather the main program itself, useful on Windows where the main
3029 /// executable cannot be searched.
3130 class DynamicLibrary {
32 /// @name Constructors
33 /// @{
34 public:
35 /// Construct a DynamicLibrary that represents the currently executing
36 /// program. The program must have been linked with -export-dynamic or
37 /// -dlopen self for this to work.
38 /// @throws std::string indicating why the program couldn't be opened.
39 /// @brief Open program as dynamic library.
40 DynamicLibrary();
31 DynamicLibrary(); // DO NOT IMPLEMENT
32 public:
33 /// This function allows a library to be loaded without instantiating a
34 /// DynamicLibrary object. Consequently, it is marked as being permanent
35 /// and will only be unloaded when the program terminates. This returns
36 /// false on success or returns true and fills in *ErrMsg on failure.
37 /// @brief Open a dynamic library permanently.
38 static bool LoadLibraryPermanently(const char *filename,
39 std::string *ErrMsg = 0);
4140
42 /// After destruction, the symbols of the library will no longer be
43 /// available to the program.
44 /// @brief Closes the DynamicLibrary
45 ~DynamicLibrary();
41 /// This function will search through all previously loaded dynamic
42 /// libraries for the symbol \p symbolName. If it is found, the addressof
43 /// that symbol is returned. If not, null is returned. Note that this will
44 /// search permanently loaded libraries (LoadLibraryPermanently) as well
45 /// as ephemerally loaded libraries (constructors).
46 /// @throws std::string on error.
47 /// @brief Search through libraries for address of a symbol
48 static void *SearchForAddressOfSymbol(const char *symbolName);
4649
47 /// @}
48 /// @name Functions
49 /// @{
50 public:
51 /// This function allows a library to be loaded without instantiating a
52 /// DynamicLibrary object. Consequently, it is marked as being permanent
53 /// and will only be unloaded when the program terminates. This returns
54 /// false on success or returns true and fills in *ErrMsg on failure.
55 /// @brief Open a dynamic library permanently.
56 static bool LoadLibraryPermanently(const char* filename,
57 std::string *ErrMsg = 0);
50 /// @brief Convenience function for C++ophiles.
51 static void *SearchForAddressOfSymbol(const std::string &symbolName) {
52 return SearchForAddressOfSymbol(symbolName.c_str());
53 }
5854
59 /// This function will search through all previously loaded dynamic
60 /// libraries for the symbol \p symbolName. If it is found, the addressof
61 /// that symbol is returned. If not, null is returned. Note that this will
62 /// search permanently loaded libraries (LoadLibraryPermanently) as well
63 /// as ephemerally loaded libraries (constructors).
64 /// @throws std::string on error.
65 /// @brief Search through libraries for address of a symbol
66 static void* SearchForAddressOfSymbol(const char* symbolName);
55 /// This functions permanently adds the symbol \p symbolName with the
56 /// value \p symbolValue. These symbols are searched before any
57 /// libraries.
58 /// @brief Add searchable symbol/value pair.
59 static void AddSymbol(const char *symbolName, void *symbolValue);
6760
68 /// @brief Convenience function for C++ophiles.
69 static void* SearchForAddressOfSymbol(const std::string& symbolName) {
70 return SearchForAddressOfSymbol(symbolName.c_str());
71 }
72
73 /// This functions permanently adds the symbol \p symbolName with the
74 /// value \p symbolValue. These symbols are searched before any
75 /// libraries.
76 /// @brief Add searchable symbol/value pair.
77 static void AddSymbol(const char* symbolName, void *symbolValue);
78
79 /// @brief Convenience function for C++ophiles.
80 static void AddSymbol(const std::string& symbolName, void *symbolValue) {
81 AddSymbol(symbolName.c_str(), symbolValue);
82 }
83
84 /// @}
85 /// @name Implementation
86 /// @{
87 protected:
88 void* handle; // Opaque handle for information about the library
89 DynamicLibrary(const DynamicLibrary&); ///< Do not implement
90 DynamicLibrary& operator=(const DynamicLibrary&); ///< Do not implement
91 /// @}
61 /// @brief Convenience function for C++ophiles.
62 static void AddSymbol(const std::string &symbolName, void *symbolValue) {
63 AddSymbol(symbolName.c_str(), symbolValue);
64 }
9265 };
9366
9467 } // End sys namespace
1717 #include
1818 #include
1919 #include
20 #include
2021
2122 // Collection of symbol name/value pairs to be searched prior to any libraries.
2223 static std::map symbols;
4647
4748 static std::vector OpenedHandles;
4849
49 DynamicLibrary::DynamicLibrary() {}
50
51 DynamicLibrary::~DynamicLibrary() {
52 SmartScopedWriter Writer(&SymbolsLock);
53 while(!OpenedHandles.empty()) {
54 void *H = OpenedHandles.back();
55 OpenedHandles.pop_back();
56 dlclose(H);
57 }
58 }
5950
6051 bool DynamicLibrary::LoadLibraryPermanently(const char *Filename,
6152 std::string *ErrMsg) {