dl-sysdep.h 4.1 KB

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