authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-05 01:55:35-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-23 00:26:55-04:00
log303521cd14e17099be7aade312e83ea539c67b42
tree86ff36ee010a747e025eedab6a84a253cb9b4d5d
parentae1130ab2090ce25cd709c89749da2e3cd161d2f

MappedFile: fixup resize node shifting when siblings have different alignments


1 files changed, 6 insertions(+), 4 deletions(-)

src/link/MappedFile.zig+6-4
...@@ -334,6 +334,7 @@ pub const Node = extern struct {...@@ -334,6 +334,7 @@ pub const Node = extern struct {
334 }334 }
335335
336 pub fn resize(ni: Node.Index, mf: *MappedFile, gpa: std.mem.Allocator, size: u64) Error!void {336 pub fn resize(ni: Node.Index, mf: *MappedFile, gpa: std.mem.Allocator, size: u64) Error!void {
337 defer if (std.debug.runtime_safety) mf.verify();
337 mf.resizeNode(gpa, ni, size) catch |err| switch (err) {338 mf.resizeNode(gpa, ni, size) catch |err| switch (err) {
338 error.OutOfMemory,339 error.OutOfMemory,
339 error.Canceled,340 error.Canceled,
...@@ -900,6 +901,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested...@@ -900,6 +901,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested
900 var last_fixed_ni = ni;901 var last_fixed_ni = ni;
901 var first_floating_ni = node.next;902 var first_floating_ni = node.next;
902 var shift = new_size - old_size;903 var shift = new_size - old_size;
904 var max_shift_align: std.mem.Alignment = .@"1";
903 var direction: enum { forward, reverse } = .forward;905 var direction: enum { forward, reverse } = .forward;
904 while (true) {906 while (true) {
905 assert(last_fixed_ni != .none);907 assert(last_fixed_ni != .none);
...@@ -916,9 +918,9 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested...@@ -916,9 +918,9 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested
916 if (new_last_fixed_offset + last_fixed_size <= old_first_floating_offset)918 if (new_last_fixed_offset + last_fixed_size <= old_first_floating_offset)
917 break :make_space;919 break :make_space;
918 assert(direction == .forward);920 assert(direction == .forward);
919 const shift_alignment = first_floating.flags.alignment.max(last_fixed.flags.alignment);921 max_shift_align = max_shift_align.max(first_floating.flags.alignment.max(last_fixed.flags.alignment));
920 if (first_floating.flags.fixed) {922 if (first_floating.flags.fixed) {
921 shift = shift_alignment.forward(@intCast(923 shift = max_shift_align.forward(@intCast(
922 @max(shift, first_floating_size),924 @max(shift, first_floating_size),
923 ));925 ));
924926
...@@ -930,7 +932,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested...@@ -930,7 +932,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested
930 // Move the found floating node to make space for preceding fixed nodes932 // Move the found floating node to make space for preceding fixed nodes
931 const last = parent.last.get(mf);933 const last = parent.last.get(mf);
932 const last_offset, const last_size = last.location().resolve(mf);934 const last_offset, const last_size = last.location().resolve(mf);
933 const new_first_floating_offset = shift_alignment.forward(935 const new_first_floating_offset = max_shift_align.forward(
934 @intCast(@max(new_last_fixed_offset + last_fixed_size, last_offset + last_size)),936 @intCast(@max(new_last_fixed_offset + last_fixed_size, last_offset + last_size)),
935 );937 );
936 const new_parent_size = new_first_floating_offset + first_floating_size;938 const new_parent_size = new_first_floating_offset + first_floating_size;
...@@ -991,7 +993,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested...@@ -991,7 +993,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested
991 last_fixed_ni.setLocationAssumeCapacity(993 last_fixed_ni.setLocationAssumeCapacity(
992 mf,994 mf,
993 old_last_fixed_offset,995 old_last_fixed_offset,
994 last_fixed_size + shift,996 new_size,
995 );997 );
996 return;998 return;
997 }999 }