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...@@ -1038,6 +1038,10 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
10381038
1039 // Beyond this point, everything has been allocated a virtual address and we can resolve1039 // Beyond this point, everything has been allocated a virtual address and we can resolve
1040 // the relocations, and commit objects to file.1040 // the relocations, and commit objects to file.
1041 for (self.objects.items) |index| {
1042 self.file(index).?.object.dirty = false;
1043 }
1044
1041 if (self.zigObjectPtr()) |zo| {1045 if (self.zigObjectPtr()) |zo| {
1042 var has_reloc_errors = false;1046 var has_reloc_errors = false;
1043 for (zo.atoms_indexes.items) |atom_index| {1047 for (zo.atoms_indexes.items) |atom_index| {
...@@ -1399,7 +1403,6 @@ pub fn parseLibraryReportingFailure(self: *Elf, lib: SystemLib, must_link: bool)...@@ -1399,7 +1403,6 @@ pub fn parseLibraryReportingFailure(self: *Elf, lib: SystemLib, must_link: bool)
1399fn parseLibrary(self: *Elf, lib: SystemLib, must_link: bool) ParseError!void {1403fn parseLibrary(self: *Elf, lib: SystemLib, must_link: bool) ParseError!void {
1400 const tracy = trace(@src());1404 const tracy = trace(@src());
1401 defer tracy.end();1405 defer tracy.end();
1402
1403 if (try Archive.isArchive(lib.path)) {1406 if (try Archive.isArchive(lib.path)) {
1404 try self.parseArchive(lib.path, must_link);1407 try self.parseArchive(lib.path, must_link);
1405 } else if (try SharedObject.isSharedObject(lib.path)) {1408 } else if (try SharedObject.isSharedObject(lib.path)) {
...@@ -2799,9 +2802,10 @@ pub fn resolveMergeSections(self: *Elf) !void {...@@ -2799,9 +2802,10 @@ pub fn resolveMergeSections(self: *Elf) !void {
27992802
2800 var has_errors = false;2803 var has_errors = false;
2801 for (self.objects.items) |index| {2804 for (self.objects.items) |index| {
2802 const file_ptr = self.file(index).?;2805 const object = self.file(index).?.object;
2803 if (!file_ptr.isAlive()) continue;2806 if (!object.alive) continue;
2804 file_ptr.object.initInputMergeSections(self) catch |err| switch (err) {2807 if (!object.dirty) continue;
2808 object.initInputMergeSections(self) catch |err| switch (err) {
2805 error.LinkFailure => has_errors = true,2809 error.LinkFailure => has_errors = true,
2806 else => |e| return e,2810 else => |e| return e,
2807 };2811 };
...@@ -2810,15 +2814,17 @@ pub fn resolveMergeSections(self: *Elf) !void {...@@ -2810,15 +2814,17 @@ pub fn resolveMergeSections(self: *Elf) !void {
2810 if (has_errors) return error.FlushFailure;2814 if (has_errors) return error.FlushFailure;
28112815
2812 for (self.objects.items) |index| {2816 for (self.objects.items) |index| {
2813 const file_ptr = self.file(index).?;2817 const object = self.file(index).?.object;
2814 if (!file_ptr.isAlive()) continue;2818 if (!object.alive) continue;
2815 try file_ptr.object.initOutputMergeSections(self);2819 if (!object.dirty) continue;
2820 try object.initOutputMergeSections(self);
2816 }2821 }
28172822
2818 for (self.objects.items) |index| {2823 for (self.objects.items) |index| {
2819 const file_ptr = self.file(index).?;2824 const object = self.file(index).?.object;
2820 if (!file_ptr.isAlive()) continue;2825 if (!object.alive) continue;
2821 file_ptr.object.resolveMergeSubsections(self) catch |err| switch (err) {2826 if (!object.dirty) continue;
2827 object.resolveMergeSubsections(self) catch |err| switch (err) {
2822 error.LinkFailure => has_errors = true,2828 error.LinkFailure => has_errors = true,
2823 else => |e| return e,2829 else => |e| return e,
2824 };2830 };
src/link/Elf/Object.zig+1
...@@ -29,6 +29,7 @@ cies: std.ArrayListUnmanaged(Cie) = .empty,...@@ -29,6 +29,7 @@ cies: std.ArrayListUnmanaged(Cie) = .empty,
29eh_frame_data: std.ArrayListUnmanaged(u8) = .empty,29eh_frame_data: std.ArrayListUnmanaged(u8) = .empty,
3030
31alive: bool = true,31alive: bool = true,
32dirty: bool = true,
32num_dynrelocs: u32 = 0,33num_dynrelocs: u32 = 0,
3334
34output_symtab_ctx: Elf.SymtabCtx = .{},35output_symtab_ctx: Elf.SymtabCtx = .{},