dl-sysdep.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Various assembly language/system dependent hacks that are required
  3. * so that we can minimize the amount of platform specific code.
  4. * Copyright (C) 2005 by Erik Andersen <andersen@codepoet.org>
  5. */
  6. /* Define this if the system uses RELOCA. */
  7. #define ELF_USES_RELOCA
  8. #include <elf.h>
  9. /* Initialization sequence for a GOT. */
  10. #define INIT_GOT(GOT_BASE,MODULE) \
  11. do { \
  12. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  13. GOT_BASE[1] = (unsigned long) (MODULE); \
  14. } while(0)
  15. /* Here we define the magic numbers that this dynamic loader should accept */
  16. #define MAGIC1 EM_68K
  17. #undef MAGIC2
  18. /* Used for error messages */
  19. #define ELF_TARGET "m68k"
  20. /* Need bootstrap relocations */
  21. #define ARCH_NEEDS_BOOTSTRAP_RELOCS
  22. struct elf_resolve;
  23. extern unsigned long _dl_linux_resolver (struct elf_resolve *, int);
  24. /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry, so
  25. PLT entries should not be allowed to define the value.
  26. ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
  27. of the main executable's symbols, as for a COPY reloc. */
  28. #define elf_machine_type_class(type) \
  29. ((((type) == R_68K_JMP_SLOT) * ELF_RTYPE_CLASS_PLT) \
  30. | (((type) == R_68K_COPY) * ELF_RTYPE_CLASS_COPY))
  31. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  32. first element of the GOT. This must be inlined in a function which
  33. uses global data. */
  34. static __always_inline Elf32_Addr
  35. elf_machine_dynamic (void)
  36. {
  37. Elf32_Addr got;
  38. __asm__ ("move.l _DYNAMIC@GOT.w(%%a5), %0"
  39. : "=a" (got));
  40. return got;
  41. }
  42. #ifdef __mcoldfire__
  43. #define PCREL_OP(OP, SRC, DST, TMP, PC) \
  44. "move.l #" SRC " - ., " TMP "\n\t" OP " (-8, " PC ", " TMP "), " DST
  45. #else
  46. #define PCREL_OP(OP, SRC, DST, TMP, PC) \
  47. OP " " SRC "(" PC "), " DST
  48. #endif
  49. /* Return the run-time load address of the shared object. */
  50. static __always_inline Elf32_Addr
  51. elf_machine_load_address (void)
  52. {
  53. Elf32_Addr addr;
  54. __asm__ (PCREL_OP ("lea", "_dl_start", "%0", "%0", "%%pc") "\n\t"
  55. "sub.l _dl_start@GOT.w(%%a5), %0"
  56. : "=a" (addr));
  57. return addr;
  58. }
  59. static __always_inline void
  60. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  61. Elf32_Word relative_count)
  62. {
  63. Elf32_Rela * rpnt = (void *)rel_addr;
  64. --rpnt;
  65. do {
  66. Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset);
  67. *reloc_addr = load_off + rpnt->r_addend;
  68. } while (--relative_count);
  69. }