From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2346 invoked by alias); 14 Oct 2010 16:07:14 -0000 Received: (qmail 2320 invoked by uid 22791); 14 Oct 2010 16:07:10 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,TW_YM,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Oct 2010 16:06:58 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9EG6vmA020488 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Oct 2010 12:06:57 -0400 Received: from host1.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9EG6sEM028229 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 14 Oct 2010 12:06:56 -0400 Received: from host1.dyn.jankratochvil.net (localhost [127.0.0.1]) by host1.dyn.jankratochvil.net (8.14.4/8.14.4) with ESMTP id o9EG6suo027561; Thu, 14 Oct 2010 18:06:54 +0200 Received: (from jkratoch@localhost) by host1.dyn.jankratochvil.net (8.14.4/8.14.4/Submit) id o9EG6rgP027554; Thu, 14 Oct 2010 18:06:53 +0200 Date: Thu, 14 Oct 2010 16:07:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Cc: Tom Tromey , Doug Evans Subject: Re: [patch] Fix ELF stale reference Message-ID: <20101014160653.GA24333@host1.dyn.jankratochvil.net> References: <20100908185837.GA24606@host1.dyn.jankratochvil.net> <20100909090511.GA937@host1.dyn.jankratochvil.net> <20100909145615.GA5771@host1.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100909145615.GA5771@host1.dyn.jankratochvil.net> User-Agent: Mutt/1.5.21 (2010-09-15) 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: 2010-10/txt/msg00244.txt.bz2 Hi, I was debugging https://bugzilla.redhat.com/show_bug.cgi?id=642879 and got to this fix from a different side. It is in fact a very common GDB crash - due to CTRL-C hit (to get GDB prompt) in the moment an ELF file is being read in. Original thread: http://sourceware.org/ml/gdb-patches/2010-09/msg00192.html On Thu, 09 Sep 2010 16:56:15 +0200, Jan Kratochvil wrote: > OTOH this patch is not completely clean, it can needlessly allocate > bfd-associated memory and the right fix would probably span into bfd/ IMO. While the memory could use for example register_objfile_data_with_cleanup instead of bfd_alloc so that if errors/CTRL-Cs happen the dynamic symbol table pointers memory is not allocated twice. Still I would not find it correct as such memory would be objfile-bound instead of abfd-bound - while being referenced by abfd. OK to check-in? Or some bfd/ API improvement should be made? Thanks, Jan gdb/ 2010-09-09 Jan Kratochvil Fix stale memory references. * elfread.c: Include libbfd.h. (elf_symfile_read): Replace xmalloc by bfd_alloc, drop xfree, new comment. --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -37,6 +37,7 @@ #include "complaints.h" #include "demangle.h" #include "psympriv.h" +#include "libbfd.h" extern void _initialize_elfread (void); @@ -792,8 +793,14 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags) if (storage_needed > 0) { - dyn_symbol_table = (asymbol **) xmalloc (storage_needed); - make_cleanup (xfree, dyn_symbol_table); + /* Memory gets permanently referenced from ABFD after + bfd_get_synthetic_symtab so it must not get freed before ABFD gets. + It happens only in the case when elf_slurp_reloc_table sees + asection->relocation NULL. Determining which section is asection is + done by _bfd_elf_get_synthetic_symtab which is all a bfd + implementation detail, though. */ + + dyn_symbol_table = bfd_alloc (abfd, storage_needed); dynsymcount = bfd_canonicalize_dynamic_symtab (objfile->obfd, dyn_symbol_table);