zig

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

commit 0cc4d54781ca3835e2f83c8ce93b485366a52b2a (tree)
parent f8cbe29a17e17edf6679feb0d582f59ed4be7d7f
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Thu, 20 Oct 2022 22:50:39 +0200

macho: do not skip over SUBTRACTOR reloc when dead stripping

Diffstat:
Msrc/link/MachO/dead_strip.zig | 30+++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)

diff --git 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) {