4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1988 AT&T
26 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
27 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
31 * Processing of relocatable objects and shared objects.
34 #define ELF_TARGET_AMD64
35 #define ELF_TARGET_SPARC
44 #include <sys/systeminfo.h>
50 * Decide if we can link against this input file.
53 ifl_verify(Ehdr
*ehdr
, Ofl_desc
*ofl
, Rej_desc
*rej
)
56 * Check the validity of the elf header information for compatibility
57 * with this machine and our own internal elf library.
59 if ((ehdr
->e_machine
!= ld_targ
.t_m
.m_mach
) &&
60 ((ehdr
->e_machine
!= ld_targ
.t_m
.m_machplus
) &&
61 ((ehdr
->e_flags
& ld_targ
.t_m
.m_flagsplus
) == 0))) {
62 rej
->rej_type
= SGS_REJ_MACH
;
63 rej
->rej_info
= (uint_t
)ehdr
->e_machine
;
66 if (ehdr
->e_ident
[EI_DATA
] != ld_targ
.t_m
.m_data
) {
67 rej
->rej_type
= SGS_REJ_DATA
;
68 rej
->rej_info
= (uint_t
)ehdr
->e_ident
[EI_DATA
];
71 if (ehdr
->e_version
> ofl
->ofl_dehdr
->e_version
) {
72 rej
->rej_type
= SGS_REJ_VERSION
;
73 rej
->rej_info
= (uint_t
)ehdr
->e_version
;
80 * Check sanity of file header and allocate an infile descriptor
81 * for the file being processed.
84 ifl_setup(const char *name
, Ehdr
*ehdr
, Elf
*elf
, Word flags
, Ofl_desc
*ofl
,
88 Rej_desc _rej
= { 0 };
90 if (ifl_verify(ehdr
, ofl
, &_rej
) == 0) {
92 DBG_CALL(Dbg_file_rejected(ofl
->ofl_lml
, &_rej
,
94 if (rej
->rej_type
== 0) {
96 rej
->rej_name
= strdup(_rej
.rej_name
);
101 if ((ifl
= libld_calloc(1, sizeof (Ifl_desc
))) == NULL
)
102 return ((Ifl_desc
*)S_ERROR
);
103 ifl
->ifl_name
= name
;
104 ifl
->ifl_ehdr
= ehdr
;
106 ifl
->ifl_flags
= flags
;
109 * Is this file using 'extended Section Indexes'. If so, use the
110 * e_shnum & e_shstrndx which can be found at:
112 * e_shnum == Shdr[0].sh_size
113 * e_shstrndx == Shdr[0].sh_link
115 if ((ehdr
->e_shnum
== 0) && (ehdr
->e_shoff
!= 0)) {
119 if ((scn
= elf_getscn(elf
, 0)) == NULL
) {
120 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_GETSCN
),
122 return ((Ifl_desc
*)S_ERROR
);
124 if ((shdr0
= elf_getshdr(scn
)) == NULL
) {
125 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_GETSHDR
),
127 return ((Ifl_desc
*)S_ERROR
);
129 ifl
->ifl_shnum
= (Word
)shdr0
->sh_size
;
130 if (ehdr
->e_shstrndx
== SHN_XINDEX
)
131 ifl
->ifl_shstrndx
= shdr0
->sh_link
;
133 ifl
->ifl_shstrndx
= ehdr
->e_shstrndx
;
135 ifl
->ifl_shnum
= ehdr
->e_shnum
;
136 ifl
->ifl_shstrndx
= ehdr
->e_shstrndx
;
139 if ((ifl
->ifl_isdesc
= libld_calloc(ifl
->ifl_shnum
,
140 sizeof (Is_desc
*))) == NULL
)
141 return ((Ifl_desc
*)S_ERROR
);
144 * Record this new input file on the shared object or relocatable
145 * object input file list.
147 if (ifl
->ifl_ehdr
->e_type
== ET_DYN
) {
148 if (aplist_append(&ofl
->ofl_sos
, ifl
, AL_CNT_OFL_LIBS
) == NULL
)
149 return ((Ifl_desc
*)S_ERROR
);
151 if (aplist_append(&ofl
->ofl_objs
, ifl
, AL_CNT_OFL_OBJS
) == NULL
)
152 return ((Ifl_desc
*)S_ERROR
);
159 * Process a generic section. The appropriate section information is added
160 * to the files input descriptor list.
163 process_section(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
164 Word ndx
, int ident
, Ofl_desc
*ofl
)
169 * Create a new input section descriptor. If this is a NOBITS
170 * section elf_getdata() will still create a data buffer (the buffer
171 * will be null and the size will reflect the actual memory size).
173 if ((isp
= libld_calloc(sizeof (Is_desc
), 1)) == NULL
)
178 isp
->is_scnndx
= ndx
;
179 isp
->is_flags
= FLG_IS_EXTERNAL
;
180 isp
->is_keyident
= ident
;
182 if ((isp
->is_indata
= elf_getdata(scn
, NULL
)) == NULL
) {
183 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_GETDATA
),
188 if ((shdr
->sh_flags
& SHF_EXCLUDE
) &&
189 ((ofl
->ofl_flags
& FLG_OF_RELOBJ
) == 0)) {
190 isp
->is_flags
|= FLG_IS_DISCARD
;
194 * Add the new input section to the files input section list and
195 * flag whether the section needs placing in an output section. This
196 * placement is deferred until all input section processing has been
197 * completed, as SHT_GROUP sections can provide information that will
198 * affect how other sections within the file should be placed.
200 ifl
->ifl_isdesc
[ndx
] = isp
;
203 if (shdr
->sh_flags
& ALL_SHF_ORDER
) {
204 isp
->is_flags
|= FLG_IS_ORDERED
;
205 ifl
->ifl_flags
|= FLG_IF_ORDERED
;
207 isp
->is_flags
|= FLG_IS_PLACE
;
213 * Determine the software capabilities of the object being built from the
214 * capabilities of the input relocatable objects. One software capability
215 * is presently recognized, and represented with the following (sys/elf.h):
217 * SF1_SUNW_FPKNWN use/non-use of frame pointer is known, and
218 * SF1_SUNW_FPUSED the frame pointer is in use.
220 * The resolution of the present fame pointer state, and the capabilities
221 * provided by a new input relocatable object are:
223 * new input relocatable object
225 * present | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown>
226 * state | SF1_SUNW_FPUSED | |
227 * ---------------------------------------------------------------------------
228 * SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN
229 * SF1_SUNW_FPUSED | SF1_SUNW_FPUSED | | SF1_SUNW_FPUSED
230 * ---------------------------------------------------------------------------
231 * SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN
233 * ---------------------------------------------------------------------------
234 * <unknown> | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown>
235 * | SF1_SUNW_FPUSED | |
238 sf1_cap(Ofl_desc
*ofl
, Xword val
, Ifl_desc
*ifl
, Is_desc
*cisp
)
240 #define FP_FLAGS (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)
245 * If a mapfile has established definitions to override any object
246 * capabilities, ignore any new object capabilities.
248 if (ofl
->ofl_flags1
& FLG_OF1_OVSFCAP1
) {
249 DBG_CALL(Dbg_cap_val_entry(ofl
->ofl_lml
, DBG_STATE_IGNORED
,
250 CA_SUNW_SF_1
, val
, ld_targ
.t_m
.m_mach
));
255 if (ifl
&& (ifl
->ifl_ehdr
->e_type
== ET_REL
)) {
257 * The SF1_SUNW_ADDR32 is only meaningful when building a 64-bit
258 * object. Warn the user, and remove the setting, if we're
259 * building a 32-bit object.
261 if (val
& SF1_SUNW_ADDR32
) {
262 ld_eprintf(ofl
, ERR_WARNING
,
263 MSG_INTL(MSG_FIL_INADDR32SF1
), ifl
->ifl_name
,
264 EC_WORD(cisp
->is_scnndx
), cisp
->is_name
);
265 val
&= ~SF1_SUNW_ADDR32
;
270 * If this object doesn't specify any capabilities, ignore it, and
271 * leave the state as is.
277 * Make sure we only accept known software capabilities. Note, that
278 * an F1_SUNW_FPUSED by itself is viewed as bad practice.
280 if ((badval
= (val
& ~SF1_SUNW_MASK
)) != 0) {
281 ld_eprintf(ofl
, ERR_WARNING
, MSG_INTL(MSG_FIL_BADSF1
),
282 ifl
->ifl_name
, EC_WORD(cisp
->is_scnndx
), cisp
->is_name
,
284 val
&= SF1_SUNW_MASK
;
286 if ((val
& FP_FLAGS
) == SF1_SUNW_FPUSED
) {
287 ld_eprintf(ofl
, ERR_WARNING
, MSG_INTL(MSG_FIL_BADSF1
),
288 ifl
->ifl_name
, EC_WORD(cisp
->is_scnndx
), cisp
->is_name
,
294 * If the input file is not a relocatable object, then we're only here
295 * to warn the user of any questionable capabilities.
297 if (ifl
->ifl_ehdr
->e_type
!= ET_REL
) {
300 * If we're building a 64-bit executable, and we come across a
301 * dependency that requires a restricted address space, then
302 * that dependencies requirement can only be satisfied if the
303 * executable triggers the restricted address space. This is a
304 * warning rather than a fatal error, as the possibility exists
305 * that an appropriate dependency will be provided at runtime.
306 * The runtime linker will refuse to use this dependency.
308 if ((val
& SF1_SUNW_ADDR32
) &&
309 (ofl
->ofl_flags
& (FLG_OF_EXEC
| FLG_OF_PIE
)) &&
310 ((ofl
->ofl_ocapset
.oc_sf_1
.cm_val
&
311 SF1_SUNW_ADDR32
) == 0)) {
312 ld_eprintf(ofl
, ERR_WARNING
,
313 MSG_INTL(MSG_FIL_EXADDR32SF1
), ifl
->ifl_name
,
314 EC_WORD(cisp
->is_scnndx
), cisp
->is_name
);
321 Dbg_cap_val_entry(ofl
->ofl_lml
, DBG_STATE_CURRENT
, CA_SUNW_SF_1
,
322 ofl
->ofl_ocapset
.oc_sf_1
.cm_val
, ld_targ
.t_m
.m_mach
);
323 Dbg_cap_val_entry(ofl
->ofl_lml
, DBG_STATE_NEW
, CA_SUNW_SF_1
,
324 val
, ld_targ
.t_m
.m_mach
);
328 * Determine the resolution of the present frame pointer and the
329 * new input relocatable objects frame pointer.
331 if ((ofl
->ofl_ocapset
.oc_sf_1
.cm_val
& FP_FLAGS
) == FP_FLAGS
) {
333 * If the new relocatable object isn't using a frame pointer,
334 * reduce the present state to unused.
336 if ((val
& FP_FLAGS
) != FP_FLAGS
)
337 ofl
->ofl_ocapset
.oc_sf_1
.cm_val
&= ~SF1_SUNW_FPUSED
;
340 * Having processed the frame pointer bits, remove them from
341 * the value so they don't get OR'd in below.
345 } else if ((ofl
->ofl_ocapset
.oc_sf_1
.cm_val
& SF1_SUNW_FPKNWN
) == 0) {
347 * If the present frame pointer state is unknown, mask it out
348 * and allow the values from the new relocatable object
351 ofl
->ofl_ocapset
.oc_sf_1
.cm_val
&= ~FP_FLAGS
;
353 /* Do not take the frame pointer flags from the object */
357 ofl
->ofl_ocapset
.oc_sf_1
.cm_val
|= val
;
359 DBG_CALL(Dbg_cap_val_entry(ofl
->ofl_lml
, DBG_STATE_RESOLVED
,
360 CA_SUNW_SF_1
, ofl
->ofl_ocapset
.oc_sf_1
.cm_val
, ld_targ
.t_m
.m_mach
));
366 * Determine the hardware capabilities of the object being built from the
367 * capabilities of the input relocatable objects. There's really little to
368 * do here, other than to offer diagnostics, hardware capabilities are simply
372 hw_cap(Ofl_desc
*ofl
, Xword tag
, Xword val
)
374 elfcap_mask_t
*hwcap
;
377 if (tag
== CA_SUNW_HW_1
) {
378 hwcap
= &ofl
->ofl_ocapset
.oc_hw_1
.cm_val
;
379 flags1
= FLG_OF1_OVHWCAP1
;
381 hwcap
= &ofl
->ofl_ocapset
.oc_hw_2
.cm_val
;
382 flags1
= FLG_OF1_OVHWCAP2
;
386 * If a mapfile has established definitions to override any object
387 * capabilities, ignore any new object capabilities.
389 if (ofl
->ofl_flags1
& flags1
) {
390 DBG_CALL(Dbg_cap_val_entry(ofl
->ofl_lml
, DBG_STATE_IGNORED
,
391 tag
, val
, ld_targ
.t_m
.m_mach
));
396 * If this object doesn't specify any capabilities, ignore it, and
397 * leave the state as is.
403 Dbg_cap_val_entry(ofl
->ofl_lml
, DBG_STATE_CURRENT
, CA_SUNW_HW_1
,
404 ofl
->ofl_ocapset
.oc_hw_1
.cm_val
, ld_targ
.t_m
.m_mach
);
405 Dbg_cap_val_entry(ofl
->ofl_lml
, DBG_STATE_NEW
, CA_SUNW_HW_1
,
406 val
, ld_targ
.t_m
.m_mach
);
411 DBG_CALL(Dbg_cap_val_entry(ofl
->ofl_lml
, DBG_STATE_RESOLVED
, tag
,
412 *hwcap
, ld_targ
.t_m
.m_mach
));
416 * Promote a machine capability or platform capability to the output file.
417 * Multiple instances of these names can be defined.
420 str_cap(Ofl_desc
*ofl
, char *pstr
, ofl_flag_t flags
, Xword tag
, Caplist
*list
)
424 Boolean found
= FALSE
;
427 * If a mapfile has established definitions to override this capability,
428 * ignore any new capability.
430 if (ofl
->ofl_flags1
& flags
) {
431 DBG_CALL(Dbg_cap_ptr_entry(ofl
->ofl_lml
, DBG_STATE_IGNORED
,
436 for (ALIST_TRAVERSE(list
->cl_val
, idx
, capstr
)) {
437 DBG_CALL(Dbg_cap_ptr_entry(ofl
->ofl_lml
,
438 DBG_STATE_CURRENT
, tag
, capstr
->cs_str
));
439 if (strcmp(capstr
->cs_str
, pstr
) == 0)
443 DBG_CALL(Dbg_cap_ptr_entry(ofl
->ofl_lml
, DBG_STATE_NEW
, tag
, pstr
));
445 if (found
== FALSE
) {
446 if ((capstr
= alist_append(&list
->cl_val
, NULL
,
447 sizeof (Capstr
), AL_CNT_CAP_NAMES
)) == NULL
) {
448 ofl
->ofl_flags
|= FLG_OF_FATAL
;
451 capstr
->cs_str
= pstr
;
455 for (ALIST_TRAVERSE(list
->cl_val
, idx
, capstr
)) {
456 DBG_CALL(Dbg_cap_ptr_entry(ofl
->ofl_lml
,
457 DBG_STATE_RESOLVED
, tag
, capstr
->cs_str
));
463 * Promote a capability identifier to the output file. A capability group can
464 * only have one identifier, and thus only the first identifier seen from any
465 * input relocatable objects is retained. An explicit user defined identifier,
466 * rather than an an identifier fabricated by ld(1) with -z symbcap processing,
467 * takes precedence. Note, a user may have defined an identifier via a mapfile,
468 * in which case the mapfile identifier is retained.
471 id_cap(Ofl_desc
*ofl
, char *pstr
, oc_flag_t flags
)
473 Objcapset
*ocapset
= &ofl
->ofl_ocapset
;
475 if (ocapset
->oc_id
.cs_str
) {
476 DBG_CALL(Dbg_cap_ptr_entry(ofl
->ofl_lml
, DBG_STATE_CURRENT
,
477 CA_SUNW_ID
, ocapset
->oc_id
.cs_str
));
479 if ((ocapset
->oc_flags
& FLG_OCS_USRDEFID
) ||
480 ((flags
& FLG_OCS_USRDEFID
) == 0)) {
481 DBG_CALL(Dbg_cap_ptr_entry(ofl
->ofl_lml
,
482 DBG_STATE_IGNORED
, CA_SUNW_ID
, pstr
));
487 DBG_CALL(Dbg_cap_ptr_entry(ofl
->ofl_lml
, DBG_STATE_NEW
,
490 ocapset
->oc_id
.cs_str
= pstr
;
491 ocapset
->oc_flags
|= flags
;
493 DBG_CALL(Dbg_cap_ptr_entry(ofl
->ofl_lml
, DBG_STATE_RESOLVED
,
498 * Promote a capabilities group to the object capabilities. This catches a
499 * corner case. An object capabilities file can be converted to symbol
500 * capabilities with -z symbolcap. However, if the user has indicated that all
501 * the symbols should be demoted, we'd be left with a symbol capabilities file,
502 * with no associated symbols. Catch this case by promoting the symbol
503 * capabilities back to object capabilities.
506 ld_cap_move_symtoobj(Ofl_desc
*ofl
)
511 for (APLIST_TRAVERSE(ofl
->ofl_capgroups
, idx1
, cgp
)) {
512 Objcapset
*scapset
= &cgp
->cg_set
;
516 if (scapset
->oc_id
.cs_str
) {
517 if (scapset
->oc_flags
& FLG_OCS_USRDEFID
)
518 id_cap(ofl
, scapset
->oc_id
.cs_str
,
521 if (scapset
->oc_plat
.cl_val
) {
522 for (ALIST_TRAVERSE(scapset
->oc_plat
.cl_val
, idx2
,
524 str_cap(ofl
, capstr
->cs_str
, FLG_OF1_OVPLATCAP
,
525 CA_SUNW_PLAT
, &ofl
->ofl_ocapset
.oc_plat
);
528 if (scapset
->oc_mach
.cl_val
) {
529 for (ALIST_TRAVERSE(scapset
->oc_mach
.cl_val
, idx2
,
531 str_cap(ofl
, capstr
->cs_str
, FLG_OF1_OVMACHCAP
,
532 CA_SUNW_MACH
, &ofl
->ofl_ocapset
.oc_mach
);
535 if (scapset
->oc_hw_2
.cm_val
)
536 hw_cap(ofl
, CA_SUNW_HW_2
, scapset
->oc_hw_2
.cm_val
);
538 if (scapset
->oc_hw_1
.cm_val
)
539 hw_cap(ofl
, CA_SUNW_HW_1
, scapset
->oc_hw_1
.cm_val
);
541 if (scapset
->oc_sf_1
.cm_val
)
542 sf1_cap(ofl
, scapset
->oc_sf_1
.cm_val
, NULL
, NULL
);
547 * Determine whether a capabilities group already exists that describes this
548 * new capabilities group.
550 * Note, a capability group identifier, CA_SUNW_ID, isn't used as part of the
551 * comparison. This attribute simply assigns a diagnostic name to the group,
552 * and in the case of multiple identifiers, the first will be taken.
555 get_cap_group(Objcapset
*ocapset
, Word cnum
, Ofl_desc
*ofl
, Is_desc
*isp
)
562 * If the new capabilities contains a CA_SUNW_ID, drop the count of the
563 * number of comparable items.
565 if (ocapset
->oc_id
.cs_str
)
569 * Traverse the existing symbols capabilities groups.
571 for (APLIST_TRAVERSE(ofl
->ofl_capgroups
, idx
, cgp
)) {
572 Word onum
= cgp
->cg_num
;
575 if (cgp
->cg_set
.oc_id
.cs_str
)
581 if (cgp
->cg_set
.oc_hw_1
.cm_val
!= ocapset
->oc_hw_1
.cm_val
)
583 if (cgp
->cg_set
.oc_sf_1
.cm_val
!= ocapset
->oc_sf_1
.cm_val
)
585 if (cgp
->cg_set
.oc_hw_2
.cm_val
!= ocapset
->oc_hw_2
.cm_val
)
588 calp
= cgp
->cg_set
.oc_plat
.cl_val
;
589 oalp
= ocapset
->oc_plat
.cl_val
;
590 if ((calp
== NULL
) && oalp
)
592 if (calp
&& ((oalp
== NULL
) || cap_names_match(calp
, oalp
)))
595 calp
= cgp
->cg_set
.oc_mach
.cl_val
;
596 oalp
= ocapset
->oc_mach
.cl_val
;
597 if ((calp
== NULL
) && oalp
)
599 if (calp
&& ((oalp
== NULL
) || cap_names_match(calp
, oalp
)))
603 * If a matching group is found, then this new group has
604 * already been supplied by a previous file, and hence the
605 * existing group can be used. Record this new input section,
606 * from which we can also derive the input file name, on the
607 * existing groups input sections.
609 if (aplist_append(&(cgp
->cg_secs
), isp
,
610 AL_CNT_CAP_SECS
) == NULL
)
616 * If a capabilities group is not found, create a new one.
618 if (((cgp
= libld_calloc(sizeof (Cap_group
), 1)) == NULL
) ||
619 (aplist_append(&(ofl
->ofl_capgroups
), cgp
,
620 AL_CNT_CAP_DESCS
) == NULL
))
624 * If we're converting object capabilities to symbol capabilities and
625 * no CA_SUNW_ID is defined, fabricate one. This identifier is appended
626 * to all symbol names that are converted into capabilities symbols,
627 * see ld_sym_process().
629 if ((isp
->is_file
->ifl_flags
& FLG_IF_OTOSCAP
) &&
630 (ocapset
->oc_id
.cs_str
== NULL
)) {
634 * Create an identifier using the group number together with a
635 * default template. We allocate a buffer large enough for any
636 * possible number of items (way more than we need).
638 len
= MSG_STR_CAPGROUPID_SIZE
+ CONV_INV_BUFSIZE
;
639 if ((ocapset
->oc_id
.cs_str
= libld_malloc(len
)) == NULL
)
642 (void) snprintf(ocapset
->oc_id
.cs_str
, len
,
643 MSG_ORIG(MSG_STR_CAPGROUPID
),
644 aplist_nitems(ofl
->ofl_capgroups
));
648 cgp
->cg_set
= *ocapset
;
652 * Null the callers alist's as they've effectively been transferred
653 * to this new Cap_group.
655 ocapset
->oc_plat
.cl_val
= ocapset
->oc_mach
.cl_val
= NULL
;
658 * Keep track of which input section, and hence input file, established
661 if (aplist_append(&(cgp
->cg_secs
), isp
, AL_CNT_CAP_SECS
) == NULL
)
665 * Keep track of the number of symbol capabilities entries that will be
666 * required in the output file. Each group requires a terminating
669 ofl
->ofl_capsymcnt
+= (cnum
+ 1);
674 * Capture symbol capability family information. This data structure is focal
675 * in maintaining all symbol capability relationships, and provides for the
676 * eventual creation of a capabilities information section, and possibly a
677 * capabilities chain section.
679 * Capabilities families are lead by a CAPINFO_SUNW_GLOB symbol. This symbol
680 * provides the visible global symbol that is referenced by all external
681 * callers. This symbol may have aliases. For example, a weak/global symbol
682 * pair, such as memcpy()/_memcpy() may lead the same capabilities family.
683 * Each family contains one or more local symbol members. These members provide
684 * the capabilities specific functions, and are associated to a capabilities
685 * group. For example, the capability members memcpy%sun4u and memcpy%sun4v
686 * might be associated with the memcpy() capability family.
688 * This routine is called when a relocatable object that provides object
689 * capabilities is transformed into a symbol capabilities object, using the
690 * -z symbolcap option.
692 * This routine is also called to collect the SUNW_capinfo section information
693 * of a relocatable object that contains symbol capability definitions.
696 ld_cap_add_family(Ofl_desc
*ofl
, Sym_desc
*lsdp
, Sym_desc
*csdp
, Cap_group
*cgp
,
699 Cap_avlnode qcav
, *cav
;
701 avl_index_t where
= 0;
706 * Make sure the capability families have an initialized AVL tree.
708 if ((avlt
= ofl
->ofl_capfamilies
) == NULL
) {
709 if ((avlt
= libld_calloc(sizeof (avl_tree_t
), 1)) == NULL
)
711 avl_create(avlt
, &ld_sym_avl_comp
, sizeof (Cap_avlnode
),
712 SGSOFFSETOF(Cap_avlnode
, cn_symavlnode
.sav_node
));
713 ofl
->ofl_capfamilies
= avlt
;
716 * When creating a dynamic object, capability family members
717 * are maintained in a .SUNW_capchain, the first entry of
718 * which is the version number of the chain.
720 ofl
->ofl_capchaincnt
= 1;
724 * Determine whether a family already exists, and if not, create one
725 * using the lead family symbol.
727 qcav
.cn_symavlnode
.sav_hash
= (Word
)elf_hash(lsdp
->sd_name
);
728 qcav
.cn_symavlnode
.sav_name
= lsdp
->sd_name
;
730 if ((cav
= avl_find(avlt
, &qcav
, &where
)) == NULL
) {
731 if ((cav
= libld_calloc(sizeof (Cap_avlnode
), 1)) == NULL
)
733 cav
->cn_symavlnode
.sav_hash
= qcav
.cn_symavlnode
.sav_hash
;
734 cav
->cn_symavlnode
.sav_name
= qcav
.cn_symavlnode
.sav_name
;
735 cav
->cn_symavlnode
.sav_sdp
= lsdp
;
737 avl_insert(avlt
, cav
, where
);
740 * When creating a dynamic object, capability family members
741 * are maintained in a .SUNW_capchain, each family starts with
742 * this lead symbol, and is terminated with a 0 element.
744 ofl
->ofl_capchaincnt
+= 2;
748 * If no group information is provided then this request is to add a
749 * lead capability symbol, or lead symbol alias. If this is the lead
750 * symbol there's nothing more to do. Otherwise save the alias.
753 if ((lsdp
!= csdp
) && (aplist_append(&cav
->cn_aliases
, csdp
,
754 AL_CNT_CAP_ALIASES
) == NULL
))
761 * Determine whether a member of the same group as this new member is
762 * already defined within this family. If so, we have a multiply
765 for (APLIST_TRAVERSE(cav
->cn_members
, idx
, mcsp
)) {
768 if (cgp
!= mcsp
->cs_group
)
772 * Diagnose that a multiple symbol definition exists.
776 ld_eprintf(ofl
, ERR_FATAL
, MSG_INTL(MSG_CAP_MULDEF
),
777 demangle(lsdp
->sd_name
));
778 ld_eprintf(ofl
, ERR_NONE
, MSG_INTL(MSG_CAP_MULDEFSYMS
),
779 msdp
->sd_file
->ifl_name
, msdp
->sd_name
,
780 csdp
->sd_file
->ifl_name
, csdp
->sd_name
);
784 * Add this capabilities symbol member to the family.
786 if (((mcsp
= libld_malloc(sizeof (Cap_sym
))) == NULL
) ||
787 (aplist_append(&cav
->cn_members
, mcsp
, AL_CNT_CAP_MEMS
) == NULL
))
791 mcsp
->cs_group
= cgp
;
794 * When creating a dynamic object, capability family members are
795 * maintained in a .SUNW_capchain. Account for this family member.
797 ofl
->ofl_capchaincnt
++;
800 * If this input file is undergoing object capabilities to symbol
801 * capabilities conversion, then this member is a new local symbol
802 * that has been generated from an original global symbol. Keep track
803 * of this symbol so that the output file symbol table can be populated
804 * with these new symbol entries.
806 if (csyms
&& (aplist_append(csyms
, mcsp
, AL_CNT_CAP_SYMS
) == NULL
))
813 * Process a SHT_SUNW_cap capabilities section.
816 process_cap(Ofl_desc
*ofl
, Ifl_desc
*ifl
, Is_desc
*cisp
)
818 Objcapset ocapset
= { 0 };
823 int objcapndx
, descapndx
, symcapndx
;
824 int nulls
, capstrs
= 0;
827 * Determine the capabilities data and size.
829 cdata
= (Cap
*)cisp
->is_indata
->d_buf
;
830 cnum
= (Word
)(cisp
->is_shdr
->sh_size
/ cisp
->is_shdr
->sh_entsize
);
832 if ((cdata
== NULL
) || (cnum
== 0))
835 DBG_CALL(Dbg_cap_sec_title(ofl
->ofl_lml
, ifl
->ifl_name
));
838 * Traverse the section to determine what capabilities groups are
841 * A capabilities section can contain one or more, CA_SUNW_NULL
844 * - The first group defines the object capabilities.
845 * - Additional groups define symbol capabilities.
846 * - Since the initial group is always reserved for object
847 * capabilities, any object with symbol capabilities must also
848 * have an object capabilities group. If the object has no object
849 * capabilities, an empty object group is defined, consisting of a
850 * CA_SUNW_NULL element in index [0].
851 * - If any capabilities require references to a named string, then
852 * the section header sh_info points to the associated string
854 * - If an object contains symbol capability groups, then the
855 * section header sh_link points to the associated capinfo table.
858 descapndx
= symcapndx
= -1;
861 for (ndx
= 0, data
= cdata
; ndx
< cnum
; ndx
++, data
++) {
862 switch (data
->c_tag
) {
865 * If this is the first CA_SUNW_NULL entry, and no
866 * capabilities group has been found, then this object
867 * does not define any object capabilities.
872 } else if ((symcapndx
== -1) && (descapndx
!= -1))
873 symcapndx
= descapndx
;
887 * If this is the start of a new group, save it.
894 ld_eprintf(ofl
, ERR_WARNING
, MSG_INTL(MSG_FIL_UNKCAP
),
895 ifl
->ifl_name
, EC_WORD(cisp
->is_scnndx
),
896 cisp
->is_name
, data
->c_tag
);
901 * If a string capabilities entry has been found, the capabilities
902 * section must reference the associated string table.
905 Word info
= cisp
->is_shdr
->sh_info
;
907 if ((info
== 0) || (info
> ifl
->ifl_shnum
)) {
908 ld_eprintf(ofl
, ERR_FATAL
, MSG_INTL(MSG_FIL_INVSHINFO
),
909 ifl
->ifl_name
, EC_WORD(cisp
->is_scnndx
),
910 cisp
->is_name
, EC_XWORD(info
));
913 strs
= (char *)ifl
->ifl_isdesc
[info
]->is_indata
->d_buf
;
917 * The processing of capabilities groups is as follows:
919 * - if a relocatable object provides only object capabilities, and
920 * the -z symbolcap option is in effect, then the object
921 * capabilities are transformed into symbol capabilities and the
922 * symbol capabilities are carried over to the output file.
923 * - in all other cases, any capabilities present in an input
924 * relocatable object are carried from the input object to the
925 * output without any transformation or conversion.
927 * Capture any object capabilities that are to be carried over to the
930 if ((objcapndx
== 0) &&
931 ((symcapndx
!= -1) || ((ofl
->ofl_flags
& FLG_OF_OTOSCAP
) == 0))) {
932 for (ndx
= 0, data
= cdata
; ndx
< cnum
; ndx
++, data
++) {
934 * Object capabilities end at the first null.
936 if (data
->c_tag
== CA_SUNW_NULL
)
940 * Only the object software capabilities that are
941 * defined in a relocatable object become part of the
942 * object software capabilities in the output file.
943 * However, check the validity of any object software
944 * capabilities of any dependencies.
946 if (data
->c_tag
== CA_SUNW_SF_1
) {
947 sf1_cap(ofl
, data
->c_un
.c_val
, ifl
, cisp
);
952 * The remaining capability types must come from a
953 * relocatable object in order to contribute to the
956 if (ifl
->ifl_ehdr
->e_type
!= ET_REL
)
959 switch (data
->c_tag
) {
962 hw_cap(ofl
, data
->c_tag
, data
->c_un
.c_val
);
966 str_cap(ofl
, strs
+ data
->c_un
.c_ptr
,
967 FLG_OF1_OVPLATCAP
, CA_SUNW_PLAT
,
968 &ofl
->ofl_ocapset
.oc_plat
);
972 str_cap(ofl
, strs
+ data
->c_un
.c_ptr
,
973 FLG_OF1_OVMACHCAP
, CA_SUNW_MACH
,
974 &ofl
->ofl_ocapset
.oc_mach
);
978 id_cap(ofl
, strs
+ data
->c_un
.c_ptr
,
983 assert(0); /* Unknown capability type */
988 * If there are no symbol capabilities, or this objects
989 * capabilities aren't being transformed into a symbol
990 * capabilities, then we're done.
992 if ((symcapndx
== -1) &&
993 ((ofl
->ofl_flags
& FLG_OF_OTOSCAP
) == 0))
998 * If these capabilities don't originate from a relocatable object
999 * there's no further processing required.
1001 if (ifl
->ifl_ehdr
->e_type
!= ET_REL
)
1005 * If this object only defines an object capabilities group, and the
1006 * -z symbolcap option is in effect, then all global function symbols
1007 * and initialized global data symbols are renamed and assigned to the
1008 * transformed symbol capabilities group.
1010 if ((objcapndx
== 0) &&
1011 (symcapndx
== -1) && (ofl
->ofl_flags
& FLG_OF_OTOSCAP
))
1012 ifl
->ifl_flags
|= FLG_IF_OTOSCAP
;
1015 * Allocate a capabilities descriptor to collect the capabilities data
1016 * for this input file. Allocate a mirror of the raw capabilities data
1017 * that points to the individual symbol capabilities groups. An APlist
1018 * is used, although it will be sparsely populated, as the list provides
1019 * a convenient mechanism for traversal later.
1021 if (((cdp
= libld_calloc(sizeof (Cap_desc
), 1)) == NULL
) ||
1022 (aplist_append(&(cdp
->ca_groups
), NULL
, cnum
) == NULL
))
1026 * Clear the allocated APlist data array, and assign the number of
1027 * items as the total number of array items.
1029 (void) memset(&cdp
->ca_groups
->apl_data
[0], 0,
1030 (cnum
* sizeof (void *)));
1031 cdp
->ca_groups
->apl_nitems
= cnum
;
1033 ifl
->ifl_caps
= cdp
;
1036 * Traverse the capabilities data, unpacking the data into a
1037 * capabilities set. Process each capabilities set as a unique group.
1042 for (ndx
= 0, data
= cdata
; ndx
< cnum
; ndx
++, data
++) {
1045 switch (data
->c_tag
) {
1050 * Process the capabilities group that this null entry
1051 * terminates. The capabilities group that is returned
1052 * will either point to this file's data, or to a
1053 * matching capabilities group that has already been
1056 * Note, if this object defines object capabilities,
1057 * the first group descriptor points to these object
1058 * capabilities. It is only necessary to save this
1059 * descriptor when object capabilities are being
1060 * transformed into symbol capabilities (-z symbolcap).
1062 if (descapndx
!= -1) {
1064 (ifl
->ifl_flags
& FLG_IF_OTOSCAP
)) {
1065 APlist
*alp
= cdp
->ca_groups
;
1067 if ((alp
->apl_data
[descapndx
] =
1068 get_cap_group(&ocapset
,
1069 (ndx
- descapndx
), ofl
,
1075 * Clean up the capabilities data in preparation
1076 * for processing additional groups. If the
1077 * collected capabilities strings were used to
1078 * establish a new output group, they will have
1079 * been saved in get_cap_group(). If these
1080 * descriptors still exist, then an existing
1081 * descriptor has been used to associate with
1082 * this file, and these string descriptors can
1085 ocapset
.oc_hw_1
.cm_val
=
1086 ocapset
.oc_sf_1
.cm_val
=
1087 ocapset
.oc_hw_2
.cm_val
= 0;
1088 if (ocapset
.oc_plat
.cl_val
) {
1089 free((void *)ocapset
.oc_plat
.cl_val
);
1090 ocapset
.oc_plat
.cl_val
= NULL
;
1092 if (ocapset
.oc_mach
.cl_val
) {
1093 free((void *)ocapset
.oc_mach
.cl_val
);
1094 ocapset
.oc_mach
.cl_val
= NULL
;
1101 ocapset
.oc_hw_1
.cm_val
= data
->c_un
.c_val
;
1102 DBG_CALL(Dbg_cap_val_entry(ofl
->ofl_lml
,
1103 DBG_STATE_ORIGINAL
, CA_SUNW_HW_1
,
1104 ocapset
.oc_hw_1
.cm_val
, ld_targ
.t_m
.m_mach
));
1108 ocapset
.oc_sf_1
.cm_val
= data
->c_un
.c_val
;
1109 DBG_CALL(Dbg_cap_val_entry(ofl
->ofl_lml
,
1110 DBG_STATE_ORIGINAL
, CA_SUNW_SF_1
,
1111 ocapset
.oc_sf_1
.cm_val
, ld_targ
.t_m
.m_mach
));
1115 ocapset
.oc_hw_2
.cm_val
= data
->c_un
.c_val
;
1116 DBG_CALL(Dbg_cap_val_entry(ofl
->ofl_lml
,
1117 DBG_STATE_ORIGINAL
, CA_SUNW_HW_2
,
1118 ocapset
.oc_hw_2
.cm_val
, ld_targ
.t_m
.m_mach
));
1122 if ((capstr
= alist_append(&ocapset
.oc_plat
.cl_val
,
1123 NULL
, sizeof (Capstr
), AL_CNT_CAP_NAMES
)) == NULL
)
1125 capstr
->cs_str
= strs
+ data
->c_un
.c_ptr
;
1126 DBG_CALL(Dbg_cap_ptr_entry(ofl
->ofl_lml
,
1127 DBG_STATE_ORIGINAL
, CA_SUNW_PLAT
, capstr
->cs_str
));
1131 if ((capstr
= alist_append(&ocapset
.oc_mach
.cl_val
,
1132 NULL
, sizeof (Capstr
), AL_CNT_CAP_NAMES
)) == NULL
)
1134 capstr
->cs_str
= strs
+ data
->c_un
.c_ptr
;
1135 DBG_CALL(Dbg_cap_ptr_entry(ofl
->ofl_lml
,
1136 DBG_STATE_ORIGINAL
, CA_SUNW_MACH
, capstr
->cs_str
));
1140 ocapset
.oc_id
.cs_str
= strs
+ data
->c_un
.c_ptr
;
1141 DBG_CALL(Dbg_cap_ptr_entry(ofl
->ofl_lml
,
1142 DBG_STATE_ORIGINAL
, CA_SUNW_ID
,
1143 ocapset
.oc_id
.cs_str
));
1148 * Save the start of this new group.
1150 if (descapndx
== -1)
1157 * Capture any symbol capabilities symbols. An object file that contains symbol
1158 * capabilities has an associated .SUNW_capinfo section. This section
1159 * identifies which symbols are associated to which capabilities, together with
1160 * their associated lead symbol. Each of these symbol pairs are recorded for
1164 process_capinfo(Ofl_desc
*ofl
, Ifl_desc
*ifl
, Is_desc
*isp
)
1166 Cap_desc
*cdp
= ifl
->ifl_caps
;
1167 Capinfo
*capinfo
= isp
->is_indata
->d_buf
;
1168 Shdr
*shdr
= isp
->is_shdr
;
1169 Word cndx
, capinfonum
;
1171 capinfonum
= (Word
)(shdr
->sh_size
/ shdr
->sh_entsize
);
1173 if ((cdp
== NULL
) || (capinfo
== NULL
) || (capinfonum
== 0))
1176 for (cndx
= 1, capinfo
++; cndx
< capinfonum
; cndx
++, capinfo
++) {
1177 Sym_desc
*sdp
, *lsdp
;
1181 if ((gndx
= (uchar_t
)ELF_C_GROUP(*capinfo
)) == 0)
1183 lndx
= (Word
)ELF_C_SYM(*capinfo
);
1186 * Catch any anomalies. A capabilities symbol should be valid,
1187 * and the capabilities lead symbol should also be global.
1188 * Note, ld(1) -z symbolcap would create local capabilities
1189 * symbols, but we don't enforce this so as to give the
1190 * compilation environment a little more freedom.
1192 if ((sdp
= ifl
->ifl_oldndx
[cndx
]) == NULL
) {
1193 ld_eprintf(ofl
, ERR_WARNING
,
1194 MSG_INTL(MSG_CAPINFO_INVALSYM
), ifl
->ifl_name
,
1195 EC_WORD(isp
->is_scnndx
), isp
->is_name
, cndx
,
1196 MSG_INTL(MSG_STR_UNKNOWN
));
1199 if ((lndx
== 0) || (lndx
>= ifl
->ifl_symscnt
) ||
1200 ((lsdp
= ifl
->ifl_oldndx
[lndx
]) == NULL
) ||
1201 (ELF_ST_BIND(lsdp
->sd_sym
->st_info
) != STB_GLOBAL
)) {
1202 ld_eprintf(ofl
, ERR_WARNING
,
1203 MSG_INTL(MSG_CAPINFO_INVALLEAD
), ifl
->ifl_name
,
1204 EC_WORD(isp
->is_scnndx
), isp
->is_name
, cndx
, lsdp
?
1205 demangle(lsdp
->sd_name
) : MSG_INTL(MSG_STR_UNKNOWN
),
1211 * Indicate that this is a capabilities symbol.
1213 sdp
->sd_flags
|= FLG_SY_CAP
;
1216 * Save any global capability symbols. Global capability
1217 * symbols are identified with a CAPINFO_SUNW_GLOB group id.
1218 * The lead symbol for this global capability symbol is either
1219 * the symbol itself, or an alias.
1221 if (gndx
== CAPINFO_SUNW_GLOB
) {
1222 if (ld_cap_add_family(ofl
, lsdp
, sdp
,
1223 NULL
, NULL
) == S_ERROR
)
1229 * Track the number of non-global capabilities symbols, as these
1230 * are used to size any symbol tables. If we're generating a
1231 * dynamic object, this symbol will be added to the dynamic
1232 * symbol table, therefore ensure there is space in the dynamic
1235 ofl
->ofl_caploclcnt
++;
1236 if (((ofl
->ofl_flags
& FLG_OF_RELOBJ
) == 0) &&
1237 (st_insert(ofl
->ofl_dynstrtab
, sdp
->sd_name
) == -1))
1241 * As we're tracking this local symbol as a capabilities symbol,
1242 * reduce the local symbol count to compensate.
1247 * Determine whether the associated lead symbol indicates
1248 * NODYNSORT. If so, remove this local entry from the
1249 * SUNW_dynsort section too. NODYNSORT tagging can only be
1250 * obtained from a mapfile symbol definition, and thus any
1251 * global definition that has this tagging has already been
1252 * instantiated and this instance resolved to it.
1254 if (lsdp
->sd_flags
& FLG_SY_NODYNSORT
) {
1255 Sym
*lsym
= lsdp
->sd_sym
;
1256 uchar_t ltype
= ELF_ST_TYPE(lsym
->st_info
);
1258 DYNSORT_COUNT(lsdp
, lsym
, ltype
, --);
1259 lsdp
->sd_flags
|= FLG_SY_NODYNSORT
;
1263 * Track this family member, together with its associated group.
1265 if (ld_cap_add_family(ofl
, lsdp
, sdp
,
1266 cdp
->ca_groups
->apl_data
[gndx
], NULL
) == S_ERROR
)
1274 * Simply process the section so that we have pointers to the data for use
1275 * in later routines, however don't add the section to the output section
1276 * list as we will be creating our own replacement sections later (ie.
1277 * symtab and relocation).
1281 process_input(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
1282 Word ndx
, int ident
, Ofl_desc
*ofl
)
1284 return (process_section(name
, ifl
, shdr
, scn
, ndx
,
1285 ld_targ
.t_id
.id_null
, ofl
));
1289 * Keep a running count of relocation entries from input relocatable objects for
1290 * sizing relocation buckets later. If we're building an executable, save any
1291 * relocations from shared objects to determine if any copy relocation symbol
1292 * has a displacement relocation against it.
1296 process_reloc(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
1297 Word ndx
, int ident
, Ofl_desc
*ofl
)
1299 if (process_section(name
, ifl
,
1300 shdr
, scn
, ndx
, ld_targ
.t_id
.id_null
, ofl
) == S_ERROR
)
1303 if (ifl
->ifl_ehdr
->e_type
== ET_REL
) {
1304 if (shdr
->sh_entsize
&& (shdr
->sh_entsize
<= shdr
->sh_size
))
1306 ofl
->ofl_relocincnt
+=
1307 (Word
)(shdr
->sh_size
/ shdr
->sh_entsize
);
1308 } else if (ofl
->ofl_flags
& FLG_OF_EXEC
) {
1309 if (aplist_append(&ifl
->ifl_relsect
, ifl
->ifl_isdesc
[ndx
],
1310 AL_CNT_IFL_RELSECS
) == NULL
)
1317 * Process a string table section. A valid section contains an initial and
1321 process_strtab(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
1322 Word ndx
, int ident
, Ofl_desc
*ofl
)
1330 * Never include .stab.excl sections in any output file.
1331 * If the -s flag has been specified strip any .stab sections.
1333 if (((ofl
->ofl_flags
& FLG_OF_STRIP
) && ident
&&
1334 (strncmp(name
, MSG_ORIG(MSG_SCN_STAB
), MSG_SCN_STAB_SIZE
) == 0)) ||
1335 (strcmp(name
, MSG_ORIG(MSG_SCN_STABEXCL
)) == 0) && ident
)
1339 * If we got here to process a .shstrtab or .dynstr table, `ident' will
1340 * be null. Otherwise make sure we don't have a .strtab section as this
1341 * should not be added to the output section list either.
1343 if ((ident
!= ld_targ
.t_id
.id_null
) &&
1344 (strcmp(name
, MSG_ORIG(MSG_SCN_STRTAB
)) == 0))
1345 ident
= ld_targ
.t_id
.id_null
;
1347 error
= process_section(name
, ifl
, shdr
, scn
, ndx
, ident
, ofl
);
1348 if ((error
== 0) || (error
== S_ERROR
))
1352 * String tables should start and end with a NULL byte. Note, it has
1353 * been known for the assembler to create empty string tables, so check
1354 * the size before attempting to verify the data itself.
1356 isp
= ifl
->ifl_isdesc
[ndx
];
1357 size
= isp
->is_indata
->d_size
;
1359 data
= isp
->is_indata
->d_buf
;
1360 if (data
[0] != '\0' || data
[size
- 1] != '\0')
1361 ld_eprintf(ofl
, ERR_WARNING
,
1362 MSG_INTL(MSG_FIL_MALSTR
), ifl
->ifl_name
,
1363 EC_WORD(isp
->is_scnndx
), name
);
1365 isp
->is_indata
->d_buf
= (void *)MSG_ORIG(MSG_STR_EMPTY
);
1367 ifl
->ifl_flags
|= FLG_IF_HSTRTAB
;
1372 * Invalid sections produce a warning and are skipped.
1376 invalid_section(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
1377 Word ndx
, int ident
, Ofl_desc
*ofl
)
1379 Conv_inv_buf_t inv_buf
;
1381 ld_eprintf(ofl
, ERR_WARNING
, MSG_INTL(MSG_FIL_INVALSEC
),
1382 ifl
->ifl_name
, EC_WORD(ndx
), name
,
1383 conv_sec_type(ifl
->ifl_ehdr
->e_ident
[EI_OSABI
],
1384 ifl
->ifl_ehdr
->e_machine
, shdr
->sh_type
, 0, &inv_buf
));
1389 * Compare an input section name to a given string, taking the ELF '%'
1390 * section naming convention into account. If an input section name
1391 * contains a '%' character, the '%' and all following characters are
1392 * ignored in the comparison.
1395 * is_name - Name of input section
1396 * match_name - Name to compare to
1397 * match_len - strlen(match_name)
1400 * Returns True (1) if the names match, and False (0) otherwise.
1403 is_name_cmp(const char *is_name
, const char *match_name
, size_t match_len
)
1406 * If the start of is_name is not a match for name,
1409 if (strncmp(is_name
, match_name
, match_len
) != 0)
1413 * The prefix matched. The next character must be either '%', or
1414 * NULL, in order for a match to be true.
1416 is_name
+= match_len
;
1417 return ((*is_name
== '\0') || (*is_name
== '%'));
1421 * Helper routine for process_progbits() to process allocable sections.
1424 * name, ifl, shdr, ndx, ident, ofl - As passed to process_progbits().
1425 * is_stab_index - TRUE if section is .index.
1426 * is_flags - Additional flags to be added to the input section.
1429 * The allocable section has been processed. *ident and *is_flags
1430 * are updated as necessary to reflect the changes. Returns TRUE
1431 * for success, FALSE for failure.
1434 inline static Boolean
1435 process_progbits_alloc(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
,
1436 Word ndx
, int *ident
, Ofl_desc
*ofl
, Boolean is_stab_index
,
1439 Boolean done
= FALSE
;
1441 if (name
[0] == '.') {
1444 if (!is_name_cmp(name
, MSG_ORIG(MSG_SCN_EHFRAME
),
1445 MSG_SCN_EHFRAME_SIZE
))
1448 *ident
= ld_targ
.t_id
.id_unwind
;
1449 *is_flags
|= FLG_IS_EHFRAME
;
1453 * Historically, the section containing the logic to
1454 * unwind stack frames -- the .eh_frame section -- was
1455 * of type SHT_PROGBITS. Apparently the most
1456 * aesthetically galling aspect of this was not the
1457 * .eh_frame section's dubious purpose or its filthy
1458 * implementation, but rather its section type; with the
1459 * introduction of the AMD64 ABI, a new section header
1460 * type (SHT_AMD64_UNWIND) was introduced for (and
1461 * dedicated to) this section. When both the Sun
1462 * compilers and the GNU compilers had been modified to
1463 * generate this new section type, the linker became
1464 * much more pedantic about .eh_frame: it refused to
1465 * link an AMD64 object that contained a .eh_frame with
1466 * the legacy SHT_PROGBITS. That this was too fussy is
1467 * evidenced by searching the net for the error message
1468 * that it generated ("section type is SHT_PROGBITS:
1469 * expected SHT_AMD64_UNWIND"), which reveals a myriad
1470 * of problems, including legacy objects, hand-coded
1471 * assembly and otherwise cross-platform objects
1472 * created on other platforms (the GNU toolchain was
1473 * only modified to create the new section type on
1474 * Solaris and derivatives). We therefore always accept
1475 * a .eh_frame of SHT_PROGBITS -- regardless of
1480 if (is_name_cmp(name
, MSG_ORIG(MSG_SCN_GOT
),
1481 MSG_SCN_GOT_SIZE
)) {
1482 *ident
= ld_targ
.t_id
.id_null
;
1486 if ((ld_targ
.t_m
.m_sht_unwind
== SHT_PROGBITS
) &&
1487 is_name_cmp(name
, MSG_ORIG(MSG_SCN_GCC_X_TBL
),
1488 MSG_SCN_GCC_X_TBL_SIZE
)) {
1489 *ident
= ld_targ
.t_id
.id_unwind
;
1495 if (is_name_cmp(name
, MSG_ORIG(MSG_SCN_PLT
),
1496 MSG_SCN_PLT_SIZE
)) {
1497 *ident
= ld_targ
.t_id
.id_null
;
1504 if (is_stab_index
) {
1506 * This is a work-around for x86 compilers that have
1507 * set SHF_ALLOC for the .stab.index section.
1509 * Because of this, make sure that the .stab.index
1510 * does not end up as the last section in the text
1511 * segment. Older linkers can produce segmentation
1512 * violations when they strip (ld -s) against a
1513 * shared object whose last section in the text
1514 * segment is a .stab.
1516 *ident
= ld_targ
.t_id
.id_interp
;
1518 *ident
= ld_targ
.t_id
.id_data
;
1526 * Process a progbits section.
1529 process_progbits(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
1530 Word ndx
, int ident
, Ofl_desc
*ofl
)
1532 Boolean is_stab_index
= FALSE
;
1537 * Never include .stab.excl sections in any output file.
1538 * If the -s flag has been specified strip any .stab sections.
1540 if (ident
&& (strncmp(name
, MSG_ORIG(MSG_SCN_STAB
),
1541 MSG_SCN_STAB_SIZE
) == 0)) {
1542 if ((ofl
->ofl_flags
& FLG_OF_STRIP
) ||
1543 (strcmp((name
+ MSG_SCN_STAB_SIZE
),
1544 MSG_ORIG(MSG_SCN_EXCL
)) == 0))
1547 if (strcmp((name
+ MSG_SCN_STAB_SIZE
),
1548 MSG_ORIG(MSG_SCN_INDEX
)) == 0)
1549 is_stab_index
= TRUE
;
1552 if ((ofl
->ofl_flags
& FLG_OF_STRIP
) && ident
) {
1553 if ((strncmp(name
, MSG_ORIG(MSG_SCN_DEBUG
),
1554 MSG_SCN_DEBUG_SIZE
) == 0) ||
1555 (strcmp(name
, MSG_ORIG(MSG_SCN_LINE
)) == 0))
1560 * Update the ident to reflect the type of section we've got.
1562 * If there is any .plt or .got section to generate we'll be creating
1563 * our own version, so don't allow any input sections of these types to
1564 * be added to the output section list (why a relocatable object would
1565 * have a .plt or .got is a mystery, but stranger things have occurred).
1567 * If there are any unwind sections, and this is a platform that uses
1568 * SHT_PROGBITS for unwind sections, then set their ident to reflect
1572 if (shdr
->sh_flags
& SHF_TLS
) {
1573 ident
= ld_targ
.t_id
.id_tls
;
1574 } else if ((shdr
->sh_flags
& ~ALL_SHF_IGNORE
) ==
1575 (SHF_ALLOC
| SHF_EXECINSTR
)) {
1576 ident
= ld_targ
.t_id
.id_text
;
1577 } else if (shdr
->sh_flags
& SHF_ALLOC
) {
1578 if (process_progbits_alloc(name
, ifl
, shdr
, ndx
,
1579 &ident
, ofl
, is_stab_index
, &is_flags
) == FALSE
)
1582 ident
= ld_targ
.t_id
.id_note
;
1586 r
= process_section(name
, ifl
, shdr
, scn
, ndx
, ident
, ofl
);
1589 * On success, process_section() creates an input section descriptor.
1590 * Now that it exists, we can add any pending input section flags.
1592 if ((is_flags
!= 0) && (r
== 1))
1593 ifl
->ifl_isdesc
[ndx
]->is_flags
|= is_flags
;
1599 * Handles the SHT_SUNW_{DEBUG,DEBUGSTR) sections.
1602 process_debug(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
1603 Word ndx
, int ident
, Ofl_desc
*ofl
)
1606 * Debug information is discarded when the 'ld -s' flag is invoked.
1608 if (ofl
->ofl_flags
& FLG_OF_STRIP
) {
1611 return (process_progbits(name
, ifl
, shdr
, scn
, ndx
, ident
, ofl
));
1615 * Process a nobits section.
1618 process_nobits(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
1619 Word ndx
, int ident
, Ofl_desc
*ofl
)
1622 if (shdr
->sh_flags
& SHF_TLS
)
1623 ident
= ld_targ
.t_id
.id_tlsbss
;
1625 else if ((shdr
->sh_flags
& SHF_AMD64_LARGE
) &&
1626 (ld_targ
.t_m
.m_mach
== EM_AMD64
))
1627 ident
= ld_targ
.t_id
.id_lbss
;
1630 ident
= ld_targ
.t_id
.id_bss
;
1632 return (process_section(name
, ifl
, shdr
, scn
, ndx
, ident
, ofl
));
1636 * Process a SHT_*_ARRAY section.
1639 process_array(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
1640 Word ndx
, int ident
, Ofl_desc
*ofl
)
1645 ident
= ld_targ
.t_id
.id_array
;
1647 error
= process_section(name
, ifl
, shdr
, scn
, ndx
, ident
, ofl
);
1648 if ((error
== 0) || (error
== S_ERROR
))
1656 array_process(Is_desc
*isc
, Ifl_desc
*ifl
, Ofl_desc
*ofl
)
1661 if ((isc
== NULL
) || ((osp
= isc
->is_osdesc
) == NULL
))
1664 shdr
= isc
->is_shdr
;
1666 if ((shdr
->sh_type
== SHT_FINI_ARRAY
) &&
1667 (ofl
->ofl_osfiniarray
== NULL
))
1668 ofl
->ofl_osfiniarray
= osp
;
1669 else if ((shdr
->sh_type
== SHT_INIT_ARRAY
) &&
1670 (ofl
->ofl_osinitarray
== NULL
))
1671 ofl
->ofl_osinitarray
= osp
;
1672 else if ((shdr
->sh_type
== SHT_PREINIT_ARRAY
) &&
1673 (ofl
->ofl_ospreinitarray
== NULL
))
1674 ofl
->ofl_ospreinitarray
= osp
;
1680 * Process a SHT_SYMTAB_SHNDX section.
1683 process_sym_shndx(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
1684 Word ndx
, int ident
, Ofl_desc
*ofl
)
1686 if (process_input(name
, ifl
, shdr
, scn
, ndx
, ident
, ofl
) == S_ERROR
)
1690 * Have we already seen the related SYMTAB - if so verify it now.
1692 if (shdr
->sh_link
< ndx
) {
1693 Is_desc
*isp
= ifl
->ifl_isdesc
[shdr
->sh_link
];
1695 if ((isp
== NULL
) || ((isp
->is_shdr
->sh_type
!= SHT_SYMTAB
) &&
1696 (isp
->is_shdr
->sh_type
!= SHT_DYNSYM
))) {
1697 ld_eprintf(ofl
, ERR_FATAL
,
1698 MSG_INTL(MSG_FIL_INVSHLINK
), ifl
->ifl_name
,
1699 EC_WORD(ndx
), name
, EC_XWORD(shdr
->sh_link
));
1702 isp
->is_symshndx
= ifl
->ifl_isdesc
[ndx
];
1708 * Final processing for SHT_SYMTAB_SHNDX section.
1712 sym_shndx_process(Is_desc
*isc
, Ifl_desc
*ifl
, Ofl_desc
*ofl
)
1714 if (isc
->is_shdr
->sh_link
> isc
->is_scnndx
) {
1715 Is_desc
*isp
= ifl
->ifl_isdesc
[isc
->is_shdr
->sh_link
];
1717 if ((isp
== NULL
) || ((isp
->is_shdr
->sh_type
!= SHT_SYMTAB
) &&
1718 (isp
->is_shdr
->sh_type
!= SHT_DYNSYM
))) {
1719 ld_eprintf(ofl
, ERR_FATAL
,
1720 MSG_INTL(MSG_FIL_INVSHLINK
), isc
->is_file
->ifl_name
,
1721 EC_WORD(isc
->is_scnndx
), isc
->is_name
,
1722 EC_XWORD(isc
->is_shdr
->sh_link
));
1725 isp
->is_symshndx
= isc
;
1731 * Process .dynamic section from a relocatable object.
1733 * Note: That the .dynamic section is only considered interesting when
1734 * dlopen()ing a relocatable object (thus FLG_OF1_RELDYN can only get
1735 * set when libld is called from ld.so.1).
1739 process_rel_dynamic(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
1740 Word ndx
, int ident
, Ofl_desc
*ofl
)
1748 * Process .dynamic sections from relocatable objects ?
1750 if ((ofl
->ofl_flags1
& FLG_OF1_RELDYN
) == 0)
1754 * Find the string section associated with the .dynamic section.
1756 if ((strscn
= elf_getscn(ifl
->ifl_elf
, shdr
->sh_link
)) == NULL
) {
1757 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_GETSCN
),
1761 dp
= elf_getdata(strscn
, NULL
);
1762 str
= (char *)dp
->d_buf
;
1765 * And get the .dynamic data
1767 dp
= elf_getdata(scn
, NULL
);
1769 for (dyn
= (Dyn
*)dp
->d_buf
; dyn
->d_tag
!= DT_NULL
; dyn
++) {
1772 switch (dyn
->d_tag
) {
1775 if (((difl
= libld_calloc(1,
1776 sizeof (Ifl_desc
))) == NULL
) ||
1777 (aplist_append(&ofl
->ofl_sos
, difl
,
1778 AL_CNT_OFL_LIBS
) == NULL
))
1781 difl
->ifl_name
= MSG_ORIG(MSG_STR_DYNAMIC
);
1782 difl
->ifl_soname
= str
+ (size_t)dyn
->d_un
.d_val
;
1783 difl
->ifl_flags
= FLG_IF_NEEDSTR
;
1787 if ((ofl
->ofl_rpath
= add_string(ofl
->ofl_rpath
,
1788 (str
+ (size_t)dyn
->d_un
.d_val
))) ==
1789 (const char *)S_ERROR
)
1794 * The Solaris ld does not put DT_VERSYM in the
1795 * dynamic section. If the object has DT_VERSYM,
1796 * then it must have been produced by the GNU ld,
1797 * and is using the GNU style of versioning.
1799 ifl
->ifl_flags
|= FLG_IF_GNUVER
;
1807 * Expand implicit references. Dependencies can be specified in terms of the
1808 * $ORIGIN, $MACHINE, $PLATFORM, $OSREL and $OSNAME tokens, either from their
1809 * needed name, or via a runpath. In addition runpaths may also specify the
1812 * Probably the most common reference to explicit dependencies (via -L) will be
1813 * sufficient to find any associated implicit dependencies, but just in case we
1814 * expand any occurrence of these known tokens here.
1816 * Note, if any errors occur we simply return the original name.
1818 * This code is remarkably similar to expand() in rtld/common/paths.c.
1820 static char *machine
= NULL
;
1821 static size_t machine_sz
= 0;
1822 static char *platform
= NULL
;
1823 static size_t platform_sz
= 0;
1824 static Isa_desc
*isa
= NULL
;
1825 static Uts_desc
*uts
= NULL
;
1828 expand(const char *parent
, const char *name
, char **next
)
1830 char _name
[PATH_MAX
], *nptr
, *_next
;
1832 size_t nrem
= PATH_MAX
- 1;
1833 int expanded
= 0, _expanded
, isaflag
= 0;
1840 return ((char *)name
);
1843 *nptr
++ = *optr
++, nrem
--;
1849 if (strncmp(optr
, MSG_ORIG(MSG_STR_ORIGIN
),
1850 MSG_STR_ORIGIN_SIZE
) == 0) {
1854 * For $ORIGIN, expansion is really just a concatenation
1855 * of the parents directory name. For example, an
1856 * explicit dependency foo/bar/lib1.so with a dependency
1857 * on $ORIGIN/lib2.so would be expanded to
1860 if ((eptr
= strrchr(parent
, '/')) == NULL
) {
1864 size_t len
= eptr
- parent
;
1867 return ((char *)name
);
1869 (void) strncpy(nptr
, parent
, len
);
1873 optr
+= MSG_STR_ORIGIN_SIZE
;
1874 expanded
= _expanded
= 1;
1876 } else if (strncmp(optr
, MSG_ORIG(MSG_STR_MACHINE
),
1877 MSG_STR_MACHINE_SIZE
) == 0) {
1879 * Establish the machine from sysconf - like uname -i.
1881 if ((machine
== NULL
) && (machine_sz
== 0)) {
1882 char info
[SYS_NMLN
];
1885 size
= sysinfo(SI_MACHINE
, info
, SYS_NMLN
);
1887 (machine
= libld_malloc((size_t)size
))) {
1888 (void) strcpy(machine
, info
);
1889 machine_sz
= (size_t)size
- 1;
1894 if (machine_sz
>= nrem
)
1895 return ((char *)name
);
1897 (void) strncpy(nptr
, machine
, machine_sz
);
1898 nptr
= nptr
+ machine_sz
;
1901 optr
+= MSG_STR_MACHINE_SIZE
;
1902 expanded
= _expanded
= 1;
1905 } else if (strncmp(optr
, MSG_ORIG(MSG_STR_PLATFORM
),
1906 MSG_STR_PLATFORM_SIZE
) == 0) {
1908 * Establish the platform from sysconf - like uname -i.
1910 if ((platform
== NULL
) && (platform_sz
== 0)) {
1911 char info
[SYS_NMLN
];
1914 size
= sysinfo(SI_PLATFORM
, info
, SYS_NMLN
);
1916 (platform
= libld_malloc((size_t)size
))) {
1917 (void) strcpy(platform
, info
);
1918 platform_sz
= (size_t)size
- 1;
1923 if (platform_sz
>= nrem
)
1924 return ((char *)name
);
1926 (void) strncpy(nptr
, platform
, platform_sz
);
1927 nptr
= nptr
+ platform_sz
;
1928 nrem
-= platform_sz
;
1930 optr
+= MSG_STR_PLATFORM_SIZE
;
1931 expanded
= _expanded
= 1;
1934 } else if (strncmp(optr
, MSG_ORIG(MSG_STR_OSNAME
),
1935 MSG_STR_OSNAME_SIZE
) == 0) {
1937 * Establish the os name - like uname -s.
1942 if (uts
&& uts
->uts_osnamesz
) {
1943 if (uts
->uts_osnamesz
>= nrem
)
1944 return ((char *)name
);
1946 (void) strncpy(nptr
, uts
->uts_osname
,
1948 nptr
= nptr
+ uts
->uts_osnamesz
;
1949 nrem
-= uts
->uts_osnamesz
;
1951 optr
+= MSG_STR_OSNAME_SIZE
;
1952 expanded
= _expanded
= 1;
1955 } else if (strncmp(optr
, MSG_ORIG(MSG_STR_OSREL
),
1956 MSG_STR_OSREL_SIZE
) == 0) {
1958 * Establish the os release - like uname -r.
1963 if (uts
&& uts
->uts_osrelsz
) {
1964 if (uts
->uts_osrelsz
>= nrem
)
1965 return ((char *)name
);
1967 (void) strncpy(nptr
, uts
->uts_osrel
,
1969 nptr
= nptr
+ uts
->uts_osrelsz
;
1970 nrem
-= uts
->uts_osrelsz
;
1972 optr
+= MSG_STR_OSREL_SIZE
;
1973 expanded
= _expanded
= 1;
1976 } else if ((strncmp(optr
, MSG_ORIG(MSG_STR_ISALIST
),
1977 MSG_STR_ISALIST_SIZE
) == 0) && next
&& (isaflag
++ == 0)) {
1979 * Establish instruction sets from sysconf. Note that
1980 * this is only meaningful from runpaths.
1983 isa
= conv_isalist();
1985 if (isa
&& isa
->isa_listsz
&&
1986 (nrem
> isa
->isa_opt
->isa_namesz
)) {
1987 size_t mlen
, tlen
, hlen
= optr
- name
;
1990 Isa_opt
*opt
= isa
->isa_opt
;
1992 (void) strncpy(nptr
, opt
->isa_name
,
1994 nptr
= nptr
+ opt
->isa_namesz
;
1995 nrem
-= opt
->isa_namesz
;
1997 optr
+= MSG_STR_ISALIST_SIZE
;
1998 expanded
= _expanded
= 1;
2000 tlen
= strlen(optr
);
2003 * As ISALIST expands to a number of elements,
2004 * establish a new list to return to the caller.
2005 * This will contain the present path being
2006 * processed redefined for each isalist option,
2007 * plus the original remaining list entries.
2009 mlen
= ((hlen
+ tlen
) * (isa
->isa_optno
- 1)) +
2010 isa
->isa_listsz
- opt
->isa_namesz
;
2012 mlen
+= strlen(*next
);
2013 if ((_next
= lptr
= libld_malloc(mlen
)) == NULL
)
2016 for (no
= 1, opt
++; no
< isa
->isa_optno
;
2018 (void) strncpy(lptr
, name
, hlen
);
2020 (void) strncpy(lptr
, opt
->isa_name
,
2022 lptr
= lptr
+ opt
->isa_namesz
;
2023 (void) strncpy(lptr
, optr
, tlen
);
2028 (void) strcpy(lptr
, *next
);
2035 * If no expansion occurred skip the $ and continue.
2038 *nptr
++ = *optr
++, nrem
--;
2042 * If any ISALIST processing has occurred not only do we return the
2043 * expanded node we're presently working on, but we must also update the
2044 * remaining list so that it is effectively prepended with this node
2045 * expanded to all remaining isalist options. Note that we can only
2046 * handle one ISALIST per node. For more than one ISALIST to be
2047 * processed we'd need a better algorithm than above to replace the
2048 * newly generated list. Whether we want to encourage the number of
2049 * pathname permutations this would provide is another question. So, for
2050 * now if more than one ISALIST is encountered we return the original
2057 return ((char *)name
);
2063 if ((nptr
= libld_malloc(strlen(_name
) + 1)) == NULL
)
2064 return ((char *)name
);
2065 (void) strcpy(nptr
, _name
);
2068 return ((char *)name
);
2072 * The Solaris ld does not put DT_VERSYM in the dynamic section, but the
2073 * GNU ld does, and it is used by the runtime linker to implement their
2074 * versioning scheme. Use this fact to determine if the sharable object
2075 * was produced by the GNU ld rather than the Solaris one, and to set
2076 * FLG_IF_GNUVER if so. This needs to be done before the symbols are
2077 * processed, since the answer determines whether we interpret the
2078 * symbols versions according to Solaris or GNU rules.
2082 process_dynamic_isgnu(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
,
2083 Elf_Scn
*scn
, Word ndx
, int ident
, Ofl_desc
*ofl
)
2089 error
= process_section(name
, ifl
, shdr
, scn
, ndx
, ident
, ofl
);
2090 if ((error
== 0) || (error
== S_ERROR
))
2093 /* Get the .dynamic data */
2094 dp
= elf_getdata(scn
, NULL
);
2096 for (dyn
= (Dyn
*)dp
->d_buf
; dyn
->d_tag
!= DT_NULL
; dyn
++) {
2097 if (dyn
->d_tag
== DT_VERSYM
) {
2098 ifl
->ifl_flags
|= FLG_IF_GNUVER
;
2106 * Process a dynamic section. If we are processing an explicit shared object
2107 * then we need to determine if it has a recorded SONAME, if so, this name will
2108 * be recorded in the output file being generated as the NEEDED entry rather
2109 * than the shared objects filename itself.
2110 * If the mode of the link-edit indicates that no undefined symbols should
2111 * remain, then we also need to build up a list of any additional shared object
2112 * dependencies this object may have. In this case save any NEEDED entries
2113 * together with any associated run-path specifications. This information is
2114 * recorded on the `ofl_soneed' list and will be analyzed after all explicit
2115 * file processing has been completed (refer finish_libs()).
2118 process_dynamic(Is_desc
*isc
, Ifl_desc
*ifl
, Ofl_desc
*ofl
)
2121 char *str
, *rpath
= NULL
;
2122 const char *soname
, *needed
;
2125 data
= (Dyn
*)isc
->is_indata
->d_buf
;
2126 str
= (char *)ifl
->ifl_isdesc
[isc
->is_shdr
->sh_link
]->is_indata
->d_buf
;
2128 /* Determine if we need to examine the runpaths and NEEDED entries */
2129 no_undef
= (ofl
->ofl_flags
& (FLG_OF_NOUNDEF
| FLG_OF_SYMBOLIC
)) ||
2130 OFL_GUIDANCE(ofl
, FLG_OFG_NO_DEFS
);
2133 * First loop through the dynamic section looking for a run path.
2136 for (dyn
= data
; dyn
->d_tag
!= DT_NULL
; dyn
++) {
2137 if ((dyn
->d_tag
!= DT_RPATH
) &&
2138 (dyn
->d_tag
!= DT_RUNPATH
))
2140 if ((rpath
= str
+ (size_t)dyn
->d_un
.d_val
) == NULL
)
2147 * Now look for any needed dependencies (which may use the rpath)
2150 for (dyn
= data
; dyn
->d_tag
!= DT_NULL
; dyn
++) {
2151 if (dyn
->d_tag
== DT_SONAME
) {
2152 if ((soname
= str
+ (size_t)dyn
->d_un
.d_val
) == NULL
)
2156 * Update the input file structure with this new name.
2158 ifl
->ifl_soname
= soname
;
2160 } else if ((dyn
->d_tag
== DT_NEEDED
) ||
2161 (dyn
->d_tag
== DT_USED
)) {
2166 if ((needed
= str
+ (size_t)dyn
->d_un
.d_val
) == NULL
)
2170 * Determine if this needed entry is already recorded on
2171 * the shared object needed list, if not create a new
2172 * definition for later processing (see finish_libs()).
2174 needed
= expand(ifl
->ifl_name
, needed
, NULL
);
2176 if ((sdf
= sdf_find(needed
, ofl
->ofl_soneed
)) == NULL
) {
2177 if ((sdf
= sdf_add(needed
,
2178 &ofl
->ofl_soneed
)) == (Sdf_desc
*)S_ERROR
)
2180 sdf
->sdf_rfile
= ifl
->ifl_name
;
2184 * Record the runpath (Note that we take the first
2185 * runpath which is exactly what ld.so.1 would do during
2186 * its dependency processing).
2188 if (rpath
&& (sdf
->sdf_rpath
== NULL
))
2189 sdf
->sdf_rpath
= rpath
;
2191 } else if (dyn
->d_tag
== DT_FLAGS_1
) {
2192 if (dyn
->d_un
.d_val
& (DF_1_INITFIRST
| DF_1_INTERPOSE
))
2193 ifl
->ifl_flags
&= ~FLG_IF_LAZYLD
;
2194 if (dyn
->d_un
.d_val
& DF_1_DISPRELPND
)
2195 ifl
->ifl_flags
|= FLG_IF_DISPPEND
;
2196 if (dyn
->d_un
.d_val
& DF_1_DISPRELDNE
)
2197 ifl
->ifl_flags
|= FLG_IF_DISPDONE
;
2198 if (dyn
->d_un
.d_val
& DF_1_NODIRECT
)
2199 ifl
->ifl_flags
|= FLG_IF_NODIRECT
;
2202 * If we are building an executable, and this
2203 * dependency is tagged as an interposer, then
2204 * assume that it is required even if symbol
2205 * resolution uncovers no evident use.
2207 * If we are building a shared object, then an
2208 * interposer dependency has no special meaning, and we
2209 * treat it as a regular dependency. By definition, all
2210 * interposers must be visible to the runtime linker
2211 * at initialization time, and cannot be added later.
2213 if ((dyn
->d_un
.d_val
& DF_1_INTERPOSE
) &&
2214 (ofl
->ofl_flags
& (FLG_OF_EXEC
| FLG_OF_PIE
)))
2215 ifl
->ifl_flags
|= FLG_IF_DEPREQD
;
2217 } else if ((dyn
->d_tag
== DT_AUDIT
) &&
2218 (ifl
->ifl_flags
& FLG_IF_NEEDED
)) {
2220 * Record audit string as DT_DEPAUDIT.
2222 if ((ofl
->ofl_depaudit
= add_string(ofl
->ofl_depaudit
,
2223 (str
+ (size_t)dyn
->d_un
.d_val
))) ==
2224 (const char *)S_ERROR
)
2227 } else if (dyn
->d_tag
== DT_SUNW_RTLDINF
) {
2229 * If this dependency has the DT_SUNW_RTLDINF .dynamic
2230 * entry, then ensure no specialized dependency
2231 * processing is in effect. This tag identifies libc,
2232 * which provides critical startup information (TLS
2233 * routines, threads initialization, etc.) that must
2234 * be exercised as part of process initialization.
2236 ifl
->ifl_flags
&= ~MSK_IF_POSFLAG1
;
2239 * libc is not subject to the usual guidance checks
2240 * for lazy loading. It cannot be lazy loaded, libld
2241 * ignores the request, and rtld would ignore the
2242 * setting if it were present.
2244 ifl
->ifl_flags
|= FLG_IF_RTLDINF
;
2249 * Perform some SONAME sanity checks.
2251 if (ifl
->ifl_flags
& FLG_IF_NEEDED
) {
2256 * Determine if anyone else will cause the same SONAME to be
2257 * used (this is either caused by two different files having the
2258 * same SONAME, or by one file SONAME actually matching another
2259 * file basename (if no SONAME is specified within a shared
2260 * library its basename will be used)). Probably rare, but some
2263 for (APLIST_TRAVERSE(ofl
->ofl_sos
, idx
, sifl
)) {
2264 if ((strcmp(ifl
->ifl_soname
, sifl
->ifl_soname
) == 0) &&
2266 const char *hint
, *iflb
, *siflb
;
2269 * Determine the basename of each file. Perhaps
2270 * there are multiple copies of the same file
2271 * being brought in using different -L search
2272 * paths, and if so give an extra hint in the
2275 iflb
= strrchr(ifl
->ifl_name
, '/');
2277 iflb
= ifl
->ifl_name
;
2281 siflb
= strrchr(sifl
->ifl_name
, '/');
2283 siflb
= sifl
->ifl_name
;
2287 if (strcmp(iflb
, siflb
) == 0)
2288 hint
= MSG_INTL(MSG_REC_CNFLTHINT
);
2290 hint
= MSG_ORIG(MSG_STR_EMPTY
);
2292 ld_eprintf(ofl
, ERR_FATAL
,
2293 MSG_INTL(MSG_REC_OBJCNFLT
), sifl
->ifl_name
,
2294 ifl
->ifl_name
, sifl
->ifl_soname
, hint
);
2300 * If the SONAME is the same as the name the user wishes to
2301 * record when building a dynamic library (refer -h option),
2302 * we also have a name clash.
2304 if (ofl
->ofl_soname
&&
2305 (strcmp(ofl
->ofl_soname
, ifl
->ifl_soname
) == 0)) {
2306 ld_eprintf(ofl
, ERR_FATAL
,
2307 MSG_INTL(MSG_REC_OPTCNFLT
), ifl
->ifl_name
,
2308 MSG_INTL(MSG_MARG_SONAME
), ifl
->ifl_soname
);
2316 * Process a progbits section from a relocatable object (ET_REL).
2317 * This is used on non-amd64 objects to recognize .eh_frame sections.
2321 process_progbits_final(Is_desc
*isc
, Ifl_desc
*ifl
, Ofl_desc
*ofl
)
2323 if (isc
->is_osdesc
&& (isc
->is_flags
& FLG_IS_EHFRAME
) &&
2324 (ld_unwind_register(isc
->is_osdesc
, ofl
) == S_ERROR
))
2331 * Process a group section.
2334 process_group(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
2335 Word ndx
, int ident
, Ofl_desc
*ofl
)
2339 error
= process_section(name
, ifl
, shdr
, scn
, ndx
, ident
, ofl
);
2340 if ((error
== 0) || (error
== S_ERROR
))
2344 * Indicate that this input file has groups to process. Groups are
2345 * processed after all input sections have been processed.
2347 ifl
->ifl_flags
|= FLG_IF_GROUPS
;
2353 * Process a relocation entry. At this point all input sections from this
2354 * input file have been assigned an input section descriptor which is saved
2355 * in the `ifl_isdesc' array.
2358 rel_process(Is_desc
*isc
, Ifl_desc
*ifl
, Ofl_desc
*ofl
)
2363 Shdr
*shdr
= isc
->is_shdr
;
2364 Conv_inv_buf_t inv_buf
;
2367 * Make sure this is a valid relocation we can handle.
2369 if (shdr
->sh_type
!= ld_targ
.t_m
.m_rel_sht_type
) {
2370 ld_eprintf(ofl
, ERR_FATAL
, MSG_INTL(MSG_FIL_INVALSEC
),
2371 ifl
->ifl_name
, EC_WORD(isc
->is_scnndx
), isc
->is_name
,
2372 conv_sec_type(ifl
->ifl_ehdr
->e_ident
[EI_OSABI
],
2373 ifl
->ifl_ehdr
->e_machine
, shdr
->sh_type
, 0, &inv_buf
));
2378 * From the relocation section header information determine which
2379 * section needs the actual relocation. Determine which output section
2380 * this input section has been assigned to and add to its relocation
2381 * list. Note that the relocation section may be null if it is not
2382 * required (ie. .debug, .stabs, etc).
2384 rndx
= shdr
->sh_info
;
2385 if (rndx
>= ifl
->ifl_shnum
) {
2387 * Broken input file.
2389 ld_eprintf(ofl
, ERR_FATAL
, MSG_INTL(MSG_FIL_INVSHINFO
),
2390 ifl
->ifl_name
, EC_WORD(isc
->is_scnndx
), isc
->is_name
,
2395 if (aplist_append(&ofl
->ofl_extrarels
, isc
,
2396 AL_CNT_OFL_RELS
) == NULL
)
2399 } else if ((risc
= ifl
->ifl_isdesc
[rndx
]) != NULL
) {
2401 * Discard relocations if they are against a section
2402 * which has been discarded.
2404 if (risc
->is_flags
& FLG_IS_DISCARD
)
2407 if ((osp
= risc
->is_osdesc
) == NULL
) {
2408 if (risc
->is_shdr
->sh_type
== SHT_SUNW_move
) {
2410 * This section is processed later in
2411 * process_movereloc().
2413 if (aplist_append(&ofl
->ofl_ismoverel
,
2414 isc
, AL_CNT_OFL_MOVE
) == NULL
)
2418 ld_eprintf(ofl
, ERR_FATAL
,
2419 MSG_INTL(MSG_FIL_INVRELOC1
), ifl
->ifl_name
,
2420 EC_WORD(isc
->is_scnndx
), isc
->is_name
,
2421 EC_WORD(risc
->is_scnndx
), risc
->is_name
);
2424 if (aplist_append(&osp
->os_relisdescs
, isc
,
2425 AL_CNT_OS_RELISDESCS
) == NULL
)
2432 * SHF_EXCLUDE flags is set for this section.
2435 process_exclude(const char *name
, Ifl_desc
*ifl
, Shdr
*shdr
, Elf_Scn
*scn
,
2436 Word ndx
, Ofl_desc
*ofl
)
2439 * Sections SHT_SYMTAB and SHT_DYNDYM, even if SHF_EXCLUDE is on, might
2440 * be needed for ld processing. These sections need to be in the
2441 * internal table. Later it will be determined whether they can be
2442 * eliminated or not.
2444 if (shdr
->sh_type
== SHT_SYMTAB
|| shdr
->sh_type
== SHT_DYNSYM
)
2450 if (shdr
->sh_flags
& SHF_ALLOC
) {
2452 * A conflict, issue an warning message, and ignore the section.
2454 ld_eprintf(ofl
, ERR_WARNING
, MSG_INTL(MSG_FIL_EXCLUDE
),
2455 ifl
->ifl_name
, EC_WORD(ndx
), name
);
2460 * This sections is not going to the output file.
2462 return (process_section(name
, ifl
, shdr
, scn
, ndx
, 0, ofl
));
2466 * Section processing state table. `Initial' describes the required initial
2467 * procedure to be called (if any), `Final' describes the final processing
2468 * procedure (ie. things that can only be done when all required sections
2469 * have been collected).
2471 typedef uintptr_t (* initial_func_t
)(const char *, Ifl_desc
*, Shdr
*,
2472 Elf_Scn
*, Word
, int, Ofl_desc
*);
2474 static initial_func_t Initial
[SHT_NUM
][2] = {
2477 /* SHT_NULL */ invalid_section
, invalid_section
,
2478 /* SHT_PROGBITS */ process_progbits
, process_progbits
,
2479 /* SHT_SYMTAB */ process_input
, process_input
,
2480 /* SHT_STRTAB */ process_strtab
, process_strtab
,
2481 /* SHT_RELA */ process_reloc
, process_reloc
,
2482 /* SHT_HASH */ invalid_section
, NULL
,
2483 /* SHT_DYNAMIC */ process_rel_dynamic
, process_dynamic_isgnu
,
2484 /* SHT_NOTE */ process_section
, NULL
,
2485 /* SHT_NOBITS */ process_nobits
, process_nobits
,
2486 /* SHT_REL */ process_reloc
, process_reloc
,
2487 /* SHT_SHLIB */ process_section
, invalid_section
,
2488 /* SHT_DYNSYM */ invalid_section
, process_input
,
2489 /* SHT_UNKNOWN12 */ process_progbits
, process_progbits
,
2490 /* SHT_UNKNOWN13 */ process_progbits
, process_progbits
,
2491 /* SHT_INIT_ARRAY */ process_array
, NULL
,
2492 /* SHT_FINI_ARRAY */ process_array
, NULL
,
2493 /* SHT_PREINIT_ARRAY */ process_array
, NULL
,
2494 /* SHT_GROUP */ process_group
, invalid_section
,
2495 /* SHT_SYMTAB_SHNDX */ process_sym_shndx
, NULL
2498 typedef uintptr_t (* final_func_t
)(Is_desc
*, Ifl_desc
*, Ofl_desc
*);
2500 static final_func_t Final
[SHT_NUM
][2] = {
2503 /* SHT_NULL */ NULL
, NULL
,
2504 /* SHT_PROGBITS */ process_progbits_final
, NULL
,
2505 /* SHT_SYMTAB */ ld_sym_process
, ld_sym_process
,
2506 /* SHT_STRTAB */ NULL
, NULL
,
2507 /* SHT_RELA */ rel_process
, NULL
,
2508 /* SHT_HASH */ NULL
, NULL
,
2509 /* SHT_DYNAMIC */ NULL
, process_dynamic
,
2510 /* SHT_NOTE */ NULL
, NULL
,
2511 /* SHT_NOBITS */ NULL
, NULL
,
2512 /* SHT_REL */ rel_process
, NULL
,
2513 /* SHT_SHLIB */ NULL
, NULL
,
2514 /* SHT_DYNSYM */ NULL
, ld_sym_process
,
2515 /* SHT_UNKNOWN12 */ NULL
, NULL
,
2516 /* SHT_UNKNOWN13 */ NULL
, NULL
,
2517 /* SHT_INIT_ARRAY */ array_process
, NULL
,
2518 /* SHT_FINI_ARRAY */ array_process
, NULL
,
2519 /* SHT_PREINIT_ARRAY */ array_process
, NULL
,
2520 /* SHT_GROUP */ NULL
, NULL
,
2521 /* SHT_SYMTAB_SHNDX */ sym_shndx_process
, NULL
2524 #define MAXNDXSIZE 10
2527 * Process an elf file. Each section is compared against the section state
2528 * table to determine whether it should be processed (saved), ignored, or
2529 * is invalid for the type of input file being processed.
2532 process_elf(Ifl_desc
*ifl
, Elf
*elf
, Ofl_desc
*ofl
)
2536 Word ndx
, sndx
, ordndx
= 0, ordcnt
= 0;
2541 Is_desc
*vdfisp
, *vndisp
, *vsyisp
, *sifisp
;
2542 Is_desc
*capinfoisp
, *capisp
;
2544 Place_path_info path_info_buf
, *path_info
;
2547 * Path information buffer used by ld_place_section() and related
2548 * routines. This information is used to evaluate entrance criteria
2549 * with non-empty file matching lists (ec_files).
2551 path_info
= ld_place_path_info_init(ofl
, ifl
, &path_info_buf
);
2554 * First process the .shstrtab section so that later sections can
2555 * reference their name.
2557 ld_sup_file(ofl
, ifl
->ifl_name
, elf_kind(elf
), ifl
->ifl_flags
, elf
);
2559 sndx
= ifl
->ifl_shstrndx
;
2560 if ((scn
= elf_getscn(elf
, (size_t)sndx
)) == NULL
) {
2561 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_GETSCN
),
2565 if ((shdr
= elf_getshdr(scn
)) == NULL
) {
2566 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_GETSHDR
),
2570 if ((name
= elf_strptr(elf
, (size_t)sndx
, (size_t)shdr
->sh_name
)) ==
2572 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_STRPTR
),
2577 if (ld_sup_input_section(ofl
, ifl
, name
, &shdr
, sndx
, scn
,
2582 * Reset the name since the shdr->sh_name could have been changed as
2583 * part of ld_sup_input_section().
2585 if ((name
= elf_strptr(elf
, (size_t)sndx
, (size_t)shdr
->sh_name
)) ==
2587 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_STRPTR
),
2592 error
= process_strtab(name
, ifl
, shdr
, scn
, sndx
, FALSE
, ofl
);
2593 if ((error
== 0) || (error
== S_ERROR
))
2595 str
= ifl
->ifl_isdesc
[sndx
]->is_indata
->d_buf
;
2598 * Determine the state table column from the input file type. Note,
2599 * shared library sections are not added to the output section list.
2601 if (ifl
->ifl_ehdr
->e_type
== ET_DYN
) {
2604 ident
= ld_targ
.t_id
.id_null
;
2608 ident
= ld_targ
.t_id
.id_unknown
;
2611 DBG_CALL(Dbg_file_generic(ofl
->ofl_lml
, ifl
));
2613 vdfisp
= vndisp
= vsyisp
= sifisp
= capinfoisp
= capisp
= NULL
;
2615 while (scn
= elf_nextscn(elf
, scn
)) {
2619 * As we've already processed the .shstrtab don't do it again.
2624 if ((shdr
= elf_getshdr(scn
)) == NULL
) {
2625 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_GETSHDR
),
2629 name
= str
+ (size_t)(shdr
->sh_name
);
2631 if (ld_sup_input_section(ofl
, ifl
, name
, &shdr
, ndx
, scn
,
2636 * Reset the name since the shdr->sh_name could have been
2637 * changed as part of ld_sup_input_section().
2639 name
= str
+ (size_t)(shdr
->sh_name
);
2641 row
= shdr
->sh_type
;
2644 * If the section has the SHF_EXCLUDE flag on, and we're not
2645 * generating a relocatable object, exclude the section.
2647 if (((shdr
->sh_flags
& SHF_EXCLUDE
) != 0) &&
2648 ((ofl
->ofl_flags
& FLG_OF_RELOBJ
) == 0)) {
2649 if ((error
= process_exclude(name
, ifl
, shdr
, scn
,
2650 ndx
, ofl
)) == S_ERROR
)
2657 * If this is a standard section type process it via the
2658 * appropriate action routine.
2660 if (row
< SHT_NUM
) {
2661 if (Initial
[row
][column
] != NULL
) {
2662 if (Initial
[row
][column
](name
, ifl
, shdr
, scn
,
2663 ndx
, ident
, ofl
) == S_ERROR
)
2668 * If this section is below SHT_LOSUNW then we don't
2669 * really know what to do with it, issue a warning
2670 * message but do the basic section processing anyway.
2672 if (row
< (Word
)SHT_LOSUNW
) {
2673 Conv_inv_buf_t inv_buf
;
2675 ld_eprintf(ofl
, ERR_WARNING
,
2676 MSG_INTL(MSG_FIL_INVALSEC
), ifl
->ifl_name
,
2677 EC_WORD(ndx
), name
, conv_sec_type(
2678 ifl
->ifl_ehdr
->e_ident
[EI_OSABI
],
2679 ifl
->ifl_ehdr
->e_machine
,
2680 shdr
->sh_type
, 0, &inv_buf
));
2684 * Handle sections greater than SHT_LOSUNW.
2688 if (process_section(name
, ifl
, shdr
, scn
,
2689 ndx
, ident
, ofl
) == S_ERROR
)
2693 if (process_section(name
, ifl
, shdr
, scn
, ndx
,
2694 ld_targ
.t_id
.id_null
, ofl
) == S_ERROR
)
2696 capisp
= ifl
->ifl_isdesc
[ndx
];
2698 case SHT_SUNW_capinfo
:
2699 if (process_section(name
, ifl
, shdr
, scn
, ndx
,
2700 ld_targ
.t_id
.id_null
, ofl
) == S_ERROR
)
2702 capinfoisp
= ifl
->ifl_isdesc
[ndx
];
2704 case SHT_SUNW_DEBUGSTR
:
2705 case SHT_SUNW_DEBUG
:
2706 if (process_debug(name
, ifl
, shdr
, scn
,
2707 ndx
, ident
, ofl
) == S_ERROR
)
2711 if (process_section(name
, ifl
, shdr
, scn
, ndx
,
2712 ld_targ
.t_id
.id_null
, ofl
) == S_ERROR
)
2715 case SHT_SUNW_syminfo
:
2716 if (process_section(name
, ifl
, shdr
, scn
, ndx
,
2717 ld_targ
.t_id
.id_null
, ofl
) == S_ERROR
)
2719 sifisp
= ifl
->ifl_isdesc
[ndx
];
2721 case SHT_SUNW_ANNOTATE
:
2722 if (process_progbits(name
, ifl
, shdr
, scn
,
2723 ndx
, ident
, ofl
) == S_ERROR
)
2726 case SHT_SUNW_COMDAT
:
2727 if (process_progbits(name
, ifl
, shdr
, scn
,
2728 ndx
, ident
, ofl
) == S_ERROR
)
2730 ifl
->ifl_isdesc
[ndx
]->is_flags
|= FLG_IS_COMDAT
;
2732 case SHT_SUNW_verdef
:
2733 if (process_section(name
, ifl
, shdr
, scn
, ndx
,
2734 ld_targ
.t_id
.id_null
, ofl
) == S_ERROR
)
2736 vdfisp
= ifl
->ifl_isdesc
[ndx
];
2738 case SHT_SUNW_verneed
:
2739 if (process_section(name
, ifl
, shdr
, scn
, ndx
,
2740 ld_targ
.t_id
.id_null
, ofl
) == S_ERROR
)
2742 vndisp
= ifl
->ifl_isdesc
[ndx
];
2744 case SHT_SUNW_versym
:
2745 if (process_section(name
, ifl
, shdr
, scn
, ndx
,
2746 ld_targ
.t_id
.id_null
, ofl
) == S_ERROR
)
2748 vsyisp
= ifl
->ifl_isdesc
[ndx
];
2750 case SHT_SPARC_GOTDATA
:
2752 * SHT_SPARC_GOTDATA (0x70000000) is in the
2753 * SHT_LOPROC - SHT_HIPROC range reserved
2754 * for processor-specific semantics. It is
2755 * only meaningful for sparc targets.
2757 if (ld_targ
.t_m
.m_mach
!=
2758 LD_TARG_BYCLASS(EM_SPARC
, EM_SPARCV9
))
2760 if (process_section(name
, ifl
, shdr
, scn
, ndx
,
2761 ld_targ
.t_id
.id_gotdata
, ofl
) == S_ERROR
)
2765 case SHT_AMD64_UNWIND
:
2767 * SHT_AMD64_UNWIND (0x70000001) is in the
2768 * SHT_LOPROC - SHT_HIPROC range reserved
2769 * for processor-specific semantics. It is
2770 * only meaningful for amd64 targets.
2772 if (ld_targ
.t_m
.m_mach
!= EM_AMD64
)
2776 * Target is x86, so this really is
2783 if (process_section(name
, ifl
, shdr
,
2784 scn
, ndx
, ld_targ
.t_id
.id_unwind
,
2787 ifl
->ifl_isdesc
[ndx
]->is_flags
|=
2794 if (process_section(name
, ifl
, shdr
, scn
, ndx
,
2795 ((ident
== ld_targ
.t_id
.id_null
) ?
2796 ident
: ld_targ
.t_id
.id_user
), ofl
) ==
2805 * Now that all input sections have been analyzed, and prior to placing
2806 * any input sections to their output sections, process any groups.
2807 * Groups can contribute COMDAT items, which may get discarded as part
2808 * of placement. In addition, COMDAT names may require transformation
2809 * to indicate different output section placement.
2811 if (ifl
->ifl_flags
& FLG_IF_GROUPS
) {
2812 for (ndx
= 1; ndx
< ifl
->ifl_shnum
; ndx
++) {
2815 if (((isp
= ifl
->ifl_isdesc
[ndx
]) == NULL
) ||
2816 (isp
->is_shdr
->sh_type
!= SHT_GROUP
))
2819 if (ld_group_process(isp
, ofl
) == S_ERROR
)
2825 * Now group information has been processed, we can safely validate
2826 * that nothing is fishy about the section COMDAT description. We
2827 * need to do this prior to placing the section (where any
2828 * SHT_SUNW_COMDAT sections will be restored to being PROGBITS)
2830 ld_comdat_validate(ofl
, ifl
);
2833 * Now that all of the input sections have been processed, place
2834 * them in the appropriate output sections.
2836 for (ndx
= 1; ndx
< ifl
->ifl_shnum
; ndx
++) {
2839 if (((isp
= ifl
->ifl_isdesc
[ndx
]) == NULL
) ||
2840 ((isp
->is_flags
& FLG_IS_PLACE
) == 0))
2844 * Place all non-ordered sections within their appropriate
2847 if ((isp
->is_flags
& FLG_IS_ORDERED
) == 0) {
2848 if (ld_place_section(ofl
, isp
, path_info
,
2849 isp
->is_keyident
, NULL
) == (Os_desc
*)S_ERROR
)
2855 * Count the number of ordered sections and retain the first
2856 * ordered section index. This will be used to optimize the
2857 * ordered section loop that immediately follows this one.
2865 * Having placed all the non-ordered sections, it is now
2866 * safe to place SHF_ORDERED/SHF_LINK_ORDER sections.
2868 if (ifl
->ifl_flags
& FLG_IF_ORDERED
) {
2869 for (ndx
= ordndx
; ndx
< ifl
->ifl_shnum
; ndx
++) {
2872 if (((isp
= ifl
->ifl_isdesc
[ndx
]) == NULL
) ||
2874 (FLG_IS_PLACE
| FLG_IS_ORDERED
)) !=
2875 (FLG_IS_PLACE
| FLG_IS_ORDERED
)))
2878 /* ld_process_ordered() calls ld_place_section() */
2879 if (ld_process_ordered(ofl
, ifl
, path_info
, ndx
) ==
2883 /* If we've done them all, stop searching */
2890 * If this is a shared object explicitly specified on the command
2891 * line (as opposed to being a dependency of such an object),
2892 * determine if the user has specified a control definition. This
2893 * descriptor may specify which version definitions can be used
2894 * from this object. It may also update the dependency to USED and
2895 * supply an alternative SONAME.
2898 if (column
&& (ifl
->ifl_flags
& FLG_IF_NEEDED
)) {
2902 * Use the basename of the input file (typically this is the
2903 * compilation environment name, ie. libfoo.so).
2905 if ((base
= strrchr(ifl
->ifl_name
, '/')) == NULL
)
2906 base
= ifl
->ifl_name
;
2910 if ((sdf
= sdf_find(base
, ofl
->ofl_socntl
)) != NULL
) {
2911 sdf
->sdf_file
= ifl
;
2912 ifl
->ifl_sdfdesc
= sdf
;
2917 * Before symbol processing, process any capabilities. Capabilities
2918 * can reference a string table, which is why this processing is
2919 * carried out after the initial section processing. Capabilities,
2920 * together with -z symbolcap, can require the conversion of global
2921 * symbols to local symbols.
2923 if (capisp
&& (process_cap(ofl
, ifl
, capisp
) == S_ERROR
))
2927 * Process any version dependencies. These will establish shared object
2928 * `needed' entries in the same manner as will be generated from the
2929 * .dynamic's NEEDED entries.
2931 if (vndisp
&& ((ofl
->ofl_flags
& (FLG_OF_NOUNDEF
| FLG_OF_SYMBOLIC
)) ||
2932 OFL_GUIDANCE(ofl
, FLG_OFG_NO_DEFS
)))
2933 if (ld_vers_need_process(vndisp
, ifl
, ofl
) == S_ERROR
)
2937 * Before processing any symbol resolution or relocations process any
2941 (void) ld_vers_sym_process(ofl
, vsyisp
, ifl
);
2943 if (ifl
->ifl_versym
&&
2944 (vdfisp
|| (sdf
&& (sdf
->sdf_flags
& FLG_SDF_SELECT
))))
2945 if (ld_vers_def_process(vdfisp
, ifl
, ofl
) == S_ERROR
)
2949 * Having collected the appropriate sections carry out any additional
2950 * processing if necessary.
2952 for (ndx
= 0; ndx
< ifl
->ifl_shnum
; ndx
++) {
2955 if ((isp
= ifl
->ifl_isdesc
[ndx
]) == NULL
)
2957 row
= isp
->is_shdr
->sh_type
;
2959 if ((isp
->is_flags
& FLG_IS_DISCARD
) == 0)
2960 ld_sup_section(ofl
, isp
->is_name
, isp
->is_shdr
, ndx
,
2961 isp
->is_indata
, elf
);
2964 * If this is a SHT_SUNW_move section from a relocatable file,
2965 * keep track of the section for later processing.
2967 if ((row
== SHT_SUNW_move
) && (column
== 0)) {
2968 if (aplist_append(&(ofl
->ofl_ismove
), isp
,
2969 AL_CNT_OFL_MOVE
) == NULL
)
2974 * If this is a standard section type process it via the
2975 * appropriate action routine.
2977 if (row
< SHT_NUM
) {
2978 if (Final
[row
][column
] != NULL
) {
2979 if (Final
[row
][column
](isp
, ifl
,
2984 } else if ((row
== SHT_AMD64_UNWIND
) && (column
== 0)) {
2985 Os_desc
*osp
= isp
->is_osdesc
;
2988 * SHT_AMD64_UNWIND (0x70000001) is in the SHT_LOPROC -
2989 * SHT_HIPROC range reserved for processor-specific
2990 * semantics, and is only meaningful for amd64 targets.
2992 * Only process unwind contents from relocatable
2995 if (osp
&& (ld_targ
.t_m
.m_mach
== EM_AMD64
) &&
2996 (ld_unwind_register(osp
, ofl
) == S_ERROR
))
3003 * Following symbol processing, if this relocatable object input file
3004 * provides symbol capabilities, tag the associated symbols so that
3005 * the symbols can be re-assigned to the new capabilities symbol
3006 * section that will be created for the output file.
3008 if (capinfoisp
&& (ifl
->ifl_ehdr
->e_type
== ET_REL
) &&
3009 (process_capinfo(ofl
, ifl
, capinfoisp
) == S_ERROR
))
3013 * After processing any symbol resolution, and if this dependency
3014 * indicates it contains symbols that can't be directly bound to,
3015 * set the symbols appropriately.
3017 if (sifisp
&& ((ifl
->ifl_flags
& (FLG_IF_NEEDED
| FLG_IF_NODIRECT
)) ==
3018 (FLG_IF_NEEDED
| FLG_IF_NODIRECT
)))
3019 (void) ld_sym_nodirect(sifisp
, ifl
, ofl
);
3025 * Process the current input file. There are basically three types of files
3026 * that come through here:
3028 * - files explicitly defined on the command line (ie. foo.o or bar.so),
3029 * in this case only the `name' field is valid.
3031 * - libraries determined from the -l command line option (ie. -lbar),
3032 * in this case the `soname' field contains the basename of the located
3035 * Any shared object specified via the above two conventions must be recorded
3036 * as a needed dependency.
3038 * - libraries specified as dependencies of those libraries already obtained
3039 * via the command line (ie. bar.so has a DT_NEEDED entry of fred.so.1),
3040 * in this case the `soname' field contains either a full pathname (if the
3041 * needed entry contained a `/'), or the basename of the located file.
3042 * These libraries are processed to verify symbol binding but are not
3043 * recorded as dependencies of the output file being generated.
3047 * soname - SONAME for needed sharable library, as described above
3048 * fd - Open file descriptor
3049 * elf - Open ELF handle
3050 * flags - FLG_IF_ flags applicable to file
3051 * ofl - Output file descriptor
3052 * rej - Rejection descriptor used to record rejection reason
3053 * ifl_ret - NULL, or address of pointer to receive reference to
3054 * resulting input descriptor for file. If ifl_ret is non-NULL,
3055 * the file cannot be an archive or it will be rejected.
3058 * If a error occurs in examining the file, S_ERROR is returned.
3059 * If the file can be examined, but is not suitable, *rej is updated,
3060 * and 0 is returned. If the file is acceptable, 1 is returned, and if
3061 * ifl_ret is non-NULL, *ifl_ret is set to contain the pointer to the
3062 * resulting input descriptor.
3065 ld_process_ifl(const char *name
, const char *soname
, int fd
, Elf
*elf
,
3066 Word flags
, Ofl_desc
*ofl
, Rej_desc
*rej
, Ifl_desc
**ifl_ret
)
3070 uintptr_t error
= 0;
3076 * If this file was not extracted from an archive obtain its device
3077 * information. This will be used to determine if the file has already
3078 * been processed (rather than simply comparing filenames, the device
3079 * information provides a quicker comparison and detects linked files).
3081 if (fd
&& ((flags
& FLG_IF_EXTRACT
) == 0))
3082 (void) fstat(fd
, &status
);
3088 switch (elf_kind(elf
)) {
3091 * If the caller has supplied a non-NULL ifl_ret, then
3092 * we cannot process archives, for there will be no
3093 * input file descriptor for us to return. In this case,
3094 * reject the attempt.
3096 if (ifl_ret
!= NULL
) {
3097 _rej
.rej_type
= SGS_REJ_ARCHIVE
;
3098 _rej
.rej_name
= name
;
3099 DBG_CALL(Dbg_file_rejected(ofl
->ofl_lml
, &_rej
,
3100 ld_targ
.t_m
.m_mach
));
3101 if (rej
->rej_type
== 0) {
3103 rej
->rej_name
= strdup(_rej
.rej_name
);
3109 * Determine if we've already come across this archive file.
3111 if (!(flags
& FLG_IF_EXTRACT
)) {
3114 for (APLIST_TRAVERSE(ofl
->ofl_ars
, idx
, adp
)) {
3115 if ((adp
->ad_stdev
!= status
.st_dev
) ||
3116 (adp
->ad_stino
!= status
.st_ino
))
3120 * We've seen this file before so reuse the
3121 * original archive descriptor and discard the
3122 * new elf descriptor. Note that a file
3123 * descriptor is unnecessary, as the file is
3124 * already available in memory.
3126 DBG_CALL(Dbg_file_reuse(ofl
->ofl_lml
, name
,
3128 (void) elf_end(elf
);
3129 if (!ld_process_archive(name
, -1, adp
, ofl
))
3136 * As we haven't processed this file before establish a new
3137 * archive descriptor.
3139 adp
= ld_ar_setup(name
, elf
, ofl
);
3140 if ((adp
== NULL
) || (adp
== (Ar_desc
*)S_ERROR
))
3141 return ((uintptr_t)adp
);
3142 adp
->ad_stdev
= status
.st_dev
;
3143 adp
->ad_stino
= status
.st_ino
;
3145 ld_sup_file(ofl
, name
, ELF_K_AR
, flags
, elf
);
3148 * Indicate that the ELF descriptor no longer requires a file
3149 * descriptor by reading the entire file. The file is already
3150 * read via the initial mmap(2) behind elf_begin(3elf), thus
3151 * this operation is effectively a no-op. However, a side-
3152 * effect is that the internal file descriptor, maintained in
3153 * the ELF descriptor, is set to -1. This setting will not
3154 * be compared with any file descriptor that is passed to
3155 * elf_begin(), should this archive, or one of the archive
3156 * members, be processed again from the command line or
3157 * because of a -z rescan.
3159 if (elf_cntl(elf
, ELF_C_FDREAD
) == -1) {
3160 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_CNTL
),
3165 if (!ld_process_archive(name
, -1, adp
, ofl
))
3171 * Obtain the elf header so that we can determine what type of
3172 * elf ELF_K_ELF file this is.
3174 if ((ehdr
= elf_getehdr(elf
)) == NULL
) {
3175 int _class
= gelf_getclass(elf
);
3178 * This can fail for a number of reasons. Typically
3179 * the object class is incorrect (ie. user is building
3180 * 64-bit but managed to point at 32-bit libraries).
3181 * Other ELF errors can include a truncated or corrupt
3182 * file. Try to get the best error message possible.
3184 if (ld_targ
.t_m
.m_class
!= _class
) {
3185 _rej
.rej_type
= SGS_REJ_CLASS
;
3186 _rej
.rej_info
= (uint_t
)_class
;
3188 _rej
.rej_type
= SGS_REJ_STR
;
3189 _rej
.rej_str
= elf_errmsg(-1);
3191 _rej
.rej_name
= name
;
3192 DBG_CALL(Dbg_file_rejected(ofl
->ofl_lml
, &_rej
,
3193 ld_targ
.t_m
.m_mach
));
3194 if (rej
->rej_type
== 0) {
3196 rej
->rej_name
= strdup(_rej
.rej_name
);
3202 * Determine if we've already come across this file.
3204 if (!(flags
& FLG_IF_EXTRACT
)) {
3208 if (ehdr
->e_type
== ET_REL
)
3209 apl
= ofl
->ofl_objs
;
3214 * Traverse the appropriate file list and determine if
3215 * a dev/inode match is found.
3217 for (APLIST_TRAVERSE(apl
, idx
, ifl
)) {
3219 * Ifl_desc generated via -Nneed, therefore no
3220 * actual file behind it.
3222 if (ifl
->ifl_flags
& FLG_IF_NEEDSTR
)
3225 if ((ifl
->ifl_stino
!= status
.st_ino
) ||
3226 (ifl
->ifl_stdev
!= status
.st_dev
))
3230 * Disregard (skip) this image.
3232 DBG_CALL(Dbg_file_skip(ofl
->ofl_lml
,
3233 ifl
->ifl_name
, name
));
3234 (void) elf_end(elf
);
3237 * If the file was explicitly defined on the
3238 * command line (this is always the case for
3239 * relocatable objects, and is true for shared
3240 * objects when they weren't specified via -l or
3241 * were dragged in as an implicit dependency),
3242 * then warn the user.
3244 if ((flags
& FLG_IF_CMDLINE
) ||
3245 (ifl
->ifl_flags
& FLG_IF_CMDLINE
)) {
3249 * Determine whether this is the same
3250 * file name as originally encountered
3251 * so as to provide the most
3252 * descriptive diagnostic.
3255 (strcmp(name
, ifl
->ifl_name
) == 0) ?
3256 MSG_INTL(MSG_FIL_MULINC_1
) :
3257 MSG_INTL(MSG_FIL_MULINC_2
);
3258 ld_eprintf(ofl
, ERR_WARNING
,
3259 errmsg
, name
, ifl
->ifl_name
);
3268 * At this point, we know we need the file. Establish an input
3269 * file descriptor and continue processing.
3271 ifl
= ifl_setup(name
, ehdr
, elf
, flags
, ofl
, rej
);
3272 if ((ifl
== NULL
) || (ifl
== (Ifl_desc
*)S_ERROR
))
3273 return ((uintptr_t)ifl
);
3274 ifl
->ifl_stdev
= status
.st_dev
;
3275 ifl
->ifl_stino
= status
.st_ino
;
3278 * If -zignore is in effect, mark this file as a potential
3279 * candidate (the files use isn't actually determined until
3280 * symbol resolution and relocation processing are completed).
3282 if (ofl
->ofl_flags1
& FLG_OF1_IGNORE
)
3283 ifl
->ifl_flags
|= FLG_IF_IGNORE
;
3285 switch (ehdr
->e_type
) {
3287 (*ld_targ
.t_mr
.mr_mach_eflags
)(ehdr
, ofl
);
3288 error
= process_elf(ifl
, elf
, ofl
);
3291 if ((ofl
->ofl_flags
& FLG_OF_STATIC
) ||
3292 !(ofl
->ofl_flags
& FLG_OF_DYNLIBS
)) {
3293 ld_eprintf(ofl
, ERR_FATAL
,
3294 MSG_INTL(MSG_FIL_SOINSTAT
), name
);
3299 * Record any additional shared object information.
3300 * If no soname is specified (eg. this file was
3301 * derived from a explicit filename declaration on the
3302 * command line, ie. bar.so) use the pathname.
3303 * This entry may be overridden if the files dynamic
3304 * section specifies an DT_SONAME value.
3307 ifl
->ifl_soname
= ifl
->ifl_name
;
3309 ifl
->ifl_soname
= soname
;
3312 * If direct bindings, lazy loading, group permissions,
3313 * or deferred dependencies need to be established, mark
3316 if (ofl
->ofl_flags1
& FLG_OF1_ZDIRECT
)
3317 ifl
->ifl_flags
|= FLG_IF_DIRECT
;
3318 if (ofl
->ofl_flags1
& FLG_OF1_LAZYLD
)
3319 ifl
->ifl_flags
|= FLG_IF_LAZYLD
;
3320 if (ofl
->ofl_flags1
& FLG_OF1_GRPPRM
)
3321 ifl
->ifl_flags
|= FLG_IF_GRPPRM
;
3322 if (ofl
->ofl_flags1
& FLG_OF1_DEFERRED
)
3324 (FLG_IF_LAZYLD
| FLG_IF_DEFERRED
);
3326 error
= process_elf(ifl
, elf
, ofl
);
3329 * Determine whether this dependency requires a syminfo.
3331 if (ifl
->ifl_flags
& MSK_IF_SYMINFO
)
3332 ofl
->ofl_flags
|= FLG_OF_SYMINFO
;
3335 * Guidance: Use -z lazyload/nolazyload.
3336 * libc is exempt from this advice, because it cannot
3337 * be lazy loaded, and requests to do so are ignored.
3339 if (OFL_GUIDANCE(ofl
, FLG_OFG_NO_LAZY
) &&
3340 ((ifl
->ifl_flags
& FLG_IF_RTLDINF
) == 0)) {
3341 ld_eprintf(ofl
, ERR_GUIDANCE
,
3342 MSG_INTL(MSG_GUIDE_LAZYLOAD
));
3343 ofl
->ofl_guideflags
|= FLG_OFG_NO_LAZY
;
3347 * Guidance: Use -B direct/nodirect or
3348 * -z direct/nodirect.
3350 if (OFL_GUIDANCE(ofl
, FLG_OFG_NO_DB
)) {
3351 ld_eprintf(ofl
, ERR_GUIDANCE
,
3352 MSG_INTL(MSG_GUIDE_DIRECT
));
3353 ofl
->ofl_guideflags
|= FLG_OFG_NO_DB
;
3359 _rej
.rej_type
= SGS_REJ_UNKFILE
;
3360 _rej
.rej_name
= name
;
3361 DBG_CALL(Dbg_file_rejected(ofl
->ofl_lml
, &_rej
,
3362 ld_targ
.t_m
.m_mach
));
3363 if (rej
->rej_type
== 0) {
3365 rej
->rej_name
= strdup(_rej
.rej_name
);
3372 _rej
.rej_type
= SGS_REJ_UNKFILE
;
3373 _rej
.rej_name
= name
;
3374 DBG_CALL(Dbg_file_rejected(ofl
->ofl_lml
, &_rej
,
3375 ld_targ
.t_m
.m_mach
));
3376 if (rej
->rej_type
== 0) {
3378 rej
->rej_name
= strdup(_rej
.rej_name
);
3382 if ((error
== 0) || (error
== S_ERROR
))
3391 * Having successfully opened a file, set up the necessary elf structures to
3392 * process it further. This small section of processing is slightly different
3393 * from the elf initialization required to process a relocatable object from an
3394 * archive (see libs.c: ld_process_archive()).
3397 ld_process_open(const char *opath
, const char *ofile
, int *fd
, Ofl_desc
*ofl
,
3398 Word flags
, Rej_desc
*rej
, Ifl_desc
**ifl_ret
)
3401 const char *npath
= opath
;
3402 const char *nfile
= ofile
;
3404 if ((elf
= elf_begin(*fd
, ELF_C_READ
, NULL
)) == NULL
) {
3405 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_BEGIN
), npath
);
3410 * Determine whether the support library wishes to process this open.
3411 * The support library may return:
3412 * . a different ELF descriptor (in which case they should have
3413 * closed the original)
3414 * . a different file descriptor (in which case they should have
3415 * closed the original)
3416 * . a different path and file name (presumably associated with
3417 * a different file descriptor)
3419 * A file descriptor of -1, or and ELF descriptor of zero indicates
3420 * the file should be ignored.
3422 ld_sup_open(ofl
, &npath
, &nfile
, fd
, flags
, &elf
, NULL
, 0,
3425 if ((*fd
== -1) || (elf
== NULL
))
3428 return (ld_process_ifl(npath
, nfile
, *fd
, elf
, flags
, ofl
, rej
,
3433 * Having successfully mapped a file, set up the necessary elf structures to
3434 * process it further. This routine is patterned after ld_process_open() and
3435 * is only called by ld.so.1(1) to process a relocatable object.
3438 ld_process_mem(const char *path
, const char *file
, char *addr
, size_t size
,
3439 Ofl_desc
*ofl
, Rej_desc
*rej
)
3445 if ((elf
= elf_memory(addr
, size
)) == NULL
) {
3446 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_MEMORY
), path
);
3450 open_ret
= ld_process_ifl(path
, file
, 0, elf
, 0, ofl
, rej
, &ifl
);
3452 return ((Ifl_desc
*) open_ret
);
3457 * Process a required library (i.e. the dependency of a shared object).
3458 * Combine the directory and filename, check the resultant path size, and try
3459 * opening the pathname.
3462 process_req_lib(Sdf_desc
*sdf
, const char *dir
, const char *file
,
3463 Ofl_desc
*ofl
, Rej_desc
*rej
)
3467 char path
[PATH_MAX
];
3468 const char *_dir
= dir
;
3471 * Determine the sizes of the directory and filename to insure we don't
3472 * exceed our buffer.
3474 if ((dlen
= strlen(dir
)) == 0) {
3475 _dir
= MSG_ORIG(MSG_STR_DOT
);
3479 plen
= dlen
+ strlen(file
) + 1;
3480 if (plen
> PATH_MAX
) {
3481 ld_eprintf(ofl
, ERR_FATAL
, MSG_INTL(MSG_FIL_PTHTOLONG
),
3487 * Build the entire pathname and try and open the file.
3489 (void) strcpy(path
, _dir
);
3490 (void) strcat(path
, MSG_ORIG(MSG_STR_SLASH
));
3491 (void) strcat(path
, file
);
3492 DBG_CALL(Dbg_libs_req(ofl
->ofl_lml
, sdf
->sdf_name
,
3493 sdf
->sdf_rfile
, path
));
3495 if ((fd
= open(path
, O_RDONLY
)) == -1)
3502 if ((_path
= libld_malloc(strlen(path
) + 1)) == NULL
)
3503 return ((Ifl_desc
*)S_ERROR
);
3504 (void) strcpy(_path
, path
);
3505 open_ret
= ld_process_open(_path
, &_path
[dlen
], &fd
, ofl
,
3510 return ((Ifl_desc
*)open_ret
);
3516 * Finish any library processing. Walk the list of so's that have been listed
3517 * as "included" by shared objects we have previously processed. Examine them,
3518 * without adding them as explicit dependents of this program, in order to
3519 * complete our symbol definition process. The search path rules are:
3521 * - use any user supplied paths, i.e. LD_LIBRARY_PATH and -L, then
3523 * - use any RPATH defined within the parent shared object, then
3525 * - use the default directories, i.e. LIBPATH or -YP.
3528 ld_finish_libs(Ofl_desc
*ofl
)
3532 Rej_desc rej
= { 0 };
3535 * Make sure we are back in dynamic mode.
3537 ofl
->ofl_flags
|= FLG_OF_DYNLIBS
;
3539 for (APLIST_TRAVERSE(ofl
->ofl_soneed
, idx1
, sdf
)) {
3541 char *path
, *slash
= NULL
;
3544 char *file
= (char *)sdf
->sdf_name
;
3547 * See if this file has already been processed. At the time
3548 * this implicit dependency was determined there may still have
3549 * been more explicit dependencies to process. Note, if we ever
3550 * do parse the command line three times we would be able to
3551 * do all this checking when processing the dynamic section.
3556 for (APLIST_TRAVERSE(ofl
->ofl_sos
, idx2
, ifl
)) {
3557 if (!(ifl
->ifl_flags
& FLG_IF_NEEDSTR
) &&
3558 (strcmp(file
, ifl
->ifl_soname
) == 0)) {
3559 sdf
->sdf_file
= ifl
;
3567 * If the current path name element embeds a "/", then it's to
3568 * be taken "as is", with no searching involved. Process all
3569 * "/" occurrences, so that we can deduce the base file name.
3571 for (path
= file
; *path
; path
++) {
3576 DBG_CALL(Dbg_libs_req(ofl
->ofl_lml
, sdf
->sdf_name
,
3577 sdf
->sdf_rfile
, file
));
3578 if ((fd
= open(file
, O_RDONLY
)) == -1) {
3579 ld_eprintf(ofl
, ERR_WARNING
,
3580 MSG_INTL(MSG_FIL_NOTFOUND
), file
,
3584 Rej_desc _rej
= { 0 };
3586 open_ret
= ld_process_open(file
, ++slash
,
3587 &fd
, ofl
, 0, &_rej
, &ifl
);
3590 if (open_ret
== S_ERROR
)
3593 if (_rej
.rej_type
) {
3594 Conv_reject_desc_buf_t rej_buf
;
3596 ld_eprintf(ofl
, ERR_WARNING
,
3597 MSG_INTL(reject
[_rej
.rej_type
]),
3598 _rej
.rej_name
? rej
.rej_name
:
3599 MSG_INTL(MSG_STR_UNKNOWN
),
3600 conv_reject_desc(&_rej
, &rej_buf
,
3601 ld_targ
.t_m
.m_mach
));
3603 sdf
->sdf_file
= ifl
;
3609 * Now search for this file in any user defined directories.
3611 for (APLIST_TRAVERSE(ofl
->ofl_ulibdirs
, idx2
, path
)) {
3612 Rej_desc _rej
= { 0 };
3614 ifl
= process_req_lib(sdf
, path
, file
, ofl
, &_rej
);
3615 if (ifl
== (Ifl_desc
*)S_ERROR
) {
3618 if (_rej
.rej_type
) {
3619 if (rej
.rej_type
== 0) {
3621 rej
.rej_name
= strdup(_rej
.rej_name
);
3625 sdf
->sdf_file
= ifl
;
3633 * Next use the local rules defined within the parent shared
3636 if (sdf
->sdf_rpath
!= NULL
) {
3639 rpath
= libld_malloc(strlen(sdf
->sdf_rpath
) + 1);
3642 (void) strcpy(rpath
, sdf
->sdf_rpath
);
3643 DBG_CALL(Dbg_libs_path(ofl
->ofl_lml
, rpath
,
3644 LA_SER_RUNPATH
, sdf
->sdf_rfile
));
3645 if ((path
= strtok_r(rpath
,
3646 MSG_ORIG(MSG_STR_COLON
), &next
)) != NULL
) {
3648 Rej_desc _rej
= { 0 };
3650 path
= expand(sdf
->sdf_rfile
, path
,
3653 ifl
= process_req_lib(sdf
, path
,
3655 if (ifl
== (Ifl_desc
*)S_ERROR
) {
3658 if ((_rej
.rej_type
) &&
3659 (rej
.rej_type
== 0)) {
3662 strdup(_rej
.rej_name
);
3665 sdf
->sdf_file
= ifl
;
3668 } while ((path
= strtok_r(NULL
,
3669 MSG_ORIG(MSG_STR_COLON
), &next
)) != NULL
);
3676 * Finally try the default library search directories.
3678 for (APLIST_TRAVERSE(ofl
->ofl_dlibdirs
, idx2
, path
)) {
3679 Rej_desc _rej
= { 0 };
3681 ifl
= process_req_lib(sdf
, path
, file
, ofl
, &rej
);
3682 if (ifl
== (Ifl_desc
*)S_ERROR
) {
3685 if (_rej
.rej_type
) {
3686 if (rej
.rej_type
== 0) {
3688 rej
.rej_name
= strdup(_rej
.rej_name
);
3692 sdf
->sdf_file
= ifl
;
3700 * If we've got this far we haven't found the shared object.
3701 * If an object was found, but was rejected for some reason,
3702 * print a diagnostic to that effect, otherwise generate a
3703 * generic "not found" diagnostic.
3706 Conv_reject_desc_buf_t rej_buf
;
3708 ld_eprintf(ofl
, ERR_WARNING
,
3709 MSG_INTL(reject
[rej
.rej_type
]),
3710 rej
.rej_name
? rej
.rej_name
:
3711 MSG_INTL(MSG_STR_UNKNOWN
),
3712 conv_reject_desc(&rej
, &rej_buf
,
3713 ld_targ
.t_m
.m_mach
));
3715 ld_eprintf(ofl
, ERR_WARNING
,
3716 MSG_INTL(MSG_FIL_NOTFOUND
), file
, sdf
->sdf_rfile
);
3721 * Finally, now that all objects have been input, make sure any version
3722 * requirements have been met.
3724 return (ld_vers_verify(ofl
));