| ... | ... | @@ -425,6 +425,7 @@ pub fn resolveRelocs(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 425 | 425 | .object => |x| elf_file.symbol(x.symbols.items[rel.r_sym()]), |
| 426 | 426 | else => unreachable, |
| 427 | 427 | }; |
| 428 | const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow; |
| 428 | 429 | |
| 429 | 430 | // We will use equation format to resolve relocations: |
| 430 | 431 | // https://intezer.com/blog/malware-analysis/executable-and-linkable-format-101-part-3-relocations/ |
| ... | ... | @@ -454,14 +455,14 @@ pub fn resolveRelocs(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 454 | 455 | |
| 455 | 456 | relocs_log.debug(" {s}: {x}: [{x} => {x}] G({x}) ({s})", .{ |
| 456 | 457 | fmtRelocType(r_type), |
| 457 | | rel.r_offset, |
| 458 | r_offset, |
| 458 | 459 | P, |
| 459 | 460 | S + A, |
| 460 | 461 | G + GOT + A, |
| 461 | 462 | target.name(elf_file), |
| 462 | 463 | }); |
| 463 | 464 | |
| 464 | | try stream.seekTo(rel.r_offset); |
| 465 | try stream.seekTo(r_offset); |
| 465 | 466 | |
| 466 | 467 | switch (rel.r_type()) { |
| 467 | 468 | elf.R_X86_64_NONE => unreachable, |
| ... | ... | @@ -481,7 +482,7 @@ pub fn resolveRelocs(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 481 | 482 | |
| 482 | 483 | elf.R_X86_64_GOTPCRELX => { |
| 483 | 484 | if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: { |
| 484 | | x86_64.relaxGotpcrelx(code[rel.r_offset - 2 ..]) catch break :blk; |
| 485 | x86_64.relaxGotpcrelx(code[r_offset - 2 ..]) catch break :blk; |
| 485 | 486 | try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A - P))); |
| 486 | 487 | continue; |
| 487 | 488 | } |
| ... | ... | @@ -490,7 +491,7 @@ pub fn resolveRelocs(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 490 | 491 | |
| 491 | 492 | elf.R_X86_64_REX_GOTPCRELX => { |
| 492 | 493 | if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: { |
| 493 | | x86_64.relaxRexGotpcrelx(code[rel.r_offset - 3 ..]) catch break :blk; |
| 494 | x86_64.relaxRexGotpcrelx(code[r_offset - 3 ..]) catch break :blk; |
| 494 | 495 | try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A - P))); |
| 495 | 496 | continue; |
| 496 | 497 | } |