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.