From patchwork Fri Nov 25 16:44:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 26094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4152216wrr; Fri, 25 Nov 2022 08:45:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf6vPiGrXMnP8rEDVt9v5eEqslnBpPuAuahoEK/JbMeRiSO4KcNNYJ2hegh72kiTfzQIfD3u X-Received: by 2002:a17:906:9255:b0:7ad:c66e:ad9d with SMTP id c21-20020a170906925500b007adc66ead9dmr31710222ejx.413.1669394711248; Fri, 25 Nov 2022 08:45:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669394711; cv=none; d=google.com; s=arc-20160816; b=SfgSAq5nZ47+uWygex5qkmLBSOs+IWi0HzXVPqgcuisViG8ZajgS/yM/u8EYBbWQmj b5dB/c/7+uy15qT5v5MHjPVcs15gcbtVMTgVgv9q1bkEhgXzWGpMw0wU5Hv0ksrAlMNN LkP4jX24kRYUZZHDY0QqnSePNXBWYafiYJ+L8F8It+f2A3fqhJe2MJnNQ22Ev/S5VMhi 01G8eLPK5dFAfbnUmYu0fdSnt/OWY3gm84y4niwSC+2ptSCF+Ghg73DLJrxZvmI/kvwk wEAXW4zMQ/3D01bZypT9zIGB2IQZbH6s3obbzH/ves3Iy9U6gcYIvunD/3gr/s5Eu4Zp 4SoA== 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=pBiUq8ExWdktUpW3jhVjWj6qtVgscL/Nm/OYGYqikEk=; b=vnnxaVNR0L3iRb71AMTH+C6gR2BZKuCWGz/5jAU/N9R4BmTpaKqlv9guibM782wnTL /iku/E/9AHp/xIwdFzk+IlpC9PC9f2ZSRg1/2icHzxvG0dK2zL9hNn81vrhibWUGvznu 0OHVmQFaWh2S5Tv9c1Yw4hXzsI4FshNCR+L9g3T/HbPB7zZEfVwDyPZnc+DSVRA/DPVt bhmn6jblVJ0Gwc7N56dYt3x+IRWK96OrEEbZ/zn7+Xcr0o0vcVdQc/ZFB1cWEteA4TFy 4UzZ8IPWeimki7oTNdZMQfOSQrQLiQZ+E79r0f2XKGrx9LXkOUTijrWkP5ctsu9NQxa6 yl9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="h/byaOld"; 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 go18-20020a1709070d9200b007aeaacd5592si3095262ejc.124.2022.11.25.08.45.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 08:45:11 -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="h/byaOld"; 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 1DA50384A482 for ; Fri, 25 Nov 2022 16:45:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DA50384A482 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669394706; bh=pBiUq8ExWdktUpW3jhVjWj6qtVgscL/Nm/OYGYqikEk=; 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=h/byaOldIa/VDh/TmRcymS78ypMOl8D4xc3cfVZpeEyw5wmtzWaVB8lXotFAhuHcP 7JolvpYVq0YUR7V1LZLKLkAvw/YPdOn+S8eL4tqu+HhsYEOTgM01u6E4T516tzIyj/ 9Vx47bQZbS3PcCJsccBrrxN/QKcd9htUC7FdliqA= 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 97D22384E396 for ; Fri, 25 Nov 2022 16:44:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 97D22384E396 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D3A8E1FD84 for ; Fri, 25 Nov 2022 16:44:54 +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 CF3592C141 for ; Fri, 25 Nov 2022 16:44:54 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id C96816586; Fri, 25 Nov 2022 16:44:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id C832C6238 for ; Fri, 25 Nov 2022 16:44:54 +0000 (UTC) Date: Fri, 25 Nov 2022 16:44:54 +0000 (UTC) To: binutils@sourceware.org Subject: [PATCH 1/8] section-select: Lazily resolve section matches 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?1750487228955273424?= X-GMAIL-MSGID: =?utf-8?q?1750487228955273424?= and remember the results. Before this the order of section matching is basically: foreach script-wild-stmt S foreach pattern P of S foreach inputfile I foreach section S of I match S against P if match: do action for S And this process is done three or four times: for each top-level call to walk_wild() or wild(), that is: check_input_sections, lang_gc_sections, lang_find_relro_sections and of course map_input_to_output_sections. So we iterate over all sections of all files many many times (for each glob). Reality is a bit more complicated (some special glob types don't need the full iteration over all sections, only over all files), but that's the gist of it. For future work this shuffles the whole ordering a bit by lazily doing the matching process and memoizing results, trading a little memory for a 75% speedup of the overall section selection process. This lazy resolution introduces a problem with sections added late that's corrected in the next patch. --- ld/ldlang.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++- ld/ldlang.h | 12 ++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/ld/ldlang.c b/ld/ldlang.c index 81a6aeb7a89..c92ebd472f4 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -1072,8 +1072,27 @@ walk_wild_file (lang_wild_statement_type *s, } } +static lang_statement_union_type * +new_statement (enum statement_enum type, + size_t size, + lang_statement_list_type *list); static void -walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) +add_matching_callback (lang_wild_statement_type *ptr, + struct wildcard_list *sec, + asection *section, + lang_input_statement_type *file, + void *data ATTRIBUTE_UNUSED) +{ + 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; +} + +static void +walk_wild_resolve (lang_wild_statement_type *s) { const char *file_spec = s->filename; char *p; @@ -1083,6 +1102,66 @@ walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) /* Perform the iteration over all files in the list. */ LANG_FOR_EACH_INPUT_STATEMENT (f) { + //printf("XXX %s\n", f->filename); + walk_wild_file (s, f, add_matching_callback, NULL); + } + } + else if ((p = archive_path (file_spec)) != NULL) + { + LANG_FOR_EACH_INPUT_STATEMENT (f) + { + if (input_statement_is_archive_path (file_spec, p, f)) + walk_wild_file (s, f, add_matching_callback, NULL); + } + } + else if (wildcardp (file_spec)) + { + LANG_FOR_EACH_INPUT_STATEMENT (f) + { + if (fnmatch (file_spec, f->filename, 0) == 0) + walk_wild_file (s, f, add_matching_callback, NULL); + } + } + else + { + lang_input_statement_type *f; + + /* Perform the iteration over a single file. */ + f = lookup_name (file_spec); + if (f) + walk_wild_file (s, f, add_matching_callback, NULL); + } +} + +static void +walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) +{ + const char *file_spec = s->filename; + //char *p; + + if (!s->resolved) + { + //printf("XXX %s\n", file_spec ? file_spec : ""); + walk_wild_resolve (s); + s->resolved = true; + } + + { + lang_statement_union_type *l; + 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); + } + return; + } + +#if 0 + if (file_spec == NULL) + { + /* Perform the iteration over all files in the list. */ + LANG_FOR_EACH_INPUT_STATEMENT (f) + { + printf("XXX %s\n", f->filename); walk_wild_file (s, f, callback, data); } } @@ -1111,6 +1190,7 @@ walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) if (f) walk_wild_file (s, f, callback, data); } +#endif } /* lang_for_each_statement walks the parse tree and calls the provided @@ -1982,6 +2062,8 @@ insert_os_after (lang_output_section_statement_type *after) case lang_group_statement_enum: case lang_insert_statement_enum: continue; + case lang_input_matcher_enum: + FAIL (); } break; } @@ -4347,6 +4429,8 @@ map_input_to_output_sections break; case lang_insert_statement_enum: break; + case lang_input_matcher_enum: + FAIL (); } } } @@ -8343,6 +8427,8 @@ 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; + 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 713c5282b55..50ad64ce057 100644 --- a/ld/ldlang.h +++ b/ld/ldlang.h @@ -76,6 +76,7 @@ enum statement_enum lang_fill_statement_enum, lang_group_statement_enum, lang_input_section_enum, + lang_input_matcher_enum, lang_input_statement_enum, lang_insert_statement_enum, lang_output_section_statement_enum, @@ -335,6 +336,14 @@ typedef struct void *pattern; } lang_input_section_type; +typedef struct +{ + lang_statement_header_type header; + asection *section; + void *pattern; + lang_input_statement_type *input_stmt; +} lang_input_matcher_type; + struct map_symbol_def { struct bfd_link_hash_entry *entry; struct map_symbol_def *next; @@ -389,6 +398,8 @@ struct lang_wild_statement_struct bool keep_sections; lang_statement_list_type children; struct name_list *exclude_name_list; + lang_statement_list_type matching_sections; + bool resolved; walk_wild_section_handler_t walk_wild_section_handler; struct wildcard_list *handler_data[4]; @@ -440,6 +451,7 @@ typedef union lang_statement_union lang_fill_statement_type fill_statement; lang_group_statement_type group_statement; lang_input_section_type input_section; + lang_input_matcher_type input_matcher; lang_input_statement_type input_statement; lang_insert_statement_type insert_statement; lang_output_section_statement_type output_section_statement; From patchwork Fri Nov 25 16:46:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 26095 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4153182wrr; Fri, 25 Nov 2022 08:46:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf5KHxYyJJNNYW/suCuSHcDkDWrC4rmsceikxskaRXzN6A4/VBZXZW08eXh4Y8YFZNzBSr59 X-Received: by 2002:a05:6402:b81:b0:45c:a651:8849 with SMTP id cf1-20020a0564020b8100b0045ca6518849mr36336290edb.209.1669394812009; Fri, 25 Nov 2022 08:46:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669394812; cv=none; d=google.com; s=arc-20160816; b=kli4OYP+TiouFbYVBrYD7D2WL2OzaKcJtsLjVJoIhZ9d4q6YzFiVKg3nxAfv3BKP/S LKwQB+j8x4J/ZJZprJ9/FdbCvQ2JHABVbksbwtSbUoJdB9ODKg9AY1sE35N2vGHd7NU3 C71iAImwuGb1vx8uK9uwI4Fimu/j1lr8q2uWL9xE8wTCJQ60GAgUZ3ysxxZSKESS1Vyg FNSvn7pZY30h1JrlCVm/pcER8ktOaf+yCUNn8XXfEBFbYfqostNovuO9cc4vCv5n4JQv qNX4FgAlZGeCWez+dOBZER8jIigMNTqZxAOrKXzlgD+rBkBj0TQmNng41T1xrwNhNwr7 nCvA== 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=UYDztNdT8/VKmNoFNcWb9tZxdixOyJuXCyvsdktWz/Q=; b=hazFGq40HG5RLf51Hm+Ph2CGRMtVglrrVXttOlpM8oNJbf+W3QW36zw4IJ+CLVlLR9 rTpx79mwW6HeM6x9VdPNm+7bjxovO0RbmDbAvjatReJK94QOGyc12JuwMQr0aJ/EvxTi gRuQ2J9qdMw2YWBrfdvZ2WIMKlRTZJ7H51y3qEN5vHI3hps6eGNUl0Ns9E0psbZZiM4c 9zjcapwYVs13g8kpwFjMqcAfJjVXSZO3PvLXbkfbFg/wTOgwXMKZdpeZ/sy15tGznUv+ kbKnS06DLtGEocmoWWbde/Q01+J0M85g95f+gByCXEPkhZ91tfErRS9CHlO9xhyMMkRZ I/pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="iL1QaCj/"; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cs12-20020a170906dc8c00b007833cbbb747si3704090ejc.578.2022.11.25.08.46.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 08:46:52 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="iL1QaCj/"; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 0BCE4384E38E for ; Fri, 25 Nov 2022 16:46:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BCE4384E38E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669394811; bh=UYDztNdT8/VKmNoFNcWb9tZxdixOyJuXCyvsdktWz/Q=; 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=iL1QaCj/dvBR0zNcV4lAJJO67eJsAc/bGZdQj3uABHctMyYWBONySk+62oNbQ6YWR qYsQixdw/u3HkHk8YVaZKHxV11sVdKJS63/PZxjnE7IDFooVlTG00EGQ8TTeosBjGo VeLuirBGWpd3KEK4TDDicl37o49J1SpukR8oQTns= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 5D921384EF76 for ; Fri, 25 Nov 2022 16:46:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5D921384EF76 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 94D4A21B0F for ; Fri, 25 Nov 2022 16:46:41 +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 8FA602C141 for ; Fri, 25 Nov 2022 16:46:41 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id 8474C6586; Fri, 25 Nov 2022 16:46:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id 82A2E6238 for ; Fri, 25 Nov 2022 16:46:41 +0000 (UTC) Date: Fri, 25 Nov 2022 16:46:41 +0000 (UTC) To: binutils@sourceware.org Subject: [PATCH 2/8] section-select: Deal with sections added late 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?1750487334460580581?= X-GMAIL-MSGID: =?utf-8?q?1750487334460580581?= at least the check_relocs callback can add input sections (for creating an dynamic output relocation section). For those we need to go through the walk_wild handlers again. For quick detection of such new sections we export a new bfd function: bfd_get_max_section_id and remember that one when resolving a wild statement. Any section whose ->id member is higher than that is new. --- I keep this patch separate (not quashed into the one before) because it adds an interface to libbfd, which might be superseded depending on an answer to patch 4/8. And keeping it )and the reversion in 7/8) separate makes it easier to throw it out or include it. bfd/bfd-in2.h | 2 ++ bfd/section.c | 19 +++++++++++++++++++ ld/ldlang.c | 12 +++++++++++- ld/ldlang.h | 1 + 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 0b071dda1e5..5350ae42b03 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -1330,6 +1330,8 @@ discarded_section (const asection *sec) { 0, NAME, 0, BSF_SECTION_SYM, SECTION } #endif +unsigned int bfd_get_max_section_id (void); + void bfd_section_list_clear (bfd *); asection *bfd_get_section_by_name (bfd *abfd, const char *name); diff --git a/bfd/section.c b/bfd/section.c index f73e0345e15..d691bf265ab 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -849,6 +849,25 @@ SUBSECTION These are the functions exported by the section handling part of BFD. */ +/* +FUNCTION + bfd_get_max_section_id + +SYNOPSIS + unsigned int bfd_get_max_section_id (void); + +DESCRIPTION + Returns an internal number representing the maximum value of + any SECTION->id member. Whenever a new section is created that + value increases. It never decreases. +*/ + +unsigned int +bfd_get_max_section_id (void) +{ + return _bfd_section_id; +} + /* FUNCTION bfd_section_list_clear diff --git a/ld/ldlang.c b/ld/ldlang.c index c92ebd472f4..1e4f3a5ee05 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -374,6 +374,8 @@ walk_wild_consider_section (lang_wild_statement_type *ptr, callback_t callback, void *data) { + 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; @@ -395,6 +397,9 @@ walk_wild_section_general (lang_wild_statement_type *ptr, for (s = file->the_bfd->sections; s != NULL; s = s->next) { + if (s->id < ptr->max_section_id) + continue; + //printf ("YYY checking %s:%s\n", s->owner->filename, s->name); sec = ptr->section_list; if (sec == NULL) (*callback) (ptr, sec, s, file, data); @@ -1139,11 +1144,14 @@ walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) const char *file_spec = s->filename; //char *p; - if (!s->resolved) +#if 1 + //if (!s->resolved) + if (s->max_section_id < bfd_get_max_section_id ()) { //printf("XXX %s\n", file_spec ? file_spec : ""); walk_wild_resolve (s); s->resolved = true; + s->max_section_id = bfd_get_max_section_id (); } { @@ -1154,6 +1162,7 @@ walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) } return; } +#endif #if 0 if (file_spec == NULL) @@ -8428,6 +8437,7 @@ lang_add_wild (struct wildcard_spec *filespec, 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 50ad64ce057..8566e022a57 100644 --- a/ld/ldlang.h +++ b/ld/ldlang.h @@ -400,6 +400,7 @@ struct lang_wild_statement_struct struct name_list *exclude_name_list; lang_statement_list_type matching_sections; bool resolved; + unsigned int max_section_id; walk_wild_section_handler_t walk_wild_section_handler; struct wildcard_list *handler_data[4]; From patchwork Fri Nov 25 16:47:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 26096 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4153522wrr; Fri, 25 Nov 2022 08:47:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf7bitT6knq8KZ21aZ+5w4uw/LQ25MCDWHoYb61yHkUNajC4HEh8Bmnh3I+4qrvDCamYirH1 X-Received: by 2002:a17:906:2612:b0:7ad:9c82:6cdb with SMTP id h18-20020a170906261200b007ad9c826cdbmr3689186ejc.233.1669394849273; Fri, 25 Nov 2022 08:47:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669394849; cv=none; d=google.com; s=arc-20160816; b=GXG0lUX17/NbVNlZNRtk5cxsGV/BQ4uA5Lbh1bCrIkA/JH201E6Z8PRbTEoXu/PzfZ xwARLr6hxMVmlRpXehcf1255uayG1mtt6Fz87JCWXOtytOmXqIFdJrvqwaWwTNcXkz6t az5R6mcc3+mCluIK0fdUw+mmWB8jAJyIcCxYRpVHnKEzojkr/Z81dEdDCd+rh4RrGCca iMK/CoR7BjgdrvBWjqqniU6C30PzEUsHbwgpWcZr+Fpd2ADMwx6ZbtZPUYVxHnfbLeJ9 rXKQUjixe1tx/lOcs+9SU5bgtI9JcSUg8EcKKyvE8uX6hlk1iXT7+Rf74MbEuWtqbk5A L5ig== 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=ZUfTPzvJqk9V3tNqjRUuHziRVNc5zoq+eOVVz3g0zMQ=; b=0+kxNYdCR0AUFsx7gBAnPVkURc3YynI0D7YwGe6meDDeiIDbQqPEOeTnrhd81SgnHL i7siGJw7/N8Tj66IzBbJD8GTTHs/ETOFGPuf36WNUH8G0Yavi4SiYEP8x1G5Y0y3x9Yv N2veNAI/kpqEjRp3VaSLHAFdNTKVgfEBOa6gHHPafFrnyYkpqmuzQ28V1NMqWxxuYhyx Xv+DeUdTlGBEhbMdEnHj1MXCkDozBGiTeb4AxR7tpLp2z0kPMGKDU704oliTjXLng6g8 4/kqCPrpfQcoNDwlsj0SoQ4SV/dHi9FbkO0I77Lh08Jppp2/YNw9Ja0QorzAGIHiS/0N bUrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=EEYoz0sP; 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 ml21-20020a170906cc1500b007ae545e330csi2725057ejb.218.2022.11.25.08.47.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 08:47:29 -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=EEYoz0sP; 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 DEF14384E38F for ; Fri, 25 Nov 2022 16:47:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEF14384E38F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669394846; bh=ZUfTPzvJqk9V3tNqjRUuHziRVNc5zoq+eOVVz3g0zMQ=; 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=EEYoz0sPN7A6c8Esel5PopDhIenNPOuZRi7LC4AHaJekm4NbMPJVrK8bttYwQpF/X MVgMRUziDH7MNnZz1Bw92G8a8h8EWoNkjcAx98smzpf3H3Zhw6TkVh0U5ZVwbtyOaj JsKgvDZ324zj6ay0ZNkTdYORSz5hue1MkH3XBDGs= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id DB438384EF7A for ; Fri, 25 Nov 2022 16:47:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DB438384EF7A Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 1923F1FD89 for ; Fri, 25 Nov 2022 16:47:17 +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 1450B2C141 for ; Fri, 25 Nov 2022 16:47:17 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id 0F1756586; Fri, 25 Nov 2022 16:47:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id 0D6FB6238 for ; Fri, 25 Nov 2022 16:47:17 +0000 (UTC) Date: Fri, 25 Nov 2022 16:47:17 +0000 (UTC) To: binutils@sourceware.org Subject: [PATCH 3/8] section-select: Implement a prefix-tree 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=-7.7 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_STATUS, 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?1750487373304482872?= X-GMAIL-MSGID: =?utf-8?q?1750487373304482872?= Now that we have a list of potentially matching sections per wild statement we can actually pre-fill that one by going once over all input sections and match their names against a prefix-tree that points to the potentially matching wild statements. So instead of looking at all sections names for each glob for each wild statement we now look at the sections only once and then only check against those globs that have a possibility of a match at all (usually only one or two). This pushes the whole section selection off the profiles. --- ld/ldlang.c | 362 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 353 insertions(+), 9 deletions(-) diff --git a/ld/ldlang.c b/ld/ldlang.c index 1e4f3a5ee05..06fa541df3a 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -59,6 +59,7 @@ /* Local variables. */ static struct obstack stat_obstack; static struct obstack map_obstack; +static struct obstack pt_obstack; #define obstack_chunk_alloc xmalloc #define obstack_chunk_free free @@ -210,6 +211,9 @@ name_match (const char *pattern, const char *name) return strcmp (pattern, name); } +/* Given an analyzed wildcard_spec SPEC, match it against NAME, + returns zero on a match, non-zero if there's no match. */ + static int spec_match (const struct wildcard_spec *spec, const char *name) { @@ -383,6 +387,63 @@ walk_wild_consider_section (lang_wild_statement_type *ptr, (*callback) (ptr, sec, s, file, data); } +static void +walk_wild_section_match (lang_wild_statement_type *ptr, + lang_input_statement_type *file, + asection *s, + callback_t callback, + void *data) +{ + struct wildcard_list *sec; + const char *file_spec = ptr->filename; + char *p; + + /* Check if filenames match. */ + if (file_spec == NULL) + ; + else if ((p = archive_path (file_spec)) != NULL) + { + if (!input_statement_is_archive_path (file_spec, p, file)) + return; + } + else if (wildcardp (file_spec)) + { + if (fnmatch (file_spec, file->filename, 0) != 0) + return; + } + else + { + lang_input_statement_type *f; + /* Perform the iteration over a single file. */ + f = lookup_name (file_spec); + if (f != file) + return; + } + + /* Check section name against each wildcard spec. If there's no + wildcard all sections match. */ + sec = ptr->section_list; + if (sec == NULL) + (*callback) (ptr, sec, s, file, data); + + while (sec != NULL) + { + bool skip = false; + + if (sec->spec.name != NULL) + { + const char *sname = bfd_section_name (s); + + skip = spec_match (&sec->spec, sname) != 0; + } + + if (!skip) + walk_wild_consider_section (ptr, file, s, sec, callback, data); + + sec = sec->next; + } +} + /* Lowest common denominator routine that can handle everything correctly, but slowly. */ @@ -922,6 +983,159 @@ wild_spec_can_overlap (const char *name1, const char *name2) return memcmp (name1, name2, min_prefix_len) == 0; } + +/* Sections are matched against wildcard statements via a prefix tree. + The prefix tree holds prefixes of all matching patterns (up to the first + wildcard character), and the wild statement from which those patterns + came. When matching a section name against the tree we're walking through + the tree character by character. Each statement we hit is one that + potentially matches. This is checked by actually going through the + (glob) matching routines. + + When the section name turns out to actually match we record that section + in the wild statements list of matching sections. */ + +/* A prefix can be matched by multiple statement, so we need a list of them. */ +struct wild_stmt_list +{ + lang_wild_statement_type *stmt; + struct wild_stmt_list *next; +}; + +/* The prefix tree itself. */ +struct prefixtree +{ + /* The list of all children (linked via .next). */ + struct prefixtree *child; + struct prefixtree *next; + /* This tree node is responsible for the prefix of parent plus 'c'. */ + char c; + /* The statements that potentially can match this prefix. */ + struct wild_stmt_list *stmt; +}; + +/* We always have a root node in the prefix tree. It corresponds to the + empty prefix. E.g. a glob like "*" would sit in this root. */ +static struct prefixtree the_root, *ptroot = &the_root; + +/* Given a prefix tree in *TREE, corresponding to prefix P, find or + INSERT the tree node corresponding to prefix P+C. */ + +static struct prefixtree * +get_prefix_tree (struct prefixtree **tree, char c, bool insert) +{ + struct prefixtree *t; + for (t = *tree; t; t = t->next) + if (t->c == c) + return t; + if (!insert) + return NULL; + t = (struct prefixtree *) obstack_alloc (&pt_obstack, sizeof *t); + t->child = NULL; + t->next = *tree; + t->c = c; + t->stmt = NULL; + *tree = t; + return t; +} + +/* Add STMT to the set of statements that can be matched by the prefix + corresponding to prefix tree T. */ + +static void +pt_add_stmt (struct prefixtree *t, lang_wild_statement_type *stmt) +{ + struct wild_stmt_list *sl, **psl; + sl = (struct wild_stmt_list *) obstack_alloc (&pt_obstack, sizeof *sl); + sl->stmt = stmt; + sl->next = NULL; + psl = &t->stmt; + while (*psl) + psl = &(*psl)->next; + *psl = sl; +} + +/* Insert STMT into the global prefix tree. */ + +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; + + if (!stmt->section_list) + { + /* If we have no section_list (no wildcards in the wild STMT), + then every section name will match, so add this to the root. */ + pt_add_stmt (ptroot, stmt); + return; + } + + for (sec = stmt->section_list; sec; sec = sec->next) + { + const char *name = sec->spec.name ? sec->spec.name : ""; + char c; + pt = &ptroot; + t = ptroot; + for (; (c = *name); name++) + { + if (c == '*' || c == '[' || c == '?') + break; + t = get_prefix_tree (&t->child, c, true); + } + /* If we hit a glob character, the matching prefix is what we saw + until now. If we hit the end of pattern (hence it's no glob) then + we can do better: we only need to record a match when a section name + completely matches, not merely a prefix, so record the trailing 0 + 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; + } +} + +/* Dump T indented by INDENT spaces. */ + +static void +debug_prefix_tree_rec (struct prefixtree *t, int indent) +{ + for (; t; t = t->next) + { + struct wild_stmt_list *sl; + printf ("%*s %c", indent, "", t->c); + for (sl = t->stmt; sl; sl = sl->next) + { + struct wildcard_list *curr; + printf (" %p ", sl->stmt); + for (curr = sl->stmt->section_list; curr; curr = curr->next) + printf ("%s ", curr->spec.name ? curr->spec.name : "*"); + } + printf ("\n"); + debug_prefix_tree_rec (t->child, indent + 2); + } +} + +/* Dump the global prefix tree. */ + +static void +debug_prefix_tree (void) +{ + debug_prefix_tree_rec (ptroot, 2); +} + +/* Like strcspn() but start to look from the end to beginning of + S. Returns the length of the suffix of S consisting entirely + of characters not in REJECT. */ + static size_t rstrcspn (const char *s, const char *reject) { @@ -936,8 +1150,8 @@ rstrcspn (const char *s, const char *reject) return sufflen; } -/* Select specialized code to handle various kinds of wildcard - statements. */ +/* Analyze the wildcards in wild statement PTR to setup various + things for quick matching. */ static void analyze_walk_wild_section_handler (lang_wild_statement_type *ptr) @@ -969,6 +1183,8 @@ analyze_walk_wild_section_handler (lang_wild_statement_type *ptr) sec->spec.namelen = sec->spec.prefixlen = sec->spec.suffixlen = 0; } + insert_prefix_tree (ptr); + /* Count how many wildcard_specs there are, and how many of those actually use wildcards in the name. Also, bail out if any of the wildcard names are NULL. (Can this actually happen? @@ -1077,6 +1293,9 @@ walk_wild_file (lang_wild_statement_type *s, } } +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, @@ -1088,12 +1307,119 @@ add_matching_callback (lang_wild_statement_type *ptr, lang_input_statement_type *file, void *data ATTRIBUTE_UNUSED) { - 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; + 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. */ + +static void +resolve_wild_sections (lang_input_statement_type *file) +{ + asection *s; + + if (file->flags.just_syms) + return; + + 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; + 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); + //printf (" ZZZ maybe place into %p\n", sl->stmt); + } + } + 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); + } + } + } +} + +/* Match all sections from all input files against the global prefix tree. */ + +static void +resolve_wilds (void) +{ + check_resolve = false; + LANG_FOR_EACH_INPUT_STATEMENT (f) + { + //printf("XXX %s\n", f->filename); + /* XXX if (walk_wild_file_in_exclude_list (s->exclude_name_list, f)) + return;*/ + + if (f->the_bfd == NULL + || !bfd_check_format (f->the_bfd, bfd_archive)) + resolve_wild_sections (f); + else + { + bfd *member; + + /* This is an archive file. We must map each member of the + archive separately. */ + member = bfd_openr_next_archived_file (f->the_bfd, NULL); + while (member != NULL) + { + /* When lookup_name is called, it will call the add_symbols + entry point for the archive. For each element of the + archive which is included, BFD will call ldlang_add_file, + which will set the usrdata field of the member to the + lang_input_statement. */ + if (bfd_usrdata (member) != NULL) + resolve_wild_sections (bfd_usrdata (member)); + + member = bfd_openr_next_archived_file (f->the_bfd, member); + } + } + } + old_max_section_id = bfd_get_max_section_id (); + check_resolve = true; } static void @@ -1138,6 +1464,9 @@ walk_wild_resolve (lang_wild_statement_type *s) } } +/* For each input section that matches wild statement S calls + CALLBACK with DATA. */ + static void walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) { @@ -1149,7 +1478,7 @@ 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", file_spec ? file_spec : ""); - walk_wild_resolve (s); + //walk_wild_resolve (s); s->resolved = true; s->max_section_id = bfd_get_max_section_id (); } @@ -1505,6 +1834,7 @@ void lang_init (void) { obstack_begin (&stat_obstack, 1000); + obstack_init (&pt_obstack); stat_ptr = &statement_list; @@ -8273,6 +8603,11 @@ lang_process (void) /* Size up the common data. */ lang_common (); + if (0) + debug_prefix_tree (); + + resolve_wilds (); + /* Remove unreferenced sections if asked to. */ lang_gc_sections (); @@ -8283,6 +8618,8 @@ lang_process (void) ldemul_after_check_relocs (); + resolve_wilds (); + /* Update wild statements in case the user gave --sort-section. Note how the option might have come after the linker script and so couldn't have been set when the wild statements were created. */ @@ -8440,6 +8777,13 @@ lang_add_wild (struct wildcard_spec *filespec, new_stmt->max_section_id = 0; lang_list_init (&new_stmt->matching_sections); analyze_walk_wild_section_handler (new_stmt); + if (0) + { + printf ("wild %s(", new_stmt->filename ? new_stmt->filename : "*"); + for (curr = new_stmt->section_list; curr; curr = curr->next) + printf ("%s ", curr->spec.name ? curr->spec.name : "*"); + printf (")\n"); + } } void From patchwork Fri Nov 25 16:55:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 26097 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4157484wrr; Fri, 25 Nov 2022 08:55:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf4et68Xg6Wst9JpcKuaFfIpwO/IjATeRlb0l5xIq8yTHh+niBOskg9c8asYvBwTtYpr71dS X-Received: by 2002:a17:906:2bcb:b0:7b8:4d91:1bcd with SMTP id n11-20020a1709062bcb00b007b84d911bcdmr15878778ejg.239.1669395322861; Fri, 25 Nov 2022 08:55:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669395322; cv=none; d=google.com; s=arc-20160816; b=0ruJZAKhvrsFfJ6lKZxTQMq324yvGczTjc+s70WPrDs2w8y8wi1yCnsgceAQlvTHqX w/QvjAc1N4p7kGTKVUHZFYBnuWLIPaqxxrV52pX2cYUtECsccflubi48qPFgW//pmllV aKmwFpMvnfUS1Px4mRxPkp/chBzkrxqfCNMPlLIM2po6UaTQtwPVPugB0xsQtFXW9LbN 6n0FGud9oDHzomk9rFsvpyoe0SNAiambB3FGvzAASBTadL0Tn5acINHOIkIHxoTg+AT+ Q7YT5BegN14zKfjGrq/0g3zsx0JTXTaxoet3QJWGInPwli95rR7AiiUHBJOey0Sx6QQK tG1Q== 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=xFJh0O9VxpfvrG0/IvBjN58otNH2icAML1kwD8xTug4=; b=lbvHrmj9pkdRUk5L5JGiRZCo+pEcwQcRdNl5HZ9jBy5XWpSHPiP6rab1u4MD2UGpzk P1FeiovLICA8JvP+Nt/bxYK+oFXU2ovKIUsPHO0gC0JbECpZnEk1HCPJHr5hTDbXTj19 R3lUyMXeSIvP6emBZ/sMfoYGh729NFtQc5N2YgPYgCKm6yxBAw5tMnBE8gPwEZezmY1o m8MXc7NUObaIfZFtHM+in2zgPoer3+hFa9jzUZi91ogCBkOXJcbPPF5ncP6jOnGWcpTZ xhFG0dDq/Zk93zKADrFq8GWWY9e5nMlWAcGrZItC2+9WX/+R5LyafuVvkrPGB5v0H3rc pUIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=m6KDGt9N; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hb17-20020a170907161100b00773db392e1esi4365281ejc.997.2022.11.25.08.55.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 08:55:22 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=m6KDGt9N; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 D87DF384E3A1 for ; Fri, 25 Nov 2022 16:55:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D87DF384E3A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669395321; bh=xFJh0O9VxpfvrG0/IvBjN58otNH2icAML1kwD8xTug4=; 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=m6KDGt9NoUjzeAhQeG2Gqjdxy3O+gCFlMqunPoP64+xCPeXRdxtr4F9zm5vLY9030 0PsagLAH4ug0WMbwLi+3U3zbppO45ttFLtD6aMGfaggO5HDWGbs2lqQxwa8dVmAZna 3/3/jBxVK33XUWdzU9lBhdCUKKpIlqEK0VKKHDaU= 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 8BFFE384EF7E for ; Fri, 25 Nov 2022 16:55:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8BFFE384EF7E Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id C770A1FD86 for ; Fri, 25 Nov 2022 16:55:12 +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 C2D432C141 for ; Fri, 25 Nov 2022 16:55:12 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id B9B886586; Fri, 25 Nov 2022 16:55:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id B85F76238 for ; Fri, 25 Nov 2022 16:55:12 +0000 (UTC) Date: Fri, 25 Nov 2022 16:55:12 +0000 (UTC) To: binutils@sourceware.org Subject: [PATCH 4/8] section-select: Completely rebuild matches 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?1750487870061114099?= X-GMAIL-MSGID: =?utf-8?q?1750487870061114099?= this resets all section matches before updating for newly created sections (i.e. completely rebuilds the matches). This fixes powerpc "TOC opt" tests that shows a difference in section order: originally .got of "linker stubs" comes before .toc (both placed into the same .got output section due to ".got {*(.got .toc)}". But .got of linker stubs is created later, and in the second run of resolve_wilds is appended to the list, hence is then coming after .toc (which was added already in the earlier resolve_wilds run). So order swapped -> test fails. The result would still work, and it's unclear if the documented meaning of multiple section selectors applies to lazily generated sections like here as well. For now lets reinstate old behaviour and simply always completely rebuild the matching sections. (Note: the reset lists aren't freed or reused) --- Alan: can you please take a look at the problem mentioned above? Without this patch the "TOC opt" tests fails on powerpc because two sections are swapped. But it's not quite clear if lazily added sections (.got of "linker stubs") are also bound to the documented behaviour of multiple globs in a single wild statement. The result with the changed section order would continue to work, and if we could decide that that's okay the section resolution wouldn't have to rebuild stuff from scratch, roughly halving the time for it. In that case I wouldn't patch 7/8 to remove the libbfd interface to get the max section id and instead use it for early outs. Sections that are generated late and lazy would then always be appended to their matching wild statement. Ciao, Michael. ld/ldlang.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ld/ldlang.c b/ld/ldlang.c index 06fa541df3a..57432700a18 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -8400,6 +8400,26 @@ lang_propagate_lma_regions (void) } } +static void +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); + } +} + +static void +reset_resolved_wilds (void) +{ + lang_for_each_statement (reset_one_wild); + old_max_section_id = 0; +} + void lang_process (void) { @@ -8618,6 +8638,7 @@ lang_process (void) ldemul_after_check_relocs (); + reset_resolved_wilds (); resolve_wilds (); /* Update wild statements in case the user gave --sort-section. From patchwork Fri Nov 25 16:55:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 26098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4157707wrr; Fri, 25 Nov 2022 08:55:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf5SEtifYhwK53YU0F71k856Afm2WENtG4YlPbBq9WPOSuAsllMyv8DmJf+TanBqGVLxOvE6 X-Received: by 2002:a17:906:704:b0:7a1:b555:6f1 with SMTP id y4-20020a170906070400b007a1b55506f1mr34324821ejb.29.1669395350991; Fri, 25 Nov 2022 08:55:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669395350; cv=none; d=google.com; s=arc-20160816; b=ED/8tMnd1XDMjoMyLgslbVXNcSli0TSiM4T06vL63FY/4FewfBjD6YzCzPmZWHMRnY fLtdojvFVsFy7UOoHvnheODVCWELcW49ix2bgUso/i207advqggnC1bTTGZNfYUFFAm+ K8oEnpBylYbD80osaAqFvWpqszmKhP5DMG3XBMNxpthpJTgIzhMp3TL6Kk63eHKxm5Xt YFeWi+T0LBshtN/21/WqbCAt1bCZevMQOviu3nEhKlsDhZvFCEgUIESCTKr2mB5csMvr T3Cg3vhI0XDsrH9DnoSlMBoR2Ky5nIbK1WxSiJfxIT/7T9kjcbwQOYe31Vb7EfBD/nn5 C5Nw== 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=QFytt3/ASppnw0ccqQAVXnMRyOtI4JO5VrYU6/ZNWAA=; b=eX6mIHedLiOStg7JWkqDJAbgEjGxf7npBDSQZV3TckDp/XgBVg1T/V5Cew7DKbPZi2 z3OqvtihCd6B6bWA7x+oSDAoT6GhXAs8jPFHjaXrkWEt1Yd98tBcmCOVXonRTwrLQ0nc ocXkkPD1ul5PRk9acJuIm03dAulgAyqJbt1Lbp7Huzc0h3LCWFq+5dPxGoqtJ2c1YlZf NaOXiIsfiz45BSm27AbXJ0yncSznSmHNupNsUopiEg0yqmTz9Jdkia13ArE0fVHsSBEk 6ton0tMiRBgdTuc+HWzYPYa6rWfvBXimBlhZuSrOqtpRrSBwpqgluN2hfOk5IvcDbpgs CT6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=RtuZUGPj; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v22-20020a056402349600b00462e5235356si4597838edc.619.2022.11.25.08.55.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 08:55:50 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=RtuZUGPj; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 C2E5D384E391 for ; Fri, 25 Nov 2022 16:55:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2E5D384E391 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669395349; bh=QFytt3/ASppnw0ccqQAVXnMRyOtI4JO5VrYU6/ZNWAA=; 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=RtuZUGPjUwCV6712cYB5F5o2Z/0TmL1GxHWOnHExeNL2mzAojit8oaPNaIPgAUn+Q LgLZJFNrXqFOkMQyXw7AK0jlUNszo3Z2ApMolnwLSO6AxkDiZ6bA3q7uWebB0cSITi 6zAHqWpNP4aE7NmeMPwkSYdkTx4IvzkAunuWFuoo= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id C0457384E394 for ; Fri, 25 Nov 2022 16:55:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C0457384E394 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 0505021B0E for ; Fri, 25 Nov 2022 16:55:37 +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 F307C2C141 for ; Fri, 25 Nov 2022 16:55:36 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id ECE526586; Fri, 25 Nov 2022 16:55:36 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id EB6306238 for ; Fri, 25 Nov 2022 16:55:36 +0000 (UTC) Date: Fri, 25 Nov 2022 16:55:36 +0000 (UTC) To: binutils@sourceware.org Subject: [PATCH 5/8] section-select: Remove unused code 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=-7.7 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_STATUS, 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?1750487899082356803?= X-GMAIL-MSGID: =?utf-8?q?1750487899082356803?= walk_wild_file, hence walk_wild_section and walk_wild_section_handler aren't called with the prefix tree. Hence initialization of the latter and all potential special cases for it aren't used anymore. That also removes the need to handler_data[] and some associated helper functions. So, remove all of that. --- ld/ldlang.c | 506 +--------------------------------------------------- ld/ldlang.h | 2 - 2 files changed, 5 insertions(+), 503 deletions(-) diff --git a/ld/ldlang.c b/ld/ldlang.c index 57432700a18..3748bf9bec9 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -444,83 +444,6 @@ walk_wild_section_match (lang_wild_statement_type *ptr, } } -/* Lowest common denominator routine that can handle everything correctly, - but slowly. */ - -static void -walk_wild_section_general (lang_wild_statement_type *ptr, - lang_input_statement_type *file, - callback_t callback, - void *data) -{ - asection *s; - struct wildcard_list *sec; - - for (s = file->the_bfd->sections; s != NULL; s = s->next) - { - if (s->id < ptr->max_section_id) - continue; - //printf ("YYY checking %s:%s\n", s->owner->filename, s->name); - sec = ptr->section_list; - if (sec == NULL) - (*callback) (ptr, sec, s, file, data); - - while (sec != NULL) - { - bool skip = false; - - if (sec->spec.name != NULL) - { - const char *sname = bfd_section_name (s); - - skip = spec_match (&sec->spec, sname) != 0; - } - - if (!skip) - walk_wild_consider_section (ptr, file, s, sec, callback, data); - - sec = sec->next; - } - } -} - -/* Routines to find a single section given its name. If there's more - than one section with that name, we report that. */ - -typedef struct -{ - asection *found_section; - bool multiple_sections_found; -} section_iterator_callback_data; - -static bool -section_iterator_callback (bfd *abfd ATTRIBUTE_UNUSED, asection *s, void *data) -{ - section_iterator_callback_data *d = (section_iterator_callback_data *) data; - - if (d->found_section != NULL) - { - d->multiple_sections_found = true; - return true; - } - - d->found_section = s; - return false; -} - -static asection * -find_section (lang_input_statement_type *file, - struct wildcard_list *sec, - bool *multiple_sections_found) -{ - section_iterator_callback_data cb_data = { NULL, false }; - - bfd_get_section_by_name_if (file->the_bfd, sec->spec.name, - section_iterator_callback, &cb_data); - *multiple_sections_found = cb_data.multiple_sections_found; - return cb_data.found_section; -} - /* Return the numerical value of the init_priority attribute from section name NAME. */ @@ -768,221 +691,6 @@ output_section_callback_tree_to_list (lang_wild_statement_type *ptr, free (tree); } -/* Specialized, optimized routines for handling different kinds of - wildcards */ - -static void -walk_wild_section_specs1_wild0 (lang_wild_statement_type *ptr, - lang_input_statement_type *file, - callback_t callback, - void *data) -{ - /* We can just do a hash lookup for the section with the right name. - But if that lookup discovers more than one section with the name - (should be rare), we fall back to the general algorithm because - we would otherwise have to sort the sections to make sure they - get processed in the bfd's order. */ - bool multiple_sections_found; - struct wildcard_list *sec0 = ptr->handler_data[0]; - asection *s0 = find_section (file, sec0, &multiple_sections_found); - - if (multiple_sections_found) - walk_wild_section_general (ptr, file, callback, data); - else if (s0) - walk_wild_consider_section (ptr, file, s0, sec0, callback, data); -} - -static void -walk_wild_section_specs1_wild1 (lang_wild_statement_type *ptr, - lang_input_statement_type *file, - callback_t callback, - void *data) -{ - asection *s; - struct wildcard_list *wildsec0 = ptr->handler_data[0]; - - for (s = file->the_bfd->sections; s != NULL; s = s->next) - { - const char *sname = bfd_section_name (s); - bool skip = !match_simple_wild (wildsec0->spec.name, sname); - //bool skip = !!spec_match (&wildsec0->spec, sname); - - if (!skip) - walk_wild_consider_section (ptr, file, s, wildsec0, callback, data); - } -} - -static void -walk_wild_section_specs2_wild1 (lang_wild_statement_type *ptr, - lang_input_statement_type *file, - callback_t callback, - void *data) -{ - asection *s; - struct wildcard_list *sec0 = ptr->handler_data[0]; - struct wildcard_list *wildsec1 = ptr->handler_data[1]; - bool multiple_sections_found; - asection *s0 = find_section (file, sec0, &multiple_sections_found); - - if (multiple_sections_found) - { - walk_wild_section_general (ptr, file, callback, data); - return; - } - - /* Note that if the section was not found, s0 is NULL and - we'll simply never succeed the s == s0 test below. */ - for (s = file->the_bfd->sections; s != NULL; s = s->next) - { - /* Recall that in this code path, a section cannot satisfy more - than one spec, so if s == s0 then it cannot match - wildspec1. */ - if (s == s0) - walk_wild_consider_section (ptr, file, s, sec0, callback, data); - else - { - const char *sname = bfd_section_name (s); - bool skip = !match_simple_wild (wildsec1->spec.name, sname); - //bool skip = !!spec_match (&wildsec1->spec, sname); - - if (!skip) - walk_wild_consider_section (ptr, file, s, wildsec1, callback, - data); - } - } -} - -static void -walk_wild_section_specs3_wild2 (lang_wild_statement_type *ptr, - lang_input_statement_type *file, - callback_t callback, - void *data) -{ - asection *s; - struct wildcard_list *sec0 = ptr->handler_data[0]; - struct wildcard_list *wildsec1 = ptr->handler_data[1]; - struct wildcard_list *wildsec2 = ptr->handler_data[2]; - bool multiple_sections_found; - asection *s0 = find_section (file, sec0, &multiple_sections_found); - - if (multiple_sections_found) - { - walk_wild_section_general (ptr, file, callback, data); - return; - } - - for (s = file->the_bfd->sections; s != NULL; s = s->next) - { - if (s == s0) - walk_wild_consider_section (ptr, file, s, sec0, callback, data); - else - { - const char *sname = bfd_section_name (s); - bool skip = !match_simple_wild (wildsec1->spec.name, sname); - - if (!skip) - walk_wild_consider_section (ptr, file, s, wildsec1, callback, data); - else - { - skip = !match_simple_wild (wildsec2->spec.name, sname); - if (!skip) - walk_wild_consider_section (ptr, file, s, wildsec2, callback, - data); - } - } - } -} - -static void -walk_wild_section_specs4_wild2 (lang_wild_statement_type *ptr, - lang_input_statement_type *file, - callback_t callback, - void *data) -{ - asection *s; - struct wildcard_list *sec0 = ptr->handler_data[0]; - struct wildcard_list *sec1 = ptr->handler_data[1]; - struct wildcard_list *wildsec2 = ptr->handler_data[2]; - struct wildcard_list *wildsec3 = ptr->handler_data[3]; - bool multiple_sections_found; - asection *s0 = find_section (file, sec0, &multiple_sections_found), *s1; - - if (multiple_sections_found) - { - walk_wild_section_general (ptr, file, callback, data); - return; - } - - s1 = find_section (file, sec1, &multiple_sections_found); - if (multiple_sections_found) - { - walk_wild_section_general (ptr, file, callback, data); - return; - } - - for (s = file->the_bfd->sections; s != NULL; s = s->next) - { - if (s == s0) - walk_wild_consider_section (ptr, file, s, sec0, callback, data); - else - if (s == s1) - walk_wild_consider_section (ptr, file, s, sec1, callback, data); - else - { - const char *sname = bfd_section_name (s); - bool skip = !match_simple_wild (wildsec2->spec.name, sname); - - if (!skip) - walk_wild_consider_section (ptr, file, s, wildsec2, callback, - data); - else - { - skip = !match_simple_wild (wildsec3->spec.name, sname); - if (!skip) - walk_wild_consider_section (ptr, file, s, wildsec3, - callback, data); - } - } - } -} - -static void -walk_wild_section (lang_wild_statement_type *ptr, - lang_input_statement_type *file, - callback_t callback, - void *data) -{ - if (file->flags.just_syms) - return; - - (*ptr->walk_wild_section_handler) (ptr, file, callback, data); -} - -/* Returns TRUE when name1 is a wildcard spec that might match - something name2 can match. We're conservative: we return FALSE - only if the prefixes of name1 and name2 are different up to the - first wildcard character. */ - -static bool -wild_spec_can_overlap (const char *name1, const char *name2) -{ - size_t prefix1_len = strcspn (name1, "?*["); - size_t prefix2_len = strcspn (name2, "?*["); - size_t min_prefix_len; - - /* Note that if there is no wildcard character, then we treat the - terminating 0 as part of the prefix. Thus ".text" won't match - ".text." or ".text.*", for example. */ - if (name1[prefix1_len] == '\0') - prefix1_len++; - if (name2[prefix2_len] == '\0') - prefix2_len++; - - min_prefix_len = prefix1_len < prefix2_len ? prefix1_len : prefix2_len; - - return memcmp (name1, name2, min_prefix_len) == 0; -} - /* Sections are matched against wildcard statements via a prefix tree. The prefix tree holds prefixes of all matching patterns (up to the first @@ -1156,17 +864,8 @@ rstrcspn (const char *s, const char *reject) static void analyze_walk_wild_section_handler (lang_wild_statement_type *ptr) { - int sec_count = 0; - int wild_name_count = 0; struct wildcard_list *sec; - int signature; - int data_counter; - - ptr->walk_wild_section_handler = walk_wild_section_general; - ptr->handler_data[0] = NULL; - ptr->handler_data[1] = NULL; - ptr->handler_data[2] = NULL; - ptr->handler_data[3] = NULL; + ptr->tree = NULL; ptr->rightmost = &ptr->tree; @@ -1184,113 +883,6 @@ analyze_walk_wild_section_handler (lang_wild_statement_type *ptr) } insert_prefix_tree (ptr); - - /* Count how many wildcard_specs there are, and how many of those - actually use wildcards in the name. Also, bail out if any of the - wildcard names are NULL. (Can this actually happen? - walk_wild_section used to test for it.) And bail out if any - of the wildcards are more complex than a simple string - ending in a single '*'. */ - for (sec = ptr->section_list; sec != NULL; sec = sec->next) - { - ++sec_count; - if (sec->spec.name == NULL) - return; - if (wildcardp (sec->spec.name)) - { - ++wild_name_count; - if (!is_simple_wild (sec->spec.name)) - return; - } - } - - /* The zero-spec case would be easy to optimize but it doesn't - happen in practice. Likewise, more than 4 specs doesn't - happen in practice. */ - if (sec_count == 0 || sec_count > 4) - return; - - /* Check that no two specs can match the same section. */ - for (sec = ptr->section_list; sec != NULL; sec = sec->next) - { - struct wildcard_list *sec2; - for (sec2 = sec->next; sec2 != NULL; sec2 = sec2->next) - { - if (wild_spec_can_overlap (sec->spec.name, sec2->spec.name)) - return; - } - } - - signature = (sec_count << 8) + wild_name_count; - switch (signature) - { - case 0x0100: - ptr->walk_wild_section_handler = walk_wild_section_specs1_wild0; - break; - case 0x0101: - ptr->walk_wild_section_handler = walk_wild_section_specs1_wild1; - break; - case 0x0201: - ptr->walk_wild_section_handler = walk_wild_section_specs2_wild1; - break; - case 0x0302: - ptr->walk_wild_section_handler = walk_wild_section_specs3_wild2; - break; - case 0x0402: - ptr->walk_wild_section_handler = walk_wild_section_specs4_wild2; - break; - default: - return; - } - - /* Now fill the data array with pointers to the specs, first the - specs with non-wildcard names, then the specs with wildcard - names. It's OK to process the specs in different order from the - given order, because we've already determined that no section - will match more than one spec. */ - data_counter = 0; - for (sec = ptr->section_list; sec != NULL; sec = sec->next) - if (!wildcardp (sec->spec.name)) - ptr->handler_data[data_counter++] = sec; - for (sec = ptr->section_list; sec != NULL; sec = sec->next) - if (wildcardp (sec->spec.name)) - ptr->handler_data[data_counter++] = sec; -} - -/* Handle a wild statement for a single file F. */ - -static void -walk_wild_file (lang_wild_statement_type *s, - lang_input_statement_type *f, - callback_t callback, - void *data) -{ - if (walk_wild_file_in_exclude_list (s->exclude_name_list, f)) - return; - - if (f->the_bfd == NULL - || !bfd_check_format (f->the_bfd, bfd_archive)) - walk_wild_section (s, f, callback, data); - else - { - bfd *member; - - /* This is an archive file. We must map each member of the - archive separately. */ - member = bfd_openr_next_archived_file (f->the_bfd, NULL); - while (member != NULL) - { - /* When lookup_name is called, it will call the add_symbols - entry point for the archive. For each element of the - archive which is included, BFD will call ldlang_add_file, - which will set the usrdata field of the member to the - lang_input_statement. */ - if (bfd_usrdata (member) != NULL) - walk_wild_section (s, bfd_usrdata (member), callback, data); - - member = bfd_openr_next_archived_file (f->the_bfd, member); - } - } } static bool check_resolve = false; @@ -1422,113 +1014,25 @@ resolve_wilds (void) check_resolve = true; } -static void -walk_wild_resolve (lang_wild_statement_type *s) -{ - const char *file_spec = s->filename; - char *p; - - if (file_spec == NULL) - { - /* Perform the iteration over all files in the list. */ - LANG_FOR_EACH_INPUT_STATEMENT (f) - { - //printf("XXX %s\n", f->filename); - walk_wild_file (s, f, add_matching_callback, NULL); - } - } - else if ((p = archive_path (file_spec)) != NULL) - { - LANG_FOR_EACH_INPUT_STATEMENT (f) - { - if (input_statement_is_archive_path (file_spec, p, f)) - walk_wild_file (s, f, add_matching_callback, NULL); - } - } - else if (wildcardp (file_spec)) - { - LANG_FOR_EACH_INPUT_STATEMENT (f) - { - if (fnmatch (file_spec, f->filename, 0) == 0) - walk_wild_file (s, f, add_matching_callback, NULL); - } - } - else - { - lang_input_statement_type *f; - - /* Perform the iteration over a single file. */ - f = lookup_name (file_spec); - if (f) - walk_wild_file (s, f, add_matching_callback, NULL); - } -} - /* For each input section that matches wild statement S calls CALLBACK with DATA. */ static void walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) { - const char *file_spec = s->filename; - //char *p; + lang_statement_union_type *l; -#if 1 - //if (!s->resolved) if (s->max_section_id < bfd_get_max_section_id ()) { - //printf("XXX %s\n", file_spec ? file_spec : ""); - //walk_wild_resolve (s); + //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) { - lang_statement_union_type *l; - 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); - } - return; - } -#endif - -#if 0 - if (file_spec == NULL) - { - /* Perform the iteration over all files in the list. */ - LANG_FOR_EACH_INPUT_STATEMENT (f) - { - printf("XXX %s\n", f->filename); - walk_wild_file (s, f, callback, data); - } - } - else if ((p = archive_path (file_spec)) != NULL) - { - LANG_FOR_EACH_INPUT_STATEMENT (f) - { - if (input_statement_is_archive_path (file_spec, p, f)) - walk_wild_file (s, f, callback, data); - } - } - else if (wildcardp (file_spec)) - { - LANG_FOR_EACH_INPUT_STATEMENT (f) - { - if (fnmatch (file_spec, f->filename, 0) == 0) - walk_wild_file (s, f, callback, data); - } + (*callback) (s, l->input_matcher.pattern, l->input_matcher.section, l->input_matcher.input_stmt, data); } - else - { - lang_input_statement_type *f; - - /* Perform the iteration over a single file. */ - f = lookup_name (file_spec); - if (f) - walk_wild_file (s, f, callback, data); - } -#endif } /* lang_for_each_statement walks the parse tree and calls the provided diff --git a/ld/ldlang.h b/ld/ldlang.h index 8566e022a57..09c43611a22 100644 --- a/ld/ldlang.h +++ b/ld/ldlang.h @@ -402,8 +402,6 @@ struct lang_wild_statement_struct bool resolved; unsigned int max_section_id; - walk_wild_section_handler_t walk_wild_section_handler; - struct wildcard_list *handler_data[4]; lang_section_bst_type *tree, **rightmost; struct flag_info *section_flag_list; }; 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; From patchwork Fri Nov 25 16:57:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 26100 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4158590wrr; Fri, 25 Nov 2022 08:57:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Zki6XIEhqoPMb/VYgHnDTjWdZgZRS7lCo6/EkmFrq7NYy2GFX/IzwGVHJQpTXIiypeL3X X-Received: by 2002:a17:907:cc9c:b0:7bb:8de1:5139 with SMTP id up28-20020a170907cc9c00b007bb8de15139mr6990631ejc.55.1669395473655; Fri, 25 Nov 2022 08:57:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669395473; cv=none; d=google.com; s=arc-20160816; b=lVWx3lsiA70df9JG1VRGgCL5iGvq/ZieD/0eLJjwR0Et7XZwmI25ZB81yV1v3ikaOF qSPJhEydu4WBcnH4C6Gckp851yCp37kK+IhrgKkR5T+qZbmX9ALKlv5xKXaZkFmrYFAq yTdZIFytSWoKUOaXJ8Yxw173K+82CXdzsW16R9YowgxOX1an6xgrOCwe/l846FptEwku 6e/jIdgS8zVxbOUDjC3/h/I/HrNMBn/24MGF6l/7x+Cb/SQok6QeLoJ6JvYtddalrSuN wyHz2PWeENX0LbGlWs5OQj9rPrtRpki17jQCJttqJFHj2cMDANweklGPiHihiOfkm/Jw QVQA== 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=ZWWL7Owde0X6XWoGeTu8bSh9cEg5WricZqZvAQimxAs=; b=zkJoE8iwTf2gmgKUAmjuzkkCffyS4VWr66BTgKmZe0fT4YglcDcPYFOM4g0O+TWW0E v5RlmIrQ2RWN2wADBuvKqP0TauR7GAJZ40R+82//TClMn2KTGXlgwbfvAEEAkSFxhL4D GsSGyA4ToBODJ3kd9OZIgd9xMlSUz9uTXAJu4GgqvdaHYEofgTEehlWm6ibs5QXXCiWP ksFHVKJd7QUdV08Wu5Bl5a3hnvAG5rAnDfEsvquJ/+d83hklpTdghxTdQ7Q1ZkEfdXH1 t7lgTXhr9WrtBDCEjJTDYx0/Qm1oA0MLXg1Ks+mjPVilMTNYgugdr5BnDikwuH2f74Zs 5aIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=sPlRnflP; 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 sg34-20020a170907a42200b007ae3958c7c9si295071ejc.999.2022.11.25.08.57.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 08:57:53 -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=sPlRnflP; 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 043D8384E3AA for ; Fri, 25 Nov 2022 16:57:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 043D8384E3AA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669395469; bh=ZWWL7Owde0X6XWoGeTu8bSh9cEg5WricZqZvAQimxAs=; 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=sPlRnflPqRwWbZYHNfaylj1hKP7gKindywXdypWJoqK9lWKUkLxa6A1LnfoUrPG2I eeTiLFN6rDDcK2n4UqWZoJAi9pR3VuxvBiU3rTab7ii+r+6NT7WJBRH9AkVF5Qmqda 7Hj+nhrRitz6MRxAZCg01vcpopbl+P33Mg66snkQ= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 3E45138493F2 for ; Fri, 25 Nov 2022 16:57:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3E45138493F2 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 76B9421B15 for ; Fri, 25 Nov 2022 16:57:38 +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 725772C141 for ; Fri, 25 Nov 2022 16:57:38 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id 676166586; Fri, 25 Nov 2022 16:57:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id 655EA6238 for ; Fri, 25 Nov 2022 16:57:38 +0000 (UTC) Date: Fri, 25 Nov 2022 16:57:38 +0000 (UTC) To: binutils@sourceware.org Subject: [PATCH 7/8] section-select: Remove bfd_max_section_id again 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?1750488028062155279?= X-GMAIL-MSGID: =?utf-8?q?1750488028062155279?= since we reset the whole matching state completely we don't need the already-seen early-outs anymore. --- Depending on how 4/8 is decided this patch might not land in the tree in the end, as without rebuilding the whole matchings from scratch the early-outs remain useful, Ciao, Michael. bfd/bfd-in2.h | 2 -- bfd/section.c | 19 ------------------- ld/ldlang.c | 19 +------------------ ld/ldlang.h | 1 - 4 files changed, 1 insertion(+), 40 deletions(-) diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 5350ae42b03..0b071dda1e5 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -1330,8 +1330,6 @@ discarded_section (const asection *sec) { 0, NAME, 0, BSF_SECTION_SYM, SECTION } #endif -unsigned int bfd_get_max_section_id (void); - void bfd_section_list_clear (bfd *); asection *bfd_get_section_by_name (bfd *abfd, const char *name); diff --git a/bfd/section.c b/bfd/section.c index d691bf265ab..f73e0345e15 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -849,25 +849,6 @@ SUBSECTION These are the functions exported by the section handling part of BFD. */ -/* -FUNCTION - bfd_get_max_section_id - -SYNOPSIS - unsigned int bfd_get_max_section_id (void); - -DESCRIPTION - Returns an internal number representing the maximum value of - any SECTION->id member. Whenever a new section is created that - value increases. It never decreases. -*/ - -unsigned int -bfd_get_max_section_id (void) -{ - return _bfd_section_id; -} - /* FUNCTION bfd_section_list_clear diff --git a/ld/ldlang.c b/ld/ldlang.c index 18d10531d51..abaa9916256 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -368,8 +368,6 @@ walk_wild_file_in_exclude_list (struct name_list *exclude_list, return false; } -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). */ @@ -402,9 +400,6 @@ walk_wild_section_match (lang_wild_statement_type *ptr, const char *file_spec = ptr->filename; char *p; - if (s->id < ptr->max_section_id) - return; - /* Check if filenames match. */ if (file_spec == NULL) ; @@ -896,8 +891,6 @@ resolve_wild_sections (lang_input_statement_type *file) const char *sname = bfd_section_name (s); 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 { @@ -954,7 +947,6 @@ resolve_wilds (void) } } } - old_max_section_id = bfd_get_max_section_id (); } /* For each input section that matches wild statement S calls @@ -965,12 +957,7 @@ walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) { lang_statement_union_type *l; - if (s->max_section_id < bfd_get_max_section_id ()) - { - //printf("XXX %s\n", s->filename ? s->filename : ""); - s->max_section_id = bfd_get_max_section_id (); - } - + //printf("XXX %s\n", s->filename ? s->filename : ""); for (l = s->matching_sections.head; l; l = l->header.next) { (*callback) (s, l->input_matcher.pattern, l->input_matcher.section, @@ -7853,8 +7840,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->max_section_id = 0; - /* XXX Leaks? */ lang_list_init (&stmt->matching_sections); } } @@ -7863,7 +7848,6 @@ static void reset_resolved_wilds (void) { lang_for_each_statement (reset_one_wild); - old_max_section_id = 0; } void @@ -8240,7 +8224,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->max_section_id = 0; lang_list_init (&new_stmt->matching_sections); analyze_walk_wild_section_handler (new_stmt); if (0) diff --git a/ld/ldlang.h b/ld/ldlang.h index 5d9d2447f1c..b92a7bb9d96 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; - unsigned int max_section_id; lang_section_bst_type *tree, **rightmost; struct flag_info *section_flag_list; From patchwork Fri Nov 25 16:58:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 26101 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4158760wrr; Fri, 25 Nov 2022 08:58:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf7xNHstU+BhypMO4pKGvp8mGanQYW7fdTsVHcO8nIItgDn8oPjYzkzmDaUD5h4G3U5dzAc/ X-Received: by 2002:a17:906:68cd:b0:7ac:f8e3:d547 with SMTP id y13-20020a17090668cd00b007acf8e3d547mr22298836ejr.53.1669395495458; Fri, 25 Nov 2022 08:58:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669395495; cv=none; d=google.com; s=arc-20160816; b=V7+SENOJJvaR9MGqBDTQZGyEJsbsoUQU9jfTIxJhfmnVlRumS1bqgNrvASbeBgiHrG 46/Hhqf/TjEuxcPomwdLxKc+Y/1tJvZvkyiEglpPsuYpt18sR2kzccbiFL6uqSJELtLG 1MBj3JK7E+SJEAk+6JjfbhJ1iclBkiU1KkTc8rxeIxyMN45izduJwaRqqEbtvqeAfNP2 kHzWjVSUEBuD+Ht2xiKm9pO4eOwNUnGZzo60FRQWNepumHYXkdkrnBgJEosPnpuxXVnB kBMYlQAabh9g0YkaASRCVyCcqyJJ1zxygaZFijZPISWYfKdq7NoJ7S5K1/CSIWv1/M1n jsww== 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=GEUdRDmm4NO9++zSMGwaumt04faIthnKWt1XTPvIdZQ=; b=zLhkVUpo9cGIFEqeDkhOrL9g1NEPcHH3TtkhYWrL9yt0NVltsKNL95qUUeylnQP7vs By414s3Xd6TpN9D4/81Ew5NuDVwSU3a3NcUbanKuFE3v4YChyJUidNiDSJipYBwTG4Vf n5M41FdUCheAXs/p2ZchrJxXOjeQMbShASplB+KAu3acEjk/qTWFsha/Ra5lt1Wpstq6 l3VjCKD/wMJmESvYELykY1DlVapm2K6f/JdYLEFTiANauA7eAKVZMPrZTNEAu50Y36It 7eyl/D+YunEfw9f7HXRD5VsCxWae7EWjmbagN+PfCQeFuclpd5/lwghhXZcM4Uh3zIOP kWWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=aDmGnnXY; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id sd36-20020a1709076e2400b007313312730esi3626929ejc.85.2022.11.25.08.58.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 08:58:15 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=aDmGnnXY; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 F32F4384E3A3 for ; Fri, 25 Nov 2022 16:58:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F32F4384E3A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669395493; bh=GEUdRDmm4NO9++zSMGwaumt04faIthnKWt1XTPvIdZQ=; 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=aDmGnnXYpWPyGB+ihQrAjGpgYi9ELfIv/rfiEunMiNwoSSdpwZKnYh9ZzBBgdz7S8 enAmNQxZQAWj98UfBOkaC4gtJ9LF9Zp2+54Bupv7IU3GZD4Xdpcf3iIDxousUOusQ2 i+4UQMXlnon9jNbV5JiYogpNa8xegFX+amC6Fs7M= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id C33E5384E394 for ; Fri, 25 Nov 2022 16:58:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C33E5384E394 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 09C4B21AF9 for ; Fri, 25 Nov 2022 16:58:04 +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 0586C2C141 for ; Fri, 25 Nov 2022 16:58:04 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id F41AC6586; Fri, 25 Nov 2022 16:58:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id F2CC46238 for ; Fri, 25 Nov 2022 16:58:03 +0000 (UTC) Date: Fri, 25 Nov 2022 16:58:03 +0000 (UTC) To: binutils@sourceware.org Subject: [PATCH 8/8] section-select: Fix exclude-file-3 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=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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?1750488051196668905?= X-GMAIL-MSGID: =?utf-8?q?1750488051196668905?= this testcase wasn't correctly testing everything, it passed, even though sections from an excluded file were included. Fixing this reveals a problem in the new section selector. This fixes that as well. --- ld/ldlang.c | 7 ++++--- ld/testsuite/ld-scripts/exclude-file-3.map | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ld/ldlang.c b/ld/ldlang.c index abaa9916256..4e9b93a83a7 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -422,6 +422,10 @@ walk_wild_section_match (lang_wild_statement_type *ptr, return; } + /* If filename is excluded we're done. */ + if (walk_wild_file_in_exclude_list (ptr->exclude_name_list, file)) + return; + /* Check section name against each wildcard spec. If there's no wildcard all sections match. */ sec = ptr->section_list; @@ -920,9 +924,6 @@ resolve_wilds (void) LANG_FOR_EACH_INPUT_STATEMENT (f) { //printf("XXX %s\n", f->filename); - /* XXX if (walk_wild_file_in_exclude_list (s->exclude_name_list, f)) - return;*/ - if (f->the_bfd == NULL || !bfd_check_format (f->the_bfd, bfd_archive)) resolve_wild_sections (f); diff --git a/ld/testsuite/ld-scripts/exclude-file-3.map b/ld/testsuite/ld-scripts/exclude-file-3.map index 389d1708c90..255182030ca 100644 --- a/ld/testsuite/ld-scripts/exclude-file-3.map +++ b/ld/testsuite/ld-scripts/exclude-file-3.map @@ -3,5 +3,7 @@ EXCLUDE_FILE\(\*-b\.o\) \*\(\.data \.data\.\*\) \.data +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o \.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o +#failif +.*data +0x[0-9a-f]+ +0x[0-9a-f]+ .*exclude-file-b.* -#... \ No newline at end of file +#...