authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-22 19:24:58+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:42+01:00
log46bc91ade533ad2f51ae32962b057952f90e8d2a
tree5c76d612b614032f6aa3f6757e66dbbf397ec0b9
parentf2dce0c33794f363d1b7448ee110ca2ae4bbafac

macho: skip -r when single input object file

This is to ensure we don't unnecessarily strip debug info from the final relocatable input file, so just copy the file out for now.

1 files changed, 14 insertions(+), 0 deletions(-)

src/link/MachO/relocatable.zig+14
......@@ -12,6 +12,20 @@ pub fn flush(macho_file: *MachO, comp: *Compilation, module_obj_path: ?[]const u
1212
1313 if (module_obj_path) |path| try positionals.append(.{ .path = path });
1414
15 if (positionals.items.len == 1) {
16 // Instead of invoking a full-blown `-r` mode on the input which sadly will strip all
17 // debug info segments/sections (this is apparently by design by Apple), we copy
18 // the *only* input file over.
19 // TODO: in the future, when we implement `dsymutil` alternative directly in the Zig
20 // compiler, investigate if we can get rid of this `if` prong here.
21 const path = positionals.items[0].path;
22 const in_file = try std.fs.cwd().openFile(path, .{});
23 const stat = try in_file.stat();
24 const amt = try in_file.copyRangeAll(0, macho_file.base.file.?, 0, stat.size);
25 if (amt != stat.size) return error.InputOutput; // TODO: report an actual user error
26 return;
27 }
28
1529 for (positionals.items) |obj| {
1630 macho_file.parsePositional(obj.path, obj.must_link) catch |err| switch (err) {
1731 error.MalformedObject,