Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Jan 2000 03:26:43 +0000
From:      Tony Finch <dot@dotat.at>
To:        jdp@polstra.com, freebsd-hackers@freebsd.org
Cc:        Tony Finch <dot@dotat.at>
Subject:   Re: LD_PRELOAD
Message-ID:  <E12CDfn-000KEt-00@fanf.eng.demon.net>
In-Reply-To: <200001221736.JAA16497@vashon.polstra.com>
References:  <E12BjiC-00031J-00@fanf.noc.demon.net> <E12BjiC-00031J-00@fanf.noc.demon.net> <E12BqX2-000Oju-00@fanf.eng.demon.net> <E12BqX2-000Oju-00@fanf.eng.demon.net>

next in thread | previous in thread | raw e-mail | index | archive | help
John Polstra <jdp@polstra.com> wrote:
>Tony Finch  <dot@dotat.at> wrote:
>>John Polstra <jdp@polstra.com> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E12CDfn-000KEt-00>