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];