From cb4c32705782e06deba08e577e3c61c8be1244c3 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Mon, 20 Jan 2025 11:44:48 +0800 Subject: [PATCH] Fix slowdown about partial linking --- 0100-Fix-slowdown-about-partial-linking.patch | 138 ++++++++++++++++++ binutils.spec | 9 +- 2 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 0100-Fix-slowdown-about-partial-linking.patch diff --git a/0100-Fix-slowdown-about-partial-linking.patch b/0100-Fix-slowdown-about-partial-linking.patch new file mode 100644 index 0000000..6d3969b --- /dev/null +++ b/0100-Fix-slowdown-about-partial-linking.patch @@ -0,0 +1,138 @@ +From 0fdc18c5be6496b0b756002cdb8e27f2f6a28883 Mon Sep 17 00:00:00 2001 +From: Xin Wang +Date: Mon, 20 Jan 2025 11:38:27 +0800 +Subject: [PATCH] Fix slowdown about partial linking + +--- + ld/ldlang.c | 66 ++++++++++++++++++++++++++++++++++++----------------- + 1 file changed, 45 insertions(+), 21 deletions(-) + +diff --git a/ld/ldlang.c b/ld/ldlang.c +index a357f802..3b6b8563 100644 +--- a/ld/ldlang.c ++++ b/ld/ldlang.c +@@ -1246,6 +1246,7 @@ struct out_section_hash_entry + { + struct bfd_hash_entry root; + lang_statement_union_type s; ++ struct out_section_hash_entry *tail; + }; + + /* The hash table. */ +@@ -1255,10 +1256,10 @@ static struct bfd_hash_table output_section_statement_table; + /* Support routines for the hash table used by lang_output_section_find, + initialize the table, fill in an entry and remove the table. */ + +-static struct bfd_hash_entry * +-output_section_statement_newfunc (struct bfd_hash_entry *entry, +- struct bfd_hash_table *table, +- const char *string) ++static struct out_section_hash_entry * ++output_section_statement_newfunc_1 (struct bfd_hash_entry *entry, ++ struct bfd_hash_table *table, ++ const char *string) + { + lang_output_section_statement_type **nextp; + struct out_section_hash_entry *ret; +@@ -1268,12 +1269,12 @@ output_section_statement_newfunc (struct bfd_hash_entry *entry, + entry = (struct bfd_hash_entry *) bfd_hash_allocate (table, + sizeof (*ret)); + if (entry == NULL) +- return entry; ++ return NULL; + } + + entry = bfd_hash_newfunc (entry, table, string); + if (entry == NULL) +- return entry; ++ return NULL; + + ret = (struct out_section_hash_entry *) entry; + memset (&ret->s, 0, sizeof (ret->s)); +@@ -1298,6 +1299,20 @@ output_section_statement_newfunc (struct bfd_hash_entry *entry, + instead. */ + nextp = &ret->s.output_section_statement.next; + lang_statement_append (&lang_os_list, &ret->s, nextp); ++ return ret; ++} ++ ++static struct bfd_hash_entry * ++output_section_statement_newfunc (struct bfd_hash_entry *entry, ++ struct bfd_hash_table *table, ++ const char *string) ++{ ++ struct out_section_hash_entry *ret; ++ ++ ret = output_section_statement_newfunc_1 (entry, table, string); ++ if (ret == NULL) ++ return NULL; ++ ret->tail = ret; + return &ret->root; + } + +@@ -1523,31 +1538,39 @@ lang_output_section_statement_lookup (const char *name, + { + /* We have a section of this name, but it might not have the correct + constraint. */ ++ struct out_section_hash_entry *first_ent = entry; + struct out_section_hash_entry *last_ent; + + name = entry->s.output_section_statement.name; +- do ++ if (create != 2 ++ && !(create && constraint == SPECIAL)) + { +- if (create != 2 +- && !(create && constraint == SPECIAL) +- && (constraint == entry->s.output_section_statement.constraint ++ do ++ { ++ if (constraint == entry->s.output_section_statement.constraint + || (constraint == 0 +- && entry->s.output_section_statement.constraint >= 0))) +- return &entry->s.output_section_statement; +- last_ent = entry; +- entry = (struct out_section_hash_entry *) entry->root.next; ++ && entry->s.output_section_statement.constraint >= 0)) ++ return &entry->s.output_section_statement; ++ last_ent = entry; ++ entry = (struct out_section_hash_entry *) entry->root.next; ++ } ++ while (entry != NULL ++ && name == entry->s.output_section_statement.name); + } +- while (entry != NULL +- && name == entry->s.output_section_statement.name); ++ else ++ last_ent = first_ent->tail; + + if (!create) + return NULL; + +- entry +- = ((struct out_section_hash_entry *) +- output_section_statement_newfunc (NULL, +- &output_section_statement_table, +- name)); ++ /* Only the first entry needs the tail pointer. */ ++ entry = bfd_hash_allocate (&output_section_statement_table, ++ offsetof (struct out_section_hash_entry, tail)); ++ if (entry != NULL) ++ entry ++ = output_section_statement_newfunc_1 (&entry->root, ++ &output_section_statement_table, ++ name); + if (entry == NULL) + { + einfo (_("%F%P: failed creating section `%s': %E\n"), name); +@@ -1555,6 +1578,7 @@ lang_output_section_statement_lookup (const char *name, + } + entry->root = last_ent->root; + last_ent->root.next = &entry->root; ++ first_ent->tail = entry; + } + + entry->s.output_section_statement.name = name; +-- +2.33.0 + diff --git a/binutils.spec b/binutils.spec index 4458142..cd1ddd3 100644 --- a/binutils.spec +++ b/binutils.spec @@ -1,4 +1,4 @@ -%define anolis_release 4 +%define anolis_release 5 # Determine if this is a native build or a cross build. # # For a cross build add --define "binutils_target " to the command @@ -357,6 +357,10 @@ Patch0039: 0039-binutils-multilib.am.patch # Lifetime: TEMPORARY Patch0099: 0099-binutils-suppress-ld-align-tests.patch +# Purpose: Fix slowdown about partial linking +# Lifetime: TEMPORARY +Patch0100: 0100-Fix-slowdown-about-partial-linking.patch + # Part 3000 - 4999 Patch3001: LoongArch-Fix-ld-no-relax-bug.patch Patch3002: LoongArch-Directly-delete-relaxed-instuctions-in-fir.patch @@ -1125,6 +1129,9 @@ exit 0 %doc README ChangeLog MAINTAINERS README-maintainer-mode %changelog +* Mon Jan 20 2025 Xin Wang - 2.41-5 +- Fix slowdown about partial linking + * Fri Nov 29 2024 Peng Fan - 2.41-4 - LoongArch: keep compatible with older gcc. -- Gitee