Limit the symbol search in DynamicLibrary to the module that was opened.
authorZachary Turner <zturner@google.com>
Wed, 27 Aug 2014 17:06:22 +0000 (17:06 +0000)
committerZachary Turner <zturner@google.com>
Wed, 27 Aug 2014 17:06:22 +0000 (17:06 +0000)
Differential Revision: http://reviews.llvm.org/D5030

Reviewed By: Reid Kleckner, Rafael Espindola

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216563 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/DynamicLibrary.cpp

index d2b551e8a0a61bc85c8186d2d2e1e90af3a49752..40072636608de494c44273b823b196f9b5e0c3cc 100644 (file)
@@ -56,8 +56,15 @@ static DenseSet<void *> *OpenedHandles = nullptr;
 DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename,
                                                    std::string *errMsg) {
   SmartScopedLock<true> lock(*SymbolsMutex);
-
-  void *handle = dlopen(filename, RTLD_LAZY|RTLD_GLOBAL);
+  int flags = RTLD_LAZY | RTLD_GLOBAL;
+#if defined(__APPLE__)
+  // RTLD_FIRST is an apple specific flag which causes dlsym() to search only
+  // the module specified in |filename|, and not dependent modules.  This
+  // behavior would be desirable for other platforms as well, except that
+  // there's not a good way to implement it.
+  flags |= RTLD_FIRST;
+#endif
+  void *handle = dlopen(filename, flags);
   if (!handle) {
     if (errMsg) *errMsg = dlerror();
     return DynamicLibrary();