authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-04 13:13:50+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-04 16:58:45+01:00
log280dad0283652aa176d0a67b8d90e9edc0869c5b
tree3d613b0c13dab58e83c5b67044383706fac4999e
parentaa8b26cf25c0d0e5e50d51f993147be8773a9c1e

dsym+dwarf: remove copyRangeAllOverlappingAlloc


2 files changed, 10 insertions(+), 42 deletions(-)

src/link/Dwarf.zig+10-29
......@@ -1163,32 +1163,28 @@ pub fn commitDeclState(
11631163 next_padding_size,
11641164 );
11651165 },
1166
11661167 .macho => {
11671168 const macho_file = file.cast(File.MachO).?;
11681169 const d_sym = &macho_file.d_sym.?;
1169 const dwarf_segment = d_sym.segments.items[d_sym.dwarf_segment_cmd_index.?];
11701170 const debug_line_sect = &d_sym.sections.items[d_sym.debug_line_section_index.?];
11711171 if (needed_size != debug_line_sect.size) {
11721172 if (needed_size > d_sym.allocatedSize(debug_line_sect.offset)) {
11731173 const new_offset = d_sym.findFreeSpace(needed_size, 1);
11741174 const existing_size = last_src_fn.off;
1175
11761175 log.debug("moving __debug_line section: {} bytes from 0x{x} to 0x{x}", .{
11771176 existing_size,
11781177 debug_line_sect.offset,
11791178 new_offset,
11801179 });
1181
1182 try copyRangeAllOverlappingAlloc(
1183 gpa,
1184 d_sym.file,
1180 const amt = try d_sym.file.copyRangeAll(
11851181 debug_line_sect.offset,
1182 d_sym.file,
11861183 new_offset,
11871184 existing_size,
11881185 );
1189
1186 if (amt != existing_size) return error.InputOutput;
11901187 debug_line_sect.offset = @intCast(u32, new_offset);
1191 debug_line_sect.addr = dwarf_segment.vmaddr + new_offset - dwarf_segment.fileoff;
11921188 }
11931189 debug_line_sect.size = needed_size;
11941190 d_sym.debug_line_header_dirty = true;
......@@ -1202,6 +1198,7 @@ pub fn commitDeclState(
12021198 next_padding_size,
12031199 );
12041200 },
1201
12051202 .wasm => {
12061203 const wasm_file = file.cast(File.Wasm).?;
12071204 const atom = wasm_file.debug_line_atom.?;
......@@ -1462,32 +1459,28 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co
14621459 trailing_zero,
14631460 );
14641461 },
1462
14651463 .macho => {
14661464 const macho_file = file.cast(File.MachO).?;
14671465 const d_sym = &macho_file.d_sym.?;
1468 const dwarf_segment = d_sym.segments.items[d_sym.dwarf_segment_cmd_index.?];
14691466 const debug_info_sect = &d_sym.sections.items[d_sym.debug_info_section_index.?];
14701467 if (needed_size != debug_info_sect.size) {
14711468 if (needed_size > d_sym.allocatedSize(debug_info_sect.offset)) {
14721469 const new_offset = d_sym.findFreeSpace(needed_size, 1);
14731470 const existing_size = last_decl.off;
1474
14751471 log.debug("moving __debug_info section: {} bytes from 0x{x} to 0x{x}", .{
14761472 existing_size,
14771473 debug_info_sect.offset,
14781474 new_offset,
14791475 });
1480
1481 try copyRangeAllOverlappingAlloc(
1482 gpa,
1483 d_sym.file,
1476 const amt = try d_sym.file.copyRangeAll(
14841477 debug_info_sect.offset,
1478 d_sym.file,
14851479 new_offset,
14861480 existing_size,
14871481 );
1488
1482 if (amt != existing_size) return error.InputOutput;
14891483 debug_info_sect.offset = @intCast(u32, new_offset);
1490 debug_info_sect.addr = dwarf_segment.vmaddr + new_offset - dwarf_segment.fileoff;
14911484 }
14921485 debug_info_sect.size = needed_size;
14931486 d_sym.debug_info_header_dirty = true;
......@@ -1502,6 +1495,7 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co
15021495 trailing_zero,
15031496 );
15041497 },
1498
15051499 .wasm => {
15061500 const wasm_file = file.cast(File.Wasm).?;
15071501 const info_atom = wasm_file.debug_info_atom.?;
......@@ -2569,16 +2563,3 @@ fn addDbgInfoErrorSet(
25692563 // DW.AT.enumeration_type delimit children
25702564 try dbg_info_buffer.append(0);
25712565}
2572
2573fn copyRangeAllOverlappingAlloc(
2574 allocator: Allocator,
2575 file: std.fs.File,
2576 in_offset: u64,
2577 out_offset: u64,
2578 len: usize,
2579) !void {
2580 const buf = try allocator.alloc(u8, len);
2581 defer allocator.free(buf);
2582 const amt = try file.preadAll(buf, in_offset);
2583 try file.pwriteAll(buf[0..amt], out_offset);
2584}
src/link/MachO/DebugSymbols.zig-13
......@@ -537,19 +537,6 @@ fn writeStrtab(self: *DebugSymbols, lc: *macho.symtab_command) !void {
537537 }
538538}
539539
540fn copyRangeAllOverlappingAlloc(
541 allocator: Allocator,
542 file: std.fs.File,
543 in_offset: u64,
544 out_offset: u64,
545 len: usize,
546) !void {
547 const buf = try allocator.alloc(u8, len);
548 defer allocator.free(buf);
549 const amt = try file.preadAll(buf, in_offset);
550 try file.pwriteAll(buf[0..amt], out_offset);
551}
552
553540pub fn getSectionIndexes(self: *DebugSymbols, segment_index: u8) struct { start: u8, end: u8 } {
554541 var start: u8 = 0;
555542 const nsects = for (self.segments.items) |seg, i| {