ld/pdb: Make global hash ordering deterministic
Ensures deterministic ordering of global symbols in PDB files by sorting on offset for hash collisions.
This patch makes the ordering of global symbols within PDB files deterministic by introducing a secondary sort key. Previously, when multiple global symbols had the same hash value, their relative order was left to the host system’s qsort implementation, leading to inconsistencies. The change modifies the global_compare_hash function to use the symbol’s record offset as a tie-breaker, ensuring reproducible PDB output across different platforms.
In Details
This patch addresses a reproducibility issue in the PDB generation for binutils' linker (ld). The global_compare_hash function is used to sort global symbols before writing them to the PDB file. When hash collisions occurred (multiple symbols yielding the same hash value), the original implementation treated them as equal, relying on the underlying qsort to determine their order. This behavior is non-deterministic across different architectures or compiler versions. The updated function now compares the offset of the symbols if their hashes are equal, providing a stable, reproducible or…
- PDB
- Program Database. A file format used by Microsoft for storing debugging and project-related information for Microsoft Windows applications.
- ld
- The GNU linker, responsible for combining object files into an executable or shared library.
- hash
- A function that converts an input into a fixed-size value, often used for indexing and searching.
- qsort
- A standard library function for sorting arrays.
- symbol
- An identifier for a memory location, such as a variable or function name.