From: Tristan Gingold Date: Mon, 1 Aug 2011 08:05:49 +0000 (+0000) Subject: 2011-08-01 Tristan Gingold X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8d8385cfb84fae7b0959b77fe287d97795415194;p=binutils-gdb.git 2011-08-01 Tristan Gingold * frags.c (frag_grow): Simplify the code. --- diff --git a/gas/ChangeLog b/gas/ChangeLog index 86886436b70..ee4d5e63e6d 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,7 @@ +2011-08-01 Tristan Gingold + + * frags.c (frag_grow): Simplify the code. + 2011-07-30 Richard Sandiford * config/tc-mips.c (nops_for_vr4130): Revert previous commit. diff --git a/gas/frags.c b/gas/frags.c index a6553bb3baa..fb3c02d3b5d 100644 --- a/gas/frags.c +++ b/gas/frags.c @@ -85,31 +85,38 @@ frag_grow (unsigned int nchars) { if (obstack_room (&frchain_now->frch_obstack) < nchars) { - unsigned int n; long oldc; + long newc; - 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. */ + for extremely big (like 2GB initialized) frags. */ if (nchars < 0x10000) - frchain_now->frch_obstack.chunk_size = 2 * nchars; + newc = 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; + newc = nchars + 0x10000; + newc += SIZEOF_STRUCT_FRAG; + + /* Check for possible overflow. */ + if (newc < 0) + as_fatal (_("can't extend frag %u chars"), nchars); + + /* Force to allocate at least NEWC bytes. */ + oldc = obstack_chunk_size (&frchain_now->frch_obstack); + obstack_chunk_size (&frchain_now->frch_obstack) = newc; + + while (obstack_room (&frchain_now->frch_obstack) < nchars) + { + /* Not enough room in this frag. Close it and start a new one. + This must be done in a loop because the created frag may not + be big enough if the current obstack chunk is used. */ + frag_wane (frag_now); + frag_new (0); + } + + /* Restore the old chunk size. */ + obstack_chunk_size (&frchain_now->frch_obstack) = 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)