aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2025-09-03 10:59:54 +0930
committerAlan Modra <amodra@gmail.com>2025-09-03 11:14:21 +0930
commit180075d14fab9f75eaf679589f9d175fb5448d21 (patch)
tree83939b5239866edc6b12137386f70ff7cc923e37
parentfcd717899e8a38dd152002ebcb432e6d508b7c38 (diff)
downloadbinutils-180075d14fab9f75eaf679589f9d175fb5448d21.zip
binutils-180075d14fab9f75eaf679589f9d175fb5448d21.tar.gz
binutils-180075d14fab9f75eaf679589f9d175fb5448d21.tar.bz2
frag_alloc use of obstack_alloc
Avoid the alignment hackery necessary when obstack_alloc is used. obstack_alloc expands to obstack_blank plus obstack_finish, and the latter call is where alignment of the tail of the obstack happens. The docs say obstack_alloc "is invoked almost like malloc", which implies a fixed size allocation and you don't need other obstack calls in its use. So I think trying to use obstack_alloc in frag_alloc was always a poor choice. * frags.c (frag_alloc): Replace obstack_alloc with obstack_blank.
-rw-r--r--gas/frags.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/gas/frags.c b/gas/frags.c
index 54b98d1..e93ae68 100644
--- a/gas/frags.c
+++ b/gas/frags.c
@@ -76,18 +76,17 @@ fragS *
frag_alloc (struct obstack *ob, size_t extra)
{
fragS *ptr;
- int oalign;
/* 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);
- obstack_alignment_mask (ob) = oalign;
+ /* Do not use obstack_alloc here. If you do, you'll need to turn
+ off alignment as otherwise obstack_alloc will align the end of
+ the frag (via obstack_finish adjusting obstack next_free
+ pointer), making it seem like the frag already has contents in
+ fr_literal. */
+ obstack_blank (ob, extra + SIZEOF_STRUCT_FRAG);
+ ptr = obstack_base (ob);
memset (ptr, 0, SIZEOF_STRUCT_FRAG);
totalfrags++;
return ptr;