public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <ian@zembu.com>
To: geoffk@ozemail.com.au
Cc: rth@twiddle.net, hjl@lucon.org, drepper@cygnus.com,
	binutils@sourceware.cygnus.com, jgg@ualberta.ca
Subject: Re: A glibc dynamic linker or gld bug?
Date: Wed, 07 Jul 1999 20:28:00 -0000	[thread overview]
Message-ID: <19990708032728.28186.qmail@daffy.airs.com> (raw)
In-Reply-To: <199907080312.NAA00645@geoffk.wattle.id.au>

   Date: Thu, 8 Jul 1999 13:12:03 +1000
   From: Geoff Keating <geoffk@ozemail.com.au>

   >    These cases are not fixable under the usual non-pic-executable model, in
   >    which all addresses referenced by the executable are fixed at link
   >    time.
   > 
   > No, they are fixable.  We just need to generate the appropriate
   > dynamic relocations.  At present we do not do that, but there is
   > nothing preventing us from doing it.

   To be precise:

   These cases, if fixed by outputting all relevant relocations, would
   lead to incredibly inefficient program loading because it would be
   necessary to have run-time relocs for any weak symbol referenced by the
   executable.  It would also cost large amounts of memory because the
   text segment of executables would no longer be sharable between
   invocations.

Does the average executable really reference that many weak symbols?

   For instance, consider the following tiny bit of code, which we assume
   goes in an executable:

   extern int foo(void);
   int main(void) { if (foo) return foo(); else return 42; }

I can only follow your example if I assume that foo is weak undefined
in the executable, although that does not appear above.

   Now, suppose foo() goes away in a future version of the DSO.  Now we
   have a weak symbol which isn't defined anywhere, so it has address 0.

If foo is not weak undefined in the executable, then if it goes away
in the DSO, the dynamic linker will signal an error at run time.  It
doesn't matter that the foo is weak defined in the DSO.  If the
executable has a non-weak reference which can not be satisfied, the
program can not be run.

   This will happen a lot.  For instance, in current glibc 'open()' is
   weak.  open() is not likely to go away, but the linker doesn't know
   that.

The fact that open is weak defined in libc.so does not imply that it
is weak undefined in the executable.

I completely agree that to fix the various cases in your original note
we must issue dynamic relocations for all weak symbols, both defined
and undefined, in the executable.  However, we do not have to issue
relocations for symbols merely because they happen to be weak in a
shared object.

The average executable probably doesn't refer to any weak symbols in
user written code.  On the crt*.o files on my RedHat 5.2 system, the
weak symbol data_start is defined and the weak symbol __gmon_start__
is referenced.  The relocations for __gmon_start__ are GOT and PLT
relocs, and as such should not require any modification to the text
section at run time.

I do agree that making this work reliably would have a cost.  But I'm
not sure the cost would be as high as you suggest it would be.

Ian

  reply	other threads:[~1999-07-07 20:28 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-04 13:52 H.J. Lu
1999-07-05  2:38 ` Geoff Keating
1999-07-05  7:41   ` Jason Gunthorpe
1999-07-05 20:48   ` Richard Henderson
1999-07-06  1:01     ` Geoff Keating
1999-07-06 12:16       ` Geoff Keating
1999-07-06 19:11     ` Ian Lance Taylor
1999-07-06 19:28       ` Richard Henderson
1999-07-06 19:31         ` Ian Lance Taylor
1999-07-06 21:45       ` H.J. Lu
1999-07-07  7:36         ` Ian Lance Taylor
1999-07-07  7:39           ` H.J. Lu
1999-07-07  7:44             ` Ian Lance Taylor
1999-07-07  7:57               ` H.J. Lu
1999-07-07  8:03                 ` Ian Lance Taylor
1999-07-07 20:12               ` Geoff Keating
1999-07-07 20:16                 ` Ian Lance Taylor
1999-07-07  1:33       ` Geoff Keating
1999-07-07  7:35         ` Ian Lance Taylor
1999-07-07 11:22         ` Ian Lance Taylor
1999-07-07 20:13           ` Geoff Keating
1999-07-07 20:28             ` Ian Lance Taylor [this message]
1999-07-08 17:29               ` Geoff Keating
1999-07-09  6:11                 ` Franz Sirl
1999-07-10  3:14                   ` Geoff Keating
1999-07-10  5:40                     ` Ian Lance Taylor

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=19990708032728.28186.qmail@daffy.airs.com \
    --to=ian@zembu.com \
    --cc=binutils@sourceware.cygnus.com \
    --cc=drepper@cygnus.com \
    --cc=geoffk@ozemail.com.au \
    --cc=hjl@lucon.org \
    --cc=jgg@ualberta.ca \
    --cc=rth@twiddle.net \
    /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).