From owner-freebsd-questions Mon Feb 12 18:36:13 2001 Delivered-To: freebsd-questions@freebsd.org Received: from tisch.mail.mindspring.net (tisch.mail.mindspring.net [207.69.200.157]) by hub.freebsd.org (Postfix) with ESMTP id 406C437B491 for ; Mon, 12 Feb 2001 18:36:04 -0800 (PST) Received: from hotdog (user-37kafod.dialup.mindspring.com [207.69.63.13]) by tisch.mail.mindspring.net (8.9.3/8.8.5) with SMTP id VAA10641 for ; Mon, 12 Feb 2001 21:36:02 -0500 (EST) Message-ID: <000901c09565$b54fdf40$2505a8c0@hotdog> From: "Greg Galloway" To: Subject: freebsd 2.x shared objects Date: Mon, 12 Feb 2001 21:35:57 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 <main.c #include #include 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 <shared.c extern void function(); void shared() { function(); } EOF cat <func.c #include 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