changeset 3696:b7087f928050

use of RTLD_DEEPBIND in dlopen() while loading plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 26 Feb 2020 11:16:35 +0100
parents 9107cca846b6
children 5331918773e7
files Core/SharedLibrary.cpp
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Core/SharedLibrary.cpp	Tue Feb 25 22:46:38 2020 +0100
+++ b/Core/SharedLibrary.cpp	Wed Feb 26 11:16:35 2020 +0100
@@ -62,7 +62,19 @@
     }
 
 #elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__)
-    handle_ = ::dlopen(path_.c_str(), RTLD_NOW);
+
+    /**
+     * "RTLD_LOCAL" is the default, and is only present to be
+     * explicit. "RTLD_DEEPBIND" was added in Orthanc 1.6.0, in order
+     * to avoid crashes while loading plugins from the LSB binaries of
+     * the Orthanc core.
+     **/
+#if defined(RTLD_DEEPBIND)  // This is a GNU extension
+    handle_ = ::dlopen(path_.c_str(), RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND);
+#else
+    handle_ = ::dlopen(path_.c_str(), RTLD_NOW | RTLD_LOCAL);
+#endif
+
     if (handle_ == NULL) 
     {
       std::string explanation;