aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-09-23 06:56:33 +0200
committerJakub Konka <kubkon@jakubkonka.com>2024-09-23 06:56:36 +0200
commitf4c4ca4b4c6f1d0c61ce85d1fd9677ff01cb3072 (patch)
treed299a7a91d52018c979dd2fba0c9a952bc3adbc5 /src
parentd83a3f1746c81026d1cf0244156513c9b5a2a9f6 (diff)
downloadzig-f4c4ca4b4c6f1d0c61ce85d1fd9677ff01cb3072.tar.gz
zig-f4c4ca4b4c6f1d0c61ce85d1fd9677ff01cb3072.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/link/Elf/Object.zig11
-rw-r--r--src/link/Elf/ZigObject.zig11
2 files changed, 10 insertions, 12 deletions
diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig
index a7091b7394..de6903504b 100644
--- a/src/link/Elf/Object.zig
+++ b/src/link/Elf/Object.zig
@@ -524,12 +524,6 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) !void {
const first_global = self.first_global orelse return;
for (self.globals(), first_global..) |_, i| {
const esym = self.symtab.items[i];
- if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON and esym.st_shndx != elf.SHN_UNDEF) {
- const atom_index = self.atoms_indexes.items[esym.st_shndx];
- const atom_ptr = self.atom(atom_index) orelse continue;
- if (!atom_ptr.alive) continue;
- }
-
const resolv = &self.symbols_resolver.items[i - first_global];
const gop = try elf_file.resolver.getOrPut(gpa, .{
.index = @intCast(i),
@@ -541,6 +535,11 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) !void {
resolv.* = gop.index;
if (esym.st_shndx == elf.SHN_UNDEF) continue;
+ if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) {
+ const atom_index = self.atoms_indexes.items[esym.st_shndx];
+ const atom_ptr = self.atom(atom_index) orelse continue;
+ if (!atom_ptr.alive) continue;
+ }
if (elf_file.symbol(gop.ref.*) == null) {
gop.ref.* = .{ .index = @intCast(i), .file = self.index };
continue;
diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig
index 671049919d..de70462b07 100644
--- a/src/link/Elf/ZigObject.zig
+++ b/src/link/Elf/ZigObject.zig
@@ -603,12 +603,6 @@ pub fn resolveSymbols(self: *ZigObject, elf_file: *Elf) !void {
const global = &self.symbols.items[index];
const esym = global.elfSym(elf_file);
const shndx = self.symtab.items(.shndx)[global.esym_index];
- if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON and esym.st_shndx != elf.SHN_UNDEF) {
- assert(esym.st_shndx == SHN_ATOM);
- const atom_ptr = self.atom(shndx) orelse continue;
- if (!atom_ptr.alive) continue;
- }
-
const resolv = &self.symbols_resolver.items[i];
const gop = try elf_file.resolver.getOrPut(gpa, .{
.index = @intCast(i | global_symbol_bit),
@@ -620,6 +614,11 @@ pub fn resolveSymbols(self: *ZigObject, elf_file: *Elf) !void {
resolv.* = gop.index;
if (esym.st_shndx == elf.SHN_UNDEF) continue;
+ if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) {
+ assert(esym.st_shndx == SHN_ATOM);
+ const atom_ptr = self.atom(shndx) orelse continue;
+ if (!atom_ptr.alive) continue;
+ }
if (elf_file.symbol(gop.ref.*) == null) {
gop.ref.* = .{ .index = @intCast(i | global_symbol_bit), .file = self.index };
continue;