[Python-Dev] Python build trouble with the new gcc/binutils

Andrew Koenig ark@research.att.com
Fri, 16 Aug 2002 15:03:41 -0400 (EDT)

Guido> I'm sure the 'struct' module is implicated only because it happens to
Guido> be the first module that setup.py tries to build.

Guido> This points to a problem with the dynamic linker.

Yes, it does.  Indeed, if I look in Python/dynload_shlib.c, near
the end, I see code like this:

        if (Py_VerboseFlag)
                printf("dlopen(\"%s\", %x);\n", pathname, dlopenflags);

        handle = dlopen(pathname, dlopenflags);

        if (handle == NULL) {
                PyErr_SetString(PyExc_ImportError, dlerror());
                return NULL;
If I insert, immediately after the call to dlopen, the following:

        if (Py_VerboseFlag)
                printf("after dlopen(\"%s\", %x);\n", pathname, dlopenflags);

and then run "./python -v" and try to import struct, it does not print
the second set of output:

$ ./python -v
<lots of output>
[GCC 3.1.1] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
import readline # builtin
>>> import struct
dlopen("/export/spurr1/homes1/ark/test-python/Python-2.2.1/build/lib.solaris-2.7-sun4u-2.2/struct.so", 2);
Segmentation Fault - core dumped

This behavior strongly suggests to me that it is crashing in dlopen.

However, when I write a little C program that just calls dlopen with the
file in question:

#include <stdio.h>
void *dlopen(const char *, int);

        void *handle = dlopen("/export/spurr1/homes1/ark/test-python/Python-2.2.1/build/lib.solaris-2.7-sun4u-2.2/struct.so", 2);
        printf ("Handle = %x\n", handle);

it quietly succeds and prints "Handle = 0"

At this point I am way out of my depth.