diff options
author | Alan Modra <amodra@gmail.com> | 2025-09-03 09:50:17 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2025-09-03 10:31:35 +0930 |
commit | fcd717899e8a38dd152002ebcb432e6d508b7c38 (patch) | |
tree | 977c0a6d12348234a443af311e613f6ac4d1ae69 | |
parent | 11e5824cda9f8d94f6982124eb2c231dfab77bee (diff) | |
download | binutils-fcd717899e8a38dd152002ebcb432e6d508b7c38.zip binutils-fcd717899e8a38dd152002ebcb432e6d508b7c38.tar.gz binutils-fcd717899e8a38dd152002ebcb432e6d508b7c38.tar.bz2 |
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.
-rw-r--r-- | gas/frags.c | 14 | ||||
-rw-r--r-- | gas/write.c | 6 |
2 files changed, 9 insertions, 11 deletions
diff --git a/gas/frags.c b/gas/frags.c index 0ad1240..54b98d1 100644 --- a/gas/frags.c +++ b/gas/frags.c @@ -69,8 +69,8 @@ frag_alloc_check (const struct obstack *ob) } /* Allocate a frag on the specified obstack. - Call this routine from everywhere else, so that all the weird alignment - hackery can be done in just one place. */ + Call this routine every time a new frag is made, so that the + alignment hackery can be done in just one place. */ fragS * frag_alloc (struct obstack *ob, size_t extra) @@ -78,7 +78,12 @@ frag_alloc (struct obstack *ob, size_t extra) fragS *ptr; 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); obstack_alignment_mask (ob) = 0; 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. */ 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; know (frchP); former_last_fragP = frchP->frch_last; diff --git a/gas/write.c b/gas/write.c index 9d30445..33d821b 100644 --- a/gas/write.c +++ b/gas/write.c @@ -1456,7 +1456,6 @@ compress_frag (bool use_zstd, void *ctx, const char *contents, int in_size, avail_out = obstack_room (ob); if (avail_out <= 0) { - obstack_finish (ob); f = frag_alloc (ob, 0); f->fr_type = rs_fill; (*last_newf)->fr_next = f; @@ -1570,10 +1569,7 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) avail_out = obstack_room (ob); if (avail_out <= 0) { - fragS *newf; - - obstack_finish (ob); - newf = frag_alloc (ob, 0); + fragS *newf = frag_alloc (ob, 0); newf->fr_type = rs_fill; last_newf->fr_next = newf; last_newf = newf; |