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