b3b8f2e
fe21e7b
Add $APR_DEEPBIND to enable use of RTLD_DEEPBIND in apr_dso_open().
b3b8f2e
b3b8f2e
--- apr-1.7.0/dso/unix/dso.c.deepbind
b3b8f2e
+++ apr-1.7.0/dso/unix/dso.c
f5eb58b
@@ -38,6 +38,8 @@
f5eb58b
 #define DYLD_LIBRARY_HANDLE (void *)-1
f5eb58b
 #endif
b3b8f2e
 
f5eb58b
+static int use_deepbind; /* 0 = unset, 1 = use DEEPBIND, -1, don't use DEEPBIND */
f5eb58b
+
f5eb58b
 APR_DECLARE(apr_status_t) apr_os_dso_handle_put(apr_dso_handle_t **aprdso,
f5eb58b
                                                 apr_os_dso_handle_t osdso,
f5eb58b
                                                 apr_pool_t *pool)
f5eb58b
@@ -125,6 +127,12 @@
b3b8f2e
 #else
f5eb58b
     int flags = RTLD_NOW | RTLD_GLOBAL;
b3b8f2e
     void *os_handle;
f5eb58b
+
f5eb58b
+    if (use_deepbind == 0)
fe21e7b
+        use_deepbind = secure_getenv("APR_DEEPBIND") != NULL ? 1 : -1;
f5eb58b
+    if (use_deepbind == 1)
f5eb58b
+        flags |= RTLD_DEEPBIND;
f5eb58b
+
b3b8f2e
 #ifdef _AIX
b3b8f2e
     if (strchr(path + 1, '(') && path[strlen(path) - 1] == ')')
f5eb58b
     {
fe21e7b
--- apr-1.7.0/README.deepbind.deepbind
fe21e7b
+++ apr-1.7.0/README.deepbind
fe21e7b
@@ -0,0 +1,30 @@
fe21e7b
+This distribution of APR contains a modification of the behaviour of
fe21e7b
+the apr_dso_open() function which allows users enable the
fe21e7b
+"RTLD_DEEPBIND" flag when dlopen() is called.
fe21e7b
+
fe21e7b
+If the "APR_DEEPBIND" environment variable is set at runtime, the
fe21e7b
+RTLD_DEEPBIND flag is always added to the flags passed to dlopen().
fe21e7b
+
fe21e7b
+With normal use of dlopen(), dynamically loaded objects will use
fe21e7b
+global symbols in preference to any symbols defined within the object.
fe21e7b
+Using RTLD_DEEPBIND reverses this binding order.  See the dlopen(3)
fe21e7b
+man page for more information.
fe21e7b
+
fe21e7b
+This can be useful with Apache httpd, where two different modules are
fe21e7b
+loaded like:
fe21e7b
+
fe21e7b
+1. mod_foo.so uses library "libfoo.so"
fe21e7b
+   libfoo.so defines a function "SomeSym"
fe21e7b
+2. mod_bar.so uses library "libbar.so"
fe21e7b
+   libbar.so defines a different "SomeSym" function
fe21e7b
+
fe21e7b
+By default, mod_bar or mod_foo would use the "SomeSym" definition from
fe21e7b
+the "wrong" library depending on the load order.  If RTLD_DEEPBIND is
fe21e7b
+used, the "SomeSym" definition will always be mapped to the definition
fe21e7b
+from the corresponding dependent library.  This can avoid symbol
fe21e7b
+conflicts.
fe21e7b
+
fe21e7b
+There are some risks with using RTLD_DEEPBIND, in particular potential
fe21e7b
+issues with modules written in C++.  It is not recommended to enable
fe21e7b
+$APR_DEEPBIND unless it solves a specific problem and after thorough
fe21e7b
+testing of the configuration.