Skip to content

Commit b431e9a

Browse files
jacobly0andrewrk
authored andcommitted
Elf: fix incrementally reallocating the last atom in a section
1 parent d53cc5e commit b431e9a

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/link/Elf/ZigObject.zig

+8-3
Original file line numberDiff line numberDiff line change
@@ -1937,9 +1937,14 @@ pub fn allocateAtom(self: *ZigObject, atom_ptr: *Atom, requires_padding: bool, e
19371937
const shdr = &slice.items(.shdr)[atom_ptr.output_section_index];
19381938
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. In
1941-
// every other case, we need to redo the prev/next links.
1942-
if (last_atom_ref.eql(atom_ptr.ref())) last_atom_ref.* = .{};
1940+
if (last_atom_ref.eql(atom_ptr.ref())) {
1941+
if (atom_ptr.prevAtom(elf_file)) |prev_atom| {
1942+
prev_atom.next_atom_ref = .{};
1943+
last_atom_ref.* = prev_atom.ref();
1944+
} else {
1945+
last_atom_ref.* = .{};
1946+
}
1947+
}
19431948

19441949
const alloc_res = try elf_file.allocateChunk(.{
19451950
.shndx = atom_ptr.output_section_index,
Original file line numberDiff line numberDiff line change
@@ -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
7+
const std = @import("std");
8+
var some_enum: enum { first, second } = .first;
9+
pub 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
15+
const std = @import("std");
16+
var some_enum: enum { first, second } = .first;
17+
pub fn main() !void {
18+
try std.io.getStdOut().writeAll(@tagName(some_enum));
19+
}
20+
#expect_stdout="first"

0 commit comments

Comments
 (0)