From e6357caf75792c4a3284dcf5698d726de5c9f5ab Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 16 Jan 2026 16:19:31 +1030 Subject: [PATCH] ld: put wild matching_sections on an obstack so that the memory can be reclaimed easily when reset_resolved_wilds throws it all away. * ldlang.c (matching_obstack): New static var. (add_matching_section): Rewrite to use matching_obstack. (lang_init): Init matching_obstack. (reset_resolved_wilds): Free matching_obstack. --- ld/ldlang.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ld/ldlang.c b/ld/ldlang.c index 812542b5697..26bd52240c1 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -62,6 +62,7 @@ /* Local variables. */ static struct obstack stat_obstack; static struct obstack map_obstack; +static struct obstack matching_obstack; static struct obstack pt_obstack; #define obstack_chunk_alloc xmalloc @@ -452,12 +453,14 @@ add_matching_section (lang_wild_statement_type *ptr, asection *section, lang_input_statement_type *file) { - lang_input_matcher_type *new_section; - /* Add a section reference to the list. */ - new_section = new_stat (lang_input_matcher, &ptr->matching_sections); - new_section->section = section; - new_section->pattern = sec; - new_section->input_stmt = file; + lang_statement_union_type *n + = obstack_alloc (&matching_obstack, sizeof (lang_input_matcher_type)); + n->header.type = lang_input_matcher_enum; + n->header.next = NULL; + n->input_matcher.section = section; + n->input_matcher.pattern = sec; + n->input_matcher.input_stmt = file; + lang_statement_append (&ptr->matching_sections, n, &n->header.next); } /* Process section S (from input file FILE) in relation to wildcard @@ -1388,6 +1391,7 @@ lang_init (bool object_only) { obstack_begin (&stat_obstack, 1000); obstack_init (&pt_obstack); + obstack_init (&matching_obstack); } stat_ptr = &statement_list; @@ -8313,6 +8317,8 @@ static void reset_resolved_wilds (void) { lang_for_each_statement (reset_one_wild); + obstack_free (&matching_obstack, NULL); + obstack_init (&matching_obstack); } /* For each output section statement, splice any entries on the -- 2.47.3