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 {
334334 }
335335
336336 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();
337338 mf.resizeNode(gpa, ni, size) catch |err| switch (err) {
338339 error.OutOfMemory,
339340 error.Canceled,
......@@ -900,6 +901,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested
900901 var last_fixed_ni = ni;
901902 var first_floating_ni = node.next;
902903 var shift = new_size - old_size;
904 var max_shift_align: std.mem.Alignment = .@"1";
903905 var direction: enum { forward, reverse } = .forward;
904906 while (true) {
905907 assert(last_fixed_ni != .none);
......@@ -916,9 +918,9 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested
916918 if (new_last_fixed_offset + last_fixed_size <= old_first_floating_offset)
917919 break :make_space;
918920 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));
920922 if (first_floating.flags.fixed) {
921 shift = shift_alignment.forward(@intCast(
923 shift = max_shift_align.forward(@intCast(
922924 @max(shift, first_floating_size),
923925 ));
924926
......@@ -930,7 +932,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested
930932 // Move the found floating node to make space for preceding fixed nodes
931933 const last = parent.last.get(mf);
932934 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(
934936 @intCast(@max(new_last_fixed_offset + last_fixed_size, last_offset + last_size)),
935937 );
936938 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
991993 last_fixed_ni.setLocationAssumeCapacity(
992994 mf,
993995 old_last_fixed_offset,
994 last_fixed_size + shift,
996 new_size,
995997 );
996998 return;
997999 }