aboutsummaryrefslogtreecommitdiff
path: root/gas
diff options
context:
space:
mode:
authorTristan Gingold <gingold@adacore.com>2011-08-01 08:05:49 +0000
committerTristan Gingold <gingold@adacore.com>2011-08-01 08:05:49 +0000
commit8d8385cfb84fae7b0959b77fe287d97795415194 (patch)
tree301de171151ecef605cecd9ccb79728f80c60763 /gas
parentd2421a70c155d87281b215b0fdbbb6e02e563da0 (diff)
downloadfsf-binutils-gdb-8d8385cfb84fae7b0959b77fe287d97795415194.zip
fsf-binutils-gdb-8d8385cfb84fae7b0959b77fe287d97795415194.tar.gz
fsf-binutils-gdb-8d8385cfb84fae7b0959b77fe287d97795415194.tar.bz2
2011-08-01 Tristan Gingold <gingold@adacore.com>
* frags.c (frag_grow): Simplify the code.
Diffstat (limited to 'gas')
-rw-r--r--gas/ChangeLog4
-rw-r--r--gas/frags.c43
2 files changed, 29 insertions, 18 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 8688643..ee4d5e6 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,7 @@
+2011-08-01 Tristan Gingold <gingold@adacore.com>
+
+ * frags.c (frag_grow): Simplify the code.
+
2011-07-30 Richard Sandiford <rdsandiford@googlemail.com>
* config/tc-mips.c (nops_for_vr4130): Revert previous commit.
diff --git a/gas/frags.c b/gas/frags.c
index a6553bb..fb3c02d 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)