ldso.h 5.1 KB

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