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
351351 // TODO This linker code currently assumes there is only 1 compilation unit and it corresponds to the
352352 // Zig source code.
353353 const module = options.module orelse return error.LinkingWithoutZigSourceUnimplemented;
354 const init_len_size: usize = 12;
354 const init_len_size: usize = 4;
355355
356356 if (self.debug_abbrev_section_dirty) {
357357 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
450450 // +1 for the final 0 that ends the compilation unit children.
451451 const dbg_info_end = last_dbg_info_decl.dbg_info_off + last_dbg_info_decl.dbg_info_len + 1;
452452 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));
455454 mem.writeIntLittle(u16, di_buf.addManyAsArrayAssumeCapacity(2), 4); // DWARF version
456455 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));
458457 di_buf.appendAssumeCapacity(8); // address size
459458 // Write the form for the compile unit, which must match the abbrev table above.
460459 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
468467 const high_pc = text_section.addr + text_section.size;
469468
470469 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
472471 mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), low_pc);
473472 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));
477476 // We are still waiting on dwarf-std.org to assign DW_LANG_Zig a number:
478477 // http://dwarfstd.org/ShowIssue.php?issue=171115.1
479478 // Until then we say it is C99.
......@@ -509,7 +508,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt
509508 mem.writeIntLittle(u16, di_buf.addManyAsArrayAssumeCapacity(2), 2); // version
510509 // When more than one compilation unit is supported, this will be the offset to it.
511510 // 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
513512 di_buf.appendAssumeCapacity(@sizeOf(u64)); // address_size
514513 di_buf.appendAssumeCapacity(0); // segment_selector_size
515514
......@@ -532,8 +531,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt
532531 const init_len = di_buf.items.len - after_init_len;
533532 // initial length - length of the .debug_aranges contribution for this compilation unit,
534533 // 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));
537535
538536 const needed_size = di_buf.items.len;
539537 const allocated_size = dwarf_segment.allocatedSize(debug_aranges_sect.offset);
......@@ -576,8 +574,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt
576574 // not including the initial length itself.
577575 const after_init_len = di_buf.items.len + init_len_size;
578576 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));
581578 mem.writeIntLittle(u16, di_buf.addManyAsArrayAssumeCapacity(2), 4); // version
582579
583580 // 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
585582 // Therefore we rely on the NOP jump at the beginning of the Line Number Program for
586583 // padding rather than this field.
587584 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.
589586 const after_header_len = di_buf.items.len;
590587
591588 const opcode_base = DW.LNS_set_isa + 1;
......@@ -624,7 +621,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt
624621 });
625622
626623 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
629626 // We use NOPs because consumers empirically do not respect the header length field.
630627 if (di_buf.items.len > dbg_line_prg_off) {