ldso.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Copyright (C) 2000-2005 by Erik Andersen <andersen@codepoet.org>
  4. *
  5. * GNU Lesser General Public License version 2.1 or later.
  6. */
  7. #ifndef _LDSO_H
  8. #define _LDSO_H
  9. #include <features.h>
  10. /* Prepare for the case that `__builtin_expect' is not available. */
  11. #if defined __GNUC__ && __GNUC__ == 2 && __GNUC_MINOR__ < 96
  12. #define __builtin_expect(x, expected_value) (x)
  13. #endif
  14. #ifndef likely
  15. # define likely(x) __builtin_expect((!!(x)),1)
  16. #endif
  17. #ifndef unlikely
  18. # define unlikely(x) __builtin_expect((!!(x)),0)
  19. #endif
  20. #ifndef __LINUX_COMPILER_H
  21. #define __LINUX_COMPILER_H
  22. #endif
  23. /* Pull in compiler and arch stuff */
  24. #include <stdlib.h>
  25. #include <stdarg.h>
  26. #include <stddef.h> /* for ptrdiff_t */
  27. #include <stdbool.h>
  28. #define _FCNTL_H
  29. #include <bits/fcntl.h>
  30. #include <bits/wordsize.h>
  31. /* Pull in the arch specific type information */
  32. #include <sys/types.h>
  33. /* Pull in the arch specific page size */
  34. #include <bits/uClibc_page.h>
  35. /* Pull in the MIN macro */
  36. #include <sys/param.h>
  37. /* Pull in the ldso syscalls and string functions */
  38. #ifndef __ARCH_HAS_NO_SHARED__
  39. #include <dl-syscall.h>
  40. #include <dl-string.h>
  41. #include <dlfcn.h>
  42. /* Now the ldso specific headers */
  43. #include <dl-elf.h>
  44. #ifdef __UCLIBC_HAS_TLS__
  45. /* Defines USE_TLS */
  46. #include <tls.h>
  47. #endif
  48. #include <dl-hash.h>
  49. /* common align masks, if not specified by sysdep headers */
  50. #ifndef ADDR_ALIGN
  51. #define ADDR_ALIGN (_dl_pagesize - 1)
  52. #endif
  53. #ifndef PAGE_ALIGN
  54. #define PAGE_ALIGN (~ADDR_ALIGN)
  55. #endif
  56. #ifndef OFFS_ALIGN
  57. #define OFFS_ALIGN (PAGE_ALIGN & ~(1ul << (sizeof(_dl_pagesize) * 8 - 1)))
  58. #endif
  59. /* For INIT/FINI dependency sorting. */
  60. struct init_fini_list {
  61. struct init_fini_list *next;
  62. struct elf_resolve *tpnt;
  63. };
  64. /* Global variables used within the shared library loader */
  65. extern char *_dl_library_path; /* Where we look for libraries */
  66. extern char *_dl_preload; /* Things to be loaded before the libs */
  67. #ifdef __LDSO_SEARCH_INTERP_PATH__
  68. extern const char *_dl_ldsopath; /* Where the shared lib loader was found */
  69. #endif
  70. extern const char *_dl_progname; /* The name of the executable being run */
  71. extern size_t _dl_pagesize; /* Store the page size for use later */
  72. #ifdef __LDSO_PRELINK_SUPPORT__
  73. extern char *_dl_trace_prelink; /* Library for prelinking trace */
  74. extern struct elf_resolve *_dl_trace_prelink_map; /* Library map for prelinking trace */
  75. #else
  76. #define _dl_trace_prelink 0
  77. #endif
  78. #ifdef __DSBT__
  79. extern void **_dl_ldso_dsbt;
  80. #endif
  81. #if defined(USE_TLS) && USE_TLS
  82. extern void _dl_add_to_slotinfo (struct link_map *l);
  83. extern void ** __attribute__ ((const)) _dl_initial_error_catch_tsd (void);
  84. #endif
  85. #ifdef USE_TLS
  86. void _dl_add_to_slotinfo (struct link_map *l);
  87. void ** __attribute__ ((const)) _dl_initial_error_catch_tsd (void);
  88. #endif
  89. #ifdef __SUPPORT_LD_DEBUG__
  90. extern char *_dl_debug;
  91. extern char *_dl_debug_symbols;
  92. extern char *_dl_debug_move;
  93. extern char *_dl_debug_reloc;
  94. extern char *_dl_debug_detail;
  95. extern char *_dl_debug_nofixups;
  96. extern char *_dl_debug_bindings;
  97. extern int _dl_debug_file;
  98. # define __dl_debug_dprint(fmt, args...) \
  99. _dl_dprintf(_dl_debug_file, "%s:%i: " fmt, __func__, __LINE__, ## args);
  100. # define _dl_if_debug_dprint(fmt, args...) \
  101. do { if (_dl_debug) __dl_debug_dprint(fmt, ## args); } while (0)
  102. #else
  103. # define __dl_debug_dprint(fmt, args...) do {} while (0)
  104. # define _dl_if_debug_dprint(fmt, args...) do {} while (0)
  105. /* disabled on purpose, _dl_debug_file should be guarded by __SUPPORT_LD_DEBUG__
  106. # define _dl_debug_file 2*/
  107. #endif /* __SUPPORT_LD_DEBUG__ */
  108. #ifdef IS_IN_rtld
  109. # ifdef __SUPPORT_LD_DEBUG__
  110. # define _dl_assert(expr) \
  111. do { \
  112. if (!(expr)) { \
  113. __dl_debug_dprint("assert(%s)\n", #expr); \
  114. _dl_exit(45); \
  115. } \
  116. } while (0)
  117. # else
  118. # define _dl_assert(expr) ((void)0)
  119. # endif
  120. #else
  121. # include <assert.h>
  122. # define _dl_assert(expr) assert(expr)
  123. #endif
  124. #ifdef __SUPPORT_LD_DEBUG_EARLY__
  125. # define _dl_debug_early(fmt, args...) __dl_debug_dprint(fmt, ## args)
  126. #else
  127. # define _dl_debug_early(fmt, args...) do {} while (0)
  128. #endif /* __SUPPORT_LD_DEBUG_EARLY__ */
  129. #ifndef NULL
  130. #define NULL ((void *) 0)
  131. #endif
  132. extern void *_dl_malloc(size_t size);
  133. extern void *_dl_calloc(size_t __nmemb, size_t __size);
  134. extern void *_dl_realloc(void *__ptr, size_t __size);
  135. extern void _dl_free(void *);
  136. extern char *_dl_getenv(const char *symbol, char **envp);
  137. extern void _dl_unsetenv(const char *symbol, char **envp);
  138. #ifdef IS_IN_rtld
  139. extern char *_dl_strdup(const char *string);
  140. extern void _dl_dprintf(int, const char *, ...);
  141. #else
  142. # include <string.h>
  143. # define _dl_strdup strdup
  144. # include <stdio.h>
  145. # ifdef __USE_GNU
  146. # define _dl_dprintf dprintf
  147. # else
  148. # define _dl_dprintf(fd, fmt, args...) fprintf(stderr, fmt, ## args)
  149. # endif
  150. #endif
  151. #ifndef DL_GET_READY_TO_RUN_EXTRA_PARMS
  152. # define DL_GET_READY_TO_RUN_EXTRA_PARMS
  153. #endif
  154. #ifndef DL_GET_READY_TO_RUN_EXTRA_ARGS
  155. # define DL_GET_READY_TO_RUN_EXTRA_ARGS
  156. #endif
  157. extern void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
  158. ElfW(auxv_t) auxvt[AT_EGID + 1], char **envp, char **argv
  159. DL_GET_READY_TO_RUN_EXTRA_PARMS);
  160. #ifdef HAVE_DL_INLINES_H
  161. #include <dl-inlines.h>
  162. #endif
  163. #else /* __ARCH_HAS_NO_SHARED__ */
  164. #include <dl-defs.h>
  165. #endif
  166. #endif /* _LDSO_H */