Commit 7fd4576596

Jakub Konka <kubkon@jakubkonka.com>
2024-02-21 22:28:02
elf+aarch64: resolve .eh_frame relocs
1 parent 7aeba3a
Changed files (1)
src
link
src/link/Elf/eh_frame.zig
@@ -318,6 +318,7 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file:
 
     switch (cpu_arch) {
         .x86_64 => try x86_64.resolveReloc(rec, elf_file, rel, P, S + A, contents[offset..]),
+        .aarch64 => try aarch64.resolveReloc(rec, elf_file, rel, P, S + A, contents[offset..]),
         else => return error.UnsupportedCpuArch,
     }
 }
@@ -563,6 +564,19 @@ const x86_64 = struct {
     }
 };
 
+const aarch64 = struct {
+    fn resolveReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) !void {
+        const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type());
+        switch (r_type) {
+            .NONE => {},
+            .ABS64 => std.mem.writeInt(i64, data[0..8], target, .little),
+            .PREL32 => std.mem.writeInt(i32, data[0..4], @as(i32, @intCast(target - source)), .little),
+            .PREL64 => std.mem.writeInt(i64, data[0..8], target - source, .little),
+            else => try reportInvalidReloc(rec, elf_file, rel),
+        }
+    }
+};
+
 fn reportInvalidReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela) !void {
     var err = try elf_file.addErrorWithNotes(1);
     try err.addMsg(elf_file, "invalid relocation type {} at offset 0x{x}", .{