From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26901 invoked by alias); 3 May 2008 16:19:23 -0000 Received: (qmail 26876 invoked by uid 22791); 3 May 2008 16:19:21 -0000 X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 03 May 2008 16:19:02 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 66A1B983D9; Sat, 3 May 2008 16:19:00 +0000 (GMT) Received: from caradoc.them.org (22.svnf5.xdsl.nauticom.net [209.195.183.55]) by nan.false.org (Postfix) with ESMTP id AA6A798150; Sat, 3 May 2008 16:18:59 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.69) (envelope-from ) id 1JsKRu-0006ij-W1; Sat, 03 May 2008 12:18:58 -0400 Date: Sat, 03 May 2008 17:19:00 -0000 From: Daniel Jacobowitz To: Ulrich Weigand Cc: gdb-patches@sourceware.org, bauerman@br.ibm.com, amodra@bigpond.net.au Subject: Re: Shared library call problems on PowerPC with current binutils/gdb Message-ID: <20080503161858.GB22851@caradoc.them.org> Mail-Followup-To: Ulrich Weigand , gdb-patches@sourceware.org, bauerman@br.ibm.com, amodra@bigpond.net.au References: <20080503152457.GA20531@caradoc.them.org> <200805031538.m43Fce6B013612@d12av02.megacenter.de.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200805031538.m43Fce6B013612@d12av02.megacenter.de.ibm.com> User-Agent: Mutt/1.5.17 (2007-12-11) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-05/txt/msg00132.txt.bz2 On Sat, May 03, 2008 at 05:38:40PM +0200, Ulrich Weigand wrote: > I see. Hmmm, we could do the same for versioned symbols and just > install two minsyms. For disassembly, we'd see the decorated name, > but searching for just the base name would find the function as well ... There's a downside of this; it shows up twice in info functions, rbreak, et cetera. (gdb) rbreak malloc Breakpoint 3 at 0x97f8 malloc; Note: breakpoint 3 also set at pc 0x97f8. Breakpoint 4 at 0x97f8 malloc@plt; So it may be worth pursuing the two-names approach, or fixing up things that list symbols to omit multiple symbols at the same address. That latter could be useful anyway for glibc aliases. I'm not sure. > > > > Hmm, thinking about this more, it probably won't work for your > > > > case after all. lookup_solib_trampoline_symbol_by_pc will return > > > > NULL if the first symbol we find is the text version. > > > > > > If we have two symbols, *both* need to be mst_solib_trampoline. > > > > Would that be true if we could search for a symbol with the > > appropriate type? Prefer the trampoline when trying to find a > > trampoline target, prefer the text symbol with the decorated name > > otherwise. > > That's probably the best solution, right. Here's the patch I'm currently using. -- Daniel Jacobowitz CodeSourcery 2008-05-03 Daniel Jacobowitz * elfread.c (elf_symtab_read): Create trampolines for @plt symbols. * minsyms.c (lookup_minimal_symbol_by_pc_section_1): Renamed from lookup_minimal_symbol_by_pc_section. Prefer trampolines if requested. (lookup_minimal_symbol_by_pc_section): Use lookup_minimal_symbol_by_pc_section_1. (lookup_solib_trampoline_symbol_by_pc): Likewise. --- gdb/elfread.c (revision 1034) +++ gdb/elfread.c (local) @@ -521,6 +521,33 @@ elf_symtab_read (struct objfile *objfile if (msym != NULL) msym->filename = filesymname; gdbarch_elf_make_msymbol_special (gdbarch, sym, msym); + + /* For @plt symbols, also record a trampoline to the + destination symbol. The @plt symbol will be used in + disassembly, and the trampoline will be used when we are + trying to find the target. */ + if (msym && ms_type == mst_text && type == ST_SYNTHETIC) + { + int len = strlen (sym->name); + + if (len > 4 && strcmp (sym->name + len - 4, "@plt") == 0) + { + char *base_name = alloca (len - 4 + 1); + struct minimal_symbol *mtramp; + + memcpy (base_name, sym->name, len - 4); + base_name[len - 4] = '\0'; + mtramp = record_minimal_symbol (base_name, symaddr, + mst_solib_trampoline, + sym->section, objfile); + if (mtramp) + { + MSYMBOL_SIZE (mtramp) = MSYMBOL_SIZE (msym); + mtramp->filename = filesymname; + gdbarch_elf_make_msymbol_special (gdbarch, sym, mtramp); + } + } + } } } } --- gdb/minsyms.c (revision 1034) +++ gdb/minsyms.c (local) @@ -357,10 +357,15 @@ lookup_minimal_symbol_solib_trampoline ( ALL the minimal symbol tables before deciding on the symbol that comes closest to the specified PC. This is because objfiles can overlap, for example objfile A has .text at 0x100 and .data at - 0x40000 and objfile B has .text at 0x234 and .data at 0x40048. */ + 0x40000 and objfile B has .text at 0x234 and .data at 0x40048. -struct minimal_symbol * -lookup_minimal_symbol_by_pc_section (CORE_ADDR pc, asection *section) + If WANT_TRAMPOLINE is set, prefer mst_solib_trampoline symbols when + there are text and trampoline symbols at the same address. + Otherwise prefer mst_text symbols. */ + +static struct minimal_symbol * +lookup_minimal_symbol_by_pc_section_1 (CORE_ADDR pc, asection *section, + int want_trampoline) { int lo; int hi; @@ -369,7 +374,11 @@ lookup_minimal_symbol_by_pc_section (COR struct minimal_symbol *msymbol; struct minimal_symbol *best_symbol = NULL; struct obj_section *pc_section; + enum minimal_symbol_type want_type, other_type; + want_type = want_trampoline ? mst_solib_trampoline : mst_text; + other_type = want_trampoline ? mst_text : mst_solib_trampoline; + /* PC has to be in a known section. This ensures that anything beyond the end of the last segment doesn't appear to be part of the last function in the last segment. */ @@ -486,6 +495,24 @@ lookup_minimal_symbol_by_pc_section (COR continue; } + /* If we are looking for a trampoline and this is a + text symbol, or the other way around, check the + preceeding symbol too. If they are otherwise + identical prefer that one. */ + if (hi > 0 + && MSYMBOL_TYPE (&msymbol[hi]) == other_type + && MSYMBOL_TYPE (&msymbol[hi - 1]) == want_type + && (MSYMBOL_SIZE (&msymbol[hi]) + == MSYMBOL_SIZE (&msymbol[hi - 1])) + && (SYMBOL_VALUE_ADDRESS (&msymbol[hi]) + == SYMBOL_VALUE_ADDRESS (&msymbol[hi - 1])) + && (SYMBOL_BFD_SECTION (&msymbol[hi]) + == SYMBOL_BFD_SECTION (&msymbol[hi - 1]))) + { + hi--; + continue; + } + /* If the minimal symbol has a zero size, save it but keep scanning backwards looking for one with a non-zero size. A zero size may mean that the @@ -566,6 +593,12 @@ lookup_minimal_symbol_by_pc_section (COR return (best_symbol); } +struct minimal_symbol * +lookup_minimal_symbol_by_pc_section (CORE_ADDR pc, asection *section) +{ + return lookup_minimal_symbol_by_pc_section_1 (pc, section, 0); +} + /* Backward compatibility: search through the minimal symbol table for a matching PC (no section given) */ @@ -1019,7 +1052,13 @@ msymbols_sort (struct objfile *objfile) struct minimal_symbol * lookup_solib_trampoline_symbol_by_pc (CORE_ADDR pc) { - struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc); + struct obj_section *section = find_pc_section (pc); + struct minimal_symbol *msymbol; + + if (section == NULL) + return NULL; + msymbol = lookup_minimal_symbol_by_pc_section_1 (pc, section->the_bfd_section, + 1); if (msymbol != NULL && MSYMBOL_TYPE (msymbol) == mst_solib_trampoline) return msymbol;