authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-28 11:31:23+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-29 07:26:59+01:00
logd53cb284de0486fbb31f6377d3b86d8de5f93cd0
treee6f3e5828a06f4283ee4a84387b8fa02d5320afd
parent3ae4c3cc3643995783c996f7950e54c95126b4d0

macho: re-enable emitting empty dSYM bundle


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

src/link/MachO.zig+32-29
......@@ -256,32 +256,36 @@ pub fn createEmpty(
256256 .program_code_size_hint = options.program_code_size_hint,
257257 });
258258
259 // TODO init dwarf
260
261 // if (comp.config.debug_format != .strip) {
262 // // Create dSYM bundle.
263 // log.debug("creating {s}.dSYM bundle", .{emit.sub_path});
264
265 // const d_sym_path = try std.fmt.allocPrint(
266 // arena,
267 // "{s}.dSYM" ++ fs.path.sep_str ++ "Contents" ++ fs.path.sep_str ++ "Resources" ++ fs.path.sep_str ++ "DWARF",
268 // .{emit.sub_path},
269 // );
270
271 // var d_sym_bundle = try emit.directory.handle.makeOpenPath(d_sym_path, .{});
272 // defer d_sym_bundle.close();
273
274 // const d_sym_file = try d_sym_bundle.createFile(emit.sub_path, .{
275 // .truncate = false,
276 // .read = true,
277 // });
278
279 // self.d_sym = .{
280 // .allocator = gpa,
281 // .dwarf = link.File.Dwarf.init(&self.base, .dwarf32),
282 // .file = d_sym_file,
283 // };
284 // }
259 switch (comp.config.debug_format) {
260 .strip => {},
261 .dwarf => {
262 // Create dSYM bundle.
263 log.debug("creating {s}.dSYM bundle", .{emit.sub_path});
264
265 const sep = fs.path.sep_str;
266 const d_sym_path = try std.fmt.allocPrint(
267 arena,
268 "{s}.dSYM" ++ sep ++ "Contents" ++ sep ++ "Resources" ++ sep ++ "DWARF",
269 .{emit.sub_path},
270 );
271
272 var d_sym_bundle = try emit.directory.handle.makeOpenPath(d_sym_path, .{});
273 defer d_sym_bundle.close();
274
275 const d_sym_file = try d_sym_bundle.createFile(emit.sub_path, .{
276 .truncate = false,
277 .read = true,
278 });
279
280 self.d_sym = .{
281 .allocator = gpa,
282 .dwarf = link.File.Dwarf.init(&self.base, .dwarf32),
283 .file = d_sym_file,
284 };
285 try self.d_sym.?.initMetadata(self);
286 },
287 .code_view => unreachable,
288 }
285289 }
286290 }
287291
......@@ -3906,9 +3910,8 @@ fn reportDuplicates(self: *MachO, dupes: anytype) error{ HasDuplicates, OutOfMem
39063910}
39073911
39083912pub fn getDebugSymbols(self: *MachO) ?*DebugSymbols {
3909 if (self.d_sym) |*ds| {
3910 return ds;
3911 } else return null;
3913 if (self.d_sym) |*ds| return ds;
3914 return null;
39123915}
39133916
39143917pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void {
src/link/MachO/DebugSymbols.zig+3-5
......@@ -36,15 +36,13 @@ pub const Reloc = struct {
3636 prev_vaddr: u64,
3737};
3838
39/// You must call this function *after* `MachO.populateMissingMetadata()`
39/// You must call this function *after* `ZigObject.initMetadata()`
4040/// has been called to get a viable debug symbols output.
41pub fn populateMissingMetadata(self: *DebugSymbols, macho_file: *MachO) !void {
42 const target = macho_file.base.comp.root_mod.resolved_target.result;
43
41pub fn initMetadata(self: *DebugSymbols, macho_file: *MachO) !void {
4442 if (self.dwarf_segment_cmd_index == null) {
4543 self.dwarf_segment_cmd_index = @as(u8, @intCast(self.segments.items.len));
4644
47 const page_size = MachO.getPageSize(target.cpu.arch);
45 const page_size = macho_file.getPageSize();
4846 const off = @as(u64, @intCast(page_size));
4947 const ideal_size: u16 = 200 + 128 + 160 + 250;
5048 const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), page_size);