authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-03-29 18:43:53-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-03-31 19:06:25-04:00
logb431e9af9764b118ac8f515b4fede3192474d338
treea196aae7f76ebe8b0095de9d95e752a0111a8e1c
parentd53cc5e5b2ac51793ea19a847d8cee409af1dee3

Elf: fix incrementally reallocating the last atom in a section


2 files changed, 28 insertions(+), 3 deletions(-)

src/link/Elf/ZigObject.zig+8-3
...@@ -1937,9 +1937,14 @@ pub fn allocateAtom(self: *ZigObject, atom_ptr: *Atom, requires_padding: bool, e...@@ -1937,9 +1937,14 @@ pub fn allocateAtom(self: *ZigObject, atom_ptr: *Atom, requires_padding: bool, e
1937 const shdr = &slice.items(.shdr)[atom_ptr.output_section_index];1937 const shdr = &slice.items(.shdr)[atom_ptr.output_section_index];
1938 const last_atom_ref = &slice.items(.last_atom)[atom_ptr.output_section_index];1938 const last_atom_ref = &slice.items(.last_atom)[atom_ptr.output_section_index];
19391939
1940 // This only works if this atom is the only atom in the output section. In1940 if (last_atom_ref.eql(atom_ptr.ref())) {
1941 // every other case, we need to redo the prev/next links.1941 if (atom_ptr.prevAtom(elf_file)) |prev_atom| {
1942 if (last_atom_ref.eql(atom_ptr.ref())) last_atom_ref.* = .{};1942 prev_atom.next_atom_ref = .{};
1943 last_atom_ref.* = prev_atom.ref();
1944 } else {
1945 last_atom_ref.* = .{};
1946 }
1947 }
19431948
1944 const alloc_res = try elf_file.allocateChunk(.{1949 const alloc_res = try elf_file.allocateChunk(.{
1945 .shndx = atom_ptr.output_section_index,1950 .shndx = atom_ptr.output_section_index,
test/incremental/no_change_preserves_tag_names created+20
...@@ -0,0 +1,20 @@
1#target=x86_64-linux-selfhosted
2#target=x86_64-linux-cbe
3#target=x86_64-windows-cbe
4//#target=wasm32-wasi-selfhosted
5#update=initial version
6#file=main.zig
7const std = @import("std");
8var some_enum: enum { first, second } = .first;
9pub fn main() !void {
10 try std.io.getStdOut().writeAll(@tagName(some_enum));
11}
12#expect_stdout="first"
13#update=no change
14#file=main.zig
15const std = @import("std");
16var some_enum: enum { first, second } = .first;
17pub fn main() !void {
18 try std.io.getStdOut().writeAll(@tagName(some_enum));
19}
20#expect_stdout="first"