diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 72889ca05d..8a394cfeae 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1038,6 +1038,10 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod // Beyond this point, everything has been allocated a virtual address and we can resolve // the relocations, and commit objects to file. + for (self.objects.items) |index| { + self.file(index).?.object.dirty = false; + } + if (self.zigObjectPtr()) |zo| { var has_reloc_errors = false; for (zo.atoms_indexes.items) |atom_index| { @@ -1399,7 +1403,6 @@ pub fn parseLibraryReportingFailure(self: *Elf, lib: SystemLib, must_link: bool) fn parseLibrary(self: *Elf, lib: SystemLib, must_link: bool) ParseError!void { const tracy = trace(@src()); defer tracy.end(); - if (try Archive.isArchive(lib.path)) { try self.parseArchive(lib.path, must_link); } else if (try SharedObject.isSharedObject(lib.path)) { @@ -2799,9 +2802,10 @@ pub fn resolveMergeSections(self: *Elf) !void { var has_errors = false; for (self.objects.items) |index| { - const file_ptr = self.file(index).?; - if (!file_ptr.isAlive()) continue; - file_ptr.object.initInputMergeSections(self) catch |err| switch (err) { + const object = self.file(index).?.object; + if (!object.alive) continue; + if (!object.dirty) continue; + object.initInputMergeSections(self) catch |err| switch (err) { error.LinkFailure => has_errors = true, else => |e| return e, }; @@ -2810,15 +2814,17 @@ pub fn resolveMergeSections(self: *Elf) !void { if (has_errors) return error.FlushFailure; for (self.objects.items) |index| { - const file_ptr = self.file(index).?; - if (!file_ptr.isAlive()) continue; - try file_ptr.object.initOutputMergeSections(self); + const object = self.file(index).?.object; + if (!object.alive) continue; + if (!object.dirty) continue; + try object.initOutputMergeSections(self); } for (self.objects.items) |index| { - const file_ptr = self.file(index).?; - if (!file_ptr.isAlive()) continue; - file_ptr.object.resolveMergeSubsections(self) catch |err| switch (err) { + const object = self.file(index).?.object; + if (!object.alive) continue; + if (!object.dirty) continue; + object.resolveMergeSubsections(self) catch |err| switch (err) { error.LinkFailure => has_errors = true, else => |e| return e, }; diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig index 461192049e..670bdc3bf5 100644 --- a/src/link/Elf/Object.zig +++ b/src/link/Elf/Object.zig @@ -29,6 +29,7 @@ cies: std.ArrayListUnmanaged(Cie) = .empty, eh_frame_data: std.ArrayListUnmanaged(u8) = .empty, alive: bool = true, +dirty: bool = true, num_dynrelocs: u32 = 0, output_symtab_ctx: Elf.SymtabCtx = .{},