]> sourceware.org Git - glibc.git/blob - elf/dl-init.c
Update.
[glibc.git] / elf / dl-init.c
1 /* Return the next shared object initializer function not yet run.
2 Copyright (C) 1995, 1996, 1998 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #include <stddef.h>
21 #include <link.h>
22
23
24 /* Run initializers for MAP and its dependencies, in inverse dependency
25 order (that is, leaf nodes first). */
26
27 ElfW(Addr)
28 _dl_init_next (struct link_map *map)
29 {
30 unsigned int i;
31
32 /* The search list for symbol lookup is a flat list in top-down
33 dependency order, so processing that list from back to front gets us
34 breadth-first leaf-to-root order. */
35
36 i = map->l_nsearchlist;
37 while (i-- > 0)
38 {
39 struct link_map *l = map->l_searchlist[i];
40
41 if (l->l_init_called)
42 /* This object is all done. */
43 continue;
44
45 if (l->l_init_running)
46 {
47 /* This object's initializer was just running.
48 Now mark it as having run, so this object
49 will be skipped in the future. */
50 l->l_init_running = 0;
51 l->l_init_called = 1;
52 continue;
53 }
54
55 if (l->l_info[DT_INIT] &&
56 !(l->l_name[0] == '\0' && l->l_type == lt_executable))
57 {
58 /* Run this object's initializer. */
59 l->l_init_running = 1;
60
61 /* Print a debug message if wanted. */
62 if (_dl_debug_impcalls)
63 _dl_debug_message (1, "\ncalling init: ",
64 l->l_name[0] ? l->l_name : _dl_argv[0],
65 "\n\n", NULL);
66
67 return l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr;
68 }
69
70 /* No initializer for this object.
71 Mark it so we will skip it in the future. */
72 l->l_init_called = 1;
73 }
74
75
76 /* Notify the debugger all new objects are now ready to go. */
77 _r_debug.r_state = RT_CONSISTENT;
78 _dl_debug_state ();
79
80 return 0;
81 }
This page took 0.038099 seconds and 5 git commands to generate.