From patchwork Fri Nov 25 16:55:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 26099 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4158331wrr; Fri, 25 Nov 2022 08:57:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf6bTJsKXmTIe24mZhhappwbzDP0EpXqh6ZZFRdnGKOsee82iA3NRJvzOlSIoPcQenzVDby+ X-Received: by 2002:a05:6402:1bc4:b0:46a:342d:dcb3 with SMTP id ch4-20020a0564021bc400b0046a342ddcb3mr12891645edb.227.1669395438592; Fri, 25 Nov 2022 08:57:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669395438; cv=none; d=google.com; s=arc-20160816; b=GyEmGkTSlU1tpAnDBua6yD5hZVpf48lXeED6WZ36LtkFisd8WC7TpZtWm6RZrtifay NUTZFVXh74yROCb2uyggkD/sJAfDRiY4GdpujerNvNkHW8M469j/f525KdOfOEMKuOv0 lB/vkLAifZPXOdgnPaIgytKh/rkBVyR2CsqO1jq86t5Xwud1frWBa+nzE9o9PJiIVMYE eObkWcZIa2hqDQqfU0xdEhW2HYaxDhJ4HIaYQfsbj6IepND0zENPjhrRwoHty33kCMPj TRtiabMiKkW6CQ13okaIolXRofttirdtKOBVBm7V6qHGlYFzmGeKhVWpSC+7+Sta2fgO vZdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:references:message-id:in-reply-to:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=h8+aACheW8WigLd7r0NuD5lrQvhIdML4+UtTamFofIA=; b=bW8TzCHQPJ1hOF0VOtjvjp3DitRyap84PCMdrc+o0ULVcDTArPJuRLsva/KuE857c3 9eHel22ImFOaT0ORza/uYtioWiuwA+TMafBmDtPUG1AWvGacerzZF/5WwPT+/8DANPxA pPSbxxy01LooZVPVGyeVfE7dylA30InRkZAC5rNDaVFZcyE59fX29n1JOt9C1oYoANm2 DzHLU6tbj8C3v2b/JrpXZiQWyTeEqzOiCH4VrJXxTTNm57Y5qp44PArK6tCL9d50Z8Ry zld9X7JValyU8nXGS3IK5ljGcIdXJtvItuuhNh3FcU7UJh+k3svb92MR9lHa0R0qFjJ0 p81g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=N5bInBXl; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id xf9-20020a17090731c900b007b28c65347esi3325454ejb.695.2022.11.25.08.57.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 08:57:18 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=N5bInBXl; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B88A8384E3AC for ; Fri, 25 Nov 2022 16:56:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B88A8384E3AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669395416; bh=h8+aACheW8WigLd7r0NuD5lrQvhIdML4+UtTamFofIA=; h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=N5bInBXljY9S3Wn+v0BqnMsvP8ZWVSHJl1TYgYxcd2etQHrdomUd/LA0svFsuyR5M uivGTRAMix1vda51L2wBTf9YSZ10JZX5PJy2jJu3OVAvVdpexQyDr7IkXD1IwgzPp2 yFHmUrXruRzcz1Rm2KjcUoG9hxScZGQJyi7390fU= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 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) 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) 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 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Michael Matz via Binutils From: Michael Matz Reply-To: Michael Matz Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750487991347035638?= X-GMAIL-MSGID: =?utf-8?q?1750487991347035638?= 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;