Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Jan 2000 09:36:34 -0800 (PST)
From:      John Polstra <jdp@polstra.com>
To:        dot@dotat.at
Cc:        hackers@freebsd.org
Subject:   Re: LD_PRELOAD
Message-ID:  <200001221736.JAA16497@vashon.polstra.com>
In-Reply-To: <E12BqX2-000Oju-00@fanf.eng.demon.net>
References:  <E12BjiC-00031J-00@fanf.noc.demon.net> <E12BjiC-00031J-00@fanf.noc.demon.net> <E12BqX2-000Oju-00@fanf.eng.demon.net>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <E12BqX2-000Oju-00@fanf.eng.demon.net>,
Tony Finch  <dot@dotat.at> wrote:
> John Polstra <jdp@polstra.com> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001221736.JAA16497>