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