Update.
[glibc.git] / elf / dl-support.c
blob1332e8a89f69f0f06d96c362cb972e9a7524006c
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 /* We expect less than a second for relocation. */
97 #ifdef HP_SMALL_TIMING_AVAIL
98 # undef HP_TIMING_AVAIL
99 # define HP_TIMING_AVAIL HP_SMALL_TIMING_AVAIL
100 #endif
102 /* Initial value of the CPU clock. */
103 #ifndef HP_TIMING_NONAVAIL
104 hp_timing_t _dl_cpuclock_offset;
105 #endif
107 /* During the program run we must not modify the global data of
108 loaded shared object simultanously in two threads. Therefore we
109 protect `_dl_open' and `_dl_close' in dl-close.c.
111 This must be a recursive lock since the initializer function of
112 the loaded object might as well require a call to this function.
113 At this time it is not anymore a problem to modify the tables. */
114 __libc_lock_define_initialized_recursive (, _dl_load_lock)
117 #ifdef HAVE_AUX_VECTOR
118 extern int _dl_clktck;
120 void
121 internal_function
122 _dl_aux_init (ElfW(auxv_t) *av)
124 for (; av->a_type != AT_NULL; ++av)
125 switch (av->a_type)
127 case AT_PAGESZ:
128 _dl_pagesize = av->a_un.a_val;
129 break;
130 case AT_CLKTCK:
131 _dl_clktck = av->a_un.a_val;
132 break;
135 #endif
137 static void non_dynamic_init (void) __attribute__ ((unused));
139 static void
140 non_dynamic_init (void)
142 if (HP_TIMING_AVAIL)
143 HP_TIMING_NOW (_dl_cpuclock_offset);
145 if (!_dl_pagesize)
146 _dl_pagesize = __getpagesize ();
148 _dl_verbose = *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1;
150 /* Initialize the data structures for the search paths for shared
151 objects. */
152 _dl_init_paths (getenv ("LD_LIBRARY_PATH"));
154 _dl_lazy = *(getenv ("LD_BIND_NOW") ?: "") == '\0';
156 _dl_bind_not = *(getenv ("LD_BIND_NOT") ?: "") != '\0';
158 _dl_dynamic_weak = *(getenv ("LD_DYNAMIC_WEAK") ?: "") == '\0';
160 if (__libc_enable_secure)
162 static const char *unsecure_envvars[] =
164 UNSECURE_ENVVARS,
165 #ifdef EXTRA_UNSECURE_ENVVARS
166 EXTRA_UNSECURE_ENVVARS
167 #endif
169 size_t cnt;
171 for (cnt = 0;
172 cnt < sizeof (unsecure_envvars) / sizeof (unsecure_envvars[0]);
173 ++cnt)
174 unsetenv (unsecure_envvars[cnt]);
176 if (__access ("/etc/suid-debug", F_OK) != 0)
177 unsetenv ("MALLOC_CHECK_");
180 #ifdef DL_PLATFORM_INIT
181 DL_PLATFORM_INIT;
182 #endif
184 /* Now determine the length of the platform string. */
185 if (_dl_platform != NULL)
186 _dl_platformlen = strlen (_dl_platform);
188 text_set_element (__libc_subinit, non_dynamic_init);
190 const struct r_strlenpair *
191 internal_function
192 _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
193 size_t *max_capstrlen)
195 static struct r_strlenpair result;
196 static char buf[1];
198 result.str = buf; /* Does not really matter. */
199 result.len = 0;
201 *sz = 1;
202 return &result;