This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch/gas]: simplify frag_grow


On Jul 11, 2011, at 4:05 AM, Alan Modra wrote:

> On Wed, Jul 06, 2011 at 09:00:29AM +0200, Tristan Gingold wrote:
>> +      if (newc <= 0)
>> +        as_fatal (_("can't extend frag to %u chars"), nchars);
> 
> Watch out for proliferation of messages.  There isn't any reason for a
> difference between this error and the later one.  (In fact this
> message isn't correct since we are extending the frag *by* nchars, not
> to a total size of nchars.)
> 
>> +      /* Force to allocate at least NEWC bytes.  */
>> +      oldc = obstack_chunk_size (&frchain_now->frch_obstack);
>> +      obstack_chunk_size (&frchain_now->frch_obstack) = newc;
>> +
>> +      /* Do the real work: create a new frag.  */
>> +      frag_new (0);
>> +
>> +      /* Restore the old chunk size.  */
>> +      obstack_chunk_size (&frchain_now->frch_obstack) = oldc;
> 
> An alternative to fixing the error message would be to wrap the above
> all in "if (newc > 0){}" and dispense with the first as_fatal call.
> Your choice.  Either way is OK to commit.

Thanks.  Here is what I am committing (using the later suggestion).

Tristan.

Index: frags.c
===================================================================
RCS file: /cvs/src/src/gas/frags.c,v
retrieving revision 1.26
diff -c -r1.26 frags.c
*** frags.c	11 Sep 2009 15:27:33 -0000	1.26
--- frags.c	25 Jul 2011 13:32:47 -0000
***************
*** 75,115 ****
    return ptr;
  }
  

! /* Try to augment current frag by nchars chars.
     If there is no room, close of the current frag with a ".fill 0"
!    and begin a new frag. Unless the new frag has nchars chars available
!    do not return. Do not set up any fields of *now_frag.  */
  
  void
  frag_grow (unsigned int nchars)
  {
    if (obstack_room (&frchain_now->frch_obstack) < nchars)
      {
-       unsigned int n;
        long oldc;
  
        frag_wane (frag_now);
!       frag_new (0);
!       oldc = frchain_now->frch_obstack.chunk_size;
        /* Try to allocate a bit more than needed right now.  But don't do
           this if we would waste too much memory.  Especially necessary
! 	 for extremely big (like 2GB initialized) frags.  */
        if (nchars < 0x10000)
! 	frchain_now->frch_obstack.chunk_size = 2 * nchars;
        else
!         frchain_now->frch_obstack.chunk_size = nchars + 0x10000;
!       frchain_now->frch_obstack.chunk_size += SIZEOF_STRUCT_FRAG;
!       if (frchain_now->frch_obstack.chunk_size > 0)
! 	while ((n = obstack_room (&frchain_now->frch_obstack)) < nchars
! 	       && (unsigned long) frchain_now->frch_obstack.chunk_size > nchars)
! 	  {
! 	    frag_wane (frag_now);
! 	    frag_new (0);
! 	  }
!       frchain_now->frch_obstack.chunk_size = oldc;
      }
-   if (obstack_room (&frchain_now->frch_obstack) < nchars)
-     as_fatal (_("can't extend frag %u chars"), nchars);
  }
  

  /* Call this to close off a completed frag, and start up a new (empty)
--- 75,121 ----
    return ptr;
  }
  

! /* Try to augment current frag by NCHARS chars.
     If there is no room, close of the current frag with a ".fill 0"
!    and begin a new frag.  Do not set up any fields of *now_frag.  */
  
  void
  frag_grow (unsigned int nchars)
  {
    if (obstack_room (&frchain_now->frch_obstack) < nchars)
      {
        long oldc;
+       long newc;
  
+       /* Not enough room in this frag.  Close it.  */
        frag_wane (frag_now);
! 
        /* Try to allocate a bit more than needed right now.  But don't do
           this if we would waste too much memory.  Especially necessary
!          for extremely big (like 2GB initialized) frags.  */
        if (nchars < 0x10000)
!         newc = 2 * nchars;
        else
!         newc = nchars + 0x10000;
!       newc += SIZEOF_STRUCT_FRAG;
! 
!       if (newc > 0)
!         {
!           /* Force to allocate at least NEWC bytes.  */
!           oldc = obstack_chunk_size (&frchain_now->frch_obstack);
!           obstack_chunk_size (&frchain_now->frch_obstack) = newc;
! 
!           /* Do the real work: create a new frag.  */
!           frag_new (0);
! 
!           /* Restore the old chunk size.  */
!           obstack_chunk_size (&frchain_now->frch_obstack) = oldc;
!         }
! 
!       /* Check for success (also handles negative values of NEWC).  */
!       if (obstack_room (&frchain_now->frch_obstack) < nchars)
!         as_fatal (_("can't extend frag %u chars"), nchars);
      }
  }
  

  /* Call this to close off a completed frag, and start up a new (empty)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]