dl-sysdep.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Various assembly 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. do { \
  13. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  14. GOT_BASE[1] = (unsigned long) MODULE; \
  15. } while(0)
  16. /* Here we define the magic numbers that this dynamic loader should accept */
  17. #define MAGIC1 EM_386
  18. #undef MAGIC2
  19. /* Used for error messages */
  20. #define ELF_TARGET "386"
  21. struct elf_resolve;
  22. extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  23. /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
  24. TLS variable, so undefined references should not be allowed to
  25. define the value.
  26. ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
  27. of the main executable's symbols, as for a COPY reloc. */
  28. #define elf_machine_type_class(type) \
  29. ((((type) == R_386_JMP_SLOT || (type) == R_386_TLS_DTPMOD32 \
  30. || (type) == R_386_TLS_DTPOFF32 || (type) == R_386_TLS_TPOFF32 \
  31. || (type) == R_386_TLS_TPOFF) * ELF_RTYPE_CLASS_PLT) \
  32. | (((type) == R_386_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 __always_inline Elf32_Addr elf_machine_dynamic (void) attribute_unused;
  37. static __always_inline Elf32_Addr
  38. elf_machine_dynamic (void)
  39. {
  40. register Elf32_Addr *got __asm__ ("%ebx");
  41. return *got;
  42. }
  43. /* Return the run-time load address of the shared object. */
  44. static __always_inline Elf32_Addr elf_machine_load_address (void) attribute_unused;
  45. static __always_inline Elf32_Addr
  46. elf_machine_load_address (void)
  47. {
  48. /* It doesn't matter what variable this is, the reference never makes
  49. it to assembly. We need a dummy reference to some global variable
  50. via the GOT to make sure the compiler initialized %ebx in time. */
  51. Elf32_Addr addr;
  52. int tmp;
  53. __asm__ ("leal _dl_start@GOTOFF(%%ebx), %0\n"
  54. "subl _dl_start@GOT(%%ebx), %0"
  55. : "=r" (addr) : "m" (tmp) : "cc");
  56. return addr;
  57. }
  58. static __always_inline void
  59. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  60. Elf32_Word relative_count)
  61. {
  62. Elf32_Rel * rpnt = (void *) rel_addr;
  63. --rpnt;
  64. do {
  65. Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset);
  66. *reloc_addr += load_off;
  67. } while (--relative_count);
  68. }