authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-08 10:37:21+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-09 09:24:25+01:00
log4bb66b63ba108a1c7e5c920348d72ed1e169fd99
tree4b668e4283f3b6a9ba51bef5786aeb4903b66028
parent05e221796a7c60f26c4c7bc996f12e1392c83d97

macho: add helper for getting ptr to DebugSymbols


2 files changed, 18 insertions(+), 25 deletions(-)

src/link/Dwarf.zig+13-25
......@@ -1104,8 +1104,7 @@ pub fn commitDeclState(
11041104 try pwriteDbgLineNops(elf_file.base.file.?, file_pos, 0, &[0]u8{}, src_fn.len);
11051105 },
11061106 .macho => {
1107 const macho_file = self.bin_file.cast(File.MachO).?;
1108 const d_sym = &macho_file.d_sym.?;
1107 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
11091108 const debug_line_sect = d_sym.getSectionPtr(d_sym.debug_line_section_index.?);
11101109 const file_pos = debug_line_sect.offset + src_fn.off;
11111110 try pwriteDbgLineNops(d_sym.file, file_pos, 0, &[0]u8{}, src_fn.len);
......@@ -1327,8 +1326,7 @@ pub fn commitDeclState(
13271326 while (decl_state.exprloc_relocs.popOrNull()) |reloc| {
13281327 switch (self.bin_file.tag) {
13291328 .macho => {
1330 const macho_file = self.bin_file.cast(File.MachO).?;
1331 const d_sym = &macho_file.d_sym.?;
1329 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
13321330 try d_sym.relocs.append(d_sym.allocator, .{
13331331 .type = switch (reloc.type) {
13341332 .direct_load => .direct_load,
......@@ -1379,8 +1377,7 @@ fn updateDeclDebugInfoAllocation(self: *Dwarf, atom: *Atom, len: u32) !void {
13791377 try pwriteDbgInfoNops(elf_file.base.file.?, file_pos, 0, &[0]u8{}, atom.len, false);
13801378 },
13811379 .macho => {
1382 const macho_file = self.bin_file.cast(File.MachO).?;
1383 const d_sym = &macho_file.d_sym.?;
1380 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
13841381 const debug_info_sect = d_sym.getSectionPtr(d_sym.debug_info_section_index.?);
13851382 const file_pos = debug_info_sect.offset + atom.off;
13861383 try pwriteDbgInfoNops(d_sym.file, file_pos, 0, &[0]u8{}, atom.len, false);
......@@ -1475,8 +1472,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom: *Atom, dbg_info_buf: []const u8) !void
14751472 },
14761473
14771474 .macho => {
1478 const macho_file = self.bin_file.cast(File.MachO).?;
1479 const d_sym = &macho_file.d_sym.?;
1475 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
14801476 const sect_index = d_sym.debug_info_section_index.?;
14811477 try d_sym.growSection(sect_index, needed_size);
14821478 const sect = d_sym.getSection(sect_index);
......@@ -1544,9 +1540,8 @@ pub fn updateDeclLineNumber(self: *Dwarf, decl: *const Module.Decl) !void {
15441540 try elf_file.base.file.?.pwriteAll(&data, file_pos);
15451541 },
15461542 .macho => {
1547 const macho_file = self.bin_file.cast(File.MachO).?;
1548 const d_sym = macho_file.d_sym.?;
1549 const sect = d_sym.sections.items[d_sym.debug_line_section_index.?];
1543 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
1544 const sect = d_sym.getSection(d_sym.debug_line_section_index.?);
15501545 const file_pos = sect.offset + decl.fn_link.macho.off + self.getRelocDbgLineOff();
15511546 try d_sym.file.pwriteAll(&data, file_pos);
15521547 },
......@@ -1769,8 +1764,7 @@ pub fn writeDbgAbbrev(self: *Dwarf) !void {
17691764 try elf_file.base.file.?.pwriteAll(&abbrev_buf, file_pos);
17701765 },
17711766 .macho => {
1772 const macho_file = self.bin_file.cast(File.MachO).?;
1773 const d_sym = &macho_file.d_sym.?;
1767 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
17741768 const dwarf_segment = d_sym.segments.items[d_sym.dwarf_segment_cmd_index.?];
17751769 const debug_abbrev_sect = &d_sym.sections.items[d_sym.debug_abbrev_section_index.?];
17761770 const allocated_size = d_sym.allocatedSize(debug_abbrev_sect.offset);
......@@ -1895,8 +1889,7 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u
18951889 try pwriteDbgInfoNops(elf_file.base.file.?, file_pos, 0, di_buf.items, jmp_amt, false);
18961890 },
18971891 .macho => {
1898 const macho_file = self.bin_file.cast(File.MachO).?;
1899 const d_sym = &macho_file.d_sym.?;
1892 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
19001893 const debug_info_sect = d_sym.getSection(d_sym.debug_info_section_index.?);
19011894 const file_pos = debug_info_sect.offset;
19021895 try pwriteDbgInfoNops(d_sym.file, file_pos, 0, di_buf.items, jmp_amt, false);
......@@ -2227,8 +2220,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {
22272220 try elf_file.base.file.?.pwriteAll(di_buf.items, file_pos);
22282221 },
22292222 .macho => {
2230 const macho_file = self.bin_file.cast(File.MachO).?;
2231 const d_sym = &macho_file.d_sym.?;
2223 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
22322224 const dwarf_seg = d_sym.segments.items[d_sym.dwarf_segment_cmd_index.?];
22332225 const debug_aranges_sect = &d_sym.sections.items[d_sym.debug_aranges_section_index.?];
22342226 const allocated_size = d_sym.allocatedSize(debug_aranges_sect.offset);
......@@ -2385,8 +2377,7 @@ pub fn writeDbgLineHeader(self: *Dwarf, module: *Module) !void {
23852377 const needed_with_padding = padToIdeal(needed_bytes);
23862378 const delta = needed_with_padding - dbg_line_prg_off;
23872379
2388 const macho_file = self.bin_file.cast(File.MachO).?;
2389 const d_sym = &macho_file.d_sym.?;
2380 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
23902381 const debug_line_sect = d_sym.getSectionPtr(d_sym.debug_line_section_index.?);
23912382 const needed_size = debug_line_sect.size + delta;
23922383
......@@ -2442,8 +2433,7 @@ pub fn writeDbgLineHeader(self: *Dwarf, module: *Module) !void {
24422433 try pwriteDbgLineNops(elf_file.base.file.?, file_pos, 0, di_buf.items, jmp_amt);
24432434 },
24442435 .macho => {
2445 const macho_file = self.bin_file.cast(File.MachO).?;
2446 const d_sym = &macho_file.d_sym.?;
2436 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
24472437 const debug_line_sect = d_sym.getSection(d_sym.debug_line_section_index.?);
24482438 const file_pos = debug_line_sect.offset;
24492439 try pwriteDbgLineNops(d_sym.file, file_pos, 0, di_buf.items, jmp_amt);
......@@ -2585,8 +2575,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {
25852575 break :blk debug_info_sect.sh_offset;
25862576 },
25872577 .macho => {
2588 const macho_file = self.bin_file.cast(File.MachO).?;
2589 const d_sym = &macho_file.d_sym.?;
2578 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
25902579 const debug_info_sect = d_sym.getSectionPtr(d_sym.debug_info_section_index.?);
25912580 break :blk debug_info_sect.offset;
25922581 },
......@@ -2606,8 +2595,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {
26062595 try elf_file.base.file.?.pwriteAll(&buf, file_pos + reloc.atom.off + reloc.offset);
26072596 },
26082597 .macho => {
2609 const macho_file = self.bin_file.cast(File.MachO).?;
2610 const d_sym = &macho_file.d_sym.?;
2598 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
26112599 try d_sym.file.pwriteAll(&buf, file_pos + reloc.atom.off + reloc.offset);
26122600 },
26132601 .wasm => {
src/link/MachO.zig+5
......@@ -4300,6 +4300,11 @@ pub fn getEntryPoint(self: MachO) error{MissingMainEntrypoint}!SymbolWithLoc {
43004300 return global;
43014301}
43024302
4303pub fn getDebugSymbols(self: *MachO) ?*DebugSymbols {
4304 if (self.d_sym == null) return null;
4305 return &self.d_sym.?;
4306}
4307
43034308pub fn findFirst(comptime T: type, haystack: []align(1) const T, start: usize, predicate: anytype) usize {
43044309 if (!@hasDecl(@TypeOf(predicate), "predicate"))
43054310 @compileError("Predicate is required to define fn predicate(@This(), T) bool");