dl-sysdep.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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) 2000-2004 by Erik Andersen <andersen@codepoet.org>
  5. */
  6. #ifndef _ARCH_DL_SYSDEP
  7. #define _ARCH_DL_SYSDEP
  8. /* Define this if the system uses RELOCA. */
  9. #undef ELF_USES_RELOCA
  10. #include <elf.h>
  11. /* Initialization sequence for the GOT. */
  12. #define INIT_GOT(GOT_BASE,MODULE) \
  13. { \
  14. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  15. GOT_BASE[1] = (unsigned long) MODULE; \
  16. }
  17. static __always_inline unsigned long arm_modulus(unsigned long m, unsigned long p)
  18. {
  19. unsigned long i,t,inc;
  20. i=p; t=0;
  21. while (!(i&(1<<31))) {
  22. i<<=1;
  23. t++;
  24. }
  25. t--;
  26. for (inc=t;inc>2;inc--) {
  27. i=p<<inc;
  28. if (i&(1<<31))
  29. break;
  30. while (m>=i) {
  31. m-=i;
  32. i<<=1;
  33. if (i&(1<<31))
  34. break;
  35. if (i<p)
  36. break;
  37. }
  38. }
  39. while (m>=p) {
  40. m-=p;
  41. }
  42. return m;
  43. }
  44. #define do_rem(result, n, base) ((result) = arm_modulus(n, base))
  45. #define do_div_10(result, remain) ((result) = (((result) - (remain)) / 2) * -(-1ul / 5ul))
  46. /* Here we define the magic numbers that this dynamic loader should accept */
  47. #define MAGIC1 EM_ARM
  48. #undef MAGIC2
  49. /* Used for error messages */
  50. #define ELF_TARGET "ARM"
  51. struct elf_resolve;
  52. unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  53. /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
  54. TLS variable, so undefined references should not be allowed to
  55. define the value.
  56. ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
  57. of the main executable's symbols, as for a COPY reloc. */
  58. #define elf_machine_type_class(type) \
  59. ((((type) == R_ARM_JUMP_SLOT || (type) == R_ARM_TLS_DTPMOD32 \
  60. || (type) == R_ARM_TLS_DTPOFF32 || (type) == R_ARM_TLS_TPOFF32) \
  61. * ELF_RTYPE_CLASS_PLT) \
  62. | (((type) == R_ARM_COPY) * ELF_RTYPE_CLASS_COPY))
  63. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  64. first element of the GOT. We used to use the PIC register to do this
  65. without a constant pool reference, but GCC 4.2 will use a pseudo-register
  66. for the PIC base, so it may not be in r10. */
  67. static __always_inline Elf32_Addr __attribute__ ((unused))
  68. elf_machine_dynamic (void)
  69. {
  70. Elf32_Addr dynamic;
  71. #if !defined __thumb__
  72. __asm__ ("ldr %0, 2f\n"
  73. "1: ldr %0, [pc, %0]\n"
  74. "b 3f\n"
  75. "2: .word _GLOBAL_OFFSET_TABLE_ - (1b+8)\n"
  76. "3:" : "=r" (dynamic));
  77. #else
  78. int tmp;
  79. __asm__ (".align 2\n"
  80. "bx pc\n"
  81. "nop\n"
  82. ".arm\n"
  83. "ldr %0, 2f\n"
  84. "1: ldr %0, [pc, %0]\n"
  85. "b 3f\n"
  86. "2: .word _GLOBAL_OFFSET_TABLE_ - (1b+8)\n"
  87. "3:"
  88. ".align 2\n"
  89. "orr %1, pc, #1\n"
  90. "bx %1\n"
  91. ".force_thumb\n"
  92. : "=r" (dynamic), "=&r" (tmp));
  93. #endif
  94. return dynamic;
  95. }
  96. extern char __dl_start[] __asm__("_dl_start");
  97. /* Return the run-time load address of the shared object. */
  98. static __always_inline Elf32_Addr __attribute__ ((unused))
  99. elf_machine_load_address (void)
  100. {
  101. Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
  102. Elf32_Addr pcrel_addr;
  103. #if defined __OPTIMIZE__ && !defined __thumb__
  104. __asm__ ("adr %0, _dl_start" : "=r" (pcrel_addr));
  105. #else
  106. /* A simple adr does not work in Thumb mode because the offset is
  107. negative, and for debug builds may be too large. */
  108. int tmp;
  109. __asm__ ("adr %1, 1f\n\t"
  110. "ldr %0, [%1]\n\t"
  111. "add %0, %0, %1\n\t"
  112. "b 2f\n\t"
  113. ".align 2\n\t"
  114. "1: .word _dl_start - 1b\n\t"
  115. "2:"
  116. : "=r" (pcrel_addr), "=r" (tmp));
  117. #endif
  118. return pcrel_addr - got_addr;
  119. }
  120. static __always_inline void
  121. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  122. Elf32_Word relative_count)
  123. {
  124. Elf32_Rel * rpnt = (void *) rel_addr;
  125. --rpnt;
  126. do {
  127. Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset);
  128. *reloc_addr += load_off;
  129. } while (--relative_count);
  130. }
  131. #endif /* !_ARCH_DL_SYSDEP */
  132. #ifdef __ARM_EABI__
  133. #define DL_MALLOC_ALIGN 8 /* EABI needs 8 byte alignment for STRD LDRD */
  134. #endif