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) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
29 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
33 * Object file dependent support for ELF objects.
37 #include <sys/procfs.h>
39 #include <sys/debug.h>
48 #include "_inline_gen.h"
49 #include "_inline_reloc.h"
53 * Default and secure dependency search paths.
55 static Spath_defn _elf_def_dirs
[] = {
57 { MSG_ORIG(MSG_PTH_LIB_64
), MSG_PTH_LIB_64_SIZE
},
58 { MSG_ORIG(MSG_PTH_USRLIB_64
), MSG_PTH_USRLIB_64_SIZE
},
60 { MSG_ORIG(MSG_PTH_LIB
), MSG_PTH_LIB_SIZE
},
61 { MSG_ORIG(MSG_PTH_USRLIB
), MSG_PTH_USRLIB_SIZE
},
66 static Spath_defn _elf_sec_dirs
[] = {
68 { MSG_ORIG(MSG_PTH_LIBSE_64
), MSG_PTH_LIBSE_64_SIZE
},
69 { MSG_ORIG(MSG_PTH_USRLIBSE_64
), MSG_PTH_USRLIBSE_64_SIZE
},
71 { MSG_ORIG(MSG_PTH_LIBSE
), MSG_PTH_LIBSE_SIZE
},
72 { MSG_ORIG(MSG_PTH_USRLIBSE
), MSG_PTH_USRLIBSE_SIZE
},
77 Alist
*elf_def_dirs
= NULL
;
78 Alist
*elf_sec_dirs
= NULL
;
81 * Defines for local functions.
83 static void elf_dladdr(ulong_t
, Rt_map
*, Dl_info
*, void **, int);
84 static Addr
elf_entry_point(void);
85 static int elf_fix_name(const char *, Rt_map
*, Alist
**, Aliste
, uint_t
);
86 static Alist
**elf_get_def_dirs(void);
87 static Alist
**elf_get_sec_dirs(void);
88 static char *elf_get_so(const char *, const char *, size_t, size_t);
89 static int elf_needed(Lm_list
*, Aliste
, Rt_map
*, int *);
92 * Functions and data accessed through indirect pointers.
110 * Default and secure dependency search paths.
115 if (elf_def_dirs
== NULL
)
116 set_dirs(&elf_def_dirs
, _elf_def_dirs
, LA_SER_DEFAULT
);
117 return (&elf_def_dirs
);
123 if (elf_sec_dirs
== NULL
)
124 set_dirs(&elf_sec_dirs
, _elf_sec_dirs
, LA_SER_SECURE
);
125 return (&elf_sec_dirs
);
129 * Redefine NEEDED name if necessary.
132 elf_fix_name(const char *name
, Rt_map
*clmp
, Alist
**alpp
, Aliste alni
,
136 * For ABI compliance, if we are asked for ld.so.1, then really give
137 * them libsys.so.1 (the SONAME of libsys.so.1 is ld.so.1).
139 if (((*name
== '/') &&
142 (strcmp(name
, MSG_ORIG(MSG_PTH_RTLD_64
)) == 0)) ||
144 (strcmp(name
, MSG_ORIG(MSG_PTH_RTLD
)) == 0)) ||
146 (strcmp(name
, MSG_ORIG(MSG_FIL_RTLD
)) == 0)) {
150 DBG_CALL(Dbg_file_fixname(LIST(clmp
), name
,
151 MSG_ORIG(MSG_PTH_LIBSYS
)));
152 if ((pdp
= alist_append(alpp
, NULL
, sizeof (Pdesc
),
156 pdp
->pd_pname
= (char *)MSG_ORIG(MSG_PTH_LIBSYS
);
157 pdp
->pd_plen
= MSG_PTH_LIBSYS_SIZE
;
158 pdp
->pd_flags
= PD_FLG_PNSLASH
;
163 return (expand_paths(clmp
, name
, alpp
, alni
, orig
, 0));
167 * Determine whether this object requires capabilities.
170 elf_cap_check(Fdesc
*fdp
, Ehdr
*ehdr
, Rej_desc
*rej
)
180 * If this is a shared object, the base address of the shared object is
181 * added to all address values defined within the object. Otherwise, if
182 * this is an executable, all object addresses are used as is.
184 if (ehdr
->e_type
== ET_EXEC
)
190 phdr
= (Phdr
*)((char *)ehdr
+ ehdr
->e_phoff
);
191 for (cnt
= 0; cnt
< ehdr
->e_phnum
; cnt
++, phdr
++) {
192 if (phdr
->p_type
== PT_DYNAMIC
) {
194 dyn
= (Dyn
*)((uintptr_t)phdr
->p_vaddr
+ base
);
195 dyncnt
= phdr
->p_filesz
/ sizeof (Dyn
);
196 } else if (phdr
->p_type
== PT_SUNWCAP
) {
198 cap
= (Cap
*)((uintptr_t)phdr
->p_vaddr
+ base
);
204 * From the .dynamic section, determine the associated string
205 * table. Required for CA_SUNW_MACH and CA_SUNW_PLAT
208 while (dyn
&& dyncnt
) {
209 if (dyn
->d_tag
== DT_NULL
) {
211 } else if (dyn
->d_tag
== DT_STRTAB
) {
212 str
= (char *)(dyn
->d_un
.d_ptr
+ base
);
220 * Establish any alternative capabilities, and validate this object
221 * if it defines it's own capabilities information.
223 return (cap_check_fdesc(fdp
, cap
, str
, rej
));
227 * Determine if we have been given an ELF file and if so determine if the file
228 * is compatible. Returns 1 if true, else 0 and sets the reject descriptor
229 * with associated error information.
232 elf_verify(caddr_t addr
, size_t size
, Fdesc
*fdp
, const char *name
,
236 char *caddr
= (char *)addr
;
239 * Determine if we're an elf file. If not simply return, we don't set
240 * any rejection information as this test allows use to scroll through
241 * the objects we support (ELF, AOUT).
243 if (size
< sizeof (Ehdr
) ||
244 caddr
[EI_MAG0
] != ELFMAG0
||
245 caddr
[EI_MAG1
] != ELFMAG1
||
246 caddr
[EI_MAG2
] != ELFMAG2
||
247 caddr
[EI_MAG3
] != ELFMAG3
) {
252 * Check class and encoding.
256 if (ehdr
->e_ident
[EI_CLASS
] != M_CLASS
) {
257 rej
->rej_type
= SGS_REJ_CLASS
;
258 rej
->rej_info
= (uint_t
)ehdr
->e_ident
[EI_CLASS
];
261 if (ehdr
->e_ident
[EI_DATA
] != M_DATA
) {
262 rej
->rej_type
= SGS_REJ_DATA
;
263 rej
->rej_info
= (uint_t
)ehdr
->e_ident
[EI_DATA
];
266 if ((ehdr
->e_type
!= ET_REL
) && (ehdr
->e_type
!= ET_EXEC
) &&
267 (ehdr
->e_type
!= ET_DYN
)) {
268 rej
->rej_type
= SGS_REJ_TYPE
;
269 rej
->rej_info
= (uint_t
)ehdr
->e_type
;
274 * Verify ELF version.
276 if (ehdr
->e_version
> EV_CURRENT
) {
277 rej
->rej_type
= SGS_REJ_VERSION
;
278 rej
->rej_info
= (uint_t
)ehdr
->e_version
;
283 * Verify machine specific flags.
285 if (elf_mach_flags_check(rej
, ehdr
) == 0)
289 * Verify any capability requirements. Note, if this object is a shared
290 * object that is explicitly defined on the ldd(1) command line, and it
291 * contains an incompatible capabilities requirement, then inform the
292 * user, but continue processing.
294 if (elf_cap_check(fdp
, ehdr
, rej
) == 0) {
295 Rt_map
*lmp
= lml_main
.lm_head
;
297 if ((lml_main
.lm_flags
& LML_FLG_TRC_LDDSTUB
) && lmp
&&
298 (FLAGS1(lmp
) & FL1_RT_LDDSTUB
) && (NEXT(lmp
) == NULL
)) {
300 (void) printf(MSG_INTL(ldd_warn
[rej
->rej_type
]), name
,
310 * The runtime linker employs lazy loading to provide the libraries needed for
311 * debugging, preloading .o's and dldump(). As these are seldom used, the
312 * standard startup of ld.so.1 doesn't initialize all the information necessary
313 * to perform plt relocation on ld.so.1's link-map. The first time lazy loading
314 * is called we get here to perform these initializations:
316 * - elf_needed() is called to establish any ld.so.1 dependencies. These
317 * dependencies should all be lazy loaded, so this routine is typically a
318 * no-op. However, we call elf_needed() for completeness, in case any
319 * NEEDED initialization is required.
321 * - For intel, ld.so.1's JMPSLOT relocations need relative updates. These
322 * are by default skipped thus delaying all relative relocation processing
323 * on every invocation of ld.so.1.
328 Lm_list
*lml
= &lml_rtld
;
329 Rt_map
*lmp
= lml
->lm_head
;
331 if (lml
->lm_flags
& LML_FLG_PLTREL
)
334 if (elf_needed(lml
, ALIST_OFF_DATA
, lmp
, NULL
) == 0)
339 * This is a kludge to give ld.so.1 a performance benefit on i386.
340 * It's based around two factors.
342 * - JMPSLOT relocations (PLT's) actually need a relative relocation
343 * applied to the GOT entry so that they can find PLT0.
345 * - ld.so.1 does not exercise *any* PLT's before it has made a call
346 * to elf_lazy_load(). This is because all dynamic dependencies
347 * are recorded as lazy dependencies.
349 (void) elf_reloc_relative_count((ulong_t
)JMPREL(lmp
),
350 (ulong_t
)(PLTRELSZ(lmp
) / RELENT(lmp
)), (ulong_t
)RELENT(lmp
),
351 (ulong_t
)ADDR(lmp
), lmp
, NULL
, 0);
353 lml
->lm_flags
|= LML_FLG_PLTREL
;
358 * Lazy load an object.
361 elf_lazy_load(Rt_map
*clmp
, Slookup
*slp
, uint_t ndx
, const char *sym
,
362 uint_t flags
, Grp_hdl
**hdl
, int *in_nfavl
)
366 Dyninfo
*dip
= &DYNINFO(clmp
)[ndx
], *pdip
;
368 Lm_list
*lml
= LIST(clmp
);
372 * If this dependency should be ignored, or has already been processed,
375 if (((nlmp
= (Rt_map
*)dip
->di_info
) != NULL
) ||
376 (dip
->di_flags
& (FLG_DI_IGNORE
| FLG_DI_LDD_DONE
)))
380 * If we're running under ldd(1), indicate that this dependency has been
381 * processed (see test above). It doesn't matter whether the object is
382 * successfully loaded or not, this flag simply ensures that we don't
383 * repeatedly attempt to load an object that has already failed to load.
384 * To do so would create multiple failure diagnostics for the same
385 * object under ldd(1).
387 if (lml
->lm_flags
& LML_FLG_TRC_ENABLE
)
388 dip
->di_flags
|= FLG_DI_LDD_DONE
;
391 * Determine the initial dependency name.
394 DBG_CALL(Dbg_file_lazyload(clmp
, name
, sym
));
397 * If this object needs to establish its own group, make sure a handle
400 if (dip
->di_flags
& FLG_DI_GROUP
)
401 flags
|= (FLG_RT_SETGROUP
| FLG_RT_PUBHDL
);
404 * Lazy dependencies are identified as DT_NEEDED entries with a
405 * DF_P1_LAZYLOAD flag in the previous DT_POSFLAG_1 element. The
406 * dynamic information element that corresponds to the DT_POSFLAG_1
407 * entry is free, and thus used to store the present entrance
408 * identifier. This identifier is used to prevent multiple attempts to
409 * load a failed lazy loadable dependency within the same runtime linker
410 * operation. However, future attempts to reload this dependency are
413 if (ndx
&& (pdip
= dip
- 1) && (pdip
->di_flags
& FLG_DI_POSFLAG1
))
414 pdip
->di_info
= (void *)slp
->sl_id
;
417 * Expand the requested name if necessary.
419 if (elf_fix_name(name
, clmp
, &palp
, AL_CNT_NEEDED
, 0) == 0)
423 * Establish a link-map control list for this request.
425 if ((lmco
= create_cntl(lml
, 0)) == 0) {
426 remove_alist(&palp
, 1);
431 * Load the associated object.
433 dip
->di_info
= nlmp
=
434 load_one(lml
, lmco
, palp
, clmp
, MODE(clmp
), flags
, hdl
, in_nfavl
);
437 * Remove any expanded pathname infrastructure. Reduce the pending lazy
438 * dependency count of the caller, together with the link-map lists
439 * count of objects that still have lazy dependencies pending.
441 remove_alist(&palp
, 1);
442 if (--LAZY(clmp
) == 0)
443 LIST(clmp
)->lm_lazy
--;
446 * Finish processing the objects associated with this request, and
447 * create an association between the caller and this dependency.
449 if (nlmp
&& ((bind_one(clmp
, nlmp
, BND_NEEDED
) == 0) ||
450 ((nlmp
= analyze_lmc(lml
, lmco
, nlmp
, clmp
, in_nfavl
)) == NULL
) ||
451 (relocate_lmc(lml
, lmco
, clmp
, nlmp
, in_nfavl
) == 0)))
452 dip
->di_info
= nlmp
= NULL
;
455 * If this lazyload has failed, and we've created a new link-map
456 * control list to which this request has added objects, then remove
457 * all the objects that have been associated to this request.
459 if ((nlmp
== NULL
) && (lmco
!= ALIST_OFF_DATA
))
460 remove_lmc(lml
, clmp
, lmco
, name
);
463 * Remove any temporary link-map control list.
465 if (lmco
!= ALIST_OFF_DATA
)
466 remove_cntl(lml
, lmco
);
469 * If this lazy loading failed, record the fact, and bump the lazy
473 dip
->di_flags
|= FLG_DI_LAZYFAIL
;
474 if (LAZY(clmp
)++ == 0)
475 LIST(clmp
)->lm_lazy
++;
482 * Return the entry point of the ELF executable.
485 elf_entry_point(void)
487 Rt_map
*lmp
= lml_main
.lm_head
;
488 Ehdr
*ehdr
= (Ehdr
*)ADDR(lmp
);
489 Addr addr
= (Addr
)(ehdr
->e_entry
);
491 if ((FLAGS(lmp
) & FLG_RT_FIXED
) == 0)
498 * Determine if a dependency requires a particular version and if so verify
499 * that the version exists in the dependency.
502 elf_verify_vers(const char *name
, Rt_map
*clmp
, Rt_map
*nlmp
)
504 Verneed
*vnd
= VERNEED(clmp
);
505 int _num
, num
= VERNEEDNUM(clmp
);
506 char *cstrs
= (char *)STRTAB(clmp
);
507 Lm_list
*lml
= LIST(clmp
);
510 * Traverse the callers version needed information and determine if any
511 * specific versions are required from the dependency.
513 DBG_CALL(Dbg_ver_need_title(LIST(clmp
), NAME(clmp
)));
514 for (_num
= 1; _num
<= num
; _num
++,
515 vnd
= (Verneed
*)((Xword
)vnd
+ vnd
->vn_next
)) {
516 Half cnt
= vnd
->vn_cnt
;
521 * Determine if a needed entry matches this dependency.
523 need
= (char *)(cstrs
+ vnd
->vn_file
);
524 if (strcmp(name
, need
) != 0)
527 if ((lml
->lm_flags
& LML_FLG_TRC_VERBOSE
) &&
528 ((FLAGS1(clmp
) & FL1_RT_LDDSTUB
) == 0))
529 (void) printf(MSG_INTL(MSG_LDD_VER_FIND
), name
);
532 * Validate that each version required actually exists in the
535 nstrs
= (char *)STRTAB(nlmp
);
537 for (vnap
= (Vernaux
*)((Xword
)vnd
+ vnd
->vn_aux
); cnt
;
538 cnt
--, vnap
= (Vernaux
*)((Xword
)vnap
+ vnap
->vna_next
)) {
539 char *version
, *define
;
540 Verdef
*vdf
= VERDEF(nlmp
);
541 ulong_t _num
, num
= VERDEFNUM(nlmp
);
545 * Skip validation of versions that are marked
546 * INFO. This optimization is used for versions
547 * that are inherited by another version. Verification
548 * of the inheriting version is sufficient.
550 * Such versions are recorded in the object for the
551 * benefit of VERSYM entries that refer to them. This
552 * provides a purely diagnostic benefit.
554 if (vnap
->vna_flags
& VER_FLG_INFO
)
557 version
= (char *)(cstrs
+ vnap
->vna_name
);
558 DBG_CALL(Dbg_ver_need_entry(lml
, 0, need
, version
));
560 for (_num
= 1; _num
<= num
; _num
++,
561 vdf
= (Verdef
*)((Xword
)vdf
+ vdf
->vd_next
)) {
564 if (vnap
->vna_hash
!= vdf
->vd_hash
)
567 vdap
= (Verdaux
*)((Xword
)vdf
+ vdf
->vd_aux
);
568 define
= (char *)(nstrs
+ vdap
->vda_name
);
569 if (strcmp(version
, define
) != 0)
577 * If we're being traced print out any matched version
578 * when the verbose (-v) option is in effect. Always
579 * print any unmatched versions.
581 if (lml
->lm_flags
& LML_FLG_TRC_ENABLE
) {
584 if (!(lml
->lm_flags
& LML_FLG_TRC_VERBOSE
))
587 (void) printf(MSG_ORIG(MSG_LDD_VER_FOUND
),
588 need
, version
, NAME(nlmp
));
590 if (rtld_flags
& RT_FL_SILENCERR
)
593 (void) printf(MSG_INTL(MSG_LDD_VER_NFOUND
),
601 * If the version hasn't been found then this is a
602 * candidate for a fatal error condition. Weak
603 * version definition requirements are silently
604 * ignored. Also, if the image inspected for a version
605 * definition has no versioning recorded at all then
606 * silently ignore this (this provides better backward
607 * compatibility to old images created prior to
608 * versioning being available). Both of these skipped
609 * diagnostics are available under tracing (see above).
611 if ((found
== 0) && (num
!= 0) &&
612 (!(vnap
->vna_flags
& VER_FLG_WEAK
))) {
613 eprintf(lml
, ERR_FATAL
,
614 MSG_INTL(MSG_VER_NFOUND
), need
, version
,
620 DBG_CALL(Dbg_ver_need_done(lml
));
625 * Search through the dynamic section for DT_NEEDED entries and perform one
626 * of two functions. If only the first argument is specified then load the
627 * defined shared object, otherwise add the link map representing the defined
628 * link map the the dlopen list.
631 elf_needed(Lm_list
*lml
, Aliste lmco
, Rt_map
*clmp
, int *in_nfavl
)
636 Word lmflags
= lml
->lm_flags
;
639 * A DYNINFO() structure is created during link-map generation that
640 * parallels the DYN() information, and defines any flags that
641 * influence a dependencies loading.
643 for (dyn
= DYN(clmp
), dip
= DYNINFO(clmp
);
644 !(dip
->di_flags
& FLG_DI_IGNORE
); dyn
++, dip
++) {
645 uint_t flags
= 0, silent
= 0;
646 const char *name
= dip
->di_name
;
649 if ((dip
->di_flags
& FLG_DI_NEEDED
) == 0)
653 * Skip any deferred dependencies, unless ldd(1) has forced
654 * their processing. By default, deferred dependencies are
655 * only processed when an explicit binding to an individual
656 * deferred reference is made.
658 if ((dip
->di_flags
& FLG_DI_DEFERRED
) &&
659 ((rtld_flags
& RT_FL_DEFERRED
) == 0))
663 * NOTE, libc.so.1 can't be lazy loaded. Although a lazy
664 * position flag won't be produced when a RTLDINFO .dynamic
665 * entry is found (introduced with the UPM in Solaris 10), it
666 * was possible to mark libc for lazy loading on previous
667 * releases. To reduce the overhead of testing for this
668 * occurrence, only carry out this check for the first object
669 * on the link-map list (there aren't many applications built
672 if ((dip
->di_flags
& FLG_DI_LAZY
) && (lml
->lm_head
== clmp
) &&
673 (strcmp(name
, MSG_ORIG(MSG_FIL_LIBC
)) == 0))
674 dip
->di_flags
&= ~FLG_DI_LAZY
;
677 * Don't bring in lazy loaded objects yet unless we've been
678 * asked to attempt to load all available objects (crle(1) sets
679 * LD_FLAGS=loadavail). Even under RTLD_NOW we don't process
680 * this - RTLD_NOW will cause relocation processing which in
681 * turn might trigger lazy loading, but its possible that the
682 * object has a lazy loaded file with no bindings (i.e., it
683 * should never have been a dependency in the first place).
685 if (dip
->di_flags
& FLG_DI_LAZY
) {
686 if ((lmflags
& LML_FLG_LOADAVAIL
) == 0) {
692 * Silence any error messages - see description under
693 * elf_lookup_filtee().
695 if ((rtld_flags
& RT_FL_SILENCERR
) == 0) {
696 rtld_flags
|= RT_FL_SILENCERR
;
701 DBG_CALL(Dbg_file_needed(clmp
, name
));
704 * If we're running under ldd(1), indicate that this dependency
705 * has been processed. It doesn't matter whether the object is
706 * successfully loaded or not, this flag simply ensures that we
707 * don't repeatedly attempt to load an object that has already
708 * failed to load. To do so would create multiple failure
709 * diagnostics for the same object under ldd(1).
711 if (lml
->lm_flags
& LML_FLG_TRC_ENABLE
)
712 dip
->di_flags
|= FLG_DI_LDD_DONE
;
715 * Identify any group permission requirements.
717 if (dip
->di_flags
& FLG_DI_GROUP
)
718 flags
= (FLG_RT_SETGROUP
| FLG_RT_PUBHDL
);
721 * Establish the objects name, load it and establish a binding
724 if ((elf_fix_name(name
, clmp
, &palp
, AL_CNT_NEEDED
, 0) == 0) ||
725 ((nlmp
= load_one(lml
, lmco
, palp
, clmp
, MODE(clmp
),
726 flags
, 0, in_nfavl
)) == NULL
) ||
727 (bind_one(clmp
, nlmp
, BND_NEEDED
) == 0))
731 * Clean up any infrastructure, including the removal of the
732 * error suppression state, if it had been previously set in
735 remove_alist(&palp
, 0);
738 rtld_flags
&= ~RT_FL_SILENCERR
;
740 if ((dip
->di_info
= (void *)nlmp
) == NULL
) {
742 * If the object could not be mapped, continue if error
743 * suppression is established or we're here with ldd(1).
745 if ((MODE(clmp
) & RTLD_CONFGEN
) || (lmflags
&
746 (LML_FLG_LOADAVAIL
| LML_FLG_TRC_ENABLE
)))
749 remove_alist(&palp
, 1);
758 remove_alist(&palp
, 1);
763 * A null symbol interpretor. Used if a filter has no associated filtees.
767 elf_null_find_sym(Slookup
*slp
, Sresult
*srp
, uint_t
*binfo
, int *in_nfavl
)
773 * Disable filtee use.
776 elf_disable_filtee(Rt_map
*lmp
, Dyninfo
*dip
)
778 if ((dip
->di_flags
& FLG_DI_SYMFLTR
) == 0) {
780 * If this is an object filter, null out the reference name.
782 if (OBJFLTRNDX(lmp
) != FLTR_DISABLED
) {
784 OBJFLTRNDX(lmp
) = FLTR_DISABLED
;
787 * Indicate that this filtee is no longer available.
789 if (dip
->di_flags
& FLG_DI_STDFLTR
)
790 SYMINTP(lmp
) = elf_null_find_sym
;
793 } else if (dip
->di_flags
& FLG_DI_STDFLTR
) {
795 * Indicate that this standard filtee is no longer available.
797 if (SYMSFLTRCNT(lmp
))
801 * Indicate that this auxiliary filtee is no longer available.
803 if (SYMAFLTRCNT(lmp
))
806 dip
->di_flags
&= ~MSK_DI_FILTER
;
810 * Find symbol interpreter - filters.
811 * This function is called when the symbols from a shared object should
812 * be resolved from the shared objects filtees instead of from within itself.
814 * A symbol name of 0 is used to trigger filtee loading.
817 _elf_lookup_filtee(Slookup
*slp
, Sresult
*srp
, uint_t
*binfo
, uint_t ndx
,
820 const char *name
= slp
->sl_name
, *filtees
;
821 Rt_map
*clmp
= slp
->sl_cmap
;
822 Rt_map
*ilmp
= slp
->sl_imap
;
825 Dyninfo
*dip
= &DYNINFO(ilmp
)[ndx
];
826 Lm_list
*lml
= LIST(ilmp
);
830 * Indicate that the filter has been used. If a binding already exists
831 * to the caller, indicate that this object is referenced. This insures
832 * we don't generate false unreferenced diagnostics from ldd -u/U or
833 * debugging. Don't create a binding regardless, as this filter may
834 * have been dlopen()'ed.
836 if (name
&& (ilmp
!= clmp
)) {
837 Word tracing
= (LIST(clmp
)->lm_flags
&
838 (LML_FLG_TRC_UNREF
| LML_FLG_TRC_UNUSED
));
840 if (tracing
|| DBG_ENABLED
) {
844 FLAGS1(ilmp
) |= FL1_RT_USED
;
846 if ((tracing
& LML_FLG_TRC_UNREF
) || DBG_ENABLED
) {
847 for (APLIST_TRAVERSE(CALLERS(ilmp
), idx
, bdp
)) {
848 if (bdp
->b_caller
== clmp
) {
849 bdp
->b_flags
|= BND_REFER
;
858 * If this is the first call to process this filter, establish the
859 * filtee list. If a configuration file exists, determine if any
860 * filtee associations for this filter, and its filtee reference, are
861 * defined. Otherwise, process the filtee reference. Any token
862 * expansion is also completed at this point (i.e., $PLATFORM).
864 filtees
= dip
->di_name
;
865 if (dip
->di_info
== NULL
) {
866 if (rtld_flags2
& RT_FL2_FLTCFG
) {
867 elf_config_flt(lml
, PATHNAME(ilmp
), filtees
,
868 (Alist
**)&dip
->di_info
, AL_CNT_FILTEES
);
870 if (dip
->di_info
== NULL
) {
871 DBG_CALL(Dbg_file_filter(lml
, NAME(ilmp
), filtees
, 0));
873 (LML_FLG_TRC_VERBOSE
| LML_FLG_TRC_SEARCH
)) &&
874 ((FLAGS1(ilmp
) & FL1_RT_LDDSTUB
) == 0))
875 (void) printf(MSG_INTL(MSG_LDD_FIL_FILTER
),
876 NAME(ilmp
), filtees
);
878 if (expand_paths(ilmp
, filtees
, (Alist
**)&dip
->di_info
,
879 AL_CNT_FILTEES
, 0, 0) == 0) {
880 elf_disable_filtee(ilmp
, dip
);
887 * Traverse the filtee list, dlopen()'ing any objects specified and
888 * using their group handle to lookup the symbol.
891 for (ALIST_TRAVERSE((Alist
*)dip
->di_info
, idx
, pdp
)) {
896 if (pdp
->pd_plen
== 0)
900 * Establish the mode of the filtee from the filter. As filtees
901 * are loaded via a dlopen(), make sure that RTLD_GROUP is set
902 * and the filtees aren't global. It would be nice to have
903 * RTLD_FIRST used here also, but as filters got out long before
904 * RTLD_FIRST was introduced it's a little too late now.
906 mode
= MODE(ilmp
) | RTLD_GROUP
;
907 mode
&= ~RTLD_GLOBAL
;
910 * Insure that any auxiliary filter can locate symbols from its
913 if (dip
->di_flags
& FLG_DI_AUXFLTR
)
917 * Process any capability directory. Establish a new link-map
918 * control list from which to analyze any newly added objects.
920 if ((pdp
->pd_info
== NULL
) && (pdp
->pd_flags
& PD_TKN_CAP
)) {
921 const char *dir
= pdp
->pd_pname
;
925 * Establish a link-map control list for this request.
927 if ((lmco
= create_cntl(lml
, 0)) == 0)
931 * Determine the capability filtees. If none can be
932 * found, provide suitable diagnostics.
934 DBG_CALL(Dbg_cap_filter(lml
, dir
, ilmp
));
935 if (cap_filtees((Alist
**)&dip
->di_info
, idx
, dir
,
936 lmco
, ilmp
, clmp
, filtees
, mode
,
937 (FLG_RT_PUBHDL
| FLG_RT_CAP
), in_nfavl
) == 0) {
938 if ((lml
->lm_flags
& LML_FLG_TRC_ENABLE
) &&
939 (dip
->di_flags
& FLG_DI_AUXFLTR
) &&
940 (rtld_flags
& RT_FL_WARNFLTR
)) {
942 MSG_INTL(MSG_LDD_CAP_NFOUND
), dir
);
944 DBG_CALL(Dbg_cap_filter(lml
, dir
, 0));
948 * Re-establish the originating path name descriptor,
949 * as the expansion of capabilities filtees may have
950 * re-allocated the controlling Alist. Mark this
951 * original pathname descriptor as unused so that the
952 * descriptor isn't revisited for processing. Any real
953 * capabilities filtees have been added as new pathname
954 * descriptors following this descriptor.
956 pdp
= alist_item((Alist
*)dip
->di_info
, idx
);
957 pdp
->pd_flags
&= ~PD_TKN_CAP
;
961 * Now that any capability objects have been processed,
962 * remove any temporary link-map control list.
964 if (lmco
!= ALIST_OFF_DATA
)
965 remove_cntl(lml
, lmco
);
968 if (pdp
->pd_plen
== 0)
972 * Process an individual filtee.
974 if (pdp
->pd_info
== NULL
) {
975 const char *filtee
= pdp
->pd_pname
;
978 DBG_CALL(Dbg_file_filtee(lml
, NAME(ilmp
), filtee
, 0));
983 * Determine if the reference link map is already
984 * loaded. As an optimization compare the filtee with
985 * our interpretor. The most common filter is
986 * libdl.so.1, which is a filter on ld.so.1.
989 if (strcmp(filtee
, MSG_ORIG(MSG_PTH_RTLD_64
)) == 0) {
991 if (strcmp(filtee
, MSG_ORIG(MSG_PTH_RTLD
)) == 0) {
993 uint_t hflags
, rdflags
, cdflags
;
996 * Establish any flags for the handle (Grp_hdl).
998 * - This is a special, public, ld.so.1
1000 * - Only the first object on this handle
1001 * can supply symbols.
1002 * - This handle provides a filtee.
1004 * Essentially, this handle allows a caller to
1005 * reference the dl*() family of interfaces from
1008 hflags
= (GPH_PUBLIC
| GPH_LDSO
|
1009 GPH_FIRST
| GPH_FILTEE
);
1012 * Establish the flags for the referenced
1013 * dependency descriptor (Grp_desc).
1015 * - ld.so.1 is available for dlsym().
1016 * - ld.so.1 is available to relocate
1018 * - There's no need to add an dependencies
1021 rdflags
= (GPD_DLSYM
| GPD_RELOC
);
1024 * Establish the flags for this callers
1025 * dependency descriptor (Grp_desc).
1027 * - The explicit creation of a handle
1028 * creates a descriptor for the referenced
1029 * object and the parent (caller).
1031 cdflags
= GPD_PARENT
;
1033 nlmp
= lml_rtld
.lm_head
;
1034 if ((ghp
= hdl_create(&lml_rtld
, nlmp
, ilmp
,
1035 hflags
, rdflags
, cdflags
)) == NULL
)
1039 * Establish the filter handle to prevent any
1043 pdp
->pd_info
= (void *)ghp
;
1046 * Audit the filter/filtee established. Ignore
1047 * any return from the auditor, as we can't
1048 * allow ignore filtering to ld.so.1, otherwise
1049 * nothing is going to work.
1051 if (nlmp
&& ((lml
->lm_tflags
| AFLAGS(ilmp
)) &
1052 LML_TFLG_AUD_OBJFILTER
))
1053 (void) audit_objfilter(ilmp
, filtees
,
1057 Rej_desc rej
= { 0 };
1062 * Trace the inspection of this file, determine
1063 * any auditor substitution, and seed the file
1064 * descriptor with the originating name.
1066 if (load_trace(lml
, pdp
, clmp
, &fd
) == NULL
)
1070 * Establish a link-map control list for this
1073 if ((lmco
= create_cntl(lml
, 0)) == 0)
1077 * Locate and load the filtee.
1079 if ((nlmp
= load_path(lml
, lmco
, ilmp
, mode
,
1080 FLG_RT_PUBHDL
, &ghp
, &fd
, &rej
,
1082 file_notfound(LIST(ilmp
), filtee
, ilmp
,
1083 FLG_RT_PUBHDL
, &rej
);
1085 filtee
= pdp
->pd_pname
;
1088 * Establish the filter handle to prevent any
1092 ghp
->gh_flags
|= GPH_FILTEE
;
1093 pdp
->pd_info
= (void *)ghp
;
1095 FLAGS1(nlmp
) |= FL1_RT_USED
;
1099 * Audit the filter/filtee established. A
1100 * return of 0 indicates the auditor wishes to
1101 * ignore this filtee.
1103 if (nlmp
&& ((lml
->lm_tflags
| FLAGS1(ilmp
)) &
1104 LML_TFLG_AUD_OBJFILTER
)) {
1105 if (audit_objfilter(ilmp
, filtees
,
1113 * Finish processing the objects associated with
1114 * this request. Create an association between
1115 * this object and the originating filter to
1116 * provide sufficient information to tear down
1117 * this filtee if necessary.
1119 if (nlmp
&& ghp
&& (((nlmp
= analyze_lmc(lml
,
1120 lmco
, nlmp
, clmp
, in_nfavl
)) == NULL
) ||
1121 (relocate_lmc(lml
, lmco
, ilmp
, nlmp
,
1126 * If the filtee has been successfully
1127 * processed, then create an association
1128 * between the filter and filtee. This
1129 * association provides sufficient information
1130 * to tear down the filter and filtee if
1133 DBG_CALL(Dbg_file_hdl_title(DBG_HDL_ADD
));
1134 if (nlmp
&& ghp
&& (hdl_add(ghp
, ilmp
,
1135 GPD_FILTER
, NULL
) == NULL
))
1139 * Generate a diagnostic if the filtee couldn't
1143 DBG_CALL(Dbg_file_filtee(lml
, 0, filtee
,
1147 * If this filtee loading has failed, and we've
1148 * created a new link-map control list to which
1149 * this request has added objects, then remove
1150 * all the objects that have been associated to
1153 if ((nlmp
== NULL
) && (lmco
!= ALIST_OFF_DATA
))
1154 remove_lmc(lml
, clmp
, lmco
, name
);
1157 * Remove any temporary link-map control list.
1159 if (lmco
!= ALIST_OFF_DATA
)
1160 remove_cntl(lml
, lmco
);
1164 * If the filtee couldn't be loaded, null out the
1165 * path name descriptor entry, and continue the search.
1166 * Otherwise, the group handle is retained for future
1170 pdp
->pd_info
= NULL
;
1176 ghp
= (Grp_hdl
*)pdp
->pd_info
;
1179 * If name is NULL, we're here to trigger filtee loading.
1180 * Skip the symbol lookup so that we'll continue looking for
1181 * additional filtees.
1189 sl
.sl_flags
|= (LKUP_FIRST
| LKUP_DLSYM
);
1193 * Look for the symbol in the handles dependencies.
1195 for (ALIST_TRAVERSE(ghp
->gh_depends
, idx
, gdp
)) {
1196 if ((gdp
->gd_flags
& GPD_DLSYM
) == 0)
1200 * If our parent is a dependency don't look at
1201 * it (otherwise we are in a recursive loop).
1202 * This situation can occur with auxiliary
1203 * filters if the filtee has a dependency on the
1204 * filter. This dependency isn't necessary as
1205 * auxiliary filters are opened RTLD_PARENT, but
1206 * users may still unknowingly add an explicit
1207 * dependency to the parent.
1209 if ((sl
.sl_imap
= gdp
->gd_depend
) == ilmp
)
1212 if (((ret
= SYMINTP(sl
.sl_imap
)(&sl
, srp
, binfo
,
1214 (ghp
->gh_flags
& GPH_FIRST
))
1219 * If a symbol has been found, indicate the binding
1220 * and return the symbol.
1223 *binfo
|= DBG_BINFO_FILTEE
;
1229 * If this object is tagged to terminate filtee processing we're
1232 if (FLAGS1(ghp
->gh_ownlmp
) & FL1_RT_ENDFILTE
)
1237 * If we're just here to trigger filtee loading then we're done.
1243 * If no filtees have been found for a filter, clean up any path name
1244 * descriptors and disable their search completely. For auxiliary
1245 * filters we can reselect the symbol search function so that we never
1246 * enter this routine again for this object. For standard filters we
1247 * use the null symbol routine.
1250 remove_alist((Alist
**)&(dip
->di_info
), 1);
1251 elf_disable_filtee(ilmp
, dip
);
1258 * Focal point for disabling error messages for auxiliary filters. As an
1259 * auxiliary filter allows for filtee use, but provides a fallback should a
1260 * filtee not exist (or fail to load), any errors generated as a consequence of
1261 * trying to load the filtees are typically suppressed. Setting RT_FL_SILENCERR
1262 * suppresses errors generated by eprintf(), but ensures a debug diagnostic is
1263 * produced. ldd(1) employs printf(), and here the selection of whether to
1264 * print a diagnostic in regards to auxiliary filters is a little more complex.
1266 * - The determination of whether to produce an ldd message, or a fatal
1267 * error message is driven by LML_FLG_TRC_ENABLE.
1268 * - More detailed ldd messages may also be driven off of LML_FLG_TRC_WARN,
1269 * (ldd -d/-r), LML_FLG_TRC_VERBOSE (ldd -v), LML_FLG_TRC_SEARCH (ldd -s),
1270 * and LML_FLG_TRC_UNREF/LML_FLG_TRC_UNUSED (ldd -U/-u).
1271 * - If the calling object is lddstub, then several classes of message are
1272 * suppressed. The user isn't trying to diagnose lddstub, this is simply
1273 * a stub executable employed to preload a user specified library against.
1274 * - If RT_FL_SILENCERR is in effect then any generic ldd() messages should
1275 * be suppressed. All detailed ldd messages should still be produced.
1278 elf_lookup_filtee(Slookup
*slp
, Sresult
*srp
, uint_t
*binfo
, uint_t ndx
,
1281 Dyninfo
*dip
= &DYNINFO(slp
->sl_imap
)[ndx
];
1282 int ret
, silent
= 0;
1285 * Make sure this entry is still acting as a filter. We may have tried
1286 * to process this previously, and disabled it if the filtee couldn't
1287 * be processed. However, other entries may provide different filtees
1288 * that are yet to be completed.
1290 if (dip
->di_flags
== 0)
1294 * Indicate whether an error message is required should this filtee not
1295 * be found, based on the type of filter.
1297 if ((dip
->di_flags
& FLG_DI_AUXFLTR
) &&
1298 ((rtld_flags
& (RT_FL_WARNFLTR
| RT_FL_SILENCERR
)) == 0)) {
1299 rtld_flags
|= RT_FL_SILENCERR
;
1303 ret
= _elf_lookup_filtee(slp
, srp
, binfo
, ndx
, in_nfavl
);
1306 rtld_flags
&= ~RT_FL_SILENCERR
;
1312 * Compute the elf hash value (as defined in the ELF access library).
1313 * The form of the hash table is:
1326 elf_hash(const char *name
)
1332 hval
= (hval
<< 4) + *name
++;
1333 if ((g
= (hval
& 0xf0000000)) != 0)
1337 return ((ulong_t
)hval
);
1341 * Look up a symbol. The callers lookup information is passed in the Slookup
1342 * structure, and any resultant binding information is returned in the Sresult
1346 elf_find_sym(Slookup
*slp
, Sresult
*srp
, uint_t
*binfo
, int *in_nfavl
)
1348 const char *name
= slp
->sl_name
;
1349 Rt_map
*ilmp
= slp
->sl_imap
;
1350 ulong_t hash
= slp
->sl_hash
;
1351 uint_t ndx
, hashoff
, buckets
, *chainptr
;
1352 Sym
*sym
, *symtabptr
;
1353 char *strtabptr
, *strtabname
;
1358 * If we're only here to establish a symbols index, skip the diagnostic
1359 * used to trace a symbol search.
1361 if ((slp
->sl_flags
& LKUP_SYMNDX
) == 0)
1362 DBG_CALL(Dbg_syms_lookup(ilmp
, name
, MSG_ORIG(MSG_STR_ELF
)));
1364 if (HASH(ilmp
) == NULL
)
1367 buckets
= HASH(ilmp
)[0];
1369 hashoff
= ((uint_t
)hash
% buckets
) + 2;
1372 * Get the first symbol from the hash chain and initialize the string
1373 * and symbol table pointers.
1375 if ((ndx
= HASH(ilmp
)[hashoff
]) == 0)
1378 chainptr
= HASH(ilmp
) + 2 + buckets
;
1379 strtabptr
= STRTAB(ilmp
);
1380 symtabptr
= SYMTAB(ilmp
);
1383 sym
= symtabptr
+ ndx
;
1384 strtabname
= strtabptr
+ sym
->st_name
;
1387 * Compare the symbol found with the name required. If the
1388 * names don't match continue with the next hash entry.
1390 if ((*strtabname
++ != *name
) || strcmp(strtabname
, &name
[1])) {
1391 hashoff
= ndx
+ buckets
+ 2;
1392 if ((ndx
= chainptr
[ndx
]) != 0)
1398 * Symbols that are defined as hidden within an object usually
1399 * have any references from within the same object bound at
1400 * link-edit time, thus ld.so.1 is not involved. However, if
1401 * these are capabilities symbols, then references to them must
1402 * be resolved at runtime. A hidden symbol can only be bound
1403 * to by the object that defines the symbol.
1405 if ((sym
->st_shndx
!= SHN_UNDEF
) &&
1406 (ELF_ST_VISIBILITY(sym
->st_other
) == STV_HIDDEN
) &&
1407 (slp
->sl_cmap
!= ilmp
))
1411 * The Solaris ld does not put DT_VERSYM in the dynamic
1412 * section, but the GNU ld does. The GNU runtime linker
1413 * interprets the top bit of the 16-bit Versym value
1414 * (0x8000) as the "hidden" bit. If this bit is set,
1415 * the linker is supposed to act as if that symbol does
1416 * not exist. The hidden bit supports their versioning
1417 * scheme, which allows multiple incompatible functions
1418 * with the same name to exist at different versions
1419 * within an object. The Solaris linker does not support this
1420 * mechanism, or the model of interface evolution that
1421 * it allows, but we honor the hidden bit in GNU ld
1422 * produced objects in order to interoperate with them.
1424 if (VERSYM(ilmp
) && (VERSYM(ilmp
)[ndx
] & 0x8000)) {
1425 DBG_CALL(Dbg_syms_ignore_gnuver(ilmp
, name
,
1426 ndx
, VERSYM(ilmp
)[ndx
]));
1431 * If we're only here to establish a symbol's index, we're done.
1433 if (slp
->sl_flags
& LKUP_SYMNDX
) {
1434 srp
->sr_dmap
= ilmp
;
1440 * If we find a match and the symbol is defined, capture the
1441 * symbol pointer and the link map in which it was found.
1443 if (sym
->st_shndx
!= SHN_UNDEF
) {
1444 srp
->sr_dmap
= ilmp
;
1446 *binfo
|= DBG_BINFO_FOUND
;
1448 if ((FLAGS(ilmp
) & FLG_RT_OBJINTPO
) ||
1449 ((FLAGS(ilmp
) & FLG_RT_SYMINTPO
) &&
1450 is_sym_interposer(ilmp
, sym
)))
1451 *binfo
|= DBG_BINFO_INTERPOSE
;
1455 * If we find a match and the symbol is undefined, the
1456 * symbol type is a function, and the value of the symbol
1457 * is non zero, then this is a special case. This allows
1458 * the resolution of a function address to the plt[] entry.
1459 * See SPARC ABI, Dynamic Linking, Function Addresses for
1462 } else if ((slp
->sl_flags
& LKUP_SPEC
) &&
1463 (FLAGS(ilmp
) & FLG_RT_ISMAIN
) && (sym
->st_value
!= 0) &&
1464 (ELF_ST_TYPE(sym
->st_info
) == STT_FUNC
)) {
1465 srp
->sr_dmap
= ilmp
;
1467 *binfo
|= (DBG_BINFO_FOUND
| DBG_BINFO_PLTADDR
);
1469 if ((FLAGS(ilmp
) & FLG_RT_OBJINTPO
) ||
1470 ((FLAGS(ilmp
) & FLG_RT_SYMINTPO
) &&
1471 is_sym_interposer(ilmp
, sym
)))
1472 *binfo
|= DBG_BINFO_INTERPOSE
;
1483 * We've found a match. Determine if the defining object contains
1484 * symbol binding information.
1486 if ((sip
= SYMINFO(ilmp
)) != NULL
)
1490 * If this definition is a singleton, and we haven't followed a default
1491 * symbol search knowing that we're looking for a singleton (presumably
1492 * because the symbol definition has been changed since the referring
1493 * object was built), then reject this binding so that the caller can
1494 * fall back to a standard symbol search.
1496 if ((ELF_ST_VISIBILITY(sym
->st_other
) == STV_SINGLETON
) &&
1497 (((slp
->sl_flags
& LKUP_STANDARD
) == 0) ||
1498 (((slp
->sl_flags
& LKUP_SINGLETON
) == 0) &&
1499 (LIST(ilmp
)->lm_flags
& LML_FLG_GROUPSEXIST
)))) {
1500 DBG_CALL(Dbg_bind_reject(slp
->sl_cmap
, ilmp
, name
,
1501 DBG_BNDREJ_SINGLE
));
1502 *binfo
|= BINFO_REJSINGLE
;
1503 *binfo
&= ~DBG_BINFO_MSK
;
1508 * If this is a direct binding request, but the symbol definition has
1509 * disabled directly binding to it (presumably because the symbol
1510 * definition has been changed since the referring object was built),
1511 * reject this binding so that the caller can fall back to a standard
1514 if (sip
&& (slp
->sl_flags
& LKUP_DIRECT
) &&
1515 (sip
->si_flags
& SYMINFO_FLG_NOEXTDIRECT
)) {
1516 DBG_CALL(Dbg_bind_reject(slp
->sl_cmap
, ilmp
, name
,
1517 DBG_BNDREJ_DIRECT
));
1518 *binfo
|= BINFO_REJDIRECT
;
1519 *binfo
&= ~DBG_BINFO_MSK
;
1524 * If this is a binding request within an RTLD_GROUP family, and the
1525 * symbol has disabled directly binding to it, reject this binding so
1526 * that the caller can fall back to a standard symbol search.
1528 * Effectively, an RTLD_GROUP family achieves what can now be
1529 * established with direct bindings. However, various symbols have
1530 * been tagged as inappropriate for direct binding to (ie. libc:malloc).
1532 * A symbol marked as no-direct cannot be used within a group without
1533 * first ensuring that the symbol has not been interposed upon outside
1534 * of the group. A common example occurs when users implement their own
1535 * version of malloc() in the executable. Such a malloc() interposes on
1536 * the libc:malloc, and this interposition must be honored within the
1539 * Following any rejection, LKUP_WORLD is established as a means of
1540 * overriding this test as we return to a standard search.
1542 if (sip
&& (sip
->si_flags
& SYMINFO_FLG_NOEXTDIRECT
) &&
1543 ((MODE(slp
->sl_cmap
) & (RTLD_GROUP
| RTLD_WORLD
)) == RTLD_GROUP
) &&
1544 ((slp
->sl_flags
& LKUP_WORLD
) == 0)) {
1545 DBG_CALL(Dbg_bind_reject(slp
->sl_cmap
, ilmp
, name
,
1547 *binfo
|= BINFO_REJGROUP
;
1548 *binfo
&= ~DBG_BINFO_MSK
;
1553 * If this symbol is associated with capabilities, then each of the
1554 * capabilities instances needs to be compared against the system
1555 * capabilities. The best instance will be chosen to satisfy this
1558 if (CAP(ilmp
) && CAPINFO(ilmp
) && ELF_C_GROUP(CAPINFO(ilmp
)[ndx
]) &&
1559 (cap_match(srp
, ndx
, symtabptr
, strtabptr
) == 0))
1563 * Determine whether this object is acting as a filter.
1565 if (((flags1
= FLAGS1(ilmp
)) & MSK_RT_FILTER
) == 0)
1569 * Determine if this object offers per-symbol filtering, and if so,
1570 * whether this symbol references a filtee.
1572 if (sip
&& (flags1
& (FL1_RT_SYMSFLTR
| FL1_RT_SYMAFLTR
))) {
1574 * If this is a standard filter reference, and no standard
1575 * filtees remain to be inspected, we're done. If this is an
1576 * auxiliary filter reference, and no auxiliary filtees remain,
1577 * we'll fall through in case any object filtering is available.
1579 if ((sip
->si_flags
& SYMINFO_FLG_FILTER
) &&
1580 (SYMSFLTRCNT(ilmp
) == 0))
1583 if ((sip
->si_flags
& SYMINFO_FLG_FILTER
) ||
1584 ((sip
->si_flags
& SYMINFO_FLG_AUXILIARY
) &&
1585 SYMAFLTRCNT(ilmp
))) {
1589 * Initialize a local symbol result descriptor, using
1590 * the original symbol name.
1592 SRESULT_INIT(sr
, slp
->sl_name
);
1595 * This symbol has an associated filtee. Lookup the
1596 * symbol in the filtee, and if it is found return it.
1597 * If the symbol doesn't exist, and this is a standard
1598 * filter, return an error, otherwise fall through to
1599 * catch any object filtering that may be available.
1601 if (elf_lookup_filtee(slp
, &sr
, binfo
, sip
->si_boundto
,
1606 if (sip
->si_flags
& SYMINFO_FLG_FILTER
)
1612 * Determine if this object provides global filtering.
1614 if (flags1
& (FL1_RT_OBJSFLTR
| FL1_RT_OBJAFLTR
)) {
1615 if (OBJFLTRNDX(ilmp
) != FLTR_DISABLED
) {
1619 * Initialize a local symbol result descriptor, using
1620 * the original symbol name.
1622 SRESULT_INIT(sr
, slp
->sl_name
);
1625 * This object has an associated filtee. Lookup the
1626 * symbol in the filtee, and if it is found return it.
1627 * If the symbol doesn't exist, and this is a standard
1628 * filter, return and error, otherwise return the symbol
1629 * within the filter itself.
1631 if (elf_lookup_filtee(slp
, &sr
, binfo
, OBJFLTRNDX(ilmp
),
1638 if (flags1
& FL1_RT_OBJSFLTR
)
1645 * Create a new Rt_map structure for an ELF object and initialize
1649 elf_new_lmp(Lm_list
*lml
, Aliste lmco
, Fdesc
*fdp
, Addr addr
, size_t msize
,
1650 void *odyn
, Rt_map
*clmp
, int *in_nfavl
)
1652 const char *name
= fdp
->fd_nname
;
1654 Ehdr
*ehdr
= (Ehdr
*)addr
;
1655 Phdr
*phdr
, *tphdr
= NULL
, *dphdr
= NULL
, *uphdr
= NULL
;
1656 Dyn
*dyn
= (Dyn
*)odyn
;
1659 Addr base
, fltr
= 0, audit
= 0, cfile
= 0, crle
= 0;
1661 size_t lmsz
, rtsz
, epsz
, dynsz
= 0;
1664 DBG_CALL(Dbg_file_elf(lml
, name
, addr
, msize
, lml
->lm_lmidstr
, lmco
));
1667 * If this is a shared object, the base address of the shared object is
1668 * added to all address values defined within the object. Otherwise, if
1669 * this is an executable, all object addresses are used as is.
1671 if (ehdr
->e_type
== ET_EXEC
)
1677 * Traverse the program header table, picking off required items. This
1678 * traversal also provides for the sizing of the PT_DYNAMIC section.
1680 phdr
= (Phdr
*)((uintptr_t)ehdr
+ ehdr
->e_phoff
);
1681 for (ndx
= 0; ndx
< (int)ehdr
->e_phnum
; ndx
++,
1682 phdr
= (Phdr
*)((uintptr_t)phdr
+ ehdr
->e_phentsize
)) {
1683 switch (phdr
->p_type
) {
1686 dyn
= (Dyn
*)((uintptr_t)phdr
->p_vaddr
+ base
);
1692 cap
= (Cap
*)((uintptr_t)phdr
->p_vaddr
+ base
);
1694 case PT_SUNW_UNWIND
:
1695 case PT_SUNW_EH_FRAME
:
1704 * Determine the number of PT_DYNAMIC entries for the DYNINFO()
1705 * allocation. Sadly, this is a little larger than we really need,
1706 * as there are typically padding DT_NULL entries. However, adding
1707 * this data to the initial link-map allocation is a win.
1710 dyncnt
= dphdr
->p_filesz
/ sizeof (Dyn
);
1711 dynsz
= dyncnt
* sizeof (Dyninfo
);
1715 * Allocate space for the link-map, private elf information, and
1716 * DYNINFO() data. Once these are allocated and initialized,
1717 * remove_so(0, lmp) can be used to tear down the link-map allocation
1718 * should any failures occur.
1720 rtsz
= S_DROUND(sizeof (Rt_map
));
1721 epsz
= S_DROUND(sizeof (Rt_elfp
));
1722 lmsz
= rtsz
+ epsz
+ dynsz
;
1723 if ((lmp
= calloc(lmsz
, 1)) == NULL
)
1725 ELFPRV(lmp
) = (void *)((uintptr_t)lmp
+ rtsz
);
1726 DYNINFO(lmp
) = (Dyninfo
*)((uintptr_t)lmp
+ rtsz
+ epsz
);
1730 * All fields not filled in were set to 0 by calloc.
1732 NAME(lmp
) = (char *)name
;
1735 SYMINTP(lmp
) = elf_find_sym
;
1736 FCT(lmp
) = &elf_fct
;
1738 OBJFLTRNDX(lmp
) = FLTR_DISABLED
;
1741 DYNINFOCNT(lmp
) = dyncnt
;
1742 PTUNWIND(lmp
) = uphdr
;
1744 if (ehdr
->e_type
== ET_EXEC
)
1745 FLAGS(lmp
) |= FLG_RT_FIXED
;
1748 * Fill in rest of the link map entries with information from the file's
1749 * dynamic structure.
1757 Word lmtflags
= lml
->lm_tflags
;
1761 * Note, we use DT_NULL to terminate processing, and the
1762 * dynamic entry count as a fall back. Normally, a DT_NULL
1763 * entry marks the end of the dynamic section. Any non-NULL
1764 * items following the first DT_NULL are silently ignored.
1765 * This situation should only occur through use of elfedit(1)
1766 * or a similar tool.
1768 for (dynndx
= 0, pdyn
= NULL
, dip
= DYNINFO(lmp
);
1769 dynndx
< dyncnt
; dynndx
++, pdyn
= dyn
++, dip
++) {
1772 dip
->di_flags
|= FLG_DI_IGNORE
;
1776 switch ((Xword
)dyn
->d_tag
) {
1778 dip
->di_flags
|= ignore
= FLG_DI_IGNORE
;
1781 dip
->di_flags
|= FLG_DI_POSFLAG1
;
1785 dip
->di_flags
|= FLG_DI_NEEDED
;
1788 if (pdyn
&& (pdyn
->d_tag
== DT_POSFLAG_1
)) {
1790 * Identify any non-deferred lazy load for
1791 * future processing, unless LD_NOLAZYLOAD
1794 if ((pdyn
->d_un
.d_val
& DF_P1_LAZYLOAD
) &&
1795 ((lmtflags
& LML_TFLG_NOLAZYLD
) == 0))
1796 dip
->di_flags
|= FLG_DI_LAZY
;
1799 * Identify any group permission
1802 if (pdyn
->d_un
.d_val
& DF_P1_GROUPPERM
)
1803 dip
->di_flags
|= FLG_DI_GROUP
;
1806 * Identify any deferred dependencies.
1808 if (pdyn
->d_un
.d_val
& DF_P1_DEFERRED
)
1809 dip
->di_flags
|= FLG_DI_DEFERRED
;
1814 SYMTAB(lmp
) = (void *)(dyn
->d_un
.d_ptr
+ base
);
1816 case DT_SUNW_SYMTAB
:
1818 (void *)(dyn
->d_un
.d_ptr
+ base
);
1821 SUNWSYMSZ(lmp
) = dyn
->d_un
.d_val
;
1824 STRTAB(lmp
) = (void *)(dyn
->d_un
.d_ptr
+ base
);
1827 SYMENT(lmp
) = dyn
->d_un
.d_val
;
1830 if (dyn
->d_un
.d_val
& DTF_1_CONFEXP
)
1834 MOVESZ(lmp
) = dyn
->d_un
.d_val
;
1835 FLAGS(lmp
) |= FLG_RT_MOVE
;
1838 MOVEENT(lmp
) = dyn
->d_un
.d_val
;
1841 MOVETAB(lmp
) = (void *)(dyn
->d_un
.d_ptr
+ base
);
1846 * At this time, ld.so. can only handle one
1847 * type of relocation per object.
1849 REL(lmp
) = (void *)(dyn
->d_un
.d_ptr
+ base
);
1853 RELSZ(lmp
) = dyn
->d_un
.d_val
;
1857 RELENT(lmp
) = dyn
->d_un
.d_val
;
1861 RELACOUNT(lmp
) = (uint_t
)dyn
->d_un
.d_val
;
1864 HASH(lmp
) = (uint_t
*)(dyn
->d_un
.d_ptr
+ base
);
1868 (uint_t
*)(dyn
->d_un
.d_ptr
+ base
);
1871 PLTRELSZ(lmp
) = dyn
->d_un
.d_val
;
1874 JMPREL(lmp
) = (void *)(dyn
->d_un
.d_ptr
+ base
);
1877 if (dyn
->d_un
.d_ptr
!= 0)
1879 (void (*)())(dyn
->d_un
.d_ptr
+
1883 if (dyn
->d_un
.d_ptr
!= 0)
1885 (void (*)())(dyn
->d_un
.d_ptr
+
1889 INITARRAY(lmp
) = (Addr
*)(dyn
->d_un
.d_ptr
+
1892 case DT_INIT_ARRAYSZ
:
1893 INITARRAYSZ(lmp
) = (uint_t
)dyn
->d_un
.d_val
;
1896 FINIARRAY(lmp
) = (Addr
*)(dyn
->d_un
.d_ptr
+
1899 case DT_FINI_ARRAYSZ
:
1900 FINIARRAYSZ(lmp
) = (uint_t
)dyn
->d_un
.d_val
;
1902 case DT_PREINIT_ARRAY
:
1903 PREINITARRAY(lmp
) = (Addr
*)(dyn
->d_un
.d_ptr
+
1906 case DT_PREINIT_ARRAYSZ
:
1907 PREINITARRAYSZ(lmp
) = (uint_t
)dyn
->d_un
.d_val
;
1911 rpath
= dyn
->d_un
.d_val
;
1914 dip
->di_flags
|= FLG_DI_STDFLTR
;
1915 fltr
= dyn
->d_un
.d_val
;
1916 OBJFLTRNDX(lmp
) = dynndx
;
1917 FLAGS1(lmp
) |= FL1_RT_OBJSFLTR
;
1920 dip
->di_flags
|= FLG_DI_AUXFLTR
;
1921 if (!(rtld_flags
& RT_FL_NOAUXFLTR
)) {
1922 fltr
= dyn
->d_un
.d_val
;
1923 OBJFLTRNDX(lmp
) = dynndx
;
1925 FLAGS1(lmp
) |= FL1_RT_OBJAFLTR
;
1927 case DT_SUNW_FILTER
:
1929 (FLG_DI_STDFLTR
| FLG_DI_SYMFLTR
);
1931 FLAGS1(lmp
) |= FL1_RT_SYMSFLTR
;
1933 case DT_SUNW_AUXILIARY
:
1935 (FLG_DI_AUXFLTR
| FLG_DI_SYMFLTR
);
1936 if (!(rtld_flags
& RT_FL_NOAUXFLTR
)) {
1939 FLAGS1(lmp
) |= FL1_RT_SYMAFLTR
;
1942 if (!(rtld_flags
& RT_FL_NOAUDIT
)) {
1943 audit
= dyn
->d_un
.d_val
;
1944 FLAGS1(lmp
) |= FL1_RT_DEPAUD
;
1948 cfile
= dyn
->d_un
.d_val
;
1952 * DT_DEBUG entries are only created in
1953 * dynamic objects that require an interpretor
1954 * (ie. all dynamic executables and some shared
1955 * objects), and provide for a hand-shake with
1956 * old debuggers. This entry is initialized to
1957 * zero by the link-editor. If a debugger is
1958 * monitoring us, and has updated this entry,
1959 * set the debugger monitor flag, and finish
1960 * initializing the debugging structure. See
1961 * setup(). Also, switch off any configuration
1962 * object use as most debuggers can't handle
1963 * fixed dynamic executables as dependencies.
1965 if (dyn
->d_un
.d_ptr
)
1967 (RT_FL_DEBUGGER
| RT_FL_NOOBJALT
);
1968 dyn
->d_un
.d_ptr
= (Addr
)&r_debug
;
1971 VERNEED(lmp
) = (Verneed
*)(dyn
->d_un
.d_ptr
+
1976 VERNEEDNUM(lmp
) = (int)dyn
->d_un
.d_val
;
1979 VERDEF(lmp
) = (Verdef
*)(dyn
->d_un
.d_ptr
+
1984 VERDEFNUM(lmp
) = (int)dyn
->d_un
.d_val
;
1988 * The Solaris ld does not produce DT_VERSYM,
1989 * but the GNU ld does, in order to support
1990 * their style of versioning, which differs
1991 * from ours in some ways, while using the
1992 * same data structures. The presence of
1993 * DT_VERSYM therefore means that GNU
1994 * versioning rules apply to the given file.
1995 * If DT_VERSYM is not present, then Solaris
1996 * versioning rules apply.
1998 VERSYM(lmp
) = (Versym
*)(dyn
->d_un
.d_ptr
+
2002 if ((dyn
->d_un
.d_val
& DF_BIND_NOW
) &&
2003 ((rtld_flags2
& RT_FL2_BINDLAZY
) == 0)) {
2004 MODE(lmp
) |= RTLD_NOW
;
2005 MODE(lmp
) &= ~RTLD_LAZY
;
2009 FLAGS1(lmp
) |= FL1_RT_DTFLAGS
;
2010 if (dyn
->d_un
.d_val
& DF_SYMBOLIC
)
2011 FLAGS1(lmp
) |= FL1_RT_SYMBOLIC
;
2012 if ((dyn
->d_un
.d_val
& DF_BIND_NOW
) &&
2013 ((rtld_flags2
& RT_FL2_BINDLAZY
) == 0)) {
2014 MODE(lmp
) |= RTLD_NOW
;
2015 MODE(lmp
) &= ~RTLD_LAZY
;
2018 * Capture any static TLS use, and enforce that
2019 * this object be non-deletable.
2021 if (dyn
->d_un
.d_val
& DF_STATIC_TLS
) {
2022 FLAGS1(lmp
) |= FL1_RT_TLSSTAT
;
2023 MODE(lmp
) |= RTLD_NODELETE
;
2027 if (dyn
->d_un
.d_val
& DF_1_DISPRELPND
)
2028 FLAGS1(lmp
) |= FL1_RT_DISPREL
;
2029 if (dyn
->d_un
.d_val
& DF_1_GROUP
)
2031 (FLG_RT_SETGROUP
| FLG_RT_PUBHDL
);
2032 if ((dyn
->d_un
.d_val
& DF_1_NOW
) &&
2033 ((rtld_flags2
& RT_FL2_BINDLAZY
) == 0)) {
2034 MODE(lmp
) |= RTLD_NOW
;
2035 MODE(lmp
) &= ~RTLD_LAZY
;
2037 if (dyn
->d_un
.d_val
& DF_1_NODELETE
)
2038 MODE(lmp
) |= RTLD_NODELETE
;
2039 if (dyn
->d_un
.d_val
& DF_1_INITFIRST
)
2040 FLAGS(lmp
) |= FLG_RT_INITFRST
;
2041 if (dyn
->d_un
.d_val
& DF_1_NOOPEN
)
2042 FLAGS(lmp
) |= FLG_RT_NOOPEN
;
2043 if (dyn
->d_un
.d_val
& DF_1_LOADFLTR
)
2044 FLAGS(lmp
) |= FLG_RT_LOADFLTR
;
2045 if (dyn
->d_un
.d_val
& DF_1_NODUMP
)
2046 FLAGS(lmp
) |= FLG_RT_NODUMP
;
2047 if (dyn
->d_un
.d_val
& DF_1_CONFALT
)
2049 if (dyn
->d_un
.d_val
& DF_1_DIRECT
)
2050 FLAGS1(lmp
) |= FL1_RT_DIRECT
;
2051 if (dyn
->d_un
.d_val
& DF_1_NODEFLIB
)
2052 FLAGS1(lmp
) |= FL1_RT_NODEFLIB
;
2053 if (dyn
->d_un
.d_val
& DF_1_ENDFILTEE
)
2054 FLAGS1(lmp
) |= FL1_RT_ENDFILTE
;
2055 if (dyn
->d_un
.d_val
& DF_1_TRANS
)
2056 FLAGS(lmp
) |= FLG_RT_TRANS
;
2059 * Global auditing is only meaningful when
2060 * specified by the initiating object of the
2061 * process - typically the dynamic executable.
2062 * If this is the initiating object, its link-
2063 * map will not yet have been added to the
2064 * link-map list, and consequently the link-map
2065 * list is empty. (see setup()).
2067 if (dyn
->d_un
.d_val
& DF_1_GLOBAUDIT
) {
2068 if (lml_main
.lm_head
== NULL
)
2069 FLAGS1(lmp
) |= FL1_RT_GLOBAUD
;
2071 DBG_CALL(Dbg_audit_ignore(lmp
));
2075 * If this object identifies itself as an
2076 * interposer, but relocation processing has
2077 * already started, then demote it. It's too
2078 * late to guarantee complete interposition.
2081 if (dyn
->d_un
.d_val
&
2082 (DF_1_INTERPOSE
| DF_1_SYMINTPOSE
)) {
2083 if (lml
->lm_flags
& LML_FLG_STARTREL
) {
2084 DBG_CALL(Dbg_util_intoolate(lmp
));
2085 if (lml
->lm_flags
& LML_FLG_TRC_ENABLE
)
2087 MSG_INTL(MSG_LDD_REL_ERR2
),
2089 } else if (dyn
->d_un
.d_val
& DF_1_INTERPOSE
)
2090 FLAGS(lmp
) |= FLG_RT_OBJINTPO
;
2092 FLAGS(lmp
) |= FLG_RT_SYMINTPO
;
2097 SYMINFO(lmp
) = (Syminfo
*)(dyn
->d_un
.d_ptr
+
2101 SYMINENT(lmp
) = dyn
->d_un
.d_val
;
2104 PLTPAD(lmp
) = (void *)(dyn
->d_un
.d_ptr
+ base
);
2107 pltpadsz
= dyn
->d_un
.d_val
;
2109 case DT_SUNW_RTLDINF
:
2111 * Maintain a list of RTLDINFO structures.
2112 * Typically, libc is the only supplier, and
2113 * only one structure is provided. However,
2114 * multiple suppliers and multiple structures
2115 * are supported. For example, one structure
2116 * may provide thread_init, and another
2117 * structure may provide atexit reservations.
2119 if ((rti
= alist_append(&lml
->lm_rti
, NULL
,
2121 AL_CNT_RTLDINFO
)) == NULL
) {
2122 remove_so(0, lmp
, clmp
);
2126 rti
->rti_info
= (void *)(dyn
->d_un
.d_ptr
+
2129 case DT_SUNW_SORTENT
:
2130 SUNWSORTENT(lmp
) = dyn
->d_un
.d_val
;
2132 case DT_SUNW_SYMSORT
:
2134 (void *)(dyn
->d_un
.d_ptr
+ base
);
2136 case DT_SUNW_SYMSORTSZ
:
2137 SUNWSYMSORTSZ(lmp
) = dyn
->d_un
.d_val
;
2139 case DT_DEPRECATED_SPARC_REGISTER
:
2141 dip
->di_flags
|= FLG_DI_REGISTER
;
2142 FLAGS(lmp
) |= FLG_RT_REGSYMS
;
2145 CAP(lmp
) = (void *)(dyn
->d_un
.d_ptr
+ base
);
2147 case DT_SUNW_CAPINFO
:
2148 CAPINFO(lmp
) = (void *)(dyn
->d_un
.d_ptr
+ base
);
2150 case DT_SUNW_CAPCHAIN
:
2151 CAPCHAIN(lmp
) = (void *)(dyn
->d_un
.d_ptr
+
2154 case DT_SUNW_CAPCHAINENT
:
2155 CAPCHAINENT(lmp
) = dyn
->d_un
.d_val
;
2157 case DT_SUNW_CAPCHAINSZ
:
2158 CAPCHAINSZ(lmp
) = dyn
->d_un
.d_val
;
2164 * Update any Dyninfo string pointers now that STRTAB() is
2167 for (dynndx
= 0, dyn
= DYN(lmp
), dip
= DYNINFO(lmp
);
2168 !(dip
->di_flags
& FLG_DI_IGNORE
); dyn
++, dip
++) {
2170 switch ((Xword
)dyn
->d_tag
) {
2175 case DT_SUNW_FILTER
:
2176 case DT_SUNW_AUXILIARY
:
2177 dip
->di_name
= STRTAB(lmp
) + dyn
->d_un
.d_val
;
2183 * Assign any padding.
2186 if (pltpadsz
== (Xword
)0)
2189 PLTPADEND(lmp
) = (void *)((Addr
)PLTPAD(lmp
) +
2195 * A dynsym contains only global functions. We want to have
2196 * a version of it that also includes local functions, so that
2197 * dladdr() will be able to report names for local functions
2198 * when used to generate a stack trace for a stripped file.
2199 * This version of the dynsym is provided via DT_SUNW_SYMTAB.
2201 * In producing DT_SUNW_SYMTAB, ld uses a non-obvious trick
2202 * in order to avoid having to have two copies of the global
2203 * symbols held in DT_SYMTAB: The local symbols are placed in
2204 * a separate section than the globals in the dynsym, but the
2205 * linker conspires to put the data for these two sections adjacent
2206 * to each other. DT_SUNW_SYMTAB points at the top of the local
2207 * symbols, and DT_SUNW_SYMSZ is the combined length of both tables.
2209 * If the two sections are not adjacent, then something went wrong
2210 * at link time. We use ASSERT to kill the process if this is
2211 * a debug build. In a production build, we will silently ignore
2212 * the presence of the .ldynsym and proceed. We can detect this
2213 * situation by checking to see that DT_SYMTAB lies in
2214 * the range given by DT_SUNW_SYMTAB/DT_SUNW_SYMSZ.
2216 if ((SUNWSYMTAB(lmp
) != NULL
) &&
2217 (((char *)SYMTAB(lmp
) <= (char *)SUNWSYMTAB(lmp
)) ||
2218 (((char *)SYMTAB(lmp
) >=
2219 (SUNWSYMSZ(lmp
) + (char *)SUNWSYMTAB(lmp
)))))) {
2221 SUNWSYMTAB(lmp
) = NULL
;
2226 * If configuration file use hasn't been disabled, and a configuration
2227 * file hasn't already been set via an environment variable, see if any
2228 * application specific configuration file is specified. An LD_CONFIG
2229 * setting is used first, but if this image was generated via crle(1)
2230 * then a default configuration file is a fall-back.
2232 if ((!(rtld_flags
& RT_FL_NOCFG
)) && (config
->c_name
== NULL
)) {
2234 config
->c_name
= (const char *)(cfile
+
2235 (char *)STRTAB(lmp
));
2237 rtld_flags
|= RT_FL_CONFAPP
;
2241 RPATH(lmp
) = (char *)(rpath
+ (char *)STRTAB(lmp
));
2243 REFNAME(lmp
) = (char *)(fltr
+ (char *)STRTAB(lmp
));
2246 * For Intel ABI compatibility. It's possible that a JMPREL can be
2247 * specified without any other relocations (e.g. a dynamic executable
2248 * normally only contains .plt relocations). If this is the case then
2249 * no REL, RELSZ or RELENT will have been created. For us to be able
2250 * to traverse the .plt relocations under LD_BIND_NOW we need to know
2251 * the RELENT for these relocations. Refer to elf_reloc() for more
2254 if (!RELENT(lmp
) && JMPREL(lmp
))
2255 RELENT(lmp
) = sizeof (M_RELOC
);
2258 * Establish any per-object auditing. If we're establishing main's
2259 * link-map its too early to go searching for audit objects so just
2260 * hold the object name for later (see setup()).
2263 char *cp
= audit
+ (char *)STRTAB(lmp
);
2266 if (((AUDITORS(lmp
) =
2267 calloc(1, sizeof (Audit_desc
))) == NULL
) ||
2268 ((AUDITORS(lmp
)->ad_name
= strdup(cp
)) == NULL
)) {
2269 remove_so(0, lmp
, clmp
);
2272 if (lml_main
.lm_head
) {
2273 if (audit_setup(lmp
, AUDITORS(lmp
), 0,
2275 remove_so(0, lmp
, clmp
);
2278 AFLAGS(lmp
) |= AUDITORS(lmp
)->ad_flags
;
2279 lml
->lm_flags
|= LML_FLG_LOCAUDIT
;
2284 if (tphdr
&& (tls_assign(lml
, lmp
, tphdr
) == 0)) {
2285 remove_so(0, lmp
, clmp
);
2290 * A capabilities section should be identified by a DT_SUNW_CAP entry,
2291 * and if non-empty object capabilities are included, a PT_SUNWCAP
2292 * header should reference the section. Make sure CAP() is set
2295 if ((CAP(lmp
) == NULL
) && cap
)
2299 * Make sure any capabilities information or chain can be handled.
2301 if (CAPINFO(lmp
) && (CAPINFO(lmp
)[0] > CAPINFO_CURRENT
))
2302 CAPINFO(lmp
) = NULL
;
2303 if (CAPCHAIN(lmp
) && (CAPCHAIN(lmp
)[0] > CAPCHAIN_CURRENT
))
2304 CAPCHAIN(lmp
) = NULL
;
2307 * As part of processing dependencies, a file descriptor is populated
2308 * with capabilities information following validation.
2310 if (fdp
->fd_flags
& FLG_FD_ALTCHECK
) {
2311 FLAGS1(lmp
) |= FL1_RT_ALTCHECK
;
2312 CAPSET(lmp
) = fdp
->fd_scapset
;
2314 if (fdp
->fd_flags
& FLG_FD_ALTCAP
)
2315 FLAGS1(lmp
) |= FL1_RT_ALTCAP
;
2317 } else if ((cap
= CAP(lmp
)) != NULL
) {
2319 * Processing of the a.out and ld.so.1 does not involve a file
2320 * descriptor as exec() did all the work, so capture the
2321 * capabilities for these cases.
2323 while (cap
->c_tag
!= CA_SUNW_NULL
) {
2324 switch (cap
->c_tag
) {
2326 CAPSET(lmp
).sc_hw_1
= cap
->c_un
.c_val
;
2329 CAPSET(lmp
).sc_sf_1
= cap
->c_un
.c_val
;
2332 CAPSET(lmp
).sc_hw_2
= cap
->c_un
.c_val
;
2335 CAPSET(lmp
).sc_plat
= STRTAB(lmp
) +
2339 CAPSET(lmp
).sc_mach
= STRTAB(lmp
) +
2348 * If a capabilities chain table exists, duplicate it. The chain table
2349 * is inspected for each initial call to a capabilities family lead
2350 * symbol. From this chain, each family member is inspected to
2351 * determine the 'best' family member. The chain table is then updated
2352 * so that the best member is immediately selected for any further
2355 if (CAPCHAIN(lmp
)) {
2358 if ((capchain
= calloc(CAPCHAINSZ(lmp
), 1)) == NULL
)
2360 (void) memcpy(capchain
, CAPCHAIN(lmp
), CAPCHAINSZ(lmp
));
2361 CAPCHAIN(lmp
) = capchain
;
2365 * Add the mapped object to the end of the link map list.
2367 lm_append(lml
, lmco
, lmp
);
2370 * Start the system loading in the ELF information we'll be processing.
2373 (void) madvise((void *)ADDR(lmp
), (uintptr_t)REL(lmp
) +
2374 (uintptr_t)RELSZ(lmp
) - (uintptr_t)ADDR(lmp
),
2381 * Build full pathname of shared object from given directory name and filename.
2384 elf_get_so(const char *dir
, const char *file
, size_t dlen
, size_t flen
)
2386 static char pname
[PATH_MAX
];
2388 (void) strncpy(pname
, dir
, dlen
);
2389 pname
[dlen
++] = '/';
2390 (void) strncpy(&pname
[dlen
], file
, flen
+ 1);
2395 * The copy relocation is recorded in a copy structure which will be applied
2396 * after all other relocations are carried out. This provides for copying data
2397 * that must be relocated itself (ie. pointers in shared objects). This
2398 * structure also provides a means of binding RTLD_GROUP dependencies to any
2399 * copy relocations that have been taken from any group members.
2401 * If the size of the .bss area available for the copy information is not the
2402 * same as the source of the data inform the user if we're under ldd(1) control
2403 * (this checking was only established in 5.3, so by only issuing an error via
2404 * ldd(1) we maintain the standard set by previous releases).
2407 elf_copy_reloc(char *name
, Sym
*rsym
, Rt_map
*rlmp
, void *radd
, Sym
*dsym
,
2408 Rt_map
*dlmp
, const void *dadd
)
2411 Lm_list
*lml
= LIST(rlmp
);
2414 rc
.r_rsym
= rsym
; /* the new reference symbol and its */
2415 rc
.r_rlmp
= rlmp
; /* associated link-map */
2416 rc
.r_dlmp
= dlmp
; /* the defining link-map */
2417 rc
.r_dsym
= dsym
; /* the original definition */
2421 if (rsym
->st_size
> dsym
->st_size
)
2422 rc
.r_size
= (size_t)dsym
->st_size
;
2424 rc
.r_size
= (size_t)rsym
->st_size
;
2426 if (alist_append(©_R(dlmp
), &rc
, sizeof (Rel_copy
),
2427 AL_CNT_COPYREL
) == NULL
) {
2428 if (!(lml
->lm_flags
& LML_FLG_TRC_WARN
))
2433 if (!(FLAGS1(dlmp
) & FL1_RT_COPYTOOK
)) {
2434 if (aplist_append(©_S(rlmp
), dlmp
,
2435 AL_CNT_COPYREL
) == NULL
) {
2436 if (!(lml
->lm_flags
& LML_FLG_TRC_WARN
))
2441 FLAGS1(dlmp
) |= FL1_RT_COPYTOOK
;
2445 * If we are tracing (ldd), warn the user if
2446 * 1) the size from the reference symbol differs from the
2447 * copy definition. We can only copy as much data as the
2448 * reference (dynamic executables) entry allows.
2449 * 2) the copy definition has STV_PROTECTED visibility.
2451 if (lml
->lm_flags
& LML_FLG_TRC_WARN
) {
2452 if (rsym
->st_size
!= dsym
->st_size
) {
2453 (void) printf(MSG_INTL(MSG_LDD_CPY_SIZDIF
),
2454 _conv_reloc_type(M_R_COPY
), demangle(name
),
2455 NAME(rlmp
), EC_XWORD(rsym
->st_size
),
2456 NAME(dlmp
), EC_XWORD(dsym
->st_size
));
2457 if (rsym
->st_size
> dsym
->st_size
)
2458 (void) printf(MSG_INTL(MSG_LDD_CPY_INSDATA
),
2461 (void) printf(MSG_INTL(MSG_LDD_CPY_DATRUNC
),
2465 if (ELF_ST_VISIBILITY(dsym
->st_other
) == STV_PROTECTED
) {
2466 (void) printf(MSG_INTL(MSG_LDD_CPY_PROT
),
2467 _conv_reloc_type(M_R_COPY
), demangle(name
),
2472 DBG_CALL(Dbg_reloc_apply_val(lml
, ELF_DBG_RTLD
, (Xword
)radd
,
2478 * Determine the symbol location of an address within a link-map. Look for
2479 * the nearest symbol (whose value is less than or equal to the required
2480 * address). This is the object specific part of dladdr().
2483 elf_dladdr(ulong_t addr
, Rt_map
*lmp
, Dl_info
*dlip
, void **info
, int flags
)
2485 ulong_t ndx
, cnt
, base
, _value
;
2486 Sym
*sym
, *_sym
= NULL
;
2489 uint_t
*dynaddr_ndx
;
2490 uint_t dynaddr_n
= 0;
2494 * If SUNWSYMTAB() is non-NULL, then it sees a special version of
2495 * the dynsym that starts with any local function symbols that exist in
2496 * the library and then moves to the data held in SYMTAB(). In this
2497 * case, SUNWSYMSZ tells us how long the symbol table is. The
2498 * availability of local function symbols will enhance the results
2501 * If SUNWSYMTAB() is non-NULL, then there might also be a
2502 * SUNWSYMSORT() vector associated with it. SUNWSYMSORT() contains
2503 * an array of indices into SUNWSYMTAB, sorted by increasing
2504 * address. We can use this to do an O(log N) search instead of a
2505 * brute force search.
2507 * If SUNWSYMTAB() is NULL, then SYMTAB() references a dynsym that
2508 * contains only global symbols. In that case, the length of
2509 * the symbol table comes from the nchain field of the related
2510 * symbol lookup hash table.
2513 if (SUNWSYMSZ(lmp
) == 0) {
2516 * If we don't have a .hash table there are no symbols
2519 if (HASH(lmp
) == NULL
)
2523 sym
= SUNWSYMTAB(lmp
);
2524 cnt
= SUNWSYMSZ(lmp
) / SYMENT(lmp
);
2525 dynaddr_ndx
= SUNWSYMSORT(lmp
);
2526 if (dynaddr_ndx
!= NULL
)
2527 dynaddr_n
= SUNWSYMSORTSZ(lmp
) / SUNWSORTENT(lmp
);
2530 if (FLAGS(lmp
) & FLG_RT_FIXED
)
2535 if (dynaddr_n
> 0) { /* Binary search */
2536 long low
= 0, low_bnd
;
2537 long high
= dynaddr_n
- 1, high_bnd
;
2542 * Note that SUNWSYMSORT only contains symbols types that
2543 * supply memory addresses, so there's no need to check and
2544 * filter out any other types.
2548 while (low
<= high
) {
2549 mid
= (low
+ high
) / 2;
2550 mid_sym
= &sym
[dynaddr_ndx
[mid
]];
2551 value
= mid_sym
->st_value
+ base
;
2553 if ((sym
[dynaddr_ndx
[high
]].st_value
+ base
) >=
2557 } else if (addr
> value
) {
2558 if ((sym
[dynaddr_ndx
[low
]].st_value
+ base
) <=
2569 * If the above didn't find it exactly, then we must
2570 * return the closest symbol with a value that doesn't
2571 * exceed the one we are looking for. If that symbol exists,
2572 * it will lie in the range bounded by low_bnd and
2573 * high_bnd. This is a linear search, but a short one.
2576 for (mid
= low_bnd
; mid
<= high_bnd
; mid
++) {
2577 mid_sym
= &sym
[dynaddr_ndx
[mid
]];
2578 value
= mid_sym
->st_value
+ base
;
2579 if (addr
>= value
) {
2587 } else { /* Linear search */
2588 for (_value
= 0, sym
++, ndx
= 1; ndx
< cnt
; ndx
++, sym
++) {
2590 * Skip expected symbol types that are not functions
2592 * - A symbol table starts with an undefined symbol
2593 * in slot 0. If we are using SUNWSYMTAB(),
2594 * there will be a second undefined symbol
2595 * right before the globals.
2596 * - The local part of SUNWSYMTAB() contains a
2597 * series of function symbols. Each section
2598 * starts with an initial STT_FILE symbol.
2600 if ((sym
->st_shndx
== SHN_UNDEF
) ||
2601 (ELF_ST_TYPE(sym
->st_info
) == STT_FILE
))
2604 value
= sym
->st_value
+ base
;
2614 * Note, because we accept local and global symbols
2615 * we could find a section symbol that matches the
2616 * associated address, which means that the symbol
2617 * name will be null. In this case continue the
2618 * search in case we can find a global symbol of
2621 if ((value
== addr
) &&
2622 (ELF_ST_TYPE(sym
->st_info
) != STT_SECTION
))
2627 _flags
= flags
& RTLD_DL_MASK
;
2629 if (_flags
== RTLD_DL_SYMENT
)
2630 *info
= (void *)_sym
;
2631 else if (_flags
== RTLD_DL_LINKMAP
)
2632 *info
= (void *)lmp
;
2634 dlip
->dli_sname
= str
+ _sym
->st_name
;
2635 dlip
->dli_saddr
= (void *)_value
;
2638 * addr lies between the beginning of the mapped segment and
2639 * the first global symbol. We have no symbol to return
2640 * and the caller requires one. We use _START_, the base
2641 * address of the mapping.
2644 if (_flags
== RTLD_DL_SYMENT
) {
2646 * An actual symbol struct is needed, so we
2647 * construct one for _START_. To do this in a
2648 * fully accurate way requires a different symbol
2649 * for each mapped segment. This requires the
2650 * use of dynamic memory and a mutex. That's too much
2651 * plumbing for a fringe case of limited importance.
2653 * Fortunately, we can simplify:
2654 * - Only the st_size and st_info fields are useful
2655 * outside of the linker internals. The others
2656 * reference things that outside code cannot see,
2657 * and can be set to 0.
2658 * - It's just a label and there is no size
2659 * to report. So, the size should be 0.
2660 * This means that only st_info needs a non-zero
2661 * (constant) value. A static struct will suffice.
2662 * It must be const (readonly) so the caller can't
2663 * change its meaning for subsequent callers.
2665 static const Sym fsym
= { 0, 0, 0,
2666 ELF_ST_INFO(STB_LOCAL
, STT_OBJECT
) };
2667 *info
= (void *) &fsym
;
2670 dlip
->dli_sname
= MSG_ORIG(MSG_SYM_START
);
2671 dlip
->dli_saddr
= (void *) ADDR(lmp
);
2676 * This routine is called as a last fall-back to search for a symbol from a
2677 * standard relocation or dlsym(). To maintain lazy loadings goal of reducing
2678 * the number of objects mapped, any symbol search is first carried out using
2679 * the objects that already exist in the process (either on a link-map list or
2680 * handle). If a symbol can't be found, and lazy dependencies are still
2681 * pending, this routine loads the dependencies in an attempt to locate the
2685 elf_lazy_find_sym(Slookup
*slp
, Sresult
*srp
, uint_t
*binfo
, int *in_nfavl
)
2687 static APlist
*alist
= NULL
;
2689 Rt_map
*lmp1
, *lmp
= slp
->sl_imap
, *clmp
= slp
->sl_cmap
;
2690 const char *name
= slp
->sl_name
;
2696 * It's quite possible we've been here before to process objects,
2697 * therefore reinitialize our dynamic list.
2700 aplist_reset(alist
);
2703 * Discard any relocation index from further symbol searches. This
2704 * index has already been used to trigger any necessary lazy-loads,
2705 * and it might be because one of these lazy loads has failed that
2706 * we're performing this fallback. By removing the relocation index
2707 * we don't try and perform the same failed lazy loading activity again.
2712 * Determine the callers link-map list so that we can monitor whether
2713 * new objects have been added.
2716 lmc
= (Lm_cntl
*)alist_item_by_offset(lml
->lm_lists
, CNTL(clmp
));
2719 * Generate a local list of new objects to process. This list can grow
2720 * as each object supplies its own lazy dependencies.
2722 if (aplist_append(&alist
, lmp
, AL_CNT_LAZYFIND
) == NULL
)
2725 for (APLIST_TRAVERSE(alist
, idx1
, lmp1
)) {
2727 Dyninfo
*dip
, *pdip
;
2730 * Loop through the lazy DT_NEEDED entries examining each object
2731 * for the required symbol. If the symbol is not found, the
2732 * object is in turn added to the local alist, so that the
2733 * objects lazy DT_NEEDED entries can be examined.
2736 for (dynndx
= 0, dip
= DYNINFO(lmp
), pdip
= NULL
;
2737 !(dip
->di_flags
& FLG_DI_IGNORE
); dynndx
++, pdip
= dip
++) {
2740 Rt_map
*nlmp
, *llmp
;
2745 if (((dip
->di_flags
& FLG_DI_LAZY
) == 0) ||
2750 * If this object has already failed to lazy load, and
2751 * we're still processing the same runtime linker
2752 * operation that produced the failure, don't bother
2753 * to try and load the object again.
2755 if ((dip
->di_flags
& FLG_DI_LAZYFAIL
) && pdip
&&
2756 (pdip
->di_flags
& FLG_DI_POSFLAG1
)) {
2757 if (pdip
->di_info
== (void *)ld_entry_cnt
)
2760 dip
->di_flags
&= ~FLG_DI_LAZYFAIL
;
2761 pdip
->di_info
= NULL
;
2765 * Determine the last link-map presently on the callers
2766 * link-map control list.
2768 llmp
= lmc
->lc_tail
;
2771 * Try loading this lazy dependency. If the object
2772 * can't be loaded, consider this non-fatal and continue
2773 * the search. Lazy loaded dependencies need not exist
2774 * and their loading should only turn out to be fatal
2775 * if they are required to satisfy a relocation.
2777 * A successful lazy load can mean one of two things:
2779 * - new objects have been loaded, in which case the
2780 * objects will have been analyzed, relocated, and
2781 * finally moved to the callers control list.
2782 * - the objects are already loaded, and this lazy
2783 * load has simply associated the referenced object
2784 * with it's lazy dependencies.
2786 * If new objects are loaded, look in these objects
2787 * first. Note, a new object can be the object being
2788 * referenced by this lazy load, however we can also
2789 * descend into multiple lazy loads as we relocate this
2792 * If the symbol hasn't been found, use the referenced
2793 * objects handle, as it might have dependencies on
2794 * objects that are already loaded. Note that existing
2795 * objects might have already been searched and skipped
2796 * as non-available to this caller. However, a lazy
2797 * load might have caused the promotion of modes, or
2798 * added this object to the family of the caller. In
2799 * either case, the handle associated with the object
2800 * is then used to carry out the symbol search.
2802 if ((nlmp
= elf_lazy_load(lmp
, &sl1
, dynndx
, name
,
2803 FLG_RT_PRIHDL
, &ghp
, in_nfavl
)) == NULL
)
2806 if (NEXT_RT_MAP(llmp
)) {
2808 * Look in any new objects.
2810 sl1
.sl_imap
= NEXT_RT_MAP(llmp
);
2811 sl1
.sl_flags
&= ~LKUP_STDRELOC
;
2814 * Initialize a local symbol result descriptor,
2815 * using the original symbol name.
2817 SRESULT_INIT(sr
, slp
->sl_name
);
2819 if (lookup_sym(&sl1
, &sr
, binfo
, in_nfavl
)) {
2826 * Use the objects handle to inspect the family of
2827 * objects associated with the handle. Note, there's
2828 * a possibility of overlap with the above search,
2829 * should a lazy load bring in new objects and
2830 * reference existing objects.
2833 for (ALIST_TRAVERSE(ghp
->gh_depends
, idx2
, gdp
)) {
2834 if ((gdp
->gd_depend
!= NEXT_RT_MAP(llmp
)) &&
2835 (gdp
->gd_flags
& GPD_DLSYM
)) {
2837 sl2
.sl_imap
= gdp
->gd_depend
;
2838 sl2
.sl_flags
|= LKUP_FIRST
;
2841 * Initialize a local symbol result
2842 * descriptor, using the original
2845 SRESULT_INIT(sr
, slp
->sl_name
);
2847 if (lookup_sym(&sl2
, &sr
, binfo
,
2856 * Some dlsym() operations are already traversing a
2857 * link-map (dlopen(0)), and thus there's no need to
2858 * save them on the dynamic dependency list.
2860 if (slp
->sl_flags
& LKUP_NODESCENT
)
2863 if (aplist_test(&alist
, nlmp
, AL_CNT_LAZYFIND
) == 0)
2872 * Warning message for bad r_offset.
2875 elf_reloc_bad(Rt_map
*lmp
, void *rel
, uchar_t rtype
, ulong_t roffset
,
2878 const char *name
= NULL
;
2879 Lm_list
*lml
= LIST(lmp
);
2882 if ((lml
->lm_flags
& LML_FLG_TRC_ENABLE
) &&
2883 (((rtld_flags
& RT_FL_SILENCERR
) == 0) ||
2884 (lml
->lm_flags
& LML_FLG_TRC_VERBOSE
)))
2889 if ((trace
== 0) && (DBG_ENABLED
== 0))
2893 Sym
*symref
= (Sym
*)((ulong_t
)SYMTAB(lmp
) +
2894 (rsymndx
* SYMENT(lmp
)));
2896 if (ELF_ST_BIND(symref
->st_info
) != STB_LOCAL
)
2897 name
= (char *)(STRTAB(lmp
) + symref
->st_name
);
2901 name
= MSG_INTL(MSG_STR_UNKNOWN
);
2906 rstr
= _conv_reloc_type((uint_t
)rtype
);
2907 (void) printf(MSG_INTL(MSG_LDD_REL_ERR1
), rstr
, name
,
2912 Dbg_reloc_error(lml
, ELF_DBG_RTLD
, M_MACH
, M_REL_SHT_TYPE
, rel
, name
);
2916 * Resolve a static TLS relocation.
2919 elf_static_tls(Rt_map
*lmp
, Sym
*sym
, void *rel
, uchar_t rtype
, char *name
,
2920 ulong_t roffset
, long value
)
2922 Lm_list
*lml
= LIST(lmp
);
2925 * Relocations against a static TLS block have limited support once
2926 * process initialization has completed. Any error condition should be
2927 * discovered by testing for DF_STATIC_TLS as part of loading an object,
2928 * however individual relocations are tested in case the dynamic flag
2929 * had not been set when this object was built.
2931 if (PTTLS(lmp
) == NULL
) {
2932 DBG_CALL(Dbg_reloc_in(lml
, ELF_DBG_RTLD
, M_MACH
,
2933 M_REL_SHT_TYPE
, rel
, NULL
, 0, name
));
2934 eprintf(lml
, ERR_FATAL
, MSG_INTL(MSG_REL_BADTLS
),
2935 _conv_reloc_type((uint_t
)rtype
), NAME(lmp
),
2936 name
? demangle(name
) : MSG_INTL(MSG_STR_UNKNOWN
));
2941 * If no static TLS has been set aside for this object, determine if
2942 * any can be obtained. Enforce that any object using static TLS is
2945 if (TLSSTATOFF(lmp
) == 0) {
2946 FLAGS1(lmp
) |= FL1_RT_TLSSTAT
;
2947 MODE(lmp
) |= RTLD_NODELETE
;
2949 if (tls_assign(lml
, lmp
, PTTLS(lmp
)) == 0) {
2950 DBG_CALL(Dbg_reloc_in(lml
, ELF_DBG_RTLD
, M_MACH
,
2951 M_REL_SHT_TYPE
, rel
, NULL
, 0, name
));
2952 eprintf(lml
, ERR_FATAL
, MSG_INTL(MSG_REL_BADTLS
),
2953 _conv_reloc_type((uint_t
)rtype
), NAME(lmp
),
2954 name
? demangle(name
) : MSG_INTL(MSG_STR_UNKNOWN
));
2960 * Typically, a static TLS offset is maintained as a symbols value.
2961 * For local symbols that are not apart of the dynamic symbol table,
2962 * the TLS relocation points to a section symbol, and the static TLS
2963 * offset was deposited in the associated GOT table. Make sure the GOT
2964 * is cleared, so that the value isn't reused in do_reloc().
2966 if (ELF_ST_BIND(sym
->st_info
) == STB_LOCAL
) {
2967 if ((ELF_ST_TYPE(sym
->st_info
) == STT_SECTION
)) {
2968 value
= *(long *)roffset
;
2969 *(long *)roffset
= 0;
2971 value
= sym
->st_value
;
2974 return (-(TLSSTATOFF(lmp
) - value
));
2978 * If the symbol is not found and the reference was not to a weak symbol, report
2979 * an error. Weak references may be unresolved.
2982 elf_reloc_error(Rt_map
*lmp
, const char *name
, void *rel
, uint_t binfo
)
2984 Lm_list
*lml
= LIST(lmp
);
2987 * Under crle(1), relocation failures are ignored.
2989 if (lml
->lm_flags
& LML_FLG_IGNRELERR
)
2993 * Under ldd(1), unresolved references are reported. However, if the
2994 * original reference is EXTERN or PARENT these references are ignored
2995 * unless ldd's -p option is in effect.
2997 if (lml
->lm_flags
& LML_FLG_TRC_WARN
) {
2998 if (((binfo
& DBG_BINFO_REF_MSK
) == 0) ||
2999 ((lml
->lm_flags
& LML_FLG_TRC_NOPAREXT
) != 0)) {
3000 (void) printf(MSG_INTL(MSG_LDD_SYM_NFOUND
),
3001 demangle(name
), NAME(lmp
));
3007 * Otherwise, the unresolved references is fatal.
3009 DBG_CALL(Dbg_reloc_in(lml
, ELF_DBG_RTLD
, M_MACH
, M_REL_SHT_TYPE
, rel
,
3011 eprintf(lml
, ERR_FATAL
, MSG_INTL(MSG_REL_NOSYM
), NAME(lmp
),