authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-02 18:50:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-02 22:06:02-07:00
logb95942744c7ded279f5695ed20fdbbc806323cba
treec02d21dbb376beb91c37256914e96bbd0d109a8a
parentd98869da430b0ab7054600dd0cb80a6d45ce0639

std.pdb: fix incorrect use of packed struct


1 files changed, 25 insertions(+), 25 deletions(-)

lib/std/pdb.zig+25-25
...@@ -14,7 +14,7 @@ const ArrayList = std.ArrayList;...@@ -14,7 +14,7 @@ const ArrayList = std.ArrayList;
14// documentation and/or contributors.14// documentation and/or contributors.
1515
16// https://llvm.org/docs/PDB/DbiStream.html#stream-header16// https://llvm.org/docs/PDB/DbiStream.html#stream-header
17pub const DbiStreamHeader = packed struct {17pub const DbiStreamHeader = extern struct {
18 VersionSignature: i32,18 VersionSignature: i32,
19 VersionHeader: u32,19 VersionHeader: u32,
20 Age: u32,20 Age: u32,
...@@ -37,7 +37,7 @@ pub const DbiStreamHeader = packed struct {...@@ -37,7 +37,7 @@ pub const DbiStreamHeader = packed struct {
37 Padding: u32,37 Padding: u32,
38};38};
3939
40pub const SectionContribEntry = packed struct {40pub const SectionContribEntry = extern struct {
41 /// COFF Section index, 1-based41 /// COFF Section index, 1-based
42 Section: u16,42 Section: u16,
43 Padding1: [2]u8,43 Padding1: [2]u8,
...@@ -50,7 +50,7 @@ pub const SectionContribEntry = packed struct {...@@ -50,7 +50,7 @@ pub const SectionContribEntry = packed struct {
50 RelocCrc: u32,50 RelocCrc: u32,
51};51};
5252
53pub const ModInfo = packed struct {53pub const ModInfo = extern struct {
54 Unused1: u32,54 Unused1: u32,
55 SectionContr: SectionContribEntry,55 SectionContr: SectionContribEntry,
56 Flags: u16,56 Flags: u16,
...@@ -68,7 +68,7 @@ pub const ModInfo = packed struct {...@@ -68,7 +68,7 @@ pub const ModInfo = packed struct {
68 //ObjFileName: char[],68 //ObjFileName: char[],
69};69};
7070
71pub const SectionMapHeader = packed struct {71pub const SectionMapHeader = extern struct {
72 /// Number of segment descriptors72 /// Number of segment descriptors
73 Count: u16,73 Count: u16,
7474
...@@ -76,7 +76,7 @@ pub const SectionMapHeader = packed struct {...@@ -76,7 +76,7 @@ pub const SectionMapHeader = packed struct {
76 LogCount: u16,76 LogCount: u16,
77};77};
7878
79pub const SectionMapEntry = packed struct {79pub const SectionMapEntry = extern struct {
80 /// See the SectionMapEntryFlags enum below.80 /// See the SectionMapEntryFlags enum below.
81 Flags: u16,81 Flags: u16,
8282
...@@ -310,7 +310,7 @@ pub const SymbolKind = enum(u16) {...@@ -310,7 +310,7 @@ pub const SymbolKind = enum(u16) {
310310
311pub const TypeIndex = u32;311pub const TypeIndex = u32;
312312
313pub const ProcSym = packed struct {313pub const ProcSym = extern struct {
314 Parent: u32,314 Parent: u32,
315 End: u32,315 End: u32,
316 Next: u32,316 Next: u32,
...@@ -342,7 +342,7 @@ pub const SectionContrSubstreamVersion = enum(u32) {...@@ -342,7 +342,7 @@ pub const SectionContrSubstreamVersion = enum(u32) {
342 _,342 _,
343};343};
344344
345pub const RecordPrefix = packed struct {345pub const RecordPrefix = extern struct {
346 /// Record length, starting from &RecordKind.346 /// Record length, starting from &RecordKind.
347 RecordLen: u16,347 RecordLen: u16,
348348
...@@ -354,7 +354,7 @@ pub const RecordPrefix = packed struct {...@@ -354,7 +354,7 @@ pub const RecordPrefix = packed struct {
354/// The structure definition follows.354/// The structure definition follows.
355/// LineBlockFragmentHeader Blocks[]355/// LineBlockFragmentHeader Blocks[]
356/// Each `LineBlockFragmentHeader` as specified below.356/// Each `LineBlockFragmentHeader` as specified below.
357pub const LineFragmentHeader = packed struct {357pub const LineFragmentHeader = extern struct {
358 /// Code offset of line contribution.358 /// Code offset of line contribution.
359 RelocOffset: u32,359 RelocOffset: u32,
360360
...@@ -376,7 +376,7 @@ pub const LineFlags = packed struct {...@@ -376,7 +376,7 @@ pub const LineFlags = packed struct {
376/// header. The structure definitions follow.376/// header. The structure definitions follow.
377/// LineNumberEntry Lines[NumLines];377/// LineNumberEntry Lines[NumLines];
378/// ColumnNumberEntry Columns[NumLines];378/// ColumnNumberEntry Columns[NumLines];
379pub const LineBlockFragmentHeader = packed struct {379pub const LineBlockFragmentHeader = extern struct {
380 /// Offset of FileChecksum entry in File380 /// Offset of FileChecksum entry in File
381 /// checksums buffer. The checksum entry then381 /// checksums buffer. The checksum entry then
382 /// contains another offset into the string382 /// contains another offset into the string
...@@ -388,7 +388,7 @@ pub const LineBlockFragmentHeader = packed struct {...@@ -388,7 +388,7 @@ pub const LineBlockFragmentHeader = packed struct {
388 BlockSize: u32,388 BlockSize: u32,
389};389};
390390
391pub const LineNumberEntry = packed struct {391pub const LineNumberEntry = extern struct {
392 /// Offset to start of code bytes for line number392 /// Offset to start of code bytes for line number
393 Offset: u32,393 Offset: u32,
394 Flags: u32,394 Flags: u32,
...@@ -404,13 +404,13 @@ pub const LineNumberEntry = packed struct {...@@ -404,13 +404,13 @@ pub const LineNumberEntry = packed struct {
404 };404 };
405};405};
406406
407pub const ColumnNumberEntry = packed struct {407pub const ColumnNumberEntry = extern struct {
408 StartColumn: u16,408 StartColumn: u16,
409 EndColumn: u16,409 EndColumn: u16,
410};410};
411411
412/// Checksum bytes follow.412/// Checksum bytes follow.
413pub const FileChecksumEntryHeader = packed struct {413pub const FileChecksumEntryHeader = extern struct {
414 /// Byte offset of filename in global string table.414 /// Byte offset of filename in global string table.
415 FileNameOffset: u32,415 FileNameOffset: u32,
416416
...@@ -441,7 +441,7 @@ pub const DebugSubsectionKind = enum(u32) {...@@ -441,7 +441,7 @@ pub const DebugSubsectionKind = enum(u32) {
441 CoffSymbolRVA = 0xfd,441 CoffSymbolRVA = 0xfd,
442};442};
443443
444pub const DebugSubsectionHeader = packed struct {444pub const DebugSubsectionHeader = extern struct {
445 /// codeview::DebugSubsectionKind enum445 /// codeview::DebugSubsectionKind enum
446 Kind: DebugSubsectionKind,446 Kind: DebugSubsectionKind,
447447
...@@ -449,7 +449,7 @@ pub const DebugSubsectionHeader = packed struct {...@@ -449,7 +449,7 @@ pub const DebugSubsectionHeader = packed struct {
449 Length: u32,449 Length: u32,
450};450};
451451
452pub const PDBStringTableHeader = packed struct {452pub const PDBStringTableHeader = extern struct {
453 /// PDBStringTableSignature453 /// PDBStringTableSignature
454 Signature: u32,454 Signature: u32,
455455
...@@ -686,12 +686,12 @@ pub const Pdb = struct {...@@ -686,12 +686,12 @@ pub const Pdb = struct {
686686
687 var symbol_i: usize = 0;687 var symbol_i: usize = 0;
688 while (symbol_i != module.symbols.len) {688 while (symbol_i != module.symbols.len) {
689 const prefix = @ptrCast(*RecordPrefix, &module.symbols[symbol_i]);689 const prefix = @ptrCast(*align(1) RecordPrefix, &module.symbols[symbol_i]);
690 if (prefix.RecordLen < 2)690 if (prefix.RecordLen < 2)
691 return null;691 return null;
692 switch (prefix.RecordKind) {692 switch (prefix.RecordKind) {
693 .S_LPROC32, .S_GPROC32 => {693 .S_LPROC32, .S_GPROC32 => {
694 const proc_sym = @ptrCast(*ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]);694 const proc_sym = @ptrCast(*align(1) ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]);
695 if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) {695 if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) {
696 return mem.sliceTo(@ptrCast([*:0]u8, proc_sym) + @sizeOf(ProcSym), 0);696 return mem.sliceTo(@ptrCast([*:0]u8, proc_sym) + @sizeOf(ProcSym), 0);
697 }697 }
...@@ -712,7 +712,7 @@ pub const Pdb = struct {...@@ -712,7 +712,7 @@ pub const Pdb = struct {
712 var skip_len: usize = undefined;712 var skip_len: usize = undefined;
713 const checksum_offset = module.checksum_offset orelse return error.MissingDebugInfo;713 const checksum_offset = module.checksum_offset orelse return error.MissingDebugInfo;
714 while (sect_offset != subsect_info.len) : (sect_offset += skip_len) {714 while (sect_offset != subsect_info.len) : (sect_offset += skip_len) {
715 const subsect_hdr = @ptrCast(*DebugSubsectionHeader, &subsect_info[sect_offset]);715 const subsect_hdr = @ptrCast(*align(1) DebugSubsectionHeader, &subsect_info[sect_offset]);
716 skip_len = subsect_hdr.Length;716 skip_len = subsect_hdr.Length;
717 sect_offset += @sizeOf(DebugSubsectionHeader);717 sect_offset += @sizeOf(DebugSubsectionHeader);
718718
...@@ -720,7 +720,7 @@ pub const Pdb = struct {...@@ -720,7 +720,7 @@ pub const Pdb = struct {
720 .Lines => {720 .Lines => {
721 var line_index = sect_offset;721 var line_index = sect_offset;
722722
723 const line_hdr = @ptrCast(*LineFragmentHeader, &subsect_info[line_index]);723 const line_hdr = @ptrCast(*align(1) LineFragmentHeader, &subsect_info[line_index]);
724 if (line_hdr.RelocSegment == 0)724 if (line_hdr.RelocSegment == 0)
725 return error.MissingDebugInfo;725 return error.MissingDebugInfo;
726 line_index += @sizeOf(LineFragmentHeader);726 line_index += @sizeOf(LineFragmentHeader);
...@@ -734,7 +734,7 @@ pub const Pdb = struct {...@@ -734,7 +734,7 @@ pub const Pdb = struct {
734 const subsection_end_index = sect_offset + subsect_hdr.Length;734 const subsection_end_index = sect_offset + subsect_hdr.Length;
735735
736 while (line_index < subsection_end_index) {736 while (line_index < subsection_end_index) {
737 const block_hdr = @ptrCast(*LineBlockFragmentHeader, &subsect_info[line_index]);737 const block_hdr = @ptrCast(*align(1) LineBlockFragmentHeader, &subsect_info[line_index]);
738 line_index += @sizeOf(LineBlockFragmentHeader);738 line_index += @sizeOf(LineBlockFragmentHeader);
739 const start_line_index = line_index;739 const start_line_index = line_index;
740740
...@@ -746,7 +746,7 @@ pub const Pdb = struct {...@@ -746,7 +746,7 @@ pub const Pdb = struct {
746 // This is done with a simple linear search.746 // This is done with a simple linear search.
747 var line_i: u32 = 0;747 var line_i: u32 = 0;
748 while (line_i < block_hdr.NumLines) : (line_i += 1) {748 while (line_i < block_hdr.NumLines) : (line_i += 1) {
749 const line_num_entry = @ptrCast(*LineNumberEntry, &subsect_info[line_index]);749 const line_num_entry = @ptrCast(*align(1) LineNumberEntry, &subsect_info[line_index]);
750 line_index += @sizeOf(LineNumberEntry);750 line_index += @sizeOf(LineNumberEntry);
751751
752 const vaddr_start = frag_vaddr_start + line_num_entry.Offset;752 const vaddr_start = frag_vaddr_start + line_num_entry.Offset;
...@@ -758,7 +758,7 @@ pub const Pdb = struct {...@@ -758,7 +758,7 @@ pub const Pdb = struct {
758 // line_i == 0 would mean that no matching LineNumberEntry was found.758 // line_i == 0 would mean that no matching LineNumberEntry was found.
759 if (line_i > 0) {759 if (line_i > 0) {
760 const subsect_index = checksum_offset + block_hdr.NameIndex;760 const subsect_index = checksum_offset + block_hdr.NameIndex;
761 const chksum_hdr = @ptrCast(*FileChecksumEntryHeader, &module.subsect_info[subsect_index]);761 const chksum_hdr = @ptrCast(*align(1) FileChecksumEntryHeader, &module.subsect_info[subsect_index]);
762 const strtab_offset = @sizeOf(PDBStringTableHeader) + chksum_hdr.FileNameOffset;762 const strtab_offset = @sizeOf(PDBStringTableHeader) + chksum_hdr.FileNameOffset;
763 try self.string_table.?.seekTo(strtab_offset);763 try self.string_table.?.seekTo(strtab_offset);
764 const source_file_name = try self.string_table.?.reader().readUntilDelimiterAlloc(self.allocator, 0, 1024);764 const source_file_name = try self.string_table.?.reader().readUntilDelimiterAlloc(self.allocator, 0, 1024);
...@@ -768,12 +768,12 @@ pub const Pdb = struct {...@@ -768,12 +768,12 @@ pub const Pdb = struct {
768 const column = if (has_column) blk: {768 const column = if (has_column) blk: {
769 const start_col_index = start_line_index + @sizeOf(LineNumberEntry) * block_hdr.NumLines;769 const start_col_index = start_line_index + @sizeOf(LineNumberEntry) * block_hdr.NumLines;
770 const col_index = start_col_index + @sizeOf(ColumnNumberEntry) * line_entry_idx;770 const col_index = start_col_index + @sizeOf(ColumnNumberEntry) * line_entry_idx;
771 const col_num_entry = @ptrCast(*ColumnNumberEntry, &subsect_info[col_index]);771 const col_num_entry = @ptrCast(*align(1) ColumnNumberEntry, &subsect_info[col_index]);
772 break :blk col_num_entry.StartColumn;772 break :blk col_num_entry.StartColumn;
773 } else 0;773 } else 0;
774774
775 const found_line_index = start_line_index + line_entry_idx * @sizeOf(LineNumberEntry);775 const found_line_index = start_line_index + line_entry_idx * @sizeOf(LineNumberEntry);
776 const line_num_entry = @ptrCast(*LineNumberEntry, &subsect_info[found_line_index]);776 const line_num_entry = @ptrCast(*align(1) LineNumberEntry, &subsect_info[found_line_index]);
777 const flags = @ptrCast(*LineNumberEntry.Flags, &line_num_entry.Flags);777 const flags = @ptrCast(*LineNumberEntry.Flags, &line_num_entry.Flags);
778778
779 return debug.LineInfo{779 return debug.LineInfo{
...@@ -833,7 +833,7 @@ pub const Pdb = struct {...@@ -833,7 +833,7 @@ pub const Pdb = struct {
833 var sect_offset: usize = 0;833 var sect_offset: usize = 0;
834 var skip_len: usize = undefined;834 var skip_len: usize = undefined;
835 while (sect_offset != mod.subsect_info.len) : (sect_offset += skip_len) {835 while (sect_offset != mod.subsect_info.len) : (sect_offset += skip_len) {
836 const subsect_hdr = @ptrCast(*DebugSubsectionHeader, &mod.subsect_info[sect_offset]);836 const subsect_hdr = @ptrCast(*align(1) DebugSubsectionHeader, &mod.subsect_info[sect_offset]);
837 skip_len = subsect_hdr.Length;837 skip_len = subsect_hdr.Length;
838 sect_offset += @sizeOf(DebugSubsectionHeader);838 sect_offset += @sizeOf(DebugSubsectionHeader);
839839
...@@ -969,7 +969,7 @@ fn blockCountFromSize(size: u32, block_size: u32) u32 {...@@ -969,7 +969,7 @@ fn blockCountFromSize(size: u32, block_size: u32) u32 {
969}969}
970970
971// https://llvm.org/docs/PDB/MsfFile.html#the-superblock971// https://llvm.org/docs/PDB/MsfFile.html#the-superblock
972const SuperBlock = packed struct {972const SuperBlock = extern struct {
973 /// The LLVM docs list a space between C / C++ but empirically this is not the case.973 /// The LLVM docs list a space between C / C++ but empirically this is not the case.
974 const file_magic = "Microsoft C/C++ MSF 7.00\r\n\x1a\x44\x53\x00\x00\x00";974 const file_magic = "Microsoft C/C++ MSF 7.00\r\n\x1a\x44\x53\x00\x00\x00";
975975