From 742aa942800e81b14ac1fc6d9a8b3cc33621e2b6 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 8 Dec 2022 14:24:10 +0100 Subject: [PATCH] dsym: hint linker when file range copy is not necessary --- src/link/Dwarf.zig | 10 +++++----- src/link/MachO/DebugSymbols.zig | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index e804871c67..7e0cbb0358 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -1166,7 +1166,7 @@ pub fn commitDeclState( .macho => { const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; const sect_index = d_sym.debug_line_section_index.?; - try d_sym.growSection(sect_index, needed_size); + try d_sym.growSection(sect_index, needed_size, true); const sect = d_sym.getSection(sect_index); const file_pos = sect.offset + src_fn.off; try pwriteDbgLineNops( @@ -1414,7 +1414,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom: *Atom, dbg_info_buf: []const u8) !void .macho => { const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; const sect_index = d_sym.debug_info_section_index.?; - try d_sym.growSection(sect_index, needed_size); + try d_sym.growSection(sect_index, needed_size, true); const sect = d_sym.getSection(sect_index); const file_pos = sect.offset + atom.off; try pwriteDbgInfoNops( @@ -1697,7 +1697,7 @@ pub fn writeDbgAbbrev(self: *Dwarf) !void { .macho => { const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; const sect_index = d_sym.debug_abbrev_section_index.?; - try d_sym.growSection(sect_index, needed_size); + try d_sym.growSection(sect_index, needed_size, false); const sect = d_sym.getSection(sect_index); const file_pos = sect.offset + abbrev_offset; try d_sym.file.pwriteAll(&abbrev_buf, file_pos); @@ -2134,7 +2134,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void { .macho => { const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; const sect_index = d_sym.debug_aranges_section_index.?; - try d_sym.growSection(sect_index, needed_size); + try d_sym.growSection(sect_index, needed_size, false); const sect = d_sym.getSection(sect_index); const file_pos = sect.offset; try d_sym.file.pwriteAll(di_buf.items, file_pos); @@ -2301,7 +2301,7 @@ pub fn writeDbgLineHeader(self: *Dwarf, module: *Module) !void { const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; const sect_index = d_sym.debug_line_section_index.?; const needed_size = @intCast(u32, d_sym.getSection(sect_index).size + delta); - try d_sym.growSection(sect_index, needed_size); + try d_sym.growSection(sect_index, needed_size, true); const file_pos = d_sym.getSection(sect_index).offset + src_fn.off; const amt = try d_sym.file.preadAll(buffer, file_pos); diff --git a/src/link/MachO/DebugSymbols.zig b/src/link/MachO/DebugSymbols.zig index 6a6bea998e..7fa4a8f4dd 100644 --- a/src/link/MachO/DebugSymbols.zig +++ b/src/link/MachO/DebugSymbols.zig @@ -147,7 +147,7 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme return index; } -pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32) !void { +pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32, requires_file_copy: bool) !void { const sect = self.getSectionPtr(sect_index); if (needed_size > self.allocatedSize(sect.offset)) { @@ -162,13 +162,15 @@ pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32) !void new_offset, }); - const amt = try self.file.copyRangeAll( - sect.offset, - self.file, - new_offset, - existing_size, - ); - if (amt != existing_size) return error.InputOutput; + if (requires_file_copy) { + const amt = try self.file.copyRangeAll( + sect.offset, + self.file, + new_offset, + existing_size, + ); + if (amt != existing_size) return error.InputOutput; + } sect.offset = @intCast(u32, new_offset); } @@ -287,7 +289,7 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void { const sect_index = self.debug_str_section_index.?; if (self.debug_string_table_dirty or self.dwarf.strtab.items.len != self.getSection(sect_index).size) { const needed_size = @intCast(u32, self.dwarf.strtab.items.len); - try self.growSection(sect_index, needed_size); + try self.growSection(sect_index, needed_size, false); try self.file.pwriteAll(self.dwarf.strtab.items, self.getSection(sect_index).offset); self.debug_string_table_dirty = false; }