public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Michael Matz <matz@suse.de>
To: binutils@sourceware.org
Subject: [PATCH 4/8] section-select: Completely rebuild matches
Date: Fri, 25 Nov 2022 16:55:12 +0000 (UTC)	[thread overview]
Message-ID: <alpine.LSU.2.20.2211251647220.24878@wotan.suse.de> (raw)
In-Reply-To: <cover.1669391757.git.matz@suse.de>

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.
-- 
2.36.1


  parent reply	other threads:[~2022-11-25 16:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1669391757.git.matz@suse.de>
2022-11-25 16:44 ` [PATCH 1/8] section-select: Lazily resolve section matches Michael Matz
2022-11-25 16:46 ` [PATCH 2/8] section-select: Deal with sections added late Michael Matz
2022-11-25 16:47 ` [PATCH 3/8] section-select: Implement a prefix-tree Michael Matz
2022-11-25 16:55 ` Michael Matz [this message]
2022-11-28  1:57   ` [PATCH 4/8] section-select: Completely rebuild matches Alan Modra
2022-11-28 14:24     ` Michael Matz
2022-11-29 12:22       ` Alan Modra
2022-11-29 13:23         ` Michael Matz
2022-11-25 16:55 ` [PATCH 5/8] section-select: Remove unused code Michael Matz
2022-11-25 16:55 ` [PATCH 6/8] section-select: Cleanup Michael Matz
2022-11-25 16:57 ` [PATCH 7/8] section-select: Remove bfd_max_section_id again Michael Matz
2022-11-25 16:58 ` [PATCH 8/8] section-select: Fix exclude-file-3 Michael Matz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.20.2211251647220.24878@wotan.suse.de \
    --to=matz@suse.de \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).