dl-sysdep.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /* Use reloca */
  16. #define ELF_USES_RELOCA
  17. #include <elf.h>
  18. /* Initialise the GOT */
  19. #define INIT_GOT(GOT_BASE,MODULE) \
  20. do { \
  21. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  22. GOT_BASE[1] = (unsigned long) MODULE; \
  23. } while(0)
  24. /* Here we define the magic numbers that this dynamic loader should accept */
  25. #define MAGIC1 EM_MICROBLAZE_OLD
  26. #undef MAGIC2
  27. /* Used for error messages */
  28. #define ELF_TARGET "microblaze"
  29. #define elf_machine_type_class(type) \
  30. (((type) == R_MICROBLAZE_JUMP_SLOT) * ELF_RTYPE_CLASS_PLT \
  31. | ((type) == R_MICROBLAZE_COPY) * ELF_RTYPE_CLASS_COPY)
  32. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  33. first element of the GOT. This must be inlined in a function which
  34. uses global data. */
  35. static inline Elf32_Addr
  36. elf_machine_dynamic (void)
  37. {
  38. Elf32_Addr got_entry_0;
  39. __asm__ __volatile__(
  40. "lwi %0,r20,0"
  41. :"=r"(got_entry_0)
  42. );
  43. return got_entry_0;
  44. }
  45. /* Return the run-time load address of the shared object. */
  46. static inline Elf32_Addr
  47. elf_machine_load_address (void)
  48. {
  49. /* Compute the difference between the runtime address of _DYNAMIC as seen
  50. by a GOTOFF reference, and the link-time address found in the special
  51. unrelocated first GOT entry. */
  52. Elf32_Addr dyn;
  53. __asm__ __volatile__ (
  54. "addik %0,r20,_DYNAMIC@GOTOFF"
  55. : "=r"(dyn)
  56. );
  57. return dyn - elf_machine_dynamic ();
  58. }
  59. static __always_inline void
  60. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  61. Elf32_Word relative_count)
  62. {
  63. Elf32_Rel * rpnt = (void *) rel_addr;
  64. do {
  65. Elf32_Addr *const reloc_addr = (void *) (load_off + (rpnt)->r_offset);
  66. *reloc_addr += load_off;
  67. } while (--relative_count);
  68. }