authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-02-06 20:57:58-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-07 23:30:35-08:00
logba5e64ff6b3e759b83294e5cf940d940c832e13d
tree8c66a1c488f5c605c16db75739ed267b862527c2
parenta8af36ab10562e58ba237fa3dcc582228197402b

x86_64: fix backend assertion failures

Fixes the backend portion of #22798

3 files changed, 30 insertions(+), 20 deletions(-)

src/arch/x86_64/CodeGen.zig+21-11
......@@ -63262,17 +63262,27 @@ fn genSetReg(
6326263262 });
6326363263 },
6326463264 .lea_symbol => |sym_off| switch (self.bin_file.tag) {
63265 .elf, .macho => try self.asmRegisterMemory(
63266 .{ ._, .lea },
63267 dst_reg.to64(),
63268 .{
63269 .base = .{ .reloc = sym_off.sym_index },
63270 .mod = .{ .rm = .{
63271 .size = .qword,
63272 .disp = sym_off.off,
63273 } },
63274 },
63275 ),
63265 .elf, .macho => {
63266 try self.asmRegisterMemory(
63267 .{ ._, .lea },
63268 dst_reg.to64(),
63269 .{
63270 .base = .{ .reloc = sym_off.sym_index },
63271 .mod = .{ .rm = .{ .size = .qword } },
63272 },
63273 );
63274 if (sym_off.off != 0) try self.asmRegisterMemory(
63275 .{ ._, .lea },
63276 dst_reg.to64(),
63277 .{
63278 .base = .{ .reg = dst_reg.to64() },
63279 .mod = .{ .rm = .{
63280 .size = .qword,
63281 .disp = sym_off.off,
63282 } },
63283 },
63284 );
63285 },
6327663286 else => return self.fail("TODO emit symbol sequence on {s}", .{
6327763287 @tagName(self.bin_file.tag),
6327863288 }),
src/link/Dwarf.zig+5-5
......@@ -735,7 +735,7 @@ const Unit = struct {
735735 try dwarf.resolveReloc(
736736 unit_off + reloc.source_off,
737737 target_unit.off + (if (reloc.target_entry.unwrap()) |target_entry|
738 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sec, dwarf).off
738 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(target_unit, sec, dwarf).off
739739 else
740740 0) + reloc.target_off,
741741 dwarf.sectionOffsetBytes(),
......@@ -749,7 +749,7 @@ const Unit = struct {
749749 try dwarf.resolveReloc(
750750 unit_off + reloc.source_off,
751751 target_unit.off + (if (reloc.target_entry.unwrap()) |target_entry|
752 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sec, dwarf).off
752 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(target_unit, sec, dwarf).off
753753 else
754754 0) + reloc.target_off,
755755 dwarf.sectionOffsetBytes(),
......@@ -1000,7 +1000,7 @@ const Entry = struct {
10001000 try dwarf.resolveReloc(
10011001 entry_off + reloc.source_off,
10021002 target_unit.off + (if (reloc.target_entry.unwrap()) |target_entry|
1003 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sec, dwarf).off
1003 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(target_unit, sec, dwarf).off
10041004 else
10051005 0) + reloc.target_off,
10061006 dwarf.sectionOffsetBytes(),
......@@ -1014,7 +1014,7 @@ const Entry = struct {
10141014 try dwarf.resolveReloc(
10151015 entry_off + reloc.source_off,
10161016 target_unit.off + (if (reloc.target_entry.unwrap()) |target_entry|
1017 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sec, dwarf).off
1017 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(target_unit, sec, dwarf).off
10181018 else
10191019 0) + reloc.target_off,
10201020 dwarf.sectionOffsetBytes(),
......@@ -1850,7 +1850,7 @@ pub const WipNav = struct {
18501850 const ty = value.typeOf(zcu);
18511851 if (std.debug.runtime_safety) assert(ty.comptimeOnly(zcu) and try ty.onePossibleValue(wip_nav.pt) == null);
18521852 if (ty.toIntern() == .type_type) return wip_nav.getTypeEntry(value.toType());
1853 if (ip.isFunctionType(ty.toIntern())) return wip_nav.getNavEntry(zcu.funcInfo(value.toIntern()).owner_nav);
1853 if (ip.isFunctionType(ty.toIntern()) and !value.isUndef(zcu)) return wip_nav.getNavEntry(zcu.funcInfo(value.toIntern()).owner_nav);
18541854 const gop = try wip_nav.dwarf.values.getOrPut(wip_nav.dwarf.gpa, value.toIntern());
18551855 const unit: Unit.Index = .main;
18561856 if (gop.found_existing) return .{ unit, gop.value_ptr.* };
src/link/Elf/ZigObject.zig+4-4
......@@ -360,7 +360,7 @@ pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
360360 const target_unit = sect.getUnit(reloc.target_unit);
361361 const r_offset = unit.off + reloc.source_off;
362362 const r_addend: i64 = @intCast(target_unit.off + reloc.target_off + (if (reloc.target_entry.unwrap()) |target_entry|
363 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sect, dwarf).off
363 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(target_unit, sect, dwarf).off
364364 else
365365 0));
366366 const r_type = relocation.dwarf.crossSectionRelocType(dwarf.format, cpu_arch);
......@@ -388,7 +388,7 @@ pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
388388 const target_unit = target_sec.getUnit(reloc.target_unit);
389389 const r_offset = unit.off + reloc.source_off;
390390 const r_addend: i64 = @intCast(target_unit.off + reloc.target_off + (if (reloc.target_entry.unwrap()) |target_entry|
391 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sect, dwarf).off
391 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(target_unit, sect, dwarf).off
392392 else
393393 0));
394394 const r_type = relocation.dwarf.crossSectionRelocType(dwarf.format, cpu_arch);
......@@ -422,7 +422,7 @@ pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
422422 const target_unit = sect.getUnit(reloc.target_unit);
423423 const r_offset = entry_off + reloc.source_off;
424424 const r_addend: i64 = @intCast(target_unit.off + reloc.target_off + (if (reloc.target_entry.unwrap()) |target_entry|
425 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sect, dwarf).off
425 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(target_unit, sect, dwarf).off
426426 else
427427 0));
428428 const r_type = relocation.dwarf.crossSectionRelocType(dwarf.format, cpu_arch);
......@@ -450,7 +450,7 @@ pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
450450 const target_unit = target_sec.getUnit(reloc.target_unit);
451451 const r_offset = entry_off + reloc.source_off;
452452 const r_addend: i64 = @intCast(target_unit.off + reloc.target_off + (if (reloc.target_entry.unwrap()) |target_entry|
453 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sect, dwarf).off
453 target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(target_unit, sect, dwarf).off
454454 else
455455 0));
456456 const r_type = relocation.dwarf.crossSectionRelocType(dwarf.format, cpu_arch);