[Zope-Perl] Loading perl modules from python

Gisle Aas gisle@ActiveState.com
23 May 2000 23:39:31 +0200


In order to get perl XS modules to load with the perl embedded in
python I had to apply the following patch to python dynamic library
loader.  (I currently only care about Linux support.)

--- Python/dynload_shlib.c.dist	Tue May 23 19:06:13 2000
+++ Python/dynload_shlib.c	Tue May 23 19:07:18 2000
@@ -103,12 +103,12 @@ dl_funcptr _PyImport_GetDynLoadFunc(cons
 #ifdef RTLD_NOW
 	/* RTLD_NOW: resolve externals now
 	   (i.e. core dump now if some are missing) */
-	handle = dlopen(pathname, RTLD_NOW);
+	handle = dlopen(pathname, RTLD_NOW | RTLD_GLOBAL);
 #else
 	if (Py_VerboseFlag)
 		printf("dlopen(\"%s\", %d);\n", pathname,
-		       RTLD_LAZY);
-	handle = dlopen(pathname, RTLD_LAZY);
+		       RTLD_LAZY | RTLD_GLOBAL);
+	handle = dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL);
 #endif /* RTLD_NOW */
 	if (handle == NULL) {
 		PyErr_SetString(PyExc_ImportError, dlerror());


The reason is that perl itself and various XS modules are loaded with
different calls to dlopen() and in order to make it possible to resolve
names between these I need to have the 'import perl' load the
'perl.so' under influence of the RTLD_GLOBAL flag.

   FYI: This is what 'man dlopen' has to say about this flag:

       External  references in the library are resolved using the
       libraries in that library's dependency list and any  other
       libraries previously opened with the RTLD_GLOBAL flag.  If
       the executable was linked with the flag "-rdynamic",  then
       the  global symbols in the executable will also be used to
       resolve references in a dynamically loaded library.

The bad thing with this approach is that we get the flag set for all
modules loaded by python, which probably imply that more name
conflicts occur.  It also seems like an unlikely patch to get adopted
for the official python.  Can anybody see a nice way to get selective
RTLD_GLOBAL for different 'imports' in python?  Or is there another
way to make this work?

Another option is to just link perl.a statically with python, but that
is not very nice either.

What is the state of this on systems that use different mechanisms for
dynamic loading?

--Gisle