authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-08 14:24:10+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-09 09:24:25+01:00
log742aa942800e81b14ac1fc6d9a8b3cc33621e2b6
tree3cc5597db58af58d685134a3f604a25c84033f45
parent9ade4f6d8c410eea63ad71569b5cf7813337659d

dsym: hint linker when file range copy is not necessary


2 files changed, 16 insertions(+), 14 deletions(-)

src/link/Dwarf.zig+5-5
......@@ -1166,7 +1166,7 @@ pub fn commitDeclState(
11661166 .macho => {
11671167 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
11681168 const sect_index = d_sym.debug_line_section_index.?;
1169 try d_sym.growSection(sect_index, needed_size);
1169 try d_sym.growSection(sect_index, needed_size, true);
11701170 const sect = d_sym.getSection(sect_index);
11711171 const file_pos = sect.offset + src_fn.off;
11721172 try pwriteDbgLineNops(
......@@ -1414,7 +1414,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom: *Atom, dbg_info_buf: []const u8) !void
14141414 .macho => {
14151415 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
14161416 const sect_index = d_sym.debug_info_section_index.?;
1417 try d_sym.growSection(sect_index, needed_size);
1417 try d_sym.growSection(sect_index, needed_size, true);
14181418 const sect = d_sym.getSection(sect_index);
14191419 const file_pos = sect.offset + atom.off;
14201420 try pwriteDbgInfoNops(
......@@ -1697,7 +1697,7 @@ pub fn writeDbgAbbrev(self: *Dwarf) !void {
16971697 .macho => {
16981698 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
16991699 const sect_index = d_sym.debug_abbrev_section_index.?;
1700 try d_sym.growSection(sect_index, needed_size);
1700 try d_sym.growSection(sect_index, needed_size, false);
17011701 const sect = d_sym.getSection(sect_index);
17021702 const file_pos = sect.offset + abbrev_offset;
17031703 try d_sym.file.pwriteAll(&abbrev_buf, file_pos);
......@@ -2134,7 +2134,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {
21342134 .macho => {
21352135 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
21362136 const sect_index = d_sym.debug_aranges_section_index.?;
2137 try d_sym.growSection(sect_index, needed_size);
2137 try d_sym.growSection(sect_index, needed_size, false);
21382138 const sect = d_sym.getSection(sect_index);
21392139 const file_pos = sect.offset;
21402140 try d_sym.file.pwriteAll(di_buf.items, file_pos);
......@@ -2301,7 +2301,7 @@ pub fn writeDbgLineHeader(self: *Dwarf, module: *Module) !void {
23012301 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
23022302 const sect_index = d_sym.debug_line_section_index.?;
23032303 const needed_size = @intCast(u32, d_sym.getSection(sect_index).size + delta);
2304 try d_sym.growSection(sect_index, needed_size);
2304 try d_sym.growSection(sect_index, needed_size, true);
23052305 const file_pos = d_sym.getSection(sect_index).offset + src_fn.off;
23062306
23072307 const amt = try d_sym.file.preadAll(buffer, file_pos);
src/link/MachO/DebugSymbols.zig+11-9
......@@ -147,7 +147,7 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme
147147 return index;
148148}
149149
150pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32) !void {
150pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32, requires_file_copy: bool) !void {
151151 const sect = self.getSectionPtr(sect_index);
152152
153153 if (needed_size > self.allocatedSize(sect.offset)) {
......@@ -162,13 +162,15 @@ pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32) !void
162162 new_offset,
163163 });
164164
165 const amt = try self.file.copyRangeAll(
166 sect.offset,
167 self.file,
168 new_offset,
169 existing_size,
170 );
171 if (amt != existing_size) return error.InputOutput;
165 if (requires_file_copy) {
166 const amt = try self.file.copyRangeAll(
167 sect.offset,
168 self.file,
169 new_offset,
170 existing_size,
171 );
172 if (amt != existing_size) return error.InputOutput;
173 }
172174
173175 sect.offset = @intCast(u32, new_offset);
174176 }
......@@ -287,7 +289,7 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {
287289 const sect_index = self.debug_str_section_index.?;
288290 if (self.debug_string_table_dirty or self.dwarf.strtab.items.len != self.getSection(sect_index).size) {
289291 const needed_size = @intCast(u32, self.dwarf.strtab.items.len);
290 try self.growSection(sect_index, needed_size);
292 try self.growSection(sect_index, needed_size, false);
291293 try self.file.pwriteAll(self.dwarf.strtab.items, self.getSection(sect_index).offset);
292294 self.debug_string_table_dirty = false;
293295 }