ldso.h 5.1 KB

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