authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-09-10 00:18:39+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-09-10 00:18:39+02:00
logfc5a6e0e327c1b671aa782d24059e27e5aa55c84
treedb51f363314a023bec3c9c5eefc05839971a5c4a
parentd8f210354577eda1b438d692b28bb3a582913b5a

x86_64: combine got_load, direct_load and imports_load into linker_load MCV


3 files changed, 70 insertions(+), 144 deletions(-)

src/arch/x86_64/CodeGen.zig+67-141
...@@ -128,15 +128,11 @@ pub const MCValue = union(enum) {...@@ -128,15 +128,11 @@ pub const MCValue = union(enum) {
128 /// The value is in memory at a hard-coded address.128 /// The value is in memory at a hard-coded address.
129 /// If the type is a pointer, it means the pointer address is at this memory location.129 /// If the type is a pointer, it means the pointer address is at this memory location.
130 memory: u64,130 memory: u64,
131 /// The value is in memory referenced indirectly via a GOT entry index.131 /// The value is in memory but requires a linker relocation fixup:
132 /// If the type is a pointer, it means the pointer is referenced indirectly via GOT.132 /// * got - the value is referenced indirectly via GOT entry index (the linker emits a got-type reloc)
133 /// When lowered, linker will emit a relocation of type X86_64_RELOC_GOT.133 /// * direct - the value is referenced directly via symbol index index (the linker emits a displacement reloc)
134 got_load: u32,134 /// * import - the value is referenced indirectly via import entry index (the linker emits an import-type reloc)
135 imports_load: u32,135 linker_load: struct { @"type": enum { got, direct, import }, sym_index: u32 },
136 /// The value is in memory referenced directly via symbol index.
137 /// If the type is a pointer, it means the pointer is referenced directly via symbol index.
138 /// When lowered, linker will emit a relocation of type X86_64_RELOC_SIGNED.
139 direct_load: u32,
140 /// The value is one of the stack variables.136 /// The value is one of the stack variables.
141 /// If the type is a pointer, it means the pointer address is in the stack at this offset.137 /// If the type is a pointer, it means the pointer address is in the stack at this offset.
142 stack_offset: i32,138 stack_offset: i32,
...@@ -150,9 +146,7 @@ pub const MCValue = union(enum) {...@@ -150,9 +146,7 @@ pub const MCValue = union(enum) {
150 .memory,146 .memory,
151 .stack_offset,147 .stack_offset,
152 .ptr_stack_offset,148 .ptr_stack_offset,
153 .direct_load,149 .linker_load,
154 .got_load,
155 .imports_load,
156 => true,150 => true,
157 else => false,151 else => false,
158 };152 };
...@@ -165,26 +159,6 @@ pub const MCValue = union(enum) {...@@ -165,26 +159,6 @@ pub const MCValue = union(enum) {
165 };159 };
166 }160 }
167161
168 fn isMutable(mcv: MCValue) bool {
169 return switch (mcv) {
170 .none => unreachable,
171 .unreach => unreachable,
172 .dead => unreachable,
173
174 .immediate,
175 .memory,
176 .eflags,
177 .ptr_stack_offset,
178 .undef,
179 .register_overflow,
180 => false,
181
182 .register,
183 .stack_offset,
184 => true,
185 };
186 }
187
188 fn isRegister(mcv: MCValue) bool {162 fn isRegister(mcv: MCValue) bool {
189 return switch (mcv) {163 return switch (mcv) {
190 .register => true,164 .register => true,
...@@ -2307,11 +2281,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2307,11 +2281,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
2307 .data = .{ .imm = @bitCast(u32, -off) },2281 .data = .{ .imm = @bitCast(u32, -off) },
2308 });2282 });
2309 },2283 },
2310 .memory,2284 .memory, .linker_load => {
2311 .got_load,
2312 .direct_load,
2313 .imports_load,
2314 => {
2315 try self.loadMemPtrIntoRegister(addr_reg, Type.usize, array);2285 try self.loadMemPtrIntoRegister(addr_reg, Type.usize, array);
2316 },2286 },
2317 else => return self.fail("TODO implement array_elem_val when array is {}", .{array}),2287 else => return self.fail("TODO implement array_elem_val when array is {}", .{array}),
...@@ -2652,11 +2622,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo...@@ -2652,11 +2622,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
2652 else => return self.fail("TODO implement loading from register into {}", .{dst_mcv}),2622 else => return self.fail("TODO implement loading from register into {}", .{dst_mcv}),
2653 }2623 }
2654 },2624 },
2655 .memory,2625 .memory, .linker_load => {
2656 .got_load,
2657 .direct_load,
2658 .imports_load,
2659 => {
2660 const reg = try self.copyToTmpRegister(ptr_ty, ptr);2626 const reg = try self.copyToTmpRegister(ptr_ty, ptr);
2661 try self.load(dst_mcv, .{ .register = reg }, ptr_ty);2627 try self.load(dst_mcv, .{ .register = reg }, ptr_ty);
2662 },2628 },
...@@ -2691,10 +2657,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -2691,10 +2657,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
26912657
2692fn loadMemPtrIntoRegister(self: *Self, reg: Register, ptr_ty: Type, ptr: MCValue) InnerError!void {2658fn loadMemPtrIntoRegister(self: *Self, reg: Register, ptr_ty: Type, ptr: MCValue) InnerError!void {
2693 switch (ptr) {2659 switch (ptr) {
2694 .got_load,2660 .linker_load => |load_struct| {
2695 .direct_load,
2696 .imports_load,
2697 => |sym_index| {
2698 const abi_size = @intCast(u32, ptr_ty.abiSize(self.target.*));2661 const abi_size = @intCast(u32, ptr_ty.abiSize(self.target.*));
2699 const mod = self.bin_file.options.module.?;2662 const mod = self.bin_file.options.module.?;
2700 const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl);2663 const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl);
...@@ -2702,11 +2665,10 @@ fn loadMemPtrIntoRegister(self: *Self, reg: Register, ptr_ty: Type, ptr: MCValue...@@ -2702,11 +2665,10 @@ fn loadMemPtrIntoRegister(self: *Self, reg: Register, ptr_ty: Type, ptr: MCValue
2702 fn_owner_decl.link.macho.sym_index2665 fn_owner_decl.link.macho.sym_index
2703 else2666 else
2704 fn_owner_decl.link.coff.sym_index;2667 fn_owner_decl.link.coff.sym_index;
2705 const flags: u2 = switch (ptr) {2668 const flags: u2 = switch (load_struct.@"type") {
2706 .got_load => 0b00,2669 .got => 0b00,
2707 .direct_load => 0b01,2670 .direct => 0b01,
2708 .imports_load => 0b10,2671 .import => 0b10,
2709 else => unreachable,
2710 };2672 };
2711 _ = try self.addInst(.{2673 _ = try self.addInst(.{
2712 .tag = .lea_pic,2674 .tag = .lea_pic,
...@@ -2717,7 +2679,7 @@ fn loadMemPtrIntoRegister(self: *Self, reg: Register, ptr_ty: Type, ptr: MCValue...@@ -2717,7 +2679,7 @@ fn loadMemPtrIntoRegister(self: *Self, reg: Register, ptr_ty: Type, ptr: MCValue
2717 .data = .{2679 .data = .{
2718 .relocation = .{2680 .relocation = .{
2719 .atom_index = atom_index,2681 .atom_index = atom_index,
2720 .sym_index = sym_index,2682 .sym_index = load_struct.sym_index,
2721 },2683 },
2722 },2684 },
2723 });2685 });
...@@ -2801,9 +2763,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type...@@ -2801,9 +2763,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
2801 .register => |src_reg| {2763 .register => |src_reg| {
2802 try self.genInlineMemcpyRegisterRegister(value_ty, reg, src_reg, 0);2764 try self.genInlineMemcpyRegisterRegister(value_ty, reg, src_reg, 0);
2803 },2765 },
2804 .got_load,2766 .linker_load,
2805 .direct_load,
2806 .imports_load,
2807 .memory,2767 .memory,
2808 .stack_offset,2768 .stack_offset,
2809 => {2769 => {
...@@ -2822,11 +2782,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type...@@ -2822,11 +2782,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
2822 },2782 },
2823 }2783 }
2824 },2784 },
2825 .got_load,2785 .linker_load, .memory => {
2826 .direct_load,
2827 .imports_load,
2828 .memory,
2829 => {
2830 const value_lock: ?RegisterLock = switch (value) {2786 const value_lock: ?RegisterLock = switch (value) {
2831 .register => |reg| self.register_manager.lockReg(reg),2787 .register => |reg| self.register_manager.lockReg(reg),
2832 else => null,2788 else => null,
...@@ -2894,11 +2850,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type...@@ -2894,11 +2850,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
2894 .register => {2850 .register => {
2895 return self.store(new_ptr, value, ptr_ty, value_ty);2851 return self.store(new_ptr, value, ptr_ty, value_ty);
2896 },2852 },
2897 .got_load,2853 .linker_load, .memory => {
2898 .direct_load,
2899 .imports_load,
2900 .memory,
2901 => {
2902 if (abi_size <= 8) {2854 if (abi_size <= 8) {
2903 const tmp_reg = try self.register_manager.allocReg(null, gp);2855 const tmp_reg = try self.register_manager.allocReg(null, gp);
2904 const tmp_reg_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);2856 const tmp_reg_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);
...@@ -3606,9 +3558,7 @@ fn genBinOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MCValu...@@ -3606,9 +3558,7 @@ fn genBinOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MCValu
3606 });3558 });
3607 },3559 },
3608 .memory,3560 .memory,
3609 .got_load,3561 .linker_load,
3610 .direct_load,
3611 .imports_load,
3612 .eflags,3562 .eflags,
3613 => {3563 => {
3614 assert(abi_size <= 8);3564 assert(abi_size <= 8);
...@@ -3694,10 +3644,7 @@ fn genBinOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MCValu...@@ -3694,10 +3644,7 @@ fn genBinOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MCValu
3694 => {3644 => {
3695 return self.fail("TODO implement x86 ADD/SUB/CMP source memory", .{});3645 return self.fail("TODO implement x86 ADD/SUB/CMP source memory", .{});
3696 },3646 },
3697 .got_load,3647 .linker_load => {
3698 .direct_load,
3699 .imports_load,
3700 => {
3701 return self.fail("TODO implement x86 ADD/SUB/CMP source symbol at index in linker", .{});3648 return self.fail("TODO implement x86 ADD/SUB/CMP source symbol at index in linker", .{});
3702 },3649 },
3703 .eflags => {3650 .eflags => {
...@@ -3708,10 +3655,7 @@ fn genBinOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MCValu...@@ -3708,10 +3655,7 @@ fn genBinOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MCValu
3708 .memory => {3655 .memory => {
3709 return self.fail("TODO implement x86 ADD/SUB/CMP destination memory", .{});3656 return self.fail("TODO implement x86 ADD/SUB/CMP destination memory", .{});
3710 },3657 },
3711 .got_load,3658 .linker_load => {
3712 .direct_load,
3713 .imports_load,
3714 => {
3715 return self.fail("TODO implement x86 ADD/SUB/CMP destination symbol at index", .{});3659 return self.fail("TODO implement x86 ADD/SUB/CMP destination symbol at index", .{});
3716 },3660 },
3717 }3661 }
...@@ -3779,10 +3723,7 @@ fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: M...@@ -3779,10 +3723,7 @@ fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: M
3779 .memory => {3723 .memory => {
3780 return self.fail("TODO implement x86 multiply source memory", .{});3724 return self.fail("TODO implement x86 multiply source memory", .{});
3781 },3725 },
3782 .got_load,3726 .linker_load => {
3783 .direct_load,
3784 .imports_load,
3785 => {
3786 return self.fail("TODO implement x86 multiply source symbol at index in linker", .{});3727 return self.fail("TODO implement x86 multiply source symbol at index in linker", .{});
3787 },3728 },
3788 .eflags => {3729 .eflags => {
...@@ -3826,10 +3767,7 @@ fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: M...@@ -3826,10 +3767,7 @@ fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: M
3826 .memory, .stack_offset => {3767 .memory, .stack_offset => {
3827 return self.fail("TODO implement x86 multiply source memory", .{});3768 return self.fail("TODO implement x86 multiply source memory", .{});
3828 },3769 },
3829 .got_load,3770 .linker_load => {
3830 .direct_load,
3831 .imports_load,
3832 => {
3833 return self.fail("TODO implement x86 multiply source symbol at index in linker", .{});3771 return self.fail("TODO implement x86 multiply source symbol at index in linker", .{});
3834 },3772 },
3835 .eflags => {3773 .eflags => {
...@@ -3840,10 +3778,7 @@ fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: M...@@ -3840,10 +3778,7 @@ fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: M
3840 .memory => {3778 .memory => {
3841 return self.fail("TODO implement x86 multiply destination memory", .{});3779 return self.fail("TODO implement x86 multiply destination memory", .{});
3842 },3780 },
3843 .got_load,3781 .linker_load => {
3844 .direct_load,
3845 .imports_load,
3846 => {
3847 return self.fail("TODO implement x86 multiply destination symbol at index in linker", .{});3782 return self.fail("TODO implement x86 multiply destination symbol at index in linker", .{});
3848 },3783 },
3849 }3784 }
...@@ -4006,9 +3941,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions....@@ -4006,9 +3941,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.
4006 .unreach => unreachable,3941 .unreach => unreachable,
4007 .dead => unreachable,3942 .dead => unreachable,
4008 .memory => unreachable,3943 .memory => unreachable,
4009 .got_load => unreachable,3944 .linker_load => unreachable,
4010 .direct_load => unreachable,
4011 .imports_load => unreachable,
4012 .eflags => unreachable,3945 .eflags => unreachable,
4013 .register_overflow => unreachable,3946 .register_overflow => unreachable,
4014 }3947 }
...@@ -4066,7 +3999,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions....@@ -4066,7 +3999,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.
4066 const func = func_payload.data;3999 const func = func_payload.data;
4067 const fn_owner_decl = mod.declPtr(func.owner_decl);4000 const fn_owner_decl = mod.declPtr(func.owner_decl);
4068 try self.genSetReg(Type.initTag(.usize), .rax, .{4001 try self.genSetReg(Type.initTag(.usize), .rax, .{
4069 .got_load = fn_owner_decl.link.coff.sym_index,4002 .linker_load = .{
4003 .@"type" = .got,
4004 .sym_index = fn_owner_decl.link.coff.sym_index,
4005 },
4070 });4006 });
4071 _ = try self.addInst(.{4007 _ = try self.addInst(.{
4072 .tag = .call,4008 .tag = .call,
...@@ -4087,7 +4023,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions....@@ -4087,7 +4023,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.
4087 }4023 }
4088 const sym_index = try coff_file.getGlobalSymbol(mem.sliceTo(decl_name, 0));4024 const sym_index = try coff_file.getGlobalSymbol(mem.sliceTo(decl_name, 0));
4089 try self.genSetReg(Type.initTag(.usize), .rax, .{4025 try self.genSetReg(Type.initTag(.usize), .rax, .{
4090 .imports_load = sym_index,4026 .linker_load = .{
4027 .@"type" = .import,
4028 .sym_index = sym_index,
4029 },
4091 });4030 });
4092 _ = try self.addInst(.{4031 _ = try self.addInst(.{
4093 .tag = .call,4032 .tag = .call,
...@@ -4119,7 +4058,12 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions....@@ -4119,7 +4058,12 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.
4119 const func = func_payload.data;4058 const func = func_payload.data;
4120 const fn_owner_decl = mod.declPtr(func.owner_decl);4059 const fn_owner_decl = mod.declPtr(func.owner_decl);
4121 const sym_index = fn_owner_decl.link.macho.sym_index;4060 const sym_index = fn_owner_decl.link.macho.sym_index;
4122 try self.genSetReg(Type.initTag(.usize), .rax, .{ .got_load = sym_index });4061 try self.genSetReg(Type.initTag(.usize), .rax, .{
4062 .linker_load = .{
4063 .@"type" = .got,
4064 .sym_index = sym_index,
4065 },
4066 });
4123 // callq *%rax4067 // callq *%rax
4124 _ = try self.addInst(.{4068 _ = try self.addInst(.{
4125 .tag = .call,4069 .tag = .call,
...@@ -4505,11 +4449,7 @@ fn genVarDbgInfo(...@@ -4505,11 +4449,7 @@ fn genVarDbgInfo(
4505 leb128.writeILEB128(dbg_info.writer(), -off) catch unreachable;4449 leb128.writeILEB128(dbg_info.writer(), -off) catch unreachable;
4506 dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);4450 dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);
4507 },4451 },
4508 .memory,4452 .memory, .linker_load => {
4509 .got_load,
4510 .direct_load,
4511 .imports_load,
4512 => {
4513 const ptr_width = @intCast(u8, @divExact(self.target.cpu.arch.ptrBitWidth(), 8));4453 const ptr_width = @intCast(u8, @divExact(self.target.cpu.arch.ptrBitWidth(), 8));
4514 const is_ptr = switch (tag) {4454 const is_ptr = switch (tag) {
4515 .dbg_var_ptr => true,4455 .dbg_var_ptr => true,
...@@ -4540,10 +4480,11 @@ fn genVarDbgInfo(...@@ -4540,10 +4480,11 @@ fn genVarDbgInfo(
4540 try dbg_info.append(DW.OP.deref);4480 try dbg_info.append(DW.OP.deref);
4541 }4481 }
4542 switch (mcv) {4482 switch (mcv) {
4543 .got_load,4483 .linker_load => |load_struct| try dw.addExprlocReloc(
4544 .direct_load,4484 load_struct.sym_index,
4545 .imports_load,4485 offset,
4546 => |index| try dw.addExprlocReloc(index, offset, is_ptr),4486 is_ptr,
4487 ),
4547 else => {},4488 else => {},
4548 }4489 }
4549 },4490 },
...@@ -5587,11 +5528,7 @@ fn genSetStackArg(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerE...@@ -5587,11 +5528,7 @@ fn genSetStackArg(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerE
5587 else => return self.fail("TODO implement inputs on stack for {} with abi size > 8", .{mcv}),5528 else => return self.fail("TODO implement inputs on stack for {} with abi size > 8", .{mcv}),
5588 }5529 }
5589 },5530 },
5590 .memory,5531 .memory, .linker_load => {
5591 .direct_load,
5592 .got_load,
5593 .imports_load,
5594 => {
5595 if (abi_size <= 8) {5532 if (abi_size <= 8) {
5596 const reg = try self.copyToTmpRegister(ty, mcv);5533 const reg = try self.copyToTmpRegister(ty, mcv);
5597 return self.genSetStackArg(ty, stack_offset, MCValue{ .register = reg });5534 return self.genSetStackArg(ty, stack_offset, MCValue{ .register = reg });
...@@ -5835,11 +5772,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl...@@ -5835,11 +5772,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl
5835 },5772 },
5836 }5773 }
5837 },5774 },
5838 .memory,5775 .memory, .linker_load => {
5839 .got_load,
5840 .direct_load,
5841 .imports_load,
5842 => {
5843 if (abi_size <= 8) {5776 if (abi_size <= 8) {
5844 const reg = try self.copyToTmpRegister(ty, mcv);5777 const reg = try self.copyToTmpRegister(ty, mcv);
5845 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg }, opts);5778 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg }, opts);
...@@ -5959,11 +5892,7 @@ fn genInlineMemcpy(...@@ -5959,11 +5892,7 @@ fn genInlineMemcpy(
5959 const tmp_reg = regs[4].to8();5892 const tmp_reg = regs[4].to8();
59605893
5961 switch (dst_ptr) {5894 switch (dst_ptr) {
5962 .memory,5895 .memory, .linker_load => {
5963 .got_load,
5964 .direct_load,
5965 .imports_load,
5966 => {
5967 try self.loadMemPtrIntoRegister(dst_addr_reg, Type.usize, dst_ptr);5896 try self.loadMemPtrIntoRegister(dst_addr_reg, Type.usize, dst_ptr);
5968 },5897 },
5969 .ptr_stack_offset, .stack_offset => |off| {5898 .ptr_stack_offset, .stack_offset => |off| {
...@@ -5992,11 +5921,7 @@ fn genInlineMemcpy(...@@ -5992,11 +5921,7 @@ fn genInlineMemcpy(
5992 }5921 }
59935922
5994 switch (src_ptr) {5923 switch (src_ptr) {
5995 .memory,5924 .memory, .linker_load => {
5996 .got_load,
5997 .direct_load,
5998 .imports_load,
5999 => {
6000 try self.loadMemPtrIntoRegister(src_addr_reg, Type.usize, src_ptr);5925 try self.loadMemPtrIntoRegister(src_addr_reg, Type.usize, src_ptr);
6001 },5926 },
6002 .ptr_stack_offset, .stack_offset => |off| {5927 .ptr_stack_offset, .stack_offset => |off| {
...@@ -6120,11 +6045,7 @@ fn genInlineMemset(...@@ -6120,11 +6045,7 @@ fn genInlineMemset(
6120 const index_reg = regs[1].to64();6045 const index_reg = regs[1].to64();
61216046
6122 switch (dst_ptr) {6047 switch (dst_ptr) {
6123 .memory,6048 .memory, .linker_load => {
6124 .got_load,
6125 .direct_load,
6126 .imports_load,
6127 => {
6128 try self.loadMemPtrIntoRegister(addr_reg, Type.usize, dst_ptr);6049 try self.loadMemPtrIntoRegister(addr_reg, Type.usize, dst_ptr);
6129 },6050 },
6130 .ptr_stack_offset, .stack_offset => |off| {6051 .ptr_stack_offset, .stack_offset => |off| {
...@@ -6356,10 +6277,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -6356,10 +6277,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
6356 .data = undefined,6277 .data = undefined,
6357 });6278 });
6358 },6279 },
6359 .direct_load,6280 .linker_load => {
6360 .got_load,
6361 .imports_load,
6362 => {
6363 switch (ty.zigTypeTag()) {6281 switch (ty.zigTypeTag()) {
6364 .Float => {6282 .Float => {
6365 const base_reg = try self.register_manager.allocReg(null, gp);6283 const base_reg = try self.register_manager.allocReg(null, gp);
...@@ -6753,11 +6671,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {...@@ -6753,11 +6671,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
6753 // TODO Is this the only condition for pointer dereference for memcpy?6671 // TODO Is this the only condition for pointer dereference for memcpy?
6754 const src: MCValue = blk: {6672 const src: MCValue = blk: {
6755 switch (src_ptr) {6673 switch (src_ptr) {
6756 .got_load,6674 .linker_load, .memory => {
6757 .direct_load,
6758 .imports_load,
6759 .memory,
6760 => {
6761 const reg = try self.register_manager.allocReg(null, gp);6675 const reg = try self.register_manager.allocReg(null, gp);
6762 try self.loadMemPtrIntoRegister(reg, src_ty, src_ptr);6676 try self.loadMemPtrIntoRegister(reg, src_ty, src_ptr);
6763 _ = try self.addInst(.{6677 _ = try self.addInst(.{
...@@ -6997,10 +6911,16 @@ fn lowerDeclRef(self: *Self, tv: TypedValue, decl_index: Module.Decl.Index) Inne...@@ -6997,10 +6911,16 @@ fn lowerDeclRef(self: *Self, tv: TypedValue, decl_index: Module.Decl.Index) Inne
6997 return MCValue{ .memory = got_addr };6911 return MCValue{ .memory = got_addr };
6998 } else if (self.bin_file.cast(link.File.MachO)) |_| {6912 } else if (self.bin_file.cast(link.File.MachO)) |_| {
6999 assert(decl.link.macho.sym_index != 0);6913 assert(decl.link.macho.sym_index != 0);
7000 return MCValue{ .got_load = decl.link.macho.sym_index };6914 return MCValue{ .linker_load = .{
6915 .@"type" = .got,
6916 .sym_index = decl.link.macho.sym_index,
6917 } };
7001 } else if (self.bin_file.cast(link.File.Coff)) |_| {6918 } else if (self.bin_file.cast(link.File.Coff)) |_| {
7002 assert(decl.link.coff.sym_index != 0);6919 assert(decl.link.coff.sym_index != 0);
7003 return MCValue{ .got_load = decl.link.coff.sym_index };6920 return MCValue{ .linker_load = .{
6921 .@"type" = .got,
6922 .sym_index = decl.link.coff.sym_index,
6923 } };
7004 } else if (self.bin_file.cast(link.File.Plan9)) |p9| {6924 } else if (self.bin_file.cast(link.File.Plan9)) |p9| {
7005 try p9.seeDecl(decl_index);6925 try p9.seeDecl(decl_index);
7006 const got_addr = p9.bases.data + decl.link.plan9.got_index.? * ptr_bytes;6926 const got_addr = p9.bases.data + decl.link.plan9.got_index.? * ptr_bytes;
...@@ -7019,9 +6939,15 @@ fn lowerUnnamedConst(self: *Self, tv: TypedValue) InnerError!MCValue {...@@ -7019,9 +6939,15 @@ fn lowerUnnamedConst(self: *Self, tv: TypedValue) InnerError!MCValue {
7019 const vaddr = elf_file.local_symbols.items[local_sym_index].st_value;6939 const vaddr = elf_file.local_symbols.items[local_sym_index].st_value;
7020 return MCValue{ .memory = vaddr };6940 return MCValue{ .memory = vaddr };
7021 } else if (self.bin_file.cast(link.File.MachO)) |_| {6941 } else if (self.bin_file.cast(link.File.MachO)) |_| {
7022 return MCValue{ .direct_load = local_sym_index };6942 return MCValue{ .linker_load = .{
6943 .@"type" = .direct,
6944 .sym_index = local_sym_index,
6945 } };
7023 } else if (self.bin_file.cast(link.File.Coff)) |_| {6946 } else if (self.bin_file.cast(link.File.Coff)) |_| {
7024 return MCValue{ .direct_load = local_sym_index };6947 return MCValue{ .linker_load = .{
6948 .@"type" = .direct,
6949 .sym_index = local_sym_index,
6950 } };
7025 } else if (self.bin_file.cast(link.File.Plan9)) |_| {6951 } else if (self.bin_file.cast(link.File.Plan9)) |_| {
7026 return self.fail("TODO lower unnamed const in Plan9", .{});6952 return self.fail("TODO lower unnamed const in Plan9", .{});
7027 } else {6953 } else {
src/arch/x86_64/Emit.zig+1-1
...@@ -1021,7 +1021,7 @@ fn mirLeaPic(emit: *Emit, inst: Mir.Inst.Index) InnerError!void {...@@ -1021,7 +1021,7 @@ fn mirLeaPic(emit: *Emit, inst: Mir.Inst.Index) InnerError!void {
1021 .@"type" = switch (ops.flags) {1021 .@"type" = switch (ops.flags) {
1022 0b00 => .got,1022 0b00 => .got,
1023 0b01 => .direct,1023 0b01 => .direct,
1024 0b10 => .imports,1024 0b10 => .import,
1025 else => unreachable,1025 else => unreachable,
1026 },1026 },
1027 .target = switch (ops.flags) {1027 .target = switch (ops.flags) {
src/link/Coff.zig+2-2
...@@ -127,7 +127,7 @@ pub const Reloc = struct {...@@ -127,7 +127,7 @@ pub const Reloc = struct {
127 @"type": enum {127 @"type": enum {
128 got,128 got,
129 direct,129 direct,
130 imports,130 import,
131 },131 },
132 target: SymbolWithLoc,132 target: SymbolWithLoc,
133 offset: u32,133 offset: u32,
...@@ -141,7 +141,7 @@ pub const Reloc = struct {...@@ -141,7 +141,7 @@ pub const Reloc = struct {
141 switch (self.@"type") {141 switch (self.@"type") {
142 .got => return coff_file.getGotAtomForSymbol(self.target),142 .got => return coff_file.getGotAtomForSymbol(self.target),
143 .direct => return coff_file.getAtomForSymbol(self.target),143 .direct => return coff_file.getAtomForSymbol(self.target),
144 .imports => return coff_file.getImportAtomForSymbol(self.target),144 .import => return coff_file.getImportAtomForSymbol(self.target),
145 }145 }
146 }146 }
147};147};