| ... | ... | @@ -1811,17 +1811,29 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type |
| 1811 | 1811 | } |
| 1812 | 1812 | }, |
| 1813 | 1813 | .memory => |addr| { |
| 1814 | | if (self.bin_file.options.pie) { |
| 1815 | | return self.fail("TODO implement storing to memory when targeting PIE", .{}); |
| 1816 | | } |
| 1817 | | |
| 1818 | | // TODO: in case the address fits in an imm32 we can use [ds:imm32] |
| 1819 | | // instead of wasting an instruction copying the address to a register |
| 1820 | | |
| 1821 | 1814 | value.freezeIfRegister(&self.register_manager); |
| 1822 | 1815 | defer value.unfreezeIfRegister(&self.register_manager); |
| 1823 | 1816 | |
| 1824 | | const addr_reg = try self.copyToTmpRegister(ptr_ty, .{ .immediate = addr }); |
| 1817 | const addr_reg: Register = blk: { |
| 1818 | if (self.bin_file.options.pie) { |
| 1819 | const addr_reg = try self.register_manager.allocReg(null); |
| 1820 | _ = try self.addInst(.{ |
| 1821 | .tag = .lea, |
| 1822 | .ops = (Mir.Ops{ |
| 1823 | .reg1 = addr_reg.to64(), |
| 1824 | .flags = 0b10, |
| 1825 | }).encode(), |
| 1826 | .data = .{ .got_entry = @truncate(u32, addr) }, |
| 1827 | }); |
| 1828 | break :blk addr_reg; |
| 1829 | } else { |
| 1830 | // TODO: in case the address fits in an imm32 we can use [ds:imm32] |
| 1831 | // instead of wasting an instruction copying the address to a register |
| 1832 | const addr_reg = try self.copyToTmpRegister(ptr_ty, .{ .immediate = addr }); |
| 1833 | break :blk addr_reg; |
| 1834 | } |
| 1835 | }; |
| 1836 | |
| 1825 | 1837 | // to get the actual address of the value we want to modify we have to go through the GOT |
| 1826 | 1838 | // mov reg, [reg] |
| 1827 | 1839 | _ = try self.addInst(.{ |