mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-05 15:15:42 +00:00
Explain frag alignment hacks
"the weird alignment hackery" comment doesn't help anyone understand the code. Explain what is going on. Replace the zero length obstack_alloc with obstack_finish, which by inspection of obstack.h is all the zero length alloc does. * frags.c (frag_alloc): Comment. Replace zero length obstack_alloc with obstack_finish. (frag_new): Remove unnecessary obstack_finish. * write.c (compress_frag, compress_debug): Likewise.
This commit is contained in:
14
gas/frags.c
14
gas/frags.c
@@ -69,8 +69,8 @@ frag_alloc_check (const struct obstack *ob)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate a frag on the specified obstack.
|
/* Allocate a frag on the specified obstack.
|
||||||
Call this routine from everywhere else, so that all the weird alignment
|
Call this routine every time a new frag is made, so that the
|
||||||
hackery can be done in just one place. */
|
alignment hackery can be done in just one place. */
|
||||||
|
|
||||||
fragS *
|
fragS *
|
||||||
frag_alloc (struct obstack *ob, size_t extra)
|
frag_alloc (struct obstack *ob, size_t extra)
|
||||||
@@ -78,7 +78,12 @@ frag_alloc (struct obstack *ob, size_t extra)
|
|||||||
fragS *ptr;
|
fragS *ptr;
|
||||||
int oalign;
|
int oalign;
|
||||||
|
|
||||||
(void) obstack_alloc (ob, 0);
|
/* This will align the obstack so the next struct we allocate on it
|
||||||
|
will begin at a correct boundary. */
|
||||||
|
(void) obstack_finish (ob);
|
||||||
|
/* Turn off alignment as otherwise obstack_alloc will align the end
|
||||||
|
of the frag (obstack next_free pointer), making it seem like the
|
||||||
|
frag already has contents in fr_literal. */
|
||||||
oalign = obstack_alignment_mask (ob);
|
oalign = obstack_alignment_mask (ob);
|
||||||
obstack_alignment_mask (ob) = 0;
|
obstack_alignment_mask (ob) = 0;
|
||||||
ptr = obstack_alloc (ob, extra + SIZEOF_STRUCT_FRAG);
|
ptr = obstack_alloc (ob, extra + SIZEOF_STRUCT_FRAG);
|
||||||
@@ -172,9 +177,6 @@ frag_new (size_t old_frags_var_max_size
|
|||||||
/* Make sure its type is valid. */
|
/* Make sure its type is valid. */
|
||||||
gas_assert (frag_now->fr_type != 0);
|
gas_assert (frag_now->fr_type != 0);
|
||||||
|
|
||||||
/* This will align the obstack so the next struct we allocate on it
|
|
||||||
will begin at a correct boundary. */
|
|
||||||
obstack_finish (&frchain_now->frch_obstack);
|
|
||||||
frchP = frchain_now;
|
frchP = frchain_now;
|
||||||
know (frchP);
|
know (frchP);
|
||||||
former_last_fragP = frchP->frch_last;
|
former_last_fragP = frchP->frch_last;
|
||||||
|
|||||||
@@ -1456,7 +1456,6 @@ compress_frag (bool use_zstd, void *ctx, const char *contents, int in_size,
|
|||||||
avail_out = obstack_room (ob);
|
avail_out = obstack_room (ob);
|
||||||
if (avail_out <= 0)
|
if (avail_out <= 0)
|
||||||
{
|
{
|
||||||
obstack_finish (ob);
|
|
||||||
f = frag_alloc (ob, 0);
|
f = frag_alloc (ob, 0);
|
||||||
f->fr_type = rs_fill;
|
f->fr_type = rs_fill;
|
||||||
(*last_newf)->fr_next = f;
|
(*last_newf)->fr_next = f;
|
||||||
@@ -1570,10 +1569,7 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
|
|||||||
avail_out = obstack_room (ob);
|
avail_out = obstack_room (ob);
|
||||||
if (avail_out <= 0)
|
if (avail_out <= 0)
|
||||||
{
|
{
|
||||||
fragS *newf;
|
fragS *newf = frag_alloc (ob, 0);
|
||||||
|
|
||||||
obstack_finish (ob);
|
|
||||||
newf = frag_alloc (ob, 0);
|
|
||||||
newf->fr_type = rs_fill;
|
newf->fr_type = rs_fill;
|
||||||
last_newf->fr_next = newf;
|
last_newf->fr_next = newf;
|
||||||
last_newf = newf;
|
last_newf = newf;
|
||||||
|
|||||||
Reference in New Issue
Block a user