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. |
---|
4 | |
---|
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. |
---|
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 | Lesser General Public License for more details. |
---|
14 | |
---|
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. */ |
---|
19 | |
---|
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. */ |
---|
22 | |
---|
23 | #include <errno.h> |
---|
24 | #include <libintl.h> |
---|
25 | #include <stdlib.h> |
---|
26 | #include <unistd.h> |
---|
27 | #include <dirent.h> |
---|
28 | #include <pthread.h> |
---|
29 | #include <ldsodefs.h> |
---|
30 | #include <machine/dl-machine.h> |
---|
31 | #include <dl-librecon.h> |
---|
32 | #include <unsecvars.h> |
---|
33 | #include <machine/hp-timing.h> |
---|
34 | |
---|
35 | char *__progname = "newlib"; |
---|
36 | char **_dl_argv = &__progname; /* This is checked for some error messages. */ |
---|
37 | |
---|
38 | /* Name of the architecture. */ |
---|
39 | const char *_dl_platform; |
---|
40 | size_t _dl_platformlen; |
---|
41 | |
---|
42 | int _dl_debug_mask; |
---|
43 | int _dl_lazy; |
---|
44 | /* XXX I know about at least one case where we depend on the old weak |
---|
45 | behavior (it has to do with librt). Until we get DSO groups implemented |
---|
46 | we have to make this the default. Bummer. --drepper */ |
---|
47 | #if 0 |
---|
48 | int _dl_dynamic_weak; |
---|
49 | #else |
---|
50 | int _dl_dynamic_weak = 1; |
---|
51 | #endif |
---|
52 | |
---|
53 | /* If nonzero print warnings about problematic situations. */ |
---|
54 | int _dl_verbose; |
---|
55 | |
---|
56 | /* Structure to store information about search paths. */ |
---|
57 | struct r_search_path *_dl_search_paths; |
---|
58 | |
---|
59 | /* We never do profiling. */ |
---|
60 | const char *_dl_profile; |
---|
61 | |
---|
62 | /* Names of shared object for which the RUNPATHs and RPATHs should be |
---|
63 | ignored. */ |
---|
64 | const char *_dl_inhibit_rpath; |
---|
65 | |
---|
66 | /* The map for the object we will profile. */ |
---|
67 | struct link_map *_dl_profile_map; |
---|
68 | |
---|
69 | /* This is the address of the last stack address ever used. */ |
---|
70 | void *__libc_stack_end; |
---|
71 | |
---|
72 | /* Path where the binary is found. */ |
---|
73 | const char *_dl_origin_path; |
---|
74 | |
---|
75 | /* Nonzero if runtime lookup should not update the .got/.plt. */ |
---|
76 | int _dl_bind_not; |
---|
77 | |
---|
78 | /* Initially empty list of loaded objects. */ |
---|
79 | struct link_map *_dl_loaded; |
---|
80 | /* Number of object in the _dl_loaded list. */ |
---|
81 | unsigned int _dl_nloaded; |
---|
82 | |
---|
83 | /* Fake scope. In dynamically linked binaries this is the scope of the |
---|
84 | main application but here we don't have something like this. So |
---|
85 | create a fake scope containing nothing. */ |
---|
86 | struct r_scope_elem _dl_initial_searchlist; |
---|
87 | /* Variable which can be used in lookup to process the global scope. */ |
---|
88 | struct r_scope_elem *_dl_global_scope[2] = { &_dl_initial_searchlist, NULL }; |
---|
89 | /* This is a global pointer to this structure which is public. It is |
---|
90 | used by dlopen/dlclose to add and remove objects from what is regarded |
---|
91 | to be the global scope. */ |
---|
92 | struct r_scope_elem *_dl_main_searchlist = &_dl_initial_searchlist; |
---|
93 | |
---|
94 | /* Nonzero during startup. */ |
---|
95 | int _dl_starting_up = 1; |
---|
96 | |
---|
97 | /* We expect less than a second for relocation. */ |
---|
98 | #ifdef HP_SMALL_TIMING_AVAIL |
---|
99 | # undef HP_TIMING_AVAIL |
---|
100 | # define HP_TIMING_AVAIL HP_SMALL_TIMING_AVAIL |
---|
101 | #endif |
---|
102 | |
---|
103 | /* Initial value of the CPU clock. */ |
---|
104 | #ifndef HP_TIMING_NONAVAIL |
---|
105 | hp_timing_t _dl_cpuclock_offset; |
---|
106 | #endif |
---|
107 | |
---|
108 | /* During the program run we must not modify the global data of |
---|
109 | loaded shared object simultanously in two threads. Therefore we |
---|
110 | protect `_dl_open' and `_dl_close' in dl-close.c. |
---|
111 | |
---|
112 | This must be a recursive lock since the initializer function of |
---|
113 | the loaded object might as well require a call to this function. |
---|
114 | At this time it is not anymore a problem to modify the tables. */ |
---|
115 | __LOCK_INIT_RECURSIVE(, _dl_load_lock) |
---|
116 | |
---|
117 | |
---|
118 | #ifdef HAVE_AUX_VECTOR |
---|
119 | extern int _dl_clktck; |
---|
120 | |
---|
121 | void |
---|
122 | internal_function |
---|
123 | _dl_aux_init (ElfW(auxv_t) *av) |
---|
124 | { |
---|
125 | for (; av->a_type != AT_NULL; ++av) |
---|
126 | switch (av->a_type) |
---|
127 | { |
---|
128 | case AT_PAGESZ: |
---|
129 | _dl_pagesize = av->a_un.a_val; |
---|
130 | break; |
---|
131 | case AT_CLKTCK: |
---|
132 | _dl_clktck = av->a_un.a_val; |
---|
133 | break; |
---|
134 | } |
---|
135 | } |
---|
136 | #endif |
---|
137 | |
---|
138 | void non_dynamic_init (void) __attribute__ ((unused)); |
---|
139 | |
---|
140 | void |
---|
141 | non_dynamic_init (void) |
---|
142 | { |
---|
143 | if (HP_TIMING_AVAIL) |
---|
144 | HP_TIMING_NOW (_dl_cpuclock_offset); |
---|
145 | |
---|
146 | if (!_dl_pagesize) |
---|
147 | _dl_pagesize = __getpagesize (); |
---|
148 | |
---|
149 | _dl_verbose = *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1; |
---|
150 | |
---|
151 | /* Initialize the data structures for the search paths for shared |
---|
152 | objects. */ |
---|
153 | _dl_init_paths (getenv ("LD_LIBRARY_PATH")); |
---|
154 | |
---|
155 | _dl_lazy = *(getenv ("LD_BIND_NOW") ?: "") == '\0'; |
---|
156 | |
---|
157 | _dl_bind_not = *(getenv ("LD_BIND_NOT") ?: "") != '\0'; |
---|
158 | |
---|
159 | _dl_dynamic_weak = *(getenv ("LD_DYNAMIC_WEAK") ?: "") == '\0'; |
---|
160 | |
---|
161 | #ifdef DL_PLATFORM_INIT |
---|
162 | DL_PLATFORM_INIT; |
---|
163 | #endif |
---|
164 | |
---|
165 | /* Now determine the length of the platform string. */ |
---|
166 | if (_dl_platform != NULL) |
---|
167 | _dl_platformlen = strlen (_dl_platform); |
---|
168 | } |
---|
169 | text_set_element (__libc_subinit, non_dynamic_init); |
---|
170 | |
---|
171 | const struct r_strlenpair * |
---|
172 | internal_function |
---|
173 | _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz, |
---|
174 | size_t *max_capstrlen) |
---|
175 | { |
---|
176 | static struct r_strlenpair result; |
---|
177 | static char buf[1]; |
---|
178 | |
---|
179 | result.str = buf; /* Does not really matter. */ |
---|
180 | result.len = 0; |
---|
181 | |
---|
182 | *sz = 1; |
---|
183 | return &result; |
---|
184 | } |
---|