[llvm] [pdb] Fix public symbol hashing in GSIHashStreamBuilder::finalizeBuckets (PR #190133)

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 01:36:17 PDT 2026


https://github.com/zmodem created https://github.com/llvm/llvm-project/pull/190133

BulkPublic.Name is not necessarily null terminated, so make sure not to hash past its actual length.

In practice it would often be null terminated due to padding at the end of the S_PUB32 symbol, but in the cases where it's not, we would compute the wrong hash here, put it in the wrong hash bucket, preventing debuggers from looking up the symbol by name, causing issues such as https://discourse.llvm.org/t/pdb-generated-by-lld-link-doesnt-point-to-correct-entry-point-when-debugged-using-visual-studio/90349

>From 78550805b23a614dc267aecfc45ec8b6b278c51e Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Thu, 2 Apr 2026 10:27:42 +0200
Subject: [PATCH] [pdb] Fix public symbols hashing in
 GSIHashStreamBuilder::finalizeBuckets

BulkPublic.Name is not guaranteed to be null terminated, so make sure
not to hash past its actual length.

In practice it would often be null terminated due to padding at the end
of the S_PUB32 symbol, but in the cases where it's not, we would compute
the wrong hash here, put it in the wrong hash bucket, preventing
debuggers from looking up the symbol by name, causing issues such as
https://discourse.llvm.org/t/pdb-generated-by-lld-link-doesnt-point-to-correct-entry-point-when-debugged-using-visual-studio/90349
---
 llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
index 0c4b9362a0f04..e3ffbcbd93ac3 100644
--- a/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
@@ -200,7 +200,8 @@ void GSIHashStreamBuilder::finalizeBuckets(
     uint32_t RecordZeroOffset, MutableArrayRef<BulkPublic> Records) {
   // Hash every name in parallel.
   parallelFor(0, Records.size(), [&](size_t I) {
-    Records[I].setBucketIdx(hashStringV1(Records[I].Name) % IPHR_HASH);
+    StringRef Name = StringRef(Records[I].Name, Records[I].NameLen);
+    Records[I].setBucketIdx(hashStringV1(Name) % IPHR_HASH);
   });
 
   // Count up the size of each bucket. Then, use an exclusive prefix sum to



More information about the llvm-commits mailing list