authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-28 08:40:17+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-09 12:38:09-07:00
log9a15c3e1a1dc01d04c976ffbdec46b206455634e
treebb7243357d3d84d29579ec3f4a38fa3be291542f
parent4604577ae17ca850621eb40523b0a67bf6ac6971

elf: mark objects as dirty/not-dirty

This way we can track if we need to redo the object parsing or not.

2 files changed, 17 insertions(+), 10 deletions(-)

src/link/Elf.zig+16-10
......@@ -1038,6 +1038,10 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
10381038
10391039 // Beyond this point, everything has been allocated a virtual address and we can resolve
10401040 // the relocations, and commit objects to file.
1041 for (self.objects.items) |index| {
1042 self.file(index).?.object.dirty = false;
1043 }
1044
10411045 if (self.zigObjectPtr()) |zo| {
10421046 var has_reloc_errors = false;
10431047 for (zo.atoms_indexes.items) |atom_index| {
......@@ -1399,7 +1403,6 @@ pub fn parseLibraryReportingFailure(self: *Elf, lib: SystemLib, must_link: bool)
13991403fn parseLibrary(self: *Elf, lib: SystemLib, must_link: bool) ParseError!void {
14001404 const tracy = trace(@src());
14011405 defer tracy.end();
1402
14031406 if (try Archive.isArchive(lib.path)) {
14041407 try self.parseArchive(lib.path, must_link);
14051408 } else if (try SharedObject.isSharedObject(lib.path)) {
......@@ -2799,9 +2802,10 @@ pub fn resolveMergeSections(self: *Elf) !void {
27992802
28002803 var has_errors = false;
28012804 for (self.objects.items) |index| {
2802 const file_ptr = self.file(index).?;
2803 if (!file_ptr.isAlive()) continue;
2804 file_ptr.object.initInputMergeSections(self) catch |err| switch (err) {
2805 const object = self.file(index).?.object;
2806 if (!object.alive) continue;
2807 if (!object.dirty) continue;
2808 object.initInputMergeSections(self) catch |err| switch (err) {
28052809 error.LinkFailure => has_errors = true,
28062810 else => |e| return e,
28072811 };
......@@ -2810,15 +2814,17 @@ pub fn resolveMergeSections(self: *Elf) !void {
28102814 if (has_errors) return error.FlushFailure;
28112815
28122816 for (self.objects.items) |index| {
2813 const file_ptr = self.file(index).?;
2814 if (!file_ptr.isAlive()) continue;
2815 try file_ptr.object.initOutputMergeSections(self);
2817 const object = self.file(index).?.object;
2818 if (!object.alive) continue;
2819 if (!object.dirty) continue;
2820 try object.initOutputMergeSections(self);
28162821 }
28172822
28182823 for (self.objects.items) |index| {
2819 const file_ptr = self.file(index).?;
2820 if (!file_ptr.isAlive()) continue;
2821 file_ptr.object.resolveMergeSubsections(self) catch |err| switch (err) {
2824 const object = self.file(index).?.object;
2825 if (!object.alive) continue;
2826 if (!object.dirty) continue;
2827 object.resolveMergeSubsections(self) catch |err| switch (err) {
28222828 error.LinkFailure => has_errors = true,
28232829 else => |e| return e,
28242830 };
src/link/Elf/Object.zig+1
......@@ -29,6 +29,7 @@ cies: std.ArrayListUnmanaged(Cie) = .empty,
2929eh_frame_data: std.ArrayListUnmanaged(u8) = .empty,
3030
3131alive: bool = true,
32dirty: bool = true,
3233num_dynrelocs: u32 = 0,
3334
3435output_symtab_ctx: Elf.SymtabCtx = .{},