From d7d47a2c0c1585885d6ba45beb10744af48c2092 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Wed, 21 Feb 2024 22:07:51 +0100 Subject: [PATCH] elf+aarch64: implement some scanReloc logic --- src/link/Elf/Atom.zig | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig index 05ecf24bd6..68d1833712 100644 --- a/src/link/Elf/Atom.zig +++ b/src/link/Elf/Atom.zig @@ -438,6 +438,10 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, code: ?[]const u8, undefs: anytype error.RelocFailure => has_reloc_errors = true, else => |e| return e, }, + .aarch64 => aarch64.scanReloc(self, elf_file, rel, symbol, code, &it) catch |err| switch (err) { + error.RelocFailure => has_reloc_errors = true, + else => |e| return e, + }, else => return error.UnsupportedCpuArch, } } @@ -1549,6 +1553,61 @@ const x86_64 = struct { const Instruction = encoder.Instruction; }; +const aarch64 = struct { + fn scanReloc( + atom: Atom, + elf_file: *Elf, + rel: elf.Elf64_Rela, + symbol: *Symbol, + code: ?[]const u8, + it: *RelocsIterator, + ) !void { + _ = code; + _ = it; + + const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type()); + switch (r_type) { + .ABS64 => { + try atom.scanReloc(symbol, rel, dynAbsRelocAction(symbol, elf_file), elf_file); + }, + + .ADR_PREL_PG_HI21 => { + try atom.scanReloc(symbol, rel, pcRelocAction(symbol, elf_file), elf_file); + }, + + .ADR_GOT_PAGE => { + // TODO: relax if possible + symbol.flags.needs_got = true; + }, + + .LD64_GOT_LO12_NC, + .LD64_GOTPAGE_LO15, + => { + symbol.flags.needs_got = true; + }, + + .CALL26, + .JUMP26, + => { + if (symbol.flags.import) { + symbol.flags.needs_plt = true; + } + }, + + .ADD_ABS_LO12_NC, + .ADR_PREL_LO21, + .LDST8_ABS_LO12_NC, + .LDST16_ABS_LO12_NC, + .LDST32_ABS_LO12_NC, + .LDST64_ABS_LO12_NC, + .LDST128_ABS_LO12_NC, + => {}, + + else => try atom.reportUnhandledRelocError(rel, elf_file), + } + } +}; + const ResolveArgs = struct { i64, i64, i64, i64, i64, i64, i64, i64 }; const RelocError = error{