[uClibc]dynamic linking problems on PPC (uclibc 0.9.15/16)

Ronald Wahl rwa at peppercon.com
Mon Nov 11 16:26:36 UTC 2002


Hallo,

I noticed that iptables and apache are segfaulting when they access shared
libraries that are loaded with dlopen. I tracked it down to the
following:

If the shared module contains a structure with function pointers and I
call one of this function pointers I get a segmentation fault. Calling
the routine directly works. With glibc both cases are working. Here is
the example code:

--------------- main_prog.c -----------------------------

#include <stdio.h>
#include <dlfcn.h>

typedef struct {
        void (*indirect)(void);
} functable_t;

int main()
{
        void * handle;
        void (*direct)(void);
        functable_t * functable;
        char *error;

        if ((handle = dlopen("/tmp/module.so", RTLD_GLOBAL|RTLD_NOW)) == NULL)
 {
                fprintf (stderr, "%s\n", dlerror());
                exit(1);
        }

        direct = dlsym(handle, "direct");
        if ((error = dlerror()) != NULL)  {
                fprintf (stderr, "%s\n", error);
                exit(1);
        }
        fprintf(stderr, "calling direct()\n");
        (*direct)();

        functable = dlsym(handle, "functable"); 
        if ((error = dlerror()) != NULL)  {
                fprintf (stderr, "%s\n", error);
                 exit(1);
        }
        fprintf(stderr, "calling indirect()\n");
        (*functable->indirect)();
        dlclose(handle);
        return 0;
}

------------------------ module.c ------------------------

#include <stdio.h>

typedef struct {
        void (*indirect_p)(void);
} functable_t;

void direct()
{
        fprintf(stderr, "direct() called\n");
}

void indirect()
{
        fprintf(stderr, "indirect() called\n");
}

functable_t functable = {
        indirect
};

------------------------------------------------------------

$ ./main_prog
calling direct()
Segmentation fault
$

Could this be fixed, please?

thanks,
ron

-- 
\\      Dipl.-Inf. Ronald Wahl   |   Peppercon AG                  //
 \\\         rwa at peppercon.com  |||  http://www.peppercon.com/   /// 
  \OO  -----------------------  OOO  -------------------------  OO/ 
   OO  GnuPG/PGP key available  OOO  Keep Systems running       OO



More information about the uClibc mailing list