A serious dlopen() problem found in qrtp. At least, it is serious for me
because it is a show stopper for my product.
dlopen() can’t distinguish 2 shared libraries with the same file name
by located in different directory.
dll1.c is the source for the first shared library.
dll2.c is the source for the 2nd shared library.
main.c is the calling program that demostrates the shared libraries
created from dll1.c and dll2.c does work if they have different file
name.
main2.c is the calling program that demostrates the problem.
$ cat dll1.c
char *s = “this is dll1”;
$ cat dll2.c
char *s = “this is dll2”;
char *t = “this is dll2”;
$ cat main.c
#include <stdio.h>
#include <dlfcn.h>
int main ()
{
void* p;
void* pp;
char** str;
p = dlopen ("./dll1.so", RTLD_NOW | RTLD_LOCAL);
if (p == 0) { printf (“failed to open dll1\n”); return (1); }
str = dlsym (p, “s”);
printf (“s=’%s’\n”, *str);
/* I mean not to dlclose it because my product requires both
- to be opened
dlclose (p);
*/
pp = dlopen ("./dll2.so", RTLD_NOW | RTLD_LOCAL);
if (pp == 0) { printf (“failed to open dll2\n”); return (1); }
str = dlsym (pp, “s”);
printf (“s=’%s’\n”, *str);
str = dlsym (pp, “t”);
printf (“t=’%s’\n”, *str);
dlclose (pp);
return (0);
}
$ cat main2.c
#include <stdio.h>
#include <dlfcn.h>
int main ()
{
void* p;
void* pp;
char** str;
p = dlopen ("./dll1/dll.so", RTLD_NOW | RTLD_LOCAL);
if (p == 0) { printf (“failed to open dll1\n”); return (1); }
str = dlsym (p, “s”);
printf (“s=’%s’\n”, *str);
/* I mean not to dlclose it because my product requires both
- to be opened
dlclose (p);
*/
pp = dlopen ("./dll2/dll.so", RTLD_NOW | RTLD_LOCAL);
if (pp == 0) { printf (“failed to open dll2\n”); return (1); }
str = dlsym (pp, “s”);
printf (“s=’%s’\n”, *str);
str = dlsym (pp, “t”);
printf (“t=’%s’\n”, *str);
dlclose (pp);
return (0);
}
$ cc -shared -o dll1.so dll1.c
$ cc -shared -o dll2.so dll2.c
$ cc -o main main.c
$ cc -o main2 main2.c
$ rm -fr dll1 dll2
$ mkdir dll1
$ mkdir dll2
$ cp dll1.so dll1/dll.so
$ cp dll2.so dll2/dll.so
$ ./main
s=‘this is dll1’
s=‘this is dll2’
t=‘this is dll2’
$ ./main2
s=‘this is dll1’
s=‘this is dll1’ <----- wrong
Memory fault (core dumped) <----- can’t find t
Any suggustion?
\
Gordon Man
Empress Software Inc.