From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11384 invoked by alias); 17 Jul 2007 13:11:41 -0000 Received: (qmail 11370 invoked by uid 22791); 17 Jul 2007 13:11:39 -0000 X-Spam-Check-By: sourceware.org Received: from alnrmhc14.comcast.net (HELO alnrmhc14.comcast.net) (206.18.177.54) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 17 Jul 2007 13:11:34 +0000 Received: from lucon.org ([24.6.230.138]) by comcast.net (alnrmhc14) with ESMTP id <20070717131132b1400ipk32e>; Tue, 17 Jul 2007 13:11:32 +0000 Received: by lucon.org (Postfix, from userid 500) id 5FEC7F824D; Tue, 17 Jul 2007 06:11:32 -0700 (PDT) Date: Tue, 17 Jul 2007 13:55:00 -0000 From: "H.J. Lu" To: Ian Lance Taylor Cc: binutils@sourceware.org, richard@codesourcery.com, rth@redhat.com Subject: Re: Fix assertion failure on aliases of dynamic weak symbols Message-ID: <20070717131132.GA17994@lucon.org> References: <87k5t0ff65.fsf@firetop.home> <20070716203505.GA15885@lucon.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.14 (2007-02-12) Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2007-07/txt/msg00305.txt.bz2 On Mon, Jul 16, 2007 at 09:32:54PM -0700, Ian Lance Taylor wrote: > "H.J. Lu" 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". It sounds familar. I looked at the binutils archive. Unfortunately, it starts around May 10, 1999 :-(. I will add a testcase for this. I think there is a small problem. We are making a typed weak def an alias of a linker-created strong def without type. I don't think we want to do it. Should we require symbols with aliass should be typed? H.J.