authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-19 22:44:09+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-22 12:06:02+02:00
log617f89f0823d766f2276651fc1bf467f54a22d35
treeb7b4ed520025cd9ae54349a84dbb4cc92e63dc0f
parentcba3389d906ff36f7913c7497d55ce1bf3164022

macho: parse input files in parallel


1 files changed, 28 insertions(+), 15 deletions(-)

src/link/MachO.zig+28-15
......@@ -96,6 +96,7 @@ debug_line_sect_index: ?u8 = null,
9696has_tlv: bool = false,
9797binds_to_weak: bool = false,
9898weak_defines: bool = false,
99has_errors: AtomicBool = AtomicBool.init(false),
99100
100101/// Options
101102/// SDK layout
......@@ -469,8 +470,6 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
469470 };
470471 }
471472
472 if (self.base.hasErrors()) return error.FlushFailure;
473
474473 try self.parseInputFiles();
475474 self.parseDependentDylibs() catch |err| {
476475 switch (err) {
......@@ -900,24 +899,36 @@ pub fn parseInputFiles(self: *MachO) !void {
900899 const tracy = trace(@src());
901900 defer tracy.end();
902901
903 for (self.objects.items) |index| {
904 self.getFile(index).?.parse(self) catch |err| switch (err) {
905 error.MalformedObject,
906 error.InvalidCpuArch,
907 error.InvalidTarget,
908 => {}, // already reported
909 else => |e| try self.reportParseError2(index, "unexpected error: parsing input file failed with error {s}", .{@errorName(e)}),
910 };
902 const tp = self.base.comp.thread_pool;
903 var wg: WaitGroup = .{};
904
905 {
906 wg.reset();
907 defer wg.wait();
908
909 for (self.objects.items) |index| {
910 tp.spawnWg(&wg, parseInputFileWorker, .{ self, index });
911 }
912 for (self.dylibs.items) |index| {
913 tp.spawnWg(&wg, parseInputFileWorker, .{ self, index });
914 }
911915 }
912 for (self.dylibs.items) |index| {
913 self.getFile(index).?.parse(self) catch |err| switch (err) {
916
917 if (self.has_errors.swap(false, .seq_cst)) return error.FlushFailure;
918}
919
920fn parseInputFileWorker(self: *MachO, index: File.Index) void {
921 self.getFile(index).?.parse(self) catch |err| {
922 switch (err) {
923 error.MalformedObject,
914924 error.MalformedDylib,
915925 error.InvalidCpuArch,
916926 error.InvalidTarget,
917927 => {}, // already reported
918 else => |e| try self.reportParseError2(index, "unexpected error: parsing input file failed with error {s}", .{@errorName(e)}),
919 };
920 }
928 else => |e| self.reportParseError2(index, "unexpected error: parsing input file failed with error {s}", .{@errorName(e)}) catch {},
929 }
930 _ = self.has_errors.swap(true, .seq_cst);
931 };
921932}
922933
923934fn addArchive(self: *MachO, lib: SystemLib, must_link: bool, handle: File.HandleIndex, fat_arch: ?fat.Arch) !void {
......@@ -4436,6 +4447,7 @@ const Alignment = Atom.Alignment;
44364447const Allocator = mem.Allocator;
44374448const Archive = @import("MachO/Archive.zig");
44384449pub const Atom = @import("MachO/Atom.zig");
4450const AtomicBool = std.atomic.Value(bool);
44394451const Bind = bind.Bind;
44404452const Cache = std.Build.Cache;
44414453const CodeSignature = @import("MachO/CodeSignature.zig");
......@@ -4471,6 +4483,7 @@ const Thunk = thunks.Thunk;
44714483const TlvPtrSection = synthetic.TlvPtrSection;
44724484const Value = @import("../Value.zig");
44734485const UnwindInfo = @import("MachO/UnwindInfo.zig");
4486const WaitGroup = std.Thread.WaitGroup;
44744487const WeakBind = bind.WeakBind;
44754488const ZigGotSection = synthetic.ZigGotSection;
44764489const ZigObject = @import("MachO/ZigObject.zig");