libtool
[Top][All Lists]
Advanced

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

Inherited linker flags


From: Sam Varshavchik
Subject: Inherited linker flags
Date: Sat, 25 Sep 2010 23:57:43 -0400

I'm looking for a way to specify custom flags for the "inherited_linker_flags" setting in my .la. It seems like I need this to implement the semantics of gcc's weak references way I'd like them to work.

The scenario:

libx.la has a weak reference to symbol "Y".

liby.la declares the symbol "Y".

For a given binary P, it may be linked either with libx.la alone, or with both libx.la and liby.la.

The intended behavior is that in the former case libx sees the weak reference as null, in the latter case libx resolves this symbol from liby.

This works as expected when P links libx and liby as shared libraries. This breaks when P links libx and liby as static libraries. There are no strong references to Y, hence its object module does not get statically linked into P, and its reference remains unresolved.

It's a catch-22. To satisfy the weak reference, I need to have a strong reference to Y, or to any symbol in Y's module, from P. If I do that, I cannot link P with libx.la alone, the strong references fail to resolve and the link fails.

By doing some experimenting, I found that that everything appears to work nicely, if I put "-Wl,--undefined=Y" into liby.la's inherited_linker_flags setting. This apparently carries no impact when "sharedly" linking against liby.la. And when statically linking liby.la the undefined symbol forces the inclusion of Y's module into P, and resolving the weak reference from libx.

I could, of course, do the same thing by explicitly specifying the extra linker flag in Makefile.am in P's LDFLAGS. Having this flag in a .la file has the nice effect of libtool automatically handling this. It goes without saying that the whole thing works only on platforms where gcc and binutils have weak references.

Aside from manually hacking .la from a Makefile by hand, is there a documented way to put arbitrary stuff into "inherited_linker_flags"? I couldn't find anything promising in the info pages.

Attachment: pgpIdLy8BUIk9.pgp
Description: PGP signature


reply via email to

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