authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-27 10:23:44+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-31 10:19:04+01:00
loga7bae1b8579475eaf4a25907405d85b98d29977d
treea1207d1eb9eff5ce4f5d8e55f0bea23a0a2de6d5
parentcf9434191004e57e1cd3a75dcd91d5ad7e378c63

macho: write matching UUID to dSym bundle


2 files changed, 35 insertions(+), 2 deletions(-)

src/link/MachO.zig+1-1
...@@ -355,7 +355,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -355,7 +355,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
355355
356 if (self.d_sym) |*ds| {356 if (self.d_sym) |*ds| {
357 // Flush debug symbols bundle.357 // Flush debug symbols bundle.
358 try ds.flush();358 try ds.flush(self.base.allocator);
359 }359 }
360360
361 if (target.cpu.arch == .aarch64) {361 if (target.cpu.arch == .aarch64) {
src/link/MachO/DebugSymbols.zig+34-1
...@@ -58,18 +58,51 @@ pub fn populateMissingMetadata(self: *DebugSymbols, allocator: *Allocator) !void...@@ -58,18 +58,51 @@ pub fn populateMissingMetadata(self: *DebugSymbols, allocator: *Allocator) !void
58 self.header = header;58 self.header = header;
59 self.header_dirty = true;59 self.header_dirty = true;
60 }60 }
61 if (self.uuid_cmd_index == null) {
62 const base_cmd = self.base.load_commands.items[self.base.uuid_cmd_index.?];
63 self.uuid_cmd_index = @intCast(u16, self.load_commands.items.len);
64 try self.load_commands.append(allocator, base_cmd);
65 self.header_dirty = true;
66 self.load_commands_dirty = true;
67 }
61}68}
6269
63pub fn flush(self: *DebugSymbols) !void {70pub fn flush(self: *DebugSymbols, allocator: *Allocator) !void {
71 try self.writeLoadCommands(allocator);
64 try self.writeHeader();72 try self.writeHeader();
65 assert(!self.header_dirty);73 assert(!self.header_dirty);
66 assert(!self.load_commands_dirty);74 assert(!self.load_commands_dirty);
67}75}
6876
69pub fn deinit(self: *DebugSymbols, allocator: *Allocator) void {77pub fn deinit(self: *DebugSymbols, allocator: *Allocator) void {
78 for (self.load_commands.items) |*lc| {
79 lc.deinit(allocator);
80 }
70 self.file.close();81 self.file.close();
71}82}
7283
84/// Writes all load commands and section headers.
85fn writeLoadCommands(self: *DebugSymbols, allocator: *Allocator) !void {
86 if (!self.load_commands_dirty) return;
87
88 var sizeofcmds: usize = 0;
89 for (self.load_commands.items) |lc| {
90 sizeofcmds += lc.cmdsize();
91 }
92
93 var buffer = try allocator.alloc(u8, sizeofcmds);
94 defer allocator.free(buffer);
95 var writer = std.io.fixedBufferStream(buffer).writer();
96 for (self.load_commands.items) |lc| {
97 try lc.write(writer);
98 }
99
100 const off = @sizeOf(macho.mach_header_64);
101 log.debug("writing {} dSym load commands from 0x{x} to 0x{x}", .{ self.load_commands.items.len, off, off + sizeofcmds });
102 try self.file.pwriteAll(buffer, off);
103 self.load_commands_dirty = false;
104}
105
73fn writeHeader(self: *DebugSymbols) !void {106fn writeHeader(self: *DebugSymbols) !void {
74 if (!self.header_dirty) return;107 if (!self.header_dirty) return;
75108