dl-sysdep.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* Copyright (C) 2003, 2004 Red Hat, Inc.
  2. * Contributed by Alexandre Oliva <aoliva@redhat.com>
  3. * Copyright (C) 2006-2011 Analog Devices, Inc.
  4. * Based on ../i386/dl-sysdep.h
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #define HAVE_DL_INLINES_H
  9. /*
  10. * Initialization sequence for a GOT. Copy the resolver function
  11. * descriptor and the pointer to the elf_resolve/link_map data
  12. * structure. Initialize the got_value in the module while at that.
  13. */
  14. #define INIT_GOT(GOT_BASE,MODULE) \
  15. { \
  16. (MODULE)->loadaddr.got_value = (GOT_BASE); \
  17. GOT_BASE[0] = ((unsigned long *)&_dl_linux_resolve)[0]; \
  18. GOT_BASE[1] = ((unsigned long *)&_dl_linux_resolve)[1]; \
  19. GOT_BASE[2] = (unsigned long) MODULE; \
  20. }
  21. struct elf_resolve;
  22. struct funcdesc_value
  23. {
  24. void *entry_point;
  25. void *got_value;
  26. } __attribute__((__aligned__(8)));
  27. struct funcdesc_ht;
  28. #define DL_LOADADDR_TYPE struct elf32_fdpic_loadaddr
  29. #define DL_RELOC_ADDR(LOADADDR, ADDR) \
  30. ((ElfW(Addr))__reloc_pointer ((void*)(ADDR), (LOADADDR).map))
  31. #define DL_ADDR_TO_FUNC_PTR(ADDR, LOADADDR) \
  32. ((void(*)(void)) _dl_funcdesc_for ((void*)(ADDR), (LOADADDR).got_value))
  33. #define _dl_stabilize_funcdesc(val) \
  34. ({ __asm__ ("" : "+m" (*(val))); (val); })
  35. #define DL_CALL_FUNC_AT_ADDR(ADDR, LOADADDR, SIGNATURE, ...) \
  36. ({ struct funcdesc_value fd = { (void*)(ADDR), (LOADADDR).got_value }; \
  37. void (*pf)(void) = (void*) _dl_stabilize_funcdesc (&fd); \
  38. (* SIGNATURE pf)(__VA_ARGS__); })
  39. #define DL_INIT_LOADADDR_BOOT(LOADADDR, BASEADDR) \
  40. (__dl_init_loadaddr_map (&(LOADADDR), dl_boot_got_pointer, \
  41. dl_boot_ldsomap ?: dl_boot_progmap))
  42. #define DL_INIT_LOADADDR_PROG(LOADADDR, BASEADDR) \
  43. (__dl_init_loadaddr_map (&(LOADADDR), 0, dl_boot_progmap))
  44. #define DL_INIT_LOADADDR_EXTRA_DECLS \
  45. int dl_init_loadaddr_load_count;
  46. #define DL_INIT_LOADADDR(LOADADDR, BASEADDR, PHDR, PHDRCNT) \
  47. (dl_init_loadaddr_load_count = \
  48. __dl_init_loadaddr (&(LOADADDR), (PHDR), (PHDRCNT)))
  49. #define DL_INIT_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \
  50. (__dl_init_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR), \
  51. dl_init_loadaddr_load_count))
  52. #define DL_UPDATE_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \
  53. (__dl_update_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR)))
  54. #define DL_LOADADDR_UNMAP(LOADADDR, LEN) \
  55. (__dl_loadaddr_unmap ((LOADADDR), (NULL)))
  56. #define DL_LIB_UNMAP(LIB, LEN) \
  57. (__dl_loadaddr_unmap ((LIB)->loadaddr, (LIB)->funcdesc_ht))
  58. #define DL_LOADADDR_BASE(LOADADDR) \
  59. ((LOADADDR).got_value)
  60. /* This is called from dladdr(), such that we map a function
  61. descriptor's address to the function's entry point before trying to
  62. find in which library it's defined. */
  63. #define DL_LOOKUP_ADDRESS(ADDRESS) (_dl_lookup_address (ADDRESS))
  64. #define DL_ADDR_IN_LOADADDR(ADDR, TPNT, TFROM) \
  65. (! (TFROM) && __dl_addr_in_loadaddr ((void*)(ADDR), (TPNT)->loadaddr))
  66. /*
  67. * Compute the GOT address. On several platforms, we use assembly
  68. * here. on FDPIC, there's no way to compute the GOT address,
  69. * since the offset between text and data is not fixed, so we arrange
  70. * for the ldso assembly entry point to pass this value as an argument
  71. * to _dl_start. */
  72. #define DL_BOOT_COMPUTE_GOT(got) ((got) = dl_boot_got_pointer)
  73. #define DL_BOOT_COMPUTE_DYN(dpnt, got, load_addr) \
  74. ((dpnt) = dl_boot_ldso_dyn_pointer)
  75. /* We want want to apply all relocations in the interpreter during
  76. bootstrap. Because of this, we have to skip the interpreter
  77. relocations in _dl_parse_relocation_information(), see
  78. elfinterp.c. */
  79. #define DL_SKIP_BOOTSTRAP_RELOC(SYMTAB, INDEX, STRTAB) 0
  80. #if defined(__NR_pread) || defined(__NR_pread64)
  81. #define _DL_PREAD(FD, BUF, SIZE, OFFSET) \
  82. (_dl_pread((FD), (BUF), (SIZE), (OFFSET)))
  83. #endif
  84. /* We want to return to dlsym() a function descriptor if the symbol
  85. turns out to be a function. */
  86. #define DL_FIND_HASH_VALUE(TPNT, TYPE_CLASS, SYM) \
  87. (((TYPE_CLASS) & ELF_RTYPE_CLASS_DLSYM) \
  88. && ELF32_ST_TYPE((SYM)->st_info) == STT_FUNC \
  89. ? _dl_funcdesc_for ((void *)DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value), \
  90. (TPNT)->loadaddr.got_value) \
  91. : (void*)DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value))
  92. #define DL_GET_READY_TO_RUN_EXTRA_PARMS \
  93. , struct elf32_fdpic_loadmap *dl_boot_progmap, Elf32_Addr dl_boot_got_pointer
  94. #define DL_GET_READY_TO_RUN_EXTRA_ARGS \
  95. , dl_boot_progmap, dl_boot_got_pointer
  96. /* Define this to declare the library offset. */
  97. #define DL_DEF_LIB_OFFSET
  98. /* Define this to get the library offset. */
  99. #define DL_GET_LIB_OFFSET() 0
  100. /* Define this to set the library offset. */
  101. #define DL_SET_LIB_OFFSET(offset)
  102. /* Define this to get the real object's runtime address. */
  103. #define DL_GET_RUN_ADDR(loadaddr, mapaddr) (loadaddr)
  104. #ifdef __USE_GNU
  105. # include <link.h>
  106. #else
  107. # define __USE_GNU
  108. # include <link.h>
  109. # undef __USE_GNU
  110. #endif