From 50be5d11289c8ca8d5aa7ec621b7110b6572612a Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Thu, 27 Oct 2022 14:50:40 +0200 Subject: section-select: Completely rebuild matches The check_relocs callback (and others) might have created new section behind our back and some of them (e.g. on powerpc the "linker stubs" .got) need to come in front of all others, despite being created late (a symptom would be "TOC opt*" failing on powerpc). This resets all section matches before updating for newly created sections (i.e. completely rebuilds the matches). --- ld/ldlang.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ld/ldlang.c b/ld/ldlang.c index 846dcdf..df5292d 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -8066,6 +8066,23 @@ 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; + lang_list_init (&stmt->matching_sections); + } +} + +static void +reset_resolved_wilds (void) +{ + lang_for_each_statement (reset_one_wild); +} + void lang_process (void) { @@ -8279,6 +8296,11 @@ lang_process (void) ldemul_after_check_relocs (); + /* There might have been new sections created (e.g. as result of + checking relocs to need a .got, or suchlike), so to properly order + them into our lists of matching sections reset them here. */ + reset_resolved_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. */ -- cgit v1.1