From owner-freebsd-hackers Sat Jan 22 19:27: 8 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from internal.mail.demon.net (internal.mail.demon.net [193.195.224.3]) by hub.freebsd.org (Postfix) with ESMTP id 5B49015041 for ; Sat, 22 Jan 2000 19:26:48 -0800 (PST) (envelope-from fanf@demon.net) Received: from fanf.eng.demon.net (fanf.eng.demon.net [195.11.55.89]) by internal.mail.demon.net with ESMTP id DAA12488; Sun, 23 Jan 2000 03:26:45 GMT Received: from fanf by fanf.eng.demon.net with local (Exim 3.12 #3) id 12CDfn-000KEt-00; Sun, 23 Jan 2000 03:26:43 +0000 To: jdp@polstra.com, freebsd-hackers@freebsd.org From: Tony Finch Cc: Tony Finch Subject: Re: LD_PRELOAD In-Reply-To: <200001221736.JAA16497@vashon.polstra.com> References: Message-Id: Date: Sun, 23 Jan 2000 03:26:43 +0000 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG John Polstra wrote: >Tony Finch wrote: >>John Polstra wrote: >>> >>> 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. :-) > >The advantage of using C++ for this is that you're using a portable >mechanism instead of a gcc extension. I'm not really worried about portability to different compilers. OS portability is important, though. I settled on using the following declaration. This works on Solaris, FreeBSD, and Linux. (This implies that the Solaris rtld documentation isn't quite complete regarding its support for C++ mechanisms.) static void startup(void) __attribute__ ((constructor)); >>> You're probably the first person on earth to >>> have more than one library in LD_PRELOAD. :-) I'm using an LD_PRELOAD hack to add functionality to a commercial application, and it has to co-exist with another vendor's commercial LD_PRELOAD hack for the same application. I've managed to get my test to work to my satisfaction on FreeBSD and Linux but it makes the Solaris 2.6 ld.so.1 crash which is a shame since Solaris is my principal OS for this project... The stuff I have done so far is available from http://www.inch.demon.co.uk/filemodshim.tar.gz Run `make test` for a bit of fun. Some Makefile frobbing may be required. Tony. -- I'm the dot in dot at To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message