OSDN Git Service

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