authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-08 11:08:00+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-09 09:24:25+01:00
logfa44c73c1efe2dae62c80a7785b496d83ddac8d1
tree6c546e402c978c930ab9c1f773067f5bce16ae4a
parentb14e580ad87d70bb14a3bf942bfac41acf1b51b8

dwarf: move any remaining section growth to dsym


2 files changed, 6 insertions(+), 11 deletions(-)

src/link/Dwarf.zig+4-9
...@@ -2336,16 +2336,13 @@ pub fn writeDbgLineHeader(self: *Dwarf, module: *Module) !void {...@@ -2336,16 +2336,13 @@ pub fn writeDbgLineHeader(self: *Dwarf, module: *Module) !void {
2336 const delta = needed_with_padding - dbg_line_prg_off;2336 const delta = needed_with_padding - dbg_line_prg_off;
23372337
2338 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;2338 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
2339 const debug_line_sect = d_sym.getSectionPtr(d_sym.debug_line_section_index.?);2339 const sect_index = d_sym.debug_line_section_index.?;
2340 const needed_size = debug_line_sect.size + delta;2340 const needed_size = @intCast(u32, d_sym.getSection(sect_index).size + delta);
23412341 try d_sym.growSection(sect_index, needed_size);
2342 if (needed_size > d_sym.allocatedSize(debug_line_sect.offset)) {
2343 @panic("TODO grow debug_line section");
2344 }
23452342
2346 var src_fn = self.dbg_line_fn_first.?;2343 var src_fn = self.dbg_line_fn_first.?;
2347 const last_fn = self.dbg_line_fn_last.?;2344 const last_fn = self.dbg_line_fn_last.?;
2348 const file_pos = debug_line_sect.offset + src_fn.off;2345 const file_pos = d_sym.getSection(sect_index).offset + src_fn.off;
23492346
2350 var buffer = try gpa.alloc(u8, last_fn.off + last_fn.len - src_fn.off);2347 var buffer = try gpa.alloc(u8, last_fn.off + last_fn.len - src_fn.off);
2351 defer gpa.free(buffer);2348 defer gpa.free(buffer);
...@@ -2354,8 +2351,6 @@ pub fn writeDbgLineHeader(self: *Dwarf, module: *Module) !void {...@@ -2354,8 +2351,6 @@ pub fn writeDbgLineHeader(self: *Dwarf, module: *Module) !void {
23542351
2355 try d_sym.file.pwriteAll(buffer, file_pos + delta);2352 try d_sym.file.pwriteAll(buffer, file_pos + delta);
23562353
2357 debug_line_sect.size = needed_size;
2358
2359 while (true) {2354 while (true) {
2360 src_fn.off += delta;2355 src_fn.off += delta;
23612356
src/link/MachO/DebugSymbols.zig+2-2
...@@ -202,7 +202,7 @@ fn detectAllocCollision(self: *DebugSymbols, start: u64, size: u64) ?u64 {...@@ -202,7 +202,7 @@ fn detectAllocCollision(self: *DebugSymbols, start: u64, size: u64) ?u64 {
202 return null;202 return null;
203}203}
204204
205pub fn findFreeSpace(self: *DebugSymbols, object_size: u64, min_alignment: u64) u64 {205fn findFreeSpace(self: *DebugSymbols, object_size: u64, min_alignment: u64) u64 {
206 const segment = self.getDwarfSegmentPtr();206 const segment = self.getDwarfSegmentPtr();
207 var offset: u64 = segment.fileoff;207 var offset: u64 = segment.fileoff;
208 while (self.detectAllocCollision(offset, object_size)) |item_end| {208 while (self.detectAllocCollision(offset, object_size)) |item_end| {
...@@ -464,7 +464,7 @@ fn writeHeader(self: *DebugSymbols, macho_file: *MachO, ncmds: u32, sizeofcmds:...@@ -464,7 +464,7 @@ fn writeHeader(self: *DebugSymbols, macho_file: *MachO, ncmds: u32, sizeofcmds:
464 try self.file.pwriteAll(mem.asBytes(&header), 0);464 try self.file.pwriteAll(mem.asBytes(&header), 0);
465}465}
466466
467pub fn allocatedSize(self: *DebugSymbols, start: u64) u64 {467fn allocatedSize(self: *DebugSymbols, start: u64) u64 {
468 const seg = self.getDwarfSegmentPtr();468 const seg = self.getDwarfSegmentPtr();
469 assert(start >= seg.fileoff);469 assert(start >= seg.fileoff);
470 var min_pos: u64 = std.math.maxInt(u64);470 var min_pos: u64 = std.math.maxInt(u64);