From owner-freebsd-hackers Sat Jan 22 9:36:39 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from wall.polstra.com (rtrwan160.accessone.com [206.213.115.74]) by hub.freebsd.org (Postfix) with ESMTP id C5DCC15011 for ; Sat, 22 Jan 2000 09:36:35 -0800 (PST) (envelope-from jdp@polstra.com) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.9.3/8.9.3) with ESMTP id JAA01040; Sat, 22 Jan 2000 09:36:34 -0800 (PST) (envelope-from jdp@polstra.com) From: John Polstra Received: (from jdp@localhost) by vashon.polstra.com (8.9.3/8.9.1) id JAA16497; Sat, 22 Jan 2000 09:36:34 -0800 (PST) (envelope-from jdp@polstra.com) Date: Sat, 22 Jan 2000 09:36:34 -0800 (PST) Message-Id: <200001221736.JAA16497@vashon.polstra.com> To: dot@dotat.at Subject: Re: LD_PRELOAD In-Reply-To: References: Organization: Polstra & Co., Seattle, WA Cc: hackers@freebsd.org Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In article , Tony Finch wrote: > John Polstra wrote: > >The right way to do it on FreeBSD is like this: > > gcc -fpic -c *.c > > gcc -shared -o libshim.so *.o > > That works fine, thanks! Any idea why my clumsy success worked and why > my clumsy failures didn't? Nah, I didn't pay that much attention to what you did. I just noticed that it wasn't right. :-) The "gcc -fpic" makes the object code position-independent. I am not sure, but probably you would also benefit (performance-wise) by using that on Solaris. The "gcc -shared" turns it into a shared library instead of a normal object file. In the process it also links in some extra little .o files which are necessary to hold it all together. You can use "gcc -v" to get the gory details. > >The names "_init" and "_fini" are "reserved for the implementation" > >in ANSI/ISO-speak. You shouldn't use them. > > I don't have any choice on Solaris, unfortunately (and my code has to > be portable between FreeBSD and Solaris). I suppose in that case > Solaris is the implementation and they have reserved it for my use. I > gather from the linker errors that FreeBSD has reserved the names for > a different use? The machinery that supports C++ constructors uses them. > >Or, write it in C++ and use a global constructor. > > No. Never. No way. NO. :-) I didn't mean write everything in C++ -- just the initialization hook. It's not that bad. There's an example in "src/lib/libc_r/uthread/uthread_autoinit.cc". The advantage of using C++ for this is that you're using a portable mechanism instead of a gcc extension. > >> I also note a user-interface incompatibility between FreeBSD's > >> implementation of LD_PRELOAD and Solaris's: on Solaris the filenames > >> listed in LD_PRELOAD are space-separated, but on FreeBSD they are > >> colon or semicolon separated. > > > >That could be a bug. You're probably the first person on earth to > >have more than one library in LD_PRELOAD. :-) What does Linux do? > > According to the documentation I looked at it uses arbitrary > whitespace as the separator. I haven't looked at the code to check. I took a look. They accept white space or colons. I'll change ours to be similarly tolerant. The semicolons are a vestige from SVR4.0, and should probably be ditched. John -- John Polstra jdp@polstra.com John D. Polstra & Co., Inc. Seattle, Washington USA "Disappointment is a good sign of basic intelligence." -- Chögyam Trungpa To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message