| ... | @@ -2601,11 +2601,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2601,11 +2601,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2601 | }).toU32()); | 2601 | }).toU32()); |
| 2602 | // adr x28, #8 | 2602 | // adr x28, #8 |
| 2603 | mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.adr(.x28, 8).toU32()); | 2603 | mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.adr(.x28, 8).toU32()); |
| 2604 | try macho_file.pie_fixups.append(self.bin_file.allocator, .{ | 2604 | if (self.bin_file.cast(link.File.MachO)) |macho_file| { |
| 2605 | .address = addr, | 2605 | try macho_file.pie_fixups.append(self.bin_file.allocator, .{ |
| 2606 | .start = self.code.items.len, | 2606 | .address = addr, |
| 2607 | .len = 4, | 2607 | .start = self.code.items.len, |
| 2608 | }); | 2608 | .len = 4, |
| | 2609 | }); |
| | 2610 | } else { |
| | 2611 | return self.fail(src, "TODO implement genSetReg for PIE on this platform", .{}); |
| | 2612 | } |
| 2609 | // b [label] | 2613 | // b [label] |
| 2610 | mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.b(0).toU32()); | 2614 | mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.b(0).toU32()); |
| 2611 | // mov r, x0 | 2615 | // mov r, x0 |
| ... | @@ -2626,11 +2630,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2626,11 +2630,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2626 | }).toU32()); | 2630 | }).toU32()); |
| 2627 | // adr x28, #8 | 2631 | // adr x28, #8 |
| 2628 | mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.adr(.x28, 8).toU32()); | 2632 | mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.adr(.x28, 8).toU32()); |
| 2629 | try macho_file.pie_fixups.append(self.bin_file.allocator, .{ | 2633 | if (self.bin_file.cast(link.File.MachO)) |macho_file| { |
| 2630 | .address = addr, | 2634 | try macho_file.pie_fixups.append(self.bin_file.allocator, .{ |
| 2631 | .start = self.code.items.len, | 2635 | .address = addr, |
| 2632 | .len = 4, | 2636 | .start = self.code.items.len, |
| 2633 | }); | 2637 | .len = 4, |
| | 2638 | }); |
| | 2639 | } else { |
| | 2640 | return self.fail(src, "TODO implement genSetReg for PIE on this platform", .{}); |
| | 2641 | } |
| 2634 | // b [label] | 2642 | // b [label] |
| 2635 | mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.b(0).toU32()); | 2643 | mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.b(0).toU32()); |
| 2636 | // mov r, x0 | 2644 | // mov r, x0 |
| ... | @@ -2828,7 +2836,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2828,7 +2836,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2828 | self.code.appendSliceAssumeCapacity(&[_]u8{ 0x8B, R }); | 2836 | self.code.appendSliceAssumeCapacity(&[_]u8{ 0x8B, R }); |
| 2829 | }, | 2837 | }, |
| 2830 | .memory => |x| { | 2838 | .memory => |x| { |
| 2831 | if (self.bin_file.cast(link.File.MachO)) |macho_file| { | 2839 | if (self.bin_file.options.pie) { |
| 2832 | // For MachO, the binary, with the exception of object files, has to be a PIE. | 2840 | // For MachO, the binary, with the exception of object files, has to be a PIE. |
| 2833 | // Therefore, we cannot load an absolute address. | 2841 | // Therefore, we cannot load an absolute address. |
| 2834 | assert(x > math.maxInt(u32)); // 32bit direct addressing is not supported by MachO. | 2842 | assert(x > math.maxInt(u32)); // 32bit direct addressing is not supported by MachO. |
| ... | @@ -2838,11 +2846,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2838,11 +2846,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2838 | // later in the linker. | 2846 | // later in the linker. |
| 2839 | if (reg.id() == 0) { // %rax is special-cased | 2847 | if (reg.id() == 0) { // %rax is special-cased |
| 2840 | try self.code.ensureCapacity(self.code.items.len + 5); | 2848 | try self.code.ensureCapacity(self.code.items.len + 5); |
| 2841 | try macho_file.pie_fixups.append(self.bin_file.allocator, .{ | 2849 | if (self.bin_file.cast(link.File.MachO)) |macho_file| { |
| 2842 | .address = x, | 2850 | try macho_file.pie_fixups.append(self.bin_file.allocator, .{ |
| 2843 | .start = self.code.items.len, | 2851 | .address = x, |
| 2844 | .len = 5, | 2852 | .start = self.code.items.len, |
| 2845 | }); | 2853 | .len = 5, |
| | 2854 | }); |
| | 2855 | } else { |
| | 2856 | return self.fail(src, "TODO implement genSetReg for PIE on this platform", .{}); |
| | 2857 | } |
| 2846 | // call [label] | 2858 | // call [label] |
| 2847 | self.code.appendSliceAssumeCapacity(&[_]u8{ | 2859 | self.code.appendSliceAssumeCapacity(&[_]u8{ |
| 2848 | 0xE8, | 2860 | 0xE8, |
| ... | @@ -2855,11 +2867,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2855,11 +2867,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2855 | try self.code.ensureCapacity(self.code.items.len + 10); | 2867 | try self.code.ensureCapacity(self.code.items.len + 10); |
| 2856 | // push %rax | 2868 | // push %rax |
| 2857 | self.code.appendSliceAssumeCapacity(&[_]u8{0x50}); | 2869 | self.code.appendSliceAssumeCapacity(&[_]u8{0x50}); |
| 2858 | try macho_file.pie_fixups.append(self.bin_file.allocator, .{ | 2870 | if (self.bin_file.cast(link.File.MachO)) |macho_file| { |
| 2859 | .address = x, | 2871 | try macho_file.pie_fixups.append(self.bin_file.allocator, .{ |
| 2860 | .start = self.code.items.len, | 2872 | .address = x, |
| 2861 | .len = 5, | 2873 | .start = self.code.items.len, |
| 2862 | }); | 2874 | .len = 5, |
| | 2875 | }); |
| | 2876 | } else { |
| | 2877 | return self.fail(src, "TODO implement genSetReg for PIE on this platform", .{}); |
| | 2878 | } |
| 2863 | // call [label] | 2879 | // call [label] |
| 2864 | self.code.appendSliceAssumeCapacity(&[_]u8{ | 2880 | self.code.appendSliceAssumeCapacity(&[_]u8{ |
| 2865 | 0xE8, | 2881 | 0xE8, |