commit 373ae980c0c7cf66f61c33def3a4fef06c1d95b7 (tree)
parent b8d78661939aac548cbac28873836b697eb0e4f3
Author: Jacob Young <jacobly0@users.noreply.github.com>
Date: Sat, 29 Mar 2025 18:43:53 -0400
Elf: fix incrementally reallocating the last atom in a section
Diffstat:
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig
@@ -1937,9 +1937,14 @@ pub fn allocateAtom(self: *ZigObject, atom_ptr: *Atom, requires_padding: bool, e
const shdr = &slice.items(.shdr)[atom_ptr.output_section_index];
const last_atom_ref = &slice.items(.last_atom)[atom_ptr.output_section_index];
- // This only works if this atom is the only atom in the output section. In
- // every other case, we need to redo the prev/next links.
- if (last_atom_ref.eql(atom_ptr.ref())) last_atom_ref.* = .{};
+ if (last_atom_ref.eql(atom_ptr.ref())) {
+ if (atom_ptr.prevAtom(elf_file)) |prev_atom| {
+ prev_atom.next_atom_ref = .{};
+ last_atom_ref.* = prev_atom.ref();
+ } else {
+ last_atom_ref.* = .{};
+ }
+ }
const alloc_res = try elf_file.allocateChunk(.{
.shndx = atom_ptr.output_section_index,
diff --git a/test/incremental/no_change_preserves_tag_names b/test/incremental/no_change_preserves_tag_names
@@ -0,0 +1,20 @@
+#target=x86_64-linux-selfhosted
+#target=x86_64-linux-cbe
+#target=x86_64-windows-cbe
+//#target=wasm32-wasi-selfhosted
+#update=initial version
+#file=main.zig
+const std = @import("std");
+var some_enum: enum { first, second } = .first;
+pub fn main() !void {
+ try std.io.getStdOut().writeAll(@tagName(some_enum));
+}
+#expect_stdout="first"
+#update=no change
+#file=main.zig
+const std = @import("std");
+var some_enum: enum { first, second } = .first;
+pub fn main() !void {
+ try std.io.getStdOut().writeAll(@tagName(some_enum));
+}
+#expect_stdout="first"