Commit 16abf51cee

Jakub Konka <kubkon@jakubkonka.com>
2024-08-12 22:04:18
x86_64: handle lea_symbol returned by genNavRef
1 parent f968dd0
Changed files (2)
src
src/arch/x86_64/CodeGen.zig
@@ -14104,7 +14104,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
                         .{ .reg = try self.copyToTmpRegister(Type.usize, .{ .lea_got = sym_index }) }
                     else
                         return self.fail("invalid modifier: '{s}'", .{modifier}),
-                    .load_symbol => |sym_off| if (mem.eql(u8, modifier, "P"))
+                    .lea_symbol => |sym_off| if (mem.eql(u8, modifier, "P"))
                         .{ .reg = try self.copyToTmpRegister(Type.usize, .{ .lea_symbol = sym_off }) }
                     else
                         return self.fail("invalid modifier: '{s}'", .{modifier}),
@@ -18798,6 +18798,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
             .immediate => |imm| .{ .immediate = imm },
             .memory => |addr| .{ .memory = addr },
             .load_symbol => |sym_index| .{ .load_symbol = .{ .sym = sym_index } },
+            .lea_symbol => |sym_index| .{ .lea_symbol = .{ .sym = sym_index } },
             .load_direct => |sym_index| .{ .load_direct = sym_index },
             .load_got => |sym_index| .{ .lea_got = sym_index },
             .load_tlv => |sym_index| .{ .lea_tlv = sym_index },
src/codegen.zig
@@ -828,6 +828,9 @@ pub const GenResult = union(enum) {
         /// Reference to memory location but deferred until linker allocated the Decl in memory.
         /// Traditionally, this corresponds to emitting a relocation in a relocatable object file.
         load_symbol: u32,
+        /// Reference to memory location but deferred until linker allocated the Decl in memory.
+        /// Traditionally, this corresponds to emitting a relocation in a relocatable object file.
+        lea_symbol: u32,
     };
 
     fn mcv(val: MCValue) GenResult {
@@ -904,7 +907,7 @@ fn genNavRef(
         if (!single_threaded and is_threadlocal) {
             return GenResult.mcv(.{ .load_tlv = sym_index });
         }
-        return GenResult.mcv(.{ .load_symbol = sym_index });
+        return GenResult.mcv(.{ .lea_symbol = sym_index });
     } else if (lf.cast(.macho)) |macho_file| {
         const zo = macho_file.getZigObject().?;
         if (is_extern) {