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

Re: -Wl,--as-needed considered possibly harmful

On Fri, Dec 21, 2007 at 04:08:28AM +1100, Robert Collins wrote:
> > (BTW, pkg-config upstream wrongly claims that exporting dependent libs
> > in the pkg-config --libs output provides this protection. :/)

> It doesn't? (I must be missing something as I thought it did, just over
> aggressively).


Consider two libraries, libfoo and libbar.  libfoo depends on libbar,
references functions from it and uses some of libbar's types in its own
exported API.

We assume the Debian-style libbar-dev, which ensures that the libbar headers
match the version of libbar.so on the system.

The pkg-config technique guarantee that, when an application links against
libfoo, it is also linked against libbar.  Because of the preceding, this
guarantees that the application is linked against the version of libbar
whose ABI matches that of the headers used when building the application.

But *nothing* here guarantees that the version of libbar the application is
linked against has the same ABI as the one libfoo itself linked against!  If
libfoo linked against libbar1, the pkg-config approach only ensures that
when your application is built against the libbar2 version of libbar-dev,
the resulting binary will depend on both libbar1 and libbar2 (despite not
using any symbols from libbar2).  All this does is increase the chances of
segfaults or bad runtime behavior as a result of symbol clobbering.

So the usage recommended by pkg-config upstream does nothing at all to solve
the problem it's supposed to, and instead causes other linkage problems.

Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
slangasek@ubuntu.com                                     vorlon@debian.org

Reply to: