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(...@@ -1166,7 +1166,7 @@ pub fn commitDeclState(
1166 .macho => {1166 .macho => {
1167 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;1167 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
1168 const sect_index = d_sym.debug_line_section_index.?;1168 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);
1170 const sect = d_sym.getSection(sect_index);1170 const sect = d_sym.getSection(sect_index);
1171 const file_pos = sect.offset + src_fn.off;1171 const file_pos = sect.offset + src_fn.off;
1172 try pwriteDbgLineNops(1172 try pwriteDbgLineNops(
...@@ -1414,7 +1414,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom: *Atom, dbg_info_buf: []const u8) !void...@@ -1414,7 +1414,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom: *Atom, dbg_info_buf: []const u8) !void
1414 .macho => {1414 .macho => {
1415 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;1415 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
1416 const sect_index = d_sym.debug_info_section_index.?;1416 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);
1418 const sect = d_sym.getSection(sect_index);1418 const sect = d_sym.getSection(sect_index);
1419 const file_pos = sect.offset + atom.off;1419 const file_pos = sect.offset + atom.off;
1420 try pwriteDbgInfoNops(1420 try pwriteDbgInfoNops(
...@@ -1697,7 +1697,7 @@ pub fn writeDbgAbbrev(self: *Dwarf) !void {...@@ -1697,7 +1697,7 @@ pub fn writeDbgAbbrev(self: *Dwarf) !void {
1697 .macho => {1697 .macho => {
1698 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;1698 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
1699 const sect_index = d_sym.debug_abbrev_section_index.?;1699 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);
1701 const sect = d_sym.getSection(sect_index);1701 const sect = d_sym.getSection(sect_index);
1702 const file_pos = sect.offset + abbrev_offset;1702 const file_pos = sect.offset + abbrev_offset;
1703 try d_sym.file.pwriteAll(&abbrev_buf, file_pos);1703 try d_sym.file.pwriteAll(&abbrev_buf, file_pos);
...@@ -2134,7 +2134,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {...@@ -2134,7 +2134,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {
2134 .macho => {2134 .macho => {
2135 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;2135 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
2136 const sect_index = d_sym.debug_aranges_section_index.?;2136 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);
2138 const sect = d_sym.getSection(sect_index);2138 const sect = d_sym.getSection(sect_index);
2139 const file_pos = sect.offset;2139 const file_pos = sect.offset;
2140 try d_sym.file.pwriteAll(di_buf.items, file_pos);2140 try d_sym.file.pwriteAll(di_buf.items, file_pos);
...@@ -2301,7 +2301,7 @@ pub fn writeDbgLineHeader(self: *Dwarf, module: *Module) !void {...@@ -2301,7 +2301,7 @@ pub fn writeDbgLineHeader(self: *Dwarf, module: *Module) !void {
2301 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;2301 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
2302 const sect_index = d_sym.debug_line_section_index.?;2302 const sect_index = d_sym.debug_line_section_index.?;
2303 const needed_size = @intCast(u32, d_sym.getSection(sect_index).size + delta);2303 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);
2305 const file_pos = d_sym.getSection(sect_index).offset + src_fn.off;2305 const file_pos = d_sym.getSection(sect_index).offset + src_fn.off;
23062306
2307 const amt = try d_sym.file.preadAll(buffer, file_pos);2307 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...@@ -147,7 +147,7 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme
147 return index;147 return index;
148}148}
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 {
151 const sect = self.getSectionPtr(sect_index);151 const sect = self.getSectionPtr(sect_index);
152152
153 if (needed_size > self.allocatedSize(sect.offset)) {153 if (needed_size > self.allocatedSize(sect.offset)) {
...@@ -162,13 +162,15 @@ pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32) !void...@@ -162,13 +162,15 @@ pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32) !void
162 new_offset,162 new_offset,
163 });163 });
164164
165 const amt = try self.file.copyRangeAll(165 if (requires_file_copy) {
166 sect.offset,166 const amt = try self.file.copyRangeAll(
167 self.file,167 sect.offset,
168 new_offset,168 self.file,
169 existing_size,169 new_offset,
170 );170 existing_size,
171 if (amt != existing_size) return error.InputOutput;171 );
172 if (amt != existing_size) return error.InputOutput;
173 }
172174
173 sect.offset = @intCast(u32, new_offset);175 sect.offset = @intCast(u32, new_offset);
174 }176 }
...@@ -287,7 +289,7 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {...@@ -287,7 +289,7 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {
287 const sect_index = self.debug_str_section_index.?;289 const sect_index = self.debug_str_section_index.?;
288 if (self.debug_string_table_dirty or self.dwarf.strtab.items.len != self.getSection(sect_index).size) {290 if (self.debug_string_table_dirty or self.dwarf.strtab.items.len != self.getSection(sect_index).size) {
289 const needed_size = @intCast(u32, self.dwarf.strtab.items.len);291 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);
291 try self.file.pwriteAll(self.dwarf.strtab.items, self.getSection(sect_index).offset);293 try self.file.pwriteAll(self.dwarf.strtab.items, self.getSection(sect_index).offset);
292 self.debug_string_table_dirty = false;294 self.debug_string_table_dirty = false;
293 }295 }