public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: "H.J. Lu" <hjl@lucon.org>
Cc: binutils@sourceware.org, richard@codesourcery.com, rth@redhat.com
Subject: Re: Fix assertion failure on aliases of dynamic weak symbols
Date: Tue, 17 Jul 2007 05:39:00 -0000	[thread overview]
Message-ID: <m3lkdf645l.fsf@localhost.localdomain> (raw)
In-Reply-To: <20070716203505.GA15885@lucon.org>

"H.J. Lu" <hjl@lucon.org> writes:

> That piece of code was added by Richard on May 3, 1999 with
> comments:

Richard added the entire binutils world on May 3, 1999.  I actually
wrote that code originally, in the Cygnus repository.

>   /* Now set the weakdefs field correctly for all the weak defined
>      symbols we found.  The only way to do this is to search all the
>      symbols.  Since we only need the information for non functions in
>      dynamic objects, that's the only time we actually put anything on
>      the list WEAKS.  We need this information so that if a regular
>      object refers to a symbol defined weakly in a dynamic object, the
>      real symbol in the dynamic object is also put in the dynamic
>      symbols; we also must arrange for both symbols to point to the
>      same memory location.  We could handle the general case of symbol
>      aliasing, but a general symbol alias can only be generated in
>      assembler code, handling it correctly would be very time
>      consuming, and other ELF linkers don't handle general aliasing
>      either.  */
> 
> It no longer applies today since there is no difference between
> weak def and strong def in a shared library. Richard, do you
> remember if there is a testcase for your change? Can we remove
> the whole u.weakdef thing now? It will make linker simpler and
> faster.

The fact that there is no difference between weak defs and strong defs
is irrelevant here.  What is happening here is that the library
defines "environ" as a weak symbol.  "environ" is a weak alias for the
real symbol named "__environ".  The program refers to "environ".
Nothing outside the shared library refers to "__environ".  The shared
library refers only to "__environ", never to "environ" (other than
defining it as a weak alias).  If we only put "environ" in the dynamic
symbol table, then the dynamic linker will update the GOT entry for
"environ" so that all references to "environ" refer to the copy in the
main program.  If we don't put "__environ" in the dynamic symbol
table, then the GOT entry for "__environ" will continue to refer to
the copy in the dynamic object's data segment.  The effect is that the
dynamic object will set "__environ" at run time, and the program will
happily look at the uninitialized variable "environ".

Ian

  parent reply	other threads:[~2007-07-17  4:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-16 17:13 Richard Sandiford
2007-07-16 21:33 ` H.J. Lu
2007-07-17  1:12   ` PATCH: Remove u.weakdef from elf_link_hash_entry H.J. Lu
2007-07-17  5:39   ` Ian Lance Taylor [this message]
2007-07-17 13:55     ` Fix assertion failure on aliases of dynamic weak symbols H.J. Lu
2007-07-17 19:31       ` Ian Lance Taylor
2007-07-18 15:58         ` H.J. Lu
2007-07-18 18:23           ` Richard Sandiford
2007-07-18 21:06             ` H.J. Lu
2007-07-19 19:56               ` PATCH: Check symbol type for symbol alias H.J. Lu
2007-07-20 12:50                 ` Richard Sandiford
2007-07-20 13:07                   ` H.J. Lu
2007-07-20 15:03                     ` Richard Sandiford
2007-07-20 17:05                       ` H.J. Lu
2007-07-21  8:55                         ` Richard Sandiford
2007-07-23  5:35                           ` H.J. Lu
2007-07-23 10:05 ` Fix assertion failure on aliases of dynamic weak symbols Alan Modra
2007-07-23 11:43   ` Richard Sandiford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3lkdf645l.fsf@localhost.localdomain \
    --to=iant@google.com \
    --cc=binutils@sourceware.org \
    --cc=hjl@lucon.org \
    --cc=richard@codesourcery.com \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).