dl-sysdep.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Various assmbly 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. #define do_rem(result, n, base) ((result) = (n) % (base))
  24. /* 4096 bytes alignment */
  25. #define PAGE_ALIGN 0xfffff000
  26. #define ADDR_ALIGN 0xfff
  27. #define OFFS_ALIGN 0x7ffff000
  28. /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
  29. TLS variable, so undefined references should not be allowed to
  30. define the value.
  31. ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
  32. of the main executable's symbols, as for a COPY reloc. */
  33. #define elf_machine_type_class(type) \
  34. ((((type) == R_386_JMP_SLOT) * ELF_RTYPE_CLASS_PLT) \
  35. | (((type) == R_386_COPY) * ELF_RTYPE_CLASS_COPY))
  36. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  37. first element of the GOT. This must be inlined in a function which
  38. uses global data. */
  39. static inline Elf32_Addr elf_machine_dynamic (void) attribute_unused;
  40. static inline Elf32_Addr
  41. elf_machine_dynamic (void)
  42. {
  43. register Elf32_Addr *got __asm__ ("%ebx");
  44. return *got;
  45. }
  46. /* Return the run-time load address of the shared object. */
  47. static inline Elf32_Addr elf_machine_load_address (void) attribute_unused;
  48. static inline Elf32_Addr
  49. elf_machine_load_address (void)
  50. {
  51. /* It doesn't matter what variable this is, the reference never makes
  52. it to assembly. We need a dummy reference to some global variable
  53. via the GOT to make sure the compiler initialized %ebx in time. */
  54. extern int _dl_errno;
  55. Elf32_Addr addr;
  56. __asm__ ("leal _dl_start@GOTOFF(%%ebx), %0\n"
  57. "subl _dl_start@GOT(%%ebx), %0"
  58. : "=r" (addr) : "m" (_dl_errno) : "cc");
  59. return addr;
  60. }
  61. static inline void
  62. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  63. Elf32_Word relative_count)
  64. {
  65. Elf32_Rel * rpnt = (void *) rel_addr;
  66. --rpnt;
  67. do {
  68. Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset);
  69. *reloc_addr += load_off;
  70. } while (--relative_count);
  71. }