authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-05-14 13:09:40+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-05-14 13:09:40+02:00
logaf9c6f2c696201e16d95f79a7275aae19b34cd59
treeebc0836bd9d1c185249b48e23ed581c38f93ffa5
parent00ebbe6df2249ba8201c0e5472d95022bf73e782

macho: put dSYM bundle in zig-cache

Originally, I thought that the dSYM bundle has to reside side-by-side with the binary it carries the debugging information for. However, it turns out macOS is clever enough that it auto-searches for matching dSYM bundle based on the embedded UUID of the binary. To verify this, run this on your macOS: ``` mdfind "com_apple_xcode_dsym_uuids == <UUID from LC_UUID>" ``` See [here] for more info. [here]: https://developer.apple.com/documentation/xcode/adding-identifiable-symbol-names-to-a-crash-report

1 files changed, 25 insertions(+), 13 deletions(-)

src/link/MachO.zig+25-13
......@@ -363,18 +363,30 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio
363363 self.base.file = file;
364364
365365 // Create dSYM bundle.
366 const d_sym_path = try fmt.allocPrint(allocator, "{s}.dSYM/Contents/Resources/DWARF/", .{sub_path});
367 defer allocator.free(d_sym_path);
368 var d_sym_bundle = try options.emit.?.directory.handle.makeOpenPath(d_sym_path, .{});
369 defer d_sym_bundle.close();
370 const d_sym_file = try d_sym_bundle.createFile(sub_path, .{
371 .truncate = false,
372 .read = true,
373 });
374 self.d_sym = .{
375 .base = self,
376 .file = d_sym_file,
377 };
366 if (options.module) |mod| {
367 const dir = mod.zig_cache_artifact_directory;
368 log.debug("creating {s}.dSYM bundle in {s}", .{ sub_path, dir.path });
369
370 const d_sym_path = try fmt.allocPrint(
371 allocator,
372 "{s}.dSYM" ++ fs.path.sep_str ++ "Contents" ++ fs.path.sep_str ++ "Resources" ++ fs.path.sep_str ++ "DWARF",
373 .{sub_path},
374 );
375 defer allocator.free(d_sym_path);
376
377 var d_sym_bundle = try dir.handle.makeOpenPath(d_sym_path, .{});
378 defer d_sym_bundle.close();
379
380 const d_sym_file = try d_sym_bundle.createFile(sub_path, .{
381 .truncate = false,
382 .read = true,
383 });
384
385 self.d_sym = .{
386 .base = self,
387 .file = d_sym_file,
388 };
389 }
378390
379391 // Index 0 is always a null symbol.
380392 try self.locals.append(allocator, .{
......@@ -387,7 +399,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio
387399
388400 switch (options.output_mode) {
389401 .Exe => {},
390 .Obj => {},
402 .Obj => return error.TODOImplementWritingObjFiles,
391403 .Lib => return error.TODOImplementWritingLibFiles,
392404 }
393405