|
| 1 | +From 8455910b34f9fbf0bc43915418617641db55f883 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Alan Modra <amodra@gmail.com> |
| 3 | +Date: Sat, 4 Jan 2025 11:33:27 +1030 |
| 4 | +Subject: [PATCH] PR32238, ld -r slowdown since 21401fc7bf |
| 5 | + |
| 6 | + PR 32238 |
| 7 | + * ldlang.c (struct out_section_hash_entry): Add "tail". |
| 8 | + (output_section_statement_newfunc_1): New, extracted from.. |
| 9 | + (output_section_statement_newfunc): ..here. Init tail. |
| 10 | + (lang_output_section_statement_lookup): Use tail to avoid |
| 11 | + list traversal. |
| 12 | +--- |
| 13 | + ld/ldlang.c | 66 ++++++++++++++++++++++++++++++++++++----------------- |
| 14 | + 1 file changed, 45 insertions(+), 21 deletions(-) |
| 15 | + |
| 16 | +diff --git a/ld/ldlang.c b/ld/ldlang.c |
| 17 | +index a357f80235f..3b6b8563c49 100644 |
| 18 | +--- a/ld/ldlang.c |
| 19 | ++++ b/ld/ldlang.c |
| 20 | +@@ -1246,6 +1246,7 @@ struct out_section_hash_entry |
| 21 | + { |
| 22 | + struct bfd_hash_entry root; |
| 23 | + lang_statement_union_type s; |
| 24 | ++ struct out_section_hash_entry *tail; |
| 25 | + }; |
| 26 | + |
| 27 | + /* The hash table. */ |
| 28 | +@@ -1255,10 +1256,10 @@ static struct bfd_hash_table output_section_statement_table; |
| 29 | + /* Support routines for the hash table used by lang_output_section_find, |
| 30 | + initialize the table, fill in an entry and remove the table. */ |
| 31 | + |
| 32 | +-static struct bfd_hash_entry * |
| 33 | +-output_section_statement_newfunc (struct bfd_hash_entry *entry, |
| 34 | +- struct bfd_hash_table *table, |
| 35 | +- const char *string) |
| 36 | ++static struct out_section_hash_entry * |
| 37 | ++output_section_statement_newfunc_1 (struct bfd_hash_entry *entry, |
| 38 | ++ struct bfd_hash_table *table, |
| 39 | ++ const char *string) |
| 40 | + { |
| 41 | + lang_output_section_statement_type **nextp; |
| 42 | + struct out_section_hash_entry *ret; |
| 43 | +@@ -1268,12 +1269,12 @@ output_section_statement_newfunc (struct bfd_hash_entry *entry, |
| 44 | + entry = (struct bfd_hash_entry *) bfd_hash_allocate (table, |
| 45 | + sizeof (*ret)); |
| 46 | + if (entry == NULL) |
| 47 | +- return entry; |
| 48 | ++ return NULL; |
| 49 | + } |
| 50 | + |
| 51 | + entry = bfd_hash_newfunc (entry, table, string); |
| 52 | + if (entry == NULL) |
| 53 | +- return entry; |
| 54 | ++ return NULL; |
| 55 | + |
| 56 | + ret = (struct out_section_hash_entry *) entry; |
| 57 | + memset (&ret->s, 0, sizeof (ret->s)); |
| 58 | +@@ -1298,6 +1299,20 @@ output_section_statement_newfunc (struct bfd_hash_entry *entry, |
| 59 | + instead. */ |
| 60 | + nextp = &ret->s.output_section_statement.next; |
| 61 | + lang_statement_append (&lang_os_list, &ret->s, nextp); |
| 62 | ++ return ret; |
| 63 | ++} |
| 64 | ++ |
| 65 | ++static struct bfd_hash_entry * |
| 66 | ++output_section_statement_newfunc (struct bfd_hash_entry *entry, |
| 67 | ++ struct bfd_hash_table *table, |
| 68 | ++ const char *string) |
| 69 | ++{ |
| 70 | ++ struct out_section_hash_entry *ret; |
| 71 | ++ |
| 72 | ++ ret = output_section_statement_newfunc_1 (entry, table, string); |
| 73 | ++ if (ret == NULL) |
| 74 | ++ return NULL; |
| 75 | ++ ret->tail = ret; |
| 76 | + return &ret->root; |
| 77 | + } |
| 78 | + |
| 79 | +@@ -1523,31 +1538,39 @@ lang_output_section_statement_lookup (const char *name, |
| 80 | + { |
| 81 | + /* We have a section of this name, but it might not have the correct |
| 82 | + constraint. */ |
| 83 | ++ struct out_section_hash_entry *first_ent = entry; |
| 84 | + struct out_section_hash_entry *last_ent; |
| 85 | + |
| 86 | + name = entry->s.output_section_statement.name; |
| 87 | +- do |
| 88 | ++ if (create != 2 |
| 89 | ++ && !(create && constraint == SPECIAL)) |
| 90 | + { |
| 91 | +- if (create != 2 |
| 92 | +- && !(create && constraint == SPECIAL) |
| 93 | +- && (constraint == entry->s.output_section_statement.constraint |
| 94 | ++ do |
| 95 | ++ { |
| 96 | ++ if (constraint == entry->s.output_section_statement.constraint |
| 97 | + || (constraint == 0 |
| 98 | +- && entry->s.output_section_statement.constraint >= 0))) |
| 99 | +- return &entry->s.output_section_statement; |
| 100 | +- last_ent = entry; |
| 101 | +- entry = (struct out_section_hash_entry *) entry->root.next; |
| 102 | ++ && entry->s.output_section_statement.constraint >= 0)) |
| 103 | ++ return &entry->s.output_section_statement; |
| 104 | ++ last_ent = entry; |
| 105 | ++ entry = (struct out_section_hash_entry *) entry->root.next; |
| 106 | ++ } |
| 107 | ++ while (entry != NULL |
| 108 | ++ && name == entry->s.output_section_statement.name); |
| 109 | + } |
| 110 | +- while (entry != NULL |
| 111 | +- && name == entry->s.output_section_statement.name); |
| 112 | ++ else |
| 113 | ++ last_ent = first_ent->tail; |
| 114 | + |
| 115 | + if (!create) |
| 116 | + return NULL; |
| 117 | + |
| 118 | +- entry |
| 119 | +- = ((struct out_section_hash_entry *) |
| 120 | +- output_section_statement_newfunc (NULL, |
| 121 | +- &output_section_statement_table, |
| 122 | +- name)); |
| 123 | ++ /* Only the first entry needs the tail pointer. */ |
| 124 | ++ entry = bfd_hash_allocate (&output_section_statement_table, |
| 125 | ++ offsetof (struct out_section_hash_entry, tail)); |
| 126 | ++ if (entry != NULL) |
| 127 | ++ entry |
| 128 | ++ = output_section_statement_newfunc_1 (&entry->root, |
| 129 | ++ &output_section_statement_table, |
| 130 | ++ name); |
| 131 | + if (entry == NULL) |
| 132 | + { |
| 133 | + einfo (_("%F%P: failed creating section `%s': %E\n"), name); |
| 134 | +@@ -1555,6 +1578,7 @@ lang_output_section_statement_lookup (const char *name, |
| 135 | + } |
| 136 | + entry->root = last_ent->root; |
| 137 | + last_ent->root.next = &entry->root; |
| 138 | ++ first_ent->tail = entry; |
| 139 | + } |
| 140 | + |
| 141 | + entry->s.output_section_statement.name = name; |
| 142 | +-- |
| 143 | +2.45.2 |
| 144 | + |
0 commit comments