Print this page
ld should reject kernel modules as input
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 {
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 2346 ifl->ifl_flags |= FLG_IF_GROUPS;
2347 2347
2348 2348 return (1);
↓ open down ↓ |
2348 lines elided |
↑ open up ↑ |
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 - Word rndx;
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 }
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 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 group information has been processed, we can safely validate
2825 2825 * that nothing is fishy about the section COMDAT description. We
2826 2826 * need to do this prior to placing the section (where any
2827 2827 * SHT_SUNW_COMDAT sections will be restored to being PROGBITS)
2828 2828 */
2829 2829 ld_comdat_validate(ofl, ifl);
2830 2830
2831 2831 /*
2832 2832 * Now that all of the input sections have been processed, place
2833 2833 * them in the appropriate output sections.
2834 2834 */
2835 2835 for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) {
2836 2836 Is_desc *isp;
2837 2837
2838 2838 if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
2839 2839 ((isp->is_flags & FLG_IS_PLACE) == 0))
2840 2840 continue;
2841 2841
2842 2842 /*
2843 2843 * Place all non-ordered sections within their appropriate
2844 2844 * output section.
2845 2845 */
2846 2846 if ((isp->is_flags & FLG_IS_ORDERED) == 0) {
2847 2847 if (ld_place_section(ofl, isp, path_info,
2848 2848 isp->is_keyident, NULL) == (Os_desc *)S_ERROR)
2849 2849 return (S_ERROR);
2850 2850 continue;
2851 2851 }
2852 2852
2853 2853 /*
2854 2854 * Count the number of ordered sections and retain the first
2855 2855 * ordered section index. This will be used to optimize the
2856 2856 * ordered section loop that immediately follows this one.
2857 2857 */
2858 2858 ordcnt++;
2859 2859 if (ordndx == 0)
2860 2860 ordndx = ndx;
2861 2861 }
2862 2862
2863 2863 /*
2864 2864 * Having placed all the non-ordered sections, it is now
2865 2865 * safe to place SHF_ORDERED/SHF_LINK_ORDER sections.
2866 2866 */
2867 2867 if (ifl->ifl_flags & FLG_IF_ORDERED) {
2868 2868 for (ndx = ordndx; ndx < ifl->ifl_shnum; ndx++) {
2869 2869 Is_desc *isp;
2870 2870
2871 2871 if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
2872 2872 ((isp->is_flags &
2873 2873 (FLG_IS_PLACE | FLG_IS_ORDERED)) !=
2874 2874 (FLG_IS_PLACE | FLG_IS_ORDERED)))
2875 2875 continue;
2876 2876
2877 2877 /* ld_process_ordered() calls ld_place_section() */
2878 2878 if (ld_process_ordered(ofl, ifl, path_info, ndx) ==
2879 2879 S_ERROR)
2880 2880 return (S_ERROR);
2881 2881
2882 2882 /* If we've done them all, stop searching */
2883 2883 if (--ordcnt == 0)
2884 2884 break;
2885 2885 }
2886 2886 }
2887 2887
2888 2888 /*
2889 2889 * If this is a shared object explicitly specified on the command
2890 2890 * line (as opposed to being a dependency of such an object),
2891 2891 * determine if the user has specified a control definition. This
2892 2892 * descriptor may specify which version definitions can be used
2893 2893 * from this object. It may also update the dependency to USED and
2894 2894 * supply an alternative SONAME.
2895 2895 */
2896 2896 sdf = NULL;
2897 2897 if (column && (ifl->ifl_flags & FLG_IF_NEEDED)) {
2898 2898 const char *base;
2899 2899
2900 2900 /*
2901 2901 * Use the basename of the input file (typically this is the
2902 2902 * compilation environment name, ie. libfoo.so).
2903 2903 */
2904 2904 if ((base = strrchr(ifl->ifl_name, '/')) == NULL)
2905 2905 base = ifl->ifl_name;
2906 2906 else
2907 2907 base++;
2908 2908
2909 2909 if ((sdf = sdf_find(base, ofl->ofl_socntl)) != NULL) {
2910 2910 sdf->sdf_file = ifl;
2911 2911 ifl->ifl_sdfdesc = sdf;
2912 2912 }
2913 2913 }
2914 2914
2915 2915 /*
2916 2916 * Before symbol processing, process any capabilities. Capabilities
2917 2917 * can reference a string table, which is why this processing is
2918 2918 * carried out after the initial section processing. Capabilities,
2919 2919 * together with -z symbolcap, can require the conversion of global
2920 2920 * symbols to local symbols.
2921 2921 */
2922 2922 if (capisp && (process_cap(ofl, ifl, capisp) == S_ERROR))
2923 2923 return (S_ERROR);
2924 2924
2925 2925 /*
2926 2926 * Process any version dependencies. These will establish shared object
2927 2927 * `needed' entries in the same manner as will be generated from the
2928 2928 * .dynamic's NEEDED entries.
2929 2929 */
2930 2930 if (vndisp && ((ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)) ||
2931 2931 OFL_GUIDANCE(ofl, FLG_OFG_NO_DEFS)))
2932 2932 if (ld_vers_need_process(vndisp, ifl, ofl) == S_ERROR)
2933 2933 return (S_ERROR);
2934 2934
2935 2935 /*
2936 2936 * Before processing any symbol resolution or relocations process any
2937 2937 * version sections.
2938 2938 */
2939 2939 if (vsyisp)
2940 2940 (void) ld_vers_sym_process(ofl, vsyisp, ifl);
2941 2941
2942 2942 if (ifl->ifl_versym &&
2943 2943 (vdfisp || (sdf && (sdf->sdf_flags & FLG_SDF_SELECT))))
2944 2944 if (ld_vers_def_process(vdfisp, ifl, ofl) == S_ERROR)
2945 2945 return (S_ERROR);
2946 2946
2947 2947 /*
2948 2948 * Having collected the appropriate sections carry out any additional
2949 2949 * processing if necessary.
2950 2950 */
2951 2951 for (ndx = 0; ndx < ifl->ifl_shnum; ndx++) {
2952 2952 Is_desc *isp;
2953 2953
2954 2954 if ((isp = ifl->ifl_isdesc[ndx]) == NULL)
2955 2955 continue;
2956 2956 row = isp->is_shdr->sh_type;
2957 2957
2958 2958 if ((isp->is_flags & FLG_IS_DISCARD) == 0)
2959 2959 ld_sup_section(ofl, isp->is_name, isp->is_shdr, ndx,
2960 2960 isp->is_indata, elf);
2961 2961
2962 2962 /*
2963 2963 * If this is a SHT_SUNW_move section from a relocatable file,
2964 2964 * keep track of the section for later processing.
2965 2965 */
2966 2966 if ((row == SHT_SUNW_move) && (column == 0)) {
2967 2967 if (aplist_append(&(ofl->ofl_ismove), isp,
2968 2968 AL_CNT_OFL_MOVE) == NULL)
2969 2969 return (S_ERROR);
2970 2970 }
2971 2971
2972 2972 /*
2973 2973 * If this is a standard section type process it via the
2974 2974 * appropriate action routine.
2975 2975 */
2976 2976 if (row < SHT_NUM) {
2977 2977 if (Final[row][column] != NULL) {
2978 2978 if (Final[row][column](isp, ifl,
2979 2979 ofl) == S_ERROR)
2980 2980 return (S_ERROR);
2981 2981 }
2982 2982 #if defined(_ELF64)
2983 2983 } else if ((row == SHT_AMD64_UNWIND) && (column == 0)) {
2984 2984 Os_desc *osp = isp->is_osdesc;
2985 2985
2986 2986 /*
2987 2987 * SHT_AMD64_UNWIND (0x70000001) is in the SHT_LOPROC -
2988 2988 * SHT_HIPROC range reserved for processor-specific
2989 2989 * semantics, and is only meaningful for amd64 targets.
2990 2990 *
2991 2991 * Only process unwind contents from relocatable
2992 2992 * objects.
2993 2993 */
2994 2994 if (osp && (ld_targ.t_m.m_mach == EM_AMD64) &&
2995 2995 (ld_unwind_register(osp, ofl) == S_ERROR))
2996 2996 return (S_ERROR);
2997 2997 #endif
2998 2998 }
2999 2999 }
3000 3000
3001 3001 /*
3002 3002 * Following symbol processing, if this relocatable object input file
3003 3003 * provides symbol capabilities, tag the associated symbols so that
3004 3004 * the symbols can be re-assigned to the new capabilities symbol
3005 3005 * section that will be created for the output file.
3006 3006 */
3007 3007 if (capinfoisp && (ifl->ifl_ehdr->e_type == ET_REL) &&
3008 3008 (process_capinfo(ofl, ifl, capinfoisp) == S_ERROR))
3009 3009 return (S_ERROR);
3010 3010
3011 3011 /*
3012 3012 * After processing any symbol resolution, and if this dependency
3013 3013 * indicates it contains symbols that can't be directly bound to,
3014 3014 * set the symbols appropriately.
3015 3015 */
3016 3016 if (sifisp && ((ifl->ifl_flags & (FLG_IF_NEEDED | FLG_IF_NODIRECT)) ==
3017 3017 (FLG_IF_NEEDED | FLG_IF_NODIRECT)))
3018 3018 (void) ld_sym_nodirect(sifisp, ifl, ofl);
3019 3019
3020 3020 return (1);
3021 3021 }
3022 3022
3023 3023 /*
3024 3024 * Process the current input file. There are basically three types of files
3025 3025 * that come through here:
3026 3026 *
3027 3027 * - files explicitly defined on the command line (ie. foo.o or bar.so),
3028 3028 * in this case only the `name' field is valid.
3029 3029 *
3030 3030 * - libraries determined from the -l command line option (ie. -lbar),
3031 3031 * in this case the `soname' field contains the basename of the located
3032 3032 * file.
3033 3033 *
3034 3034 * Any shared object specified via the above two conventions must be recorded
3035 3035 * as a needed dependency.
3036 3036 *
3037 3037 * - libraries specified as dependencies of those libraries already obtained
3038 3038 * via the command line (ie. bar.so has a DT_NEEDED entry of fred.so.1),
3039 3039 * in this case the `soname' field contains either a full pathname (if the
3040 3040 * needed entry contained a `/'), or the basename of the located file.
3041 3041 * These libraries are processed to verify symbol binding but are not
3042 3042 * recorded as dependencies of the output file being generated.
3043 3043 *
3044 3044 * entry:
3045 3045 * name - File name
3046 3046 * soname - SONAME for needed sharable library, as described above
3047 3047 * fd - Open file descriptor
3048 3048 * elf - Open ELF handle
3049 3049 * flags - FLG_IF_ flags applicable to file
3050 3050 * ofl - Output file descriptor
3051 3051 * rej - Rejection descriptor used to record rejection reason
3052 3052 * ifl_ret - NULL, or address of pointer to receive reference to
3053 3053 * resulting input descriptor for file. If ifl_ret is non-NULL,
3054 3054 * the file cannot be an archive or it will be rejected.
3055 3055 *
3056 3056 * exit:
3057 3057 * If a error occurs in examining the file, S_ERROR is returned.
3058 3058 * If the file can be examined, but is not suitable, *rej is updated,
3059 3059 * and 0 is returned. If the file is acceptable, 1 is returned, and if
3060 3060 * ifl_ret is non-NULL, *ifl_ret is set to contain the pointer to the
3061 3061 * resulting input descriptor.
3062 3062 */
3063 3063 uintptr_t
3064 3064 ld_process_ifl(const char *name, const char *soname, int fd, Elf *elf,
3065 3065 Word flags, Ofl_desc *ofl, Rej_desc *rej, Ifl_desc **ifl_ret)
3066 3066 {
3067 3067 Ifl_desc *ifl;
3068 3068 Ehdr *ehdr;
3069 3069 uintptr_t error = 0;
3070 3070 struct stat status;
3071 3071 Ar_desc *adp;
3072 3072 Rej_desc _rej;
3073 3073
3074 3074 /*
3075 3075 * If this file was not extracted from an archive obtain its device
3076 3076 * information. This will be used to determine if the file has already
3077 3077 * been processed (rather than simply comparing filenames, the device
3078 3078 * information provides a quicker comparison and detects linked files).
3079 3079 */
3080 3080 if (fd && ((flags & FLG_IF_EXTRACT) == 0))
3081 3081 (void) fstat(fd, &status);
3082 3082 else {
3083 3083 status.st_dev = 0;
3084 3084 status.st_ino = 0;
3085 3085 }
3086 3086
3087 3087 switch (elf_kind(elf)) {
3088 3088 case ELF_K_AR:
3089 3089 /*
3090 3090 * If the caller has supplied a non-NULL ifl_ret, then
3091 3091 * we cannot process archives, for there will be no
3092 3092 * input file descriptor for us to return. In this case,
3093 3093 * reject the attempt.
3094 3094 */
3095 3095 if (ifl_ret != NULL) {
3096 3096 _rej.rej_type = SGS_REJ_ARCHIVE;
3097 3097 _rej.rej_name = name;
3098 3098 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3099 3099 ld_targ.t_m.m_mach));
3100 3100 if (rej->rej_type == 0) {
3101 3101 *rej = _rej;
3102 3102 rej->rej_name = strdup(_rej.rej_name);
3103 3103 }
3104 3104 return (0);
3105 3105 }
3106 3106
3107 3107 /*
3108 3108 * Determine if we've already come across this archive file.
3109 3109 */
3110 3110 if (!(flags & FLG_IF_EXTRACT)) {
3111 3111 Aliste idx;
3112 3112
3113 3113 for (APLIST_TRAVERSE(ofl->ofl_ars, idx, adp)) {
3114 3114 if ((adp->ad_stdev != status.st_dev) ||
3115 3115 (adp->ad_stino != status.st_ino))
3116 3116 continue;
3117 3117
3118 3118 /*
3119 3119 * We've seen this file before so reuse the
3120 3120 * original archive descriptor and discard the
3121 3121 * new elf descriptor. Note that a file
3122 3122 * descriptor is unnecessary, as the file is
3123 3123 * already available in memory.
3124 3124 */
3125 3125 DBG_CALL(Dbg_file_reuse(ofl->ofl_lml, name,
3126 3126 adp->ad_name));
3127 3127 (void) elf_end(elf);
3128 3128 if (!ld_process_archive(name, -1, adp, ofl))
3129 3129 return (S_ERROR);
3130 3130 return (1);
3131 3131 }
3132 3132 }
3133 3133
3134 3134 /*
3135 3135 * As we haven't processed this file before establish a new
3136 3136 * archive descriptor.
3137 3137 */
3138 3138 adp = ld_ar_setup(name, elf, ofl);
3139 3139 if ((adp == NULL) || (adp == (Ar_desc *)S_ERROR))
3140 3140 return ((uintptr_t)adp);
3141 3141 adp->ad_stdev = status.st_dev;
3142 3142 adp->ad_stino = status.st_ino;
3143 3143
3144 3144 ld_sup_file(ofl, name, ELF_K_AR, flags, elf);
3145 3145
3146 3146 /*
3147 3147 * Indicate that the ELF descriptor no longer requires a file
3148 3148 * descriptor by reading the entire file. The file is already
3149 3149 * read via the initial mmap(2) behind elf_begin(3elf), thus
3150 3150 * this operation is effectively a no-op. However, a side-
3151 3151 * effect is that the internal file descriptor, maintained in
3152 3152 * the ELF descriptor, is set to -1. This setting will not
3153 3153 * be compared with any file descriptor that is passed to
3154 3154 * elf_begin(), should this archive, or one of the archive
3155 3155 * members, be processed again from the command line or
3156 3156 * because of a -z rescan.
3157 3157 */
3158 3158 if (elf_cntl(elf, ELF_C_FDREAD) == -1) {
3159 3159 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_CNTL),
3160 3160 name);
3161 3161 return (0);
3162 3162 }
3163 3163
3164 3164 if (!ld_process_archive(name, -1, adp, ofl))
3165 3165 return (S_ERROR);
3166 3166 return (1);
3167 3167
3168 3168 case ELF_K_ELF:
3169 3169 /*
3170 3170 * Obtain the elf header so that we can determine what type of
3171 3171 * elf ELF_K_ELF file this is.
3172 3172 */
3173 3173 if ((ehdr = elf_getehdr(elf)) == NULL) {
3174 3174 int _class = gelf_getclass(elf);
3175 3175
3176 3176 /*
3177 3177 * This can fail for a number of reasons. Typically
3178 3178 * the object class is incorrect (ie. user is building
3179 3179 * 64-bit but managed to point at 32-bit libraries).
3180 3180 * Other ELF errors can include a truncated or corrupt
3181 3181 * file. Try to get the best error message possible.
3182 3182 */
↓ open down ↓ |
813 lines elided |
↑ open up ↑ |
3183 3183 if (ld_targ.t_m.m_class != _class) {
3184 3184 _rej.rej_type = SGS_REJ_CLASS;
3185 3185 _rej.rej_info = (uint_t)_class;
3186 3186 } else {
3187 3187 _rej.rej_type = SGS_REJ_STR;
3188 3188 _rej.rej_str = elf_errmsg(-1);
3189 3189 }
3190 3190 _rej.rej_name = name;
3191 3191 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3192 3192 ld_targ.t_m.m_mach));
3193 + if (rej->rej_type == 0) {
3194 + *rej = _rej;
3195 + rej->rej_name = strdup(_rej.rej_name);
3196 + }
3197 + return (0);
3198 + }
3199 +
3200 + if (_gelf_getdynval(elf, DT_SUNW_KMOD) == 1) {
3201 + _rej.rej_name = name;
3202 + DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3203 + ld_targ.t_m.m_mach));
3204 + _rej.rej_type = SGS_REJ_KMOD;
3205 + _rej.rej_str = elf_errmsg(-1);
3206 +
3193 3207 if (rej->rej_type == 0) {
3194 3208 *rej = _rej;
3195 3209 rej->rej_name = strdup(_rej.rej_name);
3196 3210 }
3197 3211 return (0);
3198 3212 }
3199 3213
3200 3214 /*
3201 3215 * Determine if we've already come across this file.
3202 3216 */
3203 3217 if (!(flags & FLG_IF_EXTRACT)) {
3204 3218 APlist *apl;
3205 3219 Aliste idx;
3206 3220
3207 3221 if (ehdr->e_type == ET_REL)
3208 3222 apl = ofl->ofl_objs;
3209 3223 else
3210 3224 apl = ofl->ofl_sos;
3211 3225
3212 3226 /*
3213 3227 * Traverse the appropriate file list and determine if
3214 3228 * a dev/inode match is found.
3215 3229 */
3216 3230 for (APLIST_TRAVERSE(apl, idx, ifl)) {
3217 3231 /*
3218 3232 * Ifl_desc generated via -Nneed, therefore no
3219 3233 * actual file behind it.
3220 3234 */
3221 3235 if (ifl->ifl_flags & FLG_IF_NEEDSTR)
3222 3236 continue;
3223 3237
3224 3238 if ((ifl->ifl_stino != status.st_ino) ||
3225 3239 (ifl->ifl_stdev != status.st_dev))
3226 3240 continue;
3227 3241
3228 3242 /*
3229 3243 * Disregard (skip) this image.
3230 3244 */
3231 3245 DBG_CALL(Dbg_file_skip(ofl->ofl_lml,
3232 3246 ifl->ifl_name, name));
3233 3247 (void) elf_end(elf);
3234 3248
3235 3249 /*
3236 3250 * If the file was explicitly defined on the
3237 3251 * command line (this is always the case for
3238 3252 * relocatable objects, and is true for shared
3239 3253 * objects when they weren't specified via -l or
3240 3254 * were dragged in as an implicit dependency),
3241 3255 * then warn the user.
3242 3256 */
3243 3257 if ((flags & FLG_IF_CMDLINE) ||
3244 3258 (ifl->ifl_flags & FLG_IF_CMDLINE)) {
3245 3259 const char *errmsg;
3246 3260
3247 3261 /*
3248 3262 * Determine whether this is the same
3249 3263 * file name as originally encountered
3250 3264 * so as to provide the most
3251 3265 * descriptive diagnostic.
3252 3266 */
3253 3267 errmsg =
3254 3268 (strcmp(name, ifl->ifl_name) == 0) ?
3255 3269 MSG_INTL(MSG_FIL_MULINC_1) :
3256 3270 MSG_INTL(MSG_FIL_MULINC_2);
3257 3271 ld_eprintf(ofl, ERR_WARNING,
3258 3272 errmsg, name, ifl->ifl_name);
3259 3273 }
3260 3274 if (ifl_ret)
3261 3275 *ifl_ret = ifl;
3262 3276 return (1);
3263 3277 }
3264 3278 }
3265 3279
3266 3280 /*
3267 3281 * At this point, we know we need the file. Establish an input
3268 3282 * file descriptor and continue processing.
3269 3283 */
3270 3284 ifl = ifl_setup(name, ehdr, elf, flags, ofl, rej);
3271 3285 if ((ifl == NULL) || (ifl == (Ifl_desc *)S_ERROR))
3272 3286 return ((uintptr_t)ifl);
3273 3287 ifl->ifl_stdev = status.st_dev;
3274 3288 ifl->ifl_stino = status.st_ino;
3275 3289
3276 3290 /*
3277 3291 * If -zignore is in effect, mark this file as a potential
3278 3292 * candidate (the files use isn't actually determined until
3279 3293 * symbol resolution and relocation processing are completed).
3280 3294 */
3281 3295 if (ofl->ofl_flags1 & FLG_OF1_IGNORE)
3282 3296 ifl->ifl_flags |= FLG_IF_IGNORE;
3283 3297
3284 3298 switch (ehdr->e_type) {
3285 3299 case ET_REL:
3286 3300 (*ld_targ.t_mr.mr_mach_eflags)(ehdr, ofl);
3287 3301 error = process_elf(ifl, elf, ofl);
3288 3302 break;
3289 3303 case ET_DYN:
3290 3304 if ((ofl->ofl_flags & FLG_OF_STATIC) ||
3291 3305 !(ofl->ofl_flags & FLG_OF_DYNLIBS)) {
3292 3306 ld_eprintf(ofl, ERR_FATAL,
3293 3307 MSG_INTL(MSG_FIL_SOINSTAT), name);
3294 3308 return (0);
3295 3309 }
3296 3310
3297 3311 /*
3298 3312 * Record any additional shared object information.
3299 3313 * If no soname is specified (eg. this file was
3300 3314 * derived from a explicit filename declaration on the
3301 3315 * command line, ie. bar.so) use the pathname.
3302 3316 * This entry may be overridden if the files dynamic
3303 3317 * section specifies an DT_SONAME value.
3304 3318 */
3305 3319 if (soname == NULL)
3306 3320 ifl->ifl_soname = ifl->ifl_name;
3307 3321 else
3308 3322 ifl->ifl_soname = soname;
3309 3323
3310 3324 /*
3311 3325 * If direct bindings, lazy loading, group permissions,
3312 3326 * or deferred dependencies need to be established, mark
3313 3327 * this object.
3314 3328 */
3315 3329 if (ofl->ofl_flags1 & FLG_OF1_ZDIRECT)
3316 3330 ifl->ifl_flags |= FLG_IF_DIRECT;
3317 3331 if (ofl->ofl_flags1 & FLG_OF1_LAZYLD)
3318 3332 ifl->ifl_flags |= FLG_IF_LAZYLD;
3319 3333 if (ofl->ofl_flags1 & FLG_OF1_GRPPRM)
3320 3334 ifl->ifl_flags |= FLG_IF_GRPPRM;
3321 3335 if (ofl->ofl_flags1 & FLG_OF1_DEFERRED)
3322 3336 ifl->ifl_flags |=
3323 3337 (FLG_IF_LAZYLD | FLG_IF_DEFERRED);
3324 3338
3325 3339 error = process_elf(ifl, elf, ofl);
3326 3340
3327 3341 /*
3328 3342 * Determine whether this dependency requires a syminfo.
3329 3343 */
3330 3344 if (ifl->ifl_flags & MSK_IF_SYMINFO)
3331 3345 ofl->ofl_flags |= FLG_OF_SYMINFO;
3332 3346
3333 3347 /*
3334 3348 * Guidance: Use -z lazyload/nolazyload.
3335 3349 * libc is exempt from this advice, because it cannot
3336 3350 * be lazy loaded, and requests to do so are ignored.
3337 3351 */
3338 3352 if (OFL_GUIDANCE(ofl, FLG_OFG_NO_LAZY) &&
3339 3353 ((ifl->ifl_flags & FLG_IF_RTLDINF) == 0)) {
3340 3354 ld_eprintf(ofl, ERR_GUIDANCE,
3341 3355 MSG_INTL(MSG_GUIDE_LAZYLOAD));
3342 3356 ofl->ofl_guideflags |= FLG_OFG_NO_LAZY;
3343 3357 }
3344 3358
3345 3359 /*
3346 3360 * Guidance: Use -B direct/nodirect or
3347 3361 * -z direct/nodirect.
3348 3362 */
3349 3363 if (OFL_GUIDANCE(ofl, FLG_OFG_NO_DB)) {
3350 3364 ld_eprintf(ofl, ERR_GUIDANCE,
3351 3365 MSG_INTL(MSG_GUIDE_DIRECT));
3352 3366 ofl->ofl_guideflags |= FLG_OFG_NO_DB;
3353 3367 }
3354 3368
3355 3369 break;
3356 3370 default:
3357 3371 (void) elf_errno();
3358 3372 _rej.rej_type = SGS_REJ_UNKFILE;
3359 3373 _rej.rej_name = name;
3360 3374 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3361 3375 ld_targ.t_m.m_mach));
3362 3376 if (rej->rej_type == 0) {
3363 3377 *rej = _rej;
3364 3378 rej->rej_name = strdup(_rej.rej_name);
3365 3379 }
3366 3380 return (0);
3367 3381 }
3368 3382 break;
3369 3383 default:
3370 3384 (void) elf_errno();
3371 3385 _rej.rej_type = SGS_REJ_UNKFILE;
3372 3386 _rej.rej_name = name;
3373 3387 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3374 3388 ld_targ.t_m.m_mach));
3375 3389 if (rej->rej_type == 0) {
3376 3390 *rej = _rej;
3377 3391 rej->rej_name = strdup(_rej.rej_name);
3378 3392 }
3379 3393 return (0);
3380 3394 }
3381 3395 if ((error == 0) || (error == S_ERROR))
3382 3396 return (error);
3383 3397
3384 3398 if (ifl_ret)
3385 3399 *ifl_ret = ifl;
3386 3400 return (1);
3387 3401 }
3388 3402
3389 3403 /*
3390 3404 * Having successfully opened a file, set up the necessary elf structures to
3391 3405 * process it further. This small section of processing is slightly different
3392 3406 * from the elf initialization required to process a relocatable object from an
3393 3407 * archive (see libs.c: ld_process_archive()).
3394 3408 */
3395 3409 uintptr_t
3396 3410 ld_process_open(const char *opath, const char *ofile, int *fd, Ofl_desc *ofl,
3397 3411 Word flags, Rej_desc *rej, Ifl_desc **ifl_ret)
3398 3412 {
3399 3413 Elf *elf;
3400 3414 const char *npath = opath;
3401 3415 const char *nfile = ofile;
3402 3416
3403 3417 if ((elf = elf_begin(*fd, ELF_C_READ, NULL)) == NULL) {
3404 3418 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_BEGIN), npath);
3405 3419 return (0);
3406 3420 }
3407 3421
3408 3422 /*
3409 3423 * Determine whether the support library wishes to process this open.
3410 3424 * The support library may return:
3411 3425 * . a different ELF descriptor (in which case they should have
3412 3426 * closed the original)
3413 3427 * . a different file descriptor (in which case they should have
3414 3428 * closed the original)
3415 3429 * . a different path and file name (presumably associated with
3416 3430 * a different file descriptor)
3417 3431 *
3418 3432 * A file descriptor of -1, or and ELF descriptor of zero indicates
3419 3433 * the file should be ignored.
3420 3434 */
3421 3435 ld_sup_open(ofl, &npath, &nfile, fd, flags, &elf, NULL, 0,
3422 3436 elf_kind(elf));
3423 3437
3424 3438 if ((*fd == -1) || (elf == NULL))
3425 3439 return (0);
3426 3440
3427 3441 return (ld_process_ifl(npath, nfile, *fd, elf, flags, ofl, rej,
3428 3442 ifl_ret));
3429 3443 }
3430 3444
3431 3445 /*
3432 3446 * Having successfully mapped a file, set up the necessary elf structures to
3433 3447 * process it further. This routine is patterned after ld_process_open() and
3434 3448 * is only called by ld.so.1(1) to process a relocatable object.
3435 3449 */
3436 3450 Ifl_desc *
3437 3451 ld_process_mem(const char *path, const char *file, char *addr, size_t size,
3438 3452 Ofl_desc *ofl, Rej_desc *rej)
3439 3453 {
3440 3454 Elf *elf;
3441 3455 uintptr_t open_ret;
3442 3456 Ifl_desc *ifl;
3443 3457
3444 3458 if ((elf = elf_memory(addr, size)) == NULL) {
3445 3459 ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_MEMORY), path);
3446 3460 return (0);
3447 3461 }
3448 3462
3449 3463 open_ret = ld_process_ifl(path, file, 0, elf, 0, ofl, rej, &ifl);
3450 3464 if (open_ret != 1)
3451 3465 return ((Ifl_desc *) open_ret);
3452 3466 return (ifl);
3453 3467 }
3454 3468
3455 3469 /*
3456 3470 * Process a required library (i.e. the dependency of a shared object).
3457 3471 * Combine the directory and filename, check the resultant path size, and try
3458 3472 * opening the pathname.
3459 3473 */
3460 3474 static Ifl_desc *
3461 3475 process_req_lib(Sdf_desc *sdf, const char *dir, const char *file,
3462 3476 Ofl_desc *ofl, Rej_desc *rej)
3463 3477 {
3464 3478 size_t dlen, plen;
3465 3479 int fd;
3466 3480 char path[PATH_MAX];
3467 3481 const char *_dir = dir;
3468 3482
3469 3483 /*
3470 3484 * Determine the sizes of the directory and filename to insure we don't
3471 3485 * exceed our buffer.
3472 3486 */
3473 3487 if ((dlen = strlen(dir)) == 0) {
3474 3488 _dir = MSG_ORIG(MSG_STR_DOT);
3475 3489 dlen = 1;
3476 3490 }
3477 3491 dlen++;
3478 3492 plen = dlen + strlen(file) + 1;
3479 3493 if (plen > PATH_MAX) {
3480 3494 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_PTHTOLONG),
3481 3495 _dir, file);
3482 3496 return (0);
3483 3497 }
3484 3498
3485 3499 /*
3486 3500 * Build the entire pathname and try and open the file.
3487 3501 */
3488 3502 (void) strcpy(path, _dir);
3489 3503 (void) strcat(path, MSG_ORIG(MSG_STR_SLASH));
3490 3504 (void) strcat(path, file);
3491 3505 DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name,
3492 3506 sdf->sdf_rfile, path));
3493 3507
3494 3508 if ((fd = open(path, O_RDONLY)) == -1)
3495 3509 return (0);
3496 3510 else {
3497 3511 uintptr_t open_ret;
3498 3512 Ifl_desc *ifl;
3499 3513 char *_path;
3500 3514
3501 3515 if ((_path = libld_malloc(strlen(path) + 1)) == NULL)
3502 3516 return ((Ifl_desc *)S_ERROR);
3503 3517 (void) strcpy(_path, path);
3504 3518 open_ret = ld_process_open(_path, &_path[dlen], &fd, ofl,
3505 3519 0, rej, &ifl);
3506 3520 if (fd != -1)
3507 3521 (void) close(fd);
3508 3522 if (open_ret != 1)
3509 3523 return ((Ifl_desc *)open_ret);
3510 3524 return (ifl);
3511 3525 }
3512 3526 }
3513 3527
3514 3528 /*
3515 3529 * Finish any library processing. Walk the list of so's that have been listed
3516 3530 * as "included" by shared objects we have previously processed. Examine them,
3517 3531 * without adding them as explicit dependents of this program, in order to
3518 3532 * complete our symbol definition process. The search path rules are:
3519 3533 *
3520 3534 * - use any user supplied paths, i.e. LD_LIBRARY_PATH and -L, then
3521 3535 *
3522 3536 * - use any RPATH defined within the parent shared object, then
3523 3537 *
3524 3538 * - use the default directories, i.e. LIBPATH or -YP.
3525 3539 */
3526 3540 uintptr_t
3527 3541 ld_finish_libs(Ofl_desc *ofl)
3528 3542 {
3529 3543 Aliste idx1;
3530 3544 Sdf_desc *sdf;
3531 3545 Rej_desc rej = { 0 };
3532 3546
3533 3547 /*
3534 3548 * Make sure we are back in dynamic mode.
3535 3549 */
3536 3550 ofl->ofl_flags |= FLG_OF_DYNLIBS;
3537 3551
3538 3552 for (APLIST_TRAVERSE(ofl->ofl_soneed, idx1, sdf)) {
3539 3553 Aliste idx2;
3540 3554 char *path, *slash = NULL;
3541 3555 int fd;
3542 3556 Ifl_desc *ifl;
3543 3557 char *file = (char *)sdf->sdf_name;
3544 3558
3545 3559 /*
3546 3560 * See if this file has already been processed. At the time
3547 3561 * this implicit dependency was determined there may still have
3548 3562 * been more explicit dependencies to process. Note, if we ever
3549 3563 * do parse the command line three times we would be able to
3550 3564 * do all this checking when processing the dynamic section.
3551 3565 */
3552 3566 if (sdf->sdf_file)
3553 3567 continue;
3554 3568
3555 3569 for (APLIST_TRAVERSE(ofl->ofl_sos, idx2, ifl)) {
3556 3570 if (!(ifl->ifl_flags & FLG_IF_NEEDSTR) &&
3557 3571 (strcmp(file, ifl->ifl_soname) == 0)) {
3558 3572 sdf->sdf_file = ifl;
3559 3573 break;
3560 3574 }
3561 3575 }
3562 3576 if (sdf->sdf_file)
3563 3577 continue;
3564 3578
3565 3579 /*
3566 3580 * If the current path name element embeds a "/", then it's to
3567 3581 * be taken "as is", with no searching involved. Process all
3568 3582 * "/" occurrences, so that we can deduce the base file name.
3569 3583 */
3570 3584 for (path = file; *path; path++) {
3571 3585 if (*path == '/')
3572 3586 slash = path;
3573 3587 }
3574 3588 if (slash) {
3575 3589 DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name,
3576 3590 sdf->sdf_rfile, file));
3577 3591 if ((fd = open(file, O_RDONLY)) == -1) {
3578 3592 ld_eprintf(ofl, ERR_WARNING,
3579 3593 MSG_INTL(MSG_FIL_NOTFOUND), file,
3580 3594 sdf->sdf_rfile);
3581 3595 } else {
3582 3596 uintptr_t open_ret;
3583 3597 Rej_desc _rej = { 0 };
3584 3598
3585 3599 open_ret = ld_process_open(file, ++slash,
3586 3600 &fd, ofl, 0, &_rej, &ifl);
3587 3601 if (fd != -1)
3588 3602 (void) close(fd);
3589 3603 if (open_ret == S_ERROR)
3590 3604 return (S_ERROR);
3591 3605
3592 3606 if (_rej.rej_type) {
3593 3607 Conv_reject_desc_buf_t rej_buf;
3594 3608
3595 3609 ld_eprintf(ofl, ERR_WARNING,
3596 3610 MSG_INTL(reject[_rej.rej_type]),
3597 3611 _rej.rej_name ? rej.rej_name :
3598 3612 MSG_INTL(MSG_STR_UNKNOWN),
3599 3613 conv_reject_desc(&_rej, &rej_buf,
3600 3614 ld_targ.t_m.m_mach));
3601 3615 } else
3602 3616 sdf->sdf_file = ifl;
3603 3617 }
3604 3618 continue;
3605 3619 }
3606 3620
3607 3621 /*
3608 3622 * Now search for this file in any user defined directories.
3609 3623 */
3610 3624 for (APLIST_TRAVERSE(ofl->ofl_ulibdirs, idx2, path)) {
3611 3625 Rej_desc _rej = { 0 };
3612 3626
3613 3627 ifl = process_req_lib(sdf, path, file, ofl, &_rej);
3614 3628 if (ifl == (Ifl_desc *)S_ERROR) {
3615 3629 return (S_ERROR);
3616 3630 }
3617 3631 if (_rej.rej_type) {
3618 3632 if (rej.rej_type == 0) {
3619 3633 rej = _rej;
3620 3634 rej.rej_name = strdup(_rej.rej_name);
3621 3635 }
3622 3636 }
3623 3637 if (ifl) {
3624 3638 sdf->sdf_file = ifl;
3625 3639 break;
3626 3640 }
3627 3641 }
3628 3642 if (sdf->sdf_file)
3629 3643 continue;
3630 3644
3631 3645 /*
3632 3646 * Next use the local rules defined within the parent shared
3633 3647 * object.
3634 3648 */
3635 3649 if (sdf->sdf_rpath != NULL) {
3636 3650 char *rpath, *next;
3637 3651
3638 3652 rpath = libld_malloc(strlen(sdf->sdf_rpath) + 1);
3639 3653 if (rpath == NULL)
3640 3654 return (S_ERROR);
3641 3655 (void) strcpy(rpath, sdf->sdf_rpath);
3642 3656 DBG_CALL(Dbg_libs_path(ofl->ofl_lml, rpath,
3643 3657 LA_SER_RUNPATH, sdf->sdf_rfile));
3644 3658 if ((path = strtok_r(rpath,
3645 3659 MSG_ORIG(MSG_STR_COLON), &next)) != NULL) {
3646 3660 do {
3647 3661 Rej_desc _rej = { 0 };
3648 3662
3649 3663 path = expand(sdf->sdf_rfile, path,
3650 3664 &next);
3651 3665
3652 3666 ifl = process_req_lib(sdf, path,
3653 3667 file, ofl, &_rej);
3654 3668 if (ifl == (Ifl_desc *)S_ERROR) {
3655 3669 return (S_ERROR);
3656 3670 }
3657 3671 if ((_rej.rej_type) &&
3658 3672 (rej.rej_type == 0)) {
3659 3673 rej = _rej;
3660 3674 rej.rej_name =
3661 3675 strdup(_rej.rej_name);
3662 3676 }
3663 3677 if (ifl) {
3664 3678 sdf->sdf_file = ifl;
3665 3679 break;
3666 3680 }
3667 3681 } while ((path = strtok_r(NULL,
3668 3682 MSG_ORIG(MSG_STR_COLON), &next)) != NULL);
3669 3683 }
3670 3684 }
3671 3685 if (sdf->sdf_file)
3672 3686 continue;
3673 3687
3674 3688 /*
3675 3689 * Finally try the default library search directories.
3676 3690 */
3677 3691 for (APLIST_TRAVERSE(ofl->ofl_dlibdirs, idx2, path)) {
3678 3692 Rej_desc _rej = { 0 };
3679 3693
3680 3694 ifl = process_req_lib(sdf, path, file, ofl, &rej);
3681 3695 if (ifl == (Ifl_desc *)S_ERROR) {
3682 3696 return (S_ERROR);
3683 3697 }
3684 3698 if (_rej.rej_type) {
3685 3699 if (rej.rej_type == 0) {
3686 3700 rej = _rej;
3687 3701 rej.rej_name = strdup(_rej.rej_name);
3688 3702 }
3689 3703 }
3690 3704 if (ifl) {
3691 3705 sdf->sdf_file = ifl;
3692 3706 break;
3693 3707 }
3694 3708 }
3695 3709 if (sdf->sdf_file)
3696 3710 continue;
3697 3711
3698 3712 /*
3699 3713 * If we've got this far we haven't found the shared object.
3700 3714 * If an object was found, but was rejected for some reason,
3701 3715 * print a diagnostic to that effect, otherwise generate a
3702 3716 * generic "not found" diagnostic.
3703 3717 */
3704 3718 if (rej.rej_type) {
3705 3719 Conv_reject_desc_buf_t rej_buf;
3706 3720
3707 3721 ld_eprintf(ofl, ERR_WARNING,
3708 3722 MSG_INTL(reject[rej.rej_type]),
3709 3723 rej.rej_name ? rej.rej_name :
3710 3724 MSG_INTL(MSG_STR_UNKNOWN),
3711 3725 conv_reject_desc(&rej, &rej_buf,
3712 3726 ld_targ.t_m.m_mach));
3713 3727 } else {
3714 3728 ld_eprintf(ofl, ERR_WARNING,
3715 3729 MSG_INTL(MSG_FIL_NOTFOUND), file, sdf->sdf_rfile);
3716 3730 }
3717 3731 }
3718 3732
3719 3733 /*
3720 3734 * Finally, now that all objects have been input, make sure any version
3721 3735 * requirements have been met.
3722 3736 */
3723 3737 return (ld_vers_verify(ofl));
3724 3738 }
↓ open down ↓ |
522 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX