Elf: fix incrementally reallocating the last atom in a section

This commit is contained in:
Jacob Young 2025-03-29 18:43:53 -04:00 committed by Andrew Kelley
parent d53cc5e5b2
commit b431e9af97
2 changed files with 28 additions and 3 deletions

View file

@ -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,

View file

@ -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"