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