Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Oct 1999 10:16:49 -0700 (PDT)
From:      John Polstra <jdp@polstra.com>
To:        patl@phoenix.volant.org
Cc:        current@freebsd.org
Subject:   Re: Weak symbols (Was: World breakage in libc_r?)
Message-ID:  <199910171716.KAA17170@vashon.polstra.com>
In-Reply-To: <ML-3.4.940026252.113.patl@asimov>
References:  <ML-3.4.940026252.113.patl@asimov>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <ML-3.4.940026252.113.patl@asimov>,
<patl@phoenix.volant.org> wrote:

> On 15-Oct-99 at 15:05, John Birrell (jb@cimlogic.com.au) wrote:
>
> > A weak symbol is like an alias for another (strong) symbol. The
> > linker will link to strong symbols first, then, for any unresolved
> > references, it will try to resolve against the weak symbols before
> > going on to the next library. Weak symbols are a good way to hide
> > things in order to stop polluting the name space. But they can
> > cause problems too.
>
> If so, then the definition has changed since they were first
> invented.  (Around 20 years ago, IIRC.)  Weak symbols were/are used
> to refer to external objects that may or may not actually be linked
> in.  The difference between a weak and a strong symbol is/was that
> a strong symbol would cause the appropriate library to be loaded
> to ensure that it would be defined (and generate errors if still
> unresolved at the end of the link) whereas a weak symbol would not
> cause a library module to be loaded and would not cause an error if
> left unresolved.

You are both right.  There are weak definitions (which jb described)
and there are weak references (which patl described).  Both are
unfortunately specified by the same assembler directive ".weak".
The distinction is made based on whether the symbol is defined in
the current module or not.

I have a couple of additions to the above.  A weak definition needn't
be an alias for another symbol, strictly speaking.  But that's
how they are normally used.  Regarding weak references, if such a
reference is still undefined at the end of a link, it is treated as if
it were defined with the value 0.

John
-- 
  John Polstra                                               jdp@polstra.com
  John D. Polstra & Co., Inc.                        Seattle, Washington USA
  "No matter how cynical I get, I just can't keep up."        -- Nora Ephron


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199910171716.KAA17170>