Update.
[platform/upstream/glibc.git] / sysdeps / generic / ldsodefs.h
1 /* Run-time dynamic linker data structures for loaded ELF shared objects.
2    Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #ifndef _LDSODEFS_H
21 #define _LDSODEFS_H     1
22
23 #include <features.h>
24
25 #include <stdbool.h>
26 #define __need_size_t
27 #define __need_NULL
28 #include <stddef.h>
29 #include <string.h>
30
31 #include <elf.h>
32 #include <dlfcn.h>
33 #include <fpu_control.h>
34 #include <sys/mman.h>
35 #include <link.h>
36 #include <dl-lookupcfg.h>
37 #include <bits/libc-lock.h>
38 #include <hp-timing.h>
39 #include <tls.h>
40
41 __BEGIN_DECLS
42
43 /* We use this macro to refer to ELF types independent of the native wordsize.
44    `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'.  */
45 #define ELFW(type)      _ElfW (ELF, __ELF_NATIVE_CLASS, type)
46
47 /* All references to the value of l_info[DT_PLTGOT],
48   l_info[DT_STRTAB], l_info[DT_SYMTAB], l_info[DT_RELA],
49   l_info[DT_REL], l_info[DT_JMPREL], and l_info[VERSYMIDX (DT_VERSYM)]
50   have to be accessed via the D_PTR macro.  The macro is needed since for
51   most architectures the entry is already relocated - but for some not
52   and we need to relocate at access time.  */
53 #ifdef DL_RO_DYN_SECTION
54 # define D_PTR(map,i) (map->i->d_un.d_ptr + map->l_addr)
55 #else
56 # define D_PTR(map,i) map->i->d_un.d_ptr
57 #endif
58
59 /* On some platforms more information than just the address of the symbol
60    is needed from the lookup functions.  In this case we return the whole
61    link map.  */
62 #ifdef DL_LOOKUP_RETURNS_MAP
63 typedef struct link_map *lookup_t;
64 # define LOOKUP_VALUE(map) map
65 # define LOOKUP_VALUE_ADDRESS(map) (map ? map->l_addr : 0)
66 #else
67 typedef ElfW(Addr) lookup_t;
68 # define LOOKUP_VALUE(map) map->l_addr
69 # define LOOKUP_VALUE_ADDRESS(address) address
70 #endif
71
72 /* on some architectures a pointer to a function is not just a pointer
73    to the actual code of the function but rather an architecture
74    specific descriptor. */
75 #ifndef ELF_FUNCTION_PTR_IS_SPECIAL
76 # define DL_SYMBOL_ADDRESS(map, ref) \
77  (void *) (LOOKUP_VALUE_ADDRESS (map) + ref->st_value)
78 # define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr))
79 # define DL_DT_INIT_ADDRESS(map, start) (start)
80 # define DL_DT_FINI_ADDRESS(map, start) (start)
81 #endif
82
83 /* Unmap a loaded object, called by _dl_close (). */
84 #ifndef DL_UNMAP_IS_SPECIAL
85 # define DL_UNMAP(map) \
86  __munmap ((void *) (map)->l_map_start,                                       \
87            (map)->l_map_end - (map)->l_map_start)
88 #endif
89
90 /* By default we do not need special support to initialize DSOs loaded
91    by statically linked binaries.  */
92 #ifndef DL_STATIC_INIT
93 # define DL_STATIC_INIT(map)
94 #endif
95
96 /* Reloc type classes as returned by elf_machine_type_class().
97    ELF_RTYPE_CLASS_PLT means this reloc should not be satisfied by
98    some PLT symbol, ELF_RTYPE_CLASS_COPY means this reloc should not be
99    satisfied by any symbol in the executable.  */
100 #define ELF_RTYPE_CLASS_PLT 1
101 #define ELF_RTYPE_CLASS_COPY 2
102
103 /* ELF uses the PF_x macros to specify the segment permissions, mmap
104    uses PROT_xxx.  In most cases the three macros have the values 1, 2,
105    and 3 but not in a matching order.  The following macros allows
106    converting from the PF_x values to PROT_xxx values.  */
107 #define PF_TO_PROT \
108   ((PROT_READ << (PF_R * 4))                                                  \
109    | (PROT_WRITE << (PF_W * 4))                                               \
110    | (PROT_EXEC << (PF_X * 4))                                                \
111    | ((PROT_READ | PROT_WRITE) << ((PF_R | PF_W) * 4))                        \
112    | ((PROT_READ | PROT_EXEC) << ((PF_R | PF_X) * 4))                         \
113    | ((PROT_WRITE | PROT_EXEC) << (PF_W | PF_X) * 4)                          \
114    | ((PROT_READ | PROT_WRITE | PROT_EXEC) << ((PF_R | PF_W | PF_X) * 4)))
115
116
117 /* For the version handling we need an array with only names and their
118    hash values.  */
119 struct r_found_version
120   {
121     const char *name;
122     ElfW(Word) hash;
123
124     int hidden;
125     const char *filename;
126   };
127
128 /* We want to cache information about the searches for shared objects.  */
129
130 enum r_dir_status { unknown, nonexisting, existing };
131
132 struct r_search_path_elem
133   {
134     /* This link is only used in the `all_dirs' member of `r_search_path'.  */
135     struct r_search_path_elem *next;
136
137     /* Strings saying where the definition came from.  */
138     const char *what;
139     const char *where;
140
141     /* Basename for this search path element.  The string must end with
142        a slash character.  */
143     const char *dirname;
144     size_t dirnamelen;
145
146     enum r_dir_status status[0];
147   };
148
149 struct r_strlenpair
150   {
151     const char *str;
152     size_t len;
153   };
154
155
156 /* A data structure for a simple single linked list of strings.  */
157 struct libname_list
158   {
159     const char *name;           /* Name requested (before search).  */
160     struct libname_list *next;  /* Link to next name for this object.  */
161     int dont_free;              /* Flag whether this element should be freed
162                                    if the object is not entirely unloaded.  */
163   };
164
165
166 /* Test whether given NAME matches any of the names of the given object.  */
167 static __inline int
168 __attribute__ ((unused))
169 _dl_name_match_p (const char *__name, struct link_map *__map)
170 {
171   int __found = strcmp (__name, __map->l_name) == 0;
172   struct libname_list *__runp = __map->l_libname;
173
174   while (! __found && __runp != NULL)
175     if (strcmp (__name, __runp->name) == 0)
176       __found = 1;
177     else
178       __runp = __runp->next;
179
180   return __found;
181 }
182
183 /* Function used as argument for `_dl_receive_error' function.  The
184    arguments are the error code, error string, and the objname the
185    error occurred in.  */
186 typedef void (*receiver_fct) (int, const char *, const char *);
187 \f
188 /* Internal functions of the run-time dynamic linker.
189    These can be accessed if you link again the dynamic linker
190    as a shared library, as in `-lld' or `/lib/ld.so' explicitly;
191    but are not normally of interest to user programs.
192
193    The `-ldl' library functions in <dlfcn.h> provide a simple
194    user interface to run-time dynamic linking.  */
195
196
197 #ifndef SHARED
198 # define EXTERN extern
199 # define GL(name) _##name
200 #else
201 # define EXTERN
202 # ifdef IS_IN_rtld
203 #  define GL(name) _rtld_local._##name
204 # else
205 #  define GL(name) _rtld_global._##name
206 # endif
207 struct rtld_global
208 {
209 #endif
210   /* Don't change the order of the following elements.  'dl_loaded'
211      must remain the first element.  Forever.  */
212
213   /* And a pointer to the map for the main map.  */
214   EXTERN struct link_map *_dl_loaded;
215   /* Number of object in the _dl_loaded list.  */
216   EXTERN unsigned int _dl_nloaded;
217   /* Array representing global scope.  */
218   EXTERN struct r_scope_elem *_dl_global_scope[2];
219   /* Direct pointer to the searchlist of the main object.  */
220   EXTERN struct r_scope_elem *_dl_main_searchlist;
221   /* Copy of the content of `_dl_main_searchlist'.  */
222   EXTERN struct r_scope_elem _dl_initial_searchlist;
223   /* This is zero at program start to signal that the global scope map is
224      allocated by rtld.  Later it keeps the size of the map.  It might be
225      reset if in _dl_close if the last global object is removed.  */
226   EXTERN size_t _dl_global_scope_alloc;
227
228   /* If nonzero the appropriate debug information is printed.  */
229   EXTERN int _dl_debug_mask;
230 #define DL_DEBUG_LIBS       (1 << 0)
231 #define DL_DEBUG_IMPCALLS   (1 << 1)
232 #define DL_DEBUG_BINDINGS   (1 << 2)
233 #define DL_DEBUG_SYMBOLS    (1 << 3)
234 #define DL_DEBUG_VERSIONS   (1 << 4)
235 #define DL_DEBUG_RELOC      (1 << 5)
236 #define DL_DEBUG_FILES      (1 << 6)
237 #define DL_DEBUG_STATISTICS (1 << 7)
238 /* These two are used only internally.  */
239 #define DL_DEBUG_HELP       (1 << 8)
240 #define DL_DEBUG_PRELINK    (1 << 9)
241
242   /* Cached value of `getpagesize ()'.  */
243   EXTERN size_t _dl_pagesize;
244
245   /* During the program run we must not modify the global data of
246      loaded shared object simultanously in two threads.  Therefore we
247      protect `_dl_open' and `_dl_close' in dl-close.c.
248
249      This must be a recursive lock since the initializer function of
250      the loaded object might as well require a call to this function.
251      At this time it is not anymore a problem to modify the tables.  */
252   __libc_lock_define_recursive (EXTERN, _dl_load_lock)
253
254   /* OS version.  */
255   EXTERN unsigned int _dl_osversion;
256   /* Platform name.  */
257   EXTERN const char *_dl_platform;
258   EXTERN size_t _dl_platformlen;
259
260 #ifndef MAP_ANON
261   /* File descriptor referring to the zero-fill device.  */
262   EXTERN int _dl_zerofd;
263 #endif
264
265   /* CLK_TCK as reported by the kernel.  */
266   EXTERN int _dl_clktck;
267
268   /* If nonzero print warnings messages.  */
269   EXTERN int _dl_verbose;
270
271   /* Do we do lazy relocations?  */
272   EXTERN int _dl_lazy;
273
274   /* Nonzero if runtime lookups should not update the .got/.plt.  */
275   EXTERN int _dl_bind_not;
276
277   /* Nonzero if references should be treated as weak during runtime
278      linking.  */
279   EXTERN int _dl_dynamic_weak;
280
281   /* Default floating-point control word.  */
282   EXTERN fpu_control_t _dl_fpu_control;
283
284   /* The object to be initialized first.  */
285   EXTERN struct link_map *_dl_initfirst;
286
287 #if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL
288   /* Start time on CPU clock.  */
289   EXTERN hp_timing_t _dl_cpuclock_offset;
290
291   /* Overhead of a high-precision timing measurement.  */
292   EXTERN hp_timing_t _dl_hp_timing_overhead;
293 #endif
294
295 #ifdef USE_TLS
296   /* Highest dtv index currently needed.  */
297   EXTERN size_t _dl_tls_max_dtv_idx;
298   /* Flag signalling whether there are gaps in the module ID allocation.  */
299   EXTERN bool _dl_tls_dtv_gaps;
300   /* Information about the dtv slots.  */
301   EXTERN struct dtv_slotinfo_list
302   {
303     size_t len;
304     struct dtv_slotinfo_list *next;
305     struct dtv_slotinfo
306     {
307       size_t gen;
308       struct link_map *map;
309     } slotinfo[0];
310   } *_dl_tls_dtv_slotinfo_list;
311   /* Number of modules in the static TLS block.  */
312   EXTERN size_t _dl_tls_static_nelem;
313   /* Size of the static TLS block.  */
314   EXTERN size_t _dl_tls_static_size;
315   /* Alignment requirement of the static TLS block.  */
316   EXTERN size_t _dl_tls_static_align;
317
318 /* Number of additional entries in the slotinfo array of each slotinfo
319    list element.  A large number makes it almost certain take we never
320    have to iterate beyond the first element in the slotinfo list.  */
321 # define TLS_SLOTINFO_SURPLUS (62)
322
323 /* Number of additional slots in the dtv allocated.  */
324 # define DTV_SURPLUS    (14)
325
326   /* True if the dtv for the initial thread was malloc()ed.  */
327   EXTERN bool _dl_initial_dtv_malloced;
328   /* Generation counter for the dtv.  */
329   EXTERN size_t _dl_tls_generation;
330 #endif
331
332   /* Name of the shared object to be profiled (if any).  */
333   EXTERN const char *_dl_profile;
334   /* Map of shared object to be profiled.  */
335   EXTERN struct link_map *_dl_profile_map;
336   /* Filename of the output file.  */
337   EXTERN const char *_dl_profile_output;
338   /* Map of shared object to be prelink traced.  */
339   EXTERN struct link_map *_dl_trace_prelink_map;
340   /* Name of the object we want to trace the prelinking.  */
341   EXTERN const char *_dl_trace_prelink;
342
343   /* Expected cache ID.  */
344   EXTERN int _dl_correct_cache_id;
345
346   /* Counters for the number of relocations performed.  */
347   EXTERN unsigned long int _dl_num_relocations;
348   EXTERN unsigned long int _dl_num_cache_relocations;
349
350   /* Mask for hardware capabilities that are available.  */
351   EXTERN unsigned long int _dl_hwcap;
352
353   /* Mask for important hardware capabilities we honour. */
354   EXTERN unsigned long int _dl_hwcap_mask;
355
356   /* Names of shared object for which the RPATH should be ignored.  */
357   EXTERN const char *_dl_inhibit_rpath;
358
359   /* Location of the binary.  */
360   EXTERN const char *_dl_origin_path;
361
362   /* List of search directories.  */
363   EXTERN struct r_search_path_elem *_dl_all_dirs;
364   EXTERN struct r_search_path_elem *_dl_init_all_dirs;
365
366   /* File descriptor to write debug messages to.  */
367   EXTERN int _dl_debug_fd;
368
369   /* Get architecture specific definitions.  */
370 #define PROCINFO_DECL
371 #include <dl-procinfo.c>
372
373   /* Structure describing the dynamic linker itself.  */
374   EXTERN struct link_map _dl_rtld_map;
375 #ifdef SHARED
376 };
377 extern struct rtld_global _rtld_global;
378 # ifdef IS_IN_rtld
379 #  ifdef HAVE_VISIBILITY_ATTRIBUTE
380 #   ifdef HAVE_SDATA_SECTION
381 #    define __rtld_local_attribute__ \
382             __attribute__ ((visibility ("hidden"), section (".sdata")))
383 #   else
384 #    define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
385 #   endif
386 #  else
387 #   define __rtld_local_attribute__
388 #  endif
389 extern struct rtld_global _rtld_local __rtld_local_attribute__;
390 # endif
391 #endif
392 #undef EXTERN
393
394 /* Parameters passed to the dynamic linker.  */
395 extern int _dl_argc attribute_hidden;
396 extern char **_dl_argv;
397 #ifdef IS_IN_rtld
398 extern char **_dl_argv_internal attribute_hidden;
399 # define rtld_progname (INTUSE(_dl_argv)[0])
400 #else
401 # define rtld_progname _dl_argv[0]
402 #endif
403
404 /* The array with message we print as a last resort.  */
405 extern const char _dl_out_of_memory[];
406 #ifdef IS_IN_rtld
407 /* XXX #ifdef should go away.  */
408 extern const char _dl_out_of_memory_internal[] attribute_hidden;
409 #endif
410
411
412 /* OS-dependent function to open the zero-fill device.  */
413 extern int _dl_sysdep_open_zero_fill (void); /* dl-sysdep.c */
414
415
416 /* Write message on the debug file descriptor.  The parameters are
417    interpreted as for a `printf' call.  All the lines start with a
418    tag showing the PID.  */
419 extern void _dl_debug_printf (const char *fmt, ...)
420      __attribute__ ((__format__ (__printf__, 1, 2)));
421 extern void _dl_debug_printf_internal (const char *fmt, ...)
422      __attribute__ ((__format__ (__printf__, 1, 2)));
423
424 /* Write message on the debug file descriptor.  The parameters are
425    interpreted as for a `printf' call.  All the lines buf the first
426    start with a tag showing the PID.  */
427 extern void _dl_debug_printf_c (const char *fmt, ...)
428      __attribute__ ((__format__ (__printf__, 1, 2)));
429
430
431 /* Write a message on the specified descriptor FD.  The parameters are
432    interpreted as for a `printf' call.  */
433 extern void _dl_dprintf (int fd, const char *fmt, ...)
434      __attribute__ ((__format__ (__printf__, 2, 3)));
435
436 /* Write a message on the specified descriptor standard output.  The
437    parameters are interpreted as for a `printf' call.  */
438 #define _dl_printf(fmt, args...) \
439   _dl_dprintf (STDOUT_FILENO, fmt, ##args)
440
441 /* Write a message on the specified descriptor standard error.  The
442    parameters are interpreted as for a `printf' call.  */
443 #define _dl_error_printf(fmt, args...) \
444   _dl_dprintf (STDERR_FILENO, fmt, ##args)
445
446 /* Write a message on the specified descriptor standard error and exit
447    the program.  The parameters are interpreted as for a `printf' call.  */
448 #define _dl_fatal_printf(fmt, args...) \
449   do                                                                          \
450     {                                                                         \
451       _dl_dprintf (STDERR_FILENO, fmt, ##args);                               \
452       _exit (127);                                                            \
453     }                                                                         \
454   while (1)
455
456
457 /* This function is called by all the internal dynamic linker functions
458    when they encounter an error.  ERRCODE is either an `errno' code or
459    zero; OBJECT is the name of the problematical shared object, or null if
460    it is a general problem; ERRSTRING is a string describing the specific
461    problem.  */
462 extern void _dl_signal_error (int errcode, const char *object,
463                               const char *occurred, const char *errstring)
464      internal_function
465      __attribute__ ((__noreturn__));
466 extern void _dl_signal_error_internal (int errcode, const char *object,
467                                        const char *occurred,
468                                        const char *errstring)
469      internal_function
470      __attribute__ ((__noreturn__));
471
472 /* Like _dl_signal_error, but may return when called in the context of
473    _dl_receive_error.  */
474 extern void _dl_signal_cerror (int errcode, const char *object,
475                                const char *occation, const char *errstring)
476      internal_function;
477
478 /* Call OPERATE, receiving errors from `dl_signal_cerror'.  Unlike
479    `_dl_catch_error' the operation is resumed after the OPERATE
480    function returns.
481    ARGS is passed as argument to OPERATE.  */
482 extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *),
483                                void *args)
484      internal_function;
485
486
487 /* Open the shared object NAME and map in its segments.
488    LOADER's DT_RPATH is used in searching for NAME.
489    If the object is already opened, returns its existing map.
490    For preloaded shared objects PRELOADED is set to a non-zero
491    value to allow additional security checks.  */
492 extern struct link_map *_dl_map_object (struct link_map *loader,
493                                         const char *name, int preloaded,
494                                         int type, int trace_mode, int mode)
495      internal_function;
496 extern struct link_map *_dl_map_object_internal (struct link_map *loader,
497                                                  const char *name,
498                                                  int preloaded,
499                                                  int type, int trace_mode,
500                                                  int mode)
501      internal_function;
502
503 /* Call _dl_map_object on the dependencies of MAP, and set up
504    MAP->l_searchlist.  PRELOADS points to a vector of NPRELOADS previously
505    loaded objects that will be inserted into MAP->l_searchlist after MAP
506    but before its dependencies.  */
507 extern void _dl_map_object_deps (struct link_map *map,
508                                  struct link_map **preloads,
509                                  unsigned int npreloads, int trace_mode,
510                                  int open_mode)
511      internal_function;
512 extern void _dl_map_object_deps_internal (struct link_map *map,
513                                           struct link_map **preloads,
514                                           unsigned int npreloads,
515                                           int trace_mode, int open_mode)
516      internal_function;
517
518 /* Cache the locations of MAP's hash table.  */
519 extern void _dl_setup_hash (struct link_map *map) internal_function;
520
521
522 /* Search loaded objects' symbol tables for a definition of the symbol
523    referred to by UNDEF.  *SYM is the symbol table entry containing the
524    reference; it is replaced with the defining symbol, and the base load
525    address of the defining object is returned.  SYMBOL_SCOPE is a
526    null-terminated list of object scopes to search; each object's
527    l_searchlist (i.e. the segment of the dependency tree starting at that
528    object) is searched in turn.  REFERENCE_NAME should name the object
529    containing the reference; it is used in error messages.
530    TYPE_CLASS describes the type of symbol we are looking for.  */
531 extern lookup_t _dl_lookup_symbol (const char *undef,
532                                    struct link_map *undef_map,
533                                    const ElfW(Sym) **sym,
534                                    struct r_scope_elem *symbol_scope[],
535                                    int type_class, int explicit)
536      internal_function;
537 extern lookup_t _dl_lookup_symbol_internal (const char *undef,
538                                             struct link_map *undef_map,
539                                             const ElfW(Sym) **sym,
540                                             struct r_scope_elem *symbol_scope[],
541                                             int type_class, int explicit)
542      internal_function;
543
544 /* Lookup versioned symbol.  */
545 extern lookup_t _dl_lookup_versioned_symbol (const char *undef,
546                                              struct link_map *undef_map,
547                                              const ElfW(Sym) **sym,
548                                              struct r_scope_elem *symbol_scope[],
549                                              const struct r_found_version *version,
550                                              int type_class, int explicit)
551      internal_function;
552 extern lookup_t _dl_lookup_versioned_symbol_internal (const char *undef,
553                                                       struct link_map *undef_map,
554                                                       const ElfW(Sym) **sym,
555                                                       struct r_scope_elem *symbol_scope[],
556                                                       const struct r_found_version *version,
557                                                       int type_class,
558                                                       int explicit)
559      internal_function;
560
561 /* For handling RTLD_NEXT we must be able to skip shared objects.  */
562 extern lookup_t _dl_lookup_symbol_skip (const char *undef,
563                                         struct link_map *undef_map,
564                                         const ElfW(Sym) **sym,
565                                         struct r_scope_elem *symbol_scope[],
566                                         struct link_map *skip_this)
567      internal_function;
568
569 /* For handling RTLD_NEXT with versioned symbols we must be able to
570    skip shared objects.  */
571 extern lookup_t _dl_lookup_versioned_symbol_skip (const char *undef,
572                                                   struct link_map *undef_map,
573                                                   const ElfW(Sym) **sym,
574                                                   struct r_scope_elem *symbol_scope[],
575                                                   const struct r_found_version *version,
576                                                   struct link_map *skip_this)
577      internal_function;
578
579 /* Look up symbol NAME in MAP's scope and return its run-time address.  */
580 extern ElfW(Addr) _dl_symbol_value (struct link_map *map, const char *name)
581      internal_function;
582
583 /* Allocate a `struct link_map' for a new object being loaded,
584    and enter it into the _dl_main_map list.  */
585 extern struct link_map *_dl_new_object (char *realname, const char *libname,
586                                         int type, struct link_map *loader)
587      internal_function;
588
589 /* Relocate the given object (if it hasn't already been).
590    SCOPE is passed to _dl_lookup_symbol in symbol lookups.
591    If LAZY is nonzero, don't relocate its PLT.  */
592 extern void _dl_relocate_object (struct link_map *map,
593                                  struct r_scope_elem *scope[],
594                                  int lazy, int consider_profiling);
595 extern void _dl_relocate_object_internal (struct link_map *map,
596                                           struct r_scope_elem *scope[],
597                                           int lazy, int consider_profiling);
598
599 /* Call _dl_signal_error with a message about an unhandled reloc type.
600    TYPE is the result of ELFW(R_TYPE) (r_info), i.e. an R_<CPU>_* value.
601    PLT is nonzero if this was a PLT reloc; it just affects the message.  */
602 extern void _dl_reloc_bad_type (struct link_map *map,
603                                 unsigned int type, int plt)
604      internal_function __attribute__ ((__noreturn__));
605
606 /* Resolve conflicts if prelinking.  */
607 extern void _dl_resolve_conflicts (struct link_map *l,
608                                    ElfW(Rela) *conflict,
609                                    ElfW(Rela) *conflictend);
610
611 /* Check the version dependencies of all objects available through
612    MAP.  If VERBOSE print some more diagnostics.  */
613 extern int _dl_check_all_versions (struct link_map *map, int verbose,
614                                    int trace_mode)
615      internal_function;
616
617 /* Check the version dependencies for MAP.  If VERBOSE print some more
618    diagnostics.  */
619 extern int _dl_check_map_versions (struct link_map *map, int verbose,
620                                    int trace_mode)
621      internal_function;
622
623 /* Initialize the object in SCOPE by calling the constructors with
624    ARGC, ARGV, and ENV as the parameters.  */
625 extern void _dl_init (struct link_map *main_map, int argc, char **argv,
626                       char **env) internal_function;
627
628 /* Call the finalizer functions of all shared objects whose
629    initializer functions have completed.  */
630 extern void _dl_fini (void) internal_function;
631
632 /* The dynamic linker calls this function before and having changing
633    any shared object mappings.  The `r_state' member of `struct r_debug'
634    says what change is taking place.  This function's address is
635    the value of the `r_brk' member.  */
636 extern void _dl_debug_state (void);
637 extern void _dl_debug_state_internal (void) attribute_hidden;
638
639 /* Initialize `struct r_debug' if it has not already been done.  The
640    argument is the run-time load address of the dynamic linker, to be put
641    in the `r_ldbase' member.  Returns the address of the structure.  */
642 extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase)
643      internal_function;
644
645 /* Initialize the basic data structure for the search paths.  */
646 extern void _dl_init_paths (const char *library_path) internal_function;
647
648 /* Gather the information needed to install the profiling tables and start
649    the timers.  */
650 extern void _dl_start_profile (struct link_map *map, const char *output_dir)
651      internal_function;
652 extern void _dl_start_profile_internal (struct link_map *map,
653                                         const char *output_dir)
654      internal_function;
655
656 /* The actual functions used to keep book on the calls.  */
657 extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc);
658 extern void _dl_mcount_internal (ElfW(Addr) frompc, ElfW(Addr) selfpc)
659      attribute_hidden;
660
661 /* This function is simply a wrapper around the _dl_mcount function
662    which does not require a FROMPC parameter since this is the
663    calling function.  */
664 extern void _dl_mcount_wrapper (void *selfpc);
665
666 /* Show the members of the auxiliary array passed up from the kernel.  */
667 extern void _dl_show_auxv (void) internal_function;
668
669 /* Return all environment variables starting with `LD_', one after the
670    other.  */
671 extern char *_dl_next_ld_env_entry (char ***position) internal_function;
672
673 /* Return an array with the names of the important hardware capabilities.  */
674 extern const struct r_strlenpair *_dl_important_hwcaps (const char *platform,
675                                                         size_t paltform_len,
676                                                         size_t *sz,
677                                                         size_t *max_capstrlen)
678      internal_function;
679
680 /* Look up NAME in ld.so.cache and return the file name stored there,
681    or null if none is found.  */
682 extern const char *_dl_load_cache_lookup (const char *name)
683      internal_function;
684
685 /* If the system does not support MAP_COPY we cannot leave the file open
686    all the time since this would create problems when the file is replaced.
687    Therefore we provide this function to close the file and open it again
688    once needed.  */
689 extern void _dl_unload_cache (void);
690 extern void _dl_unload_cache_internal (void);
691
692 /* System-dependent function to read a file's whole contents in the
693    most convenient manner available.  *SIZEP gets the size of the
694    file.  On error MAP_FAILED is returned.  */
695 extern void *_dl_sysdep_read_whole_file (const char *file, size_t *sizep,
696                                          int prot)
697      internal_function;
698
699 /* System-specific function to do initial startup for the dynamic linker.
700    After this, file access calls and getenv must work.  This is responsible
701    for setting __libc_enable_secure if we need to be secure (e.g. setuid),
702    and for setting _dl_argc and _dl_argv, and then calling _dl_main.  */
703 extern ElfW(Addr) _dl_sysdep_start (void **start_argptr,
704                                     void (*dl_main) (const ElfW(Phdr) *phdr,
705                                                      ElfW(Word) phnum,
706                                                      ElfW(Addr) *user_entry));
707
708 extern void _dl_sysdep_start_cleanup (void)
709      internal_function;
710
711
712 /* Determine next available module ID.  */
713 extern size_t _dl_next_tls_modid (void) internal_function;
714
715 /* Calculate offset of the TLS blocks in the static TLS block.  */
716 extern void _dl_determine_tlsoffset (void) internal_function;
717
718 /* Allocate memory for static TLS block and dtv.  */
719 extern void *_dl_allocate_tls (void) internal_function;
720 extern void *_dl_allocate_tls_internal (void) internal_function;
721
722 /* Deallocate memory allocated with _dl_allocate_tls.  */
723 extern void _dl_deallocate_tls (void *tcb) internal_function;
724
725 /* Return the symbol address given the map of the module it is in and
726    the symbol record.  */
727 extern void *_dl_tls_symaddr (struct link_map *map, const ElfW(Sym) *ref)
728      internal_function;
729
730 __END_DECLS
731
732 #endif /* ldsodefs.h */