ldso.h 4.8 KB

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