| ... | ... | @@ -318,6 +318,7 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file: |
| 318 | 318 | |
| 319 | 319 | switch (cpu_arch) { |
| 320 | 320 | .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..]), |
| 321 | 322 | else => return error.UnsupportedCpuArch, |
| 322 | 323 | } |
| 323 | 324 | } |
| ... | ... | @@ -563,6 +564,19 @@ const x86_64 = struct { |
| 563 | 564 | } |
| 564 | 565 | }; |
| 565 | 566 | |
| 567 | const 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 | |
| 566 | 580 | fn reportInvalidReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela) !void { |
| 567 | 581 | var err = try elf_file.addErrorWithNotes(1); |
| 568 | 582 | try err.addMsg(elf_file, "invalid relocation type {} at offset 0x{x}", .{ |