ld/pdb: Make globals hash ordering deterministic

Message ID 20260930193657.733-6-oleg.tolmatcev@gmail.com
State New
Headers
Series ld/pdb: Make globals hash ordering deterministic |

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

Oleg Tolmatcev Sept. 30, 2026, 7:36 p.m. UTC
  global_compare_hash treated entries with colliding hashes as equal,
leaving their relative order to the host qsort implementation.  Sort
collisions by symbol-record offset so PDB output is reproducible across
hosts.

ld/
	* pdb.c (global_compare_hash): Compare offsets when hashes are equal.
---
 ld/pdb.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Patch

diff --git a/ld/pdb.c b/ld/pdb.c
index 9988fd94f51..36b600e34bd 100644
--- a/ld/pdb.c
+++ b/ld/pdb.c
@@ -4473,6 +4473,11 @@  global_compare_hash (const void *s1, const void *s2)
   if (g1->hash > g2->hash)
     return 1;
 
+  if (g1->offset < g2->offset)
+    return -1;
+  if (g1->offset > g2->offset)
+    return 1;
+
   return 0;
 }