From owner-freebsd-current@FreeBSD.ORG Sat Feb 14 17:48:27 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 53A5F16A4CE for ; Sat, 14 Feb 2004 17:48:27 -0800 (PST) Received: from mta4.rcsntx.swbell.net (mta4.rcsntx.swbell.net [151.164.30.28]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2D76143D1F for ; Sat, 14 Feb 2004 17:48:27 -0800 (PST) (envelope-from mbsd@pacbell.net) Received: from sotec.home (adsl-64-168-24-48.dsl.snfc21.pacbell.net [64.168.24.48])i1F1mPa4008729; Sat, 14 Feb 2004 19:48:26 -0600 (CST) Date: Sat, 14 Feb 2004 17:48:25 -0800 (PST) From: =?ISO-8859-1?Q?Mikko_Ty=F6l=E4j=E4rvi?= X-X-Sender: mikko@sotec.home To: Kimura Fuyuki In-Reply-To: <86n07oa7sa.wl%fuyuki@nigredo.org> Message-ID: <20040214172047.K96655@sotec.home> References: <86n07oa7sa.wl%fuyuki@nigredo.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-current@freebsd.org Subject: Re: relocator oddity? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Feb 2004 01:48:27 -0000 On Thu, 12 Feb 2004, Kimura Fuyuki wrote: > Someone please run the test below and tell me why dltest[12] show the > different results on my 5.2.1-RC2 box. At least NetBSD 1.5.2 and some > sort of Linux pass the test. > > #!/bin/sh > > cat <<[EOF] >shared.c > double sin(double d) {return 9;} > double faked_sin(double d) {return sin(d);} > [EOF] > > cat <<[EOF] >dltest.c > #include > #include > > int main(void) > { > void *h; > double (*faked_sin)(double); > > h = dlopen("./shared.so", RTLD_LAZY); > faked_sin = dlsym(h, "faked_sin"); > printf("%f\n", faked_sin(0)); > } > [EOF] > > cc -shared -o shared.so shared.c # Try this: cc -shared -o shared.so shared.c -Wl,-Bsymbolic > cc dltest.c -o dltest1 > ./dltest1 >result1 > > cc dltest.c -o dltest2 -lm > ./dltest2 >result2 > > if diff result1 result2 >/dev/null; then > echo "You are very talented." > else > echo "Please tell me what's happening!" > fi Use the line I changed above and try again. If you want to ensure that global symbol refereces inside a shared object are bound to symbols inside the object itself, you'll have to tell the linker to do so, otherwise it will resolve the symbols at run time, possibly from somewhere else. Another way is to make your internal "sin()" implementation static. This is how one can do lots of funny things with LD_PRELOAD :) I see the same result on Solaris 9 (w/ gcc 3.3) as on FreeBSD. I don't know if there is a complete specification for the dynamic linker search order somewhere, or if it is "implentation defined". I do know that there are subtle differences between systems, though. $.02, /Mikko