From 7aeba3a3d12323c2593da5742665865b33818451 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Wed, 21 Feb 2024 22:25:25 +0100 Subject: [PATCH] elf+aarch64: implement some resolveRelocNonAlloc logic --- src/link/Elf/Atom.zig | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig index b6b61a063b02ae9426717edd691fd1629420dc63..1067e10fd88557319ecea4f87930ec6e869d63d1 100644 --- a/src/link/Elf/Atom.zig +++ b/src/link/Elf/Atom.zig @@ -949,6 +949,10 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any error.RelocFailure => has_reloc_errors = true, else => |e| return e, }, + .aarch64 => aarch64.resolveRelocNonAlloc(self, elf_file, rel, target, args, &it, code, &stream) catch |err| switch (err) { + error.RelocFailure => has_reloc_errors = true, + else => |e| return e, + }, else => return error.UnsupportedCpuArch, } } @@ -1629,8 +1633,6 @@ const aarch64 = struct { const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type()); const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow; - - try stream.seekTo(r_offset); const cwriter = stream.writer(); const P, const A, const S, const GOT, const G, const TP, const DTP, const ZIG_GOT = args; @@ -1724,6 +1726,33 @@ const aarch64 = struct { } } + fn resolveRelocNonAlloc( + atom: Atom, + elf_file: *Elf, + rel: elf.Elf64_Rela, + target: *const Symbol, + args: ResolveArgs, + it: *RelocsIterator, + code: []u8, + stream: anytype, + ) !void { + _ = it; + _ = code; + _ = target; + + const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type()); + const cwriter = stream.writer(); + + _, const A, const S, _, _, _, _, _ = args; + + switch (r_type) { + .NONE => unreachable, + .ABS32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A)), .little), + .ABS64 => try cwriter.writeInt(i64, S + A, .little), + else => try atom.reportUnhandledRelocError(rel, elf_file), + } + } + const aarch64_util = @import("../aarch64.zig"); }; -- 2.54.0