authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-03-07 23:01:06+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-03-08 22:46:17+01:00
logc1dbf01aa3e7ee1922762e6f9b86b2ad4c4a7e6f
tree6a2c6b2eba57d235cbf0fba7ded107bdd50a5300
parent69f9f359dd5107cd071f3801a6824336b5d2bce6

elf+aarch64: resolve TLS LE model


2 files changed, 30 insertions(+), 1 deletions(-)

src/link/Elf/Atom.zig+19-1
...@@ -1592,6 +1592,8 @@ const aarch64 = struct {...@@ -1592,6 +1592,8 @@ const aarch64 = struct {
1592 _ = it;1592 _ = it;
15931593
1594 const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type());1594 const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type());
1595 const is_dyn_lib = elf_file.base.isDynLib();
1596
1595 switch (r_type) {1597 switch (r_type) {
1596 .ABS64 => {1598 .ABS64 => {
1597 try atom.scanReloc(symbol, rel, dynAbsRelocAction(symbol, elf_file), elf_file);1599 try atom.scanReloc(symbol, rel, dynAbsRelocAction(symbol, elf_file), elf_file);
...@@ -1629,6 +1631,12 @@ const aarch64 = struct {...@@ -1629,6 +1631,12 @@ const aarch64 = struct {
1629 .LDST128_ABS_LO12_NC,1631 .LDST128_ABS_LO12_NC,
1630 => {},1632 => {},
16311633
1634 .TLSLE_ADD_TPREL_HI12,
1635 .TLSLE_ADD_TPREL_LO12_NC,
1636 => {
1637 if (is_dyn_lib) try atom.reportPicError(symbol, rel, elf_file);
1638 },
1639
1632 else => try atom.reportUnhandledRelocError(rel, elf_file),1640 else => try atom.reportUnhandledRelocError(rel, elf_file),
1633 }1641 }
1634 }1642 }
...@@ -1650,7 +1658,6 @@ const aarch64 = struct {...@@ -1650,7 +1658,6 @@ const aarch64 = struct {
1650 const cwriter = stream.writer();1658 const cwriter = stream.writer();
16511659
1652 const P, const A, const S, const GOT, const G, const TP, const DTP, const ZIG_GOT = args;1660 const P, const A, const S, const GOT, const G, const TP, const DTP, const ZIG_GOT = args;
1653 _ = TP;
1654 _ = DTP;1661 _ = DTP;
1655 _ = ZIG_GOT;1662 _ = ZIG_GOT;
16561663
...@@ -1736,6 +1743,17 @@ const aarch64 = struct {...@@ -1736,6 +1743,17 @@ const aarch64 = struct {
1736 try aarch64_util.writePageOffset(kind, taddr, code[r_offset..][0..4]);1743 try aarch64_util.writePageOffset(kind, taddr, code[r_offset..][0..4]);
1737 },1744 },
17381745
1746 .TLSLE_ADD_TPREL_HI12 => {
1747 const value = math.cast(i12, (S + A - TP) >> 12) orelse
1748 return error.Overflow;
1749 try aarch64_util.writeAddInst(@bitCast(value), code[rel.r_offset..][0..4]);
1750 },
1751
1752 .TLSLE_ADD_TPREL_LO12_NC => {
1753 const value: i12 = @truncate(S + A - TP);
1754 try aarch64_util.writeAddInst(@bitCast(value), code[rel.r_offset..][0..4]);
1755 },
1756
1739 else => try atom.reportUnhandledRelocError(rel, elf_file),1757 else => try atom.reportUnhandledRelocError(rel, elf_file),
1740 }1758 }
1741 }1759 }
src/link/aarch64.zig+11
...@@ -95,6 +95,17 @@ pub fn writeBranchImm(disp: i28, code: *[4]u8) !void {...@@ -95,6 +95,17 @@ pub fn writeBranchImm(disp: i28, code: *[4]u8) !void {
95 mem.writeInt(u32, code, inst.toU32(), .little);95 mem.writeInt(u32, code, inst.toU32(), .little);
96}96}
9797
98pub fn writeAddInst(value: u12, code: *[4]u8) !void {
99 var inst = Instruction{
100 .add_subtract_immediate = mem.bytesToValue(std.meta.TagPayload(
101 Instruction,
102 Instruction.add_subtract_immediate,
103 ), code),
104 };
105 inst.add_subtract_immediate.imm12 = value;
106 mem.writeInt(u32, code, inst.toU32(), .little);
107}
108
98const assert = std.debug.assert;109const assert = std.debug.assert;
99const bits = @import("../arch/aarch64/bits.zig");110const bits = @import("../arch/aarch64/bits.zig");
100const builtin = @import("builtin");111const builtin = @import("builtin");