zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 04a8f217c651f56a2e185d87dd40c0a87ee78bc5 (tree)
parent 9a80ac0429b34541b91671246833c47143d1e4da
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Thu,  5 Oct 2023 00:34:45 +0200

elf: fix COMDAT deduping logic

Diffstat:
Msrc/link/Elf/Atom.zig | 2+-
Msrc/link/Elf/Object.zig | 8+++++---
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig @@ -1172,7 +1172,7 @@ pub const Index = u32; pub const Flags = packed struct { /// Specifies whether this atom is alive or has been garbage collected. - alive: bool = false, + alive: bool = true, /// Specifies if the atom has been visited during garbage collection. visited: bool = false, diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig @@ -130,7 +130,10 @@ fn initAtoms(self: *Object, elf_file: *Elf) !void { continue; } - const group_signature_off = try self.strings.insert(elf_file.base.allocator, group_signature); + // Note the assumption about a global strtab used here to disambiguate common + // COMDAT owners. + const gpa = elf_file.base.allocator; + const group_signature_off = try elf_file.strtab.insert(gpa, group_signature); const gop = try elf_file.getOrCreateComdatGroupOwner(group_signature_off); const comdat_group_index = try elf_file.addComdatGroup(); const comdat_group = elf_file.comdatGroup(comdat_group_index); @@ -138,7 +141,7 @@ fn initAtoms(self: *Object, elf_file: *Elf) !void { .owner = gop.index, .shndx = shndx, }; - try self.comdat_groups.append(elf_file.base.allocator, comdat_group_index); + try self.comdat_groups.append(gpa, comdat_group_index); }, elf.SHT_SYMTAB_SHNDX => @panic("TODO SHT_SYMTAB_SHNDX"), @@ -184,7 +187,6 @@ fn addAtom( atom.name_offset = try elf_file.strtab.insert(elf_file.base.allocator, name); atom.file_index = self.index; atom.input_section_index = shndx; - atom.flags.alive = true; self.atoms.items[shndx] = atom_index; if (shdr.sh_flags & elf.SHF_COMPRESSED != 0) {