]> sourceware.org Git - glibc.git/blob - elf/dl-init.c
e3bfc2ccea135b1ef32a58b3cd6cd592db5831dd
[glibc.git] / elf / dl-init.c
1 /* Return the next shared object initializer function not yet run.
2 Copyright (C) 1995 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
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
19
20 #include <stddef.h>
21 #include <link.h>
22
23
24 Elf32_Addr
25 _dl_init_next (void)
26 {
27 struct link_map *l;
28 Elf32_Addr init;
29
30 Elf32_Addr next_init (struct link_map *l)
31 {
32 if (l->l_init_called)
33 /* This object is all done. */
34 return 0;
35 if (l->l_init_running)
36 {
37 /* This object's initializer was just running.
38 Now mark it as having run, so this object
39 will be skipped in the future. */
40 l->l_init_called = 1;
41 l->l_init_running = 0;
42 return 0;
43 }
44
45 if (l->l_info[DT_NEEDED])
46 {
47 /* Find each dependency in order, and see if it
48 needs to run an initializer. */
49 const Elf32_Dyn *d;
50 for (d = l->l_ld; d->d_tag != DT_NULL; ++d)
51 if (d->d_tag == DT_NEEDED)
52 {
53 struct link_map *needed = _dl_map_object
54 (l, (const char *) (l->l_addr + d->d_un.d_ptr), NULL);
55 Elf32_Addr init;
56 --needed->l_opencount;
57 init = next_init (l); /* Recurse on this dependency. */
58 if (init != 0)
59 return init;
60 }
61 }
62
63 if (l->l_info[DT_INIT])
64 {
65 /* Run this object's initializer. */
66 l->l_init_running = 1;
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 return 0;
74 }
75
76 /* Look for the first initializer not yet called. */
77 l = _dl_loaded;
78 do
79 {
80 init = next_init (l);
81 l = l->l_next;
82 }
83 while (init == 0 && l);
84
85 return init;
86 }
This page took 0.04227 seconds and 4 git commands to generate.