dlopen / dlsym issue ? / Reproducing the issue
jean-marie.verdun at splitted-desktop.org
jean-marie.verdun at splitted-desktop.org
Mon Apr 24 17:20:18 UTC 2006
Hi Joakim,
Here is a patch file you can probably incorporate into the test suite. I
build it on top of the 0.9.28 release, hope it will work with the svn,
just let me know !
To apply the patch go into test/dlopen, copy the attachement into the
directory and run patch -p1 < dlsym.patch
It should be ok, I hope so, I will really appreciate if you could test it.
Just let me know if you face some issues !
Jm
On Tue, 11 Apr 2006, Joakim Tjernlund wrote:
> > Hi,
>>
>> I have written a simple reproducer which make easily raise the bug.
>> just follow this into a chroot environment with 0.9.27 or 0.9.28
>
> Nice test case, this reminds me that I fixed a bug in current SVN that
> had to do with with "same name" DSO's in diffrent dirs. Can you try
> this with current SVN?
> You can see the fix in
> http://uclibc.org/cgi-bin/viewcvs.cgi?rev=11492&view=rev
>
> Would be great if you could submit a patch with this test case that
> maps into uClibc/test/dlopen
>
> Jocke
>
-------------- next part --------------
diff -Naur dlopen/main.c dlopen.new/main.c
--- dlopen/main.c 1969-12-31 17:00:00.000000000 -0700
+++ dlopen.new/main.c 2006-04-24 11:09:20.000000000 -0600
@@ -0,0 +1,65 @@
+/*
+ Copyright (C) 2006 Jean-Marie Verdun <jean-marie.verdun at splitted-desktop.org>
+
+ This program is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Library General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
+ details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this program; if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/* This test kit aims to track down a bug into the dlopen/dlsym function from
+the dl library, fixed into 0.9.28 release of uClibc... When one program was opening
+2 differents shared objects with the same name into 2 different directories,
+ calling the same functions name into both of them, through a dlsym resolution, symbol
+ name address returned was wrong and always first opened object address was returned ...
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+int main()
+{
+int ret = EXIT_SUCCESS;
+ void *handle;
+ void (*ptr)();
+ void (*ptr2)();
+ handle=dlopen("dlsym_test2/module.so", RTLD_LAZY);
+ printf("Handle %lx\n",handle);
+ if (handle)
+ {
+ ptr=dlsym(handle,"module_open");
+ }
+ else
+ ret=EXIT_FAILURE;
+ printf("Return function addr %lx\n",ptr);
+ if (ptr)
+ (*ptr)();
+ else
+ ret=EXIT_FAILURE;
+ handle=dlopen("dlsym_test1/module.so", RTLD_LAZY);
+ printf("Handle %lx\n",handle);
+ if (handle)
+ {
+ ptr2=dlsym(handle,"module_open");
+ }
+ else
+ ret=EXIT_FAILURE;
+ printf("Return function addr %lx\n",ptr2);
+ if ( ptr == ptr2 )
+ ret=EXIT_FAILURE;
+ if (ptr)
+ (*ptr2)();
+ else
+ ret=EXIT_FAILURE;
+
+ return(0);
+}
diff -Naur dlopen/Makefile dlopen.new/Makefile
--- dlopen/Makefile 2006-04-24 11:13:45.000000000 -0600
+++ dlopen.new/Makefile 2006-04-24 11:14:22.000000000 -0600
@@ -24,40 +24,51 @@
all: run
test1: test1.c
- $(CC) $(CFLAGS) $(LDFLAGS) -o test1 test1.c -ldl
+ $(CC) -o test1 test1.c -ldl ./libtest2.so
test2: test2.c
- $(CC) $(CFLAGS) $(LDFLAGS) -o test2 test2.c -ldl
+ $(CC) -o test2 test2.c -ldl ./libtest2.so
test3: test3.c
- $(CC) $(CFLAGS) $(LDFLAGS) -o test3 test3.c -ldl ./libtest1.so ./libtest2.so
+ $(CC) -o test3 test3.c -ldl ./libtest1.so ./libtest2.so
libtest1.o: libtest1.c
- $(CC) $(CFLAGS) $(LDFLAGS) -fPIC -c libtest1.c -o libtest1.o
+ $(CC) -fPIC -c libtest1.c -o libtest1.o
libtest2.o: libtest2.c
- $(CC) $(CFLAGS) $(LDFLAGS) -fPIC -c libtest2.c -o libtest2.o
+ $(CC) -fPIC -c libtest2.c -o libtest2.o
libtest1.so: libtest1.o
- $(CC) $(CFLAGS) -fPIC -shared -o libtest1.so -Wl,-soname,libtest1.so libtest1.o ./libtest2.so
+ $(CC) -shared -o libtest1.so libtest1.o
libtest2.so: libtest2.o
- $(CC) $(CFLAGS) -fPIC -shared -o libtest2.so -Wl,-soname,libtest2.so libtest2.o
+ $(CC) -shared -o libtest2.so libtest2.o
dltest: dltest.c
- $(CC) $(CFLAGS) $(LDFLAGS) -DLIBNAME="\"./libtest.so\"" dltest.c -ldl -lpthread -o dltest
+ $(CC) -DLIBNAME="\"./libtest.so\"" dltest.c -ldl -lpthread -o dltest
libtest.so: libtest.c
- $(CC) $(CFLAGS) -fPIC -shared -Wl,-soname,libtest.so libtest.c -o libtest.so
+ $(CC) -shared libtest.c -o libtest.so
# Second time, directly link libtest3.so with libpthread
dltest2: dltest.c
- $(CC) $(CFLAGS) $(LDFLAGS) -DLIBNAME="\"./libtest3.so\"" dltest.c -ldl -lpthread -o dltest2
+ $(CC) -DLIBNAME="\"./libtest3.so\"" dltest.c -ldl -lpthread -o dltest2
libtest3.so: libtest.c
- $(CC) $(CFLAGS) -fPIC -shared -Wl,-soname,libtest3.so libtest.c -o libtest3.so -lpthread
-
-run: libtest2.so libtest1.so test1 test2 test3 dltest libtest.so dltest2 libtest3.so
+ $(CC) -shared libtest.c -o libtest3.so -lpthread
+
+module1: module1.c
+ $(CC) -c module1.c
+ \mkdir dlsym_test1
+ $(CC) -o dlsym_test1/module.so -shared module1.o
+module2: module2.c
+ $(CC) -c module2.c
+ \mkdir dlsym_test2
+ $(CC) -o dlsym_test2/module.so -shared module2.o
+test: main.c
+ $(CC) -o test main.c -ldl
+
+run: libtest2.so libtest1.so test1 test2 test3 dltest libtest.so dltest2 libtest3.so module1 module2 test
@echo "----------running test 1--------------"
LD_LIBRARY_PATH=`pwd`:. $(DEBUG_LIBS)=all ./test1
@echo "----------running test 2--------------"
@@ -68,7 +79,9 @@
$(DEBUG_LIBS)=all ./dltest2
@echo "----------running test 4--------------"
$(DEBUG_LIBS)=all ./dltest
+ @echo "----------running test 5--------------"
+ $(DEBUG_LIBS)=all ./test
clean:
$(RM) *.o libtest1.so* libtest2.so* test1 test2 test3 \
- dltest dltest2 libtest.so libtest3.so
+ dltest dltest2 libtest.so libtest3.so test dlsym*/*
diff -Naur dlopen/module1.c dlopen.new/module1.c
--- dlopen/module1.c 1969-12-31 17:00:00.000000000 -0700
+++ dlopen.new/module1.c 2006-04-24 11:09:20.000000000 -0600
@@ -0,0 +1,22 @@
+/*
+ Copyright (C) 2006 Jean-Marie Verdun <jean-marie.verdun at splitted-desktop.org>
+
+ This program is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Library General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
+ details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this program; if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#include <stdio.h>
+void module_open()
+{
+ printf("Module Open call ok module 1\n");
+}
diff -Naur dlopen/module2.c dlopen.new/module2.c
--- dlopen/module2.c 1969-12-31 17:00:00.000000000 -0700
+++ dlopen.new/module2.c 2006-04-24 11:09:20.000000000 -0600
@@ -0,0 +1,23 @@
+/*
+ Copyright (C) 2006 Jean-Marie Verdun <jean-marie.verdun at splitted-desktop.org>
+
+ This program is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Library General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
+ details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this program; if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#include <stdio.h>
+
+void module_open()
+{
+ printf("Module Open call ok module 2\n");
+}
diff -Naur dlopen/test1.c dlopen.new/test1.c
--- dlopen/test1.c 2006-04-24 11:13:45.000000000 -0600
+++ dlopen.new/test1.c 2006-04-24 11:09:20.000000000 -0600
@@ -11,6 +11,8 @@
void *handle;
int (*mydltest)(const char *s);
char *error;
+ system("pwd");
+
handle = dlopen ("./libtest1.so", RTLD_LAZY);
if (!handle) {
More information about the uClibc
mailing list