Update.
[glibc.git] / elf / dl-support.c
blob09822218eb692a99d15668e86b842e252171bd4f
1 /* Support for dynamic linking code in static libc.
2 Copyright (C) 1996, 97, 98, 99, 2000, 2001 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 /* This file defines some things that for the dynamic linker are defined in
21 rtld.c and dl-sysdep.c in ways appropriate to bootstrap dynamic linking. */
23 #include <errno.h>
24 #include <libintl.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <ldsodefs.h>
28 #include <dl-machine.h>
29 #include <bits/libc-lock.h>
30 #include <dl-librecon.h>
31 #include <unsecvars.h>
32 #include <hp-timing.h>
34 extern char *__progname;
35 char **_dl_argv = &__progname; /* This is checked for some error messages. */
37 /* Name of the architecture. */
38 const char *_dl_platform;
39 size_t _dl_platformlen;
41 int _dl_debug_mask;
42 int _dl_lazy;
43 /* XXX I know about at least one case where we depend on the old weak
44 behavior (it has to do with librt). Until we get DSO groups implemented
45 we have to make this the default. Bummer. --drepper */
46 #if 0
47 int _dl_dynamic_weak;
48 #else
49 int _dl_dynamic_weak = 1;
50 #endif
52 /* If nonzero print warnings about problematic situations. */
53 int _dl_verbose;
55 /* Structure to store information about search paths. */
56 struct r_search_path *_dl_search_paths;
58 /* We never do profiling. */
59 const char *_dl_profile;
61 /* Names of shared object for which the RUNPATHs and RPATHs should be
62 ignored. */
63 const char *_dl_inhibit_rpath;
65 /* The map for the object we will profile. */
66 struct link_map *_dl_profile_map;
68 /* This is the address of the last stack address ever used. */
69 void *__libc_stack_end;
71 /* Path where the binary is found. */
72 const char *_dl_origin_path;
74 /* Nonzero if runtime lookup should not update the .got/.plt. */
75 int _dl_bind_not;
77 /* Initially empty list of loaded objects. */
78 struct link_map *_dl_loaded;
79 /* Number of object in the _dl_loaded list. */
80 unsigned int _dl_nloaded;
82 /* Fake scope. In dynamically linked binaries this is the scope of the
83 main application but here we don't have something like this. So
84 create a fake scope containing nothing. */
85 struct r_scope_elem _dl_initial_searchlist;
86 /* Variable which can be used in lookup to process the global scope. */
87 struct r_scope_elem *_dl_global_scope[2] = { &_dl_initial_searchlist, NULL };
88 /* This is a global pointer to this structure which is public. It is
89 used by dlopen/dlclose to add and remove objects from what is regarded
90 to be the global scope. */
91 struct r_scope_elem *_dl_main_searchlist = &_dl_initial_searchlist;
93 /* Nonzero during startup. */
94 int _dl_starting_up = 1;
96 /* Initial value of the CPU clock. */
97 #if HP_TIMING_AVAIL
98 hp_timing_t _dl_cpuclock_offset;
99 #endif
101 /* During the program run we must not modify the global data of
102 loaded shared object simultanously in two threads. Therefore we
103 protect `_dl_open' and `_dl_close' in dl-close.c.
105 This must be a recursive lock since the initializer function of
106 the loaded object might as well require a call to this function.
107 At this time it is not anymore a problem to modify the tables. */
108 __libc_lock_define_initialized_recursive (, _dl_load_lock)
111 #ifdef HAVE_AUX_VECTOR
112 extern int _dl_clktck;
114 void
115 internal_function
116 _dl_aux_init (ElfW(auxv_t) *av)
118 for (; av->a_type != AT_NULL; ++av)
119 switch (av->a_type)
121 case AT_PAGESZ:
122 _dl_pagesize = av->a_un.a_val;
123 break;
124 case AT_CLKTCK:
125 _dl_clktck = av->a_un.a_val;
126 break;
129 #endif
131 static void non_dynamic_init (void) __attribute__ ((unused));
133 static void
134 non_dynamic_init (void)
136 #if HP_TIMING_AVAIL
137 HP_TIMING_NOW (_dl_cpuclock_offset);
138 #endif
140 if (!_dl_pagesize)
141 _dl_pagesize = __getpagesize ();
143 _dl_verbose = *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1;
145 /* Initialize the data structures for the search paths for shared
146 objects. */
147 _dl_init_paths (getenv ("LD_LIBRARY_PATH"));
149 _dl_lazy = *(getenv ("LD_BIND_NOW") ?: "") == '\0';
151 _dl_bind_not = *(getenv ("LD_BIND_NOT") ?: "") != '\0';
153 _dl_dynamic_weak = *(getenv ("LD_DYNAMIC_WEAK") ?: "") == '\0';
155 if (__libc_enable_secure)
157 static const char *unsecure_envvars[] =
159 UNSECURE_ENVVARS,
160 #ifdef EXTRA_UNSECURE_ENVVARS
161 EXTRA_UNSECURE_ENVVARS
162 #endif
164 size_t cnt;
166 for (cnt = 0;
167 cnt < sizeof (unsecure_envvars) / sizeof (unsecure_envvars[0]);
168 ++cnt)
169 unsetenv (unsecure_envvars[cnt]);
171 if (__access ("/etc/suid-debug", F_OK) != 0)
172 unsetenv ("MALLOC_CHECK_");
175 #ifdef DL_PLATFORM_INIT
176 DL_PLATFORM_INIT;
177 #endif
179 /* Now determine the length of the platform string. */
180 if (_dl_platform != NULL)
181 _dl_platformlen = strlen (_dl_platform);
183 text_set_element (__libc_subinit, non_dynamic_init);
185 const struct r_strlenpair *
186 internal_function
187 _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
188 size_t *max_capstrlen)
190 struct r_strlenpair *result;
192 /* XXX We don't try to find the capabilities in this case. */
193 result = (struct r_strlenpair *) malloc (sizeof (*result));
194 if (result == NULL)
195 _dl_signal_error (ENOMEM, NULL, N_("cannot create capability list"));
197 result[0].str = (char *) result; /* Does not really matter. */
198 result[0].len = 0;
200 *sz = 1;
201 return result;