Commit 93cc5496e1

Jakub Konka <kubkon@jakubkonka.com>
2022-10-20 20:00:25
macho: rewrite movq to leaq when TLV is not external pointer
1 parent 5823f19
Changed files (1)
src
link
src/link/MachO/ZldAtom.zig
@@ -843,8 +843,10 @@ fn resolveRelocsX86(
                 log.debug("    | target_addr = 0x{x}", .{adjusted_target_addr});
                 const disp = try calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
 
-                // We need to rewrite the opcode from movq to leaq.
-                atom_code[rel_offset - 2] = 0x8d;
+                if (zld.tlv_ptr_table.get(target) == null) {
+                    // We need to rewrite the opcode from movq to leaq.
+                    atom_code[rel_offset - 2] = 0x8d;
+                }
 
                 mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp);
             },