Commit 742aa94280
Changed files (2)
src
link
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;
}
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);