dl-sysdep.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Use reloca */
  2. #define ELF_USES_RELOCA
  3. #include <elf.h>
  4. /* Initialise the GOT */
  5. #define INIT_GOT(GOT_BASE,MODULE) \
  6. do { \
  7. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  8. GOT_BASE[1] = (unsigned long) MODULE; \
  9. } while(0)
  10. /* Here we define the magic numbers that this dynamic loader should accept */
  11. #define MAGIC1 EM_ALTERA_NIOS2
  12. #undef MAGIC2
  13. /* Used for error messages */
  14. #define ELF_TARGET "nios2"
  15. struct elf_resolve;
  16. unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  17. /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry, so
  18. PLT entries should not be allowed to define the value.
  19. ELF_RTYPE_CLASS_COPY iff TYPE should not be allowed to resolve to one
  20. of the main executable's symbols, as for a COPY reloc. */
  21. #define elf_machine_type_class(type) \
  22. ((((type) == R_NIOS2_JUMP_SLOT \
  23. || (type) == R_NIOS2_TLS_DTPMOD \
  24. || (type) == R_NIOS2_TLS_DTPREL \
  25. || (type) == R_NIOS2_TLS_TPREL) * ELF_RTYPE_CLASS_PLT) \
  26. | (((type) == R_NIOS2_COPY) * ELF_RTYPE_CLASS_COPY))
  27. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  28. first element of the GOT. */
  29. static inline Elf32_Addr
  30. elf_machine_dynamic (void)
  31. {
  32. Elf32_Addr *dynamic;
  33. int tmp;
  34. __asm__ ("nextpc\t%0\n\t"
  35. "1: movhi\t%1, %%hiadj(_GLOBAL_OFFSET_TABLE_ - 1b)\n\t"
  36. "addi\t%1, %1, %%lo(_GLOBAL_OFFSET_TABLE_ - 1b)\n\t"
  37. "add\t%0, %0, %1\n"
  38. : "=r" (dynamic), "=r" (tmp));
  39. return *dynamic;
  40. }
  41. /* Return the run-time load address of the shared object. */
  42. static inline Elf32_Addr
  43. elf_machine_load_address (void)
  44. {
  45. Elf32_Addr result;
  46. int tmp;
  47. __asm__ ("nextpc\t%0\n\t"
  48. "1: movhi\t%1, %%hiadj(1b)\n\t"
  49. "addi\t%1, %1, %%lo(1b)\n\t"
  50. "sub\t%0, %0, %1\n"
  51. : "=r" (result), "=r" (tmp));
  52. return result;
  53. }
  54. static __always_inline void
  55. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  56. Elf32_Word relative_count)
  57. {
  58. Elf32_Rel * rpnt = (void *) rel_addr;
  59. do {
  60. Elf32_Addr *const reloc_addr = (void *) (load_off + (rpnt)->r_offset);
  61. *reloc_addr += load_off;
  62. } while (--relative_count);
  63. }