From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22490 invoked by alias); 11 Aug 2010 20:31:19 -0000 Received: (qmail 22470 invoked by uid 22791); 11 Aug 2010 20:31:17 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Aug 2010 20:31:12 +0000 Received: (qmail 9085 invoked from network); 11 Aug 2010 20:31:10 -0000 Received: from unknown (HELO caradoc.them.org) (dan@127.0.0.2) by mail.codesourcery.com with ESMTPA; 11 Aug 2010 20:31:10 -0000 Date: Wed, 11 Aug 2010 20:31:00 -0000 From: Daniel Jacobowitz To: Chris January Cc: Hui Zhu , gdb@sourceware.org Subject: Re: [RFC] make gdb handle weak function better Message-ID: <20100811203057.GA25122@caradoc.them.org> Mail-Followup-To: Chris January , Hui Zhu , gdb@sourceware.org References: <1281513884.1935.7.camel@gumtree> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1281513884.1935.7.camel@gumtree> User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2010-08/txt/msg00067.txt.bz2 On Wed, Aug 11, 2010 at 09:04:44AM +0100, Chris January wrote: > I don't think this is right. My understanding is that the linker > (ld-linux) doesn't keep searching other shared libraries if it finds a > weak symbol. So the search order is as follows: > 1. 'strong' calloc in libc.so.6. > 2. 'weak' calloc in libc.so.6. > 3. 'strong' calloc in ld-linux.so.2. > 4. 'weak' calloc in ld-linux.so.2. There won't be both a strong and weak symbol in the same library; not from the point of view of ld.so. There may be in the static symbol table (.symtab) but only one will end up in .dynsym/.hash/.gnu_hash. But the important point is this one: > Notice that a 'weak' calloc in libc trumps any definition of calloc in > ld-linux. This is correct. > The problem with gdb is that it search the shared libraries in the order > they were loaded - notice info sharedlibrary gave you ld-linux first > instead of libc - so gdb incorrectly picks ld-linux's calloc. As a > general heuristic gdb should instead start looking for symbols in the > most recently loaded shared library (i.e. objfile) (after the main > executable) and work backwards. This doesn't necessarily match the > dynamic linker's behaviour exactly, but it gets pretty close for little > effort. That makes sense, although it may be system-specific. Even better would be to revisit our support for multiple-location breakpoints. "break calloc" ought to stop on every instance of calloc. -- Daniel Jacobowitz CodeSourcery