From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20476 invoked by alias); 11 Aug 2010 08:05:39 -0000 Received: (qmail 20368 invoked by uid 22791); 11 Aug 2010 08:05:36 -0000 X-SWARE-Spam-Status: No, hits=-0.9 required=5.0 tests=AWL,BAYES_50 X-Spam-Check-By: sourceware.org Received: from mail.streamline-computing.com (HELO mail.streamline-computing.com) (217.32.220.20) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Aug 2010 08:04:49 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.streamline-computing.com (Postfix) with ESMTP id 19C6CBB38; Wed, 11 Aug 2010 09:04:46 +0100 (BST) Received: from mail.streamline-computing.com ([127.0.0.1]) by localhost (mail.streamline-computing.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jvrsGW1LxwzL; Wed, 11 Aug 2010 09:04:45 +0100 (BST) Received: by mail.streamline-computing.com (Postfix, from userid 114) id 49280BB3F; Wed, 11 Aug 2010 09:04:45 +0100 (BST) Received: from [192.168.0.6] (cpc1-sotn6-0-0-cust372.sotn.cable.virginmedia.com [213.105.213.117]) (Authenticated sender: cjanuary) by mail.streamline-computing.com (Postfix) with ESMTP id 1FE32BB3D; Wed, 11 Aug 2010 09:04:45 +0100 (BST) Subject: Re: [RFC] make gdb handle weak function better From: Chris January To: Hui Zhu Cc: gdb@sourceware.org In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Date: Wed, 11 Aug 2010 08:05:00 -0000 Message-ID: <1281513884.1935.7.camel@gumtree> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Copyrighted-Material: X-IsSubscribed: yes 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/msg00060.txt.bz2 On Wed, 2010-08-11 at 11:21 +0800, Hui Zhu wrote: > > (gdb) info sharedlibrary > > From To Syms Read Shared Object Library > > 0xb7fe47f0 0xb7ff97df Yes (*) /lib/ld-linux.so.2 > > 0xb7e80230 0xb7f80ea4 Yes (*) /lib/tls/i686/cmov/libc.so.6 > > (*): Shared library is missing debugging information. > > > > Program exited with code 010. > > > > The inferior is not break because gdb set breakpoint in the weak > > function calloc in lib/ld-linux.so.2. > > But the inferior call the calloc in /lib/tls/i686/cmov/libc.so.6. > > > > And I check the lookup_symbol and lookup_minimal_symbol, both of them > > are return the first symbol that they found. > > What about do some work on it? > > > > What I think is: > > In lookup_symbol and lookup_minimal_symbol, when it get a weak symbol, > > just record it but keep search. When the search complete, if GDB get > > a simple symbol then return it. If GDB doesn't get a simple symbol. > > Then return the weak symbol. 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. Notice that a 'weak' calloc in libc trumps any definition of calloc in ld-linux. 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. Regards, Chris This e-mail message may contain confidential and/or privileged information. If you are not an addressee or otherwise authorized to receive this message, you should not use, copy, disclose or take any action based on this e-mail or any information contained in the message. If you have received this material in error, please advise the sender immediately by reply e-mail and delete this message. Thank you. Allinea Software Limited: Registered in England and Wales No: 6871298 Registered Address: The Innovation Centre, Warwick Technology Park, Gallows Hill, Warwick, CV34 6UW, United Kingdom