authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-10-20 22:50:39+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-10-22 07:59:24+02:00
log0cc4d54781ca3835e2f83c8ce93b485366a52b2a
treed91f8644359a2210fcc7424fec9c279fd6ce4dd6
parentf8cbe29a17e17edf6679feb0d582f59ed4be7d7f

macho: do not skip over SUBTRACTOR reloc when dead stripping


1 files changed, 21 insertions(+), 9 deletions(-)

src/link/MachO/dead_strip.zig+21-9
...@@ -129,25 +129,37 @@ fn markLive(...@@ -129,25 +129,37 @@ fn markLive(
129 const relocs = Atom.getAtomRelocs(zld, atom_index);129 const relocs = Atom.getAtomRelocs(zld, atom_index);
130 const reverse_lookup = reverse_lookups[atom.getFile().?];130 const reverse_lookup = reverse_lookups[atom.getFile().?];
131 for (relocs) |rel| {131 for (relocs) |rel| {
132 switch (cpu_arch) {132 const target = switch (cpu_arch) {
133 .aarch64 => {133 .aarch64 => blk: {
134 const rel_type = @intToEnum(macho.reloc_type_arm64, rel.r_type);134 const rel_type = @intToEnum(macho.reloc_type_arm64, rel.r_type);
135 switch (rel_type) {135 switch (rel_type) {
136 .ARM64_RELOC_ADDEND, .ARM64_RELOC_SUBTRACTOR => continue,136 .ARM64_RELOC_ADDEND => continue,
137 else => {},137 .ARM64_RELOC_SUBTRACTOR => {
138 const sym_index = reverse_lookup[rel.r_symbolnum];
139 break :blk SymbolWithLoc{
140 .sym_index = sym_index,
141 .file = atom.file,
142 };
143 },
144 else => break :blk try Atom.parseRelocTarget(zld, atom_index, rel, reverse_lookup),
138 }145 }
139 },146 },
140 .x86_64 => {147 .x86_64 => blk: {
141 const rel_type = @intToEnum(macho.reloc_type_x86_64, rel.r_type);148 const rel_type = @intToEnum(macho.reloc_type_x86_64, rel.r_type);
142 switch (rel_type) {149 switch (rel_type) {
143 .X86_64_RELOC_SUBTRACTOR => continue,150 .X86_64_RELOC_SUBTRACTOR => {
144 else => {},151 const sym_index = reverse_lookup[rel.r_symbolnum];
152 break :blk SymbolWithLoc{
153 .sym_index = sym_index,
154 .file = atom.file,
155 };
156 },
157 else => break :blk try Atom.parseRelocTarget(zld, atom_index, rel, reverse_lookup),
145 }158 }
146 },159 },
147 else => unreachable,160 else => unreachable,
148 }161 };
149162
150 const target = try Atom.parseRelocTarget(zld, atom_index, rel, reverse_lookup);
151 const target_sym = zld.getSymbol(target);163 const target_sym = zld.getSymbol(target);
152 if (target_sym.undf()) continue;164 if (target_sym.undf()) continue;
153 if (target.getFile() == null) {165 if (target.getFile() == null) {