From 0f306eba2f7982a3ab98434204099b3397f43340 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 23 Dec 2009 19:12:50 +0000 Subject: [PATCH] Alternative fix to make sure that the extern declarations used by DynamicLibrary::SearchForAddressOfSymbol refer to declarations in the global namespace. llvm-svn: 92023 --- lib/System/DynamicLibrary.cpp | 52 +++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/lib/System/DynamicLibrary.cpp b/lib/System/DynamicLibrary.cpp index 7eb9f5f3ef8..63baa6d787c 100644 --- a/lib/System/DynamicLibrary.cpp +++ b/lib/System/DynamicLibrary.cpp @@ -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::iterator I = - ExplicitSymbols->find(symbolName); - std::map::iterator E = ExplicitSymbols->end(); - - if (I != E) - return I->second; - } - - // Now search the libraries. - if (OpenedHandles) { - for (std::vector::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::iterator I = + ExplicitSymbols->find(symbolName); + std::map::iterator E = ExplicitSymbols->end(); + + if (I != E) + return I->second; + } + + // Now search the libraries. + if (OpenedHandles) { + for (std::vector::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) \