From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19794 invoked by alias); 16 Aug 2012 21:11:24 -0000 Received: (qmail 19772 invoked by uid 22791); 16 Aug 2012 21:11:23 -0000 X-SWARE-Spam-Status: No, hits=-3.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-ob0-f169.google.com (HELO mail-ob0-f169.google.com) (209.85.214.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Aug 2012 21:11:09 +0000 Received: by obhx4 with SMTP id x4so4870672obh.0 for ; Thu, 16 Aug 2012 14:11:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.60.172.202 with SMTP id be10mr2137159oec.53.1345151468417; Thu, 16 Aug 2012 14:11:08 -0700 (PDT) Received: by 10.76.10.6 with HTTP; Thu, 16 Aug 2012 14:11:08 -0700 (PDT) In-Reply-To: <87393mpy79.fsf@fleche.redhat.com> References: <87txwknhzj.fsf@fleche.redhat.com> <20120803160934.GE4430@bubble.grove.modra.org> <87hasdgv0h.fsf@fleche.redhat.com> <20120809101540.GA30412@bubble.grove.modra.org> <87wr0zsw9h.fsf@fleche.redhat.com> <20120816135258.GN3947@bubble.grove.modra.org> <87393mpy79.fsf@fleche.redhat.com> Date: Thu, 16 Aug 2012 21:35:00 -0000 Message-ID: Subject: Re: [PATCH 3/5] remove deleted BFDs from the archive cache From: "H.J. Lu" To: Tom Tromey Cc: Binutils Development Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2012-08/txt/msg00307.txt.bz2 On Thu, Aug 16, 2012 at 10:02 AM, Tom Tromey wrote: > HJ> Your checkin destroys binutils: > HJ> http://sourceware.org/bugzilla/show_bug.cgi?id=14475 > HJ> Can you fix it? > > Sorry about that. I see now that I will need a more clever plan to > destroy binutils. > > I debugged it. The immediate problem is that > _bfd_compute_and_write_armap calls bfd_free_cached_info > (aka _bfd_free_cached_info). This then does: > > objalloc_free ((struct objalloc *) abfd->memory); > > Whoops, this also frees the areltdata. > > So, I have two possible fixes for it. > > I've appended the first possible fix. It changes _bfd_free_cached_info > not to free all the memory attached to the BFD. > > A couple notes here. > > First, it seems very wrong to me to clear usrdata in this function. I > didn't touch this; since presumably clients may be relying on this > clearing in a subtle way (if they allocate the usrdata on the BFD > objalloc, which is perhaps the only sensible approach anyhow). But, I > think that if the appended patch goes in then this line should be > removed in a follow-up. > > Second, the check in _bfd_delete_bfd is perhaps ugly. Maybe > bfd_hash_table_free should do this check instead. Let me know what you > think. > > I rebuilt ld and binutils with this patch. Additionally, I hacked the > Makefiles to link all the programs with -lmcheck. Then I ran the ld and > binutils test suites. There were no regressions. I also examined one > particular case from ar.exp using valgrind -- I could reproduce the > problem before the patch, but not after. > > > Another possible fix for this bug would be to allocate the areltdata > using malloc. That way it would be immune to the objalloc_free call. > This would require a few more tweaks, like properly freeing it in > _bfd_delete_bfd, etc. > > I'm happy to make and test this change if you think it would be better. > > Tom > > 2012-08-16 Tom Tromey > > * opncls.c (_bfd_delete_bfd): Check to see if section htab is > already freed. > (_bfd_free_cached_info): Don't free the objalloc. > > Index: opncls.c > =================================================================== > RCS file: /cvs/src/src/bfd/opncls.c,v > retrieving revision 1.72 > diff -u -r1.72 opncls.c > --- opncls.c 9 Aug 2012 06:25:53 -0000 1.72 > +++ opncls.c 16 Aug 2012 16:57:36 -0000 > @@ -132,14 +132,15 @@ > { > if (abfd->memory) > { > - bfd_hash_table_free (&abfd->section_htab); > + if (abfd->section_htab.memory != NULL) > + bfd_hash_table_free (&abfd->section_htab); > objalloc_free ((struct objalloc *) abfd->memory); > } > > free (abfd); > } > > -/* Free objalloc memory. */ > +/* Free some information cached in the BFD. */ > > bfd_boolean > _bfd_free_cached_info (bfd *abfd) > @@ -147,14 +148,12 @@ > if (abfd->memory) > { > bfd_hash_table_free (&abfd->section_htab); > - objalloc_free ((struct objalloc *) abfd->memory); > > abfd->sections = NULL; > abfd->section_last = NULL; > abfd->outsymbols = NULL; > abfd->tdata.any = NULL; > abfd->usrdata = NULL; > - abfd->memory = NULL; > } > > return TRUE; I think it is better to use malloc on areltdata so that we can call objalloc_free to keep memory usage down. Thanks. -- H.J.