diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2022-10-20 22:50:39 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2022-10-22 07:59:24 +0200 |
| commit | 0cc4d54781ca3835e2f83c8ce93b485366a52b2a (patch) | |
| tree | d91f8644359a2210fcc7424fec9c279fd6ce4dd6 /src/link | |
| parent | f8cbe29a17e17edf6679feb0d582f59ed4be7d7f (diff) | |
| download | zig-0cc4d54781ca3835e2f83c8ce93b485366a52b2a.tar.gz zig-0cc4d54781ca3835e2f83c8ce93b485366a52b2a.zip | |
macho: do not skip over SUBTRACTOR reloc when dead stripping
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/MachO/dead_strip.zig | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/link/MachO/dead_strip.zig b/src/link/MachO/dead_strip.zig index 8bcc6ca062..39ab4417c2 100644 --- a/src/link/MachO/dead_strip.zig +++ b/src/link/MachO/dead_strip.zig @@ -129,25 +129,37 @@ fn markLive( const relocs = Atom.getAtomRelocs(zld, atom_index); const reverse_lookup = reverse_lookups[atom.getFile().?]; for (relocs) |rel| { - switch (cpu_arch) { - .aarch64 => { + const target = switch (cpu_arch) { + .aarch64 => blk: { const rel_type = @intToEnum(macho.reloc_type_arm64, rel.r_type); switch (rel_type) { - .ARM64_RELOC_ADDEND, .ARM64_RELOC_SUBTRACTOR => continue, - else => {}, + .ARM64_RELOC_ADDEND => continue, + .ARM64_RELOC_SUBTRACTOR => { + const sym_index = reverse_lookup[rel.r_symbolnum]; + break :blk SymbolWithLoc{ + .sym_index = sym_index, + .file = atom.file, + }; + }, + else => break :blk try Atom.parseRelocTarget(zld, atom_index, rel, reverse_lookup), } }, - .x86_64 => { + .x86_64 => blk: { const rel_type = @intToEnum(macho.reloc_type_x86_64, rel.r_type); switch (rel_type) { - .X86_64_RELOC_SUBTRACTOR => continue, - else => {}, + .X86_64_RELOC_SUBTRACTOR => { + const sym_index = reverse_lookup[rel.r_symbolnum]; + break :blk SymbolWithLoc{ + .sym_index = sym_index, + .file = atom.file, + }; + }, + else => break :blk try Atom.parseRelocTarget(zld, atom_index, rel, reverse_lookup), } }, else => unreachable, - } + }; - const target = try Atom.parseRelocTarget(zld, atom_index, rel, reverse_lookup); const target_sym = zld.getSymbol(target); if (target_sym.undf()) continue; if (target.getFile() == null) { |
