OSDN Git Service

Merge remote-tracking branch 'origin/master' into prelink
[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 #define _FCNTL_H
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 #include <dlfcn.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
53 /* common align masks, if not specified by sysdep headers */
54 #ifndef ADDR_ALIGN
55 #define ADDR_ALIGN (_dl_pagesize - 1)
56 #endif
57
58 #ifndef PAGE_ALIGN
59 #define PAGE_ALIGN (~ADDR_ALIGN)
60 #endif
61
62 #ifndef OFFS_ALIGN
63 #define OFFS_ALIGN (PAGE_ALIGN & ~(1ul << (sizeof(_dl_pagesize) * 8 - 1)))
64 #endif
65
66 /* For INIT/FINI dependency sorting. */
67 struct init_fini_list {
68         struct init_fini_list *next;
69         struct elf_resolve *tpnt;
70 };
71
72 /* Global variables used within the shared library loader */
73 extern char *_dl_library_path;         /* Where we look for libraries */
74 extern char *_dl_preload;              /* Things to be loaded before the libs */
75 extern char *_dl_ldsopath;             /* Where the shared lib loader was found */
76 extern const char *_dl_progname;       /* The name of the executable being run */
77 extern size_t _dl_pagesize;            /* Store the page size for use later */
78 #ifdef __LDSO_PRELINK_SUPPORT__
79 extern char *_dl_trace_prelink;        /* Library for prelinking trace */
80 extern struct elf_resolve *_dl_trace_prelink_map;       /* Library map for prelinking trace */
81 #else
82 #define _dl_trace_prelink               0
83 #endif
84
85 #if defined(USE_TLS) && USE_TLS
86 extern void _dl_add_to_slotinfo (struct link_map  *l);
87 extern void ** __attribute__ ((const)) _dl_initial_error_catch_tsd (void);
88 #endif
89
90 #ifdef USE_TLS
91 void _dl_add_to_slotinfo (struct link_map  *l);
92 void ** __attribute__ ((const)) _dl_initial_error_catch_tsd (void);
93 #endif
94 #ifdef __SUPPORT_LD_DEBUG__
95 extern char *_dl_debug;
96 extern char *_dl_debug_symbols;
97 extern char *_dl_debug_move;
98 extern char *_dl_debug_reloc;
99 extern char *_dl_debug_detail;
100 extern char *_dl_debug_nofixups;
101 extern char *_dl_debug_bindings;
102 extern int   _dl_debug_file;
103 # define __dl_debug_dprint(fmt, args...) \
104         _dl_dprintf(_dl_debug_file, "%s:%i: " fmt, __FUNCTION__, __LINE__, ## args);
105 # define _dl_if_debug_dprint(fmt, args...) \
106         do { if (_dl_debug) __dl_debug_dprint(fmt, ## args); } while (0)
107 #else
108 # define __dl_debug_dprint(fmt, args...) do {} while (0)
109 # define _dl_if_debug_dprint(fmt, args...) do {} while (0)
110 # define _dl_debug_file 2
111 #endif /* __SUPPORT_LD_DEBUG__ */
112
113 #ifdef IS_IN_rtld
114 # ifdef __SUPPORT_LD_DEBUG__
115 #  define _dl_assert(expr)                                              \
116         do {                                                            \
117                 if (!(expr)) {                                          \
118                         __dl_debug_dprint("assert(%s)\n", #expr);       \
119                         _dl_exit(45);                                   \
120                 }                                                       \
121         } while (0)
122 # else
123 #  define _dl_assert(expr) ((void)0)
124 # endif
125 #else
126 # include <assert.h>
127 # define _dl_assert(expr) assert(expr)
128 #endif
129
130 #ifdef __SUPPORT_LD_DEBUG_EARLY__
131 # define _dl_debug_early(fmt, args...) __dl_debug_dprint(fmt, ## args)
132 #else
133 # define _dl_debug_early(fmt, args...) do {} while (0)
134 #endif /* __SUPPORT_LD_DEBUG_EARLY__ */
135
136 #ifndef NULL
137 #define NULL ((void *) 0)
138 #endif
139
140 extern void *_dl_malloc(size_t size);
141 extern void *_dl_calloc(size_t __nmemb, size_t __size);
142 extern void *_dl_realloc(void *__ptr, size_t __size);
143 extern void _dl_free(void *);
144 extern char *_dl_getenv(const char *symbol, char **envp);
145 extern void _dl_unsetenv(const char *symbol, char **envp);
146 extern char *_dl_strdup(const char *string);
147 extern void _dl_dprintf(int, const char *, ...);
148
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
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
160 #ifdef HAVE_DL_INLINES_H
161 #include <dl-inlines.h>
162 #endif
163
164 #else /* __ARCH_HAS_NO_SHARED__ */
165 #include <dl-defs.h>
166 #endif
167
168 #endif /* _LDSO_H_ */