[PATCH] loader: Use RTLD_DEEPBIND if available to prefer local symbols

Egbert Eich eich at freedesktop.org
Mon Aug 12 09:25:49 PDT 2013


If there are namespace clashes among different drivers it would be
preferrable if each driver used its local symbols. Use the
RTLD_DEEPBIND if available to achive this.

Signed-off-by: Egbert Eich <eich at freedesktop.org>
---
 configure.ac               |  2 ++
 hw/xfree86/loader/loader.c | 13 ++++++++++---
 include/xorg-config.h.in   |  3 +++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index c6ecba4..8abd66b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1139,6 +1139,8 @@ if test "x$DRI2" = xyes; then
 fi
 AM_CONDITIONAL(DRI2_AIGLX, test "x$DRI2_AIGLX" = xyes)
 
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <dlfcn.h>]], [[dlopen("foo", RTLD_DEEPBIND);]])],
+	[AC_DEFINE([DLOPEN_HAVE_DEEPBIND], [1], [Define if dlopen() has RTLD_DEEPBIND])])
 
 AM_CONDITIONAL(XINERAMA, [test "x$XINERAMA" = xyes])
 if test "x$XINERAMA" = xyes; then
diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index 64c69bb..f7bae3c 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -128,8 +128,12 @@ LoaderOpen(const char *module, int *errmaj, int *errmin)
 #endif
 
     xf86Msg(X_INFO, "Loading %s\n", module);
-
-    if (!(ret = dlopen(module, DLOPEN_LAZY | DLOPEN_GLOBAL))) {
+#if defined(DLOPEN_HAVE_DEEPBIND)
+    if (!(ret = dlopen(module, DLOPEN_LAZY | DLOPEN_GLOBAL | RTLD_DEEPBIND)))
+#else
+    if (!(ret = dlopen(module, DLOPEN_LAZY | DLOPEN_GLOBAL)))
+#endif
+    {
         xf86Msg(X_ERROR, "Failed to load %s: %s\n", module, dlerror());
         if (errmaj)
             *errmaj = LDR_NOLOAD;
@@ -152,8 +156,11 @@ LoaderSymbol(const char *name)
         return p;
 
     if (!global_scope)
+#if defined(DLOPEN_HAVE_DEEPBIND)
+        global_scope = dlopen(NULL, DLOPEN_LAZY | DLOPEN_GLOBAL | RTLD_DEEPBIND);
+#else
         global_scope = dlopen(NULL, DLOPEN_LAZY | DLOPEN_GLOBAL);
-
+#endif
     if (global_scope)
         return dlsym(global_scope, name);
 
diff --git a/include/xorg-config.h.in b/include/xorg-config.h.in
index a71b25d..dc2a57d 100644
--- a/include/xorg-config.h.in
+++ b/include/xorg-config.h.in
@@ -139,4 +139,7 @@
 /* Have X server platform bus support */
 #undef XSERVER_PLATFORM_BUS
 
+/* Define if dlopen() has RTLD_DEEPBIND */
+#undef DLOPEN_HAVE_DEEPBIND
+
 #endif /* _XORG_CONFIG_H_ */
-- 
1.8.1.4



More information about the xorg-devel mailing list