Date: Mon, 12 Feb 2001 21:35:57 -0500 From: "Greg Galloway" <greggalloway@mindspring.com> To: <freebsd-questions@freebsd.org> Subject: freebsd 2.x shared objects Message-ID: <000901c09565$b54fdf40$2505a8c0@hotdog>
next in thread | raw e-mail | index | archive | help
I am trying to port an application from Solaris 2.6 to an embedded system which is based on FreeBSD 2.x. The application supports dynamic updates in the form of .so files which are loaded via dlopen. The updates will contain functions which have the same name as functions in the main program.Under FreeBSD 2.x dlopen seems to re-resolve these symbols to point to their counterparts int the main app. I've included a script which demonstrates the problem. Under Solaris and FreeBSD 3.x and newer systems, this script produces: inside function() in main program inside function() in shared object Under FreeBSD 2.x and SunOS 4.x, it produces: inside function() in main program inside function() in main program Is this a limitation of a.out systems, or is there a workaround? Unfortunately we cannot upgrade to a newer FreeBSD version at this time. Thanks, Greg ----------------------------------------------------------- #!/bin/sh cat <<EOF >main.c #include <stdio.h> #include <dlfcn.h> void function() { printf("inside function() in main program\n"); } int main() { void *handle; void (*pshared)(); function(); handle = dlopen("./libshared.so", RTLD_LAZY); if (!handle) exit(1); dlerror(); /* Clear error */ #ifdef __FreeBSD__ pshared = (void(*)())dlsym(handle, "_shared"); #else pshared = (void(*)())dlsym(handle, "shared"); #endif if (dlerror()) exit(2); (*pshared)(); dlclose(handle); return 0; } EOF cat <<EOF >shared.c extern void function(); void shared() { function(); } EOF cat <<EOF >func.c #include <stdio.h> void function() { printf("inside function() in shared object\n"); } EOF set -x rm -f *.o *.so main case `uname -s`-`uname -r` in FreeBSD-2*) gcc -o main main.c gcc -fPIC -c shared.c gcc -fPIC -c func.c ld -Bshareable -o libshared.so shared.o func.o /usr/lib/c++rt0.o ;; SunOS-4*) cc -o main main.c cc -PIC -c shared.c cc -PIC -c func.c ld -assert pure-text -o libshared.so shared.o func.o ;; SunOS-5*) gcc -o main main.c gcc -fPIC -c shared.c gcc -fPIC -c func.c ld -shared -o libshared.so shared.o func.o ;; esac ./main To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000901c09565$b54fdf40$2505a8c0>