From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27902 invoked by alias); 6 Jan 2014 20:30:55 -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 27706 invoked by uid 89); 6 Jan 2014 20:30:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 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; Mon, 06 Jan 2014 20:30:54 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s06KUqpF016686 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 6 Jan 2014 15:30:52 -0500 Received: from barimba.redhat.com (ovpn-113-85.phx2.redhat.com [10.3.113.85]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s06KUp2c004766; Mon, 6 Jan 2014 15:30:52 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/3] relocate the entry point addess when used Date: Mon, 06 Jan 2014 20:30:00 -0000 Message-Id: <1389040247-2620-3-git-send-email-tromey@redhat.com> In-Reply-To: <1389040247-2620-1-git-send-email-tromey@redhat.com> References: <1389040247-2620-1-git-send-email-tromey@redhat.com> X-SW-Source: 2014-01/txt/msg00094.txt.bz2 This changes the entry point to be unrelocated in the objfile, and instead applies the relocation when it is used. I think the existing code here is wrong. It computes the entry point address directly from the BFD, not applying any runtime offsets. However, then objfile_relocate1 passes this address to find_pc_section -- which does use the offsets . So, it seems to me that the current code can only find the correct address by luck. 2014-01-06 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. --- gdb/ChangeLog | 10 ++++++++++ gdb/objfiles.c | 20 +++----------------- gdb/objfiles.h | 5 ++++- gdb/symfile.c | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 73847bd..2604ae4 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 4f0fea8..a0ff9db 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -895,6 +895,7 @@ 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; /* Make certain that the address points at real code, and not a @@ -908,6 +909,23 @@ init_entry_point_info (struct objfile *objfile) symbol table. */ objfile->ei.entry_point = gdbarch_addr_bits_remove (get_objfile_arch (objfile), entry_point); + + 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); + break; + } + } + + if (osect == NULL) + objfile->ei.the_bfd_section_index = SECT_OFF_TEXT (objfile); } } -- 1.8.1.4