0

I am working on linker development for an open source project. The target architecture is AMD_X86_X64. In AMD_X86_X64 specification The relocation types' calculations for ELF are declared for example, R_X86_64_64 the calculation is S + A. How to do these calculations in COFF I can't find them online ?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

1 Answers1

1

COFF relocation types are enumerated at COFF Relocations for x64.

IMAGE_REL_AMD64_ABSOLUTE corresponds with R_X86_X64_COPY (no relocation),
IMAGE_REL_AMD64_ADDR64 corresponds with R_X86_X64_64 (S+A),
IMAGE_REL_AMD64_ADDR32 corresponds with R_X86_X64_32 (S+A),
IMAGE_REL_AMD64_REL32 corresponds with R_X86_X64_PC32 (S+A-P).

vitsoft
  • 5,515
  • 1
  • 18
  • 31
  • So for `IMAGE_REL_AMD64_REL32_1` the calculation will be (S + A - P + 1). What about the other calculations ? They are just enumerated in the docs – Mohamed Atef Jul 05 '22 at 03:06
  • Yes, `IMAGE_AMD64_REL32_x` are used when the relocated DWORD is not the last field in instruction encoding and x bytes follow it. `IMAGE_REL_AMD64_ADDR32NB` (NoBase) is related to RVA rather than VA, Microsoft employs it for relocations in *resources*. I don't think that the remaining relocation types were ever used. – vitsoft Jul 05 '22 at 05:45