From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18587 invoked by alias); 20 Jun 2013 16:19:29 -0000 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 Received: (qmail 18558 invoked by uid 89); 20 Jun 2013 16:19:25 -0000 X-Spam-SWARE-Status: No, score=-4.6 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 20 Jun 2013 16:19:24 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1UphZy-0007Hx-8e from Maciej_Rozycki@mentor.com ; Thu, 20 Jun 2013 09:19:22 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 20 Jun 2013 09:19:22 -0700 Received: from [172.30.64.40] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.2.247.3; Thu, 20 Jun 2013 17:19:18 +0100 Date: Thu, 20 Jun 2013 16:20:00 -0000 From: "Maciej W. Rozycki" To: Tom Tromey CC: Richard Sandiford , Catherine Moore , , Subject: [PING^2][PATCH] in_plt_section: support alternate stub section names (was: [PATCH 1/2] MIPS: Compressed PLT/stubs support) In-Reply-To: <87wqu19y1x.fsf@fleche.redhat.com> Message-ID: References: <87wqu19y1x.fsf@fleche.redhat.com> User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-SW-Source: 2013-06/txt/msg00546.txt.bz2 Tom, I have now recalled that you made this comment about the original version of this change: On Thu, 21 Feb 2013, Tom Tromey wrote: > Maciej> -/* In SVR4, we recognize a trampoline by it's section name. > Maciej> - That is, if the pc is in a section named ".plt" then we are in > Maciej> - a trampoline. */ > Maciej> +/* In SVR4, we recognize a trampoline by it's section name. That is, > Maciej> + if the pc is in a section named ".plt" then we are in a trampoline. > Maciej> + We let targets request an alternative name, this is currently used > Maciej> + by the MIPS backend to handle the SVR4 lazy resolution stubs that > Maciej> + binutils put into ".MIPS.stubs" instead. */ > > IMO comments like this tend to get stale over time. > It is better, I think, to describe the function's interface and purpose, > and leave it to future developers to grep for uses of it, should they > need to know. I have now made the requested update, see below. Is this version OK to apply? 2013-06-20 Maciej W. Rozycki gdb/ * mips-linux-tdep.c (mips_linux_in_dynsym_stub): Handle .MIPS.stubs section like .plt. Remove unused `name' argument. Return 1 rather than the low 16-bit halfword of any instruction examined. (mips_linux_in_dynsym_resolve_code): Update accordingly. * mips-tdep.c (mips_stub_frame_sniffer): Call in_plt_section in place of an equivalent hand-coded sequence. * objfiles.c (in_plt_section): Reuse the `name' argument as an trampoline section name override. Maciej gdb-mips-in-stubs-section.diff Index: gdb-fsf-trunk-quilt/gdb/mips-linux-tdep.c =================================================================== --- gdb-fsf-trunk-quilt.orig/gdb/mips-linux-tdep.c 2013-06-19 16:54:49.000000000 +0100 +++ gdb-fsf-trunk-quilt/gdb/mips-linux-tdep.c 2013-06-19 16:55:00.280199593 +0100 @@ -30,6 +30,7 @@ #include "trad-frame.h" #include "tramp-frame.h" #include "gdbtypes.h" +#include "objfiles.h" #include "solib.h" #include "solib-svr4.h" #include "solist.h" @@ -666,25 +667,34 @@ mips_linux_core_read_description (struct /* Check the code at PC for a dynamic linker lazy resolution stub. - Because they aren't in the .plt section, we pattern-match on the - code generated by GNU ld. They look like this: + GNU ld for MIPS has put lazy resolution stubs into a ".MIPS.stubs" + section uniformly since version 2.15. If the pc is in that section, + then we are in such a stub. Before that ".stub" was used in 32-bit + ELF binaries, however we do not bother checking for that since we + have never had and that case should be extremely rare these days. + Instead we pattern-match on the code generated by GNU ld. They look + like this: lw t9,0x8010(gp) addu t7,ra jalr t9,ra addiu t8,zero,INDEX - (with the appropriate doubleword instructions for N64). Also - return the dynamic symbol index used in the last instruction. */ + (with the appropriate doubleword instructions for N64). As any lazy + resolution stubs in microMIPS binaries will always be in a + ".MIPS.stubs" section we only ever verify standard MIPS patterns. */ static int -mips_linux_in_dynsym_stub (CORE_ADDR pc, char *name) +mips_linux_in_dynsym_stub (CORE_ADDR pc) { gdb_byte buf[28], *p; ULONGEST insn, insn1; int n64 = (mips_abi (target_gdbarch ()) == MIPS_ABI_N64); enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ()); + if (in_plt_section (pc, ".MIPS.stubs")) + return 1; + read_memory (pc - 12, buf, 28); if (n64) @@ -742,7 +752,7 @@ mips_linux_in_dynsym_stub (CORE_ADDR pc, return 0; } - return (insn & 0xffff); + return 1; } /* Return non-zero iff PC belongs to the dynamic linker resolution @@ -756,9 +766,10 @@ mips_linux_in_dynsym_resolve_code (CORE_ if (svr4_in_dynsym_resolve_code (pc)) return 1; - /* Pattern match for the stub. It would be nice if there were a - more efficient way to avoid this check. */ - if (mips_linux_in_dynsym_stub (pc, NULL)) + /* Likewise for the stubs. They live in the .MIPS.stubs section these + days, so we check if the PC is within, than fall back to a pattern + match. */ + if (mips_linux_in_dynsym_stub (pc)) return 1; return 0; Index: gdb-fsf-trunk-quilt/gdb/mips-tdep.c =================================================================== --- gdb-fsf-trunk-quilt.orig/gdb/mips-tdep.c 2013-06-19 16:54:49.000000000 +0100 +++ gdb-fsf-trunk-quilt/gdb/mips-tdep.c 2013-06-19 16:55:00.280199593 +0100 @@ -3628,12 +3628,7 @@ mips_stub_frame_sniffer (const struct fr if (in_plt_section (pc, NULL)) return 1; - /* Binutils for MIPS puts lazy resolution stubs into .MIPS.stubs. */ - s = find_pc_section (pc); - - if (s != NULL - && strcmp (bfd_get_section_name (s->objfile->obfd, s->the_bfd_section), - ".MIPS.stubs") == 0) + if (in_plt_section (pc, ".MIPS.stubs")) return 1; /* Calling a PIC function from a non-PIC function passes through a Index: gdb-fsf-trunk-quilt/gdb/objfiles.c =================================================================== --- gdb-fsf-trunk-quilt.orig/gdb/objfiles.c 2013-06-19 16:45:58.000000000 +0100 +++ gdb-fsf-trunk-quilt/gdb/objfiles.c 2013-06-20 17:10:59.240259104 +0100 @@ -1410,9 +1410,9 @@ find_pc_section (CORE_ADDR pc) } -/* In SVR4, we recognize a trampoline by it's section name. - That is, if the pc is in a section named ".plt" then we are in - a trampoline. */ +/* Return non-zero if PC is in a dynamic function call trampoline. In + SVR4, we recognize a trampoline by its section name NAME, or ".plt" + if NAME is null. */ int in_plt_section (CORE_ADDR pc, char *name) @@ -1424,7 +1424,7 @@ in_plt_section (CORE_ADDR pc, char *name retval = (s != NULL && s->the_bfd_section->name != NULL - && strcmp (s->the_bfd_section->name, ".plt") == 0); + && strcmp (s->the_bfd_section->name, name ? name : ".plt") == 0); return (retval); }