From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5654 invoked by alias); 9 Sep 2010 14:52:20 -0000 Received: (qmail 5628 invoked by uid 22791); 9 Sep 2010 14:52:12 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,TW_BJ,TW_YM,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Sep 2010 14:52:00 +0000 Received: from wpaz5.hot.corp.google.com (wpaz5.hot.corp.google.com [172.24.198.69]) by smtp-out.google.com with ESMTP id o89EpuxB003257 for ; Thu, 9 Sep 2010 07:51:57 -0700 Received: from vws11 (vws11.prod.google.com [10.241.21.139]) by wpaz5.hot.corp.google.com with ESMTP id o89EpOG5014130 for ; Thu, 9 Sep 2010 07:51:55 -0700 Received: by vws11 with SMTP id 11so1622238vws.8 for ; Thu, 09 Sep 2010 07:51:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.61.13 with SMTP id r13mr75675vch.202.1284043912156; Thu, 09 Sep 2010 07:51:52 -0700 (PDT) Received: by 10.220.178.139 with HTTP; Thu, 9 Sep 2010 07:51:51 -0700 (PDT) In-Reply-To: <20100909090511.GA937@host1.dyn.jankratochvil.net> References: <20100908185837.GA24606@host1.dyn.jankratochvil.net> <20100909090511.GA937@host1.dyn.jankratochvil.net> Date: Thu, 09 Sep 2010 16:01:00 -0000 Message-ID: Subject: Re: [patch] Fix ELF stale reference [Re: [patch] .gdb_index: Do not crash on NOBITS] From: Doug Evans To: Jan Kratochvil Cc: Tom Tromey , gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true 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-09/txt/msg00199.txt.bz2 On Thu, Sep 9, 2010 at 2:05 AM, Jan Kratochvil wrote: > > gdb/ > 2010-09-09 =A0Jan Kratochvil =A0 > > =A0 =A0 =A0 =A0Fix stale memory references. > =A0 =A0 =A0 =A0* elfread.c: Include libbfd.h. > =A0 =A0 =A0 =A0(elf_symfile_read): Replace xmalloc by bfd_alloc, drop xfr= ee, new > =A0 =A0 =A0 =A0comment. > > --- a/gdb/elfread.c > +++ b/gdb/elfread.c > @@ -37,6 +37,7 @@ > =A0#include "complaints.h" > =A0#include "demangle.h" > =A0#include "psympriv.h" > +#include "libbfd.h" Apologies for nitpicking but this raises an issue I'd like to understand be= tter. I thought libbfd.h was an internal bfd header. [I know I've wanted to use it at least once and been told "No." :-)] > > =A0extern void _initialize_elfread (void); > > @@ -792,8 +793,14 @@ elf_symfile_read (struct objfile *objfile, int symfi= le_flags) > > =A0 if (storage_needed > 0) > =A0 =A0 { > - =A0 =A0 =A0dyn_symbol_table =3D (asymbol **) xmalloc (storage_needed); > - =A0 =A0 =A0make_cleanup (xfree, dyn_symbol_table); > + =A0 =A0 =A0/* Memory gets permanently referenced from ABFD after > + =A0 =A0 =A0 =A0bfd_get_synthetic_symtab so it must not get freed before= ABFD gets. > + =A0 =A0 =A0 =A0It happens only in the case when elf_slurp_reloc_table s= ees > + =A0 =A0 =A0 =A0asection->relocation NULL. =A0Determining which section = is asection is > + =A0 =A0 =A0 =A0done by _bfd_elf_get_synthetic_symtab which is all a bfd > + =A0 =A0 =A0 =A0implementation detail, though. =A0*/ > + > + =A0 =A0 =A0dyn_symbol_table =3D bfd_alloc (abfd, storage_needed); > =A0 =A0 =A0 dynsymcount =3D bfd_canonicalize_dynamic_symtab (objfile->obf= d, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dyn_symbol_table); >