diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2025-03-29 18:43:53 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-03-31 19:06:25 -0400 |
| commit | b431e9af9764b118ac8f515b4fede3192474d338 (patch) | |
| tree | a196aae7f76ebe8b0095de9d95e752a0111a8e1c /src | |
| parent | d53cc5e5b2ac51793ea19a847d8cee409af1dee3 (diff) | |
| download | zig-b431e9af9764b118ac8f515b4fede3192474d338.tar.gz zig-b431e9af9764b118ac8f515b4fede3192474d338.zip | |
Elf: fix incrementally reallocating the last atom in a section
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/Elf/ZigObject.zig | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index 5afb33826c..86abc5e7ae 100644 --- 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, |
