From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5341 invoked by alias); 20 Feb 2006 15:03:09 -0000 Received: (qmail 5330 invoked by uid 22791); 20 Feb 2006 15:03:08 -0000 X-Spam-Check-By: sourceware.org Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.31.1) with ESMTP; Mon, 20 Feb 2006 15:03:00 +0000 Received: from drow by nevyn.them.org with local (Exim 4.54) id 1FBCYz-0003sd-I5 for gdb-patches@sourceware.org; Mon, 20 Feb 2006 10:02:58 -0500 Date: Mon, 20 Feb 2006 15:03:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Subject: Re: RFC: Fix an infinite loop placing sections in relocatable objects Message-ID: <20060220150257.GA14155@nevyn.them.org> Mail-Followup-To: gdb-patches@sourceware.org References: <20060216152444.GA22371@nevyn.them.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060216152444.GA22371@nevyn.them.org> User-Agent: Mutt/1.5.8i X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-02/txt/msg00354.txt.bz2 On Thu, Feb 16, 2006 at 10:24:44AM -0500, Daniel Jacobowitz wrote: > While trying to track down something completely different, I accidentally > got GDB stuck in an infinite loop. I'm not entirely sure what I was > thinking when I wrote this, but I believe the attached patch is a correct > fix: > - if we can't place at this address, we bump start_addr, so we should > restart the inner for loop. > - arg->lowest and align are both invariant in the function up to this > point, so there's no point resetting start_addr inside the loop and > clobbering the retry logic. > > Tested x86_64-pc-linux-gnu, where I can no longer trigger an infinite loop > here. Any opinions? I've checked in this version; thanks to both Jim and Andreas. -- Daniel Jacobowitz CodeSourcery 2006-02-20 Daniel Jacobowitz * symfile.c (place_section): Correct retry logic. Index: symfile.c =================================================================== RCS file: /cvs/src/src/gdb/symfile.c,v retrieving revision 1.167 diff -u -p -r1.167 symfile.c --- symfile.c 7 Feb 2006 19:40:30 -0000 1.167 +++ symfile.c 20 Feb 2006 14:58:31 -0000 @@ -476,6 +476,7 @@ place_section (bfd *abfd, asection *sect struct place_section_arg *arg = obj; CORE_ADDR *offsets = arg->offsets->offsets, start_addr; int done; + ULONGEST align = ((ULONGEST) 1) << bfd_get_section_alignment (abfd, sect); /* We are only interested in loadable sections. */ if ((bfd_get_section_flags (abfd, sect) & SEC_LOAD) == 0) @@ -486,11 +487,11 @@ place_section (bfd *abfd, asection *sect return; /* Otherwise, let's try to find a place for the section. */ + start_addr = (arg->lowest + align - 1) & -align; + do { asection *cur_sec; - ULONGEST align = 1 << bfd_get_section_alignment (abfd, sect); - start_addr = (arg->lowest + align - 1) & -align; done = 1; for (cur_sec = abfd->sections; cur_sec != NULL; cur_sec = cur_sec->next) @@ -524,7 +525,7 @@ place_section (bfd *abfd, asection *sect start_addr = offsets[indx] + bfd_get_section_size (cur_sec); start_addr = (start_addr + align - 1) & -align; done = 0; - continue; + break; } /* Otherwise, we appear to be OK. So far. */