dl-sysdep.h 2.5 KB

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