llvm.org GIT mirror llvm / 1a46635
Eliminate use of ltdl.c when doing a VC++ build. Because libtool isn't used, ltdl's LGPL license would infect all of LLVM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19137 91177308-0d34-0410-b5e6-96231b3b80d8 Jeff Cohen 14 years ago
6 changed file(s) with 161 addition(s) and 53 deletion(s). Raw diff Collapse all Expand all
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/System/DynamicLibrary.h"
14
15 // It is not possible to use ltdl.c on VC++ builds as the terms of its LGPL
16 // license and special exception would cause all of LLVM to be placed under
17 // the LGPL. This is because the exception applies only when libtool is
18 // used, and obviously libtool is not used with Visual Studio. An entirely
19 // separate implementation is provided in win32/DynamicLibrary.cpp.
20
21 #ifdef _WIN32
22
23 #include "win32/DynamicLibrary.cpp"
24
25 #else
26
1427 #include "ltdl.h"
1528 #include
1629 using namespace llvm;
134147 return lt_dlsym((lt_dlhandle) handle, symbolName);
135148 }
136149
150 #endif // _WIN32
11 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Jeff Cohen and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
66 //
77 //===----------------------------------------------------------------------===//
88 //
9 // This file provides the Win32 specific implementation of the DynamicLibrary
9 // This file provides the Win32 specific implementation of DynamicLibrary.
1010 //
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "Win32.h"
14 #include
15
16 #pragma comment(lib, "dbghelp.lib")
1417
1518 namespace llvm {
1619 using namespace sys;
1720
1821 //===----------------------------------------------------------------------===//
1922 //=== WARNING: Implementation here must contain only Win32 specific code
20 //=== and must not be UNIX code
23 //=== and must not be UNIX code.
2124 //===----------------------------------------------------------------------===//
2225
26 static std::vector OpenedHandles;
27
28 BOOL CALLBACK ELM_Callback(PSTR ModuleName,
29 ULONG ModuleBase,
30 ULONG ModuleSize,
31 PVOID UserContext)
32 {
33 OpenedHandles.push_back((HMODULE)ModuleBase);
34 return TRUE;
35 }
36
2337 DynamicLibrary::DynamicLibrary() : handle(0) {
24 handle = (void*) GetModuleHandle(NULL);
25
26 if (handle == 0) {
27 ThrowError("Can't GetModuleHandle: ");
38 handle = GetModuleHandle(NULL);
39 OpenedHandles.push_back((HMODULE)handle);
40 }
41
42 DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) {
43 HMODULE a_handle = LoadLibrary(filename);
44
45 if (a_handle == 0)
46 ThrowError(std::string(filename) + ": Can't open : ");
47
48 handle = a_handle;
49 OpenedHandles.push_back(a_handle);
50 }
51
52 DynamicLibrary::~DynamicLibrary() {
53 if (handle == 0)
54 return;
55
56 // GetModuleHandle() does not increment the ref count, so we must not free
57 // the handle to the executable.
58 if (handle != GetModuleHandle(NULL))
59 FreeLibrary((HMODULE)handle);
60 handle = 0;
61
62 for (std::vector::iterator I = OpenedHandles.begin(),
63 E = OpenedHandles.end(); I != E; ++I) {
64 if (*I == handle) {
65 // Note: don't use the swap/pop_back trick here. Order is important.
66 OpenedHandles.erase(I);
67 }
2868 }
2969 }
3070
31 DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) {
32 handle = LoadLibrary(filename);
71 void DynamicLibrary::LoadLibraryPermanently(const char* filename) {
72 if (filename) {
73 HMODULE a_handle = LoadLibrary(filename);
3374
34 if (handle == 0) {
35 ThrowError("Can't LoadLibrary: ");
75 if (a_handle == 0)
76 ThrowError(std::string(filename) + ": Can't open : ");
77
78 OpenedHandles.push_back(a_handle);
79 } else {
80 // When no file is specified, enumerate all DLLs and EXEs in the
81 // process.
82 EnumerateLoadedModules(GetCurrentProcess(), ELM_Callback, 0);
3683 }
84
85 // Because we don't remember the handles, we will never free them; hence,
86 // it is loaded permanently.
3787 }
3888
39 DynamicLibrary::~DynamicLibrary() {
40 assert(handle !=0 && "Invalid DynamicLibrary handle");
41 if (handle)
42 FreeLibrary((HMODULE*)handle);
89 void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
90 for (std::vector::iterator I = OpenedHandles.begin(),
91 E = OpenedHandles.end(); I != E; ++I) {
92 FARPROC ptr = GetProcAddress((HMODULE)*I, symbolName);
93 if (ptr)
94 return ptr;
95 }
96
97 return 0;
4398 }
4499
45100 void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) {
46 assert(handle !=0 && "Invalid DynamicLibrary handle");
47 return (void*) GetProcAddress((HMODULE*)handle, symbolName);
101 assert(handle != 0 && "Invalid DynamicLibrary handle");
102 return GetProcAddress((HMODULE)handle, symbolName);
48103 }
49104
50105 }
11 //
22 // The LLVM Compiler Infrastructure
33 //
4 // This file was developed by Reid Spencer and is distributed under the
4 // This file was developed by Jeff Cohen and is distributed under the
55 // University of Illinois Open Source License. See LICENSE.TXT for details.
66 //
77 //===----------------------------------------------------------------------===//
88 //
9 // This file provides the Win32 specific implementation of the DynamicLibrary
9 // This file provides the Win32 specific implementation of DynamicLibrary.
1010 //
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "Win32.h"
14 #include
15
16 #pragma comment(lib, "dbghelp.lib")
1417
1518 namespace llvm {
1619 using namespace sys;
1720
1821 //===----------------------------------------------------------------------===//
1922 //=== WARNING: Implementation here must contain only Win32 specific code
20 //=== and must not be UNIX code
23 //=== and must not be UNIX code.
2124 //===----------------------------------------------------------------------===//
2225
26 static std::vector OpenedHandles;
27
28 BOOL CALLBACK ELM_Callback(PSTR ModuleName,
29 ULONG ModuleBase,
30 ULONG ModuleSize,
31 PVOID UserContext)
32 {
33 OpenedHandles.push_back((HMODULE)ModuleBase);
34 return TRUE;
35 }
36
2337 DynamicLibrary::DynamicLibrary() : handle(0) {
24 handle = (void*) GetModuleHandle(NULL);
25
26 if (handle == 0) {
27 ThrowError("Can't GetModuleHandle: ");
38 handle = GetModuleHandle(NULL);
39 OpenedHandles.push_back((HMODULE)handle);
40 }
41
42 DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) {
43 HMODULE a_handle = LoadLibrary(filename);
44
45 if (a_handle == 0)
46 ThrowError(std::string(filename) + ": Can't open : ");
47
48 handle = a_handle;
49 OpenedHandles.push_back(a_handle);
50 }
51
52 DynamicLibrary::~DynamicLibrary() {
53 if (handle == 0)
54 return;
55
56 // GetModuleHandle() does not increment the ref count, so we must not free
57 // the handle to the executable.
58 if (handle != GetModuleHandle(NULL))
59 FreeLibrary((HMODULE)handle);
60 handle = 0;
61
62 for (std::vector::iterator I = OpenedHandles.begin(),
63 E = OpenedHandles.end(); I != E; ++I) {
64 if (*I == handle) {
65 // Note: don't use the swap/pop_back trick here. Order is important.
66 OpenedHandles.erase(I);
67 }
2868 }
2969 }
3070
31 DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) {
32 handle = LoadLibrary(filename);
71 void DynamicLibrary::LoadLibraryPermanently(const char* filename) {
72 if (filename) {
73 HMODULE a_handle = LoadLibrary(filename);
3374
34 if (handle == 0) {
35 ThrowError("Can't LoadLibrary: ");
75 if (a_handle == 0)
76 ThrowError(std::string(filename) + ": Can't open : ");
77
78 OpenedHandles.push_back(a_handle);
79 } else {
80 // When no file is specified, enumerate all DLLs and EXEs in the
81 // process.
82 EnumerateLoadedModules(GetCurrentProcess(), ELM_Callback, 0);
3683 }
84
85 // Because we don't remember the handles, we will never free them; hence,
86 // it is loaded permanently.
3787 }
3888
39 DynamicLibrary::~DynamicLibrary() {
40 assert(handle !=0 && "Invalid DynamicLibrary handle");
41 if (handle)
42 FreeLibrary((HMODULE*)handle);
89 void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
90 for (std::vector::iterator I = OpenedHandles.begin(),
91 E = OpenedHandles.end(); I != E; ++I) {
92 FARPROC ptr = GetProcAddress((HMODULE)*I, symbolName);
93 if (ptr)
94 return ptr;
95 }
96
97 return 0;
4398 }
4499
45100 void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) {
46 assert(handle !=0 && "Invalid DynamicLibrary handle");
47 return (void*) GetProcAddress((HMODULE*)handle, symbolName);
101 assert(handle != 0 && "Invalid DynamicLibrary handle");
102 return GetProcAddress((HMODULE)handle, symbolName);
48103 }
49104
50105 }
130130 RelativePath="..\..\lib\System\DynamicLibrary.cpp">
131131
132132
133 RelativePath="..\..\lib\System\ltdl.c">
134
135 Name="Debug|Win32">
136
137 Name="VCCLCompilerTool"
138 PreprocessorDefinitions="__WINDOWS__"/>
139
140
141 Name="Release|Win32">
142
143 Name="VCCLCompilerTool"
144 PreprocessorDefinitions="__WINDOWS__"/>
145
146
147
148133 RelativePath="..\..\lib\System\MappedFile.cpp">
149134
150135
177162 RelativePath="..\..\include\llvm\System\DynamicLibrary.h">
178163
179164
180 RelativePath="..\..\lib\System\ltdl.h">
181
182
183165 RelativePath="..\..\include\llvm\System\MappedFile.h">
184166
185167
3737 Name="VCLinkerTool"
3838 OutputFile="$(OutDir)/lli.exe"
3939 LinkIncremental="2"
40 ForceSymbolReferences="_X86TargetMachineModule"
4041 GenerateDebugInformation="TRUE"
4142 ProgramDatabaseFile="$(OutDir)/lli.pdb"
4243 SubSystem="1"
8788 Name="VCLinkerTool"
8889 OutputFile="$(OutDir)/lli.exe"
8990 LinkIncremental="1"
91 ForceSymbolReferences="_X86TargetMachineModule"
9092 GenerateDebugInformation="TRUE"
9193 SubSystem="1"
9294 OptimizeReferences="2"
7171 EndProject
7272 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lli", "lli\lli.vcproj", "{FB6FFD68-C1E4-4DCF-AB02-36D205D5263E}"
7373 ProjectSection(ProjectDependencies) = postProject
74 {0622E827-8464-489D-8B1C-B0B496F35C08} = {0622E827-8464-489D-8B1C-B0B496F35C08}
7475 {28AA9146-3482-4F41-9CC6-407B1D258508} = {28AA9146-3482-4F41-9CC6-407B1D258508}
7576 {F1EFF064-8869-4DFF-8E1A-CD8F4A5F8D61} = {F1EFF064-8869-4DFF-8E1A-CD8F4A5F8D61}
7677 {059FBAB8-C76D-48A0-AA75-3C57BD3EAFE4} = {059FBAB8-C76D-48A0-AA75-3C57BD3EAFE4}
9293 {059FBAB8-C76D-48A0-AA75-3C57BD3EAFE4} = {059FBAB8-C76D-48A0-AA75-3C57BD3EAFE4}
9394 {45CD78D7-C5D9-47FE-AD12-F3251EEDAFFB} = {45CD78D7-C5D9-47FE-AD12-F3251EEDAFFB}
9495 {0F8407F3-FA23-4CF1-83A9-DCBE0B361489} = {0F8407F3-FA23-4CF1-83A9-DCBE0B361489}
95 {144EEBF6-8C9B-4473-B715-2C821666AF6C} = {144EEBF6-8C9B-4473-B715-2C821666AF6C}
9696 EndProjectSection
9797 EndProject
9898 Global