Print this page
3638 ld confuses files with group sections and files that should lazy load
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sgs/libld/common/files.c
+++ new/usr/src/cmd/sgs/libld/common/files.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1988 AT&T
24 24 * All Rights Reserved
25 25 *
26 26 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
27 27 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
28 28 */
29 29
30 30 /*
31 31 * Processing of relocatable objects and shared objects.
32 32 */
33 33
34 34 #define ELF_TARGET_AMD64
35 35 #define ELF_TARGET_SPARC
36 36
37 37 #include <stdio.h>
38 38 #include <string.h>
39 39 #include <fcntl.h>
40 40 #include <unistd.h>
41 41 #include <link.h>
42 42 #include <limits.h>
43 43 #include <sys/stat.h>
44 44 #include <sys/systeminfo.h>
45 45 #include <debug.h>
46 46 #include <msg.h>
47 47 #include <_libld.h>
48 48
49 49 /*
50 50 * Decide if we can link against this input file.
51 51 */
52 52 static int
53 53 ifl_verify(Ehdr *ehdr, Ofl_desc *ofl, Rej_desc *rej)
54 54 {
55 55 /*
56 56 * Check the validity of the elf header information for compatibility
57 57 * with this machine and our own internal elf library.
58 58 */
59 59 if ((ehdr->e_machine != ld_targ.t_m.m_mach) &&
60 60 ((ehdr->e_machine != ld_targ.t_m.m_machplus) &&
61 61 ((ehdr->e_flags & ld_targ.t_m.m_flagsplus) == 0))) {
62 62 rej->rej_type = SGS_REJ_MACH;
63 63 rej->rej_info = (uint_t)ehdr->e_machine;
64 64 return (0);
65 65 }
66 66 if (ehdr->e_ident[EI_DATA] != ld_targ.t_m.m_data) {
67 67 rej->rej_type = SGS_REJ_DATA;
68 68 rej->rej_info = (uint_t)ehdr->e_ident[EI_DATA];
69 69 return (0);
70 70 }
71 71 if (ehdr->e_version > ofl->ofl_dehdr->e_version) {
72 72 rej->rej_type = SGS_REJ_VERSION;
73 73 rej->rej_info = (uint_t)ehdr->e_version;
74 74 return (0);
75 75 }
76 76 return (1);
77 77 }
78 78
79 79 /*
80 80 * Check sanity of file header and allocate an infile descriptor
81 81 * for the file being processed.
82 82 */
83 83 static Ifl_desc *
84 84 ifl_setup(const char *name, Ehdr *ehdr, Elf *elf, Word flags, Ofl_desc *ofl,
85 85 Rej_desc *rej)
86 86 {
87 87 Ifl_desc *ifl;
88 88 Rej_desc _rej = { 0 };
89 89
90 90 if (ifl_verify(ehdr, ofl, &_rej) == 0) {
91 91 _rej.rej_name = name;
92 92 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
93 93 ld_targ.t_m.m_mach));
94 94 if (rej->rej_type == 0) {
95 95 *rej = _rej;
96 96 rej->rej_name = strdup(_rej.rej_name);
97 97 }
98 98 return (0);
99 99 }
100 100
101 101 if ((ifl = libld_calloc(1, sizeof (Ifl_desc))) == NULL)
102 102 return ((Ifl_desc *)S_ERROR);
103 103 ifl->ifl_name = name;
104 104 ifl->ifl_ehdr = ehdr;
105 105 ifl->ifl_elf = elf;
106 106 ifl->ifl_flags = flags;
107 107
108 108 /*
109 109 * Is this file using 'extended Section Indexes'. If so, use the
110 110 * e_shnum & e_shstrndx which can be found at:
111 111 *
112 112 * e_shnum == Shdr[0].sh_size
113 113 * e_shstrndx == Shdr[0].sh_link
114 114 */
115 115 if ((ehdr->e_shnum == 0) && (ehdr->e_shoff != 0)) {
116 116 Elf_Scn *scn;
117 117 Shdr *shdr0;
118 118
119 119 if ((scn = elf_getscn(elf, 0)) == NULL) {
120 120 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN),
121 121 name);
122 122 return ((Ifl_desc *)S_ERROR);
123 123 }
124 124 if ((shdr0 = elf_getshdr(scn)) == NULL) {
125 125 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR),
126 126 name);
127 127 return ((Ifl_desc *)S_ERROR);
128 128 }
129 129 ifl->ifl_shnum = (Word)shdr0->sh_size;
130 130 if (ehdr->e_shstrndx == SHN_XINDEX)
131 131 ifl->ifl_shstrndx = shdr0->sh_link;
132 132 else
133 133 ifl->ifl_shstrndx = ehdr->e_shstrndx;
134 134 } else {
135 135 ifl->ifl_shnum = ehdr->e_shnum;
136 136 ifl->ifl_shstrndx = ehdr->e_shstrndx;
137 137 }
138 138
139 139 if ((ifl->ifl_isdesc = libld_calloc(ifl->ifl_shnum,
140 140 sizeof (Is_desc *))) == NULL)
141 141 return ((Ifl_desc *)S_ERROR);
142 142
143 143 /*
144 144 * Record this new input file on the shared object or relocatable
145 145 * object input file list.
146 146 */
147 147 if (ifl->ifl_ehdr->e_type == ET_DYN) {
148 148 if (aplist_append(&ofl->ofl_sos, ifl, AL_CNT_OFL_LIBS) == NULL)
149 149 return ((Ifl_desc *)S_ERROR);
150 150 } else {
151 151 if (aplist_append(&ofl->ofl_objs, ifl, AL_CNT_OFL_OBJS) == NULL)
152 152 return ((Ifl_desc *)S_ERROR);
153 153 }
154 154
155 155 return (ifl);
156 156 }
157 157
158 158 /*
159 159 * Process a generic section. The appropriate section information is added
160 160 * to the files input descriptor list.
161 161 */
162 162 static uintptr_t
163 163 process_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
164 164 Word ndx, int ident, Ofl_desc *ofl)
165 165 {
166 166 Is_desc *isp;
167 167
168 168 /*
169 169 * Create a new input section descriptor. If this is a NOBITS
170 170 * section elf_getdata() will still create a data buffer (the buffer
171 171 * will be null and the size will reflect the actual memory size).
172 172 */
173 173 if ((isp = libld_calloc(sizeof (Is_desc), 1)) == NULL)
174 174 return (S_ERROR);
175 175 isp->is_shdr = shdr;
176 176 isp->is_file = ifl;
177 177 isp->is_name = name;
178 178 isp->is_scnndx = ndx;
179 179 isp->is_flags = FLG_IS_EXTERNAL;
180 180 isp->is_keyident = ident;
181 181
182 182 if ((isp->is_indata = elf_getdata(scn, NULL)) == NULL) {
183 183 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETDATA),
184 184 ifl->ifl_name);
185 185 return (0);
186 186 }
187 187
188 188 if ((shdr->sh_flags & SHF_EXCLUDE) &&
189 189 ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0)) {
190 190 isp->is_flags |= FLG_IS_DISCARD;
191 191 }
192 192
193 193 /*
194 194 * Add the new input section to the files input section list and
195 195 * flag whether the section needs placing in an output section. This
196 196 * placement is deferred until all input section processing has been
197 197 * completed, as SHT_GROUP sections can provide information that will
198 198 * affect how other sections within the file should be placed.
199 199 */
200 200 ifl->ifl_isdesc[ndx] = isp;
201 201
202 202 if (ident) {
203 203 if (shdr->sh_flags & ALL_SHF_ORDER) {
204 204 isp->is_flags |= FLG_IS_ORDERED;
205 205 ifl->ifl_flags |= FLG_IF_ORDERED;
206 206 }
207 207 isp->is_flags |= FLG_IS_PLACE;
208 208 }
209 209 return (1);
210 210 }
211 211
212 212 /*
213 213 * Determine the software capabilities of the object being built from the
214 214 * capabilities of the input relocatable objects. One software capability
215 215 * is presently recognized, and represented with the following (sys/elf.h):
216 216 *
217 217 * SF1_SUNW_FPKNWN use/non-use of frame pointer is known, and
218 218 * SF1_SUNW_FPUSED the frame pointer is in use.
219 219 *
220 220 * The resolution of the present fame pointer state, and the capabilities
221 221 * provided by a new input relocatable object are:
222 222 *
223 223 * new input relocatable object
224 224 *
225 225 * present | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown>
226 226 * state | SF1_SUNW_FPUSED | |
227 227 * ---------------------------------------------------------------------------
228 228 * SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN
229 229 * SF1_SUNW_FPUSED | SF1_SUNW_FPUSED | | SF1_SUNW_FPUSED
230 230 * ---------------------------------------------------------------------------
231 231 * SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN
232 232 * | | |
233 233 * ---------------------------------------------------------------------------
234 234 * <unknown> | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown>
235 235 * | SF1_SUNW_FPUSED | |
236 236 */
237 237 static void
238 238 sf1_cap(Ofl_desc *ofl, Xword val, Ifl_desc *ifl, Is_desc *cisp)
239 239 {
240 240 #define FP_FLAGS (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)
241 241
242 242 Xword badval;
243 243
244 244 /*
245 245 * If a mapfile has established definitions to override any object
246 246 * capabilities, ignore any new object capabilities.
247 247 */
248 248 if (ofl->ofl_flags1 & FLG_OF1_OVSFCAP1) {
249 249 DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
250 250 CA_SUNW_SF_1, val, ld_targ.t_m.m_mach));
251 251 return;
252 252 }
253 253
254 254 #if !defined(_ELF64)
255 255 if (ifl && (ifl->ifl_ehdr->e_type == ET_REL)) {
256 256 /*
257 257 * The SF1_SUNW_ADDR32 is only meaningful when building a 64-bit
258 258 * object. Warn the user, and remove the setting, if we're
259 259 * building a 32-bit object.
260 260 */
261 261 if (val & SF1_SUNW_ADDR32) {
262 262 ld_eprintf(ofl, ERR_WARNING,
263 263 MSG_INTL(MSG_FIL_INADDR32SF1), ifl->ifl_name,
264 264 EC_WORD(cisp->is_scnndx), cisp->is_name);
265 265 val &= ~SF1_SUNW_ADDR32;
266 266 }
267 267 }
268 268 #endif
269 269 /*
270 270 * If this object doesn't specify any capabilities, ignore it, and
271 271 * leave the state as is.
272 272 */
273 273 if (val == 0)
274 274 return;
275 275
276 276 /*
277 277 * Make sure we only accept known software capabilities. Note, that
278 278 * an F1_SUNW_FPUSED by itself is viewed as bad practice.
279 279 */
280 280 if ((badval = (val & ~SF1_SUNW_MASK)) != 0) {
281 281 ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1),
282 282 ifl->ifl_name, EC_WORD(cisp->is_scnndx), cisp->is_name,
283 283 EC_XWORD(badval));
284 284 val &= SF1_SUNW_MASK;
285 285 }
286 286 if ((val & FP_FLAGS) == SF1_SUNW_FPUSED) {
287 287 ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1),
288 288 ifl->ifl_name, EC_WORD(cisp->is_scnndx), cisp->is_name,
289 289 EC_XWORD(val));
290 290 return;
291 291 }
292 292
293 293 /*
294 294 * If the input file is not a relocatable object, then we're only here
295 295 * to warn the user of any questionable capabilities.
296 296 */
297 297 if (ifl->ifl_ehdr->e_type != ET_REL) {
298 298 #if defined(_ELF64)
299 299 /*
300 300 * If we're building a 64-bit executable, and we come across a
301 301 * dependency that requires a restricted address space, then
302 302 * that dependencies requirement can only be satisfied if the
303 303 * executable triggers the restricted address space. This is a
304 304 * warning rather than a fatal error, as the possibility exists
305 305 * that an appropriate dependency will be provided at runtime.
306 306 * The runtime linker will refuse to use this dependency.
307 307 */
308 308 if ((val & SF1_SUNW_ADDR32) && (ofl->ofl_flags & FLG_OF_EXEC) &&
309 309 ((ofl->ofl_ocapset.oc_sf_1.cm_val &
310 310 SF1_SUNW_ADDR32) == 0)) {
311 311 ld_eprintf(ofl, ERR_WARNING,
312 312 MSG_INTL(MSG_FIL_EXADDR32SF1), ifl->ifl_name,
313 313 EC_WORD(cisp->is_scnndx), cisp->is_name);
314 314 }
315 315 #endif
316 316 return;
317 317 }
318 318
319 319 if (DBG_ENABLED) {
320 320 Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_CURRENT, CA_SUNW_SF_1,
321 321 ofl->ofl_ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach);
322 322 Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_NEW, CA_SUNW_SF_1,
323 323 val, ld_targ.t_m.m_mach);
324 324 }
325 325
326 326 /*
327 327 * Determine the resolution of the present frame pointer and the
328 328 * new input relocatable objects frame pointer.
329 329 */
330 330 if ((ofl->ofl_ocapset.oc_sf_1.cm_val & FP_FLAGS) == FP_FLAGS) {
331 331 /*
332 332 * If the new relocatable object isn't using a frame pointer,
333 333 * reduce the present state to unused.
334 334 */
335 335 if ((val & FP_FLAGS) != FP_FLAGS)
336 336 ofl->ofl_ocapset.oc_sf_1.cm_val &= ~SF1_SUNW_FPUSED;
337 337
338 338 /*
339 339 * Having processed the frame pointer bits, remove them from
340 340 * the value so they don't get OR'd in below.
341 341 */
342 342 val &= ~FP_FLAGS;
343 343
344 344 } else if ((ofl->ofl_ocapset.oc_sf_1.cm_val & SF1_SUNW_FPKNWN) == 0) {
345 345 /*
346 346 * If the present frame pointer state is unknown, mask it out
347 347 * and allow the values from the new relocatable object
348 348 * to overwrite them.
349 349 */
350 350 ofl->ofl_ocapset.oc_sf_1.cm_val &= ~FP_FLAGS;
351 351 } else {
352 352 /* Do not take the frame pointer flags from the object */
353 353 val &= ~FP_FLAGS;
354 354 }
355 355
356 356 ofl->ofl_ocapset.oc_sf_1.cm_val |= val;
357 357
358 358 DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_RESOLVED,
359 359 CA_SUNW_SF_1, ofl->ofl_ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach));
360 360
361 361 #undef FP_FLAGS
362 362 }
363 363
364 364 /*
365 365 * Determine the hardware capabilities of the object being built from the
366 366 * capabilities of the input relocatable objects. There's really little to
367 367 * do here, other than to offer diagnostics, hardware capabilities are simply
368 368 * additive.
369 369 */
370 370 static void
371 371 hw_cap(Ofl_desc *ofl, Xword tag, Xword val)
372 372 {
373 373 elfcap_mask_t *hwcap;
374 374 ofl_flag_t flags1;
375 375
376 376 if (tag == CA_SUNW_HW_1) {
377 377 hwcap = &ofl->ofl_ocapset.oc_hw_1.cm_val;
378 378 flags1 = FLG_OF1_OVHWCAP1;
379 379 } else {
380 380 hwcap = &ofl->ofl_ocapset.oc_hw_2.cm_val;
381 381 flags1 = FLG_OF1_OVHWCAP2;
382 382 }
383 383
384 384 /*
385 385 * If a mapfile has established definitions to override any object
386 386 * capabilities, ignore any new object capabilities.
387 387 */
388 388 if (ofl->ofl_flags1 & flags1) {
389 389 DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
390 390 tag, val, ld_targ.t_m.m_mach));
391 391 return;
392 392 }
393 393
394 394 /*
395 395 * If this object doesn't specify any capabilities, ignore it, and
396 396 * leave the state as is.
397 397 */
398 398 if (val == 0)
399 399 return;
400 400
401 401 if (DBG_ENABLED) {
402 402 Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_CURRENT, CA_SUNW_HW_1,
403 403 ofl->ofl_ocapset.oc_hw_1.cm_val, ld_targ.t_m.m_mach);
404 404 Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_NEW, CA_SUNW_HW_1,
405 405 val, ld_targ.t_m.m_mach);
406 406 }
407 407
408 408 *hwcap |= val;
409 409
410 410 DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_RESOLVED, tag,
411 411 *hwcap, ld_targ.t_m.m_mach));
412 412 }
413 413
414 414 /*
415 415 * Promote a machine capability or platform capability to the output file.
416 416 * Multiple instances of these names can be defined.
417 417 */
418 418 static void
419 419 str_cap(Ofl_desc *ofl, char *pstr, ofl_flag_t flags, Xword tag, Caplist *list)
420 420 {
421 421 Capstr *capstr;
422 422 Aliste idx;
423 423 Boolean found = FALSE;
424 424
425 425 /*
426 426 * If a mapfile has established definitions to override this capability,
427 427 * ignore any new capability.
428 428 */
429 429 if (ofl->ofl_flags1 & flags) {
430 430 DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
431 431 tag, pstr));
432 432 return;
433 433 }
434 434
435 435 for (ALIST_TRAVERSE(list->cl_val, idx, capstr)) {
436 436 DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
437 437 DBG_STATE_CURRENT, tag, capstr->cs_str));
438 438 if (strcmp(capstr->cs_str, pstr) == 0)
439 439 found = TRUE;
440 440 }
441 441
442 442 DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_NEW, tag, pstr));
443 443
444 444 if (found == FALSE) {
445 445 if ((capstr = alist_append(&list->cl_val, NULL,
446 446 sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL) {
447 447 ofl->ofl_flags |= FLG_OF_FATAL;
448 448 return;
449 449 }
450 450 capstr->cs_str = pstr;
451 451 }
452 452
453 453 if (DBG_ENABLED) {
454 454 for (ALIST_TRAVERSE(list->cl_val, idx, capstr)) {
455 455 DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
456 456 DBG_STATE_RESOLVED, tag, capstr->cs_str));
457 457 }
458 458 }
459 459 }
460 460
461 461 /*
462 462 * Promote a capability identifier to the output file. A capability group can
463 463 * only have one identifier, and thus only the first identifier seen from any
464 464 * input relocatable objects is retained. An explicit user defined identifier,
465 465 * rather than an an identifier fabricated by ld(1) with -z symbcap processing,
466 466 * takes precedence. Note, a user may have defined an identifier via a mapfile,
467 467 * in which case the mapfile identifier is retained.
468 468 */
469 469 static void
470 470 id_cap(Ofl_desc *ofl, char *pstr, oc_flag_t flags)
471 471 {
472 472 Objcapset *ocapset = &ofl->ofl_ocapset;
473 473
474 474 if (ocapset->oc_id.cs_str) {
475 475 DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_CURRENT,
476 476 CA_SUNW_ID, ocapset->oc_id.cs_str));
477 477
478 478 if ((ocapset->oc_flags & FLG_OCS_USRDEFID) ||
479 479 ((flags & FLG_OCS_USRDEFID) == 0)) {
480 480 DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
481 481 DBG_STATE_IGNORED, CA_SUNW_ID, pstr));
482 482 return;
483 483 }
484 484 }
485 485
486 486 DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_NEW,
487 487 CA_SUNW_ID, pstr));
488 488
489 489 ocapset->oc_id.cs_str = pstr;
490 490 ocapset->oc_flags |= flags;
491 491
492 492 DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_RESOLVED,
493 493 CA_SUNW_ID, pstr));
494 494 }
495 495
496 496 /*
497 497 * Promote a capabilities group to the object capabilities. This catches a
498 498 * corner case. An object capabilities file can be converted to symbol
499 499 * capabilities with -z symbolcap. However, if the user has indicated that all
500 500 * the symbols should be demoted, we'd be left with a symbol capabilities file,
501 501 * with no associated symbols. Catch this case by promoting the symbol
502 502 * capabilities back to object capabilities.
503 503 */
504 504 void
505 505 ld_cap_move_symtoobj(Ofl_desc *ofl)
506 506 {
507 507 Cap_group *cgp;
508 508 Aliste idx1;
509 509
510 510 for (APLIST_TRAVERSE(ofl->ofl_capgroups, idx1, cgp)) {
511 511 Objcapset *scapset = &cgp->cg_set;
512 512 Capstr *capstr;
513 513 Aliste idx2;
514 514
515 515 if (scapset->oc_id.cs_str) {
516 516 if (scapset->oc_flags & FLG_OCS_USRDEFID)
517 517 id_cap(ofl, scapset->oc_id.cs_str,
518 518 scapset->oc_flags);
519 519 }
520 520 if (scapset->oc_plat.cl_val) {
521 521 for (ALIST_TRAVERSE(scapset->oc_plat.cl_val, idx2,
522 522 capstr)) {
523 523 str_cap(ofl, capstr->cs_str, FLG_OF1_OVPLATCAP,
524 524 CA_SUNW_PLAT, &ofl->ofl_ocapset.oc_plat);
525 525 }
526 526 }
527 527 if (scapset->oc_mach.cl_val) {
528 528 for (ALIST_TRAVERSE(scapset->oc_mach.cl_val, idx2,
529 529 capstr)) {
530 530 str_cap(ofl, capstr->cs_str, FLG_OF1_OVMACHCAP,
531 531 CA_SUNW_MACH, &ofl->ofl_ocapset.oc_mach);
532 532 }
533 533 }
534 534 if (scapset->oc_hw_2.cm_val)
535 535 hw_cap(ofl, CA_SUNW_HW_2, scapset->oc_hw_2.cm_val);
536 536
537 537 if (scapset->oc_hw_1.cm_val)
538 538 hw_cap(ofl, CA_SUNW_HW_1, scapset->oc_hw_1.cm_val);
539 539
540 540 if (scapset->oc_sf_1.cm_val)
541 541 sf1_cap(ofl, scapset->oc_sf_1.cm_val, NULL, NULL);
542 542 }
543 543 }
544 544
545 545 /*
546 546 * Determine whether a capabilities group already exists that describes this
547 547 * new capabilities group.
548 548 *
549 549 * Note, a capability group identifier, CA_SUNW_ID, isn't used as part of the
550 550 * comparison. This attribute simply assigns a diagnostic name to the group,
551 551 * and in the case of multiple identifiers, the first will be taken.
552 552 */
553 553 static Cap_group *
554 554 get_cap_group(Objcapset *ocapset, Word cnum, Ofl_desc *ofl, Is_desc *isp)
555 555 {
556 556 Aliste idx;
557 557 Cap_group *cgp;
558 558 Word ccnum = cnum;
559 559
560 560 /*
561 561 * If the new capabilities contains a CA_SUNW_ID, drop the count of the
562 562 * number of comparable items.
563 563 */
564 564 if (ocapset->oc_id.cs_str)
565 565 ccnum--;
566 566
567 567 /*
568 568 * Traverse the existing symbols capabilities groups.
569 569 */
570 570 for (APLIST_TRAVERSE(ofl->ofl_capgroups, idx, cgp)) {
571 571 Word onum = cgp->cg_num;
572 572 Alist *calp, *oalp;
573 573
574 574 if (cgp->cg_set.oc_id.cs_str)
575 575 onum--;
576 576
577 577 if (onum != ccnum)
578 578 continue;
579 579
580 580 if (cgp->cg_set.oc_hw_1.cm_val != ocapset->oc_hw_1.cm_val)
581 581 continue;
582 582 if (cgp->cg_set.oc_sf_1.cm_val != ocapset->oc_sf_1.cm_val)
583 583 continue;
584 584 if (cgp->cg_set.oc_hw_2.cm_val != ocapset->oc_hw_2.cm_val)
585 585 continue;
586 586
587 587 calp = cgp->cg_set.oc_plat.cl_val;
588 588 oalp = ocapset->oc_plat.cl_val;
589 589 if ((calp == NULL) && oalp)
590 590 continue;
591 591 if (calp && ((oalp == NULL) || cap_names_match(calp, oalp)))
592 592 continue;
593 593
594 594 calp = cgp->cg_set.oc_mach.cl_val;
595 595 oalp = ocapset->oc_mach.cl_val;
596 596 if ((calp == NULL) && oalp)
597 597 continue;
598 598 if (calp && ((oalp == NULL) || cap_names_match(calp, oalp)))
599 599 continue;
600 600
601 601 /*
602 602 * If a matching group is found, then this new group has
603 603 * already been supplied by a previous file, and hence the
604 604 * existing group can be used. Record this new input section,
605 605 * from which we can also derive the input file name, on the
606 606 * existing groups input sections.
607 607 */
608 608 if (aplist_append(&(cgp->cg_secs), isp,
609 609 AL_CNT_CAP_SECS) == NULL)
610 610 return (NULL);
611 611 return (cgp);
612 612 }
613 613
614 614 /*
615 615 * If a capabilities group is not found, create a new one.
616 616 */
617 617 if (((cgp = libld_calloc(sizeof (Cap_group), 1)) == NULL) ||
618 618 (aplist_append(&(ofl->ofl_capgroups), cgp,
619 619 AL_CNT_CAP_DESCS) == NULL))
620 620 return (NULL);
621 621
622 622 /*
623 623 * If we're converting object capabilities to symbol capabilities and
624 624 * no CA_SUNW_ID is defined, fabricate one. This identifier is appended
625 625 * to all symbol names that are converted into capabilities symbols,
626 626 * see ld_sym_process().
627 627 */
628 628 if ((isp->is_file->ifl_flags & FLG_IF_OTOSCAP) &&
629 629 (ocapset->oc_id.cs_str == NULL)) {
630 630 size_t len;
631 631
632 632 /*
633 633 * Create an identifier using the group number together with a
634 634 * default template. We allocate a buffer large enough for any
635 635 * possible number of items (way more than we need).
636 636 */
637 637 len = MSG_STR_CAPGROUPID_SIZE + CONV_INV_BUFSIZE;
638 638 if ((ocapset->oc_id.cs_str = libld_malloc(len)) == NULL)
639 639 return (NULL);
640 640
641 641 (void) snprintf(ocapset->oc_id.cs_str, len,
642 642 MSG_ORIG(MSG_STR_CAPGROUPID),
643 643 aplist_nitems(ofl->ofl_capgroups));
644 644 cnum++;
645 645 }
646 646
647 647 cgp->cg_set = *ocapset;
648 648 cgp->cg_num = cnum;
649 649
650 650 /*
651 651 * Null the callers alist's as they've effectively been transferred
652 652 * to this new Cap_group.
653 653 */
654 654 ocapset->oc_plat.cl_val = ocapset->oc_mach.cl_val = NULL;
655 655
656 656 /*
657 657 * Keep track of which input section, and hence input file, established
658 658 * this group.
659 659 */
660 660 if (aplist_append(&(cgp->cg_secs), isp, AL_CNT_CAP_SECS) == NULL)
661 661 return (NULL);
662 662
663 663 /*
664 664 * Keep track of the number of symbol capabilities entries that will be
665 665 * required in the output file. Each group requires a terminating
666 666 * CA_SUNW_NULL.
667 667 */
668 668 ofl->ofl_capsymcnt += (cnum + 1);
669 669 return (cgp);
670 670 }
671 671
672 672 /*
673 673 * Capture symbol capability family information. This data structure is focal
674 674 * in maintaining all symbol capability relationships, and provides for the
675 675 * eventual creation of a capabilities information section, and possibly a
676 676 * capabilities chain section.
677 677 *
678 678 * Capabilities families are lead by a CAPINFO_SUNW_GLOB symbol. This symbol
679 679 * provides the visible global symbol that is referenced by all external
680 680 * callers. This symbol may have aliases. For example, a weak/global symbol
681 681 * pair, such as memcpy()/_memcpy() may lead the same capabilities family.
682 682 * Each family contains one or more local symbol members. These members provide
683 683 * the capabilities specific functions, and are associated to a capabilities
684 684 * group. For example, the capability members memcpy%sun4u and memcpy%sun4v
685 685 * might be associated with the memcpy() capability family.
686 686 *
687 687 * This routine is called when a relocatable object that provides object
688 688 * capabilities is transformed into a symbol capabilities object, using the
689 689 * -z symbolcap option.
690 690 *
691 691 * This routine is also called to collect the SUNW_capinfo section information
692 692 * of a relocatable object that contains symbol capability definitions.
693 693 */
694 694 uintptr_t
695 695 ld_cap_add_family(Ofl_desc *ofl, Sym_desc *lsdp, Sym_desc *csdp, Cap_group *cgp,
696 696 APlist **csyms)
697 697 {
698 698 Cap_avlnode qcav, *cav;
699 699 avl_tree_t *avlt;
700 700 avl_index_t where = 0;
701 701 Cap_sym *mcsp;
702 702 Aliste idx;
703 703
704 704 /*
705 705 * Make sure the capability families have an initialized AVL tree.
706 706 */
707 707 if ((avlt = ofl->ofl_capfamilies) == NULL) {
708 708 if ((avlt = libld_calloc(sizeof (avl_tree_t), 1)) == NULL)
709 709 return (S_ERROR);
710 710 avl_create(avlt, &ld_sym_avl_comp, sizeof (Cap_avlnode),
711 711 SGSOFFSETOF(Cap_avlnode, cn_symavlnode.sav_node));
712 712 ofl->ofl_capfamilies = avlt;
713 713
714 714 /*
715 715 * When creating a dynamic object, capability family members
716 716 * are maintained in a .SUNW_capchain, the first entry of
717 717 * which is the version number of the chain.
718 718 */
719 719 ofl->ofl_capchaincnt = 1;
720 720 }
721 721
722 722 /*
723 723 * Determine whether a family already exists, and if not, create one
724 724 * using the lead family symbol.
725 725 */
726 726 qcav.cn_symavlnode.sav_hash = (Word)elf_hash(lsdp->sd_name);
727 727 qcav.cn_symavlnode.sav_name = lsdp->sd_name;
728 728
729 729 if ((cav = avl_find(avlt, &qcav, &where)) == NULL) {
730 730 if ((cav = libld_calloc(sizeof (Cap_avlnode), 1)) == NULL)
731 731 return (S_ERROR);
732 732 cav->cn_symavlnode.sav_hash = qcav.cn_symavlnode.sav_hash;
733 733 cav->cn_symavlnode.sav_name = qcav.cn_symavlnode.sav_name;
734 734 cav->cn_symavlnode.sav_sdp = lsdp;
735 735
736 736 avl_insert(avlt, cav, where);
737 737
738 738 /*
739 739 * When creating a dynamic object, capability family members
740 740 * are maintained in a .SUNW_capchain, each family starts with
741 741 * this lead symbol, and is terminated with a 0 element.
742 742 */
743 743 ofl->ofl_capchaincnt += 2;
744 744 }
745 745
746 746 /*
747 747 * If no group information is provided then this request is to add a
748 748 * lead capability symbol, or lead symbol alias. If this is the lead
749 749 * symbol there's nothing more to do. Otherwise save the alias.
750 750 */
751 751 if (cgp == NULL) {
752 752 if ((lsdp != csdp) && (aplist_append(&cav->cn_aliases, csdp,
753 753 AL_CNT_CAP_ALIASES) == NULL))
754 754 return (S_ERROR);
755 755
756 756 return (0);
757 757 }
758 758
759 759 /*
760 760 * Determine whether a member of the same group as this new member is
761 761 * already defined within this family. If so, we have a multiply
762 762 * defined symbol.
763 763 */
764 764 for (APLIST_TRAVERSE(cav->cn_members, idx, mcsp)) {
765 765 Sym_desc *msdp;
766 766
767 767 if (cgp != mcsp->cs_group)
768 768 continue;
769 769
770 770 /*
771 771 * Diagnose that a multiple symbol definition exists.
772 772 */
773 773 msdp = mcsp->cs_sdp;
774 774
775 775 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_CAP_MULDEF),
776 776 demangle(lsdp->sd_name));
777 777 ld_eprintf(ofl, ERR_NONE, MSG_INTL(MSG_CAP_MULDEFSYMS),
778 778 msdp->sd_file->ifl_name, msdp->sd_name,
779 779 csdp->sd_file->ifl_name, csdp->sd_name);
780 780 }
781 781
782 782 /*
783 783 * Add this capabilities symbol member to the family.
784 784 */
785 785 if (((mcsp = libld_malloc(sizeof (Cap_sym))) == NULL) ||
786 786 (aplist_append(&cav->cn_members, mcsp, AL_CNT_CAP_MEMS) == NULL))
787 787 return (S_ERROR);
788 788
789 789 mcsp->cs_sdp = csdp;
790 790 mcsp->cs_group = cgp;
791 791
792 792 /*
793 793 * When creating a dynamic object, capability family members are
794 794 * maintained in a .SUNW_capchain. Account for this family member.
795 795 */
796 796 ofl->ofl_capchaincnt++;
797 797
798 798 /*
799 799 * If this input file is undergoing object capabilities to symbol
800 800 * capabilities conversion, then this member is a new local symbol
801 801 * that has been generated from an original global symbol. Keep track
802 802 * of this symbol so that the output file symbol table can be populated
803 803 * with these new symbol entries.
804 804 */
805 805 if (csyms && (aplist_append(csyms, mcsp, AL_CNT_CAP_SYMS) == NULL))
806 806 return (S_ERROR);
807 807
808 808 return (0);
809 809 }
810 810
811 811 /*
812 812 * Process a SHT_SUNW_cap capabilities section.
813 813 */
814 814 static uintptr_t
815 815 process_cap(Ofl_desc *ofl, Ifl_desc *ifl, Is_desc *cisp)
816 816 {
817 817 Objcapset ocapset = { 0 };
818 818 Cap_desc *cdp;
819 819 Cap *data, *cdata;
820 820 char *strs;
821 821 Word ndx, cnum;
822 822 int objcapndx, descapndx, symcapndx;
823 823 int nulls, capstrs = 0;
824 824
825 825 /*
826 826 * Determine the capabilities data and size.
827 827 */
828 828 cdata = (Cap *)cisp->is_indata->d_buf;
829 829 cnum = (Word)(cisp->is_shdr->sh_size / cisp->is_shdr->sh_entsize);
830 830
831 831 if ((cdata == NULL) || (cnum == 0))
832 832 return (0);
833 833
834 834 DBG_CALL(Dbg_cap_sec_title(ofl->ofl_lml, ifl->ifl_name));
835 835
836 836 /*
837 837 * Traverse the section to determine what capabilities groups are
838 838 * available.
839 839 *
840 840 * A capabilities section can contain one or more, CA_SUNW_NULL
841 841 * terminated groups.
842 842 *
843 843 * - The first group defines the object capabilities.
844 844 * - Additional groups define symbol capabilities.
845 845 * - Since the initial group is always reserved for object
846 846 * capabilities, any object with symbol capabilities must also
847 847 * have an object capabilities group. If the object has no object
848 848 * capabilities, an empty object group is defined, consisting of a
849 849 * CA_SUNW_NULL element in index [0].
850 850 * - If any capabilities require references to a named string, then
851 851 * the section header sh_info points to the associated string
852 852 * table.
853 853 * - If an object contains symbol capability groups, then the
854 854 * section header sh_link points to the associated capinfo table.
855 855 */
856 856 objcapndx = 0;
857 857 descapndx = symcapndx = -1;
858 858 nulls = 0;
859 859
860 860 for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
861 861 switch (data->c_tag) {
862 862 case CA_SUNW_NULL:
863 863 /*
864 864 * If this is the first CA_SUNW_NULL entry, and no
865 865 * capabilities group has been found, then this object
866 866 * does not define any object capabilities.
867 867 */
868 868 if (nulls++ == 0) {
869 869 if (ndx == 0)
870 870 objcapndx = -1;
871 871 } else if ((symcapndx == -1) && (descapndx != -1))
872 872 symcapndx = descapndx;
873 873
874 874 break;
875 875
876 876 case CA_SUNW_PLAT:
877 877 case CA_SUNW_MACH:
878 878 case CA_SUNW_ID:
879 879 capstrs++;
880 880 /* FALLTHROUGH */
881 881
882 882 case CA_SUNW_HW_1:
883 883 case CA_SUNW_SF_1:
884 884 case CA_SUNW_HW_2:
885 885 /*
886 886 * If this is the start of a new group, save it.
887 887 */
888 888 if (descapndx == -1)
889 889 descapndx = ndx;
890 890 break;
891 891
892 892 default:
893 893 ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_UNKCAP),
894 894 ifl->ifl_name, EC_WORD(cisp->is_scnndx),
895 895 cisp->is_name, data->c_tag);
896 896 }
897 897 }
898 898
899 899 /*
900 900 * If a string capabilities entry has been found, the capabilities
901 901 * section must reference the associated string table.
902 902 */
903 903 if (capstrs) {
904 904 Word info = cisp->is_shdr->sh_info;
905 905
906 906 if ((info == 0) || (info > ifl->ifl_shnum)) {
907 907 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHINFO),
908 908 ifl->ifl_name, EC_WORD(cisp->is_scnndx),
909 909 cisp->is_name, EC_XWORD(info));
910 910 return (S_ERROR);
911 911 }
912 912 strs = (char *)ifl->ifl_isdesc[info]->is_indata->d_buf;
913 913 }
914 914
915 915 /*
916 916 * The processing of capabilities groups is as follows:
917 917 *
918 918 * - if a relocatable object provides only object capabilities, and
919 919 * the -z symbolcap option is in effect, then the object
920 920 * capabilities are transformed into symbol capabilities and the
921 921 * symbol capabilities are carried over to the output file.
922 922 * - in all other cases, any capabilities present in an input
923 923 * relocatable object are carried from the input object to the
924 924 * output without any transformation or conversion.
925 925 *
926 926 * Capture any object capabilities that are to be carried over to the
927 927 * output file.
928 928 */
929 929 if ((objcapndx == 0) &&
930 930 ((symcapndx != -1) || ((ofl->ofl_flags & FLG_OF_OTOSCAP) == 0))) {
931 931 for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
932 932 /*
933 933 * Object capabilities end at the first null.
934 934 */
935 935 if (data->c_tag == CA_SUNW_NULL)
936 936 break;
937 937
938 938 /*
939 939 * Only the object software capabilities that are
940 940 * defined in a relocatable object become part of the
941 941 * object software capabilities in the output file.
942 942 * However, check the validity of any object software
943 943 * capabilities of any dependencies.
944 944 */
945 945 if (data->c_tag == CA_SUNW_SF_1) {
946 946 sf1_cap(ofl, data->c_un.c_val, ifl, cisp);
947 947 continue;
948 948 }
949 949
950 950 /*
951 951 * The remaining capability types must come from a
952 952 * relocatable object in order to contribute to the
953 953 * output.
954 954 */
955 955 if (ifl->ifl_ehdr->e_type != ET_REL)
956 956 continue;
957 957
958 958 switch (data->c_tag) {
959 959 case CA_SUNW_HW_1:
960 960 case CA_SUNW_HW_2:
961 961 hw_cap(ofl, data->c_tag, data->c_un.c_val);
962 962 break;
963 963
964 964 case CA_SUNW_PLAT:
965 965 str_cap(ofl, strs + data->c_un.c_ptr,
966 966 FLG_OF1_OVPLATCAP, CA_SUNW_PLAT,
967 967 &ofl->ofl_ocapset.oc_plat);
968 968 break;
969 969
970 970 case CA_SUNW_MACH:
971 971 str_cap(ofl, strs + data->c_un.c_ptr,
972 972 FLG_OF1_OVMACHCAP, CA_SUNW_MACH,
973 973 &ofl->ofl_ocapset.oc_mach);
974 974 break;
975 975
976 976 case CA_SUNW_ID:
977 977 id_cap(ofl, strs + data->c_un.c_ptr,
978 978 FLG_OCS_USRDEFID);
979 979 break;
980 980
981 981 default:
982 982 assert(0); /* Unknown capability type */
983 983 }
984 984 }
985 985
986 986 /*
987 987 * If there are no symbol capabilities, or this objects
988 988 * capabilities aren't being transformed into a symbol
989 989 * capabilities, then we're done.
990 990 */
991 991 if ((symcapndx == -1) &&
992 992 ((ofl->ofl_flags & FLG_OF_OTOSCAP) == 0))
993 993 return (1);
994 994 }
995 995
996 996 /*
997 997 * If these capabilities don't originate from a relocatable object
998 998 * there's no further processing required.
999 999 */
1000 1000 if (ifl->ifl_ehdr->e_type != ET_REL)
1001 1001 return (1);
1002 1002
1003 1003 /*
1004 1004 * If this object only defines an object capabilities group, and the
1005 1005 * -z symbolcap option is in effect, then all global function symbols
1006 1006 * and initialized global data symbols are renamed and assigned to the
1007 1007 * transformed symbol capabilities group.
1008 1008 */
1009 1009 if ((objcapndx == 0) &&
1010 1010 (symcapndx == -1) && (ofl->ofl_flags & FLG_OF_OTOSCAP))
1011 1011 ifl->ifl_flags |= FLG_IF_OTOSCAP;
1012 1012
1013 1013 /*
1014 1014 * Allocate a capabilities descriptor to collect the capabilities data
1015 1015 * for this input file. Allocate a mirror of the raw capabilities data
1016 1016 * that points to the individual symbol capabilities groups. An APlist
1017 1017 * is used, although it will be sparsely populated, as the list provides
1018 1018 * a convenient mechanism for traversal later.
1019 1019 */
1020 1020 if (((cdp = libld_calloc(sizeof (Cap_desc), 1)) == NULL) ||
1021 1021 (aplist_append(&(cdp->ca_groups), NULL, cnum) == NULL))
1022 1022 return (S_ERROR);
1023 1023
1024 1024 /*
1025 1025 * Clear the allocated APlist data array, and assign the number of
1026 1026 * items as the total number of array items.
1027 1027 */
1028 1028 (void) memset(&cdp->ca_groups->apl_data[0], 0,
1029 1029 (cnum * sizeof (void *)));
1030 1030 cdp->ca_groups->apl_nitems = cnum;
1031 1031
1032 1032 ifl->ifl_caps = cdp;
1033 1033
1034 1034 /*
1035 1035 * Traverse the capabilities data, unpacking the data into a
1036 1036 * capabilities set. Process each capabilities set as a unique group.
1037 1037 */
1038 1038 descapndx = -1;
1039 1039 nulls = 0;
1040 1040
1041 1041 for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
1042 1042 Capstr *capstr;
1043 1043
1044 1044 switch (data->c_tag) {
1045 1045 case CA_SUNW_NULL:
1046 1046 nulls++;
1047 1047
1048 1048 /*
1049 1049 * Process the capabilities group that this null entry
1050 1050 * terminates. The capabilities group that is returned
1051 1051 * will either point to this file's data, or to a
1052 1052 * matching capabilities group that has already been
1053 1053 * processed.
1054 1054 *
1055 1055 * Note, if this object defines object capabilities,
1056 1056 * the first group descriptor points to these object
1057 1057 * capabilities. It is only necessary to save this
1058 1058 * descriptor when object capabilities are being
1059 1059 * transformed into symbol capabilities (-z symbolcap).
1060 1060 */
1061 1061 if (descapndx != -1) {
1062 1062 if ((nulls > 1) ||
1063 1063 (ifl->ifl_flags & FLG_IF_OTOSCAP)) {
1064 1064 APlist *alp = cdp->ca_groups;
1065 1065
1066 1066 if ((alp->apl_data[descapndx] =
1067 1067 get_cap_group(&ocapset,
1068 1068 (ndx - descapndx), ofl,
1069 1069 cisp)) == NULL)
1070 1070 return (S_ERROR);
1071 1071 }
1072 1072
1073 1073 /*
1074 1074 * Clean up the capabilities data in preparation
1075 1075 * for processing additional groups. If the
1076 1076 * collected capabilities strings were used to
1077 1077 * establish a new output group, they will have
1078 1078 * been saved in get_cap_group(). If these
1079 1079 * descriptors still exist, then an existing
1080 1080 * descriptor has been used to associate with
1081 1081 * this file, and these string descriptors can
1082 1082 * be freed.
1083 1083 */
1084 1084 ocapset.oc_hw_1.cm_val =
1085 1085 ocapset.oc_sf_1.cm_val =
1086 1086 ocapset.oc_hw_2.cm_val = 0;
1087 1087 if (ocapset.oc_plat.cl_val) {
1088 1088 free((void *)ocapset.oc_plat.cl_val);
1089 1089 ocapset.oc_plat.cl_val = NULL;
1090 1090 }
1091 1091 if (ocapset.oc_mach.cl_val) {
1092 1092 free((void *)ocapset.oc_mach.cl_val);
1093 1093 ocapset.oc_mach.cl_val = NULL;
1094 1094 }
1095 1095 descapndx = -1;
1096 1096 }
1097 1097 continue;
1098 1098
1099 1099 case CA_SUNW_HW_1:
1100 1100 ocapset.oc_hw_1.cm_val = data->c_un.c_val;
1101 1101 DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
1102 1102 DBG_STATE_ORIGINAL, CA_SUNW_HW_1,
1103 1103 ocapset.oc_hw_1.cm_val, ld_targ.t_m.m_mach));
1104 1104 break;
1105 1105
1106 1106 case CA_SUNW_SF_1:
1107 1107 ocapset.oc_sf_1.cm_val = data->c_un.c_val;
1108 1108 DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
1109 1109 DBG_STATE_ORIGINAL, CA_SUNW_SF_1,
1110 1110 ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach));
1111 1111 break;
1112 1112
1113 1113 case CA_SUNW_HW_2:
1114 1114 ocapset.oc_hw_2.cm_val = data->c_un.c_val;
1115 1115 DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
1116 1116 DBG_STATE_ORIGINAL, CA_SUNW_HW_2,
1117 1117 ocapset.oc_hw_2.cm_val, ld_targ.t_m.m_mach));
1118 1118 break;
1119 1119
1120 1120 case CA_SUNW_PLAT:
1121 1121 if ((capstr = alist_append(&ocapset.oc_plat.cl_val,
1122 1122 NULL, sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL)
1123 1123 return (S_ERROR);
1124 1124 capstr->cs_str = strs + data->c_un.c_ptr;
1125 1125 DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
1126 1126 DBG_STATE_ORIGINAL, CA_SUNW_PLAT, capstr->cs_str));
1127 1127 break;
1128 1128
1129 1129 case CA_SUNW_MACH:
1130 1130 if ((capstr = alist_append(&ocapset.oc_mach.cl_val,
1131 1131 NULL, sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL)
1132 1132 return (S_ERROR);
1133 1133 capstr->cs_str = strs + data->c_un.c_ptr;
1134 1134 DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
1135 1135 DBG_STATE_ORIGINAL, CA_SUNW_MACH, capstr->cs_str));
1136 1136 break;
1137 1137
1138 1138 case CA_SUNW_ID:
1139 1139 ocapset.oc_id.cs_str = strs + data->c_un.c_ptr;
1140 1140 DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
1141 1141 DBG_STATE_ORIGINAL, CA_SUNW_ID,
1142 1142 ocapset.oc_id.cs_str));
1143 1143 break;
1144 1144 }
1145 1145
1146 1146 /*
1147 1147 * Save the start of this new group.
1148 1148 */
1149 1149 if (descapndx == -1)
1150 1150 descapndx = ndx;
1151 1151 }
1152 1152 return (1);
1153 1153 }
1154 1154
1155 1155 /*
1156 1156 * Capture any symbol capabilities symbols. An object file that contains symbol
1157 1157 * capabilities has an associated .SUNW_capinfo section. This section
1158 1158 * identifies which symbols are associated to which capabilities, together with
1159 1159 * their associated lead symbol. Each of these symbol pairs are recorded for
1160 1160 * processing later.
1161 1161 */
1162 1162 static uintptr_t
1163 1163 process_capinfo(Ofl_desc *ofl, Ifl_desc *ifl, Is_desc *isp)
1164 1164 {
1165 1165 Cap_desc *cdp = ifl->ifl_caps;
1166 1166 Capinfo *capinfo = isp->is_indata->d_buf;
1167 1167 Shdr *shdr = isp->is_shdr;
1168 1168 Word cndx, capinfonum;
1169 1169
1170 1170 capinfonum = (Word)(shdr->sh_size / shdr->sh_entsize);
1171 1171
1172 1172 if ((cdp == NULL) || (capinfo == NULL) || (capinfonum == 0))
1173 1173 return (0);
1174 1174
1175 1175 for (cndx = 1, capinfo++; cndx < capinfonum; cndx++, capinfo++) {
1176 1176 Sym_desc *sdp, *lsdp;
1177 1177 Word lndx;
1178 1178 uchar_t gndx;
1179 1179
1180 1180 if ((gndx = (uchar_t)ELF_C_GROUP(*capinfo)) == 0)
1181 1181 continue;
1182 1182 lndx = (Word)ELF_C_SYM(*capinfo);
1183 1183
1184 1184 /*
1185 1185 * Catch any anomalies. A capabilities symbol should be valid,
1186 1186 * and the capabilities lead symbol should also be global.
1187 1187 * Note, ld(1) -z symbolcap would create local capabilities
1188 1188 * symbols, but we don't enforce this so as to give the
1189 1189 * compilation environment a little more freedom.
1190 1190 */
1191 1191 if ((sdp = ifl->ifl_oldndx[cndx]) == NULL) {
1192 1192 ld_eprintf(ofl, ERR_WARNING,
1193 1193 MSG_INTL(MSG_CAPINFO_INVALSYM), ifl->ifl_name,
1194 1194 EC_WORD(isp->is_scnndx), isp->is_name, cndx,
1195 1195 MSG_INTL(MSG_STR_UNKNOWN));
1196 1196 continue;
1197 1197 }
1198 1198 if ((lndx == 0) || (lndx >= ifl->ifl_symscnt) ||
1199 1199 ((lsdp = ifl->ifl_oldndx[lndx]) == NULL) ||
1200 1200 (ELF_ST_BIND(lsdp->sd_sym->st_info) != STB_GLOBAL)) {
1201 1201 ld_eprintf(ofl, ERR_WARNING,
1202 1202 MSG_INTL(MSG_CAPINFO_INVALLEAD), ifl->ifl_name,
1203 1203 EC_WORD(isp->is_scnndx), isp->is_name, cndx, lsdp ?
1204 1204 demangle(lsdp->sd_name) : MSG_INTL(MSG_STR_UNKNOWN),
1205 1205 lndx);
1206 1206 continue;
1207 1207 }
1208 1208
1209 1209 /*
1210 1210 * Indicate that this is a capabilities symbol.
1211 1211 */
1212 1212 sdp->sd_flags |= FLG_SY_CAP;
1213 1213
1214 1214 /*
1215 1215 * Save any global capability symbols. Global capability
1216 1216 * symbols are identified with a CAPINFO_SUNW_GLOB group id.
1217 1217 * The lead symbol for this global capability symbol is either
1218 1218 * the symbol itself, or an alias.
1219 1219 */
1220 1220 if (gndx == CAPINFO_SUNW_GLOB) {
1221 1221 if (ld_cap_add_family(ofl, lsdp, sdp,
1222 1222 NULL, NULL) == S_ERROR)
1223 1223 return (S_ERROR);
1224 1224 continue;
1225 1225 }
1226 1226
1227 1227 /*
1228 1228 * Track the number of non-global capabilities symbols, as these
1229 1229 * are used to size any symbol tables. If we're generating a
1230 1230 * dynamic object, this symbol will be added to the dynamic
1231 1231 * symbol table, therefore ensure there is space in the dynamic
1232 1232 * string table.
1233 1233 */
1234 1234 ofl->ofl_caploclcnt++;
1235 1235 if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) &&
1236 1236 (st_insert(ofl->ofl_dynstrtab, sdp->sd_name) == -1))
1237 1237 return (S_ERROR);
1238 1238
1239 1239 /*
1240 1240 * As we're tracking this local symbol as a capabilities symbol,
1241 1241 * reduce the local symbol count to compensate.
1242 1242 */
1243 1243 ofl->ofl_locscnt--;
1244 1244
1245 1245 /*
1246 1246 * Determine whether the associated lead symbol indicates
1247 1247 * NODYNSORT. If so, remove this local entry from the
1248 1248 * SUNW_dynsort section too. NODYNSORT tagging can only be
1249 1249 * obtained from a mapfile symbol definition, and thus any
1250 1250 * global definition that has this tagging has already been
1251 1251 * instantiated and this instance resolved to it.
1252 1252 */
1253 1253 if (lsdp->sd_flags & FLG_SY_NODYNSORT) {
1254 1254 Sym *lsym = lsdp->sd_sym;
1255 1255 uchar_t ltype = ELF_ST_TYPE(lsym->st_info);
1256 1256
1257 1257 DYNSORT_COUNT(lsdp, lsym, ltype, --);
1258 1258 lsdp->sd_flags |= FLG_SY_NODYNSORT;
1259 1259 }
1260 1260
1261 1261 /*
1262 1262 * Track this family member, together with its associated group.
1263 1263 */
1264 1264 if (ld_cap_add_family(ofl, lsdp, sdp,
1265 1265 cdp->ca_groups->apl_data[gndx], NULL) == S_ERROR)
1266 1266 return (S_ERROR);
1267 1267 }
1268 1268
1269 1269 return (0);
1270 1270 }
1271 1271
1272 1272 /*
1273 1273 * Simply process the section so that we have pointers to the data for use
1274 1274 * in later routines, however don't add the section to the output section
1275 1275 * list as we will be creating our own replacement sections later (ie.
1276 1276 * symtab and relocation).
1277 1277 */
1278 1278 static uintptr_t
1279 1279 /* ARGSUSED5 */
1280 1280 process_input(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1281 1281 Word ndx, int ident, Ofl_desc *ofl)
1282 1282 {
1283 1283 return (process_section(name, ifl, shdr, scn, ndx,
1284 1284 ld_targ.t_id.id_null, ofl));
1285 1285 }
1286 1286
1287 1287 /*
1288 1288 * Keep a running count of relocation entries from input relocatable objects for
1289 1289 * sizing relocation buckets later. If we're building an executable, save any
1290 1290 * relocations from shared objects to determine if any copy relocation symbol
1291 1291 * has a displacement relocation against it.
1292 1292 */
1293 1293 static uintptr_t
1294 1294 /* ARGSUSED5 */
1295 1295 process_reloc(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1296 1296 Word ndx, int ident, Ofl_desc *ofl)
1297 1297 {
1298 1298 if (process_section(name, ifl,
1299 1299 shdr, scn, ndx, ld_targ.t_id.id_null, ofl) == S_ERROR)
1300 1300 return (S_ERROR);
1301 1301
1302 1302 if (ifl->ifl_ehdr->e_type == ET_REL) {
1303 1303 if (shdr->sh_entsize && (shdr->sh_entsize <= shdr->sh_size))
1304 1304 /* LINTED */
1305 1305 ofl->ofl_relocincnt +=
1306 1306 (Word)(shdr->sh_size / shdr->sh_entsize);
1307 1307 } else if (ofl->ofl_flags & FLG_OF_EXEC) {
1308 1308 if (aplist_append(&ifl->ifl_relsect, ifl->ifl_isdesc[ndx],
1309 1309 AL_CNT_IFL_RELSECS) == NULL)
1310 1310 return (S_ERROR);
1311 1311 }
1312 1312 return (1);
1313 1313 }
1314 1314
1315 1315 /*
1316 1316 * Process a string table section. A valid section contains an initial and
1317 1317 * final null byte.
1318 1318 */
1319 1319 static uintptr_t
1320 1320 process_strtab(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1321 1321 Word ndx, int ident, Ofl_desc *ofl)
1322 1322 {
1323 1323 char *data;
1324 1324 size_t size;
1325 1325 Is_desc *isp;
1326 1326 uintptr_t error;
1327 1327
1328 1328 /*
1329 1329 * Never include .stab.excl sections in any output file.
1330 1330 * If the -s flag has been specified strip any .stab sections.
1331 1331 */
1332 1332 if (((ofl->ofl_flags & FLG_OF_STRIP) && ident &&
1333 1333 (strncmp(name, MSG_ORIG(MSG_SCN_STAB), MSG_SCN_STAB_SIZE) == 0)) ||
1334 1334 (strcmp(name, MSG_ORIG(MSG_SCN_STABEXCL)) == 0) && ident)
1335 1335 return (1);
1336 1336
1337 1337 /*
1338 1338 * If we got here to process a .shstrtab or .dynstr table, `ident' will
1339 1339 * be null. Otherwise make sure we don't have a .strtab section as this
1340 1340 * should not be added to the output section list either.
1341 1341 */
1342 1342 if ((ident != ld_targ.t_id.id_null) &&
1343 1343 (strcmp(name, MSG_ORIG(MSG_SCN_STRTAB)) == 0))
1344 1344 ident = ld_targ.t_id.id_null;
1345 1345
1346 1346 error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
1347 1347 if ((error == 0) || (error == S_ERROR))
1348 1348 return (error);
1349 1349
1350 1350 /*
1351 1351 * String tables should start and end with a NULL byte. Note, it has
1352 1352 * been known for the assembler to create empty string tables, so check
1353 1353 * the size before attempting to verify the data itself.
1354 1354 */
1355 1355 isp = ifl->ifl_isdesc[ndx];
1356 1356 size = isp->is_indata->d_size;
1357 1357 if (size) {
1358 1358 data = isp->is_indata->d_buf;
1359 1359 if (data[0] != '\0' || data[size - 1] != '\0')
1360 1360 ld_eprintf(ofl, ERR_WARNING,
1361 1361 MSG_INTL(MSG_FIL_MALSTR), ifl->ifl_name,
1362 1362 EC_WORD(isp->is_scnndx), name);
1363 1363 } else
1364 1364 isp->is_indata->d_buf = (void *)MSG_ORIG(MSG_STR_EMPTY);
1365 1365
1366 1366 ifl->ifl_flags |= FLG_IF_HSTRTAB;
1367 1367 return (1);
1368 1368 }
1369 1369
1370 1370 /*
1371 1371 * Invalid sections produce a warning and are skipped.
1372 1372 */
1373 1373 static uintptr_t
1374 1374 /* ARGSUSED3 */
1375 1375 invalid_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1376 1376 Word ndx, int ident, Ofl_desc *ofl)
1377 1377 {
1378 1378 Conv_inv_buf_t inv_buf;
1379 1379
1380 1380 ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_INVALSEC),
1381 1381 ifl->ifl_name, EC_WORD(ndx), name,
1382 1382 conv_sec_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
1383 1383 ifl->ifl_ehdr->e_machine, shdr->sh_type, 0, &inv_buf));
1384 1384 return (1);
1385 1385 }
1386 1386
1387 1387 /*
1388 1388 * Compare an input section name to a given string, taking the ELF '%'
1389 1389 * section naming convention into account. If an input section name
1390 1390 * contains a '%' character, the '%' and all following characters are
1391 1391 * ignored in the comparison.
1392 1392 *
1393 1393 * entry:
1394 1394 * is_name - Name of input section
1395 1395 * match_name - Name to compare to
1396 1396 * match_len - strlen(match_name)
1397 1397 *
1398 1398 * exit:
1399 1399 * Returns True (1) if the names match, and False (0) otherwise.
1400 1400 */
1401 1401 inline static int
1402 1402 is_name_cmp(const char *is_name, const char *match_name, size_t match_len)
1403 1403 {
1404 1404 /*
1405 1405 * If the start of is_name is not a match for name,
1406 1406 * the match fails.
1407 1407 */
1408 1408 if (strncmp(is_name, match_name, match_len) != 0)
1409 1409 return (0);
1410 1410
1411 1411 /*
1412 1412 * The prefix matched. The next character must be either '%', or
1413 1413 * NULL, in order for a match to be true.
1414 1414 */
1415 1415 is_name += match_len;
1416 1416 return ((*is_name == '\0') || (*is_name == '%'));
1417 1417 }
1418 1418
1419 1419 /*
1420 1420 * Helper routine for process_progbits() to process allocable sections.
1421 1421 *
1422 1422 * entry:
1423 1423 * name, ifl, shdr, ndx, ident, ofl - As passed to process_progbits().
1424 1424 * is_stab_index - TRUE if section is .index.
1425 1425 * is_flags - Additional flags to be added to the input section.
1426 1426 *
1427 1427 * exit:
1428 1428 * The allocable section has been processed. *ident and *is_flags
1429 1429 * are updated as necessary to reflect the changes. Returns TRUE
1430 1430 * for success, FALSE for failure.
1431 1431 */
1432 1432 /*ARGSUSED*/
1433 1433 inline static Boolean
1434 1434 process_progbits_alloc(const char *name, Ifl_desc *ifl, Shdr *shdr,
1435 1435 Word ndx, int *ident, Ofl_desc *ofl, Boolean is_stab_index,
1436 1436 Word *is_flags)
1437 1437 {
1438 1438 Boolean done = FALSE;
1439 1439
1440 1440 if (name[0] == '.') {
1441 1441 switch (name[1]) {
1442 1442 case 'e':
1443 1443 if (!is_name_cmp(name, MSG_ORIG(MSG_SCN_EHFRAME),
1444 1444 MSG_SCN_EHFRAME_SIZE))
1445 1445 break;
1446 1446
1447 1447 *ident = ld_targ.t_id.id_unwind;
1448 1448 *is_flags |= FLG_IS_EHFRAME;
1449 1449 done = TRUE;
1450 1450
1451 1451 /*
1452 1452 * Historically, the section containing the logic to
1453 1453 * unwind stack frames -- the .eh_frame section -- was
1454 1454 * of type SHT_PROGBITS. Apparently the most
1455 1455 * aesthetically galling aspect of this was not the
1456 1456 * .eh_frame section's dubious purpose or its filthy
1457 1457 * implementation, but rather its section type; with the
1458 1458 * introduction of the AMD64 ABI, a new section header
1459 1459 * type (SHT_AMD64_UNWIND) was introduced for (and
1460 1460 * dedicated to) this section. When both the Sun
1461 1461 * compilers and the GNU compilers had been modified to
1462 1462 * generate this new section type, the linker became
1463 1463 * much more pedantic about .eh_frame: it refused to
1464 1464 * link an AMD64 object that contained a .eh_frame with
1465 1465 * the legacy SHT_PROGBITS. That this was too fussy is
1466 1466 * evidenced by searching the net for the error message
1467 1467 * that it generated ("section type is SHT_PROGBITS:
1468 1468 * expected SHT_AMD64_UNWIND"), which reveals a myriad
1469 1469 * of problems, including legacy objects, hand-coded
1470 1470 * assembly and otherwise cross-platform objects
1471 1471 * created on other platforms (the GNU toolchain was
1472 1472 * only modified to create the new section type on
1473 1473 * Solaris and derivatives). We therefore always accept
1474 1474 * a .eh_frame of SHT_PROGBITS -- regardless of
1475 1475 * m_sht_unwind.
1476 1476 */
1477 1477 break;
1478 1478 case 'g':
1479 1479 if (is_name_cmp(name, MSG_ORIG(MSG_SCN_GOT),
1480 1480 MSG_SCN_GOT_SIZE)) {
1481 1481 *ident = ld_targ.t_id.id_null;
1482 1482 done = TRUE;
1483 1483 break;
1484 1484 }
1485 1485 if ((ld_targ.t_m.m_sht_unwind == SHT_PROGBITS) &&
1486 1486 is_name_cmp(name, MSG_ORIG(MSG_SCN_GCC_X_TBL),
1487 1487 MSG_SCN_GCC_X_TBL_SIZE)) {
1488 1488 *ident = ld_targ.t_id.id_unwind;
1489 1489 done = TRUE;
1490 1490 break;
1491 1491 }
1492 1492 break;
1493 1493 case 'p':
1494 1494 if (is_name_cmp(name, MSG_ORIG(MSG_SCN_PLT),
1495 1495 MSG_SCN_PLT_SIZE)) {
1496 1496 *ident = ld_targ.t_id.id_null;
1497 1497 done = TRUE;
1498 1498 }
1499 1499 break;
1500 1500 }
1501 1501 }
1502 1502 if (!done) {
1503 1503 if (is_stab_index) {
1504 1504 /*
1505 1505 * This is a work-around for x86 compilers that have
1506 1506 * set SHF_ALLOC for the .stab.index section.
1507 1507 *
1508 1508 * Because of this, make sure that the .stab.index
1509 1509 * does not end up as the last section in the text
1510 1510 * segment. Older linkers can produce segmentation
1511 1511 * violations when they strip (ld -s) against a
1512 1512 * shared object whose last section in the text
1513 1513 * segment is a .stab.
1514 1514 */
1515 1515 *ident = ld_targ.t_id.id_interp;
1516 1516 } else {
1517 1517 *ident = ld_targ.t_id.id_data;
1518 1518 }
1519 1519 }
1520 1520
1521 1521 return (TRUE);
1522 1522 }
1523 1523
1524 1524 /*
1525 1525 * Process a progbits section.
1526 1526 */
1527 1527 static uintptr_t
1528 1528 process_progbits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1529 1529 Word ndx, int ident, Ofl_desc *ofl)
1530 1530 {
1531 1531 Boolean is_stab_index = FALSE;
1532 1532 Word is_flags = 0;
1533 1533 uintptr_t r;
1534 1534
1535 1535 /*
1536 1536 * Never include .stab.excl sections in any output file.
1537 1537 * If the -s flag has been specified strip any .stab sections.
1538 1538 */
1539 1539 if (ident && (strncmp(name, MSG_ORIG(MSG_SCN_STAB),
1540 1540 MSG_SCN_STAB_SIZE) == 0)) {
1541 1541 if ((ofl->ofl_flags & FLG_OF_STRIP) ||
1542 1542 (strcmp((name + MSG_SCN_STAB_SIZE),
1543 1543 MSG_ORIG(MSG_SCN_EXCL)) == 0))
1544 1544 return (1);
1545 1545
1546 1546 if (strcmp((name + MSG_SCN_STAB_SIZE),
1547 1547 MSG_ORIG(MSG_SCN_INDEX)) == 0)
1548 1548 is_stab_index = TRUE;
1549 1549 }
1550 1550
1551 1551 if ((ofl->ofl_flags & FLG_OF_STRIP) && ident) {
1552 1552 if ((strncmp(name, MSG_ORIG(MSG_SCN_DEBUG),
1553 1553 MSG_SCN_DEBUG_SIZE) == 0) ||
1554 1554 (strcmp(name, MSG_ORIG(MSG_SCN_LINE)) == 0))
1555 1555 return (1);
1556 1556 }
1557 1557
1558 1558 /*
1559 1559 * Update the ident to reflect the type of section we've got.
1560 1560 *
1561 1561 * If there is any .plt or .got section to generate we'll be creating
1562 1562 * our own version, so don't allow any input sections of these types to
1563 1563 * be added to the output section list (why a relocatable object would
1564 1564 * have a .plt or .got is a mystery, but stranger things have occurred).
1565 1565 *
1566 1566 * If there are any unwind sections, and this is a platform that uses
1567 1567 * SHT_PROGBITS for unwind sections, then set their ident to reflect
1568 1568 * that.
1569 1569 */
1570 1570 if (ident) {
1571 1571 if (shdr->sh_flags & SHF_TLS) {
1572 1572 ident = ld_targ.t_id.id_tls;
1573 1573 } else if ((shdr->sh_flags & ~ALL_SHF_IGNORE) ==
1574 1574 (SHF_ALLOC | SHF_EXECINSTR)) {
1575 1575 ident = ld_targ.t_id.id_text;
1576 1576 } else if (shdr->sh_flags & SHF_ALLOC) {
1577 1577 if (process_progbits_alloc(name, ifl, shdr, ndx,
1578 1578 &ident, ofl, is_stab_index, &is_flags) == FALSE)
1579 1579 return (S_ERROR);
1580 1580 } else {
1581 1581 ident = ld_targ.t_id.id_note;
1582 1582 }
1583 1583 }
1584 1584
1585 1585 r = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
1586 1586
1587 1587 /*
1588 1588 * On success, process_section() creates an input section descriptor.
1589 1589 * Now that it exists, we can add any pending input section flags.
1590 1590 */
1591 1591 if ((is_flags != 0) && (r == 1))
1592 1592 ifl->ifl_isdesc[ndx]->is_flags |= is_flags;
1593 1593
1594 1594 return (r);
1595 1595 }
1596 1596
1597 1597 /*
1598 1598 * Handles the SHT_SUNW_{DEBUG,DEBUGSTR) sections.
1599 1599 */
1600 1600 static uintptr_t
1601 1601 process_debug(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1602 1602 Word ndx, int ident, Ofl_desc *ofl)
1603 1603 {
1604 1604 /*
1605 1605 * Debug information is discarded when the 'ld -s' flag is invoked.
1606 1606 */
1607 1607 if (ofl->ofl_flags & FLG_OF_STRIP) {
1608 1608 return (1);
1609 1609 }
1610 1610 return (process_progbits(name, ifl, shdr, scn, ndx, ident, ofl));
1611 1611 }
1612 1612
1613 1613 /*
1614 1614 * Process a nobits section.
1615 1615 */
1616 1616 static uintptr_t
1617 1617 process_nobits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1618 1618 Word ndx, int ident, Ofl_desc *ofl)
1619 1619 {
1620 1620 if (ident) {
1621 1621 if (shdr->sh_flags & SHF_TLS)
1622 1622 ident = ld_targ.t_id.id_tlsbss;
1623 1623 #if defined(_ELF64)
1624 1624 else if ((shdr->sh_flags & SHF_AMD64_LARGE) &&
1625 1625 (ld_targ.t_m.m_mach == EM_AMD64))
1626 1626 ident = ld_targ.t_id.id_lbss;
1627 1627 #endif
1628 1628 else
1629 1629 ident = ld_targ.t_id.id_bss;
1630 1630 }
1631 1631 return (process_section(name, ifl, shdr, scn, ndx, ident, ofl));
1632 1632 }
1633 1633
1634 1634 /*
1635 1635 * Process a SHT_*_ARRAY section.
1636 1636 */
1637 1637 static uintptr_t
1638 1638 process_array(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1639 1639 Word ndx, int ident, Ofl_desc *ofl)
1640 1640 {
1641 1641 uintptr_t error;
1642 1642
1643 1643 if (ident)
1644 1644 ident = ld_targ.t_id.id_array;
1645 1645
1646 1646 error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
1647 1647 if ((error == 0) || (error == S_ERROR))
1648 1648 return (error);
1649 1649
1650 1650 return (1);
1651 1651 }
1652 1652
1653 1653 static uintptr_t
1654 1654 /* ARGSUSED1 */
1655 1655 array_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
1656 1656 {
1657 1657 Os_desc *osp;
1658 1658 Shdr *shdr;
1659 1659
1660 1660 if ((isc == NULL) || ((osp = isc->is_osdesc) == NULL))
1661 1661 return (0);
1662 1662
1663 1663 shdr = isc->is_shdr;
1664 1664
1665 1665 if ((shdr->sh_type == SHT_FINI_ARRAY) &&
1666 1666 (ofl->ofl_osfiniarray == NULL))
1667 1667 ofl->ofl_osfiniarray = osp;
1668 1668 else if ((shdr->sh_type == SHT_INIT_ARRAY) &&
1669 1669 (ofl->ofl_osinitarray == NULL))
1670 1670 ofl->ofl_osinitarray = osp;
1671 1671 else if ((shdr->sh_type == SHT_PREINIT_ARRAY) &&
1672 1672 (ofl->ofl_ospreinitarray == NULL))
1673 1673 ofl->ofl_ospreinitarray = osp;
1674 1674
1675 1675 return (1);
1676 1676 }
1677 1677
1678 1678 /*
1679 1679 * Process a SHT_SYMTAB_SHNDX section.
1680 1680 */
1681 1681 static uintptr_t
1682 1682 process_sym_shndx(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1683 1683 Word ndx, int ident, Ofl_desc *ofl)
1684 1684 {
1685 1685 if (process_input(name, ifl, shdr, scn, ndx, ident, ofl) == S_ERROR)
1686 1686 return (S_ERROR);
1687 1687
1688 1688 /*
1689 1689 * Have we already seen the related SYMTAB - if so verify it now.
1690 1690 */
1691 1691 if (shdr->sh_link < ndx) {
1692 1692 Is_desc *isp = ifl->ifl_isdesc[shdr->sh_link];
1693 1693
1694 1694 if ((isp == NULL) || ((isp->is_shdr->sh_type != SHT_SYMTAB) &&
1695 1695 (isp->is_shdr->sh_type != SHT_DYNSYM))) {
1696 1696 ld_eprintf(ofl, ERR_FATAL,
1697 1697 MSG_INTL(MSG_FIL_INVSHLINK), ifl->ifl_name,
1698 1698 EC_WORD(ndx), name, EC_XWORD(shdr->sh_link));
1699 1699 return (S_ERROR);
1700 1700 }
1701 1701 isp->is_symshndx = ifl->ifl_isdesc[ndx];
1702 1702 }
1703 1703 return (1);
1704 1704 }
1705 1705
1706 1706 /*
1707 1707 * Final processing for SHT_SYMTAB_SHNDX section.
1708 1708 */
1709 1709 static uintptr_t
1710 1710 /* ARGSUSED2 */
1711 1711 sym_shndx_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
1712 1712 {
1713 1713 if (isc->is_shdr->sh_link > isc->is_scnndx) {
1714 1714 Is_desc *isp = ifl->ifl_isdesc[isc->is_shdr->sh_link];
1715 1715
1716 1716 if ((isp == NULL) || ((isp->is_shdr->sh_type != SHT_SYMTAB) &&
1717 1717 (isp->is_shdr->sh_type != SHT_DYNSYM))) {
1718 1718 ld_eprintf(ofl, ERR_FATAL,
1719 1719 MSG_INTL(MSG_FIL_INVSHLINK), isc->is_file->ifl_name,
1720 1720 EC_WORD(isc->is_scnndx), isc->is_name,
1721 1721 EC_XWORD(isc->is_shdr->sh_link));
1722 1722 return (S_ERROR);
1723 1723 }
1724 1724 isp->is_symshndx = isc;
1725 1725 }
1726 1726 return (1);
1727 1727 }
1728 1728
1729 1729 /*
1730 1730 * Process .dynamic section from a relocatable object.
1731 1731 *
1732 1732 * Note: That the .dynamic section is only considered interesting when
1733 1733 * dlopen()ing a relocatable object (thus FLG_OF1_RELDYN can only get
1734 1734 * set when libld is called from ld.so.1).
1735 1735 */
1736 1736 /*ARGSUSED*/
1737 1737 static uintptr_t
1738 1738 process_rel_dynamic(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1739 1739 Word ndx, int ident, Ofl_desc *ofl)
1740 1740 {
1741 1741 Dyn *dyn;
1742 1742 Elf_Scn *strscn;
1743 1743 Elf_Data *dp;
1744 1744 char *str;
1745 1745
1746 1746 /*
1747 1747 * Process .dynamic sections from relocatable objects ?
1748 1748 */
1749 1749 if ((ofl->ofl_flags1 & FLG_OF1_RELDYN) == 0)
1750 1750 return (1);
1751 1751
1752 1752 /*
1753 1753 * Find the string section associated with the .dynamic section.
1754 1754 */
1755 1755 if ((strscn = elf_getscn(ifl->ifl_elf, shdr->sh_link)) == NULL) {
1756 1756 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN),
1757 1757 ifl->ifl_name);
1758 1758 return (0);
1759 1759 }
1760 1760 dp = elf_getdata(strscn, NULL);
1761 1761 str = (char *)dp->d_buf;
1762 1762
1763 1763 /*
1764 1764 * And get the .dynamic data
1765 1765 */
1766 1766 dp = elf_getdata(scn, NULL);
1767 1767
1768 1768 for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) {
1769 1769 Ifl_desc *difl;
1770 1770
1771 1771 switch (dyn->d_tag) {
1772 1772 case DT_NEEDED:
1773 1773 case DT_USED:
1774 1774 if (((difl = libld_calloc(1,
1775 1775 sizeof (Ifl_desc))) == NULL) ||
1776 1776 (aplist_append(&ofl->ofl_sos, difl,
1777 1777 AL_CNT_OFL_LIBS) == NULL))
1778 1778 return (S_ERROR);
1779 1779
1780 1780 difl->ifl_name = MSG_ORIG(MSG_STR_DYNAMIC);
1781 1781 difl->ifl_soname = str + (size_t)dyn->d_un.d_val;
1782 1782 difl->ifl_flags = FLG_IF_NEEDSTR;
1783 1783 break;
1784 1784 case DT_RPATH:
1785 1785 case DT_RUNPATH:
1786 1786 if ((ofl->ofl_rpath = add_string(ofl->ofl_rpath,
1787 1787 (str + (size_t)dyn->d_un.d_val))) ==
1788 1788 (const char *)S_ERROR)
1789 1789 return (S_ERROR);
1790 1790 break;
1791 1791 case DT_VERSYM:
1792 1792 /*
1793 1793 * The Solaris ld does not put DT_VERSYM in the
1794 1794 * dynamic section. If the object has DT_VERSYM,
1795 1795 * then it must have been produced by the GNU ld,
1796 1796 * and is using the GNU style of versioning.
1797 1797 */
1798 1798 ifl->ifl_flags |= FLG_IF_GNUVER;
1799 1799 break;
1800 1800 }
1801 1801 }
1802 1802 return (1);
1803 1803 }
1804 1804
1805 1805 /*
1806 1806 * Expand implicit references. Dependencies can be specified in terms of the
1807 1807 * $ORIGIN, $MACHINE, $PLATFORM, $OSREL and $OSNAME tokens, either from their
1808 1808 * needed name, or via a runpath. In addition runpaths may also specify the
1809 1809 * $ISALIST token.
1810 1810 *
1811 1811 * Probably the most common reference to explicit dependencies (via -L) will be
1812 1812 * sufficient to find any associated implicit dependencies, but just in case we
1813 1813 * expand any occurrence of these known tokens here.
1814 1814 *
1815 1815 * Note, if any errors occur we simply return the original name.
1816 1816 *
1817 1817 * This code is remarkably similar to expand() in rtld/common/paths.c.
1818 1818 */
1819 1819 static char *machine = NULL;
1820 1820 static size_t machine_sz = 0;
1821 1821 static char *platform = NULL;
1822 1822 static size_t platform_sz = 0;
1823 1823 static Isa_desc *isa = NULL;
1824 1824 static Uts_desc *uts = NULL;
1825 1825
1826 1826 static char *
1827 1827 expand(const char *parent, const char *name, char **next)
1828 1828 {
1829 1829 char _name[PATH_MAX], *nptr, *_next;
1830 1830 const char *optr;
1831 1831 size_t nrem = PATH_MAX - 1;
1832 1832 int expanded = 0, _expanded, isaflag = 0;
1833 1833
1834 1834 optr = name;
1835 1835 nptr = _name;
1836 1836
1837 1837 while (*optr) {
1838 1838 if (nrem == 0)
1839 1839 return ((char *)name);
1840 1840
1841 1841 if (*optr != '$') {
1842 1842 *nptr++ = *optr++, nrem--;
1843 1843 continue;
1844 1844 }
1845 1845
1846 1846 _expanded = 0;
1847 1847
1848 1848 if (strncmp(optr, MSG_ORIG(MSG_STR_ORIGIN),
1849 1849 MSG_STR_ORIGIN_SIZE) == 0) {
1850 1850 char *eptr;
1851 1851
1852 1852 /*
1853 1853 * For $ORIGIN, expansion is really just a concatenation
1854 1854 * of the parents directory name. For example, an
1855 1855 * explicit dependency foo/bar/lib1.so with a dependency
1856 1856 * on $ORIGIN/lib2.so would be expanded to
1857 1857 * foo/bar/lib2.so.
1858 1858 */
1859 1859 if ((eptr = strrchr(parent, '/')) == NULL) {
1860 1860 *nptr++ = '.';
1861 1861 nrem--;
1862 1862 } else {
1863 1863 size_t len = eptr - parent;
1864 1864
1865 1865 if (len >= nrem)
1866 1866 return ((char *)name);
1867 1867
1868 1868 (void) strncpy(nptr, parent, len);
1869 1869 nptr = nptr + len;
1870 1870 nrem -= len;
1871 1871 }
1872 1872 optr += MSG_STR_ORIGIN_SIZE;
1873 1873 expanded = _expanded = 1;
1874 1874
1875 1875 } else if (strncmp(optr, MSG_ORIG(MSG_STR_MACHINE),
1876 1876 MSG_STR_MACHINE_SIZE) == 0) {
1877 1877 /*
1878 1878 * Establish the machine from sysconf - like uname -i.
1879 1879 */
1880 1880 if ((machine == NULL) && (machine_sz == 0)) {
1881 1881 char info[SYS_NMLN];
1882 1882 long size;
1883 1883
1884 1884 size = sysinfo(SI_MACHINE, info, SYS_NMLN);
1885 1885 if ((size != -1) &&
1886 1886 (machine = libld_malloc((size_t)size))) {
1887 1887 (void) strcpy(machine, info);
1888 1888 machine_sz = (size_t)size - 1;
1889 1889 } else
1890 1890 machine_sz = 1;
1891 1891 }
1892 1892 if (machine) {
1893 1893 if (machine_sz >= nrem)
1894 1894 return ((char *)name);
1895 1895
1896 1896 (void) strncpy(nptr, machine, machine_sz);
1897 1897 nptr = nptr + machine_sz;
1898 1898 nrem -= machine_sz;
1899 1899
1900 1900 optr += MSG_STR_MACHINE_SIZE;
1901 1901 expanded = _expanded = 1;
1902 1902 }
1903 1903
1904 1904 } else if (strncmp(optr, MSG_ORIG(MSG_STR_PLATFORM),
1905 1905 MSG_STR_PLATFORM_SIZE) == 0) {
1906 1906 /*
1907 1907 * Establish the platform from sysconf - like uname -i.
1908 1908 */
1909 1909 if ((platform == NULL) && (platform_sz == 0)) {
1910 1910 char info[SYS_NMLN];
1911 1911 long size;
1912 1912
1913 1913 size = sysinfo(SI_PLATFORM, info, SYS_NMLN);
1914 1914 if ((size != -1) &&
1915 1915 (platform = libld_malloc((size_t)size))) {
1916 1916 (void) strcpy(platform, info);
1917 1917 platform_sz = (size_t)size - 1;
1918 1918 } else
1919 1919 platform_sz = 1;
1920 1920 }
1921 1921 if (platform) {
1922 1922 if (platform_sz >= nrem)
1923 1923 return ((char *)name);
1924 1924
1925 1925 (void) strncpy(nptr, platform, platform_sz);
1926 1926 nptr = nptr + platform_sz;
1927 1927 nrem -= platform_sz;
1928 1928
1929 1929 optr += MSG_STR_PLATFORM_SIZE;
1930 1930 expanded = _expanded = 1;
1931 1931 }
1932 1932
1933 1933 } else if (strncmp(optr, MSG_ORIG(MSG_STR_OSNAME),
1934 1934 MSG_STR_OSNAME_SIZE) == 0) {
1935 1935 /*
1936 1936 * Establish the os name - like uname -s.
1937 1937 */
1938 1938 if (uts == NULL)
1939 1939 uts = conv_uts();
1940 1940
1941 1941 if (uts && uts->uts_osnamesz) {
1942 1942 if (uts->uts_osnamesz >= nrem)
1943 1943 return ((char *)name);
1944 1944
1945 1945 (void) strncpy(nptr, uts->uts_osname,
1946 1946 uts->uts_osnamesz);
1947 1947 nptr = nptr + uts->uts_osnamesz;
1948 1948 nrem -= uts->uts_osnamesz;
1949 1949
1950 1950 optr += MSG_STR_OSNAME_SIZE;
1951 1951 expanded = _expanded = 1;
1952 1952 }
1953 1953
1954 1954 } else if (strncmp(optr, MSG_ORIG(MSG_STR_OSREL),
1955 1955 MSG_STR_OSREL_SIZE) == 0) {
1956 1956 /*
1957 1957 * Establish the os release - like uname -r.
1958 1958 */
1959 1959 if (uts == NULL)
1960 1960 uts = conv_uts();
1961 1961
1962 1962 if (uts && uts->uts_osrelsz) {
1963 1963 if (uts->uts_osrelsz >= nrem)
1964 1964 return ((char *)name);
1965 1965
1966 1966 (void) strncpy(nptr, uts->uts_osrel,
1967 1967 uts->uts_osrelsz);
1968 1968 nptr = nptr + uts->uts_osrelsz;
1969 1969 nrem -= uts->uts_osrelsz;
1970 1970
1971 1971 optr += MSG_STR_OSREL_SIZE;
1972 1972 expanded = _expanded = 1;
1973 1973 }
1974 1974
1975 1975 } else if ((strncmp(optr, MSG_ORIG(MSG_STR_ISALIST),
1976 1976 MSG_STR_ISALIST_SIZE) == 0) && next && (isaflag++ == 0)) {
1977 1977 /*
1978 1978 * Establish instruction sets from sysconf. Note that
1979 1979 * this is only meaningful from runpaths.
1980 1980 */
1981 1981 if (isa == NULL)
1982 1982 isa = conv_isalist();
1983 1983
1984 1984 if (isa && isa->isa_listsz &&
1985 1985 (nrem > isa->isa_opt->isa_namesz)) {
1986 1986 size_t mlen, tlen, hlen = optr - name;
1987 1987 size_t no;
1988 1988 char *lptr;
1989 1989 Isa_opt *opt = isa->isa_opt;
1990 1990
1991 1991 (void) strncpy(nptr, opt->isa_name,
1992 1992 opt->isa_namesz);
1993 1993 nptr = nptr + opt->isa_namesz;
1994 1994 nrem -= opt->isa_namesz;
1995 1995
1996 1996 optr += MSG_STR_ISALIST_SIZE;
1997 1997 expanded = _expanded = 1;
1998 1998
1999 1999 tlen = strlen(optr);
2000 2000
2001 2001 /*
2002 2002 * As ISALIST expands to a number of elements,
2003 2003 * establish a new list to return to the caller.
2004 2004 * This will contain the present path being
2005 2005 * processed redefined for each isalist option,
2006 2006 * plus the original remaining list entries.
2007 2007 */
2008 2008 mlen = ((hlen + tlen) * (isa->isa_optno - 1)) +
2009 2009 isa->isa_listsz - opt->isa_namesz;
2010 2010 if (*next)
2011 2011 mlen += strlen(*next);
2012 2012 if ((_next = lptr = libld_malloc(mlen)) == NULL)
2013 2013 return (0);
2014 2014
2015 2015 for (no = 1, opt++; no < isa->isa_optno;
2016 2016 no++, opt++) {
2017 2017 (void) strncpy(lptr, name, hlen);
2018 2018 lptr = lptr + hlen;
2019 2019 (void) strncpy(lptr, opt->isa_name,
2020 2020 opt->isa_namesz);
2021 2021 lptr = lptr + opt->isa_namesz;
2022 2022 (void) strncpy(lptr, optr, tlen);
2023 2023 lptr = lptr + tlen;
2024 2024 *lptr++ = ':';
2025 2025 }
2026 2026 if (*next)
2027 2027 (void) strcpy(lptr, *next);
2028 2028 else
2029 2029 *--lptr = '\0';
2030 2030 }
2031 2031 }
2032 2032
2033 2033 /*
2034 2034 * If no expansion occurred skip the $ and continue.
2035 2035 */
2036 2036 if (_expanded == 0)
2037 2037 *nptr++ = *optr++, nrem--;
2038 2038 }
2039 2039
2040 2040 /*
2041 2041 * If any ISALIST processing has occurred not only do we return the
2042 2042 * expanded node we're presently working on, but we must also update the
2043 2043 * remaining list so that it is effectively prepended with this node
2044 2044 * expanded to all remaining isalist options. Note that we can only
2045 2045 * handle one ISALIST per node. For more than one ISALIST to be
2046 2046 * processed we'd need a better algorithm than above to replace the
2047 2047 * newly generated list. Whether we want to encourage the number of
2048 2048 * pathname permutations this would provide is another question. So, for
2049 2049 * now if more than one ISALIST is encountered we return the original
2050 2050 * node untouched.
2051 2051 */
2052 2052 if (isaflag) {
2053 2053 if (isaflag == 1)
2054 2054 *next = _next;
2055 2055 else
2056 2056 return ((char *)name);
2057 2057 }
2058 2058
2059 2059 *nptr = '\0';
2060 2060
2061 2061 if (expanded) {
2062 2062 if ((nptr = libld_malloc(strlen(_name) + 1)) == NULL)
2063 2063 return ((char *)name);
2064 2064 (void) strcpy(nptr, _name);
2065 2065 return (nptr);
2066 2066 }
2067 2067 return ((char *)name);
2068 2068 }
2069 2069
2070 2070 /*
2071 2071 * The Solaris ld does not put DT_VERSYM in the dynamic section, but the
2072 2072 * GNU ld does, and it is used by the runtime linker to implement their
2073 2073 * versioning scheme. Use this fact to determine if the sharable object
2074 2074 * was produced by the GNU ld rather than the Solaris one, and to set
2075 2075 * FLG_IF_GNUVER if so. This needs to be done before the symbols are
2076 2076 * processed, since the answer determines whether we interpret the
2077 2077 * symbols versions according to Solaris or GNU rules.
2078 2078 */
2079 2079 /*ARGSUSED*/
2080 2080 static uintptr_t
2081 2081 process_dynamic_isgnu(const char *name, Ifl_desc *ifl, Shdr *shdr,
2082 2082 Elf_Scn *scn, Word ndx, int ident, Ofl_desc *ofl)
2083 2083 {
2084 2084 Dyn *dyn;
2085 2085 Elf_Data *dp;
2086 2086 uintptr_t error;
2087 2087
2088 2088 error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
2089 2089 if ((error == 0) || (error == S_ERROR))
2090 2090 return (error);
2091 2091
2092 2092 /* Get the .dynamic data */
2093 2093 dp = elf_getdata(scn, NULL);
2094 2094
2095 2095 for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) {
2096 2096 if (dyn->d_tag == DT_VERSYM) {
2097 2097 ifl->ifl_flags |= FLG_IF_GNUVER;
2098 2098 break;
2099 2099 }
2100 2100 }
2101 2101 return (1);
2102 2102 }
2103 2103
2104 2104 /*
2105 2105 * Process a dynamic section. If we are processing an explicit shared object
2106 2106 * then we need to determine if it has a recorded SONAME, if so, this name will
2107 2107 * be recorded in the output file being generated as the NEEDED entry rather
2108 2108 * than the shared objects filename itself.
2109 2109 * If the mode of the link-edit indicates that no undefined symbols should
2110 2110 * remain, then we also need to build up a list of any additional shared object
2111 2111 * dependencies this object may have. In this case save any NEEDED entries
2112 2112 * together with any associated run-path specifications. This information is
2113 2113 * recorded on the `ofl_soneed' list and will be analyzed after all explicit
2114 2114 * file processing has been completed (refer finish_libs()).
2115 2115 */
2116 2116 static uintptr_t
2117 2117 process_dynamic(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
2118 2118 {
2119 2119 Dyn *data, *dyn;
2120 2120 char *str, *rpath = NULL;
2121 2121 const char *soname, *needed;
2122 2122 Boolean no_undef;
2123 2123
2124 2124 data = (Dyn *)isc->is_indata->d_buf;
2125 2125 str = (char *)ifl->ifl_isdesc[isc->is_shdr->sh_link]->is_indata->d_buf;
2126 2126
2127 2127 /* Determine if we need to examine the runpaths and NEEDED entries */
2128 2128 no_undef = (ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)) ||
2129 2129 OFL_GUIDANCE(ofl, FLG_OFG_NO_DEFS);
2130 2130
2131 2131 /*
2132 2132 * First loop through the dynamic section looking for a run path.
2133 2133 */
2134 2134 if (no_undef) {
2135 2135 for (dyn = data; dyn->d_tag != DT_NULL; dyn++) {
2136 2136 if ((dyn->d_tag != DT_RPATH) &&
2137 2137 (dyn->d_tag != DT_RUNPATH))
2138 2138 continue;
2139 2139 if ((rpath = str + (size_t)dyn->d_un.d_val) == NULL)
2140 2140 continue;
2141 2141 break;
2142 2142 }
2143 2143 }
2144 2144
2145 2145 /*
2146 2146 * Now look for any needed dependencies (which may use the rpath)
2147 2147 * or a new SONAME.
2148 2148 */
2149 2149 for (dyn = data; dyn->d_tag != DT_NULL; dyn++) {
2150 2150 if (dyn->d_tag == DT_SONAME) {
2151 2151 if ((soname = str + (size_t)dyn->d_un.d_val) == NULL)
2152 2152 continue;
2153 2153
2154 2154 /*
2155 2155 * Update the input file structure with this new name.
2156 2156 */
2157 2157 ifl->ifl_soname = soname;
2158 2158
2159 2159 } else if ((dyn->d_tag == DT_NEEDED) ||
2160 2160 (dyn->d_tag == DT_USED)) {
2161 2161 Sdf_desc *sdf;
2162 2162
2163 2163 if (!no_undef)
2164 2164 continue;
2165 2165 if ((needed = str + (size_t)dyn->d_un.d_val) == NULL)
2166 2166 continue;
2167 2167
2168 2168 /*
2169 2169 * Determine if this needed entry is already recorded on
2170 2170 * the shared object needed list, if not create a new
2171 2171 * definition for later processing (see finish_libs()).
2172 2172 */
2173 2173 needed = expand(ifl->ifl_name, needed, NULL);
2174 2174
2175 2175 if ((sdf = sdf_find(needed, ofl->ofl_soneed)) == NULL) {
2176 2176 if ((sdf = sdf_add(needed,
2177 2177 &ofl->ofl_soneed)) == (Sdf_desc *)S_ERROR)
2178 2178 return (S_ERROR);
2179 2179 sdf->sdf_rfile = ifl->ifl_name;
2180 2180 }
2181 2181
2182 2182 /*
2183 2183 * Record the runpath (Note that we take the first
2184 2184 * runpath which is exactly what ld.so.1 would do during
2185 2185 * its dependency processing).
2186 2186 */
2187 2187 if (rpath && (sdf->sdf_rpath == NULL))
2188 2188 sdf->sdf_rpath = rpath;
2189 2189
2190 2190 } else if (dyn->d_tag == DT_FLAGS_1) {
2191 2191 if (dyn->d_un.d_val & (DF_1_INITFIRST | DF_1_INTERPOSE))
2192 2192 ifl->ifl_flags &= ~FLG_IF_LAZYLD;
2193 2193 if (dyn->d_un.d_val & DF_1_DISPRELPND)
2194 2194 ifl->ifl_flags |= FLG_IF_DISPPEND;
2195 2195 if (dyn->d_un.d_val & DF_1_DISPRELDNE)
2196 2196 ifl->ifl_flags |= FLG_IF_DISPDONE;
2197 2197 if (dyn->d_un.d_val & DF_1_NODIRECT)
2198 2198 ifl->ifl_flags |= FLG_IF_NODIRECT;
2199 2199
2200 2200 /*
2201 2201 * If we are building an executable, and this
2202 2202 * dependency is tagged as an interposer, then
2203 2203 * assume that it is required even if symbol
2204 2204 * resolution uncovers no evident use.
2205 2205 *
2206 2206 * If we are building a shared object, then an
2207 2207 * interposer dependency has no special meaning, and we
2208 2208 * treat it as a regular dependency. By definition, all
2209 2209 * interposers must be visible to the runtime linker
2210 2210 * at initialization time, and cannot be added later.
2211 2211 */
2212 2212 if ((dyn->d_un.d_val & DF_1_INTERPOSE) &&
2213 2213 (ofl->ofl_flags & FLG_OF_EXEC))
2214 2214 ifl->ifl_flags |= FLG_IF_DEPREQD;
2215 2215
2216 2216 } else if ((dyn->d_tag == DT_AUDIT) &&
2217 2217 (ifl->ifl_flags & FLG_IF_NEEDED)) {
2218 2218 /*
2219 2219 * Record audit string as DT_DEPAUDIT.
2220 2220 */
2221 2221 if ((ofl->ofl_depaudit = add_string(ofl->ofl_depaudit,
2222 2222 (str + (size_t)dyn->d_un.d_val))) ==
2223 2223 (const char *)S_ERROR)
2224 2224 return (S_ERROR);
2225 2225
2226 2226 } else if (dyn->d_tag == DT_SUNW_RTLDINF) {
2227 2227 /*
2228 2228 * If this dependency has the DT_SUNW_RTLDINF .dynamic
2229 2229 * entry, then ensure no specialized dependency
2230 2230 * processing is in effect. This tag identifies libc,
2231 2231 * which provides critical startup information (TLS
2232 2232 * routines, threads initialization, etc.) that must
2233 2233 * be exercised as part of process initialization.
2234 2234 */
2235 2235 ifl->ifl_flags &= ~MSK_IF_POSFLAG1;
2236 2236
2237 2237 /*
2238 2238 * libc is not subject to the usual guidance checks
2239 2239 * for lazy loading. It cannot be lazy loaded, libld
2240 2240 * ignores the request, and rtld would ignore the
2241 2241 * setting if it were present.
2242 2242 */
2243 2243 ifl->ifl_flags |= FLG_IF_RTLDINF;
2244 2244 }
2245 2245 }
2246 2246
2247 2247 /*
2248 2248 * Perform some SONAME sanity checks.
2249 2249 */
2250 2250 if (ifl->ifl_flags & FLG_IF_NEEDED) {
2251 2251 Ifl_desc *sifl;
2252 2252 Aliste idx;
2253 2253
2254 2254 /*
2255 2255 * Determine if anyone else will cause the same SONAME to be
2256 2256 * used (this is either caused by two different files having the
2257 2257 * same SONAME, or by one file SONAME actually matching another
2258 2258 * file basename (if no SONAME is specified within a shared
2259 2259 * library its basename will be used)). Probably rare, but some
2260 2260 * idiot will do it.
2261 2261 */
2262 2262 for (APLIST_TRAVERSE(ofl->ofl_sos, idx, sifl)) {
2263 2263 if ((strcmp(ifl->ifl_soname, sifl->ifl_soname) == 0) &&
2264 2264 (ifl != sifl)) {
2265 2265 const char *hint, *iflb, *siflb;
2266 2266
2267 2267 /*
2268 2268 * Determine the basename of each file. Perhaps
2269 2269 * there are multiple copies of the same file
2270 2270 * being brought in using different -L search
2271 2271 * paths, and if so give an extra hint in the
2272 2272 * error message.
2273 2273 */
2274 2274 iflb = strrchr(ifl->ifl_name, '/');
2275 2275 if (iflb == NULL)
2276 2276 iflb = ifl->ifl_name;
2277 2277 else
2278 2278 iflb++;
2279 2279
2280 2280 siflb = strrchr(sifl->ifl_name, '/');
2281 2281 if (siflb == NULL)
2282 2282 siflb = sifl->ifl_name;
2283 2283 else
2284 2284 siflb++;
2285 2285
2286 2286 if (strcmp(iflb, siflb) == 0)
2287 2287 hint = MSG_INTL(MSG_REC_CNFLTHINT);
2288 2288 else
2289 2289 hint = MSG_ORIG(MSG_STR_EMPTY);
2290 2290
2291 2291 ld_eprintf(ofl, ERR_FATAL,
2292 2292 MSG_INTL(MSG_REC_OBJCNFLT), sifl->ifl_name,
2293 2293 ifl->ifl_name, sifl->ifl_soname, hint);
2294 2294 return (0);
2295 2295 }
2296 2296 }
2297 2297
2298 2298 /*
2299 2299 * If the SONAME is the same as the name the user wishes to
2300 2300 * record when building a dynamic library (refer -h option),
2301 2301 * we also have a name clash.
2302 2302 */
2303 2303 if (ofl->ofl_soname &&
2304 2304 (strcmp(ofl->ofl_soname, ifl->ifl_soname) == 0)) {
2305 2305 ld_eprintf(ofl, ERR_FATAL,
2306 2306 MSG_INTL(MSG_REC_OPTCNFLT), ifl->ifl_name,
2307 2307 MSG_INTL(MSG_MARG_SONAME), ifl->ifl_soname);
2308 2308 return (0);
2309 2309 }
2310 2310 }
2311 2311 return (1);
2312 2312 }
2313 2313
2314 2314 /*
2315 2315 * Process a progbits section from a relocatable object (ET_REL).
2316 2316 * This is used on non-amd64 objects to recognize .eh_frame sections.
2317 2317 */
2318 2318 /*ARGSUSED1*/
2319 2319 static uintptr_t
2320 2320 process_progbits_final(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
2321 2321 {
2322 2322 if (isc->is_osdesc && (isc->is_flags & FLG_IS_EHFRAME) &&
2323 2323 (ld_unwind_register(isc->is_osdesc, ofl) == S_ERROR))
2324 2324 return (S_ERROR);
2325 2325
2326 2326 return (1);
2327 2327 }
2328 2328
2329 2329 /*
2330 2330 * Process a group section.
2331 2331 */
2332 2332 static uintptr_t
2333 2333 process_group(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
2334 2334 Word ndx, int ident, Ofl_desc *ofl)
2335 2335 {
↓ open down ↓ |
2335 lines elided |
↑ open up ↑ |
2336 2336 uintptr_t error;
2337 2337
2338 2338 error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
2339 2339 if ((error == 0) || (error == S_ERROR))
2340 2340 return (error);
2341 2341
2342 2342 /*
2343 2343 * Indicate that this input file has groups to process. Groups are
2344 2344 * processed after all input sections have been processed.
2345 2345 */
2346 - ifl->ifl_flags |= FLG_IS_GROUPS;
2346 + ifl->ifl_flags |= FLG_IF_GROUPS;
2347 2347
2348 2348 return (1);
2349 2349 }
2350 2350
2351 2351 /*
2352 2352 * Process a relocation entry. At this point all input sections from this
2353 2353 * input file have been assigned an input section descriptor which is saved
2354 2354 * in the `ifl_isdesc' array.
2355 2355 */
2356 2356 static uintptr_t
2357 2357 rel_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
2358 2358 {
2359 2359 Word rndx;
2360 2360 Is_desc *risc;
2361 2361 Os_desc *osp;
2362 2362 Shdr *shdr = isc->is_shdr;
2363 2363 Conv_inv_buf_t inv_buf;
2364 2364
2365 2365 /*
2366 2366 * Make sure this is a valid relocation we can handle.
2367 2367 */
2368 2368 if (shdr->sh_type != ld_targ.t_m.m_rel_sht_type) {
2369 2369 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVALSEC),
2370 2370 ifl->ifl_name, EC_WORD(isc->is_scnndx), isc->is_name,
2371 2371 conv_sec_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
2372 2372 ifl->ifl_ehdr->e_machine, shdr->sh_type, 0, &inv_buf));
2373 2373 return (0);
2374 2374 }
2375 2375
2376 2376 /*
2377 2377 * From the relocation section header information determine which
2378 2378 * section needs the actual relocation. Determine which output section
2379 2379 * this input section has been assigned to and add to its relocation
2380 2380 * list. Note that the relocation section may be null if it is not
2381 2381 * required (ie. .debug, .stabs, etc).
2382 2382 */
2383 2383 rndx = shdr->sh_info;
2384 2384 if (rndx >= ifl->ifl_shnum) {
2385 2385 /*
2386 2386 * Broken input file.
2387 2387 */
2388 2388 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHINFO),
2389 2389 ifl->ifl_name, EC_WORD(isc->is_scnndx), isc->is_name,
2390 2390 EC_XWORD(rndx));
2391 2391 return (0);
2392 2392 }
2393 2393 if (rndx == 0) {
2394 2394 if (aplist_append(&ofl->ofl_extrarels, isc,
2395 2395 AL_CNT_OFL_RELS) == NULL)
2396 2396 return (S_ERROR);
2397 2397
2398 2398 } else if ((risc = ifl->ifl_isdesc[rndx]) != NULL) {
2399 2399 /*
2400 2400 * Discard relocations if they are against a section
2401 2401 * which has been discarded.
2402 2402 */
2403 2403 if (risc->is_flags & FLG_IS_DISCARD)
2404 2404 return (1);
2405 2405
2406 2406 if ((osp = risc->is_osdesc) == NULL) {
2407 2407 if (risc->is_shdr->sh_type == SHT_SUNW_move) {
2408 2408 /*
2409 2409 * This section is processed later in
2410 2410 * process_movereloc().
2411 2411 */
2412 2412 if (aplist_append(&ofl->ofl_ismoverel,
2413 2413 isc, AL_CNT_OFL_MOVE) == NULL)
2414 2414 return (S_ERROR);
2415 2415 return (1);
2416 2416 }
2417 2417 ld_eprintf(ofl, ERR_FATAL,
2418 2418 MSG_INTL(MSG_FIL_INVRELOC1), ifl->ifl_name,
2419 2419 EC_WORD(isc->is_scnndx), isc->is_name,
2420 2420 EC_WORD(risc->is_scnndx), risc->is_name);
2421 2421 return (0);
2422 2422 }
2423 2423 if (aplist_append(&osp->os_relisdescs, isc,
2424 2424 AL_CNT_OS_RELISDESCS) == NULL)
2425 2425 return (S_ERROR);
2426 2426 }
2427 2427 return (1);
2428 2428 }
2429 2429
2430 2430 /*
2431 2431 * SHF_EXCLUDE flags is set for this section.
2432 2432 */
2433 2433 static uintptr_t
2434 2434 process_exclude(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
2435 2435 Word ndx, Ofl_desc *ofl)
2436 2436 {
2437 2437 /*
2438 2438 * Sections SHT_SYMTAB and SHT_DYNDYM, even if SHF_EXCLUDE is on, might
2439 2439 * be needed for ld processing. These sections need to be in the
2440 2440 * internal table. Later it will be determined whether they can be
2441 2441 * eliminated or not.
2442 2442 */
2443 2443 if (shdr->sh_type == SHT_SYMTAB || shdr->sh_type == SHT_DYNSYM)
2444 2444 return (0);
2445 2445
2446 2446 /*
2447 2447 * Other checks
2448 2448 */
2449 2449 if (shdr->sh_flags & SHF_ALLOC) {
2450 2450 /*
2451 2451 * A conflict, issue an warning message, and ignore the section.
2452 2452 */
2453 2453 ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_EXCLUDE),
2454 2454 ifl->ifl_name, EC_WORD(ndx), name);
2455 2455 return (0);
2456 2456 }
2457 2457
2458 2458 /*
2459 2459 * This sections is not going to the output file.
2460 2460 */
2461 2461 return (process_section(name, ifl, shdr, scn, ndx, 0, ofl));
2462 2462 }
2463 2463
2464 2464 /*
2465 2465 * Section processing state table. `Initial' describes the required initial
2466 2466 * procedure to be called (if any), `Final' describes the final processing
2467 2467 * procedure (ie. things that can only be done when all required sections
2468 2468 * have been collected).
2469 2469 */
2470 2470 typedef uintptr_t (* initial_func_t)(const char *, Ifl_desc *, Shdr *,
2471 2471 Elf_Scn *, Word, int, Ofl_desc *);
2472 2472
2473 2473 static initial_func_t Initial[SHT_NUM][2] = {
2474 2474 /* ET_REL ET_DYN */
2475 2475
2476 2476 /* SHT_NULL */ invalid_section, invalid_section,
2477 2477 /* SHT_PROGBITS */ process_progbits, process_progbits,
2478 2478 /* SHT_SYMTAB */ process_input, process_input,
2479 2479 /* SHT_STRTAB */ process_strtab, process_strtab,
2480 2480 /* SHT_RELA */ process_reloc, process_reloc,
2481 2481 /* SHT_HASH */ invalid_section, NULL,
2482 2482 /* SHT_DYNAMIC */ process_rel_dynamic, process_dynamic_isgnu,
2483 2483 /* SHT_NOTE */ process_section, NULL,
2484 2484 /* SHT_NOBITS */ process_nobits, process_nobits,
2485 2485 /* SHT_REL */ process_reloc, process_reloc,
2486 2486 /* SHT_SHLIB */ process_section, invalid_section,
2487 2487 /* SHT_DYNSYM */ invalid_section, process_input,
2488 2488 /* SHT_UNKNOWN12 */ process_progbits, process_progbits,
2489 2489 /* SHT_UNKNOWN13 */ process_progbits, process_progbits,
2490 2490 /* SHT_INIT_ARRAY */ process_array, NULL,
2491 2491 /* SHT_FINI_ARRAY */ process_array, NULL,
2492 2492 /* SHT_PREINIT_ARRAY */ process_array, NULL,
2493 2493 /* SHT_GROUP */ process_group, invalid_section,
2494 2494 /* SHT_SYMTAB_SHNDX */ process_sym_shndx, NULL
2495 2495 };
2496 2496
2497 2497 typedef uintptr_t (* final_func_t)(Is_desc *, Ifl_desc *, Ofl_desc *);
2498 2498
2499 2499 static final_func_t Final[SHT_NUM][2] = {
2500 2500 /* ET_REL ET_DYN */
2501 2501
2502 2502 /* SHT_NULL */ NULL, NULL,
2503 2503 /* SHT_PROGBITS */ process_progbits_final, NULL,
2504 2504 /* SHT_SYMTAB */ ld_sym_process, ld_sym_process,
2505 2505 /* SHT_STRTAB */ NULL, NULL,
2506 2506 /* SHT_RELA */ rel_process, NULL,
2507 2507 /* SHT_HASH */ NULL, NULL,
2508 2508 /* SHT_DYNAMIC */ NULL, process_dynamic,
2509 2509 /* SHT_NOTE */ NULL, NULL,
2510 2510 /* SHT_NOBITS */ NULL, NULL,
2511 2511 /* SHT_REL */ rel_process, NULL,
2512 2512 /* SHT_SHLIB */ NULL, NULL,
2513 2513 /* SHT_DYNSYM */ NULL, ld_sym_process,
2514 2514 /* SHT_UNKNOWN12 */ NULL, NULL,
2515 2515 /* SHT_UNKNOWN13 */ NULL, NULL,
2516 2516 /* SHT_INIT_ARRAY */ array_process, NULL,
2517 2517 /* SHT_FINI_ARRAY */ array_process, NULL,
2518 2518 /* SHT_PREINIT_ARRAY */ array_process, NULL,
2519 2519 /* SHT_GROUP */ NULL, NULL,
2520 2520 /* SHT_SYMTAB_SHNDX */ sym_shndx_process, NULL
2521 2521 };
2522 2522
2523 2523 #define MAXNDXSIZE 10
2524 2524
2525 2525 /*
2526 2526 * Process an elf file. Each section is compared against the section state
2527 2527 * table to determine whether it should be processed (saved), ignored, or
2528 2528 * is invalid for the type of input file being processed.
2529 2529 */
2530 2530 static uintptr_t
2531 2531 process_elf(Ifl_desc *ifl, Elf *elf, Ofl_desc *ofl)
2532 2532 {
2533 2533 Elf_Scn *scn;
2534 2534 Shdr *shdr;
2535 2535 Word ndx, sndx, ordndx = 0, ordcnt = 0;
2536 2536 char *str, *name;
2537 2537 Word row, column;
2538 2538 int ident;
2539 2539 uintptr_t error;
2540 2540 Is_desc *vdfisp, *vndisp, *vsyisp, *sifisp;
2541 2541 Is_desc *capinfoisp, *capisp;
2542 2542 Sdf_desc *sdf;
2543 2543 Place_path_info path_info_buf, *path_info;
2544 2544
2545 2545 /*
2546 2546 * Path information buffer used by ld_place_section() and related
2547 2547 * routines. This information is used to evaluate entrance criteria
2548 2548 * with non-empty file matching lists (ec_files).
2549 2549 */
2550 2550 path_info = ld_place_path_info_init(ofl, ifl, &path_info_buf);
2551 2551
2552 2552 /*
2553 2553 * First process the .shstrtab section so that later sections can
2554 2554 * reference their name.
2555 2555 */
2556 2556 ld_sup_file(ofl, ifl->ifl_name, elf_kind(elf), ifl->ifl_flags, elf);
2557 2557
2558 2558 sndx = ifl->ifl_shstrndx;
2559 2559 if ((scn = elf_getscn(elf, (size_t)sndx)) == NULL) {
2560 2560 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN),
2561 2561 ifl->ifl_name);
2562 2562 return (0);
2563 2563 }
2564 2564 if ((shdr = elf_getshdr(scn)) == NULL) {
2565 2565 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR),
2566 2566 ifl->ifl_name);
2567 2567 return (0);
2568 2568 }
2569 2569 if ((name = elf_strptr(elf, (size_t)sndx, (size_t)shdr->sh_name)) ==
2570 2570 NULL) {
2571 2571 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR),
2572 2572 ifl->ifl_name);
2573 2573 return (0);
2574 2574 }
2575 2575
2576 2576 if (ld_sup_input_section(ofl, ifl, name, &shdr, sndx, scn,
2577 2577 elf) == S_ERROR)
2578 2578 return (S_ERROR);
2579 2579
2580 2580 /*
2581 2581 * Reset the name since the shdr->sh_name could have been changed as
2582 2582 * part of ld_sup_input_section().
2583 2583 */
2584 2584 if ((name = elf_strptr(elf, (size_t)sndx, (size_t)shdr->sh_name)) ==
2585 2585 NULL) {
2586 2586 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR),
2587 2587 ifl->ifl_name);
2588 2588 return (0);
2589 2589 }
2590 2590
2591 2591 error = process_strtab(name, ifl, shdr, scn, sndx, FALSE, ofl);
2592 2592 if ((error == 0) || (error == S_ERROR))
2593 2593 return (error);
2594 2594 str = ifl->ifl_isdesc[sndx]->is_indata->d_buf;
2595 2595
2596 2596 /*
2597 2597 * Determine the state table column from the input file type. Note,
2598 2598 * shared library sections are not added to the output section list.
2599 2599 */
2600 2600 if (ifl->ifl_ehdr->e_type == ET_DYN) {
2601 2601 column = 1;
2602 2602 ofl->ofl_soscnt++;
2603 2603 ident = ld_targ.t_id.id_null;
2604 2604 } else {
2605 2605 column = 0;
2606 2606 ofl->ofl_objscnt++;
2607 2607 ident = ld_targ.t_id.id_unknown;
2608 2608 }
2609 2609
2610 2610 DBG_CALL(Dbg_file_generic(ofl->ofl_lml, ifl));
2611 2611 ndx = 0;
2612 2612 vdfisp = vndisp = vsyisp = sifisp = capinfoisp = capisp = NULL;
2613 2613 scn = NULL;
2614 2614 while (scn = elf_nextscn(elf, scn)) {
2615 2615 ndx++;
2616 2616
2617 2617 /*
2618 2618 * As we've already processed the .shstrtab don't do it again.
2619 2619 */
2620 2620 if (ndx == sndx)
2621 2621 continue;
2622 2622
2623 2623 if ((shdr = elf_getshdr(scn)) == NULL) {
2624 2624 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR),
2625 2625 ifl->ifl_name);
2626 2626 return (0);
2627 2627 }
2628 2628 name = str + (size_t)(shdr->sh_name);
2629 2629
2630 2630 if (ld_sup_input_section(ofl, ifl, name, &shdr, ndx, scn,
2631 2631 elf) == S_ERROR)
2632 2632 return (S_ERROR);
2633 2633
2634 2634 /*
2635 2635 * Reset the name since the shdr->sh_name could have been
2636 2636 * changed as part of ld_sup_input_section().
2637 2637 */
2638 2638 name = str + (size_t)(shdr->sh_name);
2639 2639
2640 2640 row = shdr->sh_type;
2641 2641
2642 2642 /*
2643 2643 * If the section has the SHF_EXCLUDE flag on, and we're not
2644 2644 * generating a relocatable object, exclude the section.
2645 2645 */
2646 2646 if (((shdr->sh_flags & SHF_EXCLUDE) != 0) &&
2647 2647 ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0)) {
2648 2648 if ((error = process_exclude(name, ifl, shdr, scn,
2649 2649 ndx, ofl)) == S_ERROR)
2650 2650 return (S_ERROR);
2651 2651 if (error == 1)
2652 2652 continue;
2653 2653 }
2654 2654
2655 2655 /*
2656 2656 * If this is a standard section type process it via the
2657 2657 * appropriate action routine.
2658 2658 */
2659 2659 if (row < SHT_NUM) {
2660 2660 if (Initial[row][column] != NULL) {
2661 2661 if (Initial[row][column](name, ifl, shdr, scn,
2662 2662 ndx, ident, ofl) == S_ERROR)
2663 2663 return (S_ERROR);
2664 2664 }
2665 2665 } else {
2666 2666 /*
2667 2667 * If this section is below SHT_LOSUNW then we don't
2668 2668 * really know what to do with it, issue a warning
2669 2669 * message but do the basic section processing anyway.
2670 2670 */
2671 2671 if (row < (Word)SHT_LOSUNW) {
2672 2672 Conv_inv_buf_t inv_buf;
2673 2673
2674 2674 ld_eprintf(ofl, ERR_WARNING,
2675 2675 MSG_INTL(MSG_FIL_INVALSEC), ifl->ifl_name,
2676 2676 EC_WORD(ndx), name, conv_sec_type(
2677 2677 ifl->ifl_ehdr->e_ident[EI_OSABI],
2678 2678 ifl->ifl_ehdr->e_machine,
2679 2679 shdr->sh_type, 0, &inv_buf));
2680 2680 }
2681 2681
2682 2682 /*
2683 2683 * Handle sections greater than SHT_LOSUNW.
2684 2684 */
2685 2685 switch (row) {
2686 2686 case SHT_SUNW_dof:
2687 2687 if (process_section(name, ifl, shdr, scn,
2688 2688 ndx, ident, ofl) == S_ERROR)
2689 2689 return (S_ERROR);
2690 2690 break;
2691 2691 case SHT_SUNW_cap:
2692 2692 if (process_section(name, ifl, shdr, scn, ndx,
2693 2693 ld_targ.t_id.id_null, ofl) == S_ERROR)
2694 2694 return (S_ERROR);
2695 2695 capisp = ifl->ifl_isdesc[ndx];
2696 2696 break;
2697 2697 case SHT_SUNW_capinfo:
2698 2698 if (process_section(name, ifl, shdr, scn, ndx,
2699 2699 ld_targ.t_id.id_null, ofl) == S_ERROR)
2700 2700 return (S_ERROR);
2701 2701 capinfoisp = ifl->ifl_isdesc[ndx];
2702 2702 break;
2703 2703 case SHT_SUNW_DEBUGSTR:
2704 2704 case SHT_SUNW_DEBUG:
2705 2705 if (process_debug(name, ifl, shdr, scn,
2706 2706 ndx, ident, ofl) == S_ERROR)
2707 2707 return (S_ERROR);
2708 2708 break;
2709 2709 case SHT_SUNW_move:
2710 2710 if (process_section(name, ifl, shdr, scn, ndx,
2711 2711 ld_targ.t_id.id_null, ofl) == S_ERROR)
2712 2712 return (S_ERROR);
2713 2713 break;
2714 2714 case SHT_SUNW_syminfo:
2715 2715 if (process_section(name, ifl, shdr, scn, ndx,
2716 2716 ld_targ.t_id.id_null, ofl) == S_ERROR)
2717 2717 return (S_ERROR);
2718 2718 sifisp = ifl->ifl_isdesc[ndx];
2719 2719 break;
2720 2720 case SHT_SUNW_ANNOTATE:
2721 2721 if (process_progbits(name, ifl, shdr, scn,
2722 2722 ndx, ident, ofl) == S_ERROR)
2723 2723 return (S_ERROR);
2724 2724 break;
2725 2725 case SHT_SUNW_COMDAT:
2726 2726 if (process_progbits(name, ifl, shdr, scn,
2727 2727 ndx, ident, ofl) == S_ERROR)
2728 2728 return (S_ERROR);
2729 2729 ifl->ifl_isdesc[ndx]->is_flags |= FLG_IS_COMDAT;
2730 2730 break;
2731 2731 case SHT_SUNW_verdef:
2732 2732 if (process_section(name, ifl, shdr, scn, ndx,
2733 2733 ld_targ.t_id.id_null, ofl) == S_ERROR)
2734 2734 return (S_ERROR);
2735 2735 vdfisp = ifl->ifl_isdesc[ndx];
2736 2736 break;
2737 2737 case SHT_SUNW_verneed:
2738 2738 if (process_section(name, ifl, shdr, scn, ndx,
2739 2739 ld_targ.t_id.id_null, ofl) == S_ERROR)
2740 2740 return (S_ERROR);
2741 2741 vndisp = ifl->ifl_isdesc[ndx];
2742 2742 break;
2743 2743 case SHT_SUNW_versym:
2744 2744 if (process_section(name, ifl, shdr, scn, ndx,
2745 2745 ld_targ.t_id.id_null, ofl) == S_ERROR)
2746 2746 return (S_ERROR);
2747 2747 vsyisp = ifl->ifl_isdesc[ndx];
2748 2748 break;
2749 2749 case SHT_SPARC_GOTDATA:
2750 2750 /*
2751 2751 * SHT_SPARC_GOTDATA (0x70000000) is in the
2752 2752 * SHT_LOPROC - SHT_HIPROC range reserved
2753 2753 * for processor-specific semantics. It is
2754 2754 * only meaningful for sparc targets.
2755 2755 */
2756 2756 if (ld_targ.t_m.m_mach !=
2757 2757 LD_TARG_BYCLASS(EM_SPARC, EM_SPARCV9))
2758 2758 goto do_default;
2759 2759 if (process_section(name, ifl, shdr, scn, ndx,
2760 2760 ld_targ.t_id.id_gotdata, ofl) == S_ERROR)
2761 2761 return (S_ERROR);
2762 2762 break;
2763 2763 #if defined(_ELF64)
2764 2764 case SHT_AMD64_UNWIND:
2765 2765 /*
2766 2766 * SHT_AMD64_UNWIND (0x70000001) is in the
2767 2767 * SHT_LOPROC - SHT_HIPROC range reserved
2768 2768 * for processor-specific semantics. It is
2769 2769 * only meaningful for amd64 targets.
2770 2770 */
2771 2771 if (ld_targ.t_m.m_mach != EM_AMD64)
2772 2772 goto do_default;
2773 2773
2774 2774 /*
2775 2775 * Target is x86, so this really is
2776 2776 * SHT_AMD64_UNWIND
2777 2777 */
2778 2778 if (column == 0) {
2779 2779 /*
2780 2780 * column == ET_REL
2781 2781 */
2782 2782 if (process_section(name, ifl, shdr,
2783 2783 scn, ndx, ld_targ.t_id.id_unwind,
2784 2784 ofl) == S_ERROR)
2785 2785 return (S_ERROR);
2786 2786 ifl->ifl_isdesc[ndx]->is_flags |=
2787 2787 FLG_IS_EHFRAME;
2788 2788 }
2789 2789 break;
2790 2790 #endif
2791 2791 default:
2792 2792 do_default:
2793 2793 if (process_section(name, ifl, shdr, scn, ndx,
2794 2794 ((ident == ld_targ.t_id.id_null) ?
2795 2795 ident : ld_targ.t_id.id_user), ofl) ==
2796 2796 S_ERROR)
2797 2797 return (S_ERROR);
2798 2798 break;
2799 2799 }
↓ open down ↓ |
443 lines elided |
↑ open up ↑ |
2800 2800 }
2801 2801 }
2802 2802
2803 2803 /*
2804 2804 * Now that all input sections have been analyzed, and prior to placing
2805 2805 * any input sections to their output sections, process any groups.
2806 2806 * Groups can contribute COMDAT items, which may get discarded as part
2807 2807 * of placement. In addition, COMDAT names may require transformation
2808 2808 * to indicate different output section placement.
2809 2809 */
2810 - if (ifl->ifl_flags & FLG_IS_GROUPS) {
2810 + if (ifl->ifl_flags & FLG_IF_GROUPS) {
2811 2811 for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) {
2812 2812 Is_desc *isp;
2813 2813
2814 2814 if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
2815 2815 (isp->is_shdr->sh_type != SHT_GROUP))
2816 2816 continue;
2817 2817
2818 2818 if (ld_group_process(isp, ofl) == S_ERROR)
2819 2819 return (S_ERROR);
2820 2820 }
2821 2821 }
2822 2822
2823 2823 /*
2824 2824 * Now that all of the input sections have been processed, place
2825 2825 * them in the appropriate output sections.
2826 2826 */
2827 2827 for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) {
2828 2828 Is_desc *isp;
2829 2829
2830 2830 if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
2831 2831 ((isp->is_flags & FLG_IS_PLACE) == 0))
2832 2832 continue;
2833 2833
2834 2834 /*
2835 2835 * Place all non-ordered sections within their appropriate
2836 2836 * output section.
2837 2837 */
2838 2838 if ((isp->is_flags & FLG_IS_ORDERED) == 0) {
2839 2839 if (ld_place_section(ofl, isp, path_info,
2840 2840 isp->is_keyident, NULL) == (Os_desc *)S_ERROR)
2841 2841 return (S_ERROR);
2842 2842 continue;
2843 2843 }
2844 2844
2845 2845 /*
2846 2846 * Count the number of ordered sections and retain the first
2847 2847 * ordered section index. This will be used to optimize the
2848 2848 * ordered section loop that immediately follows this one.
2849 2849 */
2850 2850 ordcnt++;
2851 2851 if (ordndx == 0)
2852 2852 ordndx = ndx;
2853 2853 }
2854 2854
2855 2855 /*
2856 2856 * Having placed all the non-ordered sections, it is now
2857 2857 * safe to place SHF_ORDERED/SHF_LINK_ORDER sections.
2858 2858 */
2859 2859 if (ifl->ifl_flags & FLG_IF_ORDERED) {
2860 2860 for (ndx = ordndx; ndx < ifl->ifl_shnum; ndx++) {
2861 2861 Is_desc *isp;
2862 2862
2863 2863 if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
2864 2864 ((isp->is_flags &
2865 2865 (FLG_IS_PLACE | FLG_IS_ORDERED)) !=
2866 2866 (FLG_IS_PLACE | FLG_IS_ORDERED)))
2867 2867 continue;
2868 2868
2869 2869 /* ld_process_ordered() calls ld_place_section() */
2870 2870 if (ld_process_ordered(ofl, ifl, path_info, ndx) ==
2871 2871 S_ERROR)
2872 2872 return (S_ERROR);
2873 2873
2874 2874 /* If we've done them all, stop searching */
2875 2875 if (--ordcnt == 0)
2876 2876 break;
2877 2877 }
2878 2878 }
2879 2879
2880 2880 /*
2881 2881 * If this is a shared object explicitly specified on the command
2882 2882 * line (as opposed to being a dependency of such an object),
2883 2883 * determine if the user has specified a control definition. This
2884 2884 * descriptor may specify which version definitions can be used
2885 2885 * from this object. It may also update the dependency to USED and
2886 2886 * supply an alternative SONAME.
2887 2887 */
2888 2888 sdf = NULL;
2889 2889 if (column && (ifl->ifl_flags & FLG_IF_NEEDED)) {
2890 2890 const char *base;
2891 2891
2892 2892 /*
2893 2893 * Use the basename of the input file (typically this is the
2894 2894 * compilation environment name, ie. libfoo.so).
2895 2895 */
2896 2896 if ((base = strrchr(ifl->ifl_name, '/')) == NULL)
2897 2897 base = ifl->ifl_name;
2898 2898 else
2899 2899 base++;
2900 2900
2901 2901 if ((sdf = sdf_find(base, ofl->ofl_socntl)) != NULL) {
2902 2902 sdf->sdf_file = ifl;
2903 2903 ifl->ifl_sdfdesc = sdf;
2904 2904 }
2905 2905 }
2906 2906
2907 2907 /*
2908 2908 * Before symbol processing, process any capabilities. Capabilities
2909 2909 * can reference a string table, which is why this processing is
2910 2910 * carried out after the initial section processing. Capabilities,
2911 2911 * together with -z symbolcap, can require the conversion of global
2912 2912 * symbols to local symbols.
2913 2913 */
2914 2914 if (capisp && (process_cap(ofl, ifl, capisp) == S_ERROR))
2915 2915 return (S_ERROR);
2916 2916
2917 2917 /*
2918 2918 * Process any version dependencies. These will establish shared object
2919 2919 * `needed' entries in the same manner as will be generated from the
2920 2920 * .dynamic's NEEDED entries.
2921 2921 */
2922 2922 if (vndisp && ((ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)) ||
2923 2923 OFL_GUIDANCE(ofl, FLG_OFG_NO_DEFS)))
2924 2924 if (ld_vers_need_process(vndisp, ifl, ofl) == S_ERROR)
2925 2925 return (S_ERROR);
2926 2926
2927 2927 /*
2928 2928 * Before processing any symbol resolution or relocations process any
2929 2929 * version sections.
2930 2930 */
2931 2931 if (vsyisp)
2932 2932 (void) ld_vers_sym_process(ofl, vsyisp, ifl);
2933 2933
2934 2934 if (ifl->ifl_versym &&
2935 2935 (vdfisp || (sdf && (sdf->sdf_flags & FLG_SDF_SELECT))))
2936 2936 if (ld_vers_def_process(vdfisp, ifl, ofl) == S_ERROR)
2937 2937 return (S_ERROR);
2938 2938
2939 2939 /*
2940 2940 * Having collected the appropriate sections carry out any additional
2941 2941 * processing if necessary.
2942 2942 */
2943 2943 for (ndx = 0; ndx < ifl->ifl_shnum; ndx++) {
2944 2944 Is_desc *isp;
2945 2945
2946 2946 if ((isp = ifl->ifl_isdesc[ndx]) == NULL)
2947 2947 continue;
2948 2948 row = isp->is_shdr->sh_type;
2949 2949
2950 2950 if ((isp->is_flags & FLG_IS_DISCARD) == 0)
2951 2951 ld_sup_section(ofl, isp->is_name, isp->is_shdr, ndx,
2952 2952 isp->is_indata, elf);
2953 2953
2954 2954 /*
2955 2955 * If this is a SHT_SUNW_move section from a relocatable file,
2956 2956 * keep track of the section for later processing.
2957 2957 */
2958 2958 if ((row == SHT_SUNW_move) && (column == 0)) {
2959 2959 if (aplist_append(&(ofl->ofl_ismove), isp,
2960 2960 AL_CNT_OFL_MOVE) == NULL)
2961 2961 return (S_ERROR);
2962 2962 }
2963 2963
2964 2964 /*
2965 2965 * If this is a standard section type process it via the
2966 2966 * appropriate action routine.
2967 2967 */
2968 2968 if (row < SHT_NUM) {
2969 2969 if (Final[row][column] != NULL) {
2970 2970 if (Final[row][column](isp, ifl,
2971 2971 ofl) == S_ERROR)
2972 2972 return (S_ERROR);
2973 2973 }
2974 2974 #if defined(_ELF64)
2975 2975 } else if ((row == SHT_AMD64_UNWIND) && (column == 0)) {
2976 2976 Os_desc *osp = isp->is_osdesc;
2977 2977
2978 2978 /*
2979 2979 * SHT_AMD64_UNWIND (0x70000001) is in the SHT_LOPROC -
2980 2980 * SHT_HIPROC range reserved for processor-specific
2981 2981 * semantics, and is only meaningful for amd64 targets.
2982 2982 *
2983 2983 * Only process unwind contents from relocatable
2984 2984 * objects.
2985 2985 */
2986 2986 if (osp && (ld_targ.t_m.m_mach == EM_AMD64) &&
2987 2987 (ld_unwind_register(osp, ofl) == S_ERROR))
2988 2988 return (S_ERROR);
2989 2989 #endif
2990 2990 }
2991 2991 }
2992 2992
2993 2993 /*
2994 2994 * Following symbol processing, if this relocatable object input file
2995 2995 * provides symbol capabilities, tag the associated symbols so that
2996 2996 * the symbols can be re-assigned to the new capabilities symbol
2997 2997 * section that will be created for the output file.
2998 2998 */
2999 2999 if (capinfoisp && (ifl->ifl_ehdr->e_type == ET_REL) &&
3000 3000 (process_capinfo(ofl, ifl, capinfoisp) == S_ERROR))
3001 3001 return (S_ERROR);
3002 3002
3003 3003 /*
3004 3004 * After processing any symbol resolution, and if this dependency
3005 3005 * indicates it contains symbols that can't be directly bound to,
3006 3006 * set the symbols appropriately.
3007 3007 */
3008 3008 if (sifisp && ((ifl->ifl_flags & (FLG_IF_NEEDED | FLG_IF_NODIRECT)) ==
3009 3009 (FLG_IF_NEEDED | FLG_IF_NODIRECT)))
3010 3010 (void) ld_sym_nodirect(sifisp, ifl, ofl);
3011 3011
3012 3012 return (1);
3013 3013 }
3014 3014
3015 3015 /*
3016 3016 * Process the current input file. There are basically three types of files
3017 3017 * that come through here:
3018 3018 *
3019 3019 * - files explicitly defined on the command line (ie. foo.o or bar.so),
3020 3020 * in this case only the `name' field is valid.
3021 3021 *
3022 3022 * - libraries determined from the -l command line option (ie. -lbar),
3023 3023 * in this case the `soname' field contains the basename of the located
3024 3024 * file.
3025 3025 *
3026 3026 * Any shared object specified via the above two conventions must be recorded
3027 3027 * as a needed dependency.
3028 3028 *
3029 3029 * - libraries specified as dependencies of those libraries already obtained
3030 3030 * via the command line (ie. bar.so has a DT_NEEDED entry of fred.so.1),
3031 3031 * in this case the `soname' field contains either a full pathname (if the
3032 3032 * needed entry contained a `/'), or the basename of the located file.
3033 3033 * These libraries are processed to verify symbol binding but are not
3034 3034 * recorded as dependencies of the output file being generated.
3035 3035 *
3036 3036 * entry:
3037 3037 * name - File name
3038 3038 * soname - SONAME for needed sharable library, as described above
3039 3039 * fd - Open file descriptor
3040 3040 * elf - Open ELF handle
3041 3041 * flags - FLG_IF_ flags applicable to file
3042 3042 * ofl - Output file descriptor
3043 3043 * rej - Rejection descriptor used to record rejection reason
3044 3044 * ifl_ret - NULL, or address of pointer to receive reference to
3045 3045 * resulting input descriptor for file. If ifl_ret is non-NULL,
3046 3046 * the file cannot be an archive or it will be rejected.
3047 3047 *
3048 3048 * exit:
3049 3049 * If a error occurs in examining the file, S_ERROR is returned.
3050 3050 * If the file can be examined, but is not suitable, *rej is updated,
3051 3051 * and 0 is returned. If the file is acceptable, 1 is returned, and if
3052 3052 * ifl_ret is non-NULL, *ifl_ret is set to contain the pointer to the
3053 3053 * resulting input descriptor.
3054 3054 */
3055 3055 uintptr_t
3056 3056 ld_process_ifl(const char *name, const char *soname, int fd, Elf *elf,
3057 3057 Word flags, Ofl_desc *ofl, Rej_desc *rej, Ifl_desc **ifl_ret)
3058 3058 {
3059 3059 Ifl_desc *ifl;
3060 3060 Ehdr *ehdr;
3061 3061 uintptr_t error = 0;
3062 3062 struct stat status;
3063 3063 Ar_desc *adp;
3064 3064 Rej_desc _rej;
3065 3065
3066 3066 /*
3067 3067 * If this file was not extracted from an archive obtain its device
3068 3068 * information. This will be used to determine if the file has already
3069 3069 * been processed (rather than simply comparing filenames, the device
3070 3070 * information provides a quicker comparison and detects linked files).
3071 3071 */
3072 3072 if (fd && ((flags & FLG_IF_EXTRACT) == 0))
3073 3073 (void) fstat(fd, &status);
3074 3074 else {
3075 3075 status.st_dev = 0;
3076 3076 status.st_ino = 0;
3077 3077 }
3078 3078
3079 3079 switch (elf_kind(elf)) {
3080 3080 case ELF_K_AR:
3081 3081 /*
3082 3082 * If the caller has supplied a non-NULL ifl_ret, then
3083 3083 * we cannot process archives, for there will be no
3084 3084 * input file descriptor for us to return. In this case,
3085 3085 * reject the attempt.
3086 3086 */
3087 3087 if (ifl_ret != NULL) {
3088 3088 _rej.rej_type = SGS_REJ_ARCHIVE;
3089 3089 _rej.rej_name = name;
3090 3090 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3091 3091 ld_targ.t_m.m_mach));
3092 3092 if (rej->rej_type == 0) {
3093 3093 *rej = _rej;
3094 3094 rej->rej_name = strdup(_rej.rej_name);
3095 3095 }
3096 3096 return (0);
3097 3097 }
3098 3098
3099 3099 /*
3100 3100 * Determine if we've already come across this archive file.
3101 3101 */
3102 3102 if (!(flags & FLG_IF_EXTRACT)) {
3103 3103 Aliste idx;
3104 3104
3105 3105 for (APLIST_TRAVERSE(ofl->ofl_ars, idx, adp)) {
3106 3106 if ((adp->ad_stdev != status.st_dev) ||
3107 3107 (adp->ad_stino != status.st_ino))
3108 3108 continue;
3109 3109
3110 3110 /*
3111 3111 * We've seen this file before so reuse the
3112 3112 * original archive descriptor and discard the
3113 3113 * new elf descriptor. Note that a file
3114 3114 * descriptor is unnecessary, as the file is
3115 3115 * already available in memory.
3116 3116 */
3117 3117 DBG_CALL(Dbg_file_reuse(ofl->ofl_lml, name,
3118 3118 adp->ad_name));
3119 3119 (void) elf_end(elf);
3120 3120 if (!ld_process_archive(name, -1, adp, ofl))
3121 3121 return (S_ERROR);
3122 3122 return (1);
3123 3123 }
3124 3124 }
3125 3125
3126 3126 /*
3127 3127 * As we haven't processed this file before establish a new
3128 3128 * archive descriptor.
3129 3129 */
3130 3130 adp = ld_ar_setup(name, elf, ofl);
3131 3131 if ((adp == NULL) || (adp == (Ar_desc *)S_ERROR))
3132 3132 return ((uintptr_t)adp);
3133 3133 adp->ad_stdev = status.st_dev;
3134 3134 adp->ad_stino = status.st_ino;
3135 3135
3136 3136 ld_sup_file(ofl, name, ELF_K_AR, flags, elf);
3137 3137
3138 3138 /*
3139 3139 * Indicate that the ELF descriptor no longer requires a file
3140 3140 * descriptor by reading the entire file. The file is already
3141 3141 * read via the initial mmap(2) behind elf_begin(3elf), thus
3142 3142 * this operation is effectively a no-op. However, a side-
3143 3143 * effect is that the internal file descriptor, maintained in
3144 3144 * the ELF descriptor, is set to -1. This setting will not
3145 3145 * be compared with any file descriptor that is passed to
3146 3146 * elf_begin(), should this archive, or one of the archive
3147 3147 * members, be processed again from the command line or
3148 3148 * because of a -z rescan.
3149 3149 */
3150 3150 if (elf_cntl(elf, ELF_C_FDREAD) == -1) {
3151 3151 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_CNTL),
3152 3152 name);
3153 3153 return (0);
3154 3154 }
3155 3155
3156 3156 if (!ld_process_archive(name, -1, adp, ofl))
3157 3157 return (S_ERROR);
3158 3158 return (1);
3159 3159
3160 3160 case ELF_K_ELF:
3161 3161 /*
3162 3162 * Obtain the elf header so that we can determine what type of
3163 3163 * elf ELF_K_ELF file this is.
3164 3164 */
3165 3165 if ((ehdr = elf_getehdr(elf)) == NULL) {
3166 3166 int _class = gelf_getclass(elf);
3167 3167
3168 3168 /*
3169 3169 * This can fail for a number of reasons. Typically
3170 3170 * the object class is incorrect (ie. user is building
3171 3171 * 64-bit but managed to point at 32-bit libraries).
3172 3172 * Other ELF errors can include a truncated or corrupt
3173 3173 * file. Try to get the best error message possible.
3174 3174 */
3175 3175 if (ld_targ.t_m.m_class != _class) {
3176 3176 _rej.rej_type = SGS_REJ_CLASS;
3177 3177 _rej.rej_info = (uint_t)_class;
3178 3178 } else {
3179 3179 _rej.rej_type = SGS_REJ_STR;
3180 3180 _rej.rej_str = elf_errmsg(-1);
3181 3181 }
3182 3182 _rej.rej_name = name;
3183 3183 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3184 3184 ld_targ.t_m.m_mach));
3185 3185 if (rej->rej_type == 0) {
3186 3186 *rej = _rej;
3187 3187 rej->rej_name = strdup(_rej.rej_name);
3188 3188 }
3189 3189 return (0);
3190 3190 }
3191 3191
3192 3192 /*
3193 3193 * Determine if we've already come across this file.
3194 3194 */
3195 3195 if (!(flags & FLG_IF_EXTRACT)) {
3196 3196 APlist *apl;
3197 3197 Aliste idx;
3198 3198
3199 3199 if (ehdr->e_type == ET_REL)
3200 3200 apl = ofl->ofl_objs;
3201 3201 else
3202 3202 apl = ofl->ofl_sos;
3203 3203
3204 3204 /*
3205 3205 * Traverse the appropriate file list and determine if
3206 3206 * a dev/inode match is found.
3207 3207 */
3208 3208 for (APLIST_TRAVERSE(apl, idx, ifl)) {
3209 3209 /*
3210 3210 * Ifl_desc generated via -Nneed, therefore no
3211 3211 * actual file behind it.
3212 3212 */
3213 3213 if (ifl->ifl_flags & FLG_IF_NEEDSTR)
3214 3214 continue;
3215 3215
3216 3216 if ((ifl->ifl_stino != status.st_ino) ||
3217 3217 (ifl->ifl_stdev != status.st_dev))
3218 3218 continue;
3219 3219
3220 3220 /*
3221 3221 * Disregard (skip) this image.
3222 3222 */
3223 3223 DBG_CALL(Dbg_file_skip(ofl->ofl_lml,
3224 3224 ifl->ifl_name, name));
3225 3225 (void) elf_end(elf);
3226 3226
3227 3227 /*
3228 3228 * If the file was explicitly defined on the
3229 3229 * command line (this is always the case for
3230 3230 * relocatable objects, and is true for shared
3231 3231 * objects when they weren't specified via -l or
3232 3232 * were dragged in as an implicit dependency),
3233 3233 * then warn the user.
3234 3234 */
3235 3235 if ((flags & FLG_IF_CMDLINE) ||
3236 3236 (ifl->ifl_flags & FLG_IF_CMDLINE)) {
3237 3237 const char *errmsg;
3238 3238
3239 3239 /*
3240 3240 * Determine whether this is the same
3241 3241 * file name as originally encountered
3242 3242 * so as to provide the most
3243 3243 * descriptive diagnostic.
3244 3244 */
3245 3245 errmsg =
3246 3246 (strcmp(name, ifl->ifl_name) == 0) ?
3247 3247 MSG_INTL(MSG_FIL_MULINC_1) :
3248 3248 MSG_INTL(MSG_FIL_MULINC_2);
3249 3249 ld_eprintf(ofl, ERR_WARNING,
3250 3250 errmsg, name, ifl->ifl_name);
3251 3251 }
3252 3252 if (ifl_ret)
3253 3253 *ifl_ret = ifl;
3254 3254 return (1);
3255 3255 }
3256 3256 }
3257 3257
3258 3258 /*
3259 3259 * At this point, we know we need the file. Establish an input
3260 3260 * file descriptor and continue processing.
3261 3261 */
3262 3262 ifl = ifl_setup(name, ehdr, elf, flags, ofl, rej);
3263 3263 if ((ifl == NULL) || (ifl == (Ifl_desc *)S_ERROR))
3264 3264 return ((uintptr_t)ifl);
3265 3265 ifl->ifl_stdev = status.st_dev;
3266 3266 ifl->ifl_stino = status.st_ino;
3267 3267
3268 3268 /*
3269 3269 * If -zignore is in effect, mark this file as a potential
3270 3270 * candidate (the files use isn't actually determined until
3271 3271 * symbol resolution and relocation processing are completed).
3272 3272 */
3273 3273 if (ofl->ofl_flags1 & FLG_OF1_IGNORE)
3274 3274 ifl->ifl_flags |= FLG_IF_IGNORE;
3275 3275
3276 3276 switch (ehdr->e_type) {
3277 3277 case ET_REL:
3278 3278 (*ld_targ.t_mr.mr_mach_eflags)(ehdr, ofl);
3279 3279 error = process_elf(ifl, elf, ofl);
3280 3280 break;
3281 3281 case ET_DYN:
3282 3282 if ((ofl->ofl_flags & FLG_OF_STATIC) ||
3283 3283 !(ofl->ofl_flags & FLG_OF_DYNLIBS)) {
3284 3284 ld_eprintf(ofl, ERR_FATAL,
3285 3285 MSG_INTL(MSG_FIL_SOINSTAT), name);
3286 3286 return (0);
3287 3287 }
3288 3288
3289 3289 /*
3290 3290 * Record any additional shared object information.
3291 3291 * If no soname is specified (eg. this file was
3292 3292 * derived from a explicit filename declaration on the
3293 3293 * command line, ie. bar.so) use the pathname.
3294 3294 * This entry may be overridden if the files dynamic
3295 3295 * section specifies an DT_SONAME value.
3296 3296 */
3297 3297 if (soname == NULL)
3298 3298 ifl->ifl_soname = ifl->ifl_name;
3299 3299 else
3300 3300 ifl->ifl_soname = soname;
3301 3301
3302 3302 /*
3303 3303 * If direct bindings, lazy loading, group permissions,
3304 3304 * or deferred dependencies need to be established, mark
3305 3305 * this object.
3306 3306 */
3307 3307 if (ofl->ofl_flags1 & FLG_OF1_ZDIRECT)
3308 3308 ifl->ifl_flags |= FLG_IF_DIRECT;
3309 3309 if (ofl->ofl_flags1 & FLG_OF1_LAZYLD)
3310 3310 ifl->ifl_flags |= FLG_IF_LAZYLD;
3311 3311 if (ofl->ofl_flags1 & FLG_OF1_GRPPRM)
3312 3312 ifl->ifl_flags |= FLG_IF_GRPPRM;
3313 3313 if (ofl->ofl_flags1 & FLG_OF1_DEFERRED)
3314 3314 ifl->ifl_flags |=
3315 3315 (FLG_IF_LAZYLD | FLG_IF_DEFERRED);
3316 3316
3317 3317 error = process_elf(ifl, elf, ofl);
3318 3318
3319 3319 /*
3320 3320 * Determine whether this dependency requires a syminfo.
3321 3321 */
3322 3322 if (ifl->ifl_flags & MSK_IF_SYMINFO)
3323 3323 ofl->ofl_flags |= FLG_OF_SYMINFO;
3324 3324
3325 3325 /*
3326 3326 * Guidance: Use -z lazyload/nolazyload.
3327 3327 * libc is exempt from this advice, because it cannot
3328 3328 * be lazy loaded, and requests to do so are ignored.
3329 3329 */
3330 3330 if (OFL_GUIDANCE(ofl, FLG_OFG_NO_LAZY) &&
3331 3331 ((ifl->ifl_flags & FLG_IF_RTLDINF) == 0)) {
3332 3332 ld_eprintf(ofl, ERR_GUIDANCE,
3333 3333 MSG_INTL(MSG_GUIDE_LAZYLOAD));
3334 3334 ofl->ofl_guideflags |= FLG_OFG_NO_LAZY;
3335 3335 }
3336 3336
3337 3337 /*
3338 3338 * Guidance: Use -B direct/nodirect or
3339 3339 * -z direct/nodirect.
3340 3340 */
3341 3341 if (OFL_GUIDANCE(ofl, FLG_OFG_NO_DB)) {
3342 3342 ld_eprintf(ofl, ERR_GUIDANCE,
3343 3343 MSG_INTL(MSG_GUIDE_DIRECT));
3344 3344 ofl->ofl_guideflags |= FLG_OFG_NO_DB;
3345 3345 }
3346 3346
3347 3347 break;
3348 3348 default:
3349 3349 (void) elf_errno();
3350 3350 _rej.rej_type = SGS_REJ_UNKFILE;
3351 3351 _rej.rej_name = name;
3352 3352 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3353 3353 ld_targ.t_m.m_mach));
3354 3354 if (rej->rej_type == 0) {
3355 3355 *rej = _rej;
3356 3356 rej->rej_name = strdup(_rej.rej_name);
3357 3357 }
3358 3358 return (0);
3359 3359 }
3360 3360 break;
3361 3361 default:
3362 3362 (void) elf_errno();
3363 3363 _rej.rej_type = SGS_REJ_UNKFILE;
3364 3364 _rej.rej_name = name;
3365 3365 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3366 3366 ld_targ.t_m.m_mach));
3367 3367 if (rej->rej_type == 0) {
3368 3368 *rej = _rej;
3369 3369 rej->rej_name = strdup(_rej.rej_name);
3370 3370 }
3371 3371 return (0);
3372 3372 }
3373 3373 if ((error == 0) || (error == S_ERROR))
3374 3374 return (error);
3375 3375
3376 3376 if (ifl_ret)
3377 3377 *ifl_ret = ifl;
3378 3378 return (1);
3379 3379 }
3380 3380
3381 3381 /*
3382 3382 * Having successfully opened a file, set up the necessary elf structures to
3383 3383 * process it further. This small section of processing is slightly different
3384 3384 * from the elf initialization required to process a relocatable object from an
3385 3385 * archive (see libs.c: ld_process_archive()).
3386 3386 */
3387 3387 uintptr_t
3388 3388 ld_process_open(const char *opath, const char *ofile, int *fd, Ofl_desc *ofl,
3389 3389 Word flags, Rej_desc *rej, Ifl_desc **ifl_ret)
3390 3390 {
3391 3391 Elf *elf;
3392 3392 const char *npath = opath;
3393 3393 const char *nfile = ofile;
3394 3394
3395 3395 if ((elf = elf_begin(*fd, ELF_C_READ, NULL)) == NULL) {
3396 3396 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_BEGIN), npath);
3397 3397 return (0);
3398 3398 }
3399 3399
3400 3400 /*
3401 3401 * Determine whether the support library wishes to process this open.
3402 3402 * The support library may return:
3403 3403 * . a different ELF descriptor (in which case they should have
3404 3404 * closed the original)
3405 3405 * . a different file descriptor (in which case they should have
3406 3406 * closed the original)
3407 3407 * . a different path and file name (presumably associated with
3408 3408 * a different file descriptor)
3409 3409 *
3410 3410 * A file descriptor of -1, or and ELF descriptor of zero indicates
3411 3411 * the file should be ignored.
3412 3412 */
3413 3413 ld_sup_open(ofl, &npath, &nfile, fd, flags, &elf, NULL, 0,
3414 3414 elf_kind(elf));
3415 3415
3416 3416 if ((*fd == -1) || (elf == NULL))
3417 3417 return (0);
3418 3418
3419 3419 return (ld_process_ifl(npath, nfile, *fd, elf, flags, ofl, rej,
3420 3420 ifl_ret));
3421 3421 }
3422 3422
3423 3423 /*
3424 3424 * Having successfully mapped a file, set up the necessary elf structures to
3425 3425 * process it further. This routine is patterned after ld_process_open() and
3426 3426 * is only called by ld.so.1(1) to process a relocatable object.
3427 3427 */
3428 3428 Ifl_desc *
3429 3429 ld_process_mem(const char *path, const char *file, char *addr, size_t size,
3430 3430 Ofl_desc *ofl, Rej_desc *rej)
3431 3431 {
3432 3432 Elf *elf;
3433 3433 uintptr_t open_ret;
3434 3434 Ifl_desc *ifl;
3435 3435
3436 3436 if ((elf = elf_memory(addr, size)) == NULL) {
3437 3437 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_MEMORY), path);
3438 3438 return (0);
3439 3439 }
3440 3440
3441 3441 open_ret = ld_process_ifl(path, file, 0, elf, 0, ofl, rej, &ifl);
3442 3442 if (open_ret != 1)
3443 3443 return ((Ifl_desc *) open_ret);
3444 3444 return (ifl);
3445 3445 }
3446 3446
3447 3447 /*
3448 3448 * Process a required library (i.e. the dependency of a shared object).
3449 3449 * Combine the directory and filename, check the resultant path size, and try
3450 3450 * opening the pathname.
3451 3451 */
3452 3452 static Ifl_desc *
3453 3453 process_req_lib(Sdf_desc *sdf, const char *dir, const char *file,
3454 3454 Ofl_desc *ofl, Rej_desc *rej)
3455 3455 {
3456 3456 size_t dlen, plen;
3457 3457 int fd;
3458 3458 char path[PATH_MAX];
3459 3459 const char *_dir = dir;
3460 3460
3461 3461 /*
3462 3462 * Determine the sizes of the directory and filename to insure we don't
3463 3463 * exceed our buffer.
3464 3464 */
3465 3465 if ((dlen = strlen(dir)) == 0) {
3466 3466 _dir = MSG_ORIG(MSG_STR_DOT);
3467 3467 dlen = 1;
3468 3468 }
3469 3469 dlen++;
3470 3470 plen = dlen + strlen(file) + 1;
3471 3471 if (plen > PATH_MAX) {
3472 3472 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_PTHTOLONG),
3473 3473 _dir, file);
3474 3474 return (0);
3475 3475 }
3476 3476
3477 3477 /*
3478 3478 * Build the entire pathname and try and open the file.
3479 3479 */
3480 3480 (void) strcpy(path, _dir);
3481 3481 (void) strcat(path, MSG_ORIG(MSG_STR_SLASH));
3482 3482 (void) strcat(path, file);
3483 3483 DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name,
3484 3484 sdf->sdf_rfile, path));
3485 3485
3486 3486 if ((fd = open(path, O_RDONLY)) == -1)
3487 3487 return (0);
3488 3488 else {
3489 3489 uintptr_t open_ret;
3490 3490 Ifl_desc *ifl;
3491 3491 char *_path;
3492 3492
3493 3493 if ((_path = libld_malloc(strlen(path) + 1)) == NULL)
3494 3494 return ((Ifl_desc *)S_ERROR);
3495 3495 (void) strcpy(_path, path);
3496 3496 open_ret = ld_process_open(_path, &_path[dlen], &fd, ofl,
3497 3497 0, rej, &ifl);
3498 3498 if (fd != -1)
3499 3499 (void) close(fd);
3500 3500 if (open_ret != 1)
3501 3501 return ((Ifl_desc *)open_ret);
3502 3502 return (ifl);
3503 3503 }
3504 3504 }
3505 3505
3506 3506 /*
3507 3507 * Finish any library processing. Walk the list of so's that have been listed
3508 3508 * as "included" by shared objects we have previously processed. Examine them,
3509 3509 * without adding them as explicit dependents of this program, in order to
3510 3510 * complete our symbol definition process. The search path rules are:
3511 3511 *
3512 3512 * - use any user supplied paths, i.e. LD_LIBRARY_PATH and -L, then
3513 3513 *
3514 3514 * - use any RPATH defined within the parent shared object, then
3515 3515 *
3516 3516 * - use the default directories, i.e. LIBPATH or -YP.
3517 3517 */
3518 3518 uintptr_t
3519 3519 ld_finish_libs(Ofl_desc *ofl)
3520 3520 {
3521 3521 Aliste idx1;
3522 3522 Sdf_desc *sdf;
3523 3523 Rej_desc rej = { 0 };
3524 3524
3525 3525 /*
3526 3526 * Make sure we are back in dynamic mode.
3527 3527 */
3528 3528 ofl->ofl_flags |= FLG_OF_DYNLIBS;
3529 3529
3530 3530 for (APLIST_TRAVERSE(ofl->ofl_soneed, idx1, sdf)) {
3531 3531 Aliste idx2;
3532 3532 char *path, *slash = NULL;
3533 3533 int fd;
3534 3534 Ifl_desc *ifl;
3535 3535 char *file = (char *)sdf->sdf_name;
3536 3536
3537 3537 /*
3538 3538 * See if this file has already been processed. At the time
3539 3539 * this implicit dependency was determined there may still have
3540 3540 * been more explicit dependencies to process. Note, if we ever
3541 3541 * do parse the command line three times we would be able to
3542 3542 * do all this checking when processing the dynamic section.
3543 3543 */
3544 3544 if (sdf->sdf_file)
3545 3545 continue;
3546 3546
3547 3547 for (APLIST_TRAVERSE(ofl->ofl_sos, idx2, ifl)) {
3548 3548 if (!(ifl->ifl_flags & FLG_IF_NEEDSTR) &&
3549 3549 (strcmp(file, ifl->ifl_soname) == 0)) {
3550 3550 sdf->sdf_file = ifl;
3551 3551 break;
3552 3552 }
3553 3553 }
3554 3554 if (sdf->sdf_file)
3555 3555 continue;
3556 3556
3557 3557 /*
3558 3558 * If the current path name element embeds a "/", then it's to
3559 3559 * be taken "as is", with no searching involved. Process all
3560 3560 * "/" occurrences, so that we can deduce the base file name.
3561 3561 */
3562 3562 for (path = file; *path; path++) {
3563 3563 if (*path == '/')
3564 3564 slash = path;
3565 3565 }
3566 3566 if (slash) {
3567 3567 DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name,
3568 3568 sdf->sdf_rfile, file));
3569 3569 if ((fd = open(file, O_RDONLY)) == -1) {
3570 3570 ld_eprintf(ofl, ERR_WARNING,
3571 3571 MSG_INTL(MSG_FIL_NOTFOUND), file,
3572 3572 sdf->sdf_rfile);
3573 3573 } else {
3574 3574 uintptr_t open_ret;
3575 3575 Rej_desc _rej = { 0 };
3576 3576
3577 3577 open_ret = ld_process_open(file, ++slash,
3578 3578 &fd, ofl, 0, &_rej, &ifl);
3579 3579 if (fd != -1)
3580 3580 (void) close(fd);
3581 3581 if (open_ret == S_ERROR)
3582 3582 return (S_ERROR);
3583 3583
3584 3584 if (_rej.rej_type) {
3585 3585 Conv_reject_desc_buf_t rej_buf;
3586 3586
3587 3587 ld_eprintf(ofl, ERR_WARNING,
3588 3588 MSG_INTL(reject[_rej.rej_type]),
3589 3589 _rej.rej_name ? rej.rej_name :
3590 3590 MSG_INTL(MSG_STR_UNKNOWN),
3591 3591 conv_reject_desc(&_rej, &rej_buf,
3592 3592 ld_targ.t_m.m_mach));
3593 3593 } else
3594 3594 sdf->sdf_file = ifl;
3595 3595 }
3596 3596 continue;
3597 3597 }
3598 3598
3599 3599 /*
3600 3600 * Now search for this file in any user defined directories.
3601 3601 */
3602 3602 for (APLIST_TRAVERSE(ofl->ofl_ulibdirs, idx2, path)) {
3603 3603 Rej_desc _rej = { 0 };
3604 3604
3605 3605 ifl = process_req_lib(sdf, path, file, ofl, &_rej);
3606 3606 if (ifl == (Ifl_desc *)S_ERROR) {
3607 3607 return (S_ERROR);
3608 3608 }
3609 3609 if (_rej.rej_type) {
3610 3610 if (rej.rej_type == 0) {
3611 3611 rej = _rej;
3612 3612 rej.rej_name = strdup(_rej.rej_name);
3613 3613 }
3614 3614 }
3615 3615 if (ifl) {
3616 3616 sdf->sdf_file = ifl;
3617 3617 break;
3618 3618 }
3619 3619 }
3620 3620 if (sdf->sdf_file)
3621 3621 continue;
3622 3622
3623 3623 /*
3624 3624 * Next use the local rules defined within the parent shared
3625 3625 * object.
3626 3626 */
3627 3627 if (sdf->sdf_rpath != NULL) {
3628 3628 char *rpath, *next;
3629 3629
3630 3630 rpath = libld_malloc(strlen(sdf->sdf_rpath) + 1);
3631 3631 if (rpath == NULL)
3632 3632 return (S_ERROR);
3633 3633 (void) strcpy(rpath, sdf->sdf_rpath);
3634 3634 DBG_CALL(Dbg_libs_path(ofl->ofl_lml, rpath,
3635 3635 LA_SER_RUNPATH, sdf->sdf_rfile));
3636 3636 if ((path = strtok_r(rpath,
3637 3637 MSG_ORIG(MSG_STR_COLON), &next)) != NULL) {
3638 3638 do {
3639 3639 Rej_desc _rej = { 0 };
3640 3640
3641 3641 path = expand(sdf->sdf_rfile, path,
3642 3642 &next);
3643 3643
3644 3644 ifl = process_req_lib(sdf, path,
3645 3645 file, ofl, &_rej);
3646 3646 if (ifl == (Ifl_desc *)S_ERROR) {
3647 3647 return (S_ERROR);
3648 3648 }
3649 3649 if ((_rej.rej_type) &&
3650 3650 (rej.rej_type == 0)) {
3651 3651 rej = _rej;
3652 3652 rej.rej_name =
3653 3653 strdup(_rej.rej_name);
3654 3654 }
3655 3655 if (ifl) {
3656 3656 sdf->sdf_file = ifl;
3657 3657 break;
3658 3658 }
3659 3659 } while ((path = strtok_r(NULL,
3660 3660 MSG_ORIG(MSG_STR_COLON), &next)) != NULL);
3661 3661 }
3662 3662 }
3663 3663 if (sdf->sdf_file)
3664 3664 continue;
3665 3665
3666 3666 /*
3667 3667 * Finally try the default library search directories.
3668 3668 */
3669 3669 for (APLIST_TRAVERSE(ofl->ofl_dlibdirs, idx2, path)) {
3670 3670 Rej_desc _rej = { 0 };
3671 3671
3672 3672 ifl = process_req_lib(sdf, path, file, ofl, &rej);
3673 3673 if (ifl == (Ifl_desc *)S_ERROR) {
3674 3674 return (S_ERROR);
3675 3675 }
3676 3676 if (_rej.rej_type) {
3677 3677 if (rej.rej_type == 0) {
3678 3678 rej = _rej;
3679 3679 rej.rej_name = strdup(_rej.rej_name);
3680 3680 }
3681 3681 }
3682 3682 if (ifl) {
3683 3683 sdf->sdf_file = ifl;
3684 3684 break;
3685 3685 }
3686 3686 }
3687 3687 if (sdf->sdf_file)
3688 3688 continue;
3689 3689
3690 3690 /*
3691 3691 * If we've got this far we haven't found the shared object.
3692 3692 * If an object was found, but was rejected for some reason,
3693 3693 * print a diagnostic to that effect, otherwise generate a
3694 3694 * generic "not found" diagnostic.
3695 3695 */
3696 3696 if (rej.rej_type) {
3697 3697 Conv_reject_desc_buf_t rej_buf;
3698 3698
3699 3699 ld_eprintf(ofl, ERR_WARNING,
3700 3700 MSG_INTL(reject[rej.rej_type]),
3701 3701 rej.rej_name ? rej.rej_name :
3702 3702 MSG_INTL(MSG_STR_UNKNOWN),
3703 3703 conv_reject_desc(&rej, &rej_buf,
3704 3704 ld_targ.t_m.m_mach));
3705 3705 } else {
3706 3706 ld_eprintf(ofl, ERR_WARNING,
3707 3707 MSG_INTL(MSG_FIL_NOTFOUND), file, sdf->sdf_rfile);
3708 3708 }
3709 3709 }
3710 3710
3711 3711 /*
3712 3712 * Finally, now that all objects have been input, make sure any version
3713 3713 * requirements have been met.
3714 3714 */
3715 3715 return (ld_vers_verify(ofl));
3716 3716 }
↓ open down ↓ |
896 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX