[binutils-gdb] ld/pdb: Avoid quadratic section lookup in handle_debugs_section
Jan Beulich
jbeulich@sourceware.org
Fri Nov 6 13:16:20 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=07cb9d7adff800116898912c75477593d4035614
commit 07cb9d7adff800116898912c75477593d4035614
Author: Oleg Tolmatcev <oleg.tolmatcev@gmail.com>
Date: Fri Nov 6 14:14:59 2026 +0100
ld/pdb: Avoid quadratic section lookup in handle_debugs_section
To map symbols to their sections, handle_debugs_section scanned all
symbols once per section, for every .debug$S section. With many
sections and symbols per object, this took about half of ld's time
when linking with --pdb.
Use coff_section_from_bfd_index, which looks sections up in a hash
table cached on the BFD.
ld/
* pdb.c (handle_debugs_section): Use coff_section_from_bfd_index
to find the sections of symbols.
Diff:
---
ld/pdb.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/ld/pdb.c b/ld/pdb.c
index 19799929c3a..7e9218d21f1 100644
--- a/ld/pdb.c
+++ b/ld/pdb.c
@@ -1940,7 +1940,6 @@ handle_debugs_section (asection *s, bfd *mod, struct string_table *strings,
struct internal_syment *symbols;
asection **sectlist;
unsigned int syment_count;
- int sect_num;
struct external_syment *ext;
syment_count = obj_raw_syment_count (mod);
@@ -1955,19 +1954,9 @@ handle_debugs_section (asection *s, bfd *mod, struct string_table *strings,
for (unsigned int i = 0; i < syment_count; i++)
{
bfd_coff_swap_sym_in (mod, &ext[i], &symbols[i]);
- }
-
- sect_num = 1;
-
- for (asection *sect = mod->sections; sect; sect = sect->next)
- {
- for (unsigned int i = 0; i < syment_count; i++)
- {
- if (symbols[i].n_scnum == sect_num)
- sectlist[i] = sect;
- }
- sect_num++;
+ if (symbols[i].n_scnum > 0)
+ sectlist[i] = coff_section_from_bfd_index (mod, symbols[i].n_scnum);
}
if (!bfd_coff_relocate_section (abfd, coff_data (abfd)->link_info, mod,
More information about the Binutils-cvs
mailing list