Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: gdb-patches@sources.redhat.com
Cc: Elena Zannoni <ezannoni@redhat.com>
Subject: [RFA/symtab] Handle weak functions as global
Date: Mon, 01 Nov 2004 17:30:00 -0000	[thread overview]
Message-ID: <20041101173014.GA20449@nevyn.them.org> (raw)

This patch is a one liner, but requires a bit of explanation.  If you have a
version of glibc available with debugging symbols (in both ld.so and
libc.so), you can see the problem like this:

  - Compile a program which calls open ().
  - Run to main.
  - Set a breakpoint on open.
  - Continue - the breakpoint will not be hit.

[Separate debug files will show the bug if you point GDB at the right
directory; on Debian this is /usr/lib/debug, not sure where it is on RH
systems.]

What happens, in my setup at least, is that gdb searches first the
executable, then libc.so.6, then ld.so for "open".  It either finds a
trampoline in the executable or nothing at all (depending on your version of
binutils).  Then, it finds open in libc.so.6, which has type mst_file_text. 
Then it finds open in ld.so, which also has a symbol named open, which also
has type mst_file_text.  We did not find any mst_text symbol, so we settle
for returning the most recent mst_file_text symbol - which is the wrong one.

There's two strange things here.  The first is that we return the second
file symbol instead of the first; it doesn't much matter, since we'll be
wrong half the time anyway.  The second is that the symbol in libc.so is
marked as mst_file_text.  This turned out to be because BSF_WEAK handling
was added to elfread for non-code symbols, but not for code symbols; and
open is a weak entry point to libc.so.6 for historical reasons.  If we treat
it as global, paralleling the non-code symbol handling, then GDB will
resolve breakpoints on "open" reliably to libc.so.6 (assuming no other
shared library defines it).  This gives the debugger much better chances of
finding the right symbol - any situation more complicated would require
setting breakpoints at all functions named "open", which is a To-Do-Later
issue.

Is this patch OK?

-- 
Daniel Jacobowitz

2004-11-01  Daniel Jacobowitz  <dan@debian.org>

	* elfread.c (elf_symtab_read): Treat weak functions as global.

Index: elfread.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/elfread.c,v
retrieving revision 1.47
diff -u -p -r1.47 elfread.c
--- elfread.c	23 Oct 2004 16:18:08 -0000	1.47
+++ elfread.c	1 Nov 2004 17:00:39 -0000
@@ -305,7 +305,7 @@ elf_symtab_read (struct objfile *objfile
 		}
 	      else if (sym->section->flags & SEC_CODE)
 		{
-		  if (sym->flags & BSF_GLOBAL)
+		  if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
 		    {
 		      ms_type = mst_text;
 		    }


             reply	other threads:[~2004-11-01 17:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-01 17:30 Daniel Jacobowitz [this message]
2004-11-29  2:12 ` Elena Zannoni
2004-11-30 21:37   ` Daniel Jacobowitz
2006-12-01 18:15 ` Daniel Jacobowitz

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=20041101173014.GA20449@nevyn.them.org \
    --to=drow@false.org \
    --cc=ezannoni@redhat.com \
    --cc=gdb-patches@sources.redhat.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