ld/pdb: Avoid quadratic section lookup in handle_debugs_section
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Test passed
|
Commit Message
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.
---
ld/pdb.c | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
Comments
On 02.11.2026 23:59, Oleg Tolmatcev wrote:
> 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.
Okay.
A remark on your sending of this and the other 5 patches: If they're
meant to be a series, they should be numbered accordingly. A series
ideally would also have a cover letter. If they're not meant to be a
series, later patches shouldn't be replies to earlier ones.
Jan
пт, 6 нояб. 2026 г. в 10:18, Jan Beulich <jbeulich@suse.com>:
>
> On 02.11.2026 23:59, Oleg Tolmatcev wrote:
> > 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.
>
> Okay.
>
> A remark on your sending of this and the other 5 patches: If they're
> meant to be a series, they should be numbered accordingly. A series
> ideally would also have a cover letter. If they're not meant to be a
> series, later patches shouldn't be replies to earlier ones.
>
> Jan
Sorry, I forgot to add "--no-thread" to "git send-email".
Thanks
Oleg
On 06.11.2026 10:28, Oleg Tolmatcev wrote:
> пт, 6 нояб. 2026 г. в 10:18, Jan Beulich <jbeulich@suse.com>:
>> On 02.11.2026 23:59, Oleg Tolmatcev wrote:
>>> 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.
>>
>> Okay.
>>
>> A remark on your sending of this and the other 5 patches: If they're
>> meant to be a series, they should be numbered accordingly. A series
>> ideally would also have a cover letter. If they're not meant to be a
>> series, later patches shouldn't be replies to earlier ones.
>
> Sorry, I forgot to add "--no-thread" to "git send-email".
Except that, now that I looked at patch 2 as well, that one depends on
patch 1 (contextually, not functionally). I haven't looked further yet.
Jan
@@ -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,8 @@ 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,