[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inter-library linking

From: Joachim Worringen
Subject: Re: inter-library linking
Date: Fri, 12 Oct 2007 18:39:20 +0200
User-agent: Thunderbird (Windows/20070728)

Ralf Wildenhues wrote:
First a general question: why do you use (need to use?) LD_PRELOAD,
as oppposed to, say, just linking your programs against the libraries?
(I can imagine two prime use cases: dealing with programs one cannot
recompile like binary-only software, or symbol interpose "hacks" for
programs like valgrind or other malloc debug stuff.)

It's for socket-call interception. No way around it.

Another general remark: convenience libraries don't enter the picture
here much; think of them as a short-hand notation for a collection of
objects that will all be copied into the final library.

Yes, I understand. The interesting thing in this context is that I can link the convenience lib into my shared lib (as it has obviously been built as PIC), but the static version of a library to be installed (which thus exists as .a and .so) can *not* be linked into my shared lib as it has obviously not been compiled as PIC. What is the rationale behind not generating PIC for the static version of a library, while the shared one needs this anyway?

1) Explicit linkage of libshared against libfoo should cause the runtime
linker to pull it in:
   libshared_la_LIBADD =
   libfoo_la_SOURCES = ...

If that's what you already did, but it's producing errors anyway, then
please post a build log that contains the mode=link and mode=install
commands for both of these libraries plus all output they generate,
and the error output of the `LD_PRELOAD=...' command.

I did this - I will re-iterate and post the log.

2) Just list both to-be-preloaded libraries in LD_PRELOAD: ...

But actually you should be listing the inter-library dependencies in
*_LIBADD anyway, and your build order should be such that libfoo is
build before libshared.

No, this would be "too complicated".

In the meantime, I had already implemented a solution by adding the PIC flag to the CFLAGS when building "libfoo" (the flag is provided by configure), and then linked libfoo.a (not .la) explicitely to libshared.

This works, but I obverved that is also used then I preload libshared (which is expected); the same binary w/o preload does not link to libpthread. Thus, the DT_NEEDED mechanism you described does actually work (as could be expected...).

Well you can make libfoo a convenience archive.  But then its code will
end up completely in libshared; and it's not a good idea to install
convenience archives, which is why it's not done by Automake.  A good
rule of thumb is that code should live in at most one installed library,
everything else can cause ugly sooner or later.

That's my feeling as well. Also, libfoo is needed as a shared library as well, as it is used on its own.

Hope that helps.

It sure does, thanks.


Joachim Worringen, Software Architect, Dolphin Interconnect Solutions
phone ++49/(0)228/324 08 17 -

reply via email to

[Prev in Thread] Current Thread [Next in Thread]