This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: weak references and --as-needed

On Wed, 21 Apr 2010 14:07:40 +0930
Alan Modra <> wrote:

> On Tue, Apr 20, 2010 at 02:02:44PM +0200, Pierre Ossman wrote:
> [snip]
> > End result is that you have programs depending on libgcc_s even though
> > they do not use exception handling, complicating the deployment to
> > non-glibc systems.
> [snip]
> Why is this a problem?  If libgcc_s is needed by your library then what
> difference does it make if libgcc_s is also marked as needed by the
> main executable?

Because the link-time libfoo isn't necessarily the same as the runtime
libfoo. In our case, where the build environment is constructed using
the GNU toolchain, this is generally the case as the target system will
often be built using the Solaris toolchain.

> > Now this is now well behaved for this scenario, but is there some other
> > scenario that will break because of this?
> Probably.  I'm loathe to change this without a really good reason.

I'd say getting an unnecessary dependency on a library that generally
is unavailable on the target systems is a really good reason.
Admittedly, this is really gcc's mess with adding more language runtime
libraries and referencing them when not needed, but changing their
architecture is a lot more difficult than making binutils do what gcc
really wants.

If keeping existing behaviour is important, then perhaps it would be
acceptable with a new flag that changes the behaviour? Something like

> > The documentation doesn't
> > mention how --as-needed and weak symbols interact, so it's currently
> > somewhat undefined.
> Worse than that, the ELF standard doesn't properly define the
> behaviour of weak symbols.

True. But from what I gather there is some form of de facto standard as
to how weak symbols should be treated. Given that, this is really more
about how binutils defines "needed" in its --as-needed flag. If it's
"required to make the result link successfully by the runtime linker"
then DSOs satisfying weak references are not "needed". But if it's
"required to satisfy each and every symbol, regardless of scope" then
weak references need to be considered.

AFAIK --as-needed is not in any standard, so you guys are free to pick
any definition you want.

It's difficult to form a picture of how people have using --as-needed
with regards to weak references. Trying to google it doesn't give
anything really useful.

Pierre Ossman            OpenSource-based Thin Client Technology
System Developer         Telephone: +46-13-21 46 00
Cendio AB                Web:

Attachment: signature.asc
Description: PGP signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]