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;
1414// documentation and/or contributors.
1515
1616// https://llvm.org/docs/PDB/DbiStream.html#stream-header
17pub const DbiStreamHeader = packed struct {
17pub const DbiStreamHeader = extern struct {
1818 VersionSignature: i32,
1919 VersionHeader: u32,
2020 Age: u32,
......@@ -37,7 +37,7 @@ pub const DbiStreamHeader = packed struct {
3737 Padding: u32,
3838};
3939
40pub const SectionContribEntry = packed struct {
40pub const SectionContribEntry = extern struct {
4141 /// COFF Section index, 1-based
4242 Section: u16,
4343 Padding1: [2]u8,
......@@ -50,7 +50,7 @@ pub const SectionContribEntry = packed struct {
5050 RelocCrc: u32,
5151};
5252
53pub const ModInfo = packed struct {
53pub const ModInfo = extern struct {
5454 Unused1: u32,
5555 SectionContr: SectionContribEntry,
5656 Flags: u16,
......@@ -68,7 +68,7 @@ pub const ModInfo = packed struct {
6868 //ObjFileName: char[],
6969};
7070
71pub const SectionMapHeader = packed struct {
71pub const SectionMapHeader = extern struct {
7272 /// Number of segment descriptors
7373 Count: u16,
7474
......@@ -76,7 +76,7 @@ pub const SectionMapHeader = packed struct {
7676 LogCount: u16,
7777};
7878
79pub const SectionMapEntry = packed struct {
79pub const SectionMapEntry = extern struct {
8080 /// See the SectionMapEntryFlags enum below.
8181 Flags: u16,
8282
......@@ -310,7 +310,7 @@ pub const SymbolKind = enum(u16) {
310310
311311pub const TypeIndex = u32;
312312
313pub const ProcSym = packed struct {
313pub const ProcSym = extern struct {
314314 Parent: u32,
315315 End: u32,
316316 Next: u32,
......@@ -342,7 +342,7 @@ pub const SectionContrSubstreamVersion = enum(u32) {
342342 _,
343343};
344344
345pub const RecordPrefix = packed struct {
345pub const RecordPrefix = extern struct {
346346 /// Record length, starting from &RecordKind.
347347 RecordLen: u16,
348348
......@@ -354,7 +354,7 @@ pub const RecordPrefix = packed struct {
354354/// The structure definition follows.
355355/// LineBlockFragmentHeader Blocks[]
356356/// Each `LineBlockFragmentHeader` as specified below.
357pub const LineFragmentHeader = packed struct {
357pub const LineFragmentHeader = extern struct {
358358 /// Code offset of line contribution.
359359 RelocOffset: u32,
360360
......@@ -376,7 +376,7 @@ pub const LineFlags = packed struct {
376376/// header. The structure definitions follow.
377377/// LineNumberEntry Lines[NumLines];
378378/// ColumnNumberEntry Columns[NumLines];
379pub const LineBlockFragmentHeader = packed struct {
379pub const LineBlockFragmentHeader = extern struct {
380380 /// Offset of FileChecksum entry in File
381381 /// checksums buffer. The checksum entry then
382382 /// contains another offset into the string
......@@ -388,7 +388,7 @@ pub const LineBlockFragmentHeader = packed struct {
388388 BlockSize: u32,
389389};
390390
391pub const LineNumberEntry = packed struct {
391pub const LineNumberEntry = extern struct {
392392 /// Offset to start of code bytes for line number
393393 Offset: u32,
394394 Flags: u32,
......@@ -404,13 +404,13 @@ pub const LineNumberEntry = packed struct {
404404 };
405405};
406406
407pub const ColumnNumberEntry = packed struct {
407pub const ColumnNumberEntry = extern struct {
408408 StartColumn: u16,
409409 EndColumn: u16,
410410};
411411
412412/// Checksum bytes follow.
413pub const FileChecksumEntryHeader = packed struct {
413pub const FileChecksumEntryHeader = extern struct {
414414 /// Byte offset of filename in global string table.
415415 FileNameOffset: u32,
416416
......@@ -441,7 +441,7 @@ pub const DebugSubsectionKind = enum(u32) {
441441 CoffSymbolRVA = 0xfd,
442442};
443443
444pub const DebugSubsectionHeader = packed struct {
444pub const DebugSubsectionHeader = extern struct {
445445 /// codeview::DebugSubsectionKind enum
446446 Kind: DebugSubsectionKind,
447447
......@@ -449,7 +449,7 @@ pub const DebugSubsectionHeader = packed struct {
449449 Length: u32,
450450};
451451
452pub const PDBStringTableHeader = packed struct {
452pub const PDBStringTableHeader = extern struct {
453453 /// PDBStringTableSignature
454454 Signature: u32,
455455
......@@ -686,12 +686,12 @@ pub const Pdb = struct {
686686
687687 var symbol_i: usize = 0;
688688 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]);
690690 if (prefix.RecordLen < 2)
691691 return null;
692692 switch (prefix.RecordKind) {
693693 .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)]);
695695 if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) {
696696 return mem.sliceTo(@ptrCast([*:0]u8, proc_sym) + @sizeOf(ProcSym), 0);
697697 }
......@@ -712,7 +712,7 @@ pub const Pdb = struct {
712712 var skip_len: usize = undefined;
713713 const checksum_offset = module.checksum_offset orelse return error.MissingDebugInfo;
714714 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]);
716716 skip_len = subsect_hdr.Length;
717717 sect_offset += @sizeOf(DebugSubsectionHeader);
718718
......@@ -720,7 +720,7 @@ pub const Pdb = struct {
720720 .Lines => {
721721 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]);
724724 if (line_hdr.RelocSegment == 0)
725725 return error.MissingDebugInfo;
726726 line_index += @sizeOf(LineFragmentHeader);
......@@ -734,7 +734,7 @@ pub const Pdb = struct {
734734 const subsection_end_index = sect_offset + subsect_hdr.Length;
735735
736736 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]);
738738 line_index += @sizeOf(LineBlockFragmentHeader);
739739 const start_line_index = line_index;
740740
......@@ -746,7 +746,7 @@ pub const Pdb = struct {
746746 // This is done with a simple linear search.
747747 var line_i: u32 = 0;
748748 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]);
750750 line_index += @sizeOf(LineNumberEntry);
751751
752752 const vaddr_start = frag_vaddr_start + line_num_entry.Offset;
......@@ -758,7 +758,7 @@ pub const Pdb = struct {
758758 // line_i == 0 would mean that no matching LineNumberEntry was found.
759759 if (line_i > 0) {
760760 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]);
762762 const strtab_offset = @sizeOf(PDBStringTableHeader) + chksum_hdr.FileNameOffset;
763763 try self.string_table.?.seekTo(strtab_offset);
764764 const source_file_name = try self.string_table.?.reader().readUntilDelimiterAlloc(self.allocator, 0, 1024);
......@@ -768,12 +768,12 @@ pub const Pdb = struct {
768768 const column = if (has_column) blk: {
769769 const start_col_index = start_line_index + @sizeOf(LineNumberEntry) * block_hdr.NumLines;
770770 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]);
772772 break :blk col_num_entry.StartColumn;
773773 } else 0;
774774
775775 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]);
777777 const flags = @ptrCast(*LineNumberEntry.Flags, &line_num_entry.Flags);
778778
779779 return debug.LineInfo{
......@@ -833,7 +833,7 @@ pub const Pdb = struct {
833833 var sect_offset: usize = 0;
834834 var skip_len: usize = undefined;
835835 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]);
837837 skip_len = subsect_hdr.Length;
838838 sect_offset += @sizeOf(DebugSubsectionHeader);
839839
......@@ -969,7 +969,7 @@ fn blockCountFromSize(size: u32, block_size: u32) u32 {
969969}
970970
971971// https://llvm.org/docs/PDB/MsfFile.html#the-superblock
972const SuperBlock = packed struct {
972const SuperBlock = extern struct {
973973 /// The LLVM docs list a space between C / C++ but empirically this is not the case.
974974 const file_magic = "Microsoft C/C++ MSF 7.00\r\n\x1a\x44\x53\x00\x00\x00";
975975