From d53cb284de0486fbb31f6377d3b86d8de5f93cd0 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sun, 28 Jan 2024 11:31:23 +0100 Subject: [PATCH] macho: re-enable emitting empty dSYM bundle --- src/link/MachO.zig | 53 +++++++++++++++++---------------- src/link/MachO/DebugSymbols.zig | 8 ++--- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/link/MachO.zig b/src/link/MachO.zig index eb32cf5c0e..581b6f0570 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -256,32 +256,36 @@ pub fn createEmpty( .program_code_size_hint = options.program_code_size_hint, }); - // TODO init dwarf + switch (comp.config.debug_format) { + .strip => {}, + .dwarf => { + // Create dSYM bundle. + log.debug("creating {s}.dSYM bundle", .{emit.sub_path}); - // if (comp.config.debug_format != .strip) { - // // Create dSYM bundle. - // log.debug("creating {s}.dSYM bundle", .{emit.sub_path}); + const sep = fs.path.sep_str; + const d_sym_path = try std.fmt.allocPrint( + arena, + "{s}.dSYM" ++ sep ++ "Contents" ++ sep ++ "Resources" ++ sep ++ "DWARF", + .{emit.sub_path}, + ); - // const d_sym_path = try std.fmt.allocPrint( - // arena, - // "{s}.dSYM" ++ fs.path.sep_str ++ "Contents" ++ fs.path.sep_str ++ "Resources" ++ fs.path.sep_str ++ "DWARF", - // .{emit.sub_path}, - // ); + var d_sym_bundle = try emit.directory.handle.makeOpenPath(d_sym_path, .{}); + defer d_sym_bundle.close(); - // var d_sym_bundle = try emit.directory.handle.makeOpenPath(d_sym_path, .{}); - // defer d_sym_bundle.close(); + const d_sym_file = try d_sym_bundle.createFile(emit.sub_path, .{ + .truncate = false, + .read = true, + }); - // const d_sym_file = try d_sym_bundle.createFile(emit.sub_path, .{ - // .truncate = false, - // .read = true, - // }); - - // self.d_sym = .{ - // .allocator = gpa, - // .dwarf = link.File.Dwarf.init(&self.base, .dwarf32), - // .file = d_sym_file, - // }; - // } + self.d_sym = .{ + .allocator = gpa, + .dwarf = link.File.Dwarf.init(&self.base, .dwarf32), + .file = d_sym_file, + }; + try self.d_sym.?.initMetadata(self); + }, + .code_view => unreachable, + } } } @@ -3906,9 +3910,8 @@ fn reportDuplicates(self: *MachO, dupes: anytype) error{ HasDuplicates, OutOfMem } pub fn getDebugSymbols(self: *MachO) ?*DebugSymbols { - if (self.d_sym) |*ds| { - return ds; - } else return null; + if (self.d_sym) |*ds| return ds; + return null; } pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void { diff --git a/src/link/MachO/DebugSymbols.zig b/src/link/MachO/DebugSymbols.zig index 74a4afeb54..a28688a61d 100644 --- a/src/link/MachO/DebugSymbols.zig +++ b/src/link/MachO/DebugSymbols.zig @@ -36,15 +36,13 @@ pub const Reloc = struct { prev_vaddr: u64, }; -/// You must call this function *after* `MachO.populateMissingMetadata()` +/// You must call this function *after* `ZigObject.initMetadata()` /// has been called to get a viable debug symbols output. -pub fn populateMissingMetadata(self: *DebugSymbols, macho_file: *MachO) !void { - const target = macho_file.base.comp.root_mod.resolved_target.result; - +pub fn initMetadata(self: *DebugSymbols, macho_file: *MachO) !void { if (self.dwarf_segment_cmd_index == null) { self.dwarf_segment_cmd_index = @as(u8, @intCast(self.segments.items.len)); - const page_size = MachO.getPageSize(target.cpu.arch); + const page_size = macho_file.getPageSize(); const off = @as(u64, @intCast(page_size)); const ideal_size: u16 = 200 + 128 + 160 + 250; const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), page_size);