Date: Tue, 13 Feb 2001 01:15:21 -0800 (PST) From: nikip@iname.com To: freebsd-gnats-submit@FreeBSD.org Subject: bin/25059: dlopen(..,RTLD_GLOBAL) doesn't work for shared libraries linked to the loaded one Message-ID: <200102130915.f1D9FLZ54623@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 25059 >Category: bin >Synopsis: dlopen(..,RTLD_GLOBAL) doesn't work for shared libraries linked to the loaded one >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Feb 13 01:20:00 PST 2001 >Closed-Date: >Last-Modified: >Originator: Nikolay Pelov >Release: FreeBSD 4.2-STABLE i386 >Organization: >Environment: FreeBSD guest1.lucky.net 4.2-STABLE FreeBSD 4.2-STABLE #0: Tue Dec 19 14:20:35 EET 2000 root@guest1.lucky.net:/usr/src/sys/compile/GUEST i386 >Description: If a shared library is loaded with dlopen(..., RTLD_GLOBAL) and it is linked at compile time to another *shared* library then the symbols of the second library are not exported. >How-To-Repeat: The test suite goes as follows. There is a shared library "dl1.so" which is linked to another shared library "st1.so". The second library exports a constant, say 'char *ok'. Then there is a third shared library, called "dl2.so" which is independent of the other two but uses the symbol defined in "st1.so". The main program dlopen()'s "dl1.so" and "dl2.so" and calls a function in "dl2.so" which uses the constant 'ok' and you get the error that it is not defined. You can download the test suite from http://www.cs.kuleuven.ac.be/~pelov/pam/download/dltest2.tar.gz To run it just type 'gmake test'. The test runs ok on both Linux and Solaris machines. A similar problem appeared in some of the early development versions of glibc2. ----------- begin Makefile ----------- CFLAGS = -g -Wall LDFLAGS = -export-dynamic -fpic all: main st1.so dl1.so dl2.so %.so: %.o $(LD) $(LDFLAGS) -o $@ -shared $< dl1.so: dl1.o st1.so $(LD) $(LDFLAGS) -o $@ -shared $^ clean: rm -f main *.so *.o test: all LD_LIBRARY_PATH=. && export LD_LIBRARY_PATH && ./main ----------- end Makefile --------------- ----------- begin main.c --------------- #include <stdio.h> #include <dlfcn.h> void * open_lib(const char *name) { void *lib = dlopen(name, RTLD_NOW | RTLD_GLOBAL); if (lib == NULL) { printf("dlopen error: %s\n", dlerror()); exit(1); } return lib; } int main() { void *dl1_lib = open_lib("dl1.so"); void *dl2_lib = open_lib("dl2.so"); void (*func)(void) = dlsym(dl2_lib, "test_dl2"); if (func == 0) { printf("dlsym error: %s\n", dlerror()); return 1; } func(); dlclose(dl1_lib); dlclose(dl2_lib); return 0; } ----------- end main.c --------------- ----------- begin dl1.c -------------- void test_dl1() { /* some dummy function */ } ----------- end dl1.c ---------------- ----------- begin st1.c -------------- char *ok = "\n The dlopen() function is OK\n"; ----------- end st1.c ---------------- ----------- begin dl2.c -------------- #include <stdio.h> extern char *ok; void test_dl2() { printf("%s\n", ok); } ----------- end dl2.c ---------------- ----------- begin output -------------- bash-2.03$ gmake test cc -g -Wall -export-dynamic -fpic main.c -o main cc -g -Wall -c -o st1.o st1.c ld -export-dynamic -fpic -o st1.so -shared st1.o cc -g -Wall -c -o dl1.o dl1.c ld -export-dynamic -fpic -o dl1.so -shared dl1.o st1.so cc -g -Wall -c -o dl2.o dl2.c ld -export-dynamic -fpic -o dl2.so -shared dl2.o LD_LIBRARY_PATH=. && export LD_LIBRARY_PATH && ./main dlopen error: ./dl2.so: Undefined symbol "ok" gmake: *** [test] Error 1 rm st1.o dl2.o >Fix: >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102130915.f1D9FLZ54623>