From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6078 invoked by alias); 14 Dec 2012 15:14:07 -0000 Received: (qmail 6050 invoked by uid 22791); 14 Dec 2012 15:14:05 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_HOSTKARMA_NO,TW_BJ,TW_FN,TW_YM X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 14 Dec 2012 15:13:54 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id F39932E3BF; Fri, 14 Dec 2012 10:13:53 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 6JF9yT-5LTaA; Fri, 14 Dec 2012 10:13:53 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 69BC92E09B; Fri, 14 Dec 2012 10:13:53 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 298B0C14D6; Fri, 14 Dec 2012 19:13:44 +0400 (RET) Date: Fri, 14 Dec 2012 15:14:00 -0000 From: Joel Brobecker To: Pedro Alves Cc: Yao Qi , gdb-patches@sourceware.org Subject: Re: crash/regression with ia64 targets Message-ID: <20121214151344.GA3654@adacore.com> References: <1353404184-22073-1-git-send-email-yao@codesourcery.com> <50AFD573.1090601@gmail.com> <50B0ABF9.1080606@codesourcery.com> <20121213120528.GA19986@adacore.com> <50CA2027.5090006@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="lrZ03NoBR/3+SXJZ" Content-Disposition: inline In-Reply-To: <50CA2027.5090006@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) 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: 2012-12/txt/msg00503.txt.bz2 --lrZ03NoBR/3+SXJZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1412 > I wonder why this crash wasn't visible before. AFAICS from find_sym_fns, > the only kinds of objfiles that can be loaded without debugging symbols are > srec, ihex and tekhex (the latter can have symbols, but we don't read > in those). > > Ah, indeed, it was. I can reproduce it: Nice! (I think) > Not clear to me which place would be best. I suggest do nothing, > as its easiest :-) Sold :) Attached is the patch I am currently testing. It already passed testing on ia64-linux (ie: I reverted the patch triggering the crash, ran the testsuite, then un-reverted it, and applied this patch), no regression. It passesd testing on x64_64-linux as well. Testing on x86_64-darwin is under way, and I will add ppc-aix and x86-windows using AdaCore's testsuite. But given the nature of the changes triggering the cross-platform testing, I remain fairly confident of the results. gdb/ChangeLog: * symfile.c (syms_from_objfile_1): Renames syms_from_objfile. Remove call to init_entry_point_info. Add OBJFILE's section_offsets and num_sections initialization. Add note about entry info in the function documentation. (syms_from_objfile): New function. * coffread.c (coff_symfile_init): Remove call to init_entry_point_info. * machoread.c (macho_symfile_init): Likewise. * xcoffread.c(xcoff_symfile_init): Likewise. Thanks, -- Joel --lrZ03NoBR/3+SXJZ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Fix-NULL-objfile-s-section_offsets-dereference-durin.patch" Content-length: 4904 >From b1508860e512c1d9ee1c9826d1df5b1990af8230 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Fri, 14 Dec 2012 01:25:26 -0500 Subject: [PATCH] Fix NULL objfile's section_offsets dereference during symbol load. gdb/ChangeLog: * symfile.c (syms_from_objfile_1): Renames syms_from_objfile. Remove call to init_entry_point_info. Add OBJFILE's section_offsets and num_sections initialization. Add note about entry info in the function documentation. (syms_from_objfile): New function. * coffread.c (coff_symfile_init): Remove call to init_entry_point_info. * machoread.c (macho_symfile_init): Likewise. * xcoffread.c(xcoff_symfile_init): Likewise. --- gdb/coffread.c | 2 -- gdb/machoread.c | 1 - gdb/symfile.c | 42 ++++++++++++++++++++++++++++++++++-------- gdb/xcoffread.c | 2 -- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/gdb/coffread.c b/gdb/coffread.c index 56ed5ae..398e61c 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -469,8 +469,6 @@ coff_symfile_init (struct objfile *objfile) find this causes a significant slowdown in gdb then we could set it in the debug symbol readers only when necessary. */ objfile->flags |= OBJF_REORDERED; - - init_entry_point_info (objfile); } /* This function is called for every section; it finds the outer diff --git a/gdb/machoread.c b/gdb/machoread.c index 6a6eaa1..c0e6d90 100644 --- a/gdb/machoread.c +++ b/gdb/machoread.c @@ -79,7 +79,6 @@ static void macho_symfile_init (struct objfile *objfile) { objfile->flags |= OBJF_REORDERED; - init_entry_point_info (objfile); } /* Add a new OSO to the vector of OSO to load. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index 6e09cbd..2a15293 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -896,6 +896,8 @@ read_symbols (struct objfile *objfile, int add_flags) /* Process a symbol file, as either the main file or as a dynamically loaded file. + This function does not set the OBJFILE's entry-point info. + OBJFILE is where the symbols are to be read from. ADDRS is the list of section load addresses. If the user has given @@ -923,12 +925,12 @@ read_symbols (struct objfile *objfile, int add_flags) an extra symbol file such as dynamically loaded code, and wether breakpoint reset should be deferred. */ -void -syms_from_objfile (struct objfile *objfile, - struct section_addr_info *addrs, - struct section_offsets *offsets, - int num_offsets, - int add_flags) +static void +syms_from_objfile_1 (struct objfile *objfile, + struct section_addr_info *addrs, + struct section_offsets *offsets, + int num_offsets, + int add_flags) { struct section_addr_info *local_addr = NULL; struct cleanup *old_chain; @@ -936,11 +938,21 @@ syms_from_objfile (struct objfile *objfile, gdb_assert (! (addrs && offsets)); - init_entry_point_info (objfile); objfile->sf = find_sym_fns (objfile->obfd); if (objfile->sf == NULL) - return; /* No symbols. */ + { + /* No symbols to load, but we still need to make sure + that the section_offsets table is allocated. */ + int num_sections = bfd_count_sections (objfile->obfd); + size_t size = SIZEOF_N_SECTION_OFFSETS (num_offsets); + + objfile->num_sections = num_sections; + objfile->section_offsets + = obstack_alloc (&objfile->objfile_obstack, size); + memset (objfile->section_offsets, 0, size); + return; + } /* Make sure that partially constructed symbol tables will be cleaned up if an error occurs during symbol reading. */ @@ -1021,6 +1033,20 @@ syms_from_objfile (struct objfile *objfile, xfree (local_addr); } +/* Same as syms_from_objfile_1, but also initializes the objfile + entry-point info. */ + +void +syms_from_objfile (struct objfile *objfile, + struct section_addr_info *addrs, + struct section_offsets *offsets, + int num_offsets, + int add_flags) +{ + syms_from_objfile_1 (objfile, addrs, offsets, num_offsets, add_flags); + init_entry_point_info (objfile); +} + /* Perform required actions after either reading in the initial symbols for a new objfile, or mapping in the symbols from a reusable objfile. ADD_FLAGS is a bitmask of enum symfile_add_flags. */ diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index ee47f6c..10c93cc 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -1922,8 +1922,6 @@ xcoff_symfile_init (struct objfile *objfile) find this causes a significant slowdown in gdb then we could set it in the debug symbol readers only when necessary. */ objfile->flags |= OBJF_REORDERED; - - init_entry_point_info (objfile); } /* Perform any local cleanups required when we are done with a particular -- 1.7.0.4 --lrZ03NoBR/3+SXJZ--