authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-12 10:26:39+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-12 10:26:39+02:00
log993c75845605c7001c8b9e4526bc5344458570cb
tree268652130cba11de3c365129da98332954c8d842
parent26450ba0f6c48a445beca483141605b9a2407d20
parentd4984092a332e6b1564b7f43e5037da0a5b7e42f

Merge pull request 'Elf2: more SPARC relocations' (#37191) from alexrp/zig:elf2-sparc into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/37191

3 files changed, 183 insertions(+), 35 deletions(-)

lib/std/debug/cpu_context.zig+46-8
...@@ -42,7 +42,7 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {...@@ -42,7 +42,7 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
42 // Deal with some special cases first.42 // Deal with some special cases first.
43 if (native_arch.isArc() and native_os == .linux) {43 if (native_arch.isArc() and native_os == .linux) {
44 var native: Native = .{44 var native: Native = .{
45 .r = [_]u32{ uc.mcontext.r31, uc.mcontext.r30, 0, uc.mcontext.r28 } ++45 .r = [_]Arc.Gpr{ uc.mcontext.r31, uc.mcontext.r30, 0, uc.mcontext.r28 } ++
46 uc.mcontext.r27_26 ++46 uc.mcontext.r27_26 ++
47 uc.mcontext.r25_13 ++47 uc.mcontext.r25_13 ++
48 uc.mcontext.r12_0,48 uc.mcontext.r12_0,
...@@ -100,15 +100,29 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {...@@ -100,15 +100,29 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
100 .i = frame.i,100 .i = frame.i,
101 .pc = uc.mcontext.pc,101 .pc = uc.mcontext.pc,
102 };102 };
103 } else if (native_arch.isSparc() and native_os == .netbsd) {
104 // The kernel flushes all user windows before delivering a signal.
105 const save: *const [16]usize = @ptrFromInt(uc.mcontext.o[6] +% if (native_arch == .sparc64) 2047 else 0);
106
107 return .{
108 .g = [_]Sparc.Gpr{0} ++ uc.mcontext.g1_7,
109 .o = uc.mcontext.o,
110 .l = save[0..8].*,
111 .i = save[8..16].*,
112 .pc = uc.mcontext.pc,
113 };
114 } else if (native_arch == .sparc64 and native_os == .openbsd) {
115 // https://codeberg.org/ziglang/zig/issues/30958
116 return null;
103 }117 }
104118
105 // Only unified conversions from here.119 // Only unified conversions from here.
106 return switch (native_arch) {120 return switch (native_arch) {
107 .arm, .armeb, .thumb, .thumbeb => .{121 .arm, .armeb, .thumb, .thumbeb => .{
108 .r = uc.mcontext.r ++ [_]u32{uc.mcontext.pc},122 .r = uc.mcontext.r ++ [_]Arm.Gpr{uc.mcontext.pc},
109 },123 },
110 .aarch64, .aarch64_be => .{124 .aarch64, .aarch64_be => .{
111 .x = uc.mcontext.x ++ [_]u64{uc.mcontext.lr},125 .x = uc.mcontext.x ++ [_]Aarch64.Gpr{uc.mcontext.lr},
112 .sp = uc.mcontext.sp,126 .sp = uc.mcontext.sp,
113 .pc = uc.mcontext.pc,127 .pc = uc.mcontext.pc,
114 },128 },
...@@ -118,9 +132,9 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {...@@ -118,9 +132,9 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
118 },132 },
119 .csky => .{133 .csky => .{
120 .r = uc.mcontext.r0_13 ++134 .r = uc.mcontext.r0_13 ++
121 [_]u32{ uc.mcontext.r14, uc.mcontext.r15 } ++135 [_]Csky.Gpr{ uc.mcontext.r14, uc.mcontext.r15 } ++
122 uc.mcontext.r16_30 ++136 uc.mcontext.r16_30 ++
123 [_]u32{uc.mcontext.r31},137 [_]Csky.Gpr{uc.mcontext.r31},
124 .pc = uc.mcontext.pc,138 .pc = uc.mcontext.pc,
125 },139 },
126 .hexagon, .loongarch32, .loongarch64, .mips, .mipsel, .mips64, .mips64el, .or1k => .{140 .hexagon, .loongarch32, .loongarch64, .mips, .mipsel, .mips64, .mips64el, .or1k => .{
...@@ -2557,7 +2571,17 @@ const signal_ucontext_t = switch (native_os) {...@@ -2557,7 +2571,17 @@ const signal_ucontext_t = switch (native_os) {
2557 },2571 },
2558 },2572 },
2559 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/sparc64/include/signal.h2573 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/sparc64/include/signal.h
2560 .sparc64 => @compileError("sparc64-openbsd ucontext_t missing"),2574 .sparc64 => extern struct {
2575 _cookie: i64,
2576 mcontext: extern struct {
2577 sp: u64,
2578 pc: u64,
2579 _npc: i64,
2580 _tstate: i64,
2581 g1: u64,
2582 o0: u64,
2583 },
2584 },
2561 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/sh/include/signal.h2585 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/sh/include/signal.h
2562 .sh => extern struct {2586 .sh => extern struct {
2563 pc: u32,2587 pc: u32,
...@@ -2694,8 +2718,22 @@ const signal_ucontext_t = switch (native_os) {...@@ -2694,8 +2718,22 @@ const signal_ucontext_t = switch (native_os) {
2694 pc: usize,2718 pc: usize,
2695 },2719 },
2696 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/sparc/include/mcontext.h2720 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/sparc/include/mcontext.h
2697 .sparc => @compileError("sparc-netbsd mcontext_t missing"),2721 .sparc => extern struct {
2698 .sparc64 => @compileError("sparc64-netbsd mcontext_t missing"),2722 _psr: i32 align(8),
2723 pc: u32,
2724 _npc: i32,
2725 _y: i32,
2726 g1_7: [7]u32,
2727 o: [8]u32,
2728 },
2729 .sparc64 => extern struct {
2730 _ccr: i64 align(16),
2731 pc: u64,
2732 _npc: i64,
2733 _y: i64,
2734 g1_7: [7]u64,
2735 o: [8]u64,
2736 },
2699 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/sh3/include/mcontext.h2737 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/sh3/include/mcontext.h
2700 .sh, .sheb => extern struct {2738 .sh, .sheb => extern struct {
2701 _gbr: i32,2739 _gbr: i32,
src/link/Elf2.zig+128-27
...@@ -1356,6 +1356,7 @@ const SymbolReloc = struct {...@@ -1356,6 +1356,7 @@ const SymbolReloc = struct {
1356 @"32[10:0]",1356 @"32[10:0]",
1357 @"32[11:0]",1357 @"32[11:0]",
1358 @"32[12:0]",1358 @"32[12:0]",
1359 @"32[18:0]",
1359 @"32[21:0]",1360 @"32[21:0]",
1360 @"32[21:10]",1361 @"32[21:10]",
1361 @"32[24:5]",1362 @"32[24:5]",
...@@ -1399,6 +1400,7 @@ const SymbolReloc = struct {...@@ -1399,6 +1400,7 @@ const SymbolReloc = struct {
1399 @"12",1400 @"12",
1400 @"22",1401 @"22",
1401 @"32",1402 @"32",
1403 @"42",
1402 @"52",1404 @"52",
1403 },1405 },
14041406
...@@ -1418,6 +1420,7 @@ const SymbolReloc = struct {...@@ -1418,6 +1420,7 @@ const SymbolReloc = struct {
1418 .@"12" => .{ 12, false },1420 .@"12" => .{ 12, false },
1419 .@"22" => .{ 22, false },1421 .@"22" => .{ 22, false },
1420 .@"32" => .{ 32, false },1422 .@"32" => .{ 32, false },
1423 .@"42" => .{ 42, false },
1421 .@"52" => .{ 52, false },1424 .@"52" => .{ 52, false },
1422 };1425 };
14231426
...@@ -1438,6 +1441,7 @@ const SymbolReloc = struct {...@@ -1438,6 +1441,7 @@ const SymbolReloc = struct {
1438 .@"32[10:0]" => .{ 32, 10, 0 },1441 .@"32[10:0]" => .{ 32, 10, 0 },
1439 .@"32[11:0]" => .{ 32, 11, 0 },1442 .@"32[11:0]" => .{ 32, 11, 0 },
1440 .@"32[12:0]" => .{ 32, 12, 0 },1443 .@"32[12:0]" => .{ 32, 12, 0 },
1444 .@"32[18:0]" => .{ 32, 18, 0 },
1441 .@"32[21:0]" => .{ 32, 21, 0 },1445 .@"32[21:0]" => .{ 32, 21, 0 },
1442 .@"32[21:10]" => .{ 32, 21, 10 },1446 .@"32[21:10]" => .{ 32, 21, 10 },
1443 .@"32[24:5]" => .{ 32, 24, 5 },1447 .@"32[24:5]" => .{ 32, 24, 5 },
...@@ -1500,7 +1504,10 @@ const SymbolReloc = struct {...@@ -1500,7 +1504,10 @@ const SymbolReloc = struct {
1500 larch_b26,1504 larch_b26,
1501 larch_call36,1505 larch_call36,
15021506
1507 sparc_hix22,
1503 sparc_le_hix22,1508 sparc_le_hix22,
1509 sparc_wdisp10,
1510 sparc_wdisp16,
15041511
1505 fn applyInner(1512 fn applyInner(
1506 s: Special,1513 s: Special,
...@@ -1598,6 +1605,17 @@ const SymbolReloc = struct {...@@ -1598,6 +1605,17 @@ const SymbolReloc = struct {
1598 else => unreachable,1605 else => unreachable,
1599 }1606 }
1600 },1607 },
1608
1609 .sparc_hix22 => {
1610 const dest_ptr: *align(1) packed struct(u32) {
1611 imm22: u22,
1612 b22_31: u10,
1613 } = @ptrCast(dest_slice);
1614 elf.targetStore(dest_ptr, .{
1615 .imm22 = @truncate(~(target.value(elf) +% addend) >> 10),
1616 .b22_31 = elf.targetLoad(dest_ptr).b22_31,
1617 });
1618 },
1601 .sparc_le_hix22 => {1619 .sparc_le_hix22 => {
1602 const tls_phndx = elf.getNode(elf.ni.tls.unwrap().?).segment;1620 const tls_phndx = elf.getNode(elf.ni.tls.unwrap().?).segment;
1603 const tls_size: u64 = switch (elf.phdrSlice()) {1621 const tls_size: u64 = switch (elf.phdrSlice()) {
...@@ -1615,6 +1633,57 @@ const SymbolReloc = struct {...@@ -1615,6 +1633,57 @@ const SymbolReloc = struct {
1615 .b22_31 = elf.targetLoad(dest_ptr).b22_31,1633 .b22_31 = elf.targetLoad(dest_ptr).b22_31,
1616 });1634 });
1617 },1635 },
1636 .sparc_wdisp16, .sparc_wdisp10 => {
1637 const target_vaddr: u64 = elf.pltEntryTargetAddr(target) orelse target.value(elf);
1638 const jump_offset: i64 = @bitCast(target_vaddr +% addend -% dest_vaddr);
1639 if ((jump_offset >> 2) << 2 != jump_offset) {
1640 return error.RelocationMisaligned;
1641 }
1642 const shifted_jump_offset: i64 = @shrExact(jump_offset, 2);
1643 switch (s) {
1644 .sparc_wdisp10 => {
1645 if ((shifted_jump_offset << (64 - 10)) >> (64 - 10) != shifted_jump_offset) {
1646 return error.RelocationOverflow;
1647 }
1648 const truncated: i10 = @intCast(shifted_jump_offset);
1649 const parts: packed struct { lo8: u8, hi2: u2 } = @bitCast(truncated);
1650 const inst: *align(1) packed struct(u32) {
1651 b0_4: u5,
1652 disp10: u8,
1653 b13_18: u6,
1654 d2: u2,
1655 b21_31: u11,
1656 } = @ptrCast(dest_slice[0..4]);
1657 elf.targetStore(inst, .{
1658 .b0_4 = elf.targetLoad(inst).b0_4,
1659 .disp10 = parts.lo8,
1660 .b13_18 = elf.targetLoad(inst).b13_18,
1661 .d2 = parts.hi2,
1662 .b21_31 = elf.targetLoad(inst).b21_31,
1663 });
1664 },
1665 .sparc_wdisp16 => {
1666 if ((shifted_jump_offset << (64 - 16)) >> (64 - 16) != shifted_jump_offset) {
1667 return error.RelocationOverflow;
1668 }
1669 const truncated: i16 = @intCast(shifted_jump_offset);
1670 const parts: packed struct { lo14: u14, hi2: u2 } = @bitCast(truncated);
1671 const inst: *align(1) packed struct(u32) {
1672 disp14: u14,
1673 b14_19: u6,
1674 d2: u2,
1675 b22_31: u10,
1676 } = @ptrCast(dest_slice[0..4]);
1677 elf.targetStore(inst, .{
1678 .disp14 = parts.lo14,
1679 .b14_19 = elf.targetLoad(inst).b14_19,
1680 .d2 = parts.hi2,
1681 .b22_31 = elf.targetLoad(inst).b22_31,
1682 });
1683 },
1684 else => unreachable,
1685 }
1686 },
1618 }1687 }
1619 }1688 }
1620 };1689 };
...@@ -1649,6 +1718,10 @@ const SymbolReloc = struct {...@@ -1649,6 +1718,10 @@ const SymbolReloc = struct {
1649 .larch_b21,1718 .larch_b21,
1650 .larch_b26,1719 .larch_b26,
1651 .larch_call36,1720 .larch_call36,
1721
1722 .sparc_hix22,
1723 .sparc_wdisp10,
1724 .sparc_wdisp16,
1652 => false,1725 => false,
1653 },1726 },
1654 },1727 },
...@@ -9000,38 +9073,31 @@ fn addRelocAssumeCapacity(...@@ -9000,38 +9073,31 @@ fn addRelocAssumeCapacity(
9000 .JMP_SLOT,9073 .JMP_SLOT,
9001 .RELATIVE,9074 .RELATIVE,
9002 .IRELATIVE,9075 .IRELATIVE,
9076 .TLS_DTPMOD32,
9077 .TLS_DTPMOD64,
9078 .TLS_TPOFF32,
9079 .TLS_TPOFF64,
9003 => return error.NonStaticRelocation,9080 => return error.NonStaticRelocation,
90049081
9005 .WDISP22,9082 // Nobody seems to support these.
9006 .HI22,
9007 .LO10,
9008 .HIPLT22,9083 .HIPLT22,
9009 .LOPLT10,9084 .LOPLT10,
9010 .PCPLT22,9085 .PCPLT22,
9011 .PCPLT10,9086 .PCPLT10,
9012 .OLO10,
9013 .HH22,
9014 .HM10,
9015 .LM22,
9016 .PC_HH22,
9017 .PC_HM10,
9018 .PC_LM22,
9019 .WDISP16,
9020 .WDISP19,
9021 .HIX22,
9022 .LOX10,
9023 .REGISTER,
9024 .TLS_IE_HI22,
9025 .TLS_IE_LO10,
9026 .TLS_DTPMOD32,
9027 .TLS_DTPMOD64,
9028 .H34,
9029 .WDISP10,
9030 => return error.UnimplementedRelocation,9087 => return error.UnimplementedRelocation,
90319088
9089 // Needs to use the second addend in `ELF64_R_TYPE_DATA(reloc.r_info)` which we currently can't model.
9090 .OLO10 => return error.UnimplementedRelocation,
9091
9092 // Does not patch any bytes. Together with `STT_SPARC_REGISTER`, this is used to indicate that an object
9093 // file owns a global register and what value it should be initialized to. I don't think this sees any
9094 // real-world use.
9095 .REGISTER => return error.UnimplementedRelocation,
9096
9032 // These need similar handling to `R_X86_64_GOTOFF64`. No compiler seems to emit them though.9097 // These need similar handling to `R_X86_64_GOTOFF64`. No compiler seems to emit them though.
9033 .GOTDATA_HIX22 => return error.UnimplementedRelocation,9098 .GOTDATA_HIX22,
9034 .GOTDATA_LOX10 => return error.UnimplementedRelocation,9099 .GOTDATA_LOX10,
9100 => return error.UnimplementedRelocation,
90359101
9036 // These relocations signal that certain relaxations are legal, but this linker does9102 // These relocations signal that certain relaxations are legal, but this linker does
9037 // not yet implement relaxation, so these are ignored.9103 // not yet implement relaxation, so these are ignored.
...@@ -9063,15 +9129,26 @@ fn addRelocAssumeCapacity(...@@ -9063,15 +9129,26 @@ fn addRelocAssumeCapacity(
9063 .DISP32 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.rel, .{ .dest = .@"32", .cast = .signed, .shift = .@"0" })),9129 .DISP32 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.rel, .{ .dest = .@"32", .cast = .signed, .shift = .@"0" })),
9064 .DISP64 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.rel, .{ .dest = .@"64", .cast = .signed, .shift = .@"0" })),9130 .DISP64 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.rel, .{ .dest = .@"64", .cast = .signed, .shift = .@"0" })),
90659131
9066 .SIZE32 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.size, .{ .dest = .@"32", .cast = .unsigned, .shift = .@"0" })),9132 .SIZE32 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.size, .{ .dest = .@"32", .cast = .unsigned, .shift = .@"0" })),
9067 .SIZE64 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.size, .{ .dest = .@"64", .cast = .unsigned, .shift = .@"0" })),9133 .SIZE64 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.size, .{ .dest = .@"64", .cast = .unsigned, .shift = .@"0" })),
90689134
9069 .PCPLT32 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.pltrel, .{ .dest = .@"32", .cast = .signed, .shift = .@"0" })),9135 .PCPLT32 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.pltrel, .{ .dest = .@"32", .cast = .signed, .shift = .@"0" })),
9070 .PLT32 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.pltabs, .{ .dest = .@"32", .cast = .unsigned, .shift = .@"0" })),9136 .PLT32 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.pltabs, .{ .dest = .@"32", .cast = .unsigned, .shift = .@"0" })),
9071 .PLT64 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.pltabs, .{ .dest = .@"64", .cast = .unsigned, .shift = .@"0" })),9137 .PLT64 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.pltabs, .{ .dest = .@"64", .cast = .unsigned, .shift = .@"0" })),
90729138
9139 .WDISP10 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .special(.sparc_wdisp10)),
9140 .WDISP16 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .special(.sparc_wdisp16)),
9141 .WDISP19 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.pltrel, .{ .dest = .@"32[18:0]", .cast = .signed, .shift = .@"2_exact" })),
9142 .WDISP22 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.pltrel, .{ .dest = .@"32[21:0]", .cast = .signed, .shift = .@"2_exact" })),
9073 .WDISP30, .WPLT30 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.pltrel, .{ .dest = .@"32[29:0]", .cast = .signed, .shift = .@"2_exact" })),9143 .WDISP30, .WPLT30 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.pltrel, .{ .dest = .@"32[29:0]", .cast = .signed, .shift = .@"2_exact" })),
9074 .PC22 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.rel, .{ .dest = .@"32[21:0]", .cast = .unsigned, .shift = .@"10" })),9144 .PC22 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.rel, .{ .dest = .@"32[21:0]", .cast = .unsigned, .shift = .@"10" })),
9145 .PC_LM22 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.rel, .{ .dest = .@"32[21:0]", .cast = .trunc, .shift = .@"10" })),
9146 .PC_HH22 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.rel, .{ .dest = .@"32[21:0]", .cast = .unsigned, .shift = .@"42" })),
9147 .HI22 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[21:0]", .cast = .unsigned, .shift = .@"10" })),
9148 .LM22 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[21:0]", .cast = .trunc, .shift = .@"10" })),
9149 .HH22 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[21:0]", .cast = .unsigned, .shift = .@"42" })),
9150 .HIX22 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .special(.sparc_hix22)),
9151 .H34 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[21:0]", .cast = .unsigned, .shift = .@"12" })),
9075 .H44 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[21:0]", .cast = .unsigned, .shift = .@"22" })),9152 .H44 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[21:0]", .cast = .unsigned, .shift = .@"22" })),
9076 .M44 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[9:0]", .cast = .trunc, .shift = .@"12" })),9153 .M44 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[9:0]", .cast = .trunc, .shift = .@"12" })),
90779154
...@@ -9079,8 +9156,6 @@ fn addRelocAssumeCapacity(...@@ -9079,8 +9156,6 @@ fn addRelocAssumeCapacity(
9079 .TLS_LE_HIX22 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .special(.sparc_le_hix22)),9156 .TLS_LE_HIX22 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .special(.sparc_le_hix22)),
9080 .TLS_DTPOFF32 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.dtpoff, .{ .dest = .@"32", .cast = .unsigned, .shift = .@"0" })),9157 .TLS_DTPOFF32 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.dtpoff, .{ .dest = .@"32", .cast = .unsigned, .shift = .@"0" })),
9081 .TLS_DTPOFF64 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.dtpoff, .{ .dest = .@"64", .cast = .unsigned, .shift = .@"0" })),9158 .TLS_DTPOFF64 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.dtpoff, .{ .dest = .@"64", .cast = .unsigned, .shift = .@"0" })),
9082 .TLS_TPOFF32 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.tpoff, .{ .dest = .@"32", .cast = .signed, .shift = .@"0" })),
9083 .TLS_TPOFF64 => try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.tpoff, .{ .dest = .@"64", .cast = .signed, .shift = .@"0" })),
90849159
9085 .GOT13 => elf.addGotRelocAssumeCapacity(node, offset, .{ .symbol = target }, addend, .simple(.offset, .{ .dest = .@"32[12:0]", .cast = .unsigned, .shift = .@"0" })),9160 .GOT13 => elf.addGotRelocAssumeCapacity(node, offset, .{ .symbol = target }, addend, .simple(.offset, .{ .dest = .@"32[12:0]", .cast = .unsigned, .shift = .@"0" })),
9086 .GOT22 => elf.addGotRelocAssumeCapacity(node, offset, .{ .symbol = target }, addend, .simple(.offset, .{ .dest = .@"32[21:0]", .cast = .trunc, .shift = .@"10" })),9161 .GOT22 => elf.addGotRelocAssumeCapacity(node, offset, .{ .symbol = target }, addend, .simple(.offset, .{ .dest = .@"32[21:0]", .cast = .trunc, .shift = .@"10" })),
...@@ -9088,6 +9163,7 @@ fn addRelocAssumeCapacity(...@@ -9088,6 +9163,7 @@ fn addRelocAssumeCapacity(
9088 .GOTDATA_OP_HIX22 => elf.addGotRelocAssumeCapacity(node, offset, .{ .symbol = target }, addend, .special(.sparc_op_hix22)),9163 .GOTDATA_OP_HIX22 => elf.addGotRelocAssumeCapacity(node, offset, .{ .symbol = target }, addend, .special(.sparc_op_hix22)),
9089 .TLS_GD_HI22 => elf.addGotRelocAssumeCapacity(node, offset, .{ .tlsgd0 = target }, addend, .simple(.offset, .{ .dest = .@"32[21:0]", .cast = .trunc, .shift = .@"10" })),9164 .TLS_GD_HI22 => elf.addGotRelocAssumeCapacity(node, offset, .{ .tlsgd0 = target }, addend, .simple(.offset, .{ .dest = .@"32[21:0]", .cast = .trunc, .shift = .@"10" })),
9090 .TLS_LDM_HI22 => elf.addGotRelocAssumeCapacity(node, offset, .tlsld0, addend, .simple(.offset, .{ .dest = .@"32[21:0]", .cast = .trunc, .shift = .@"10" })),9165 .TLS_LDM_HI22 => elf.addGotRelocAssumeCapacity(node, offset, .tlsld0, addend, .simple(.offset, .{ .dest = .@"32[21:0]", .cast = .trunc, .shift = .@"10" })),
9166 .TLS_IE_HI22 => elf.addGotRelocAssumeCapacity(node, offset, .{ .tpoff = target }, addend, .simple(.offset, .{ .dest = .@"32[21:0]", .cast = .trunc, .shift = .@"10" })),
9091 // zig fmt: on9167 // zig fmt: on
90929168
9093 .TLS_GD_CALL, .TLS_LDM_CALL => {9169 .TLS_GD_CALL, .TLS_LDM_CALL => {
...@@ -9109,6 +9185,22 @@ fn addRelocAssumeCapacity(...@@ -9109,6 +9185,22 @@ fn addRelocAssumeCapacity(
9109 try elf.one_shot_fixups.append(elf.base.comp.gpa, .{ .node = node, .offset = offset, .action = .@"32[12:10] = 0b000" });9185 try elf.one_shot_fixups.append(elf.base.comp.gpa, .{ .node = node, .offset = offset, .action = .@"32[12:10] = 0b000" });
9110 try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.rel, .{ .dest = .@"32[9:0]", .cast = .trunc, .shift = .@"0" }));9186 try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.rel, .{ .dest = .@"32[9:0]", .cast = .trunc, .shift = .@"0" }));
9111 },9187 },
9188 .PC_HM10 => {
9189 try elf.one_shot_fixups.append(elf.base.comp.gpa, .{ .node = node, .offset = offset, .action = .@"32[12:10] = 0b000" });
9190 try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.rel, .{ .dest = .@"32[9:0]", .cast = .trunc, .shift = .@"32" }));
9191 },
9192 .LO10 => {
9193 try elf.one_shot_fixups.append(elf.base.comp.gpa, .{ .node = node, .offset = offset, .action = .@"32[12:10] = 0b000" });
9194 try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[9:0]", .cast = .trunc, .shift = .@"0" }));
9195 },
9196 .HM10 => {
9197 try elf.one_shot_fixups.append(elf.base.comp.gpa, .{ .node = node, .offset = offset, .action = .@"32[12:10] = 0b000" });
9198 try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[9:0]", .cast = .trunc, .shift = .@"32" }));
9199 },
9200 .LOX10 => {
9201 try elf.one_shot_fixups.append(elf.base.comp.gpa, .{ .node = node, .offset = offset, .action = .@"32[12:10] = 0b111" });
9202 try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[9:0]", .cast = .trunc, .shift = .@"0" }));
9203 },
9112 .L44 => {9204 .L44 => {
9113 try elf.one_shot_fixups.append(elf.base.comp.gpa, .{ .node = node, .offset = offset, .action = .@"32[12:12] = 0b0" });9205 try elf.one_shot_fixups.append(elf.base.comp.gpa, .{ .node = node, .offset = offset, .action = .@"32[12:12] = 0b0" });
9114 try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[11:0]", .cast = .trunc, .shift = .@"0" }));9206 try elf.addSymbolRelocAssumeCapacity(node, offset, target, addend, .simple(.abs, .{ .dest = .@"32[11:0]", .cast = .trunc, .shift = .@"0" }));
...@@ -9133,6 +9225,10 @@ fn addRelocAssumeCapacity(...@@ -9133,6 +9225,10 @@ fn addRelocAssumeCapacity(
9133 try elf.one_shot_fixups.append(elf.base.comp.gpa, .{ .node = node, .offset = offset, .action = .@"32[12:10] = 0b000" });9225 try elf.one_shot_fixups.append(elf.base.comp.gpa, .{ .node = node, .offset = offset, .action = .@"32[12:10] = 0b000" });
9134 elf.addGotRelocAssumeCapacity(node, offset, .tlsld0, addend, .simple(.offset, .{ .dest = .@"32[9:0]", .cast = .trunc, .shift = .@"0" }));9226 elf.addGotRelocAssumeCapacity(node, offset, .tlsld0, addend, .simple(.offset, .{ .dest = .@"32[9:0]", .cast = .trunc, .shift = .@"0" }));
9135 },9227 },
9228 .TLS_IE_LO10 => {
9229 try elf.one_shot_fixups.append(elf.base.comp.gpa, .{ .node = node, .offset = offset, .action = .@"32[12:10] = 0b000" });
9230 elf.addGotRelocAssumeCapacity(node, offset, .{ .tpoff = target }, addend, .simple(.offset, .{ .dest = .@"32[9:0]", .cast = .trunc, .shift = .@"0" }));
9231 },
9136 },9232 },
9137 .X86_64 => rel_type: switch (@"type".X86_64) {9233 .X86_64 => rel_type: switch (@"type".X86_64) {
9138 .NONE => {},9234 .NONE => {},
...@@ -9256,12 +9352,17 @@ fn addSymbolRelocAssumeCapacity(...@@ -9256,12 +9352,17 @@ fn addSymbolRelocAssumeCapacity(
9256 .larch_pcala_hi20,9352 .larch_pcala_hi20,
9257 .larch_pcala64_lo20,9353 .larch_pcala64_lo20,
9258 .larch_pcala64_hi12,9354 .larch_pcala64_hi12,
9355
9356 .sparc_hix22,
9259 => true,9357 => true,
92609358
9261 .larch_b21,9359 .larch_b21,
9262 .larch_b26,9360 .larch_b26,
9263 .larch_call36,9361 .larch_call36,
9362
9264 .sparc_le_hix22,9363 .sparc_le_hix22,
9364 .sparc_wdisp10,
9365 .sparc_wdisp16,
9265 => false,9366 => false,
9266 },9367 },
9267 };9368 };
test/tests.zig+9
...@@ -1566,6 +1566,15 @@ const module_test_targets = blk: {...@@ -1566,6 +1566,15 @@ const module_test_targets = blk: {
1566 .link_libc = true,1566 .link_libc = true,
1567 },1567 },
15681568
1569 .{
1570 .target = .{
1571 .cpu_arch = .sparc64,
1572 .os_tag = .openbsd,
1573 .abi = .none,
1574 },
1575 .link_libc = true,
1576 },
1577
1569 .{1578 .{
1570 .target = .{1579 .target = .{
1571 .cpu_arch = .x86,1580 .cpu_arch = .x86,