authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-05 00:34:45+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:04+02:00
log04a8f217c651f56a2e185d87dd40c0a87ee78bc5
tree88c21a1678fa5be114b227d873c89a9e067888cb
parent9a80ac0429b34541b91671246833c47143d1e4da

elf: fix COMDAT deduping logic


2 files changed, 6 insertions(+), 4 deletions(-)

src/link/Elf/Atom.zig+1-1
...@@ -1172,7 +1172,7 @@ pub const Index = u32;...@@ -1172,7 +1172,7 @@ pub const Index = u32;
11721172
1173pub const Flags = packed struct {1173pub const Flags = packed struct {
1174 /// Specifies whether this atom is alive or has been garbage collected.1174 /// Specifies whether this atom is alive or has been garbage collected.
1175 alive: bool = false,1175 alive: bool = true,
11761176
1177 /// Specifies if the atom has been visited during garbage collection.1177 /// Specifies if the atom has been visited during garbage collection.
1178 visited: bool = false,1178 visited: bool = false,
src/link/Elf/Object.zig+5-3
...@@ -130,7 +130,10 @@ fn initAtoms(self: *Object, elf_file: *Elf) !void {...@@ -130,7 +130,10 @@ fn initAtoms(self: *Object, elf_file: *Elf) !void {
130 continue;130 continue;
131 }131 }
132132
133 const group_signature_off = try self.strings.insert(elf_file.base.allocator, group_signature);133 // Note the assumption about a global strtab used here to disambiguate common
134 // COMDAT owners.
135 const gpa = elf_file.base.allocator;
136 const group_signature_off = try elf_file.strtab.insert(gpa, group_signature);
134 const gop = try elf_file.getOrCreateComdatGroupOwner(group_signature_off);137 const gop = try elf_file.getOrCreateComdatGroupOwner(group_signature_off);
135 const comdat_group_index = try elf_file.addComdatGroup();138 const comdat_group_index = try elf_file.addComdatGroup();
136 const comdat_group = elf_file.comdatGroup(comdat_group_index);139 const comdat_group = elf_file.comdatGroup(comdat_group_index);
...@@ -138,7 +141,7 @@ fn initAtoms(self: *Object, elf_file: *Elf) !void {...@@ -138,7 +141,7 @@ fn initAtoms(self: *Object, elf_file: *Elf) !void {
138 .owner = gop.index,141 .owner = gop.index,
139 .shndx = shndx,142 .shndx = shndx,
140 };143 };
141 try self.comdat_groups.append(elf_file.base.allocator, comdat_group_index);144 try self.comdat_groups.append(gpa, comdat_group_index);
142 },145 },
143146
144 elf.SHT_SYMTAB_SHNDX => @panic("TODO SHT_SYMTAB_SHNDX"),147 elf.SHT_SYMTAB_SHNDX => @panic("TODO SHT_SYMTAB_SHNDX"),
...@@ -184,7 +187,6 @@ fn addAtom(...@@ -184,7 +187,6 @@ fn addAtom(
184 atom.name_offset = try elf_file.strtab.insert(elf_file.base.allocator, name);187 atom.name_offset = try elf_file.strtab.insert(elf_file.base.allocator, name);
185 atom.file_index = self.index;188 atom.file_index = self.index;
186 atom.input_section_index = shndx;189 atom.input_section_index = shndx;
187 atom.flags.alive = true;
188 self.atoms.items[shndx] = atom_index;190 self.atoms.items[shndx] = atom_index;
189191
190 if (shdr.sh_flags & elf.SHF_COMPRESSED != 0) {192 if (shdr.sh_flags & elf.SHF_COMPRESSED != 0) {