diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2022-12-04 13:13:50 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2022-12-04 16:58:45 +0100 |
| commit | 280dad0283652aa176d0a67b8d90e9edc0869c5b (patch) | |
| tree | 3d613b0c13dab58e83c5b67044383706fac4999e /src | |
| parent | aa8b26cf25c0d0e5e50d51f993147be8773a9c1e (diff) | |
| download | zig-280dad0283652aa176d0a67b8d90e9edc0869c5b.tar.gz zig-280dad0283652aa176d0a67b8d90e9edc0869c5b.zip | |
dsym+dwarf: remove copyRangeAllOverlappingAlloc
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/Dwarf.zig | 39 | ||||
| -rw-r--r-- | src/link/MachO/DebugSymbols.zig | 13 |
2 files changed, 10 insertions, 42 deletions
diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index f0da3b143b..e9d59b1d02 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -1163,32 +1163,28 @@ pub fn commitDeclState( next_padding_size, ); }, + .macho => { const macho_file = file.cast(File.MachO).?; const d_sym = &macho_file.d_sym.?; - const dwarf_segment = d_sym.segments.items[d_sym.dwarf_segment_cmd_index.?]; const debug_line_sect = &d_sym.sections.items[d_sym.debug_line_section_index.?]; if (needed_size != debug_line_sect.size) { if (needed_size > d_sym.allocatedSize(debug_line_sect.offset)) { const new_offset = d_sym.findFreeSpace(needed_size, 1); const existing_size = last_src_fn.off; - log.debug("moving __debug_line section: {} bytes from 0x{x} to 0x{x}", .{ existing_size, debug_line_sect.offset, new_offset, }); - - try copyRangeAllOverlappingAlloc( - gpa, - d_sym.file, + const amt = try d_sym.file.copyRangeAll( debug_line_sect.offset, + d_sym.file, new_offset, existing_size, ); - + if (amt != existing_size) return error.InputOutput; debug_line_sect.offset = @intCast(u32, new_offset); - debug_line_sect.addr = dwarf_segment.vmaddr + new_offset - dwarf_segment.fileoff; } debug_line_sect.size = needed_size; d_sym.debug_line_header_dirty = true; @@ -1202,6 +1198,7 @@ pub fn commitDeclState( next_padding_size, ); }, + .wasm => { const wasm_file = file.cast(File.Wasm).?; const atom = wasm_file.debug_line_atom.?; @@ -1462,32 +1459,28 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co trailing_zero, ); }, + .macho => { const macho_file = file.cast(File.MachO).?; const d_sym = &macho_file.d_sym.?; - const dwarf_segment = d_sym.segments.items[d_sym.dwarf_segment_cmd_index.?]; const debug_info_sect = &d_sym.sections.items[d_sym.debug_info_section_index.?]; if (needed_size != debug_info_sect.size) { if (needed_size > d_sym.allocatedSize(debug_info_sect.offset)) { const new_offset = d_sym.findFreeSpace(needed_size, 1); const existing_size = last_decl.off; - log.debug("moving __debug_info section: {} bytes from 0x{x} to 0x{x}", .{ existing_size, debug_info_sect.offset, new_offset, }); - - try copyRangeAllOverlappingAlloc( - gpa, - d_sym.file, + const amt = try d_sym.file.copyRangeAll( debug_info_sect.offset, + d_sym.file, new_offset, existing_size, ); - + if (amt != existing_size) return error.InputOutput; debug_info_sect.offset = @intCast(u32, new_offset); - debug_info_sect.addr = dwarf_segment.vmaddr + new_offset - dwarf_segment.fileoff; } debug_info_sect.size = needed_size; d_sym.debug_info_header_dirty = true; @@ -1502,6 +1495,7 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co trailing_zero, ); }, + .wasm => { const wasm_file = file.cast(File.Wasm).?; const info_atom = wasm_file.debug_info_atom.?; @@ -2569,16 +2563,3 @@ fn addDbgInfoErrorSet( // DW.AT.enumeration_type delimit children try dbg_info_buffer.append(0); } - -fn copyRangeAllOverlappingAlloc( - allocator: Allocator, - file: std.fs.File, - in_offset: u64, - out_offset: u64, - len: usize, -) !void { - const buf = try allocator.alloc(u8, len); - defer allocator.free(buf); - const amt = try file.preadAll(buf, in_offset); - try file.pwriteAll(buf[0..amt], out_offset); -} diff --git a/src/link/MachO/DebugSymbols.zig b/src/link/MachO/DebugSymbols.zig index ef47257694..2791fcd7a2 100644 --- a/src/link/MachO/DebugSymbols.zig +++ b/src/link/MachO/DebugSymbols.zig @@ -537,19 +537,6 @@ fn writeStrtab(self: *DebugSymbols, lc: *macho.symtab_command) !void { } } -fn copyRangeAllOverlappingAlloc( - allocator: Allocator, - file: std.fs.File, - in_offset: u64, - out_offset: u64, - len: usize, -) !void { - const buf = try allocator.alloc(u8, len); - defer allocator.free(buf); - const amt = try file.preadAll(buf, in_offset); - try file.pwriteAll(buf[0..amt], out_offset); -} - pub fn getSectionIndexes(self: *DebugSymbols, segment_index: u8) struct { start: u8, end: u8 } { var start: u8 = 0; const nsects = for (self.segments.items) |seg, i| { |
