[llvm] [gsymutil] Fix a warning on systems with 32-bit `off_t` (PR #189524)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 08:52:09 PDT 2026


https://github.com/bogner updated https://github.com/llvm/llvm-project/pull/189524

>From bc073caac6662b3b2396fb02362b70fca8c2a062 Mon Sep 17 00:00:00 2001
From: Justin Bogner <mail at justinbogner.com>
Date: Mon, 30 Mar 2026 19:44:33 -0700
Subject: [PATCH 1/2] [gsymutil] Fix a warning on systems with 32-bit `off_t`

The size of `off_t` isn't specified, so it can be either 32 or 64 bits
depending on the system. In particular, on LLP64 systems like windows it's
generally only 32 bits. This means the `if (StrtabSize > UINT32_MAX)` check
added in #181458 may warn on such systems (Giving -Wsign-compare).

Given that `FileWriter::tell` doesn't even return `off_t`, but `uint64_t`, the
simplest fix is to just use the return type of the function instead of
potentially truncating.
---
 llvm/lib/DebugInfo/GSYM/GsymCreator.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
index f26e69fda2540..b4f7a52b2e95e 100644
--- a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
+++ b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
@@ -164,9 +164,9 @@ llvm::Error GsymCreator::encode(FileWriter &O) const {
   }
 
   // Write out the string table.
-  const off_t StrtabOffset = O.tell();
+  const uint64_t StrtabOffset = O.tell();
   StrTab.write(O.get_stream());
-  const off_t StrtabSize = O.tell() - StrtabOffset;
+  const uint64_t StrtabSize = O.tell() - StrtabOffset;
   std::vector<uint32_t> AddrInfoOffsets;
 
   // Verify that the size of the string table does not exceed 32-bit max.

>From 19858195117383511901dea619eb3c4609dbed76 Mon Sep 17 00:00:00 2001
From: Justin Bogner <mail at justinbogner.com>
Date: Fri, 10 Apr 2026 16:49:21 +0100
Subject: [PATCH 2/2] fixup: switch other callers of raw_ostream::tell to use
 uint64_t

---
 llvm/lib/DebugInfo/GSYM/FileWriter.cpp  | 6 +++---
 llvm/lib/DebugInfo/GSYM/GsymCreator.cpp | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/DebugInfo/GSYM/FileWriter.cpp b/llvm/lib/DebugInfo/GSYM/FileWriter.cpp
index 7c55ae03b6f0b..84e1c62360545 100644
--- a/llvm/lib/DebugInfo/GSYM/FileWriter.cpp
+++ b/llvm/lib/DebugInfo/GSYM/FileWriter.cpp
@@ -85,10 +85,10 @@ uint64_t FileWriter::tell() {
 }
 
 void FileWriter::alignTo(size_t Align) {
-  off_t Offset = OS.tell();
-  off_t AlignedOffset = (Offset + Align - 1) / Align * Align;
+  uint64_t Offset = OS.tell();
+  uint64_t AlignedOffset = (Offset + Align - 1) / Align * Align;
   if (AlignedOffset == Offset)
     return;
-  off_t PadCount = AlignedOffset - Offset;
+  uint64_t PadCount = AlignedOffset - Offset;
   OS.write_zeros(PadCount);
 }
diff --git a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
index b4f7a52b2e95e..399587587a679 100644
--- a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
+++ b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
@@ -145,7 +145,7 @@ llvm::Error GsymCreator::encode(FileWriter &O) const {
 
   // Write out all zeros for the AddrInfoOffsets.
   O.alignTo(4);
-  const off_t AddrInfoOffsetsOffset = O.tell();
+  const uint64_t AddrInfoOffsetsOffset = O.tell();
   for (size_t i = 0, n = Funcs.size(); i < n; ++i)
     O.writeU32(0);
 



More information about the llvm-commits mailing list