OSDN Git Service

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