From owner-freebsd-current Sun Oct 17 10:17: 0 1999 Delivered-To: freebsd-current@freebsd.org Received: from wall.polstra.com (rtrwan160.accessone.com [206.213.115.74]) by hub.freebsd.org (Postfix) with ESMTP id 8039A14CA1 for ; Sun, 17 Oct 1999 10:16:56 -0700 (PDT) (envelope-from jdp@polstra.com) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.9.3/8.9.3) with ESMTP id KAA02163; Sun, 17 Oct 1999 10:16:50 -0700 (PDT) (envelope-from jdp@polstra.com) From: John Polstra Received: (from jdp@localhost) by vashon.polstra.com (8.9.3/8.9.1) id KAA17170; Sun, 17 Oct 1999 10:16:49 -0700 (PDT) (envelope-from jdp@polstra.com) Date: Sun, 17 Oct 1999 10:16:49 -0700 (PDT) Message-Id: <199910171716.KAA17170@vashon.polstra.com> To: patl@phoenix.volant.org Subject: Re: Weak symbols (Was: World breakage in libc_r?) In-Reply-To: References: Organization: Polstra & Co., Seattle, WA Cc: current@freebsd.org Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In article , 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