author | Rod Evans <Rod.Evans@Sun.COM> |
Wed, 19 May 2010 22:33:49 -0700 | |
changeset 12449 | a87750d92895 |
parent 6387 | 4977cc444d39 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1618
8c9a4f31d225
6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents:
0
diff
changeset
|
5 |
* Common Development and Distribution License (the "License"). |
8c9a4f31d225
6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents:
0
diff
changeset
|
6 |
* You may not use this file except in compliance with the License. |
0 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
1618
8c9a4f31d225
6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents:
0
diff
changeset
|
21 |
|
0 | 22 |
/* |
12449
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
23 |
* Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 24 |
* |
25 |
* Update any dynamic entry offsets. One issue with dynamic entries is that |
|
26 |
* you only know whether they refer to a value or an offset if you know each |
|
27 |
* type. Thus we check for all types we know about, it a type is found that |
|
28 |
* we don't know about then return and error as we have no idea what to do. |
|
29 |
*/ |
|
30 |
||
31 |
#include <libelf.h> |
|
32 |
#include <link.h> |
|
33 |
#include "libld.h" |
|
34 |
#include "msg.h" |
|
35 |
#include "rtld.h" |
|
36 |
#include "_librtld.h" |
|
37 |
||
38 |
int |
|
1618
8c9a4f31d225
6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents:
0
diff
changeset
|
39 |
update_dynamic(Cache *cache, Cache *_cache, Rt_map *lmp, int flags, |
0 | 40 |
Addr addr, Off off, const char *file, Xword null, Xword data, Xword func, |
41 |
Xword entsize, Xword checksum) |
|
42 |
{ |
|
1618
8c9a4f31d225
6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents:
0
diff
changeset
|
43 |
Dyn *dyn = (Dyn *)_cache->c_data->d_buf, *posdyn = 0; |
0 | 44 |
const char *strs; |
1618
8c9a4f31d225
6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents:
0
diff
changeset
|
45 |
Cache *__cache; |
0 | 46 |
|
47 |
/* |
|
48 |
* If we're dealing with an object that might have bound to an external |
|
49 |
* dependency establish our string table for possible NEEDED processing. |
|
50 |
*/ |
|
51 |
if (flags & RTLD_REL_DEPENDS) { |
|
52 |
__cache = &cache[_cache->c_shdr->sh_link]; |
|
53 |
strs = (const char *)__cache->c_data->d_buf; |
|
54 |
} |
|
55 |
||
56 |
/* |
|
57 |
* Loop through the dynamic table updating all offsets. |
|
58 |
*/ |
|
59 |
while (dyn->d_tag != DT_NULL) { |
|
12449
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
60 |
Rt_map *dlmp; |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
61 |
|
0 | 62 |
switch ((Xword)dyn->d_tag) { |
63 |
case DT_NEEDED: |
|
12449
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
64 |
if (posdyn == 0) |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
65 |
break; |
0 | 66 |
|
12449
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
67 |
/* |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
68 |
* Determine whether this dependency has been loaded |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
69 |
* (this is the most generic way to check any alias |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
70 |
* names), and if it has been bound to, undo any |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
71 |
* lazy-loading or deferred position flag. |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
72 |
*/ |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
73 |
if (dlmp = is_so_loaded(LIST(lmp), |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
74 |
(strs + dyn->d_un.d_val), NULL)) { |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
75 |
Bnd_desc *bdp; |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
76 |
Aliste idx; |
0 | 77 |
|
12449
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
78 |
for (APLIST_TRAVERSE(DEPENDS(lmp), idx, bdp)) { |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
79 |
if (dlmp != bdp->b_depend) |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
80 |
continue; |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
81 |
|
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
82 |
posdyn->d_un.d_val &= |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
83 |
~(DF_P1_LAZYLOAD | DF_P1_DEFERRED); |
a87750d92895
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents:
6387
diff
changeset
|
84 |
break; |
0 | 85 |
} |
86 |
} |
|
87 |
break; |
|
88 |
||
89 |
case DT_RELAENT: |
|
90 |
case DT_STRSZ: |
|
91 |
case DT_SYMENT: |
|
92 |
case DT_SONAME: |
|
93 |
case DT_RPATH: |
|
94 |
case DT_SYMBOLIC: |
|
95 |
case DT_RELENT: |
|
96 |
case DT_PLTREL: |
|
97 |
case DT_TEXTREL: |
|
98 |
case DT_VERDEFNUM: |
|
99 |
case DT_VERNEEDNUM: |
|
100 |
case DT_AUXILIARY: |
|
101 |
case DT_USED: |
|
102 |
case DT_FILTER: |
|
103 |
case DT_DEPRECATED_SPARC_REGISTER: |
|
104 |
case M_DT_REGISTER: |
|
105 |
case DT_BIND_NOW: |
|
106 |
case DT_INIT_ARRAYSZ: |
|
107 |
case DT_FINI_ARRAYSZ: |
|
108 |
case DT_RUNPATH: |
|
109 |
case DT_FLAGS: |
|
110 |
case DT_CONFIG: |
|
111 |
case DT_DEPAUDIT: |
|
112 |
case DT_AUDIT: |
|
2766
897bcb036a29
PSARC 2006/526 SHT_SUNW_LDYNSYM - default local symbol addition
ab196087
parents:
1618
diff
changeset
|
113 |
case DT_SUNW_SYMSZ: |
0 | 114 |
break; |
115 |
case DT_PLTGOT: |
|
116 |
case DT_HASH: |
|
117 |
case DT_STRTAB: |
|
118 |
case DT_SYMTAB: |
|
2766
897bcb036a29
PSARC 2006/526 SHT_SUNW_LDYNSYM - default local symbol addition
ab196087
parents:
1618
diff
changeset
|
119 |
case DT_SUNW_SYMTAB: |
0 | 120 |
case DT_INIT: |
121 |
case DT_FINI: |
|
122 |
case DT_VERSYM: |
|
123 |
case DT_VERDEF: |
|
124 |
case DT_VERNEED: |
|
125 |
case DT_INIT_ARRAY: |
|
126 |
case DT_FINI_ARRAY: |
|
127 |
dyn->d_un.d_ptr += addr; |
|
128 |
break; |
|
129 |
||
130 |
/* |
|
131 |
* If the memory image is being used, this element would have |
|
132 |
* been initialized to the runtime linkers internal link-map |
|
133 |
* list. Clear it. |
|
134 |
*/ |
|
135 |
case DT_DEBUG: |
|
136 |
dyn->d_un.d_val = 0; |
|
137 |
break; |
|
138 |
||
139 |
/* |
|
140 |
* The number of relocations may have been reduced if |
|
141 |
* relocations have been saved in the new image. Thus we |
|
142 |
* compute the new relocation size and start. |
|
143 |
*/ |
|
144 |
case DT_RELASZ: |
|
145 |
case DT_RELSZ: |
|
146 |
dyn->d_un.d_val = ((data + func) * entsize); |
|
147 |
break; |
|
148 |
||
149 |
case DT_RELA: |
|
150 |
case DT_REL: |
|
151 |
dyn->d_un.d_ptr = (addr + off + (null * entsize)); |
|
152 |
break; |
|
153 |
||
154 |
/* |
|
155 |
* If relative relocations have been processed clear the count. |
|
156 |
*/ |
|
157 |
case DT_RELACOUNT: |
|
158 |
case DT_RELCOUNT: |
|
159 |
if (flags & RTLD_REL_RELATIVE) |
|
160 |
dyn->d_un.d_val = 0; |
|
161 |
break; |
|
162 |
||
163 |
case DT_PLTRELSZ: |
|
164 |
dyn->d_un.d_val = (func * entsize); |
|
165 |
break; |
|
166 |
||
167 |
case DT_JMPREL: |
|
168 |
dyn->d_un.d_ptr = (addr + off + |
|
5892
b863dde33f1b
6492726 Merge SHF_MERGE|SHF_STRINGS input sections
ab196087
parents:
3787
diff
changeset
|
169 |
((null + data) * entsize)); |
0 | 170 |
break; |
171 |
||
172 |
/* |
|
173 |
* Recompute the images elf checksum. |
|
174 |
*/ |
|
175 |
case DT_CHECKSUM: |
|
176 |
dyn->d_un.d_val = checksum; |
|
177 |
break; |
|
178 |
||
179 |
/* |
|
180 |
* If a flag entry is available, indicate if this image has |
|
181 |
* been generated via the configuration process (crle(1)). |
|
182 |
* Because we only started depositing DT_FLAGS_1 entries in all |
|
183 |
* objects starting with Solaris 8, set a feature flag if it |
|
184 |
* is present (these got added in Solaris 7). |
|
185 |
* The runtime linker may use this flag to search for a local |
|
186 |
* configuration file - this is only meaningful in executables |
|
187 |
* but the flag has value for identifying images regardless. |
|
188 |
* |
|
189 |
* If this file is acting as a filter, and dependency |
|
190 |
* relocations have been processed (a filter is thought of as a |
|
191 |
* dependency in terms of symbol binding), we may have bound to |
|
192 |
* the filtee, and hence carried out the relocation. Indicate |
|
193 |
* that the filtee must be preloaded, as the .plt won't get |
|
194 |
* exercised to cause its normal loading. |
|
195 |
*/ |
|
196 |
case DT_FLAGS_1: |
|
197 |
if (flags & RTLD_CONFSET) |
|
198 |
dyn->d_un.d_val |= DF_1_CONFALT; |
|
199 |
if ((flags & RTLD_REL_DEPENDS) && |
|
200 |
(FLAGS1(lmp)) & MSK_RT_FILTER) |
|
201 |
dyn->d_un.d_val |= DF_1_LOADFLTR; |
|
202 |
break; |
|
203 |
||
204 |
case DT_FEATURE_1: |
|
205 |
if (flags & RTLD_CONFSET) |
|
206 |
dyn->d_un.d_val |= DTF_1_CONFEXP; |
|
207 |
break; |
|
208 |
||
209 |
/* |
|
210 |
* If a position flag is available save it for possible update |
|
211 |
* when processing the next NEEDED tag. |
|
212 |
*/ |
|
213 |
case DT_POSFLAG_1: |
|
214 |
if (flags & RTLD_REL_DEPENDS) { |
|
215 |
posdyn = dyn++; |
|
216 |
continue; |
|
217 |
} |
|
218 |
break; |
|
219 |
||
220 |
/* |
|
221 |
* Collect the defaults. |
|
222 |
*/ |
|
223 |
default: |
|
224 |
/* |
|
225 |
* If d_val is used, don't touch. |
|
226 |
*/ |
|
227 |
if ((dyn->d_tag >= DT_VALRNGLO) && |
|
228 |
(dyn->d_tag <= DT_VALRNGHI)) |
|
229 |
break; |
|
230 |
||
231 |
/* |
|
232 |
* If d_ptr is used, adjust. Note, some entries that |
|
233 |
* fell into this range are offsets into the dynamic |
|
234 |
* string table. Although these would need modifying |
|
235 |
* if the section itself were resized, there is no |
|
236 |
* resizing with dldump(). Entries that correspond to |
|
237 |
* offsets are picked off in the initial DT_ loop |
|
238 |
* above. |
|
239 |
*/ |
|
240 |
if ((dyn->d_tag >= DT_ADDRRNGLO) && |
|
241 |
(dyn->d_tag <= DT_ADDRRNGHI)) { |
|
242 |
dyn->d_un.d_ptr += addr; |
|
243 |
break; |
|
244 |
} |
|
245 |
||
246 |
/* |
|
247 |
* Check to see if this DT_ entry conforms |
|
248 |
* to the DT_ENCODING rules. |
|
249 |
*/ |
|
250 |
if ((dyn->d_tag >= DT_ENCODING) && |
|
251 |
(dyn->d_tag <= DT_HIOS)) { |
|
252 |
/* |
|
253 |
* Even tag values are ADDRESS encodings |
|
254 |
*/ |
|
255 |
if ((dyn->d_tag % 2) == 0) { |
|
256 |
dyn->d_un.d_ptr += addr; |
|
257 |
} |
|
258 |
break; |
|
259 |
} |
|
1618
8c9a4f31d225
6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents:
0
diff
changeset
|
260 |
eprintf(LIST(lmp), ERR_WARNING, |
8c9a4f31d225
6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents:
0
diff
changeset
|
261 |
MSG_INTL(MSG_DT_UNKNOWN), file, |
0 | 262 |
EC_XWORD(dyn->d_tag)); |
263 |
return (1); |
|
264 |
} |
|
265 |
posdyn = 0; |
|
266 |
dyn++; |
|
267 |
} |
|
268 |
return (0); |
|
269 |
} |