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(...@@ -1163,32 +1163,28 @@ pub fn commitDeclState(
1163 next_padding_size,1163 next_padding_size,
1164 );1164 );
1165 },1165 },
1166
1166 .macho => {1167 .macho => {
1167 const macho_file = file.cast(File.MachO).?;1168 const macho_file = file.cast(File.MachO).?;
1168 const d_sym = &macho_file.d_sym.?;1169 const d_sym = &macho_file.d_sym.?;
1169 const dwarf_segment = d_sym.segments.items[d_sym.dwarf_segment_cmd_index.?];
1170 const debug_line_sect = &d_sym.sections.items[d_sym.debug_line_section_index.?];1170 const debug_line_sect = &d_sym.sections.items[d_sym.debug_line_section_index.?];
1171 if (needed_size != debug_line_sect.size) {1171 if (needed_size != debug_line_sect.size) {
1172 if (needed_size > d_sym.allocatedSize(debug_line_sect.offset)) {1172 if (needed_size > d_sym.allocatedSize(debug_line_sect.offset)) {
1173 const new_offset = d_sym.findFreeSpace(needed_size, 1);1173 const new_offset = d_sym.findFreeSpace(needed_size, 1);
1174 const existing_size = last_src_fn.off;1174 const existing_size = last_src_fn.off;
1175
1176 log.debug("moving __debug_line section: {} bytes from 0x{x} to 0x{x}", .{1175 log.debug("moving __debug_line section: {} bytes from 0x{x} to 0x{x}", .{
1177 existing_size,1176 existing_size,
1178 debug_line_sect.offset,1177 debug_line_sect.offset,
1179 new_offset,1178 new_offset,
1180 });1179 });
11811180 const amt = try d_sym.file.copyRangeAll(
1182 try copyRangeAllOverlappingAlloc(
1183 gpa,
1184 d_sym.file,
1185 debug_line_sect.offset,1181 debug_line_sect.offset,
1182 d_sym.file,
1186 new_offset,1183 new_offset,
1187 existing_size,1184 existing_size,
1188 );1185 );
11891186 if (amt != existing_size) return error.InputOutput;
1190 debug_line_sect.offset = @intCast(u32, new_offset);1187 debug_line_sect.offset = @intCast(u32, new_offset);
1191 debug_line_sect.addr = dwarf_segment.vmaddr + new_offset - dwarf_segment.fileoff;
1192 }1188 }
1193 debug_line_sect.size = needed_size;1189 debug_line_sect.size = needed_size;
1194 d_sym.debug_line_header_dirty = true;1190 d_sym.debug_line_header_dirty = true;
...@@ -1202,6 +1198,7 @@ pub fn commitDeclState(...@@ -1202,6 +1198,7 @@ pub fn commitDeclState(
1202 next_padding_size,1198 next_padding_size,
1203 );1199 );
1204 },1200 },
1201
1205 .wasm => {1202 .wasm => {
1206 const wasm_file = file.cast(File.Wasm).?;1203 const wasm_file = file.cast(File.Wasm).?;
1207 const atom = wasm_file.debug_line_atom.?;1204 const atom = wasm_file.debug_line_atom.?;
...@@ -1462,32 +1459,28 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co...@@ -1462,32 +1459,28 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co
1462 trailing_zero,1459 trailing_zero,
1463 );1460 );
1464 },1461 },
1462
1465 .macho => {1463 .macho => {
1466 const macho_file = file.cast(File.MachO).?;1464 const macho_file = file.cast(File.MachO).?;
1467 const d_sym = &macho_file.d_sym.?;1465 const d_sym = &macho_file.d_sym.?;
1468 const dwarf_segment = d_sym.segments.items[d_sym.dwarf_segment_cmd_index.?];
1469 const debug_info_sect = &d_sym.sections.items[d_sym.debug_info_section_index.?];1466 const debug_info_sect = &d_sym.sections.items[d_sym.debug_info_section_index.?];
1470 if (needed_size != debug_info_sect.size) {1467 if (needed_size != debug_info_sect.size) {
1471 if (needed_size > d_sym.allocatedSize(debug_info_sect.offset)) {1468 if (needed_size > d_sym.allocatedSize(debug_info_sect.offset)) {
1472 const new_offset = d_sym.findFreeSpace(needed_size, 1);1469 const new_offset = d_sym.findFreeSpace(needed_size, 1);
1473 const existing_size = last_decl.off;1470 const existing_size = last_decl.off;
1474
1475 log.debug("moving __debug_info section: {} bytes from 0x{x} to 0x{x}", .{1471 log.debug("moving __debug_info section: {} bytes from 0x{x} to 0x{x}", .{
1476 existing_size,1472 existing_size,
1477 debug_info_sect.offset,1473 debug_info_sect.offset,
1478 new_offset,1474 new_offset,
1479 });1475 });
14801476 const amt = try d_sym.file.copyRangeAll(
1481 try copyRangeAllOverlappingAlloc(
1482 gpa,
1483 d_sym.file,
1484 debug_info_sect.offset,1477 debug_info_sect.offset,
1478 d_sym.file,
1485 new_offset,1479 new_offset,
1486 existing_size,1480 existing_size,
1487 );1481 );
14881482 if (amt != existing_size) return error.InputOutput;
1489 debug_info_sect.offset = @intCast(u32, new_offset);1483 debug_info_sect.offset = @intCast(u32, new_offset);
1490 debug_info_sect.addr = dwarf_segment.vmaddr + new_offset - dwarf_segment.fileoff;
1491 }1484 }
1492 debug_info_sect.size = needed_size;1485 debug_info_sect.size = needed_size;
1493 d_sym.debug_info_header_dirty = true;1486 d_sym.debug_info_header_dirty = true;
...@@ -1502,6 +1495,7 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co...@@ -1502,6 +1495,7 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co
1502 trailing_zero,1495 trailing_zero,
1503 );1496 );
1504 },1497 },
1498
1505 .wasm => {1499 .wasm => {
1506 const wasm_file = file.cast(File.Wasm).?;1500 const wasm_file = file.cast(File.Wasm).?;
1507 const info_atom = wasm_file.debug_info_atom.?;1501 const info_atom = wasm_file.debug_info_atom.?;
...@@ -2569,16 +2563,3 @@ fn addDbgInfoErrorSet(...@@ -2569,16 +2563,3 @@ fn addDbgInfoErrorSet(
2569 // DW.AT.enumeration_type delimit children2563 // DW.AT.enumeration_type delimit children
2570 try dbg_info_buffer.append(0);2564 try dbg_info_buffer.append(0);
2571}2565}
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 {...@@ -537,19 +537,6 @@ fn writeStrtab(self: *DebugSymbols, lc: *macho.symtab_command) !void {
537 }537 }
538}538}
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
553pub fn getSectionIndexes(self: *DebugSymbols, segment_index: u8) struct { start: u8, end: u8 } {540pub fn getSectionIndexes(self: *DebugSymbols, segment_index: u8) struct { start: u8, end: u8 } {
554 var start: u8 = 0;541 var start: u8 = 0;
555 const nsects = for (self.segments.items) |seg, i| {542 const nsects = for (self.segments.items) |seg, i| {