authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-29 23:39:58+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-31 10:19:04+01:00
log9318656ce297de09b1247fde300ad2f794d51feb
tree18f6e07d113cdc2bffa22d2a6f8957f672a7154e
parent2875a7335aa5363303019dae8b837036ed547d53

macho: use 32bit DWARF format


1 files changed, 12 insertions(+), 15 deletions(-)

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