reloc.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include <elf.h>
  4. #define LDSO_ARCH "x86_64"
  5. #define IS_COPY(x) ((x)==R_X86_64_COPY)
  6. #define IS_PLT(x) ((x)==R_X86_64_JUMP_SLOT)
  7. static inline void do_single_reloc(
  8. struct dso *self, unsigned char *base_addr,
  9. size_t *reloc_addr, int type, size_t addend,
  10. Sym *sym, size_t sym_size,
  11. struct symdef def, size_t sym_val)
  12. {
  13. switch(type) {
  14. case R_X86_64_GLOB_DAT:
  15. case R_X86_64_JUMP_SLOT:
  16. case R_X86_64_64:
  17. *reloc_addr = sym_val + addend;
  18. break;
  19. case R_X86_64_32:
  20. *(uint32_t *)reloc_addr = sym_val + addend;
  21. break;
  22. case R_X86_64_PC32:
  23. *reloc_addr = sym_val + addend - (size_t)reloc_addr + (size_t)base_addr;
  24. break;
  25. case R_X86_64_RELATIVE:
  26. *reloc_addr = (size_t)base_addr + addend;
  27. break;
  28. case R_X86_64_COPY:
  29. memcpy(reloc_addr, (void *)sym_val, sym_size);
  30. break;
  31. case R_X86_64_DTPMOD64:
  32. *reloc_addr = def.dso ? def.dso->tls_id : self->tls_id;
  33. break;
  34. case R_X86_64_DTPOFF64:
  35. *reloc_addr = def.sym->st_value + addend;
  36. break;
  37. case R_X86_64_TPOFF64:
  38. *reloc_addr = (def.sym
  39. ? def.sym->st_value - def.dso->tls_offset
  40. : 0 - self->tls_offset) + addend;
  41. break;
  42. }
  43. }