Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <dan@codesourcery.com>
To: Chris January <chris.january@allinea.com>
Cc: Hui Zhu <teawater@gmail.com>, gdb@sourceware.org
Subject: Re: [RFC] make gdb handle weak function better
Date: Wed, 11 Aug 2010 20:31:00 -0000	[thread overview]
Message-ID: <20100811203057.GA25122@caradoc.them.org> (raw)
In-Reply-To: <1281513884.1935.7.camel@gumtree>

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


  reply	other threads:[~2010-08-11 20:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-05  9:04 Hui Zhu
2010-08-11  3:21 ` Hui Zhu
2010-08-11  8:05   ` Chris January
2010-08-11 20:31     ` Daniel Jacobowitz [this message]
2010-08-12  3:17       ` Hui Zhu
2010-08-18  8:17       ` Chris January
2011-08-09  9:11         ` Hui Zhu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100811203057.GA25122@caradoc.them.org \
    --to=dan@codesourcery.com \
    --cc=chris.january@allinea.com \
    --cc=gdb@sourceware.org \
    --cc=teawater@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox