[PATCH] D33475: [pdb] pad source file name buffer at the end instead of the beginning

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 18:02:56 PDT 2017


inglorion created this revision.

DbiStreamBuilder calculated the offset of the source file names inside
the file info substream as the size of the file info substream minus
the size of the file names. Since the file info substream is padded to
a multiple of 4 bytes, this caused the first file name to be aligned
on a 4-byte boundary. By contrast, DbiModuleList would read the file
names immediately after the file name offset table, without skipping
to the next 4-byte boundary. This change makes it so that the file
names are written to the location where DbiModuleList expects them,
and puts any necessary padding for the file info substream after the
file names instead of before it.


https://reviews.llvm.org/D33475

Files:
  include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
  lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp


Index: lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
===================================================================
--- lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
+++ lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
@@ -129,7 +129,7 @@
   return sizeof(SecMapHeader) + sizeof(SecMapEntry) * SectionMap.size();
 }
 
-uint32_t DbiStreamBuilder::calculateFileInfoSubstreamSize() const {
+uint32_t DbiStreamBuilder::calculateNamesOffset() const {
   uint32_t Size = 0;
   Size += sizeof(ulittle16_t);                         // NumModules
   Size += sizeof(ulittle16_t);                         // NumSourceFiles
@@ -139,6 +139,11 @@
   for (const auto &M : ModiList)
     NumFileInfos += M->source_files().size();
   Size += NumFileInfos * sizeof(ulittle32_t); // FileNameOffsets
+  return Size;
+}
+
+uint32_t DbiStreamBuilder::calculateFileInfoSubstreamSize() const {
+  uint32_t Size = calculateNamesOffset();
   Size += calculateNamesBufferSize();
   return alignTo(Size, sizeof(uint32_t));
 }
@@ -157,9 +162,8 @@
 
 Error DbiStreamBuilder::generateFileInfoSubstream() {
   uint32_t Size = calculateFileInfoSubstreamSize();
-  uint32_t NameSize = calculateNamesBufferSize();
   auto Data = Allocator.Allocate<uint8_t>(Size);
-  uint32_t NamesOffset = Size - NameSize;
+  uint32_t NamesOffset = calculateNamesOffset();
 
   FileInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size),
                                            llvm::support::little);
@@ -207,6 +211,9 @@
     }
   }
 
+  if (auto EC = NameBufferWriter.padToAlignment(sizeof(uint32_t)))
+    return EC;
+
   if (NameBufferWriter.bytesRemaining() > 0)
     return make_error<RawError>(raw_error_code::invalid_format,
                                 "The names buffer contained unexpected data.");
Index: include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
===================================================================
--- include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
+++ include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
@@ -82,6 +82,7 @@
 
   Error finalize();
   uint32_t calculateModiSubstreamSize() const;
+  uint32_t calculateNamesOffset() const;
   uint32_t calculateSectionContribsStreamSize() const;
   uint32_t calculateSectionMapStreamSize() const;
   uint32_t calculateFileInfoSubstreamSize() const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33475.100026.patch
Type: text/x-patch
Size: 2320 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170524/8d170ff6/attachment.bin>


More information about the llvm-commits mailing list