From owner-freebsd-hackers Fri Feb 12 16:31:47 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id QAA01456 for freebsd-hackers-outgoing; Fri, 12 Feb 1999 16:31:47 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from smtp01.primenet.com (smtp01.primenet.com [206.165.6.131]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA01439 for ; Fri, 12 Feb 1999 16:31:43 -0800 (PST) (envelope-from tlambert@usr01.primenet.com) Received: (from daemon@localhost) by smtp01.primenet.com (8.8.8/8.8.8) id RAA12666; Fri, 12 Feb 1999 17:31:36 -0700 (MST) Received: from usr01.primenet.com(206.165.6.201) via SMTP by smtp01.primenet.com, id smtpd012588; Fri Feb 12 17:31:31 1999 Received: (from tlambert@localhost) by usr01.primenet.com (8.8.5/8.8.5) id RAA29859; Fri, 12 Feb 1999 17:31:19 -0700 (MST) From: Terry Lambert Message-Id: <199902130031.RAA29859@usr01.primenet.com> Subject: Re: dlopen and ELF v. a.out To: erich@lodgenet.com (Eric L. Hernes) Date: Sat, 13 Feb 1999 00:31:18 +0000 (GMT) Cc: hackers@FreeBSD.ORG, erich@lodgenet.com In-Reply-To: <199902121628.KAA29685@jake.lodgenet.com> from "Eric L. Hernes" at Feb 12, 99 10:28:33 am X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > 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)? Use ld -r to make a single object per module. See also -x and -X, if you are willing to edit symbol names. You may also look at -s, in combination with either -defsym or --wrap, though I'm not sure about precedence. You could also modify your test program: > Attached is a test prog that illustrates the problem. There is two [ ... ] > 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); dlclose( h); > } This is probably not an option for you, I'm betting, if the code is that promiscuous. The resoloution order is not specific; a.out's dlopen (apparently) puts newer symbols first, so FreeBSD's behaviour in that case is not really incorrect. One final alternative would be to correct the namespace pollution, and submit the changes back. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message