dl-sysdep.h 2.4 KB

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