kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

reloc_x86_64.c (1803B)


      1 #include "core/util.h"
      2 #include "obj/macho/macho.h"
      3 
      4 u32 macho_x86_64_reloc_to(u32 kind /* RelocKind */) {
      5   switch (kind) {
      6     case R_NONE:
      7       return (u32)-1;
      8     case R_ABS64:
      9     case R_ABS32:
     10       return X86_64_RELOC_UNSIGNED;
     11     case R_PC32:
     12     case R_REL32:
     13     case R_PC64:
     14     case R_REL64:
     15     case R_X64_PC8:
     16       return X86_64_RELOC_SIGNED;
     17     case R_PLT32:
     18     case R_X64_PLT32:
     19       return X86_64_RELOC_BRANCH;
     20     case R_X64_GOTPCRELX:
     21     case R_X64_REX_GOTPCRELX:
     22       return X86_64_RELOC_GOT_LOAD;
     23     case R_X64_GOTPCREL:
     24       return X86_64_RELOC_GOT;
     25     case R_X64_TPOFF32:
     26       return X86_64_RELOC_TLV;
     27     default:
     28       return (u32)-1;
     29   }
     30 }
     31 
     32 u32 macho_x86_64_reloc_pcrel(u32 kind /* RelocKind */) {
     33   switch (kind) {
     34     case R_PC32:
     35     case R_REL32:
     36     case R_PC64:
     37     case R_REL64:
     38     case R_X64_PC8:
     39     case R_PLT32:
     40     case R_X64_PLT32:
     41     case R_X64_GOTPCREL:
     42     case R_X64_GOTPCRELX:
     43     case R_X64_REX_GOTPCRELX:
     44     case R_X64_TPOFF32:
     45       return 1;
     46     default:
     47       return 0;
     48   }
     49 }
     50 
     51 u32 macho_x86_64_reloc_length(u32 kind /* RelocKind */) {
     52   switch (kind) {
     53     case R_ABS64:
     54     case R_PC64:
     55     case R_REL64:
     56       return 3;
     57     case R_X64_PC8:
     58       return 0;
     59     default:
     60       return 2;
     61   }
     62 }
     63 
     64 u32 macho_x86_64_reloc_from(u32 macho_type) {
     65   switch (macho_type) {
     66     case X86_64_RELOC_UNSIGNED:
     67       return R_ABS64;
     68     case X86_64_RELOC_SIGNED:
     69     case X86_64_RELOC_SIGNED_1:
     70     case X86_64_RELOC_SIGNED_2:
     71     case X86_64_RELOC_SIGNED_4:
     72       return R_PC32;
     73     case X86_64_RELOC_BRANCH:
     74       return R_X64_PLT32;
     75     case X86_64_RELOC_GOT_LOAD:
     76       return R_X64_REX_GOTPCRELX;
     77     case X86_64_RELOC_GOT:
     78       return R_X64_GOTPCREL;
     79     case X86_64_RELOC_TLV:
     80       return R_X64_TPOFF32;
     81     default:
     82       return (u32)-1;
     83   }
     84 }