dl-sysdep.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. The GNU C Library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Lesser General Public
  4. License as published by the Free Software Foundation; either
  5. version 2.1 of the License, or (at your option) any later version.
  6. The GNU C Library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Lesser General Public License for more details.
  10. You should have received a copy of the GNU Lesser General Public
  11. License along with the GNU C Library; if not, see
  12. <http://www.gnu.org/licenses/>. */
  13. #define ELF_USES_RELOCA
  14. #include <elf.h>
  15. /* Initialise the GOT */
  16. #define INIT_GOT(GOT_BASE,MODULE) \
  17. do { \
  18. GOT_BASE[1] = (unsigned long) MODULE; \
  19. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  20. } while(0)
  21. /* Here we define the magic numbers that this dynamic loader should accept */
  22. #define MAGIC1 EM_MICROBLAZE
  23. #undef MAGIC2
  24. /* Used for error messages */
  25. #define ELF_TARGET "microblaze"
  26. /* Need bootstrap relocations */
  27. #define ARCH_NEEDS_BOOTSTRAP_RELOCS
  28. struct elf_resolve;
  29. unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  30. #define elf_machine_type_class(type) \
  31. (((type) == R_MICROBLAZE_JUMP_SLOT || \
  32. (type) == R_MICROBLAZE_TLSDTPREL32 || \
  33. (type) == R_MICROBLAZE_TLSDTPMOD32 || \
  34. (type) == R_MICROBLAZE_TLSTPREL32) \
  35. * ELF_RTYPE_CLASS_PLT \
  36. | ((type) == R_MICROBLAZE_COPY) * ELF_RTYPE_CLASS_COPY)
  37. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  38. first element of the GOT. This must be inlined in a function which
  39. uses global data. */
  40. static __always_inline Elf32_Addr __attribute__ ((unused))
  41. elf_machine_dynamic (void)
  42. {
  43. Elf32_Addr got_entry_0;
  44. __asm__ __volatile__(
  45. "lwi %0,r20,0"
  46. :"=r"(got_entry_0)
  47. );
  48. return got_entry_0;
  49. }
  50. /* Return the run-time load address of the shared object. */
  51. static inline Elf32_Addr
  52. elf_machine_load_address (void)
  53. {
  54. /* Compute the difference between the runtime address of _DYNAMIC as seen
  55. by a GOTOFF reference, and the link-time address found in the special
  56. unrelocated first GOT entry. */
  57. Elf32_Addr dyn;
  58. __asm__ __volatile__ (
  59. "addik %0,r20,_DYNAMIC@GOTOFF"
  60. : "=r"(dyn)
  61. );
  62. return dyn - elf_machine_dynamic ();
  63. }
  64. static __always_inline void
  65. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  66. Elf32_Word relative_count)
  67. {
  68. Elf32_Rel * rpnt = (void *) rel_addr;
  69. do {
  70. Elf32_Addr *const reloc_addr = (void *) (load_off + (rpnt)->r_offset);
  71. *reloc_addr += load_off;
  72. } while (--relative_count);
  73. }