authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-21 22:28:02+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-21 22:28:02+01:00
log7fd4576596a95d68300035cd59c3723bdadae353
tree4267e52b94facf10ac560455fcc51c262c32abc0
parent7aeba3a3d12323c2593da5742665865b33818451

elf+aarch64: resolve .eh_frame relocs


1 files changed, 14 insertions(+), 0 deletions(-)

src/link/Elf/eh_frame.zig+14
......@@ -318,6 +318,7 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file:
318318
319319 switch (cpu_arch) {
320320 .x86_64 => try x86_64.resolveReloc(rec, elf_file, rel, P, S + A, contents[offset..]),
321 .aarch64 => try aarch64.resolveReloc(rec, elf_file, rel, P, S + A, contents[offset..]),
321322 else => return error.UnsupportedCpuArch,
322323 }
323324}
......@@ -563,6 +564,19 @@ const x86_64 = struct {
563564 }
564565};
565566
567const aarch64 = struct {
568 fn resolveReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) !void {
569 const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type());
570 switch (r_type) {
571 .NONE => {},
572 .ABS64 => std.mem.writeInt(i64, data[0..8], target, .little),
573 .PREL32 => std.mem.writeInt(i32, data[0..4], @as(i32, @intCast(target - source)), .little),
574 .PREL64 => std.mem.writeInt(i64, data[0..8], target - source, .little),
575 else => try reportInvalidReloc(rec, elf_file, rel),
576 }
577 }
578};
579
566580fn reportInvalidReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela) !void {
567581 var err = try elf_file.addErrorWithNotes(1);
568582 try err.addMsg(elf_file, "invalid relocation type {} at offset 0x{x}", .{