| ... | ... | @@ -351,7 +351,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 351 | 351 | // TODO This linker code currently assumes there is only 1 compilation unit and it corresponds to the |
| 352 | 352 | // Zig source code. |
| 353 | 353 | const module = options.module orelse return error.LinkingWithoutZigSourceUnimplemented; |
| 354 | | const init_len_size: usize = 12; |
| 354 | const init_len_size: usize = 4; |
| 355 | 355 | |
| 356 | 356 | if (self.debug_abbrev_section_dirty) { |
| 357 | 357 | const dwarf_segment = &self.load_commands.items[self.dwarf_segment_cmd_index.?].Segment; |
| ... | ... | @@ -450,11 +450,10 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 450 | 450 | // +1 for the final 0 that ends the compilation unit children. |
| 451 | 451 | const dbg_info_end = last_dbg_info_decl.dbg_info_off + last_dbg_info_decl.dbg_info_len + 1; |
| 452 | 452 | const init_len = dbg_info_end - after_init_len; |
| 453 | | di_buf.appendNTimesAssumeCapacity(0xff, 4); |
| 454 | | mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), init_len); |
| 453 | mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, init_len)); |
| 455 | 454 | mem.writeIntLittle(u16, di_buf.addManyAsArrayAssumeCapacity(2), 4); // DWARF version |
| 456 | 455 | const abbrev_offset = self.debug_abbrev_table_offset.?; |
| 457 | | mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), abbrev_offset); |
| 456 | mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, abbrev_offset)); |
| 458 | 457 | di_buf.appendAssumeCapacity(8); // address size |
| 459 | 458 | // Write the form for the compile unit, which must match the abbrev table above. |
| 460 | 459 | const name_strp = try self.makeDebugString(allocator, module.root_pkg.root_src_path); |
| ... | ... | @@ -468,12 +467,12 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 468 | 467 | const high_pc = text_section.addr + text_section.size; |
| 469 | 468 | |
| 470 | 469 | di_buf.appendAssumeCapacity(abbrev_compile_unit); |
| 471 | | mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), 0); // DW.AT_stmt_list, DW.FORM_sec_offset |
| 470 | mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), 0); // DW.AT_stmt_list, DW.FORM_sec_offset |
| 472 | 471 | mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), low_pc); |
| 473 | 472 | mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), high_pc); |
| 474 | | mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), name_strp); |
| 475 | | mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), comp_dir_strp); |
| 476 | | mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), producer_strp); |
| 473 | mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, name_strp)); |
| 474 | mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, comp_dir_strp)); |
| 475 | mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, producer_strp)); |
| 477 | 476 | // We are still waiting on dwarf-std.org to assign DW_LANG_Zig a number: |
| 478 | 477 | // http://dwarfstd.org/ShowIssue.php?issue=171115.1 |
| 479 | 478 | // Until then we say it is C99. |
| ... | ... | @@ -509,7 +508,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 509 | 508 | mem.writeIntLittle(u16, di_buf.addManyAsArrayAssumeCapacity(2), 2); // version |
| 510 | 509 | // When more than one compilation unit is supported, this will be the offset to it. |
| 511 | 510 | // For now it is always at offset 0 in .debug_info. |
| 512 | | mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), debug_info_sect.addr); // __debug_info offset |
| 511 | mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), 0); // __debug_info offset |
| 513 | 512 | di_buf.appendAssumeCapacity(@sizeOf(u64)); // address_size |
| 514 | 513 | di_buf.appendAssumeCapacity(0); // segment_selector_size |
| 515 | 514 | |
| ... | ... | @@ -532,8 +531,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 532 | 531 | const init_len = di_buf.items.len - after_init_len; |
| 533 | 532 | // initial length - length of the .debug_aranges contribution for this compilation unit, |
| 534 | 533 | // not including the initial length itself. |
| 535 | | di_buf.items[init_len_index..][0..4].* = [_]u8{ 0xff, 0xff, 0xff, 0xff }; |
| 536 | | mem.writeIntLittle(u64, di_buf.items[init_len_index + 4 ..][0..8], init_len); |
| 534 | mem.writeIntLittle(u32, di_buf.items[init_len_index..][0..4], @intCast(u32, init_len)); |
| 537 | 535 | |
| 538 | 536 | const needed_size = di_buf.items.len; |
| 539 | 537 | const allocated_size = dwarf_segment.allocatedSize(debug_aranges_sect.offset); |
| ... | ... | @@ -576,8 +574,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 576 | 574 | // not including the initial length itself. |
| 577 | 575 | const after_init_len = di_buf.items.len + init_len_size; |
| 578 | 576 | const init_len = dbg_line_prg_end - after_init_len; |
| 579 | | di_buf.appendNTimesAssumeCapacity(0xff, 4); |
| 580 | | mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), init_len); |
| 577 | mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, init_len)); |
| 581 | 578 | mem.writeIntLittle(u16, di_buf.addManyAsArrayAssumeCapacity(2), 4); // version |
| 582 | 579 | |
| 583 | 580 | // Empirically, debug info consumers do not respect this field, or otherwise |
| ... | ... | @@ -585,7 +582,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 585 | 582 | // Therefore we rely on the NOP jump at the beginning of the Line Number Program for |
| 586 | 583 | // padding rather than this field. |
| 587 | 584 | const before_header_len = di_buf.items.len; |
| 588 | | di_buf.items.len += @sizeOf(u64); // We will come back and write this. |
| 585 | di_buf.items.len += @sizeOf(u32); // We will come back and write this. |
| 589 | 586 | const after_header_len = di_buf.items.len; |
| 590 | 587 | |
| 591 | 588 | const opcode_base = DW.LNS_set_isa + 1; |
| ... | ... | @@ -624,7 +621,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 624 | 621 | }); |
| 625 | 622 | |
| 626 | 623 | const header_len = di_buf.items.len - after_header_len; |
| 627 | | mem.writeIntLittle(u64, di_buf.items[before_header_len..][0..8], header_len); |
| 624 | mem.writeIntLittle(u32, di_buf.items[before_header_len..][0..4], @intCast(u32, header_len)); |
| 628 | 625 | |
| 629 | 626 | // We use NOPs because consumers empirically do not respect the header length field. |
| 630 | 627 | if (di_buf.items.len > dbg_line_prg_off) { |