summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/DebugInfo
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2019-04-29 23:09:35 +0000
committerNico Weber <nicolasweber@gmx.de>2019-04-29 23:09:35 +0000
commite577be4ed1ecb7e354ec25f431de058365befe16 (patch)
treeea06db783b16b4a382bd701336315a8210b02fd6 /llvm/unittests/DebugInfo
parent8c474a38d174b472e75c948af11f8cf46dc465cc (diff)
downloadbcm5719-llvm-e577be4ed1ecb7e354ec25f431de058365befe16.tar.gz
bcm5719-llvm-e577be4ed1ecb7e354ec25f431de058365befe16.zip
[PDB] Fix hash function used to write /src/headerblock
lld-link used to write PDB files that DIA couldn't recover natvis files from if: - The global strings table was > 64kiB - There were at least 3 natvis files The cause was that the hash function for the /src/headerblock stream was incorrect: It needs to be truncated to 16 bit. If the global strings table was <= 64kiB, truncating to 16 bit is a no-op, so this wasn't needed for small programs. If there are only 1 or 2 natvis files, then the growth strategy in HashTable::grow() would mean the hash table would have 2 buckets (for 1 natvis file) or 4 buckets (for 4 natvis files), and since the hash function is used modulo number of buckets, and since 2 and 4 divide 0x10000, the missing `% 0x10000` is a no-op there too. For 3 natvis files, the hash table grows to 6 buckets, which has a factor that's not common with 0x10000 and the difference starts to matter. Fixes PR41626. Differential Revision: https://reviews.llvm.org/D61277 llvm-svn: 359515
Diffstat (limited to 'llvm/unittests/DebugInfo')
-rw-r--r--llvm/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/llvm/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp b/llvm/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp
index 719cb807a2b..2f7c0619440 100644
--- a/llvm/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp
+++ b/llvm/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp
@@ -19,11 +19,7 @@ using namespace llvm;
using namespace llvm::pdb;
using namespace llvm::support;
-namespace {
-class StringTableBuilderTest : public ::testing::Test {};
-}
-
-TEST_F(StringTableBuilderTest, Simple) {
+TEST(StringTableBuilderTest, Simple) {
// Create /names table contents.
PDBStringTableBuilder Builder;
@@ -78,3 +74,21 @@ TEST_F(StringTableBuilderTest, Simple) {
EXPECT_THAT_EXPECTED(Table.getIDForString("bazz"), HasValue(BazzID));
EXPECT_THAT_EXPECTED(Table.getIDForString("barr"), HasValue(BarrID));
}
+
+TEST(StringTableHashTraitsTest, Simple) {
+ PDBStringTableBuilder Builder;
+
+ // Create more than 64kiB of dummy entries.
+ for (int i = 0; i < 320; ++i) {
+ std::string aaaaa = std::string(220, 'a') + std::to_string(i);
+ Builder.insert(aaaaa);
+ }
+
+ std::string S = "foo.natvis";
+ uint32_t Pos = Builder.insert(S);
+
+ EXPECT_GT(Pos, 0xFFFFu);
+
+ StringTableHashTraits Traits(Builder);
+ EXPECT_LE(Traits.hashLookupKey(S), 0xFFFFu);
+}
OpenPOWER on IntegriCloud