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 {
15921592 _ = it;
15931593
15941594 const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type());
1595 const is_dyn_lib = elf_file.base.isDynLib();
1596
15951597 switch (r_type) {
15961598 .ABS64 => {
15971599 try atom.scanReloc(symbol, rel, dynAbsRelocAction(symbol, elf_file), elf_file);
......@@ -1629,6 +1631,12 @@ const aarch64 = struct {
16291631 .LDST128_ABS_LO12_NC,
16301632 => {},
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
16321640 else => try atom.reportUnhandledRelocError(rel, elf_file),
16331641 }
16341642 }
......@@ -1650,7 +1658,6 @@ const aarch64 = struct {
16501658 const cwriter = stream.writer();
16511659
16521660 const P, const A, const S, const GOT, const G, const TP, const DTP, const ZIG_GOT = args;
1653 _ = TP;
16541661 _ = DTP;
16551662 _ = ZIG_GOT;
16561663
......@@ -1736,6 +1743,17 @@ const aarch64 = struct {
17361743 try aarch64_util.writePageOffset(kind, taddr, code[r_offset..][0..4]);
17371744 },
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
17391757 else => try atom.reportUnhandledRelocError(rel, elf_file),
17401758 }
17411759 }
src/link/aarch64.zig+11
......@@ -95,6 +95,17 @@ pub fn writeBranchImm(disp: i28, code: *[4]u8) !void {
9595 mem.writeInt(u32, code, inst.toU32(), .little);
9696}
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
98109const assert = std.debug.assert;
99110const bits = @import("../arch/aarch64/bits.zig");
100111const builtin = @import("builtin");