From owner-freebsd-hackers Fri Feb 12 08:29:53 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id IAA02387 for freebsd-hackers-outgoing; Fri, 12 Feb 1999 08:29:53 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from garbo.lodgenet.com (garbo.lodgenet.com [204.124.122.252]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA02379 for ; Fri, 12 Feb 1999 08:29:51 -0800 (PST) (envelope-from erich@lodgenet.com) Received: from jake.lodgenet.com (jake.lodgenet.com [10.0.122.30]) by garbo.lodgenet.com (8.9.3/8.9.3) with ESMTP id KAA08477; Fri, 12 Feb 1999 10:29:48 -0600 (CST) Received: from jake.lodgenet.com (localhost [127.0.0.1]) by jake.lodgenet.com (8.9.3/8.8.5) with ESMTP id KAA29685; Fri, 12 Feb 1999 10:28:33 -0600 (CST) Message-Id: <199902121628.KAA29685@jake.lodgenet.com> X-Mailer: exmh version 2.0.2 2/24/98 To: hackers@FreeBSD.ORG cc: erich@lodgenet.com Subject: dlopen and ELF v. a.out Mime-Version: 1.0 Content-Type: multipart/mixed ; boundary="==_Exmh_-7836634220" Date: Fri, 12 Feb 1999 10:28:33 -0600 From: "Eric L. Hernes" Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG This is a multipart MIME message. --==_Exmh_-7836634220 Content-Type: text/plain; charset=us-ascii I've been looking at x11amp, and I've run into a bit of a problem. The program is set up as a program and a few shared-library plug-ins. The shared libs all have some common symbol names in global scope, (obviously) to provide an interface between the program and the plugin. What happens, though is that the plug-ins aren't very well encapsulated, so there's big time global symbol polution. If the plug-ins were contained in one .c module, I could just declare the offending symbols as static, and all would be fine. But the plug-ins are often aggregates where some symbols need to be seen from different c-sources. So is there any way to get the linker to export only specific symbols, and hide the rest (and resolve them internally to the lib)? Attached is a test prog that illustrates the problem. There is two source files, a ldsoTest.c, that is the main program that dlopen()s three `plug-ins'. Each plugin is compiled from the same test.c source with different pre-processor defines to get a different message. If the programs are compiled a.out, it works as desired. But if I build with ELF, it's not right. Here's the output when I run it: (code attached below) (ttyp1@jake)$ env OBJFORMAT=aout make cc -O -pipe -g -shared -o test0.so -DTST_MESSAGE="\"This is test 0"\" test.c cc -O -pipe -g -shared -o test1.so -DTST_MESSAGE="\"This is test 1"\" test.c cc -O -pipe -g -shared -o test2.so -DTST_MESSAGE="\"This is test 2"\" test.c cc -O -pipe -g -o ldsoTest ldsoTest.c (ttyp1@jake)$ ./ldsoTest got fp at 0x200170f0 message: This is test 0 got fp at 0x200970f0 message: This is test 1 got fp at 0x200990f0 message: This is test 2 (ttyp1@jake)$ make clean rm -f test0.so test1.so test2.so ldsoTest (ttyp1@jake)$ env OBJFORMAT=elf make cc -O -pipe -g -shared -o test0.so -DTST_MESSAGE="\"This is test 0"\" test.c cc -O -pipe -g -shared -o test1.so -DTST_MESSAGE="\"This is test 1"\" test.c cc -O -pipe -g -shared -o test2.so -DTST_MESSAGE="\"This is test 2"\" test.c cc -O -pipe -g -o ldsoTest ldsoTest.c (ttyp1@jake)$ ./ldsoTest got fp at 0x280d2288 message: This is test 0 got fp at 0x280d4288 message: This is test 0 got fp at 0x280d6288 message: This is test 0 --==_Exmh_-7836634220 Content-Type: text/plain ; name="test.c"; charset=us-ascii Content-Description: test.c Content-Disposition: attachment; filename="test.c" #include char *msg = TST_MESSAGE; char * testFunction(void){ return msg; } --==_Exmh_-7836634220 Content-Type: text/plain ; name="ldsoTest.c"; charset=us-ascii Content-Description: ldsoTest.c Content-Disposition: attachment; filename="ldsoTest.c" #include #include #include typedef char *fcn(void); int main(int ac, char **av){ int i; char *pn; char *cwd=getwd(NULL); void *h; fcn *fp; char *m; for(i=0;i<3;i++) { asprintf(&pn, "%s/test%d.so", cwd, i); h = dlopen(pn, RTLD_NOW); if (h) { fp = dlsym(h, "testFunction"); if (fp){ fprintf(stderr, "got fp at %p\n", fp); m = fp(); fprintf(stderr, "message: %s\n", m); } } else { warn("%s: dlopen failed", pn); } free(pn); } return 0; } --==_Exmh_-7836634220 Content-Type: text/plain ; name="Makefile"; charset=us-ascii Content-Description: Makefile Content-Disposition: attachment; filename="Makefile" CFLAGS+=-g BINS=test0.so test1.so test2.so ldsoTest all: ${BINS} ldsoTest: ldsoTest.c ${CC} ${CFLAGS} -o $@ $< test0.so: test.c ${CC} ${CFLAGS} -shared -o $@ -DTST_MESSAGE="\"This is test 0"\" test.c test1.so: test.c ${CC} ${CFLAGS} -shared -o $@ -DTST_MESSAGE="\"This is test 1"\" test.c test2.so: test.c ${CC} ${CFLAGS} -shared -o $@ -DTST_MESSAGE="\"This is test 2"\" test.c clean: rm -f ${BINS} --==_Exmh_-7836634220 Content-Type: text/plain; charset=us-ascii Eric L. Hernes erich@lodgenet.com --==_Exmh_-7836634220-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message