Update.
[glibc.git] / elf / rtld.c
blob0c8bba3c7c6c5d63f545ad708529b597577c0b8b
1 /* Run time dynamic linker.
2 Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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. */
20 #include <errno.h>
21 #include <fcntl.h>
22 #include <stdbool.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <sys/mman.h> /* Check if MAP_ANON is defined. */
27 #include <sys/param.h>
28 #include <sys/stat.h>
29 #include <ldsodefs.h>
30 #include <stdio-common/_itoa.h>
31 #include <entry.h>
32 #include <fpu_control.h>
33 #include <hp-timing.h>
34 #include <bits/libc-lock.h>
35 #include "dynamic-link.h"
36 #include "dl-librecon.h"
37 #include <unsecvars.h>
38 #include <dl-cache.h>
39 #include <dl-procinfo.h>
41 #include <assert.h>
43 /* Helper function to handle errors while resolving symbols. */
44 static void print_unresolved (int errcode, const char *objname,
45 const char *errsting);
47 /* Helper function to handle errors when a version is missing. */
48 static void print_missing_version (int errcode, const char *objname,
49 const char *errsting);
51 /* Print the various times we collected. */
52 static void print_statistics (void);
54 /* This is a list of all the modes the dynamic loader can be in. */
55 enum mode { normal, list, verify, trace };
57 /* Process all environments variables the dynamic linker must recognize.
58 Since all of them start with `LD_' we are a bit smarter while finding
59 all the entries. */
60 static void process_envvars (enum mode *modep);
62 int _dl_argc attribute_hidden;
63 char **_dl_argv = NULL;
64 INTDEF(_dl_argv)
66 /* Nonzero if we were run directly. */
67 unsigned int _dl_skip_args attribute_hidden;
69 /* Set nonzero during loading and initialization of executable and
70 libraries, cleared before the executable's entry point runs. This
71 must not be initialized to nonzero, because the unused dynamic
72 linker loaded in for libc.so's "ld.so.1" dep will provide the
73 definition seen by libc.so's initializer; that value must be zero,
74 and will be since that dynamic linker's _dl_start and dl_main will
75 never be called. */
76 int _dl_starting_up = 0;
77 INTVARDEF(_dl_starting_up)
79 /* This is the structure which defines all variables global to ld.so
80 (except those which cannot be added for some reason). */
81 struct rtld_global _rtld_global =
83 /* Get architecture specific initializer. */
84 #include <dl-procinfo.c>
85 ._dl_debug_fd = STDERR_FILENO,
86 #if 1
87 /* XXX I know about at least one case where we depend on the old
88 weak behavior (it has to do with librt). Until we get DSO
89 groups implemented we have to make this the default.
90 Bummer. --drepper */
91 ._dl_dynamic_weak = 1,
92 #endif
93 ._dl_lazy = 1,
94 ._dl_fpu_control = _FPU_DEFAULT,
95 ._dl_correct_cache_id = _DL_CACHE_DEFAULT_ID,
96 ._dl_hwcap_mask = HWCAP_IMPORTANT,
97 ._dl_load_lock = _LIBC_LOCK_RECURSIVE_INITIALIZER
99 strong_alias (_rtld_global, _rtld_local);
101 static void dl_main (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
102 ElfW(Addr) *user_entry);
104 static struct libname_list _dl_rtld_libname;
105 static struct libname_list _dl_rtld_libname2;
107 /* We expect less than a second for relocation. */
108 #ifdef HP_SMALL_TIMING_AVAIL
109 # undef HP_TIMING_AVAIL
110 # define HP_TIMING_AVAIL HP_SMALL_TIMING_AVAIL
111 #endif
113 /* Variable for statistics. */
114 #ifndef HP_TIMING_NONAVAIL
115 static hp_timing_t rtld_total_time;
116 static hp_timing_t relocate_time;
117 static hp_timing_t load_time;
118 static hp_timing_t start_time;
119 #endif
121 /* Additional definitions needed by TLS initialization. */
122 #ifdef TLS_INIT_HELPER
123 TLS_INIT_HELPER
124 #endif
126 /* Before ld.so is relocated we must not access variables which need
127 relocations. This means variables which are exported. Variables
128 declared as static are fine. If we can mark a variable hidden this
129 is fine, too. The latter is impotant here. We can avoid setting
130 up a temporary link map for ld.so if we can mark _rtld_global as
131 hidden. */
132 #if defined PI_STATIC_AND_HIDDEN && defined HAVE_HIDDEN \
133 && defined HAVE_VISIBILITY_ATTRIBUTE
134 # define DONT_USE_BOOTSTRAP_MAP 1
135 #endif
137 #ifdef DONT_USE_BOOTSTRAP_MAP
138 static ElfW(Addr) _dl_start_final (void *arg);
139 #else
140 static ElfW(Addr) _dl_start_final (void *arg,
141 struct link_map *bootstrap_map_p);
142 #endif
144 #ifdef RTLD_START
145 RTLD_START
146 #else
147 # error "sysdeps/MACHINE/dl-machine.h fails to define RTLD_START"
148 #endif
150 #ifndef VALIDX
151 # define VALIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \
152 + DT_EXTRANUM + DT_VALTAGIDX (tag))
153 #endif
154 #ifndef ADDRIDX
155 # define ADDRIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \
156 + DT_EXTRANUM + DT_VALNUM + DT_ADDRTAGIDX (tag))
157 #endif
159 /* This is the second half of _dl_start (below). It can be inlined safely
160 under DONT_USE_BOOTSTRAP_MAP, where it is careful not to make any GOT
161 references. When the tools don't permit us to avoid using a GOT entry
162 for _dl_rtld_global (no attribute_hidden support), we must make sure
163 this function is not inlined (see below). */
165 #ifdef DONT_USE_BOOTSTRAP_MAP
166 static inline ElfW(Addr) __attribute__ ((always_inline))
167 _dl_start_final (void *arg)
168 #else
169 static ElfW(Addr) __attribute__ ((noinline))
170 _dl_start_final (void *arg, struct link_map *bootstrap_map_p)
171 #endif
173 ElfW(Addr) start_addr;
174 extern char _begin[] attribute_hidden;
175 extern char _end[] attribute_hidden;
177 if (HP_TIMING_AVAIL)
179 /* If it hasn't happen yet record the startup time. */
180 if (! HP_TIMING_INLINE)
181 HP_TIMING_NOW (start_time);
183 /* Initialize the timing functions. */
184 HP_TIMING_DIFF_INIT ();
187 /* Transfer data about ourselves to the permanent link_map structure. */
188 #ifndef DONT_USE_BOOTSTRAP_MAP
189 GL(dl_rtld_map).l_addr = bootstrap_map_p->l_addr;
190 GL(dl_rtld_map).l_ld = bootstrap_map_p->l_ld;
191 memcpy (GL(dl_rtld_map).l_info, bootstrap_map_p->l_info,
192 sizeof GL(dl_rtld_map).l_info);
193 GL(dl_rtld_map).l_mach = bootstrap_map_p->l_mach;
194 #endif
195 _dl_setup_hash (&GL(dl_rtld_map));
196 GL(dl_rtld_map).l_opencount = 1;
197 GL(dl_rtld_map).l_map_start = (ElfW(Addr)) _begin;
198 GL(dl_rtld_map).l_map_end = (ElfW(Addr)) _end;
199 /* Copy the TLS related data if necessary. */
200 #if USE_TLS && !defined DONT_USE_BOOTSTRAP_MAP
201 # ifdef HAVE___THREAD
202 assert (bootstrap_map_p->l_tls_modid != 0);
203 # else
204 if (bootstrap_map_p->l_tls_modid != 0)
205 # endif
207 GL(dl_rtld_map).l_tls_blocksize = bootstrap_map_p->l_tls_blocksize;
208 GL(dl_rtld_map).l_tls_align = bootstrap_map_p->l_tls_align;
209 GL(dl_rtld_map).l_tls_initimage_size
210 = bootstrap_map_p->l_tls_initimage_size;
211 GL(dl_rtld_map).l_tls_initimage = bootstrap_map_p->l_tls_initimage;
212 GL(dl_rtld_map).l_tls_offset = bootstrap_map_p->l_tls_offset;
213 GL(dl_rtld_map).l_tls_modid = 1;
214 GL(dl_rtld_map).l_tls_tp_initialized
215 = bootstrap_map_p->l_tls_tp_initialized;
217 #endif
219 #if HP_TIMING_AVAIL
220 HP_TIMING_NOW (GL(dl_cpuclock_offset));
221 #endif
223 /* Call the OS-dependent function to set up life so we can do things like
224 file access. It will call `dl_main' (below) to do all the real work
225 of the dynamic linker, and then unwind our frame and run the user
226 entry point on the same stack we entered on. */
227 start_addr = _dl_sysdep_start (arg, &dl_main);
229 #ifndef HP_TIMING_NONAVAIL
230 if (HP_TIMING_AVAIL)
232 hp_timing_t end_time;
234 /* Get the current time. */
235 HP_TIMING_NOW (end_time);
237 /* Compute the difference. */
238 HP_TIMING_DIFF (rtld_total_time, start_time, end_time);
240 #endif
242 if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_STATISTICS, 0))
243 print_statistics ();
245 return start_addr;
248 static ElfW(Addr) __attribute_used__ internal_function
249 _dl_start (void *arg)
251 #ifdef DONT_USE_BOOTSTRAP_MAP
252 # define bootstrap_map GL(dl_rtld_map)
253 #else
254 struct link_map bootstrap_map;
255 #endif
256 #if !defined HAVE_BUILTIN_MEMSET || defined USE_TLS
257 size_t cnt;
258 #endif
259 #ifdef USE_TLS
260 ElfW(Ehdr) *ehdr;
261 ElfW(Phdr) *phdr;
262 dtv_t initdtv[3];
263 #endif
265 /* This #define produces dynamic linking inline functions for
266 bootstrap relocation instead of general-purpose relocation. */
267 #define RTLD_BOOTSTRAP
268 #define RESOLVE_MAP(sym, version, flags) \
269 ((*(sym))->st_shndx == SHN_UNDEF ? 0 : &bootstrap_map)
270 #define RESOLVE(sym, version, flags) \
271 ((*(sym))->st_shndx == SHN_UNDEF ? 0 : bootstrap_map.l_addr)
272 #include "dynamic-link.h"
274 if (HP_TIMING_INLINE && HP_TIMING_AVAIL)
275 HP_TIMING_NOW (start_time);
277 /* Partly clean the `bootstrap_map' structure up. Don't use
278 `memset' since it might not be built in or inlined and we cannot
279 make function calls at this point. Use '__builtin_memset' if we
280 know it is available. We do not have to clear the memory if we
281 do not have to use the temporary bootstrap_map. Global variables
282 are initialized to zero by default. */
283 #ifndef DONT_USE_BOOTSTRAP_MAP
284 # ifdef HAVE_BUILTIN_MEMSET
285 __builtin_memset (bootstrap_map.l_info, '\0', sizeof (bootstrap_map.l_info));
286 # else
287 for (cnt = 0;
288 cnt < sizeof (bootstrap_map.l_info) / sizeof (bootstrap_map.l_info[0]);
289 ++cnt)
290 bootstrap_map.l_info[cnt] = 0;
291 # endif
292 #endif
294 /* Figure out the run-time load address of the dynamic linker itself. */
295 bootstrap_map.l_addr = elf_machine_load_address ();
297 /* Read our own dynamic section and fill in the info array. */
298 bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic ();
299 elf_get_dynamic_info (&bootstrap_map);
301 #if USE_TLS
302 # if !defined HAVE___THREAD && !defined DONT_USE_BOOTSTRAP_MAP
303 /* Signal that we have not found TLS data so far. */
304 bootstrap_map.l_tls_modid = 0;
305 # endif
307 /* Get the dynamic linkers program header. */
308 ehdr = (ElfW(Ehdr) *) bootstrap_map.l_addr;
309 phdr = (ElfW(Phdr) *) (bootstrap_map.l_addr + ehdr->e_phoff);
310 for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
311 if (phdr[cnt].p_type == PT_TLS)
313 void *tlsblock;
314 size_t max_align = MAX (TLS_INIT_TCB_ALIGN, phdr[cnt].p_align);
315 char *p;
317 bootstrap_map.l_tls_blocksize = phdr[cnt].p_memsz;
318 bootstrap_map.l_tls_align = phdr[cnt].p_align;
319 assert (bootstrap_map.l_tls_blocksize != 0);
320 bootstrap_map.l_tls_initimage_size = phdr[cnt].p_filesz;
321 bootstrap_map.l_tls_initimage = (void *) (bootstrap_map.l_addr
322 + phdr[cnt].p_vaddr);
324 /* We can now allocate the initial TLS block. This can happen
325 on the stack. We'll get the final memory later when we
326 know all about the various objects loaded at startup
327 time. */
328 # if TLS_TCB_AT_TP
329 tlsblock = alloca (roundup (bootstrap_map.l_tls_blocksize,
330 TLS_INIT_TCB_ALIGN)
331 + TLS_INIT_TCB_SIZE
332 + max_align);
333 # elif TLS_DTV_AT_TP
334 tlsblock = alloca (roundup (TLS_INIT_TCB_SIZE,
335 bootstrap_map.l_tls_align)
336 + bootstrap_map.l_tls_blocksize
337 + max_align);
338 # else
339 /* In case a model with a different layout for the TCB and DTV
340 is defined add another #elif here and in the following #ifs. */
341 # error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
342 # endif
343 /* Align the TLS block. */
344 tlsblock = (void *) (((uintptr_t) tlsblock + max_align - 1)
345 & ~(max_align - 1));
347 /* Initialize the dtv. [0] is the length, [1] the generation
348 counter. */
349 initdtv[0].counter = 1;
350 initdtv[1].counter = 0;
352 /* Initialize the TLS block. */
353 # if TLS_TCB_AT_TP
354 initdtv[2].pointer = tlsblock;
355 # elif TLS_DTV_AT_TP
356 bootstrap_map.l_tls_offset = roundup (TLS_INIT_TCB_SIZE,
357 bootstrap_map.l_tls_align);
358 initdtv[2].pointer = (char *) tlsblock + bootstrap_map.l_tls_offset;
359 # else
360 # error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
361 # endif
362 p = __mempcpy (initdtv[2].pointer, bootstrap_map.l_tls_initimage,
363 bootstrap_map.l_tls_initimage_size);
364 # ifdef HAVE_BUILTIN_MEMSET
365 __builtin_memset (p, '\0', (bootstrap_map.l_tls_blocksize
366 - bootstrap_map.l_tls_initimage_size));
367 # else
369 size_t remaining = (bootstrap_map.l_tls_blocksize
370 - bootstrap_map.l_tls_initimage_size);
371 while (remaining-- > 0)
372 *p++ = '\0';
374 #endif
376 /* Install the pointer to the dtv. */
378 /* Initialize the thread pointer. */
379 # if TLS_TCB_AT_TP
380 bootstrap_map.l_tls_offset
381 = roundup (bootstrap_map.l_tls_blocksize, TLS_INIT_TCB_ALIGN);
383 INSTALL_DTV ((char *) tlsblock + bootstrap_map.l_tls_offset,
384 initdtv);
386 if (TLS_INIT_TP ((char *) tlsblock + bootstrap_map.l_tls_offset, 0)
387 != 0)
388 _dl_fatal_printf ("cannot setup thread-local storage\n");
389 # elif TLS_DTV_AT_TP
390 INSTALL_DTV (tlsblock, initdtv);
391 if (TLS_INIT_TP (tlsblock, 0) != 0)
392 _dl_fatal_printf ("cannot setup thread-local storage\n");
393 # else
394 # error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
395 # endif
397 /* So far this is module number one. */
398 bootstrap_map.l_tls_modid = 1;
399 /* The TP got initialized. */
400 bootstrap_map.l_tls_tp_initialized = 1;
402 /* There can only be one PT_TLS entry. */
403 break;
405 #endif /* use TLS */
407 #ifdef ELF_MACHINE_BEFORE_RTLD_RELOC
408 ELF_MACHINE_BEFORE_RTLD_RELOC (bootstrap_map.l_info);
409 #endif
411 if (bootstrap_map.l_addr || ! bootstrap_map.l_info[VALIDX(DT_GNU_PRELINKED)])
413 /* Relocate ourselves so we can do normal function calls and
414 data access using the global offset table. */
416 ELF_DYNAMIC_RELOCATE (&bootstrap_map, 0, 0);
419 /* Please note that we don't allow profiling of this object and
420 therefore need not test whether we have to allocate the array
421 for the relocation results (as done in dl-reloc.c). */
423 /* Now life is sane; we can call functions and access global data.
424 Set up to use the operating system facilities, and find out from
425 the operating system's program loader where to find the program
426 header table in core. Put the rest of _dl_start into a separate
427 function, that way the compiler cannot put accesses to the GOT
428 before ELF_DYNAMIC_RELOCATE. */
430 #ifdef DONT_USE_BOOTSTRAP_MAP
431 ElfW(Addr) entry = _dl_start_final (arg);
432 #else
433 ElfW(Addr) entry = _dl_start_final (arg, &bootstrap_map);
434 #endif
436 #ifndef ELF_MACHINE_START_ADDRESS
437 # define ELF_MACHINE_START_ADDRESS(map, start) (start)
438 #endif
440 return ELF_MACHINE_START_ADDRESS (GL(dl_loaded), entry);
446 /* Now life is peachy; we can do all normal operations.
447 On to the real work. */
449 /* Some helper functions. */
451 /* Arguments to relocate_doit. */
452 struct relocate_args
454 struct link_map *l;
455 int lazy;
458 struct map_args
460 /* Argument to map_doit. */
461 char *str;
462 /* Return value of map_doit. */
463 struct link_map *main_map;
466 /* Arguments to version_check_doit. */
467 struct version_check_args
469 int doexit;
470 int dotrace;
473 static void
474 relocate_doit (void *a)
476 struct relocate_args *args = (struct relocate_args *) a;
478 INTUSE(_dl_relocate_object) (args->l, args->l->l_scope, args->lazy, 0);
481 static void
482 map_doit (void *a)
484 struct map_args *args = (struct map_args *) a;
485 args->main_map = INTUSE(_dl_map_object) (NULL, args->str, 0, lt_library, 0, 0);
488 static void
489 version_check_doit (void *a)
491 struct version_check_args *args = (struct version_check_args *) a;
492 if (_dl_check_all_versions (GL(dl_loaded), 1, args->dotrace) && args->doexit)
493 /* We cannot start the application. Abort now. */
494 _exit (1);
498 static inline struct link_map *
499 find_needed (const char *name)
501 unsigned int n = GL(dl_loaded)->l_searchlist.r_nlist;
503 while (n-- > 0)
504 if (_dl_name_match_p (name, GL(dl_loaded)->l_searchlist.r_list[n]))
505 return GL(dl_loaded)->l_searchlist.r_list[n];
507 /* Should never happen. */
508 return NULL;
511 static int
512 match_version (const char *string, struct link_map *map)
514 const char *strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
515 ElfW(Verdef) *def;
517 #define VERDEFTAG (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (DT_VERDEF))
518 if (map->l_info[VERDEFTAG] == NULL)
519 /* The file has no symbol versioning. */
520 return 0;
522 def = (ElfW(Verdef) *) ((char *) map->l_addr
523 + map->l_info[VERDEFTAG]->d_un.d_ptr);
524 while (1)
526 ElfW(Verdaux) *aux = (ElfW(Verdaux) *) ((char *) def + def->vd_aux);
528 /* Compare the version strings. */
529 if (strcmp (string, strtab + aux->vda_name) == 0)
530 /* Bingo! */
531 return 1;
533 /* If no more definitions we failed to find what we want. */
534 if (def->vd_next == 0)
535 break;
537 /* Next definition. */
538 def = (ElfW(Verdef) *) ((char *) def + def->vd_next);
541 return 0;
544 static const char *library_path; /* The library search path. */
545 static const char *preloadlist; /* The list preloaded objects. */
546 static int version_info; /* Nonzero if information about
547 versions has to be printed. */
549 static void
550 dl_main (const ElfW(Phdr) *phdr,
551 ElfW(Word) phnum,
552 ElfW(Addr) *user_entry)
554 const ElfW(Phdr) *ph;
555 enum mode mode;
556 struct link_map **preloads;
557 unsigned int npreloads;
558 size_t file_size;
559 char *file;
560 bool has_interp = false;
561 unsigned int i;
562 bool prelinked = false;
563 bool rtld_is_main = false;
564 #ifndef HP_TIMING_NONAVAIL
565 hp_timing_t start;
566 hp_timing_t stop;
567 hp_timing_t diff;
568 #endif
569 #ifdef USE_TLS
570 void *tcbp;
571 #endif
573 /* Process the environment variable which control the behaviour. */
574 process_envvars (&mode);
576 /* Set up a flag which tells we are just starting. */
577 INTUSE(_dl_starting_up) = 1;
579 if (*user_entry == (ElfW(Addr)) ENTRY_POINT)
581 /* Ho ho. We are not the program interpreter! We are the program
582 itself! This means someone ran ld.so as a command. Well, that
583 might be convenient to do sometimes. We support it by
584 interpreting the args like this:
586 ld.so PROGRAM ARGS...
588 The first argument is the name of a file containing an ELF
589 executable we will load and run with the following arguments.
590 To simplify life here, PROGRAM is searched for using the
591 normal rules for shared objects, rather than $PATH or anything
592 like that. We just load it and use its entry point; we don't
593 pay attention to its PT_INTERP command (we are the interpreter
594 ourselves). This is an easy way to test a new ld.so before
595 installing it. */
596 rtld_is_main = true;
598 /* Note the place where the dynamic linker actually came from. */
599 GL(dl_rtld_map).l_name = rtld_progname;
601 while (_dl_argc > 1)
602 if (! strcmp (INTUSE(_dl_argv)[1], "--list"))
604 mode = list;
605 GL(dl_lazy) = -1; /* This means do no dependency analysis. */
607 ++_dl_skip_args;
608 --_dl_argc;
609 ++INTUSE(_dl_argv);
611 else if (! strcmp (INTUSE(_dl_argv)[1], "--verify"))
613 mode = verify;
615 ++_dl_skip_args;
616 --_dl_argc;
617 ++INTUSE(_dl_argv);
619 else if (! strcmp (INTUSE(_dl_argv)[1], "--library-path")
620 && _dl_argc > 2)
622 library_path = INTUSE(_dl_argv)[2];
624 _dl_skip_args += 2;
625 _dl_argc -= 2;
626 INTUSE(_dl_argv) += 2;
628 else if (! strcmp (INTUSE(_dl_argv)[1], "--inhibit-rpath")
629 && _dl_argc > 2)
631 GL(dl_inhibit_rpath) = INTUSE(_dl_argv)[2];
633 _dl_skip_args += 2;
634 _dl_argc -= 2;
635 INTUSE(_dl_argv) += 2;
637 else
638 break;
640 /* If we have no further argument the program was called incorrectly.
641 Grant the user some education. */
642 if (_dl_argc < 2)
643 _dl_fatal_printf ("\
644 Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]\n\
645 You have invoked `ld.so', the helper program for shared library executables.\n\
646 This program usually lives in the file `/lib/ld.so', and special directives\n\
647 in executable files using ELF shared libraries tell the system's program\n\
648 loader to load the helper program from this file. This helper program loads\n\
649 the shared libraries needed by the program executable, prepares the program\n\
650 to run, and runs it. You may invoke this helper program directly from the\n\
651 command line to load and run an ELF executable file; this is like executing\n\
652 that file itself, but always uses this helper program from the file you\n\
653 specified, instead of the helper program file specified in the executable\n\
654 file you run. This is mostly of use for maintainers to test new versions\n\
655 of this helper program; chances are you did not intend to run this program.\n\
657 --list list all dependencies and how they are resolved\n\
658 --verify verify that given object really is a dynamically linked\n\
659 object we can handle\n\
660 --library-path PATH use given PATH instead of content of the environment\n\
661 variable LD_LIBRARY_PATH\n\
662 --inhibit-rpath LIST ignore RUNPATH and RPATH information in object names\n\
663 in LIST\n");
665 ++_dl_skip_args;
666 --_dl_argc;
667 ++INTUSE(_dl_argv);
669 /* Initialize the data structures for the search paths for shared
670 objects. */
671 _dl_init_paths (library_path);
673 if (__builtin_expect (mode, normal) == verify)
675 const char *objname;
676 const char *err_str = NULL;
677 struct map_args args;
679 args.str = rtld_progname;
680 (void) INTUSE(_dl_catch_error) (&objname, &err_str, map_doit, &args);
681 if (__builtin_expect (err_str != NULL, 0))
682 /* We don't free the returned string, the programs stops
683 anyway. */
684 _exit (EXIT_FAILURE);
686 else
688 HP_TIMING_NOW (start);
689 INTUSE(_dl_map_object) (NULL, rtld_progname, 0, lt_library, 0, 0);
690 HP_TIMING_NOW (stop);
692 HP_TIMING_DIFF (load_time, start, stop);
695 phdr = GL(dl_loaded)->l_phdr;
696 phnum = GL(dl_loaded)->l_phnum;
697 /* We overwrite here a pointer to a malloc()ed string. But since
698 the malloc() implementation used at this point is the dummy
699 implementations which has no real free() function it does not
700 makes sense to free the old string first. */
701 GL(dl_loaded)->l_name = (char *) "";
702 *user_entry = GL(dl_loaded)->l_entry;
704 else
706 /* Create a link_map for the executable itself.
707 This will be what dlopen on "" returns. */
708 _dl_new_object ((char *) "", "", lt_executable, NULL);
709 if (GL(dl_loaded) == NULL)
710 _dl_fatal_printf ("cannot allocate memory for link map\n");
711 GL(dl_loaded)->l_phdr = phdr;
712 GL(dl_loaded)->l_phnum = phnum;
713 GL(dl_loaded)->l_entry = *user_entry;
715 /* At this point we are in a bit of trouble. We would have to
716 fill in the values for l_dev and l_ino. But in general we
717 do not know where the file is. We also do not handle AT_EXECFD
718 even if it would be passed up.
720 We leave the values here defined to 0. This is normally no
721 problem as the program code itself is normally no shared
722 object and therefore cannot be loaded dynamically. Nothing
723 prevent the use of dynamic binaries and in these situations
724 we might get problems. We might not be able to find out
725 whether the object is already loaded. But since there is no
726 easy way out and because the dynamic binary must also not
727 have an SONAME we ignore this program for now. If it becomes
728 a problem we can force people using SONAMEs. */
730 /* We delay initializing the path structure until we got the dynamic
731 information for the program. */
734 GL(dl_loaded)->l_map_end = 0;
735 /* Perhaps the executable has no PT_LOAD header entries at all. */
736 GL(dl_loaded)->l_map_start = ~0;
737 /* We opened the file, account for it. */
738 ++GL(dl_loaded)->l_opencount;
740 /* Scan the program header table for the dynamic section. */
741 for (ph = phdr; ph < &phdr[phnum]; ++ph)
742 switch (ph->p_type)
744 case PT_PHDR:
745 /* Find out the load address. */
746 GL(dl_loaded)->l_addr = (ElfW(Addr)) phdr - ph->p_vaddr;
747 break;
748 case PT_DYNAMIC:
749 /* This tells us where to find the dynamic section,
750 which tells us everything we need to do. */
751 GL(dl_loaded)->l_ld = (void *) GL(dl_loaded)->l_addr + ph->p_vaddr;
752 break;
753 case PT_INTERP:
754 /* This "interpreter segment" was used by the program loader to
755 find the program interpreter, which is this program itself, the
756 dynamic linker. We note what name finds us, so that a future
757 dlopen call or DT_NEEDED entry, for something that wants to link
758 against the dynamic linker as a shared library, will know that
759 the shared object is already loaded. */
760 _dl_rtld_libname.name = ((const char *) GL(dl_loaded)->l_addr
761 + ph->p_vaddr);
762 /* _dl_rtld_libname.next = NULL; Already zero. */
763 GL(dl_rtld_map).l_libname = &_dl_rtld_libname;
765 /* Ordinarilly, we would get additional names for the loader from
766 our DT_SONAME. This can't happen if we were actually linked as
767 a static executable (detect this case when we have no DYNAMIC).
768 If so, assume the filename component of the interpreter path to
769 be our SONAME, and add it to our name list. */
770 if (GL(dl_rtld_map).l_ld == NULL)
772 const char *p = NULL;
773 const char *cp = _dl_rtld_libname.name;
775 /* Find the filename part of the path. */
776 while (*cp != '\0')
777 if (*cp++ == '/')
778 p = cp;
780 if (p != NULL)
782 _dl_rtld_libname2.name = p;
783 /* _dl_rtld_libname2.next = NULL; Already zero. */
784 _dl_rtld_libname.next = &_dl_rtld_libname2;
788 has_interp = true;
789 break;
790 case PT_LOAD:
792 ElfW(Addr) mapstart;
793 ElfW(Addr) allocend;
795 /* Remember where the main program starts in memory. */
796 mapstart = (GL(dl_loaded)->l_addr
797 + (ph->p_vaddr & ~(ph->p_align - 1)));
798 if (GL(dl_loaded)->l_map_start > mapstart)
799 GL(dl_loaded)->l_map_start = mapstart;
801 /* Also where it ends. */
802 allocend = GL(dl_loaded)->l_addr + ph->p_vaddr + ph->p_memsz;
803 if (GL(dl_loaded)->l_map_end < allocend)
804 GL(dl_loaded)->l_map_end = allocend;
806 break;
807 #ifdef USE_TLS
808 case PT_TLS:
809 if (ph->p_memsz > 0)
811 /* Note that in the case the dynamic linker we duplicate work
812 here since we read the PT_TLS entry already in
813 _dl_start_final. But the result is repeatable so do not
814 check for this special but unimportant case. */
815 GL(dl_loaded)->l_tls_blocksize = ph->p_memsz;
816 GL(dl_loaded)->l_tls_align = ph->p_align;
817 GL(dl_loaded)->l_tls_initimage_size = ph->p_filesz;
818 GL(dl_loaded)->l_tls_initimage = (void *) ph->p_vaddr;
820 /* This image gets the ID one. */
821 GL(dl_tls_max_dtv_idx) = GL(dl_loaded)->l_tls_modid = 1;
823 break;
824 #endif
826 if (! GL(dl_loaded)->l_map_end)
827 GL(dl_loaded)->l_map_end = ~0;
828 if (! GL(dl_rtld_map).l_libname && GL(dl_rtld_map).l_name)
830 /* We were invoked directly, so the program might not have a
831 PT_INTERP. */
832 _dl_rtld_libname.name = GL(dl_rtld_map).l_name;
833 /* _dl_rtld_libname.next = NULL; Already zero. */
834 GL(dl_rtld_map).l_libname = &_dl_rtld_libname;
836 else
837 assert (GL(dl_rtld_map).l_libname); /* How else did we get here? */
839 if (! rtld_is_main)
841 /* Extract the contents of the dynamic section for easy access. */
842 elf_get_dynamic_info (GL(dl_loaded));
843 if (GL(dl_loaded)->l_info[DT_HASH])
844 /* Set up our cache of pointers into the hash table. */
845 _dl_setup_hash (GL(dl_loaded));
848 if (__builtin_expect (mode, normal) == verify)
850 /* We were called just to verify that this is a dynamic
851 executable using us as the program interpreter. Exit with an
852 error if we were not able to load the binary or no interpreter
853 is specified (i.e., this is no dynamically linked binary. */
854 if (GL(dl_loaded)->l_ld == NULL)
855 _exit (1);
857 /* We allow here some platform specific code. */
858 #ifdef DISTINGUISH_LIB_VERSIONS
859 DISTINGUISH_LIB_VERSIONS;
860 #endif
861 _exit (has_interp ? 0 : 2);
864 if (! rtld_is_main)
865 /* Initialize the data structures for the search paths for shared
866 objects. */
867 _dl_init_paths (library_path);
869 /* Put the link_map for ourselves on the chain so it can be found by
870 name. Note that at this point the global chain of link maps contains
871 exactly one element, which is pointed to by dl_loaded. */
872 if (! GL(dl_rtld_map).l_name)
873 /* If not invoked directly, the dynamic linker shared object file was
874 found by the PT_INTERP name. */
875 GL(dl_rtld_map).l_name = (char *) GL(dl_rtld_map).l_libname->name;
876 GL(dl_rtld_map).l_type = lt_library;
877 GL(dl_loaded)->l_next = &GL(dl_rtld_map);
878 GL(dl_rtld_map).l_prev = GL(dl_loaded);
879 ++GL(dl_nloaded);
881 /* We have two ways to specify objects to preload: via environment
882 variable and via the file /etc/ld.so.preload. The latter can also
883 be used when security is enabled. */
884 preloads = NULL;
885 npreloads = 0;
887 if (__builtin_expect (preloadlist != NULL, 0))
889 /* The LD_PRELOAD environment variable gives list of libraries
890 separated by white space or colons that are loaded before the
891 executable's dependencies and prepended to the global scope
892 list. If the binary is running setuid all elements
893 containing a '/' are ignored since it is insecure. */
894 char *list = strdupa (preloadlist);
895 char *p;
897 HP_TIMING_NOW (start);
899 /* Prevent optimizing strsep. Speed is not important here. */
900 while ((p = (strsep) (&list, " :")) != NULL)
901 if (p[0] != '\0'
902 && (__builtin_expect (! INTUSE(__libc_enable_secure), 1)
903 || strchr (p, '/') == NULL))
905 struct link_map *new_map = INTUSE(_dl_map_object) (GL(dl_loaded),
906 p, 1,
907 lt_library,
908 0, 0);
909 if (++new_map->l_opencount == 1)
910 /* It is no duplicate. */
911 ++npreloads;
914 HP_TIMING_NOW (stop);
915 HP_TIMING_DIFF (diff, start, stop);
916 HP_TIMING_ACCUM_NT (load_time, diff);
919 /* Read the contents of the file. */
920 file = _dl_sysdep_read_whole_file ("/etc/ld.so.preload", &file_size,
921 PROT_READ | PROT_WRITE);
922 if (__builtin_expect (file != MAP_FAILED, 0))
924 /* Parse the file. It contains names of libraries to be loaded,
925 separated by white spaces or `:'. It may also contain
926 comments introduced by `#'. */
927 char *problem;
928 char *runp;
929 size_t rest;
931 /* Eliminate comments. */
932 runp = file;
933 rest = file_size;
934 while (rest > 0)
936 char *comment = memchr (runp, '#', rest);
937 if (comment == NULL)
938 break;
940 rest -= comment - runp;
942 *comment = ' ';
943 while (--rest > 0 && *++comment != '\n');
946 /* We have one problematic case: if we have a name at the end of
947 the file without a trailing terminating characters, we cannot
948 place the \0. Handle the case separately. */
949 if (file[file_size - 1] != ' ' && file[file_size - 1] != '\t'
950 && file[file_size - 1] != '\n' && file[file_size - 1] != ':')
952 problem = &file[file_size];
953 while (problem > file && problem[-1] != ' ' && problem[-1] != '\t'
954 && problem[-1] != '\n' && problem[-1] != ':')
955 --problem;
957 if (problem > file)
958 problem[-1] = '\0';
960 else
962 problem = NULL;
963 file[file_size - 1] = '\0';
966 HP_TIMING_NOW (start);
968 if (file != problem)
970 char *p;
971 runp = file;
972 while ((p = strsep (&runp, ": \t\n")) != NULL)
973 if (p[0] != '\0')
975 struct link_map *new_map = INTUSE(_dl_map_object) (GL(dl_loaded),
976 p, 1,
977 lt_library,
978 0, 0);
979 if (++new_map->l_opencount == 1)
980 /* It is no duplicate. */
981 ++npreloads;
985 if (problem != NULL)
987 char *p = strndupa (problem, file_size - (problem - file));
988 struct link_map *new_map = INTUSE(_dl_map_object) (GL(dl_loaded), p,
989 1, lt_library,
990 0, 0);
991 if (++new_map->l_opencount == 1)
992 /* It is no duplicate. */
993 ++npreloads;
996 HP_TIMING_NOW (stop);
997 HP_TIMING_DIFF (diff, start, stop);
998 HP_TIMING_ACCUM_NT (load_time, diff);
1000 /* We don't need the file anymore. */
1001 __munmap (file, file_size);
1004 if (__builtin_expect (npreloads, 0) != 0)
1006 /* Set up PRELOADS with a vector of the preloaded libraries. */
1007 struct link_map *l;
1008 preloads = __alloca (npreloads * sizeof preloads[0]);
1009 l = GL(dl_rtld_map).l_next; /* End of the chain before preloads. */
1010 i = 0;
1013 preloads[i++] = l;
1014 l = l->l_next;
1015 } while (l);
1016 assert (i == npreloads);
1019 /* Load all the libraries specified by DT_NEEDED entries. If LD_PRELOAD
1020 specified some libraries to load, these are inserted before the actual
1021 dependencies in the executable's searchlist for symbol resolution. */
1022 HP_TIMING_NOW (start);
1023 INTUSE(_dl_map_object_deps) (GL(dl_loaded), preloads, npreloads,
1024 mode == trace, 0);
1025 HP_TIMING_NOW (stop);
1026 HP_TIMING_DIFF (diff, start, stop);
1027 HP_TIMING_ACCUM_NT (load_time, diff);
1029 /* Mark all objects as being in the global scope and set the open
1030 counter. */
1031 for (i = GL(dl_loaded)->l_searchlist.r_nlist; i > 0; )
1033 --i;
1034 GL(dl_loaded)->l_searchlist.r_list[i]->l_global = 1;
1035 ++GL(dl_loaded)->l_searchlist.r_list[i]->l_opencount;
1038 #ifndef MAP_ANON
1039 /* We are done mapping things, so close the zero-fill descriptor. */
1040 __close (_dl_zerofd);
1041 _dl_zerofd = -1;
1042 #endif
1044 /* Remove _dl_rtld_map from the chain. */
1045 GL(dl_rtld_map).l_prev->l_next = GL(dl_rtld_map).l_next;
1046 if (GL(dl_rtld_map).l_next)
1047 GL(dl_rtld_map).l_next->l_prev = GL(dl_rtld_map).l_prev;
1049 if (__builtin_expect (GL(dl_rtld_map).l_opencount > 1, 1))
1051 /* Some DT_NEEDED entry referred to the interpreter object itself, so
1052 put it back in the list of visible objects. We insert it into the
1053 chain in symbol search order because gdb uses the chain's order as
1054 its symbol search order. */
1055 i = 1;
1056 while (GL(dl_loaded)->l_searchlist.r_list[i] != &GL(dl_rtld_map))
1057 ++i;
1058 GL(dl_rtld_map).l_prev = GL(dl_loaded)->l_searchlist.r_list[i - 1];
1059 if (__builtin_expect (mode, normal) == normal)
1060 GL(dl_rtld_map).l_next = (i + 1 < GL(dl_loaded)->l_searchlist.r_nlist
1061 ? GL(dl_loaded)->l_searchlist.r_list[i + 1]
1062 : NULL);
1063 else
1064 /* In trace mode there might be an invisible object (which we
1065 could not find) after the previous one in the search list.
1066 In this case it doesn't matter much where we put the
1067 interpreter object, so we just initialize the list pointer so
1068 that the assertion below holds. */
1069 GL(dl_rtld_map).l_next = GL(dl_rtld_map).l_prev->l_next;
1071 assert (GL(dl_rtld_map).l_prev->l_next == GL(dl_rtld_map).l_next);
1072 GL(dl_rtld_map).l_prev->l_next = &GL(dl_rtld_map);
1073 if (GL(dl_rtld_map).l_next != NULL)
1075 assert (GL(dl_rtld_map).l_next->l_prev == GL(dl_rtld_map).l_prev);
1076 GL(dl_rtld_map).l_next->l_prev = &GL(dl_rtld_map);
1080 /* Now let us see whether all libraries are available in the
1081 versions we need. */
1083 struct version_check_args args;
1084 args.doexit = mode == normal;
1085 args.dotrace = mode == trace;
1086 _dl_receive_error (print_missing_version, version_check_doit, &args);
1089 #ifdef USE_TLS
1090 /* Now it is time to determine the layout of the static TLS block
1091 and allocate it for the initial thread. Note that we always
1092 allocate the static block, we never defer it even if no
1093 DF_STATIC_TLS bit is set. The reason is that we know glibc will
1094 use the static model. First add the dynamic linker to the list
1095 if it also uses TLS. */
1096 if (GL(dl_rtld_map).l_tls_blocksize != 0)
1097 /* Assign a module ID. */
1098 GL(dl_rtld_map).l_tls_modid = _dl_next_tls_modid ();
1100 # ifndef SHARED
1101 /* If dynamic loading of modules with TLS is impossible we do not
1102 have to initialize any of the TLS functionality unless any of the
1103 initial modules uses TLS. */
1104 if (GL(dl_tls_max_dtv_idx) > 0)
1105 # endif
1107 struct link_map *l;
1108 size_t nelem;
1109 struct dtv_slotinfo *slotinfo;
1111 /* Number of elements in the static TLS block. */
1112 GL(dl_tls_static_nelem) = GL(dl_tls_max_dtv_idx);
1114 /* Allocate the array which contains the information about the
1115 dtv slots. We allocate a few entries more than needed to
1116 avoid the need for reallocation. */
1117 nelem = GL(dl_tls_max_dtv_idx) + 1 + TLS_SLOTINFO_SURPLUS;
1119 /* Allocate. */
1120 GL(dl_tls_dtv_slotinfo_list) = (struct dtv_slotinfo_list *)
1121 malloc (sizeof (struct dtv_slotinfo_list)
1122 + nelem * sizeof (struct dtv_slotinfo));
1123 /* No need to check the return value. If memory allocation failed
1124 the program would have been terminated. */
1126 slotinfo = memset (GL(dl_tls_dtv_slotinfo_list)->slotinfo, '\0',
1127 nelem * sizeof (struct dtv_slotinfo));
1128 GL(dl_tls_dtv_slotinfo_list)->len = nelem;
1129 GL(dl_tls_dtv_slotinfo_list)->next = NULL;
1131 /* Fill in the information from the loaded modules. */
1132 for (l = GL(dl_loaded), i = 0; l != NULL; l = l->l_next)
1133 if (l->l_tls_blocksize != 0)
1134 /* This is a module with TLS data. Store the map reference.
1135 The generation counter is zero. */
1136 slotinfo[++i].map = l;
1137 assert (i == GL(dl_tls_max_dtv_idx));
1139 /* Compute the TLS offsets for the various blocks. We call this
1140 function even if none of the modules available at startup time
1141 uses TLS to initialize some variables. */
1142 _dl_determine_tlsoffset ();
1144 /* Construct the static TLS block and the dtv for the initial
1145 thread. For some platforms this will include allocating memory
1146 for the thread descriptor. The memory for the TLS block will
1147 never be freed. It should be allocated accordingly. The dtv
1148 array can be changed if dynamic loading requires it. */
1149 tcbp = _dl_allocate_tls_storage ();
1150 if (tcbp == NULL)
1151 _dl_fatal_printf ("\
1152 cannot allocate TLS data structures for initial thread");
1154 /* Store for detection of the special case by __tls_get_addr
1155 so it knows not to pass this dtv to the normal realloc. */
1156 GL(dl_initial_dtv) = GET_DTV (tcbp);
1158 #endif
1160 if (__builtin_expect (mode, normal) != normal)
1162 /* We were run just to list the shared libraries. It is
1163 important that we do this before real relocation, because the
1164 functions we call below for output may no longer work properly
1165 after relocation. */
1166 if (! GL(dl_loaded)->l_info[DT_NEEDED])
1167 _dl_printf ("\tstatically linked\n");
1168 else
1170 struct link_map *l;
1172 if (GL(dl_debug_mask) & DL_DEBUG_PRELINK)
1174 struct r_scope_elem *scope = &GL(dl_loaded)->l_searchlist;
1176 for (i = 0; i < scope->r_nlist; i++)
1178 l = scope->r_list [i];
1179 if (l->l_faked)
1181 _dl_printf ("\t%s => not found\n", l->l_libname->name);
1182 continue;
1184 if (_dl_name_match_p (GL(dl_trace_prelink), l))
1185 GL(dl_trace_prelink_map) = l;
1186 _dl_printf ("\t%s => %s (0x%0*Zx, 0x%0*Zx)",
1187 l->l_libname->name[0] ? l->l_libname->name
1188 : rtld_progname ?: "<main program>",
1189 l->l_name[0] ? l->l_name
1190 : rtld_progname ?: "<main program>",
1191 (int) sizeof l->l_map_start * 2,
1192 l->l_map_start,
1193 (int) sizeof l->l_addr * 2,
1194 l->l_addr);
1195 #ifdef USE_TLS
1196 if (l->l_tls_modid)
1197 _dl_printf (" TLS(0x%Zx, 0x%0*Zx)\n", l->l_tls_modid,
1198 (int) sizeof l->l_tls_offset * 2,
1199 l->l_tls_offset);
1200 else
1201 #endif
1202 _dl_printf ("\n");
1205 else
1207 for (l = GL(dl_loaded)->l_next; l; l = l->l_next)
1208 if (l->l_faked)
1209 /* The library was not found. */
1210 _dl_printf ("\t%s => not found\n", l->l_libname->name);
1211 else
1212 _dl_printf ("\t%s => %s (0x%0*Zx)\n", l->l_libname->name,
1213 l->l_name, (int) sizeof l->l_map_start * 2,
1214 l->l_map_start);
1218 if (__builtin_expect (mode, trace) != trace)
1219 for (i = 1; i < (unsigned int) _dl_argc; ++i)
1221 const ElfW(Sym) *ref = NULL;
1222 ElfW(Addr) loadbase;
1223 lookup_t result;
1225 result = INTUSE(_dl_lookup_symbol) (INTUSE(_dl_argv)[i],
1226 GL(dl_loaded),
1227 &ref, GL(dl_loaded)->l_scope,
1228 ELF_RTYPE_CLASS_PLT, 1);
1230 loadbase = LOOKUP_VALUE_ADDRESS (result);
1232 _dl_printf ("%s found at 0x%0*Zd in object at 0x%0*Zd\n",
1233 INTUSE(_dl_argv)[i],
1234 (int) sizeof ref->st_value * 2, ref->st_value,
1235 (int) sizeof loadbase * 2, loadbase);
1237 else
1239 /* If LD_WARN is set warn about undefined symbols. */
1240 if (GL(dl_lazy) >= 0 && GL(dl_verbose))
1242 /* We have to do symbol dependency testing. */
1243 struct relocate_args args;
1244 struct link_map *l;
1246 args.lazy = GL(dl_lazy);
1248 l = GL(dl_loaded);
1249 while (l->l_next)
1250 l = l->l_next;
1253 if (l != &GL(dl_rtld_map) && ! l->l_faked)
1255 args.l = l;
1256 _dl_receive_error (print_unresolved, relocate_doit,
1257 &args);
1259 l = l->l_prev;
1260 } while (l);
1262 if ((GL(dl_debug_mask) & DL_DEBUG_PRELINK)
1263 && GL(dl_rtld_map).l_opencount > 1)
1264 INTUSE(_dl_relocate_object) (&GL(dl_rtld_map),
1265 GL(dl_loaded)->l_scope, 0, 0);
1268 #define VERNEEDTAG (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (DT_VERNEED))
1269 if (version_info)
1271 /* Print more information. This means here, print information
1272 about the versions needed. */
1273 int first = 1;
1274 struct link_map *map = GL(dl_loaded);
1276 for (map = GL(dl_loaded); map != NULL; map = map->l_next)
1278 const char *strtab;
1279 ElfW(Dyn) *dyn = map->l_info[VERNEEDTAG];
1280 ElfW(Verneed) *ent;
1282 if (dyn == NULL)
1283 continue;
1285 strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
1286 ent = (ElfW(Verneed) *) (map->l_addr + dyn->d_un.d_ptr);
1288 if (first)
1290 _dl_printf ("\n\tVersion information:\n");
1291 first = 0;
1294 _dl_printf ("\t%s:\n",
1295 map->l_name[0] ? map->l_name : rtld_progname);
1297 while (1)
1299 ElfW(Vernaux) *aux;
1300 struct link_map *needed;
1302 needed = find_needed (strtab + ent->vn_file);
1303 aux = (ElfW(Vernaux) *) ((char *) ent + ent->vn_aux);
1305 while (1)
1307 const char *fname = NULL;
1309 if (needed != NULL
1310 && match_version (strtab + aux->vna_name,
1311 needed))
1312 fname = needed->l_name;
1314 _dl_printf ("\t\t%s (%s) %s=> %s\n",
1315 strtab + ent->vn_file,
1316 strtab + aux->vna_name,
1317 aux->vna_flags & VER_FLG_WEAK
1318 ? "[WEAK] " : "",
1319 fname ?: "not found");
1321 if (aux->vna_next == 0)
1322 /* No more symbols. */
1323 break;
1325 /* Next symbol. */
1326 aux = (ElfW(Vernaux) *) ((char *) aux
1327 + aux->vna_next);
1330 if (ent->vn_next == 0)
1331 /* No more dependencies. */
1332 break;
1334 /* Next dependency. */
1335 ent = (ElfW(Verneed) *) ((char *) ent + ent->vn_next);
1341 _exit (0);
1344 if (GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_LIBLIST)]
1345 && ! __builtin_expect (GL(dl_profile) != NULL, 0))
1347 ElfW(Lib) *liblist, *liblistend;
1348 struct link_map **r_list, **r_listend, *l;
1349 const char *strtab = (const void *) D_PTR (GL(dl_loaded),
1350 l_info[DT_STRTAB]);
1352 assert (GL(dl_loaded)->l_info [VALIDX (DT_GNU_LIBLISTSZ)] != NULL);
1353 liblist = (ElfW(Lib) *)
1354 GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_LIBLIST)]->d_un.d_ptr;
1355 liblistend = (ElfW(Lib) *)
1356 ((char *) liblist
1357 + GL(dl_loaded)->l_info [VALIDX (DT_GNU_LIBLISTSZ)]->d_un.d_val);
1358 r_list = GL(dl_loaded)->l_searchlist.r_list;
1359 r_listend = r_list + GL(dl_loaded)->l_searchlist.r_nlist;
1361 for (; r_list < r_listend && liblist < liblistend; r_list++)
1363 l = *r_list;
1365 if (l == GL(dl_loaded))
1366 continue;
1368 /* If the library is not mapped where it should, fail. */
1369 if (l->l_addr)
1370 break;
1372 /* Next, check if checksum matches. */
1373 if (l->l_info [VALIDX(DT_CHECKSUM)] == NULL
1374 || l->l_info [VALIDX(DT_CHECKSUM)]->d_un.d_val
1375 != liblist->l_checksum)
1376 break;
1378 if (l->l_info [VALIDX(DT_GNU_PRELINKED)] == NULL
1379 || l->l_info [VALIDX(DT_GNU_PRELINKED)]->d_un.d_val
1380 != liblist->l_time_stamp)
1381 break;
1383 if (! _dl_name_match_p (strtab + liblist->l_name, l))
1384 break;
1386 ++liblist;
1390 if (r_list == r_listend && liblist == liblistend)
1391 prelinked = true;
1393 if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_LIBS, 0))
1394 _dl_printf ("\nprelink checking: %s\n", prelinked ? "ok" : "failed");
1397 if (prelinked)
1399 if (GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_CONFLICT)] != NULL)
1401 ElfW(Rela) *conflict, *conflictend;
1402 #ifndef HP_TIMING_NONAVAIL
1403 hp_timing_t start;
1404 hp_timing_t stop;
1405 #endif
1407 HP_TIMING_NOW (start);
1408 assert (GL(dl_loaded)->l_info [VALIDX (DT_GNU_CONFLICTSZ)] != NULL);
1409 conflict = (ElfW(Rela) *)
1410 GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_CONFLICT)]->d_un.d_ptr;
1411 conflictend = (ElfW(Rela) *)
1412 ((char *) conflict
1413 + GL(dl_loaded)->l_info [VALIDX (DT_GNU_CONFLICTSZ)]->d_un.d_val);
1414 _dl_resolve_conflicts (GL(dl_loaded), conflict, conflictend);
1415 HP_TIMING_NOW (stop);
1416 HP_TIMING_DIFF (relocate_time, start, stop);
1419 _dl_sysdep_start_cleanup ();
1421 else
1423 /* Now we have all the objects loaded. Relocate them all except for
1424 the dynamic linker itself. We do this in reverse order so that copy
1425 relocs of earlier objects overwrite the data written by later
1426 objects. We do not re-relocate the dynamic linker itself in this
1427 loop because that could result in the GOT entries for functions we
1428 call being changed, and that would break us. It is safe to relocate
1429 the dynamic linker out of order because it has no copy relocs (we
1430 know that because it is self-contained). */
1432 struct link_map *l;
1433 int consider_profiling = GL(dl_profile) != NULL;
1434 #ifndef HP_TIMING_NONAVAIL
1435 hp_timing_t start;
1436 hp_timing_t stop;
1437 hp_timing_t add;
1438 #endif
1440 /* If we are profiling we also must do lazy reloaction. */
1441 GL(dl_lazy) |= consider_profiling;
1443 l = GL(dl_loaded);
1444 while (l->l_next)
1445 l = l->l_next;
1447 HP_TIMING_NOW (start);
1450 /* While we are at it, help the memory handling a bit. We have to
1451 mark some data structures as allocated with the fake malloc()
1452 implementation in ld.so. */
1453 struct libname_list *lnp = l->l_libname->next;
1455 while (__builtin_expect (lnp != NULL, 0))
1457 lnp->dont_free = 1;
1458 lnp = lnp->next;
1461 if (l != &GL(dl_rtld_map))
1462 INTUSE(_dl_relocate_object) (l, l->l_scope, GL(dl_lazy),
1463 consider_profiling);
1465 l = l->l_prev;
1467 while (l);
1468 HP_TIMING_NOW (stop);
1470 HP_TIMING_DIFF (relocate_time, start, stop);
1472 /* Do any necessary cleanups for the startup OS interface code.
1473 We do these now so that no calls are made after rtld re-relocation
1474 which might be resolved to different functions than we expect.
1475 We cannot do this before relocating the other objects because
1476 _dl_relocate_object might need to call `mprotect' for DT_TEXTREL. */
1477 _dl_sysdep_start_cleanup ();
1479 /* Now enable profiling if needed. Like the previous call,
1480 this has to go here because the calls it makes should use the
1481 rtld versions of the functions (particularly calloc()), but it
1482 needs to have _dl_profile_map set up by the relocator. */
1483 if (__builtin_expect (GL(dl_profile_map) != NULL, 0))
1484 /* We must prepare the profiling. */
1485 INTUSE(_dl_start_profile) (GL(dl_profile_map), GL(dl_profile_output));
1487 if (GL(dl_rtld_map).l_opencount > 1)
1489 /* There was an explicit ref to the dynamic linker as a shared lib.
1490 Re-relocate ourselves with user-controlled symbol definitions. */
1491 HP_TIMING_NOW (start);
1492 INTUSE(_dl_relocate_object) (&GL(dl_rtld_map), GL(dl_loaded)->l_scope,
1493 0, 0);
1494 HP_TIMING_NOW (stop);
1495 HP_TIMING_DIFF (add, start, stop);
1496 HP_TIMING_ACCUM_NT (relocate_time, add);
1500 /* Now set up the variable which helps the assembler startup code. */
1501 GL(dl_main_searchlist) = &GL(dl_loaded)->l_searchlist;
1502 GL(dl_global_scope)[0] = &GL(dl_loaded)->l_searchlist;
1504 /* Save the information about the original global scope list since
1505 we need it in the memory handling later. */
1506 GL(dl_initial_searchlist) = *GL(dl_main_searchlist);
1508 #ifdef USE_TLS
1509 # ifndef SHARED
1510 if (GL(dl_tls_max_dtv_idx) > 0)
1511 # endif
1513 /* Now that we have completed relocation, the initializer data
1514 for the TLS blocks has its final values and we can copy them
1515 into the main thread's TLS area, which we allocated above. */
1516 _dl_allocate_tls_init (tcbp);
1518 /* And finally install it for the main thread. */
1519 # ifndef HAVE___THREAD
1520 TLS_INIT_TP (tcbp, GL(dl_rtld_map).l_tls_tp_initialized);
1521 # else
1522 /* If the compiler supports the __thread keyword we know that
1523 at least ld.so itself uses TLS and therefore the thread
1524 pointer was initialized earlier. */
1525 assert (GL(dl_rtld_map).l_tls_tp_initialized != 0);
1526 TLS_INIT_TP (tcbp, 1);
1527 # endif
1529 #endif
1532 /* Initialize _r_debug. */
1533 struct r_debug *r = _dl_debug_initialize (GL(dl_rtld_map).l_addr);
1534 struct link_map *l;
1536 l = GL(dl_loaded);
1538 #ifdef ELF_MACHINE_DEBUG_SETUP
1540 /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way. */
1542 ELF_MACHINE_DEBUG_SETUP (l, r);
1543 ELF_MACHINE_DEBUG_SETUP (&GL(dl_rtld_map), r);
1545 #else
1547 if (l->l_info[DT_DEBUG] != NULL)
1548 /* There is a DT_DEBUG entry in the dynamic section. Fill it in
1549 with the run-time address of the r_debug structure */
1550 l->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
1552 /* Fill in the pointer in the dynamic linker's own dynamic section, in
1553 case you run gdb on the dynamic linker directly. */
1554 if (GL(dl_rtld_map).l_info[DT_DEBUG] != NULL)
1555 GL(dl_rtld_map).l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
1557 #endif
1559 /* Notify the debugger that all objects are now mapped in. */
1560 r->r_state = RT_ADD;
1561 INTUSE(_dl_debug_state) ();
1564 #ifndef MAP_COPY
1565 /* We must munmap() the cache file. */
1566 INTUSE(_dl_unload_cache) ();
1567 #endif
1569 /* Once we return, _dl_sysdep_start will invoke
1570 the DT_INIT functions and then *USER_ENTRY. */
1573 /* This is a little helper function for resolving symbols while
1574 tracing the binary. */
1575 static void
1576 print_unresolved (int errcode __attribute__ ((unused)), const char *objname,
1577 const char *errstring)
1579 if (objname[0] == '\0')
1580 objname = rtld_progname ?: "<main program>";
1581 _dl_error_printf ("%s (%s)\n", errstring, objname);
1584 /* This is a little helper function for resolving symbols while
1585 tracing the binary. */
1586 static void
1587 print_missing_version (int errcode __attribute__ ((unused)),
1588 const char *objname, const char *errstring)
1590 _dl_error_printf ("%s: %s: %s\n", rtld_progname ?: "<program name unknown>",
1591 objname, errstring);
1594 /* Nonzero if any of the debugging options is enabled. */
1595 static int any_debug;
1597 /* Process the string given as the parameter which explains which debugging
1598 options are enabled. */
1599 static void
1600 process_dl_debug (const char *dl_debug)
1602 /* When adding new entries make sure that the maximal length of a name
1603 is correctly handled in the LD_DEBUG_HELP code below. */
1604 static const struct
1606 unsigned char len;
1607 const char name[10];
1608 const char helptext[41];
1609 unsigned short int mask;
1610 } debopts[] =
1612 #define LEN_AND_STR(str) sizeof (str) - 1, str
1613 { LEN_AND_STR ("libs"), "display library search paths",
1614 DL_DEBUG_LIBS | DL_DEBUG_IMPCALLS },
1615 { LEN_AND_STR ("reloc"), "display relocation processing",
1616 DL_DEBUG_RELOC | DL_DEBUG_IMPCALLS },
1617 { LEN_AND_STR ("files"), "display progress for input file",
1618 DL_DEBUG_FILES | DL_DEBUG_IMPCALLS },
1619 { LEN_AND_STR ("symbols"), "display symbol table processing",
1620 DL_DEBUG_SYMBOLS | DL_DEBUG_IMPCALLS },
1621 { LEN_AND_STR ("bindings"), "display information about symbol binding",
1622 DL_DEBUG_BINDINGS | DL_DEBUG_IMPCALLS },
1623 { LEN_AND_STR ("versions"), "display version dependencies",
1624 DL_DEBUG_VERSIONS | DL_DEBUG_IMPCALLS },
1625 { LEN_AND_STR ("all"), "all previous options combined",
1626 DL_DEBUG_LIBS | DL_DEBUG_RELOC | DL_DEBUG_FILES | DL_DEBUG_SYMBOLS
1627 | DL_DEBUG_BINDINGS | DL_DEBUG_VERSIONS | DL_DEBUG_IMPCALLS },
1628 { LEN_AND_STR ("statistics"), "display relocation statistics",
1629 DL_DEBUG_STATISTICS },
1630 { LEN_AND_STR ("help"), "display this help message and exit",
1631 DL_DEBUG_HELP },
1633 #define ndebopts (sizeof (debopts) / sizeof (debopts[0]))
1635 /* Skip separating white spaces and commas. */
1636 while (*dl_debug != '\0')
1638 if (*dl_debug != ' ' && *dl_debug != ',' && *dl_debug != ':')
1640 size_t cnt;
1641 size_t len = 1;
1643 while (dl_debug[len] != '\0' && dl_debug[len] != ' '
1644 && dl_debug[len] != ',' && dl_debug[len] != ':')
1645 ++len;
1647 for (cnt = 0; cnt < ndebopts; ++cnt)
1648 if (debopts[cnt].len == len
1649 && memcmp (dl_debug, debopts[cnt].name, len) == 0)
1651 GL(dl_debug_mask) |= debopts[cnt].mask;
1652 any_debug = 1;
1653 break;
1656 if (cnt == ndebopts)
1658 /* Display a warning and skip everything until next
1659 separator. */
1660 char *copy = strndupa (dl_debug, len);
1661 _dl_error_printf ("\
1662 warning: debug option `%s' unknown; try LD_DEBUG=help\n", copy);
1665 dl_debug += len;
1666 continue;
1669 ++dl_debug;
1672 if (GL(dl_debug_mask) & DL_DEBUG_HELP)
1674 size_t cnt;
1676 _dl_printf ("\
1677 Valid options for the LD_DEBUG environment variable are:\n\n");
1679 for (cnt = 0; cnt < ndebopts; ++cnt)
1680 _dl_printf (" %.*s%s%s\n", debopts[cnt].len, debopts[cnt].name,
1681 " " + debopts[cnt].len - 3,
1682 debopts[cnt].helptext);
1684 _dl_printf ("\n\
1685 To direct the debugging output into a file instead of standard output\n\
1686 a filename can be specified using the LD_DEBUG_OUTPUT environment variable.\n");
1687 _exit (0);
1691 /* Process all environments variables the dynamic linker must recognize.
1692 Since all of them start with `LD_' we are a bit smarter while finding
1693 all the entries. */
1694 extern char **_environ attribute_hidden;
1697 static void
1698 process_envvars (enum mode *modep)
1700 char **runp = _environ;
1701 char *envline;
1702 enum mode mode = normal;
1703 char *debug_output = NULL;
1705 /* This is the default place for profiling data file. */
1706 GL(dl_profile_output)
1707 = &"/var/tmp\0/var/profile"[INTUSE(__libc_enable_secure) ? 9 : 0];
1709 while ((envline = _dl_next_ld_env_entry (&runp)) != NULL)
1711 size_t len = 0;
1713 while (envline[len] != '\0' && envline[len] != '=')
1714 ++len;
1716 if (envline[len] != '=')
1717 /* This is a "LD_" variable at the end of the string without
1718 a '=' character. Ignore it since otherwise we will access
1719 invalid memory below. */
1720 continue;
1722 switch (len)
1724 case 4:
1725 /* Warning level, verbose or not. */
1726 if (memcmp (envline, "WARN", 4) == 0)
1727 GL(dl_verbose) = envline[5] != '\0';
1728 break;
1730 case 5:
1731 /* Debugging of the dynamic linker? */
1732 if (memcmp (envline, "DEBUG", 5) == 0)
1733 process_dl_debug (&envline[6]);
1734 break;
1736 case 7:
1737 /* Print information about versions. */
1738 if (memcmp (envline, "VERBOSE", 7) == 0)
1740 version_info = envline[8] != '\0';
1741 break;
1744 /* List of objects to be preloaded. */
1745 if (memcmp (envline, "PRELOAD", 7) == 0)
1747 preloadlist = &envline[8];
1748 break;
1751 /* Which shared object shall be profiled. */
1752 if (memcmp (envline, "PROFILE", 7) == 0 && envline[8] != '\0')
1753 GL(dl_profile) = &envline[8];
1754 break;
1756 case 8:
1757 /* Do we bind early? */
1758 if (memcmp (envline, "BIND_NOW", 8) == 0)
1760 GL(dl_lazy) = envline[9] == '\0';
1761 break;
1763 if (memcmp (envline, "BIND_NOT", 8) == 0)
1764 GL(dl_bind_not) = envline[9] != '\0';
1765 break;
1767 case 9:
1768 /* Test whether we want to see the content of the auxiliary
1769 array passed up from the kernel. */
1770 if (memcmp (envline, "SHOW_AUXV", 9) == 0)
1771 _dl_show_auxv ();
1772 break;
1774 case 10:
1775 /* Mask for the important hardware capabilities. */
1776 if (memcmp (envline, "HWCAP_MASK", 10) == 0)
1777 GL(dl_hwcap_mask) = __strtoul_internal (&envline[11], NULL, 0, 0);
1778 break;
1780 case 11:
1781 /* Path where the binary is found. */
1782 if (!INTUSE(__libc_enable_secure)
1783 && memcmp (envline, "ORIGIN_PATH", 11) == 0)
1784 GL(dl_origin_path) = &envline[12];
1785 break;
1787 case 12:
1788 /* The library search path. */
1789 if (memcmp (envline, "LIBRARY_PATH", 12) == 0)
1791 library_path = &envline[13];
1792 break;
1795 /* Where to place the profiling data file. */
1796 if (memcmp (envline, "DEBUG_OUTPUT", 12) == 0)
1798 debug_output = &envline[13];
1799 break;
1802 if (memcmp (envline, "DYNAMIC_WEAK", 12) == 0)
1803 GL(dl_dynamic_weak) = 1;
1804 break;
1806 case 14:
1807 /* Where to place the profiling data file. */
1808 if (!INTUSE(__libc_enable_secure)
1809 && memcmp (envline, "PROFILE_OUTPUT", 14) == 0
1810 && envline[15] != '\0')
1811 GL(dl_profile_output) = &envline[15];
1812 break;
1814 case 16:
1815 /* The mode of the dynamic linker can be set. */
1816 if (memcmp (envline, "TRACE_PRELINKING", 16) == 0)
1818 mode = trace;
1819 GL(dl_verbose) = 1;
1820 GL(dl_debug_mask) |= DL_DEBUG_PRELINK;
1821 GL(dl_trace_prelink) = &envline[17];
1823 break;
1825 case 20:
1826 /* The mode of the dynamic linker can be set. */
1827 if (memcmp (envline, "TRACE_LOADED_OBJECTS", 20) == 0)
1828 mode = trace;
1829 break;
1831 /* We might have some extra environment variable to handle. This
1832 is tricky due to the pre-processing of the length of the name
1833 in the switch statement here. The code here assumes that added
1834 environment variables have a different length. */
1835 #ifdef EXTRA_LD_ENVVARS
1836 EXTRA_LD_ENVVARS
1837 #endif
1841 /* The caller wants this information. */
1842 *modep = mode;
1844 /* Extra security for SUID binaries. Remove all dangerous environment
1845 variables. */
1846 if (__builtin_expect (INTUSE(__libc_enable_secure), 0))
1848 static const char unsecure_envvars[] =
1849 #ifdef EXTRA_UNSECURE_ENVVARS
1850 EXTRA_UNSECURE_ENVVARS
1851 #endif
1852 UNSECURE_ENVVARS;
1853 const char *nextp;
1855 nextp = unsecure_envvars;
1858 unsetenv (nextp);
1859 /* We could use rawmemchr but this need not be fast. */
1860 nextp = (char *) (strchr) (nextp, '\0') + 1;
1862 while (*nextp != '\0');
1864 if (__access ("/etc/suid-debug", F_OK) != 0)
1865 unsetenv ("MALLOC_CHECK_");
1867 /* If we have to run the dynamic linker in debugging mode and the
1868 LD_DEBUG_OUTPUT environment variable is given, we write the debug
1869 messages to this file. */
1870 else if (any_debug && debug_output != NULL)
1872 #ifdef O_NOFOLLOW
1873 const int flags = O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW;
1874 #else
1875 const int flags = O_WRONLY | O_APPEND | O_CREAT;
1876 #endif
1877 size_t name_len = strlen (debug_output);
1878 char buf[name_len + 12];
1879 char *startp;
1881 buf[name_len + 11] = '\0';
1882 startp = _itoa (__getpid (), &buf[name_len + 11], 10, 0);
1883 *--startp = '.';
1884 startp = memcpy (startp - name_len, debug_output, name_len);
1886 GL(dl_debug_fd) = __open (startp, flags, DEFFILEMODE);
1887 if (GL(dl_debug_fd) == -1)
1888 /* We use standard output if opening the file failed. */
1889 GL(dl_debug_fd) = STDOUT_FILENO;
1894 /* Print the various times we collected. */
1895 static void
1896 print_statistics (void)
1898 #ifndef HP_TIMING_NONAVAIL
1899 char buf[200];
1900 char *cp;
1901 char *wp;
1903 /* Total time rtld used. */
1904 if (HP_TIMING_AVAIL)
1906 HP_TIMING_PRINT (buf, sizeof (buf), rtld_total_time);
1907 INTUSE(_dl_debug_printf) ("\nruntime linker statistics:\n"
1908 " total startup time in dynamic loader: %s\n",
1909 buf);
1912 /* Print relocation statistics. */
1913 if (HP_TIMING_AVAIL)
1915 char pbuf[30];
1916 HP_TIMING_PRINT (buf, sizeof (buf), relocate_time);
1917 cp = _itoa ((1000ULL * relocate_time) / rtld_total_time,
1918 pbuf + sizeof (pbuf), 10, 0);
1919 wp = pbuf;
1920 switch (pbuf + sizeof (pbuf) - cp)
1922 case 3:
1923 *wp++ = *cp++;
1924 case 2:
1925 *wp++ = *cp++;
1926 case 1:
1927 *wp++ = '.';
1928 *wp++ = *cp++;
1930 *wp = '\0';
1931 INTUSE(_dl_debug_printf) ("\
1932 time needed for relocation: %s (%s%%)\n",
1933 buf, pbuf);
1935 #endif
1936 INTUSE(_dl_debug_printf) (" number of relocations: %lu\n",
1937 GL(dl_num_relocations));
1938 INTUSE(_dl_debug_printf) (" number of relocations from cache: %lu\n",
1939 GL(dl_num_cache_relocations));
1941 #ifndef HP_TIMING_NONAVAIL
1942 /* Time spend while loading the object and the dependencies. */
1943 if (HP_TIMING_AVAIL)
1945 char pbuf[30];
1946 HP_TIMING_PRINT (buf, sizeof (buf), load_time);
1947 cp = _itoa ((1000ULL * load_time) / rtld_total_time,
1948 pbuf + sizeof (pbuf), 10, 0);
1949 wp = pbuf;
1950 switch (pbuf + sizeof (pbuf) - cp)
1952 case 3:
1953 *wp++ = *cp++;
1954 case 2:
1955 *wp++ = *cp++;
1956 case 1:
1957 *wp++ = '.';
1958 *wp++ = *cp++;
1960 *wp = '\0';
1961 INTUSE(_dl_debug_printf) ("\
1962 time needed to load objects: %s (%s%%)\n",
1963 buf, pbuf);
1965 #endif