FRIDAY, NOVEMBER 6, 2026
ld/pdb Performance Win
ld/pdb: Avoid quadratic section lookup in handle_debugs_section
Optimizes section lookups in ld's --pdb mode for faster linking.
The linker’s --pdb option previously scanned all symbols for each section, leading to quadratic performance with many sections. This commit optimizes the process by using coff_section_from_bfd_index to look up sections in a hash table, significantly reducing linking time for objects with numerous sections.
In Details
The handle_debugs_section function in ld/pdb.c previously iterated through all sections for each symbol to determine symbol-section mapping. This commit replaces the linear scan with a hash-table lookup using coff_section_from_bfd_index, which is cached on the BFD. This change addresses a performance bottleneck in PDB generation for large object files.
For Context
- ld
- The GNU linker, responsible for combining object files and libraries into an executable or library.
- --pdb
- A linker option to generate Program Database files, commonly used by Microsoft Windows debuggers.
- handle_debugs_section
- A function within ld/pdb.c that processes debug information sections, specifically for PDB generation.
- coff_section_from_bfd_index
- A function that retrieves section information from a BFD (Binary File Descriptor) using a pre-computed hash table, providing faster lookups than a linear scan.
- BFD
- Binary File Descriptor library, a low-level interface used by GNU binutils to abstract away differences between object file formats.