dl-sysdep.h 3.8 KB

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