authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-23 06:56:33+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-23 06:56:36+02:00
logf4c4ca4b4c6f1d0c61ce85d1fd9677ff01cb3072
treed299a7a91d52018c979dd2fba0c9a952bc3adbc5
parentd83a3f1746c81026d1cf0244156513c9b5a2a9f6

elf: fix condition for skipping symbols if atom is dead

Skipping the symbols too early when resolving would end up in the linker not deduping CIEs fully.

2 files changed, 10 insertions(+), 12 deletions(-)

src/link/Elf/Object.zig+5-6
......@@ -524,12 +524,6 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) !void {
524524 const first_global = self.first_global orelse return;
525525 for (self.globals(), first_global..) |_, i| {
526526 const esym = self.symtab.items[i];
527 if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON and esym.st_shndx != elf.SHN_UNDEF) {
528 const atom_index = self.atoms_indexes.items[esym.st_shndx];
529 const atom_ptr = self.atom(atom_index) orelse continue;
530 if (!atom_ptr.alive) continue;
531 }
532
533527 const resolv = &self.symbols_resolver.items[i - first_global];
534528 const gop = try elf_file.resolver.getOrPut(gpa, .{
535529 .index = @intCast(i),
......@@ -541,6 +535,11 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) !void {
541535 resolv.* = gop.index;
542536
543537 if (esym.st_shndx == elf.SHN_UNDEF) continue;
538 if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) {
539 const atom_index = self.atoms_indexes.items[esym.st_shndx];
540 const atom_ptr = self.atom(atom_index) orelse continue;
541 if (!atom_ptr.alive) continue;
542 }
544543 if (elf_file.symbol(gop.ref.*) == null) {
545544 gop.ref.* = .{ .index = @intCast(i), .file = self.index };
546545 continue;
src/link/Elf/ZigObject.zig+5-6
......@@ -603,12 +603,6 @@ pub fn resolveSymbols(self: *ZigObject, elf_file: *Elf) !void {
603603 const global = &self.symbols.items[index];
604604 const esym = global.elfSym(elf_file);
605605 const shndx = self.symtab.items(.shndx)[global.esym_index];
606 if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON and esym.st_shndx != elf.SHN_UNDEF) {
607 assert(esym.st_shndx == SHN_ATOM);
608 const atom_ptr = self.atom(shndx) orelse continue;
609 if (!atom_ptr.alive) continue;
610 }
611
612606 const resolv = &self.symbols_resolver.items[i];
613607 const gop = try elf_file.resolver.getOrPut(gpa, .{
614608 .index = @intCast(i | global_symbol_bit),
......@@ -620,6 +614,11 @@ pub fn resolveSymbols(self: *ZigObject, elf_file: *Elf) !void {
620614 resolv.* = gop.index;
621615
622616 if (esym.st_shndx == elf.SHN_UNDEF) continue;
617 if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) {
618 assert(esym.st_shndx == SHN_ATOM);
619 const atom_ptr = self.atom(shndx) orelse continue;
620 if (!atom_ptr.alive) continue;
621 }
623622 if (elf_file.symbol(gop.ref.*) == null) {
624623 gop.ref.* = .{ .index = @intCast(i | global_symbol_bit), .file = self.index };
625624 continue;