[PATCH 4/8] section-select: Completely rebuild matches
Michael Matz
matz@suse.de
Fri Nov 25 16:55:12 GMT 2022
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
More information about the Binutils
mailing list