authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-11 13:46:54+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-18 09:13:08+02:00
logb4e6b3c53c0fd54b43f648d9a207e8ff592dd0ff
tree80aecf7a8b554ce6179cf57b3d30a6770a29373f
parent05a790d784e4f1258d550e31178cf1e163750b6b

macho: bring back parts of r mode


2 files changed, 60 insertions(+), 58 deletions(-)

src/link/MachO.zig+1-1
...@@ -357,7 +357,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n...@@ -357,7 +357,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
357357
358 if (self.getZigObject()) |zo| try zo.flushModule(self, tid);358 if (self.getZigObject()) |zo| try zo.flushModule(self, tid);
359 if (self.base.isStaticLib()) return relocatable.flushStaticLib(self, comp, module_obj_path);359 if (self.base.isStaticLib()) return relocatable.flushStaticLib(self, comp, module_obj_path);
360 // if (self.base.isObject()) return relocatable.flushObject(self, comp, module_obj_path);360 if (self.base.isObject()) return relocatable.flushObject(self, comp, module_obj_path);
361361
362 var positionals = std.ArrayList(Compilation.LinkObject).init(gpa);362 var positionals = std.ArrayList(Compilation.LinkObject).init(gpa);
363 defer positionals.deinit();363 defer positionals.deinit();
src/link/MachO/relocatable.zig+59-57
...@@ -26,68 +26,70 @@ pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?[]c...@@ -26,68 +26,70 @@ pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?[]c
26 return;26 return;
27 }27 }
2828
29 for (positionals.items) |obj| {29 @panic("TODO -r mode");
30 macho_file.parsePositional(obj.path, obj.must_link) catch |err| switch (err) {30
31 error.MalformedObject,31 // for (positionals.items) |obj| {
32 error.MalformedArchive,32 // macho_file.parsePositional(obj.path, obj.must_link) catch |err| switch (err) {
33 error.InvalidCpuArch,33 // error.MalformedObject,
34 error.InvalidTarget,34 // error.MalformedArchive,
35 => continue, // already reported35 // error.InvalidCpuArch,
36 error.UnknownFileType => try macho_file.reportParseError(obj.path, "unknown file type for an object file", .{}),36 // error.InvalidTarget,
37 else => |e| try macho_file.reportParseError(37 // => continue, // already reported
38 obj.path,38 // error.UnknownFileType => try macho_file.reportParseError(obj.path, "unknown file type for an object file", .{}),
39 "unexpected error: parsing input file failed with error {s}",39 // else => |e| try macho_file.reportParseError(
40 .{@errorName(e)},40 // obj.path,
41 ),41 // "unexpected error: parsing input file failed with error {s}",
42 };42 // .{@errorName(e)},
43 }43 // ),
4444 // };
45 if (comp.link_errors.items.len > 0) return error.FlushFailure;45 // }
46
47 try macho_file.addUndefinedGlobals();
48 try macho_file.resolveSymbols();
49 try macho_file.parseDebugInfo();
50 try macho_file.dedupLiterals();
51 markExports(macho_file);
52 claimUnresolved(macho_file);
53 try initOutputSections(macho_file);
54 try macho_file.sortSections();
55 try macho_file.addAtomsToSections();
56 try calcSectionSizes(macho_file);
57
58 try createSegment(macho_file);
59 try allocateSections(macho_file);
60 allocateSegment(macho_file);
61
62 var off = off: {
63 const seg = macho_file.segments.items[0];
64 const off = math.cast(u32, seg.fileoff + seg.filesize) orelse return error.Overflow;
65 break :off mem.alignForward(u32, off, @alignOf(macho.relocation_info));
66 };
67 off = allocateSectionsRelocs(macho_file, off);
6846
69 if (build_options.enable_logging) {47 // if (comp.link_errors.items.len > 0) return error.FlushFailure;
70 state_log.debug("{}", .{macho_file.dumpState()});48
71 }49 // try macho_file.addUndefinedGlobals();
50 // try macho_file.resolveSymbols();
51 // try macho_file.parseDebugInfo();
52 // try macho_file.dedupLiterals();
53 // markExports(macho_file);
54 // claimUnresolved(macho_file);
55 // try initOutputSections(macho_file);
56 // try macho_file.sortSections();
57 // try macho_file.addAtomsToSections();
58 // try calcSectionSizes(macho_file);
59
60 // try createSegment(macho_file);
61 // try allocateSections(macho_file);
62 // allocateSegment(macho_file);
63
64 // var off = off: {
65 // const seg = macho_file.segments.items[0];
66 // const off = math.cast(u32, seg.fileoff + seg.filesize) orelse return error.Overflow;
67 // break :off mem.alignForward(u32, off, @alignOf(macho.relocation_info));
68 // };
69 // off = allocateSectionsRelocs(macho_file, off);
70
71 // if (build_options.enable_logging) {
72 // state_log.debug("{}", .{macho_file.dumpState()});
73 // }
7274
73 try macho_file.calcSymtabSize();75 // try macho_file.calcSymtabSize();
74 try writeAtoms(macho_file);76 // try writeAtoms(macho_file);
75 try writeCompactUnwind(macho_file);77 // try writeCompactUnwind(macho_file);
76 try writeEhFrame(macho_file);78 // try writeEhFrame(macho_file);
7779
78 off = mem.alignForward(u32, off, @alignOf(u64));80 // off = mem.alignForward(u32, off, @alignOf(u64));
79 off = try macho_file.writeDataInCode(0, off);81 // off = try macho_file.writeDataInCode(0, off);
80 off = mem.alignForward(u32, off, @alignOf(u64));82 // off = mem.alignForward(u32, off, @alignOf(u64));
81 off = try macho_file.writeSymtab(off);83 // off = try macho_file.writeSymtab(off);
82 off = mem.alignForward(u32, off, @alignOf(u64));84 // off = mem.alignForward(u32, off, @alignOf(u64));
83 off = try macho_file.writeStrtab(off);85 // off = try macho_file.writeStrtab(off);
8486
85 // In order to please Apple ld (and possibly other MachO linkers in the wild),87 // // In order to please Apple ld (and possibly other MachO linkers in the wild),
86 // we will now sanitize segment names of Zig-specific segments.88 // // we will now sanitize segment names of Zig-specific segments.
87 sanitizeZigSections(macho_file);89 // sanitizeZigSections(macho_file);
8890
89 const ncmds, const sizeofcmds = try writeLoadCommands(macho_file);91 // const ncmds, const sizeofcmds = try writeLoadCommands(macho_file);
90 try writeHeader(macho_file, ncmds, sizeofcmds);92 // try writeHeader(macho_file, ncmds, sizeofcmds);
91}93}
9294
93pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void {95pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void {