From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 82EE8384E3A5 for ; Fri, 25 Nov 2022 16:55:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 82EE8384E3A5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id C08B41FD84 for ; Fri, 25 Nov 2022 16:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1669395357; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=h8+aACheW8WigLd7r0NuD5lrQvhIdML4+UtTamFofIA=; b=CCPEEy45DopX9kM/Kc0OT0NNk3NsX6F2+7GqE8iuShbFnc6BESOR2r8bFPSFRuBMTIpraU nrUMqO5WlEfbYrhhw+UcxtdOMmAJLHs2c9ccFvI+8GmBA+qPf6zADkdV/ALJzP1cKQSx61 DaFO1cagwB+BCshGaOSokxx50yL1FY4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1669395357; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=h8+aACheW8WigLd7r0NuD5lrQvhIdML4+UtTamFofIA=; b=7IIf1Ndc3bl+2p2Vk8RpygTyvHcTlgnLIvjgWKlYxrbvc4maBU0IOaUChENDo4A8eNojXR tCVt2wspE2GfQDCw== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id BC19F2C141 for ; Fri, 25 Nov 2022 16:55:57 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id B6C656586; Fri, 25 Nov 2022 16:55:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id B5B076238 for ; Fri, 25 Nov 2022 16:55:57 +0000 (UTC) Date: Fri, 25 Nov 2022 16:55:57 +0000 (UTC) From: Michael Matz To: binutils@sourceware.org Subject: [PATCH 6/8] section-select: Cleanup In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: more cleanups, removing useless callbacks, inlining some things, removing check_resolved and stmt->resolved. --- ld/ldlang.c | 157 ++++++++++++++++------------------------------------ ld/ldlang.h | 1 - 2 files changed, 49 insertions(+), 109 deletions(-) diff --git a/ld/ldlang.c b/ld/ldlang.c index 3748bf9bec9..18d10531d51 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -81,6 +81,9 @@ static void exp_init_os (etree_type *); static lang_input_statement_type *lookup_name (const char *); static void insert_undefined (const char *); static bool sort_def_symbol (struct bfd_link_hash_entry *, void *); +static lang_statement_union_type *new_statement (enum statement_enum type, + size_t size, + lang_statement_list_type *list); static void print_statement (lang_statement_union_type *, lang_output_section_statement_type *); static void print_statement_list (lang_statement_union_type *, @@ -365,39 +368,43 @@ walk_wild_file_in_exclude_list (struct name_list *exclude_list, return false; } -/* Try processing a section against a wildcard. This just calls - the callback unless the filename exclusion list is present - and excludes the file. It's hardly ever present so this - function is very fast. */ +static unsigned int old_max_section_id = 0; + +/* Add SECTION (from input FILE) to the list of matching sections + within PTR (the matching wildcard is SEC). */ static void -walk_wild_consider_section (lang_wild_statement_type *ptr, - lang_input_statement_type *file, - asection *s, - struct wildcard_list *sec, - callback_t callback, - void *data) +add_matching_section (lang_wild_statement_type *ptr, + struct wildcard_list *sec, + asection *section, + lang_input_statement_type *file) { - if (s->id < ptr->max_section_id) - return; - /* Don't process sections from files which were excluded. */ - if (walk_wild_file_in_exclude_list (sec->spec.exclude_name_list, file)) - return; - - (*callback) (ptr, sec, s, file, data); + 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; } +/* Process section S (from input file FILE) in relation to wildcard + statement PTR. We already know that a prefix of the name of S matches + some wildcard in PTR's wildcard list. Here we check if the filename + matches as well (if it's specified) and if any of the wildcards in fact + does match. */ + static void walk_wild_section_match (lang_wild_statement_type *ptr, lang_input_statement_type *file, - asection *s, - callback_t callback, - void *data) + asection *s) { struct wildcard_list *sec; const char *file_spec = ptr->filename; char *p; + if (s->id < ptr->max_section_id) + return; + /* Check if filenames match. */ if (file_spec == NULL) ; @@ -424,23 +431,21 @@ walk_wild_section_match (lang_wild_statement_type *ptr, wildcard all sections match. */ sec = ptr->section_list; if (sec == NULL) - (*callback) (ptr, sec, s, file, data); - - while (sec != NULL) + add_matching_section (ptr, sec, s, file); + else { - bool skip = false; - - if (sec->spec.name != NULL) + const char *sname = bfd_section_name (s); + for (; sec != NULL; sec = sec->next) { - const char *sname = bfd_section_name (s); + if (sec->spec.name != NULL + && spec_match (&sec->spec, sname) != 0) + continue; - skip = spec_match (&sec->spec, sname) != 0; + /* Don't process sections from files which were excluded. */ + if (!walk_wild_file_in_exclude_list (sec->spec.exclude_name_list, + file)) + add_matching_section (ptr, sec, s, file); } - - if (!skip) - walk_wild_consider_section (ptr, file, s, sec, callback, data); - - sec = sec->next; } } @@ -769,8 +774,7 @@ static void insert_prefix_tree (lang_wild_statement_type *stmt) { struct wildcard_list *sec; - struct prefixtree **pt = &ptroot, *t; - struct wild_stmt_list *sl, **psl; + struct prefixtree *t; if (!stmt->section_list) { @@ -782,9 +786,8 @@ insert_prefix_tree (lang_wild_statement_type *stmt) for (sec = stmt->section_list; sec; sec = sec->next) { - const char *name = sec->spec.name ? sec->spec.name : ""; + const char *name = sec->spec.name ? sec->spec.name : "*"; char c; - pt = &ptroot; t = ptroot; for (; (c = *name); name++) { @@ -799,15 +802,7 @@ insert_prefix_tree (lang_wild_statement_type *stmt) as well. */ if (!c) t = get_prefix_tree (&t->child, 0, true); - else if (!t) - abort(); - sl = (struct wild_stmt_list *) xmalloc (sizeof *sl); - sl->stmt = stmt; - sl->next = NULL; - psl = &t->stmt; - while (*psl) - psl = &(*psl)->next; - *psl = sl; + pt_add_stmt (t, stmt); } } @@ -885,47 +880,6 @@ analyze_walk_wild_section_handler (lang_wild_statement_type *ptr) insert_prefix_tree (ptr); } -static bool check_resolve = false; -static unsigned int old_max_section_id = 0; - -static lang_statement_union_type * -new_statement (enum statement_enum type, - size_t size, - lang_statement_list_type *list); -static void -add_matching_callback (lang_wild_statement_type *ptr, - struct wildcard_list *sec, - asection *section, - lang_input_statement_type *file, - void *data ATTRIBUTE_UNUSED) -{ - if (check_resolve) - { - if (0) - { - lang_statement_union_type *l; - for (l = ptr->matching_sections.head; l; l = l->header.next) - { - if (section == l->input_matcher.section - && sec == l->input_matcher.pattern - && file == l->input_matcher.input_stmt) - break; - } - if (!l) - abort(); - } - } - else - { - 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; - } -} - /* Match all sections from FILE against the global prefix tree, and record them into each wild statement that has a match. */ @@ -940,37 +894,28 @@ resolve_wild_sections (lang_input_statement_type *file) for (s = file->the_bfd->sections; s != NULL; s = s->next) { const char *sname = bfd_section_name (s); - char c; - struct prefixtree **pt = &ptroot, *t = *pt; + char c = 1; + struct prefixtree *t = ptroot; if (old_max_section_id && s->id < old_max_section_id) continue; //printf (" YYY consider %s of %s\n", sname, file->the_bfd->filename); do { - if (!t) - break; if (t->stmt) { struct wild_stmt_list *sl; for (sl = t->stmt; sl; sl = sl->next) { - walk_wild_section_match (sl->stmt, file, s, add_matching_callback, NULL); + walk_wild_section_match (sl->stmt, file, s); //printf (" ZZZ maybe place into %p\n", sl->stmt); } } + if (!c) + break; c = *sname++; t = get_prefix_tree (&t->child, c, false); } - while (c && t); - if (t && t->stmt) - { - struct wild_stmt_list *sl; - for (sl = t->stmt; sl; sl = sl->next) - { - walk_wild_section_match (sl->stmt, file, s, add_matching_callback, NULL); - //printf (" ZZZ maybe place into %p\n", sl->stmt); - } - } + while (t); } } @@ -979,7 +924,6 @@ resolve_wild_sections (lang_input_statement_type *file) static void resolve_wilds (void) { - check_resolve = false; LANG_FOR_EACH_INPUT_STATEMENT (f) { //printf("XXX %s\n", f->filename); @@ -1011,7 +955,6 @@ resolve_wilds (void) } } old_max_section_id = bfd_get_max_section_id (); - check_resolve = true; } /* For each input section that matches wild statement S calls @@ -1025,13 +968,13 @@ walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) if (s->max_section_id < bfd_get_max_section_id ()) { //printf("XXX %s\n", s->filename ? s->filename : ""); - s->resolved = true; s->max_section_id = bfd_get_max_section_id (); } for (l = s->matching_sections.head; l; l = l->header.next) { - (*callback) (s, l->input_matcher.pattern, l->input_matcher.section, l->input_matcher.input_stmt, data); + (*callback) (s, l->input_matcher.pattern, l->input_matcher.section, + l->input_matcher.input_stmt, data); } } @@ -7910,7 +7853,6 @@ reset_one_wild (lang_statement_union_type *statement) if (statement->header.type == lang_wild_statement_enum) { lang_wild_statement_type *stmt = &statement->wild_statement; - stmt->resolved = false; stmt->max_section_id = 0; /* XXX Leaks? */ lang_list_init (&stmt->matching_sections); @@ -8298,7 +8240,6 @@ lang_add_wild (struct wildcard_spec *filespec, new_stmt->section_list = section_list; new_stmt->keep_sections = keep_sections; lang_list_init (&new_stmt->children); - new_stmt->resolved = false; new_stmt->max_section_id = 0; lang_list_init (&new_stmt->matching_sections); analyze_walk_wild_section_handler (new_stmt); diff --git a/ld/ldlang.h b/ld/ldlang.h index 09c43611a22..5d9d2447f1c 100644 --- a/ld/ldlang.h +++ b/ld/ldlang.h @@ -399,7 +399,6 @@ struct lang_wild_statement_struct lang_statement_list_type children; struct name_list *exclude_name_list; lang_statement_list_type matching_sections; - bool resolved; unsigned int max_section_id; lang_section_bst_type *tree, **rightmost; -- 2.36.1