aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

ld_arch.h (1863B)


      1 /* ld arch dispatch: per-architecture relocation handlers
      2  * the linker discovers the target arch from input object e_machine
      3  * and selects the matching backend at runtime */
      4 
      5 #ifndef LD_LD_ARCH_H
      6 #define LD_LD_ARCH_H
      7 
      8 #include "ld.h"
      9 
     10 /* a single relocation to apply. all fields are set by the core
     11  * relocation loop before calling the arch handler */
     12 struct ld_reloc {
     13   unsigned int   type;        /* ELF relocation type (R_* constant) */
     14   unsigned long  val;         /* resolved symbol value + addend */
     15   unsigned long *dst;         /* pointer to target bytes in section data */
     16   unsigned long  addr;        /* virtual address of the relocation site */
     17   struct outelf *oe;          /* linker state for GOT lookups */
     18   Elf_Shdr      *target_shdr; /* section header of section being patched */
     19   int            sym_idx;     /* symbol index in source object */
     20   int            obj_idx;     /* index of source object in oe->objs */
     21   long           addend;      /* raw rela addend, unmixed with symval */
     22 };
     23 
     24 /* per-arch relocation backend */
     25 struct ld_arch_backend {
     26   int em_machine; /* EM_* constant */
     27   /* apply a single relocation. modifies *dst in place */
     28   void (*reloc_apply)(struct ld_reloc *r);
     29   /* check if a relocation type requires a got entry */
     30   int (*is_got_rel)(unsigned int type);
     31 };
     32 
     33 /* select the arch backend matching the given e_machine
     34  * returns NULL for unsupported arches */
     35 const struct ld_arch_backend *ld_arch_select(int em_machine);
     36 
     37 /* per-arch backend definitions, one per arch source file */
     38 extern const struct ld_arch_backend ld_arch_x64;
     39 extern const struct ld_arch_backend ld_arch_x86;
     40 extern const struct ld_arch_backend ld_arch_arm;
     41 #ifdef EM_RISCV
     42 extern const struct ld_arch_backend ld_arch_riscv;
     43 #endif
     44 #ifdef EM_AARCH64
     45 extern const struct ld_arch_backend ld_arch_aarch64;
     46 #endif
     47 
     48 #endif /* LD_LD_ARCH_H */