Alternative fix to make sure that the extern declarations used by

DynamicLibrary::SearchForAddressOfSymbol refer to declarations in the
global namespace.

llvm-svn: 92023
This commit is contained in:
Douglas Gregor 2009-12-23 19:12:50 +00:00
parent 44f2fe915f
commit 0f306eba2f

View File

@ -69,29 +69,7 @@ bool DynamicLibrary::LoadLibraryPermanently(const char *Filename,
return false;
}
void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
// First check symbols added via AddSymbol().
if (ExplicitSymbols) {
std::map<std::string, void *>::iterator I =
ExplicitSymbols->find(symbolName);
std::map<std::string, void *>::iterator E = ExplicitSymbols->end();
if (I != E)
return I->second;
}
// Now search the libraries.
if (OpenedHandles) {
for (std::vector<void *>::iterator I = OpenedHandles->begin(),
E = OpenedHandles->end(); I != E; ++I) {
//lt_ptr ptr = lt_dlsym(*I, symbolName);
void *ptr = dlsym(*I, symbolName);
if (ptr) {
return ptr;
}
}
}
static void *SearchForAddressOfSpecialSymbol(const char* symbolName) {
#define EXPLICIT_SYMBOL(SYM) \
extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM
@ -128,6 +106,34 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
#endif
#undef EXPLICIT_SYMBOL
return 0;
}
void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
// First check symbols added via AddSymbol().
if (ExplicitSymbols) {
std::map<std::string, void *>::iterator I =
ExplicitSymbols->find(symbolName);
std::map<std::string, void *>::iterator E = ExplicitSymbols->end();
if (I != E)
return I->second;
}
// Now search the libraries.
if (OpenedHandles) {
for (std::vector<void *>::iterator I = OpenedHandles->begin(),
E = OpenedHandles->end(); I != E; ++I) {
//lt_ptr ptr = lt_dlsym(*I, symbolName);
void *ptr = dlsym(*I, symbolName);
if (ptr) {
return ptr;
}
}
}
if (void *Result = SearchForAddressOfSpecialSymbol(symbolName))
return Result;
// This macro returns the address of a well-known, explicit symbol
#define EXPLICIT_SYMBOL(SYM) \