[Lldb-commits] [lldb] [lldb] Add static asserts on Symbol size to DataFileCache (PR #203735)

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Sat Jun 13 18:35:16 PDT 2026


https://github.com/jasonmolenda created https://github.com/llvm/llvm-project/pull/203735

DataFileCache is a serialization to disk of a Symtab - the symbol names and array of Symbol objects - so if the contents of the Symbol object change, the serialization may need to change as well, and we need to bump the DataFileCache version number to avoid misparsing an older format.

It's also a little too easy to change Symbol and not notice that Symbol::Encode/Decode and Symtab::Encode/Decode need to be updated.

static_asserting the size of Symbol isn't perfect, but as long as we're doing it in Symbol.h already to warn anyone increasing the size of this object, I want to use the same technique to make sure people look at these other sites that are tied to the contents.

>From 2f9f71cf54320dea50527ac1433249f97e03a686 Mon Sep 17 00:00:00 2001
From: Jason Molenda <jmolenda at apple.com>
Date: Sat, 13 Jun 2026 18:32:05 -0700
Subject: [PATCH] [lldb] Add static asserts on Symbol size to DataFileCache

DataFileCache is a serialization to disk of a Symtab - the symbol
names and array of Symbol objects - so if the contents of the Symbol
object change, the serialization may need to change as well, and
we need to bump the DataFileCache version number to avoid misparsing
an older format.

It's also a little too easy to change Symbol and not notice that
Symbol::Encode/Decode and Symtab::Encode/Decode need to be updated.

static_asserting the size of Symbol isn't perfect, but as long as
we're doing it in Symbol.h already to warn anyone increasing the
size of this object, I want to use the same technique to make sure
people look at these other sites that are tied to the contents.
---
 lldb/source/Symbol/Symbol.cpp | 10 ++++++++++
 lldb/source/Symbol/Symtab.cpp |  9 +++++++++
 2 files changed, 19 insertions(+)

diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index 308f4b086b0df..78d1fd2e569c3 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -646,6 +646,16 @@ bool Symbol::Decode(const DataExtractor &data, lldb::offset_t *offset_ptr,
   return true;
 }
 
+// If the size of Symbol has changed, the Encode and
+// Decode methods also likely need to be updated and
+// the DataFileCache version number in Symtab::Encode
+// will need to be incremented as well.
+#if __SIZEOF_POINTER__ == 8
+static_assert(sizeof(lldb_private::Symbol) == 80,
+              "Symbol size has changed, Symbol::Encode and Decode likely need "
+              "to be updated");
+#endif
+
 /// The encoding format for the symbol is as follows:
 ///
 /// uint32_t m_uid;
diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp
index 2f226afeaf37c..767b1d416361f 100644
--- a/lldb/source/Symbol/Symtab.cpp
+++ b/lldb/source/Symbol/Symtab.cpp
@@ -1229,6 +1229,15 @@ bool DecodeCStrMap(const DataExtractor &data, lldb::offset_t *offset_ptr,
 constexpr llvm::StringLiteral kIdentifierSymbolTable("SYMB");
 constexpr uint32_t CURRENT_CACHE_VERSION = 1;
 
+// If the size of the Symbol object changes, the serialized
+// format likely also needs to change so the
+// CURRENT_CACHE_VERSION number will need to be incremented.
+#if __SIZEOF_POINTER__ == 8
+static_assert(
+    sizeof(lldb_private::Symbol) == 80,
+    "Symbol size has changed, DataFileCache version likely needs updating");
+#endif
+
 /// The encoding format for the symbol table is as follows:
 ///
 /// Signature signature;



More information about the lldb-commits mailing list