aboutsummaryrefslogtreecommitdiff
path: root/gas/subsegs.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2022-07-04 12:45:47 +0930
committerAlan Modra <amodra@gmail.com>2022-07-04 22:51:56 +0930
commiteeeaf705fe1c94e9330fa222d7928a9d0f03832a (patch)
treeedbba8cbb9a0deedb2dda7a037511c9ef2031d1b /gas/subsegs.c
parent0772daccb3ebaf513badf4266e1948454b4455c1 (diff)
downloadgdb-eeeaf705fe1c94e9330fa222d7928a9d0f03832a.zip
gdb-eeeaf705fe1c94e9330fa222d7928a9d0f03832a.tar.gz
gdb-eeeaf705fe1c94e9330fa222d7928a9d0f03832a.tar.bz2
alloc gas seginfo on notes obstack
Lots of memory used in gas should go on this obstack. The patch also frees all the gas obstacks on exit, which isn't a completely trivial task. * subsegs.c (alloc_seginfo): New function. (subseg_change, subseg_get): Use it. (subsegs_end): New function. * as.h (subsegs_end): Declare. * output-file.c: Include subsegs.h (stash_frchain_obs): New function. (output_file_close): Save obstacks attached to output bfd before closing. Call subsegs_end with the array of obstacks.
Diffstat (limited to 'gas/subsegs.c')
-rw-r--r--gas/subsegs.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/gas/subsegs.c b/gas/subsegs.c
index cb598e8..1776511 100644
--- a/gas/subsegs.c
+++ b/gas/subsegs.c
@@ -43,7 +43,27 @@ subsegs_begin (void)
frchain_now = NULL; /* Warn new_subseg() that we are booting. */
frag_now = &dummy_frag;
}
+
+void
+subsegs_end (struct obstack **obs)
+{
+ for (; *obs; obs++)
+ _obstack_free (*obs, NULL);
+ _obstack_free (&frchains, NULL);
+ _obstack_free (&cond_obstack, NULL);
+ _obstack_free (&notes, NULL);
+}
+static void
+alloc_seginfo (segT seg)
+{
+ segment_info_type *seginfo;
+
+ seginfo = obstack_alloc (&notes, sizeof (*seginfo));
+ memset (seginfo, 0, sizeof (*seginfo));
+ seginfo->bfd_section = seg;
+ bfd_set_section_userdata (seg, seginfo);
+}
/*
* subseg_change()
*
@@ -57,16 +77,11 @@ subsegs_begin (void)
void
subseg_change (segT seg, int subseg)
{
- segment_info_type *seginfo = seg_info (seg);
now_seg = seg;
now_subseg = subseg;
- if (! seginfo)
- {
- seginfo = XCNEW (segment_info_type);
- seginfo->bfd_section = seg;
- bfd_set_section_userdata (seg, seginfo);
- }
+ if (!seg_info (seg))
+ alloc_seginfo (seg);
}
static void
@@ -149,7 +164,6 @@ segT
subseg_get (const char *segname, int force_new)
{
segT secptr;
- segment_info_type *seginfo;
const char *now_seg_name = now_seg ? bfd_section_name (now_seg) : 0;
if (!force_new
@@ -163,13 +177,10 @@ subseg_get (const char *segname, int force_new)
else
secptr = bfd_make_section_anyway (stdoutput, segname);
- seginfo = seg_info (secptr);
- if (! seginfo)
+ if (!seg_info (secptr))
{
secptr->output_section = secptr;
- seginfo = XCNEW (segment_info_type);
- seginfo->bfd_section = secptr;
- bfd_set_section_userdata (secptr, seginfo);
+ alloc_seginfo (secptr);
}
return secptr;
}