dl-sysdep.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Various assmbly 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 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. /* Here we define the magic numbers that this dynamic loader should accept */
  45. #define MAGIC1 EM_ARM
  46. #undef MAGIC2
  47. /* Used for error messages */
  48. #define ELF_TARGET "ARM"
  49. struct elf_resolve;
  50. unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  51. /* 4096 bytes alignment */
  52. #define PAGE_ALIGN 0xfffff000
  53. #define ADDR_ALIGN 0xfff
  54. #define OFFS_ALIGN 0x7ffff000
  55. /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry, so
  56. PLT entries should not be allowed to define the value.
  57. ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
  58. of the main executable's symbols, as for a COPY reloc. */
  59. #define elf_machine_type_class(type) \
  60. ((((type) == R_ARM_JUMP_SLOT) * ELF_RTYPE_CLASS_PLT) \
  61. | (((type) == R_ARM_COPY) * ELF_RTYPE_CLASS_COPY))
  62. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  63. first element of the GOT. This must be inlined in a function which
  64. uses global data. */
  65. static inline Elf32_Addr __attribute__ ((unused))
  66. elf_machine_dynamic (void)
  67. {
  68. register Elf32_Addr *got asm ("r10");
  69. return *got;
  70. }
  71. /* Return the run-time load address of the shared object. */
  72. static inline Elf32_Addr __attribute__ ((unused))
  73. elf_machine_load_address (void)
  74. {
  75. extern void __dl_start asm ("_dl_start");
  76. Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
  77. Elf32_Addr pcrel_addr;
  78. asm ("adr %0, _dl_start" : "=r" (pcrel_addr));
  79. return pcrel_addr - got_addr;
  80. }
  81. static inline void
  82. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  83. Elf32_Word relative_count)
  84. {
  85. Elf32_Rel * rpnt = (void *) (rel_addr + load_off);
  86. --rpnt;
  87. do {
  88. Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset);
  89. *reloc_addr += load_off;
  90. } while (--relative_count);
  91. }