From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26855 invoked by alias); 15 Jan 2014 17:59:40 -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 26844 invoked by uid 89); 15 Jan 2014 17:59:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Jan 2014 17:59:38 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0FHxbCd006556 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 15 Jan 2014 12:59:37 -0500 Received: from barimba (ovpn-113-85.phx2.redhat.com [10.3.113.85]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s0FHxZD3028654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 15 Jan 2014 12:59:36 -0500 From: Tom Tromey To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 2/3] relocate the entry point addess when used References: <1389040247-2620-1-git-send-email-tromey@redhat.com> <1389040247-2620-3-git-send-email-tromey@redhat.com> <52CD5129.7090003@redhat.com> <8738kr1ug8.fsf@fleche.redhat.com> <52D67425.9050904@redhat.com> Date: Wed, 15 Jan 2014 17:59:00 -0000 In-Reply-To: <52D67425.9050904@redhat.com> (Pedro Alves's message of "Wed, 15 Jan 2014 11:42:29 +0000") Message-ID: <87iotlqg6w.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2014-01/txt/msg00531.txt.bz2 >>>>> "Pedro" == Pedro Alves writes: Pedro> I think it's just that the entry point is only really used for the main Pedro> executable, and if that is loaded at some relocation offset, we'll Pedro> always go through objfile_relocate (either PIE handling, or RSP Pedro> qOffsets handling for embedded systems) after reading in symbols, Pedro> while shared libraries are read in with the offsets already handy Pedro> upfront. Yeah, that makes sense. Pedro> This is assuming osect ends up NULL after iterating over all. Pedro> It's violating the abstraction of the macro. And, actually, Pedro> it's wrong, showing exactly why such assumptions are a bad idea: Tom> Sorry about that, I'll fix it up locally. Pedro> Thanks. Here's the updated patch. Tom commit 9211b8474f76a95e993f4dc6e2ee873c6997caa4 Author: Tom Tromey Date: Tue Dec 31 06:52:33 2013 -0700 relocate the entry point address when used This changes the entry point to be unrelocated in the objfile, and instead applies the relocation when it is used. 2014-01-15 Tom Tromey * objfiles.c (entry_point_address_query): Relocate entry point address. (objfile_relocate1): Do not relocate entry point address. * objfiles.h (struct entry_info) : Update comment. : New field. * symfile.c (init_entry_point_info): Find the entry point's section. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 01a4087..5d48363 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2014-01-15 Tom Tromey + * objfiles.c (entry_point_address_query): Relocate entry point + address. + (objfile_relocate1): Do not relocate entry point address. + * objfiles.h (struct entry_info) : Update comment. + : New field. + * symfile.c (init_entry_point_info): Find the entry point's + section. + +2014-01-15 Tom Tromey + * solib-frv.c (enable_break): Use entry_point_address_query. 2014-01-15 Pedro Alves diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 9cc0054..a80d4c7 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -367,7 +367,9 @@ entry_point_address_query (CORE_ADDR *entry_p) if (symfile_objfile == NULL || !symfile_objfile->ei.entry_point_p) return 0; - *entry_p = symfile_objfile->ei.entry_point; + *entry_p = (symfile_objfile->ei.entry_point + + ANOFFSET (symfile_objfile->section_offsets, + symfile_objfile->ei.the_bfd_section_index)); return 1; } @@ -794,22 +796,6 @@ objfile_relocate1 (struct objfile *objfile, to be out of order. */ msymbols_sort (objfile); - if (objfile->ei.entry_point_p) - { - /* Relocate ei.entry_point with its section offset, use SECT_OFF_TEXT - only as a fallback. */ - struct obj_section *s; - s = find_pc_section (objfile->ei.entry_point); - if (s) - { - int idx = gdb_bfd_section_index (objfile->obfd, s->the_bfd_section); - - objfile->ei.entry_point += ANOFFSET (delta, idx); - } - else - objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile)); - } - { int i; diff --git a/gdb/objfiles.h b/gdb/objfiles.h index c2b6177..620d7e8 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -101,9 +101,12 @@ struct objfile_data; struct entry_info { - /* The relocated value we should use for this objfile entry point. */ + /* The unrelocated value we should use for this objfile entry point. */ CORE_ADDR entry_point; + /* The index of the section in which the entry point appears. */ + int the_bfd_section_index; + /* Set to 1 iff ENTRY_POINT contains a valid value. */ unsigned entry_point_p : 1; }; diff --git a/gdb/symfile.c b/gdb/symfile.c index d863282..bd12552 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -894,7 +894,9 @@ init_entry_point_info (struct objfile *objfile) if (objfile->ei.entry_point_p) { + struct obj_section *osect; CORE_ADDR entry_point = objfile->ei.entry_point; + int found; /* Make certain that the address points at real code, and not a function descriptor. */ @@ -907,6 +909,25 @@ init_entry_point_info (struct objfile *objfile) symbol table. */ objfile->ei.entry_point = gdbarch_addr_bits_remove (get_objfile_arch (objfile), entry_point); + + found = 0; + ALL_OBJFILE_OSECTIONS (objfile, osect) + { + struct bfd_section *sect = osect->the_bfd_section; + + if (entry_point >= bfd_get_section_vma (objfile->obfd, sect) + && entry_point < (bfd_get_section_vma (objfile->obfd, sect) + + bfd_get_section_size (sect))) + { + objfile->ei.the_bfd_section_index + = gdb_bfd_section_index (objfile->obfd, sect); + found = 1; + break; + } + } + + if (!found) + objfile->ei.the_bfd_section_index = SECT_OFF_TEXT (objfile); } }