analyze.c revision 8af2c5b9bdbf69a55f079d7ad9483d38fae9f023
2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 1988 AT&T
2N/A * All Rights Reserved
2N/A *
2N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include "_synonyms.h"
2N/A
2N/A#include <string.h>
2N/A#include <stdio.h>
2N/A#include <unistd.h>
2N/A#include <sys/stat.h>
2N/A#include <sys/mman.h>
2N/A#include <fcntl.h>
2N/A#include <limits.h>
2N/A#include <dlfcn.h>
2N/A#include <errno.h>
2N/A#include <link.h>
2N/A#include <debug.h>
2N/A#include <conv.h>
2N/A#include "_rtld.h"
2N/A#include "_audit.h"
2N/A#include "_elf.h"
2N/A#include "msg.h"
2N/A
2N/Astatic Fct * vector[] = {
2N/A &elf_fct,
2N/A#ifdef A_OUT
2N/A &aout_fct,
2N/A#endif
2N/A 0
2N/A};
2N/A
2N/A/*
2N/A * If a load filter flag is in effect, and this object is a filter, trigger the
2N/A * loading of all its filtees. The load filter flag is in effect when creating
2N/A * configuration files, or when under the control of ldd(1), or the LD_LOADFLTR
2N/A * environment variable is set, or this object was built with the -zloadfltr
2N/A * flag. Otherwise, filtee loading is deferred until triggered by a relocation.
2N/A */
2N/Astatic void
2N/Aload_filtees(Rt_map *lmp)
2N/A{
2N/A if ((FLAGS1(lmp) & MSK_RT_FILTER) &&
2N/A ((FLAGS(lmp) & FLG_RT_LOADFLTR) ||
2N/A (LIST(lmp)->lm_tflags & LML_TFLG_LOADFLTR))) {
2N/A Dyninfo * dip = DYNINFO(lmp);
2N/A uint_t cnt, max = DYNINFOCNT(lmp);
2N/A Slookup sl;
2N/A
2N/A sl.sl_name = 0;
2N/A sl.sl_hash = 0;
2N/A sl.sl_imap = sl.sl_cmap = lmp;
2N/A
2N/A for (cnt = 0; cnt < max; cnt++, dip++) {
2N/A if (((dip->di_flags & MSK_DI_FILTER) == 0) ||
2N/A ((dip->di_flags & FLG_DI_AUXFLTR) &&
2N/A (rtld_flags & RT_FL_NOAUXFLTR)))
2N/A continue;
2N/A (void) elf_lookup_filtee(&sl, 0, 0, cnt);
2N/A }
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * Analyze one or more link-maps of a link map control list. This routine is
2N/A * called at startup to continue the processing of the main executable. It is
2N/A * also called each time a new set of objects are loaded, ie. from filters,
2N/A * lazy-loaded objects, or dlopen().
2N/A *
2N/A * In each instance we traverse the link-map control list starting with the
2N/A * initial object. As dependencies are analyzed they are added to the link-map
2N/A * control list. Thus the list grows as we traverse it - this results in the
2N/A * breadth first ordering of all needed objects.
2N/A */
2N/Aint
2N/Aanalyze_lmc(Lm_list *lml, Aliste nlmco, Rt_map *nlmp)
2N/A{
2N/A Rt_map *lmp = nlmp;
2N/A Lm_cntl *nlmc;
2N/A int ret = 1;
2N/A
2N/A /*
2N/A * If this link-map control list is being analyzed, return. The object
2N/A * that has just been added will be picked up by the existing analysis
2N/A * thread. Note, this is only really meaningful during process init-
2N/A * ialization, as objects are added to the main link-map control list.
2N/A * Following this initialization, each family of objects that are loaded
2N/A * are added to a new link-map control list.
2N/A */
2N/A /* LINTED */
2N/A nlmc = (Lm_cntl *)((char *)lml->lm_lists + nlmco);
2N/A if (nlmc->lc_flags & LMC_FLG_ANALYZING)
2N/A return (1);
2N/A
2N/A /*
2N/A * If this object doesn't belong to the present link-map control list
2N/A * then it must already have been analyzed, or it is in the process of
2N/A * being analyzed prior to us recursing into this analysis. In either
2N/A * case, ignore the object as it's already being taken care of.
2N/A */
2N/A if (nlmco != CNTL(nlmp))
2N/A return (1);
2N/A
2N/A nlmc->lc_flags |= LMC_FLG_ANALYZING;
2N/A
2N/A for (; lmp; lmp = (Rt_map *)NEXT(lmp)) {
2N/A if (FLAGS(lmp) &
2N/A (FLG_RT_ANALZING | FLG_RT_ANALYZED | FLG_RT_DELETE))
2N/A continue;
2N/A
2N/A /*
2N/A * Indicate that analyzing is under way.
2N/A */
2N/A FLAGS(lmp) |= FLG_RT_ANALZING;
2N/A
2N/A /*
2N/A * If this link map represents a relocatable object, then we
2N/A * need to finish the link-editing of the object at this point.
2N/A */
2N/A if (FLAGS(lmp) & FLG_RT_OBJECT) {
2N/A if (elf_obj_fini(lml, lmp) == 0) {
2N/A if (lml->lm_flags & LML_FLG_TRC_ENABLE)
2N/A continue;
2N/A ret = 0;
2N/A break;
2N/A }
2N/A }
2N/A
2N/A DBG_CALL(Dbg_file_analyze(lmp));
2N/A
2N/A /*
2N/A * Establish any dependencies this object requires.
2N/A */
2N/A if (LM_NEEDED(lmp)(lml, nlmco, lmp) == 0) {
2N/A if (lml->lm_flags & LML_FLG_TRC_ENABLE)
2N/A continue;
2N/A ret = 0;
2N/A break;
2N/A }
2N/A
2N/A FLAGS(lmp) &= ~FLG_RT_ANALZING;
2N/A FLAGS(lmp) |= FLG_RT_ANALYZED;
2N/A
2N/A /*
2N/A * If we're building a configuration file, determine if this
2N/A * object is a filter and if so load its filtees. This
2N/A * traversal is only necessary for crle(1), as typical use of
2N/A * an object will load filters as part of relocation processing.
2N/A */
2N/A if (MODE(nlmp) & RTLD_CONFGEN)
2N/A load_filtees(lmp);
2N/A
2N/A /*
2N/A * If an interposer has been added, it will have been inserted
2N/A * in the link-map before the link we're presently analyzing.
2N/A * Break out of this analysis loop and return to the head of
2N/A * the link-map control list to analyze the interposer. Note
2N/A * that this rescan preserves the breadth first loading of
2N/A * dependencies.
2N/A */
2N/A /* LINTED */
2N/A nlmc = (Lm_cntl *)((char *)lml->lm_lists + nlmco);
2N/A if (nlmc->lc_flags & LMC_FLG_REANALYZE) {
2N/A nlmc->lc_flags &= ~LMC_FLG_REANALYZE;
2N/A lmp = nlmc->lc_head;
2N/A }
2N/A }
2N/A
2N/A /* LINTED */
2N/A nlmc = (Lm_cntl *)((char *)lml->lm_lists + nlmco);
2N/A nlmc->lc_flags &= ~LMC_FLG_ANALYZING;
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * Copy relocation test. If the symbol definition is within .bss, then it's
2N/A * zero filled, and as the destination is within .bss, we can skip copying
2N/A * zero's to zero's. However, if the destination object has a MOVE table, it's
2N/A * .bss might contain non-zero data, in which case copy it regardless.
2N/A */
2N/Astatic int
2N/Acopy_zerobits(Rt_map *dlmp, Sym *dsym)
2N/A{
2N/A if ((FLAGS(dlmp) & FLG_RT_MOVE) == 0) {
2N/A Mmap *mmaps;
2N/A caddr_t daddr = (caddr_t)dsym->st_value;
2N/A
2N/A if ((FLAGS(dlmp) & FLG_RT_FIXED) == 0)
2N/A daddr += ADDR(dlmp);
2N/A
2N/A for (mmaps = MMAPS(dlmp); mmaps->m_vaddr; mmaps++) {
2N/A if ((mmaps->m_fsize != mmaps->m_msize) &&
2N/A (daddr >= (mmaps->m_vaddr + mmaps->m_fsize)) &&
2N/A (daddr < (mmaps->m_vaddr + mmaps->m_msize)))
2N/A return (1);
2N/A }
2N/A }
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Relocate an individual object.
2N/A */
2N/Astatic int
2N/Arelocate_so(Lm_list *lml, Rt_map *lmp, int *relocated, int now)
2N/A{
2N/A /*
2N/A * If we're running under ldd(1), and haven't been asked to trace any
2N/A * warnings, skip any actual relocation processing.
2N/A */
2N/A if (((lml->lm_flags & LML_FLG_TRC_ENABLE) == 0) ||
2N/A (lml->lm_flags & LML_FLG_TRC_WARN)) {
2N/A
2N/A if (relocated)
2N/A (*relocated)++;
2N/A
2N/A if ((LM_RELOC(lmp)(lmp, now) == 0) &&
2N/A ((lml->lm_flags & LML_FLG_TRC_ENABLE) == 0))
2N/A return (0);
2N/A }
2N/A return (1);
2N/A}
2N/A
2N/A/*
2N/A * Relocate the objects on a link-map control list.
2N/A */
2N/Astatic int
2N/A_relocate_lmc(Lm_list *lml, Rt_map *nlmp, int *relocated)
2N/A{
2N/A Rt_map *lmp;
2N/A
2N/A for (lmp = nlmp; lmp; lmp = (Rt_map *)NEXT(lmp)) {
2N/A /*
2N/A * If this object has already been relocated, we're done. If
2N/A * this object is being deleted, skip it, there's probably a
2N/A * relocation error somewhere that's causing this deletion.
2N/A */
2N/A if (FLAGS(lmp) &
2N/A (FLG_RT_RELOCING | FLG_RT_RELOCED | FLG_RT_DELETE))
2N/A continue;
2N/A
2N/A /*
2N/A * Indicate that relocation processing is under way.
2N/A */
2N/A FLAGS(lmp) |= FLG_RT_RELOCING;
2N/A
2N/A /*
2N/A * Relocate the object.
2N/A */
2N/A if (relocate_so(lml, lmp, relocated, 0) == 0)
2N/A return (0);
2N/A
2N/A /*
2N/A * Indicate that the objects relocation is complete.
2N/A */
2N/A FLAGS(lmp) &= ~FLG_RT_RELOCING;
2N/A FLAGS(lmp) |= FLG_RT_RELOCED;
2N/A
2N/A /*
2N/A * Mark this object's init is available for harvesting. Under
2N/A * ldd(1) this marking is necessary for -i (tsort) gathering.
2N/A */
2N/A lml->lm_init++;
2N/A lml->lm_flags |= LML_FLG_OBJADDED;
2N/A
2N/A /*
2N/A * Process any move data (not necessary under ldd()).
2N/A */
2N/A if ((FLAGS(lmp) & FLG_RT_MOVE) &&
2N/A ((lml->lm_flags & LML_FLG_TRC_ENABLE) == 0))
2N/A move_data(lmp);
2N/A
2N/A /*
2N/A * Determine if this object is a filter, and if a load filter
2N/A * flag is in effect, trigger the loading of all its filtees.
2N/A */
2N/A load_filtees(lmp);
2N/A }
2N/A
2N/A /*
2N/A * Perform special copy relocations. These are only meaningful for
2N/A * dynamic executables (fixed and head of their link-map list). If
2N/A * this ever has to change then the infrastructure of COPY() has to
2N/A * change as presently this element is used to capture both receiver
2N/A * and supplier of copy data.
2N/A */
2N/A if ((FLAGS(nlmp) & FLG_RT_FIXED) && (nlmp == LIST(nlmp)->lm_head) &&
2N/A (((lml->lm_flags & LML_FLG_TRC_ENABLE) == 0) ||
2N/A (lml->lm_flags & LML_FLG_TRC_WARN))) {
2N/A Rt_map ** lmpp;
2N/A Aliste off1;
2N/A Word tracing;
2N/A
2N/A#if defined(__i386)
2N/A if (elf_copy_gen(nlmp) == 0)
2N/A return (0);
2N/A#endif
2N/A if (COPY(nlmp) == 0)
2N/A return (1);
2N/A
2N/A if ((LIST(nlmp)->lm_flags & LML_FLG_TRC_ENABLE) &&
2N/A (((rtld_flags & RT_FL_SILENCERR) == 0) ||
2N/A (LIST(nlmp)->lm_flags & LML_FLG_TRC_VERBOSE)))
2N/A tracing = 1;
2N/A else
2N/A tracing = 0;
2N/A
2N/A DBG_CALL(Dbg_util_nl(lml, DBG_NL_STD));
2N/A
2N/A for (ALIST_TRAVERSE(COPY(nlmp), off1, lmpp)) {
2N/A Rt_map * lmp = *lmpp;
2N/A Rel_copy * rcp;
2N/A Aliste off2;
2N/A
2N/A for (ALIST_TRAVERSE(COPY(lmp), off2, rcp)) {
2N/A int zero;
2N/A
2N/A /*
2N/A * Only copy the bits if it's from non-zero
2N/A * filled memory.
2N/A */
2N/A zero = copy_zerobits(rcp->r_dlmp, rcp->r_dsym);
2N/A DBG_CALL(Dbg_reloc_copy(rcp->r_dlmp, nlmp,
2N/A rcp->r_name, zero));
2N/A if (zero)
2N/A continue;
2N/A
2N/A (void) memcpy(rcp->r_radd, rcp->r_dadd,
2N/A rcp->r_size);
2N/A
2N/A if ((tracing == 0) || ((FLAGS1(rcp->r_dlmp) &
2N/A FL1_RT_DISPREL) == 0))
2N/A continue;
2N/A
2N/A (void) printf(MSG_INTL(MSG_LDD_REL_CPYDISP),
2N/A demangle(rcp->r_name), NAME(rcp->r_dlmp));
2N/A }
2N/A }
2N/A
2N/A DBG_CALL(Dbg_util_nl(lml, DBG_NL_STD));
2N/A
2N/A free(COPY(nlmp));
2N/A COPY(nlmp) = 0;
2N/A }
2N/A return (1);
2N/A}
2N/A
2N/Aint
2N/Arelocate_lmc(Lm_list *lml, Aliste nlmco, Rt_map *clmp, Rt_map *nlmp)
2N/A{
2N/A int lret = 1, pret = 1;
2N/A Alist *alp;
2N/A Aliste plmco;
2N/A Lm_cntl *plmc, *nlmc;
2N/A
2N/A /*
2N/A * If this link-map control list is being relocated, return. The object
2N/A * that has just been added will be picked up by the existing relocation
2N/A * thread. Note, this is only really meaningful during process init-
2N/A * ialization, as objects are added to the main link-map control list.
2N/A * Following this initialization, each family of objects that are loaded
2N/A * are added to a new link-map control list.
2N/A */
2N/A /* LINTED */
2N/A nlmc = (Lm_cntl *)((char *)lml->lm_lists + nlmco);
2N/A
2N/A if (nlmc->lc_flags & LMC_FLG_RELOCATING)
2N/A return (1);
2N/A
2N/A nlmc->lc_flags |= LMC_FLG_RELOCATING;
2N/A
2N/A /*
2N/A * Relocate one or more link-maps of a link map control list. If this
2N/A * object doesn't belong to the present link-map control list then it
2N/A * must already have been relocated, or it is in the process of being
2N/A * relocated prior to us recursing into this relocation. In either
2N/A * case, ignore the object as it's already being taken care of, however,
2N/A * fall through and capture any relocation promotions that might have
2N/A * been established from the reference mode of this object.
2N/A *
2N/A * If we're generating a configuration file using crle(1), two passes
2N/A * may be involved. Under the first pass, RTLD_CONFGEN is set. Under
2N/A * this pass, crle() loads objects into the process address space. No
2N/A * relocation is necessary at this point, we simply need to analyze the
2N/A * objects to insure any directly bound dependencies, filtees, etc.
2N/A * get loaded. Although we skip the relocation, fall through to insure
2N/A * any control lists are maintained appropriately.
2N/A *
2N/A * If objects are to be dldump(3c)'ed, crle(1) makes a second pass,
2N/A * using RTLD_NOW and RTLD_CONFGEN. The RTLD_NOW effectively carries
2N/A * out the relocations of all loaded objects.
2N/A */
2N/A if ((nlmco == CNTL(nlmp)) &&
2N/A ((MODE(nlmp) & (RTLD_NOW | RTLD_CONFGEN)) != RTLD_CONFGEN)) {
2N/A int relocated = 0;
2N/A
2N/A /*
2N/A * Determine whether the initial link-map control list has
2N/A * started relocation. From this point, should any interposing
2N/A * objects be added to this link-map control list, the objects
2N/A * are demoted to standard objects. Their interposition can't
2N/A * be guaranteed once relocations have been carried out.
2N/A */
2N/A if (nlmco == ALO_DATA)
2N/A lml->lm_flags |= LML_FLG_STARTREL;
2N/A
2N/A /*
2N/A * Relocate the link-map control list. Should this relocation
2N/A * fail, clean up this link-map list. Relocations within this
2N/A * list may have required relocation promotions on other lists,
2N/A * so before acting upon these, and possibly adding more objects
2N/A * to the present link-map control list, try and clean up any
2N/A * failed objects now.
2N/A */
2N/A lret = _relocate_lmc(lml, nlmp, &relocated);
2N/A if ((lret == 0) && (nlmco != ALO_DATA))
2N/A remove_lmc(lml, clmp, nlmc, nlmco, NAME(nlmp));
2N/A }
2N/A
2N/A /*
2N/A * Determine the new, and previous link-map control lists.
2N/A */
2N/A /* LINTED */
2N/A nlmc = (Lm_cntl *)((char *)lml->lm_lists + nlmco);
2N/A if (nlmco == ALO_DATA) {
2N/A plmco = nlmco;
2N/A plmc = nlmc;
2N/A } else {
2N/A plmco = nlmco - lml->lm_lists->al_size;
2N/A /* LINTED */
2N/A plmc = (Lm_cntl *)((char *)lml->lm_lists + plmco);
2N/A }
2N/A
2N/A /*
2N/A * Having completed this control list of objects, they can now be bound
2N/A * to from other objects. Move this control list to the control list
2N/A * that precedes it. Although this control list may have only bound to
2N/A * controls lists much higher up the control list stack, it must only
2N/A * be moved up one control list so as to preserve the link-map order
2N/A * that may have already been traversed in search of symbols.
2N/A */
2N/A if (lret && (nlmco != ALO_DATA) && nlmc->lc_head)
2N/A lm_move(lml, nlmco, plmco, nlmc, plmc);
2N/A
2N/A /*
2N/A * Determine whether existing objects that have already been relocated,
2N/A * need any additional relocations performed. This can occur when new
2N/A * objects are loaded with RTLD_NOW, and these new objects have
2N/A * dependencies on objects that are already loaded. Note, that we peel
2N/A * any relocation promotions off of one control list at a time. This
2N/A * prevents relocations from being bound to objects that might yet fail
2N/A * to relocate themselves.
2N/A */
2N/A while ((alp = plmc->lc_now) != 0) {
2N/A Aliste off;
2N/A Rt_map **lmpp;
2N/A
2N/A /*
2N/A * Remove the relocation promotion list, as performing more
2N/A * relocations may result in discovering more objects that need
2N/A * promotion.
2N/A */
2N/A plmc->lc_now = 0;
2N/A
2N/A for (ALIST_TRAVERSE(alp, off, lmpp)) {
2N/A Rt_map *lmp = *lmpp;
2N/A
2N/A /*
2N/A * If the original relocation of the link-map control
2N/A * list failed, or one of the relocation promotions of
2N/A * this loop has failed, demote any pending objects
2N/A * relocation mode.
2N/A */
2N/A if ((lret == 0) || (pret == 0)) {
2N/A MODE(lmp) &= ~RTLD_NOW;
2N/A MODE(lmp) |= RTLD_LAZY;
2N/A continue;
2N/A }
2N/A
2N/A /*
2N/A * If a relocation fails, save the error condition.
2N/A * It's possible that all new objects on the original
2N/A * link-map control list have been relocated
2N/A * successfully, but if the user request requires
2N/A * promoting objects that have already been loaded, we
2N/A * have to indicate that this operation couldn't be
2N/A * performed. The unrelocated objects are in use on
2N/A * another control list, and may continue to be used.
2N/A * If the .plt that resulted in the error is called,
2N/A * then the process will receive a fatal error at that
2N/A * time. But, the .plt may never be called.
2N/A */
2N/A if (relocate_so(lml, lmp, 0, 1) == 0)
2N/A pret = 0;
2N/A }
2N/A
2N/A /*
2N/A * Having promoted any objects, determine whether additional
2N/A * dependencies were added, and if so move them to the previous
2N/A * link-map control list.
2N/A */
2N/A /* LINTED */
2N/A nlmc = (Lm_cntl *)((char *)lml->lm_lists + nlmco);
2N/A /* LINTED */
2N/A plmc = (Lm_cntl *)((char *)lml->lm_lists + plmco);
2N/A if ((nlmco != ALO_DATA) && nlmc->lc_head)
2N/A lm_move(lml, nlmco, plmco, nlmc, plmc);
2N/A free(alp);
2N/A }
2N/A
2N/A /*
2N/A * If relocations have been successful, indicate that relocations are
2N/A * no longer active for this control list. Otherwise, leave the
2N/A * relocation flag, as this flag is used to determine the style of
2N/A * cleanup (see remove_lmc()).
2N/A */
2N/A if (lret && pret) {
2N/A /* LINTED */
2N/A nlmc = (Lm_cntl *)((char *)lml->lm_lists + nlmco);
2N/A nlmc->lc_flags &= ~LMC_FLG_RELOCATING;
2N/A
2N/A return (1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Inherit the first rejection message for possible later diagnostics.
2N/A *
2N/A * Any attempt to process a file that is unsuccessful, should be accompanied
2N/A * with an error diagnostic. However, some operations like searching for a
2N/A * simple filename, involve trying numerous paths, and an error message for each
2N/A * lookup is not required. Although a multiple search can fail, it's possible
2N/A * that a file was found, but was rejected because it was the wrong type.
2N/A * To satisfy these possibilities, the first failure is recorded as a rejection
2N/A * message, and this message is used later for a more specific diagnostic.
2N/A *
2N/A * File searches are focused at load_one(), and from here a rejection descriptor
2N/A * is passed down to various child routines. If these child routines can
2N/A * process multiple files, then they will maintain their own rejection desc-
2N/A * riptor. This is filled in for any failures, and a diagnostic produced to
2N/A * reflect the failure. The child routines then employ rejection_inherit() to
2N/A * pass the first rejection message back to load_one().
2N/A *
2N/A * Note that the name, and rejection string must be duplicated, as the name
2N/A * buffer and error string buffer (see conv_ routines) may be reused for
2N/A * additional processing or rejection messages.
2N/A */
2N/Avoid
2N/Arejection_inherit(Rej_desc *rej1, Rej_desc *rej2)
2N/A{
2N/A if (rej2->rej_type && (rej1->rej_type == 0)) {
2N/A rej1->rej_type = rej2->rej_type;
2N/A rej1->rej_info = rej2->rej_info;
2N/A rej1->rej_flag = rej2->rej_flag;
2N/A if (rej2->rej_name)
2N/A rej1->rej_name = strdup(rej2->rej_name);
2N/A if (rej2->rej_str) {
2N/A if ((rej1->rej_str = strdup(rej2->rej_str)) == NULL)
2N/A rej1->rej_str = MSG_ORIG(MSG_EMG_ENOMEM);
2N/A }
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * Determine the object type of a file.
2N/A */
2N/AFct *
2N/Aare_u_this(Rej_desc *rej, int fd, struct stat *status, const char *name)
2N/A{
2N/A int i;
2N/A char *maddr = 0;
2N/A
2N/A fmap->fm_fsize = status->st_size;
2N/A
2N/A /*
2N/A * If this is a directory (which can't be mmap()'ed) generate a precise
2N/A * error message.
2N/A */
2N/A if ((status->st_mode & S_IFMT) == S_IFDIR) {
2N/A rej->rej_type = SGS_REJ_STR;
2N/A rej->rej_str = strerror(EISDIR);
2N/A return (0);
2N/A }
2N/A
2N/A /*
2N/A * Map in the first page of the file. When this buffer is first used,
2N/A * the mapping is a single system page. This is typically enough to
2N/A * inspect the ehdr and phdrs of the file, and can be reused for each
2N/A * file that get loaded. If a larger mapping is required to read the
2N/A * ehdr and phdrs, a new mapping is created (see elf_map_it()). This
2N/A * new mapping is again used for each new file loaded. Some objects,
2N/A * such as filters, only take up one page, and in this case this mapping
2N/A * will suffice for the file.
2N/A */
2N/A maddr = mmap(fmap->fm_maddr, fmap->fm_msize, (PROT_READ | PROT_EXEC),
2N/A fmap->fm_mflags, fd, 0);
2N/A#if defined(MAP_ALIGN)
2N/A if ((maddr == MAP_FAILED) && (errno == EINVAL)) {
2N/A /*
2N/A * If the mapping failed, and we used MAP_ALIGN, assume we're
2N/A * on a system that doesn't support this option. Try again
2N/A * without MAP_ALIGN.
2N/A */
2N/A if (fmap->fm_mflags & MAP_ALIGN) {
2N/A rtld_flags2 |= RT_FL2_NOMALIGN;
2N/A fmap_setup();
2N/A
2N/A maddr = (char *)mmap(fmap->fm_maddr, fmap->fm_msize,
2N/A (PROT_READ | PROT_EXEC), fmap->fm_mflags, fd, 0);
2N/A }
2N/A }
2N/A#endif
2N/A if (maddr == MAP_FAILED) {
2N/A rej->rej_type = SGS_REJ_STR;
2N/A rej->rej_str = strerror(errno);
2N/A return (0);
2N/A }
2N/A
2N/A /*
2N/A * From now on we will re-use fmap->fm_maddr as the mapping address
2N/A * so we augment the flags with MAP_FIXED and drop any MAP_ALIGN.
2N/A */
2N/A fmap->fm_maddr = maddr;
2N/A fmap->fm_mflags |= MAP_FIXED;
2N/A#if defined(MAP_ALIGN)
2N/A fmap->fm_mflags &= ~MAP_ALIGN;
2N/A#endif
2N/A
2N/A /*
2N/A * Search through the object vectors to determine what kind of
2N/A * object we have.
2N/A */
2N/A for (i = 0; vector[i]; i++) {
2N/A if ((vector[i]->fct_are_u_this)(rej))
2N/A return (vector[i]);
2N/A else if (rej->rej_type) {
2N/A Rt_map *lmp;
2N/A
2N/A /*
2N/A * If this object is an explicitly defined shared
2N/A * object under inspection by ldd, and contains a
2N/A * incompatible hardware capabilities requirement, then
2N/A * inform the user, but continue processing.
2N/A *
2N/A * XXXX - ldd -v for any rej failure.
2N/A */
2N/A if ((rej->rej_type == SGS_REJ_HWCAP_1) &&
2N/A (lml_main.lm_flags & LML_FLG_TRC_LDDSTUB) &&
2N/A ((lmp = lml_main.lm_head) != 0) &&
2N/A (FLAGS1(lmp) & FL1_RT_LDDSTUB) &&
2N/A (NEXT(lmp) == 0)) {
2N/A (void) printf(MSG_INTL(MSG_LDD_GEN_HWCAP_1),
2N/A name, rej->rej_str);
2N/A return (vector[i]);
2N/A }
2N/A return (0);
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Unknown file type.
2N/A */
2N/A rej->rej_type = SGS_REJ_UNKFILE;
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Helper routine for is_so_matched() that consolidates matching a path name,
2N/A * or file name component of a link-map name.
2N/A */
2N/Astatic int
2N/A_is_so_matched(const char *name, const char *str, int path)
2N/A{
2N/A const char *_str;
2N/A
2N/A if ((path == 0) && ((_str = strrchr(str, '/')) != NULL))
2N/A _str++;
2N/A else
2N/A _str = str;
2N/A
2N/A return (strcmp(name, _str));
2N/A}
2N/A
2N/A/*
2N/A * Determine whether a search name matches one of the names associated with a
2N/A * link-map. A link-map contains several names:
2N/A *
2N/A * . a NAME() - typically the full pathname of an object that has been
2N/A * loaded. For example, when looking for the dependency "libc.so.1", a
2N/A * search path is applied, with the eventual NAME() being "/lib/ld.so.1".
2N/A * The name of the executable is typically a simple filename, such as
2N/A * "main", as this is the name passed to exec() to start the process.
2N/A *
2N/A * . a PATHNAME() - this is maintained if the resolved NAME() is different
2N/A * to NAME(), ie. the original name is a symbolic link. This is also
2N/A * the resolved full pathname for a dynamic executable.
2N/A *
2N/A * . a list of ALIAS() names - these are alternative names by which the
2N/A * object has been found, ie. when dependencies are loaded through a
2N/A * variety of different symbolic links.
2N/A *
2N/A * The name pattern matching can differ depending on whether we are looking
2N/A * for a full path name (path != 0), or a simple file name (path == 0). Full
2N/A * path names typically match NAME() or PATHNAME() entries, so these link-map
2N/A * names are inspected first when a full path name is being searched for.
2N/A * Simple file names typically match ALIAS() names, so these link-map names are
2N/A * inspected first when a simple file name is being searched for.
2N/A *
2N/A * For all full path name searches, the link-map names are taken as is. For
2N/A * simple file name searches, only the file name component of any link-map
2N/A * names are used for comparison.
2N/A */
2N/Astatic Rt_map *
2N/Ais_so_matched(Rt_map *lmp, const char *name, int path)
2N/A{
2N/A Aliste off;
2N/A const char **cpp;
2N/A
2N/A /*
2N/A * A pathname is typically going to match a NAME() or PATHNAME(), so
2N/A * check these first.
2N/A */
2N/A if (path) {
2N/A if (strcmp(name, NAME(lmp)) == 0)
2N/A return (lmp);
2N/A
2N/A if (PATHNAME(lmp) != NAME(lmp)) {
2N/A if (strcmp(name, PATHNAME(lmp)) == 0)
2N/A return (lmp);
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Typically, dependencies are specified as simple file names
2N/A * (DT_NEEDED == libc.so.1), which are expanded to full pathnames to
2N/A * open the file. The full pathname is NAME(), and the original name
2N/A * is maintained on the ALIAS() list.
2N/A *
2N/A * If this is a simple filename, or a pathname has failed to match the
2N/A * NAME() and PATHNAME() check above, look through the ALIAS() list.
2N/A */
2N/A for (ALIST_TRAVERSE(ALIAS(lmp), off, cpp)) {
2N/A /*
2N/A * If we're looking for a simple filename, _is_so_matched()
2N/A * will reduce the ALIAS name to its simple name.
2N/A */
2N/A if (_is_so_matched(name, *cpp, path) == 0)
2N/A return (lmp);
2N/A }
2N/A
2N/A /*
2N/A * Finally, if this is a simple file name, and any ALIAS() search has
2N/A * been completed, match the simple file name of NAME() and PATHNAME().
2N/A */
2N/A if (path == 0) {
2N/A if (_is_so_matched(name, NAME(lmp), 0) == 0)
2N/A return (lmp);
2N/A
2N/A if (PATHNAME(lmp) != NAME(lmp)) {
2N/A if (_is_so_matched(name, PATHNAME(lmp), 0) == 0)
2N/A return (lmp);
2N/A }
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Files are opened by ld.so.1 to satisfy dependencies, filtees and dlopen()
2N/A * requests. Each request investigates the file based upon the callers
2N/A * environment, and once a full path name has been established a check is made
2N/A * against the FullpathNode AVL tree and a device/inode check, to ensure the
2N/A * same file isn't mapped multiple times. See file_open().
2N/A *
2N/A * However, there are one of two cases where a test for an existing file name
2N/A * needs to be carried out, such as dlopen(NOLOAD) requests, dldump() requests,
2N/A * and as a final fallback to dependency loading. These requests are handled
2N/A * by is_so_loaded().
2N/A *
2N/A * A traversal through the callers link-map list is carried out, and from each
2N/A * link-map, a comparison is made against all of the various names by which the
2N/A * object has been referenced. The subroutine, is_so_matched() compares the
2N/A * link-map names against the name being searched for. Whether the search name
2N/A * is a full path name or a simple file name, governs what comparisons are made.
2N/A *
2N/A * A full path name, which is a fully resolved path name that starts with a "/"
2N/A * character, or a relative path name that includes a "/" character, must match
2N/A * the link-map names explicitly. A simple file name, which is any name *not*
2N/A * containing a "/" character, are matched against the file name component of
2N/A * any link-map names.
2N/A */
2N/ARt_map *
2N/Ais_so_loaded(Lm_list *lml, const char *name)
2N/A{
2N/A Rt_map *lmp;
2N/A avl_index_t where;
2N/A Lm_cntl *lmc;
2N/A Aliste off;
2N/A int path = 0;
2N/A
2N/A /*
2N/A * If the name is a full path name, first determine if the path name is
2N/A * registered in the FullpathNode AVL tree.
2N/A */
2N/A if ((name[0] == '/') &&
2N/A ((lmp = fpavl_loaded(lml, name, &where)) != NULL) &&
2N/A ((FLAGS(lmp) & (FLG_RT_OBJECT | FLG_RT_DELETE)) == 0))
2N/A return (lmp);
2N/A
2N/A /*
2N/A * Determine whether the name is a simple file name, or a path name.
2N/A */
2N/A if (strchr(name, '/'))
2N/A path++;
2N/A
2N/A /*
2N/A * Loop through the callers link-map lists.
2N/A */
2N/A for (ALIST_TRAVERSE(lml->lm_lists, off, lmc)) {
2N/A for (lmp = lmc->lc_head; lmp; lmp = (Rt_map *)NEXT(lmp)) {
2N/A if (FLAGS(lmp) & (FLG_RT_OBJECT | FLG_RT_DELETE))
2N/A continue;
2N/A
2N/A if (is_so_matched(lmp, name, path))
2N/A return (lmp);
2N/A }
2N/A }
2N/A return ((Rt_map *)0);
2N/A}
2N/A
2N/A/*
2N/A * Tracing is enabled by the LD_TRACE_LOADED_OPTIONS environment variable which
2N/A * is normally set from ldd(1). For each link map we load, print the load name
2N/A * and the full pathname of the shared object.
2N/A */
2N/A/* ARGSUSED4 */
2N/Astatic void
2N/Atrace_so(Rt_map *clmp, Rej_desc *rej, const char *name, const char *path,
2N/A int alter, const char *nfound)
2N/A{
2N/A const char *str = MSG_ORIG(MSG_STR_EMPTY);
2N/A const char *reject = MSG_ORIG(MSG_STR_EMPTY);
2N/A char _reject[PATH_MAX];
2N/A
2N/A /*
2N/A * The first time through trace_so() will only have lddstub on the
2N/A * link-map list and the preloaded shared object is supplied as "path".
2N/A * As we don't want to print this shared object as a dependency, but
2N/A * instead inspect *its* dependencies, return.
2N/A */
2N/A if (FLAGS1(clmp) & FL1_RT_LDDSTUB)
2N/A return;
2N/A
2N/A /*
2N/A * Without any rejection info, this is a supplied not-found condition.
2N/A */
2N/A if (rej && (rej->rej_type == 0)) {
2N/A (void) printf(nfound, name);
2N/A return;
2N/A }
2N/A
2N/A /*
2N/A * If rejection information exists then establish what object was
2N/A * found and the reason for its rejection.
2N/A */
2N/A if (rej) {
2N/A Conv_reject_desc_buf_t rej_buf;
2N/A
2N/A /* LINTED */
2N/A (void) snprintf(_reject, PATH_MAX,
2N/A MSG_INTL(ldd_reject[rej->rej_type]),
2N/A conv_reject_desc(rej, &rej_buf));
2N/A if (rej->rej_name)
2N/A path = rej->rej_name;
2N/A reject = (char *)_reject;
2N/A
2N/A /*
2N/A * Was an alternative pathname defined (from a configuration
2N/A * file).
2N/A */
2N/A if (rej->rej_flag & FLG_FD_ALTER)
2N/A str = MSG_INTL(MSG_LDD_FIL_ALTER);
2N/A } else {
2N/A if (alter)
2N/A str = MSG_INTL(MSG_LDD_FIL_ALTER);
2N/A }
2N/A
2N/A /*
2N/A * If the load name isn't a full pathname print its associated pathname
2N/A * together with all the other information we've gathered.
2N/A */
2N/A if (*name == '/')
2N/A (void) printf(MSG_ORIG(MSG_LDD_FIL_PATH), path, str, reject);
2N/A else
2N/A (void) printf(MSG_ORIG(MSG_LDD_FIL_EQUIV), name, path, str,
2N/A reject);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Establish a link-map mode, initializing it if it has just been loaded, or
2N/A * potentially updating it if it already exists.
2N/A */
2N/Aint
2N/Aupdate_mode(Rt_map *lmp, int omode, int nmode)
2N/A{
2N/A Lm_list *lml = LIST(lmp);
2N/A int pmode = 0;
2N/A
2N/A /*
2N/A * A newly loaded object hasn't had its mode set yet. Modes are used to
2N/A * load dependencies, so don't propagate any parent or no-load flags, as
2N/A * these would adversely affect this objects ability to load any of its
2N/A * dependencies that aren't already loaded. RTLD_FIRST is applicable to
2N/A * this objects handle creation only, and should not be propagated.
2N/A */
2N/A if ((FLAGS(lmp) & FLG_RT_MODESET) == 0) {
2N/A MODE(lmp) |= nmode & ~(RTLD_PARENT | RTLD_NOLOAD | RTLD_FIRST);
2N/A FLAGS(lmp) |= FLG_RT_MODESET;
2N/A return (1);
2N/A }
2N/A
2N/A /*
2N/A * Establish any new overriding modes. RTLD_LAZY and RTLD_NOW should be
2N/A * represented individually (this is historic, as these two flags were
2N/A * the only flags originally available to dlopen()). Other flags are
2N/A * accumulative, but have a hierarchy of preference.
2N/A */
2N/A if ((omode & RTLD_LAZY) && (nmode & RTLD_NOW)) {
2N/A MODE(lmp) &= ~RTLD_LAZY;
2N/A pmode |= RTLD_NOW;
2N/A }
2N/A
2N/A pmode |= ((~omode & nmode) &
2N/A (RTLD_GLOBAL | RTLD_WORLD | RTLD_NODELETE));
2N/A if (pmode) {
2N/A DBG_CALL(Dbg_file_mode_promote(lmp, pmode));
2N/A MODE(lmp) |= pmode;
2N/A }
2N/A
2N/A /*
2N/A * If this load is an RTLD_NOW request and the object has already been
2N/A * loaded non-RTLD_NOW, append this object to the relocation-now list
2N/A * of the objects associated control list. Note, if the object hasn't
2N/A * yet been relocated, setting its MODE() to RTLD_NOW will establish
2N/A * full relocation processing when it eventually gets relocated.
2N/A */
2N/A if ((pmode & RTLD_NOW) &&
2N/A (FLAGS(lmp) & (FLG_RT_RELOCED | FLG_RT_RELOCING))) {
2N/A Lm_cntl *lmc;
2N/A
2N/A /* LINTED */
2N/A lmc = (Lm_cntl *)((char *)(LIST(lmp)->lm_lists) + CNTL(lmp));
2N/A (void) alist_append(&(lmc->lc_now), &lmp, sizeof (Rt_map *),
2N/A AL_CNT_LMNOW);
2N/A }
2N/A
2N/A#ifdef SIEBEL_DISABLE
2N/A /*
2N/A * For patch backward compatibility the following .init collection
2N/A * is disabled.
2N/A */
2N/A if (rtld_flags & RT_FL_DISFIX_1)
2N/A return (pmode);
2N/A#endif
2N/A
2N/A /*
2N/A * If this objects .init has been collected but has not yet been called,
2N/A * it may be necessary to reevaluate the object using tsort(). For
2N/A * example, a new dlopen() hierarchy may bind to uninitialized objects
2N/A * that are already loaded, or a dlopen(RTLD_NOW) can establish new
2N/A * bindings between already loaded objects that require the tsort()
2N/A * information be recomputed. If however, no new objects have been
2N/A * added to the process, and this object hasn't been promoted, don't
2N/A * bother reevaluating the .init. The present tsort() information is
2N/A * probably as accurate as necessary, and by not establishing a parallel
2N/A * tsort() we can help reduce the amount of recursion possible between
2N/A * .inits.
2N/A */
2N/A if (((FLAGS(lmp) &
2N/A (FLG_RT_INITCLCT | FLG_RT_INITCALL)) == FLG_RT_INITCLCT) &&
2N/A ((lml->lm_flags & LML_FLG_OBJADDED) || ((pmode & RTLD_NOW) &&
2N/A (FLAGS(lmp) & (FLG_RT_RELOCED | FLG_RT_RELOCING))))) {
2N/A FLAGS(lmp) &= ~FLG_RT_INITCLCT;
2N/A LIST(lmp)->lm_init++;
2N/A LIST(lmp)->lm_flags |= LML_FLG_OBJREEVAL;
2N/A }
2N/A
2N/A return (pmode);
2N/A}
2N/A
2N/A/*
2N/A * Determine whether an alias name already exists, and if not create one. This
2N/A * is typically used to retain dependency names, such as "libc.so.1", which
2N/A * would have been expanded to full path names when they were loaded. The
2N/A * full path names (NAME() and possibly PATHNAME()) are maintained as Fullpath
2N/A * AVL nodes, and thus would have been matched by fpavl_loaded() during
2N/A * file_open().
2N/A */
2N/Aint
2N/Aappend_alias(Rt_map *lmp, const char *str, int *added)
2N/A{
2N/A Aliste off;
2N/A char **cpp, *cp;
2N/A
2N/A /*
2N/A * Determine if this filename is already on the alias list.
2N/A */
2N/A for (ALIST_TRAVERSE(ALIAS(lmp), off, cpp)) {
2N/A if (strcmp(*cpp, str) == 0)
2N/A return (1);
2N/A }
2N/A
2N/A /*
2N/A * This is a new alias, append it to the alias list.
2N/A */
2N/A if ((cp = strdup(str)) == NULL)
2N/A return (0);
2N/A
2N/A if (alist_append(&ALIAS(lmp), &cp, sizeof (char *),
2N/A AL_CNT_ALIAS) == 0) {
2N/A free(cp);
2N/A return (0);
2N/A }
2N/A if (added)
2N/A *added = 1;
2N/A return (1);
2N/A}
2N/A
2N/A/*
2N/A * Determine whether a file is already loaded by comparing device and inode
2N/A * values.
2N/A */
2N/Astatic Rt_map *
2N/Ais_devinode_loaded(struct stat *status, Lm_list *lml, const char *name,
2N/A uint_t flags)
2N/A{
2N/A Lm_cntl *lmc;
2N/A Aliste off;
2N/A
2N/A /*
2N/A * If this is an auditor, it will have been opened on a new link-map.
2N/A * To prevent multiple occurrences of the same auditor on multiple
2N/A * link-maps, search the head of each link-map list and see if this
2N/A * object is already loaded as an auditor.
2N/A */
2N/A if (flags & FLG_RT_AUDIT) {
2N/A Lm_list * lml;
2N/A Listnode * lnp;
2N/A
2N/A for (LIST_TRAVERSE(&dynlm_list, lnp, lml)) {
2N/A Rt_map *nlmp = lml->lm_head;
2N/A
2N/A if (nlmp && ((FLAGS(nlmp) &
2N/A (FLG_RT_AUDIT | FLG_RT_DELETE)) == FLG_RT_AUDIT) &&
2N/A (STDEV(nlmp) == status->st_dev) &&
2N/A (STINO(nlmp) == status->st_ino))
2N/A return (nlmp);
2N/A }
2N/A return ((Rt_map *)0);
2N/A }
2N/A
2N/A /*
2N/A * If the file has been found determine from the new files status
2N/A * information if this file is actually linked to one we already have
2N/A * mapped. This catches symlink names not caught by is_so_loaded().
2N/A */
2N/A for (ALIST_TRAVERSE(lml->lm_lists, off, lmc)) {
2N/A Rt_map *nlmp;
2N/A
2N/A for (nlmp = lmc->lc_head; nlmp; nlmp = (Rt_map *)NEXT(nlmp)) {
2N/A if ((FLAGS(nlmp) & FLG_RT_DELETE) ||
2N/A (FLAGS1(nlmp) & FL1_RT_LDDSTUB))
2N/A continue;
2N/A
2N/A if ((STDEV(nlmp) != status->st_dev) ||
2N/A (STINO(nlmp) != status->st_ino))
2N/A continue;
2N/A
2N/A if (lml->lm_flags & LML_FLG_TRC_VERBOSE) {
2N/A /* BEGIN CSTYLED */
2N/A if (*name == '/')
2N/A (void) printf(MSG_ORIG(MSG_LDD_FIL_PATH),
2N/A name, MSG_ORIG(MSG_STR_EMPTY),
2N/A MSG_ORIG(MSG_STR_EMPTY));
2N/A else
2N/A (void) printf(MSG_ORIG(MSG_LDD_FIL_EQUIV),
2N/A name, NAME(nlmp),
2N/A MSG_ORIG(MSG_STR_EMPTY),
2N/A MSG_ORIG(MSG_STR_EMPTY));
2N/A /* END CSTYLED */
2N/A }
2N/A return (nlmp);
2N/A }
2N/A }
2N/A return ((Rt_map *)0);
2N/A}
2N/A
2N/A/*
2N/A * Generate any error messages indicating a file could not be found. When
2N/A * preloading or auditing a secure application, it can be a little more helpful
2N/A * to indicate that a search of secure directories has failed, so adjust the
2N/A * messages accordingly.
2N/A */
2N/Avoid
2N/Afile_notfound(Lm_list *lml, const char *name, Rt_map *clmp, uint_t flags,
2N/A Rej_desc * rej)
2N/A{
2N/A int secure = 0;
2N/A
2N/A if ((rtld_flags & RT_FL_SECURE) &&
2N/A (flags & (FLG_RT_PRELOAD | FLG_RT_AUDIT)))
2N/A secure++;
2N/A
2N/A if (lml->lm_flags & LML_FLG_TRC_ENABLE) {
2N/A /*
2N/A * Under ldd(1), auxiliary filtees that can't be loaded are
2N/A * ignored, unless verbose errors are requested.
2N/A */
2N/A if ((rtld_flags & RT_FL_SILENCERR) &&
2N/A ((lml->lm_flags & LML_FLG_TRC_VERBOSE) == 0))
2N/A return;
2N/A
2N/A if (secure)
2N/A trace_so(clmp, rej, name, 0, 0,
2N/A MSG_INTL(MSG_LDD_SEC_NFOUND));
2N/A else
2N/A trace_so(clmp, rej, name, 0, 0,
2N/A MSG_INTL(MSG_LDD_FIL_NFOUND));
2N/A return;
2N/A }
2N/A
2N/A if (rej->rej_type) {
2N/A Conv_reject_desc_buf_t rej_buf;
2N/A
2N/A eprintf(lml, ERR_FATAL, MSG_INTL(err_reject[rej->rej_type]),
2N/A rej->rej_name ? rej->rej_name : MSG_INTL(MSG_STR_UNKNOWN),
2N/A conv_reject_desc(rej, &rej_buf));
2N/A return;
2N/A }
2N/A
2N/A if (secure)
2N/A eprintf(lml, ERR_FATAL, MSG_INTL(MSG_SEC_OPEN), name);
2N/A else
2N/A eprintf(lml, ERR_FATAL, MSG_INTL(MSG_SYS_OPEN), name,
2N/A strerror(ENOENT));
2N/A}
2N/A
2N/Astatic int
2N/Afile_open(int err, Lm_list *lml, const char *oname, const char *nname,
2N/A Rt_map *clmp, uint_t flags, Fdesc *fdesc, Rej_desc *rej)
2N/A{
2N/A struct stat status;
2N/A Rt_map *nlmp;
2N/A int resolved = 0;
2N/A
2N/A fdesc->fd_oname = oname;
2N/A
2N/A if ((err == 0) && (fdesc->fd_flags & FLG_FD_ALTER))
2N/A DBG_CALL(Dbg_file_config_obj(lml, oname, 0, nname));
2N/A
2N/A /*
2N/A * If we're dealing with a full pathname, determine whether this
2N/A * pathname is already known. Other pathnames fall through to the
2N/A * dev/inode check, as even though the pathname may look the same as
2N/A * one previously used, the process may have changed directory.
2N/A */
2N/A if ((err == 0) && (nname[0] == '/')) {
2N/A if ((nlmp = fpavl_loaded(lml, nname,
2N/A &(fdesc->fd_avlwhere))) != NULL) {
2N/A fdesc->fd_nname = nname;
2N/A fdesc->fd_lmp = nlmp;
2N/A return (1);
2N/A }
2N/A }
2N/A
2N/A if ((err == 0) && ((stat(nname, &status)) != -1)) {
2N/A char path[PATH_MAX];
2N/A int fd, size, added;
2N/A
2N/A /*
2N/A * If this path has been constructed as part of expanding a
2N/A * HWCAP directory, ignore any subdirectories. As this is a
2N/A * silent failure, where no rejection message is created, free
2N/A * the original name to simplify the life of the caller. For
2N/A * any other reference that expands to a directory, fall through
2N/A * to construct a meaningful rejection message.
2N/A */
2N/A if ((flags & FLG_RT_HWCAP) &&
2N/A ((status.st_mode & S_IFMT) == S_IFDIR)) {
2N/A free((void *)nname);
2N/A return (0);
2N/A }
2N/A
2N/A /*
2N/A * Resolve the filename and determine whether the resolved name
2N/A * is already known. Typically, the previous fpavl_loaded()
2N/A * will have caught this, as both NAME() and PATHNAME() for a
2N/A * link-map are recorded in the FullNode AVL tree. However,
2N/A * instances exist where a file can be replaced (loop-back
2N/A * mounts, bfu, etc.), and reference is made to the original
2N/A * file through a symbolic link. By checking the pathname here,
2N/A * we don't fall through to the dev/inode check and conclude
2N/A * that a new file should be loaded.
2N/A */
2N/A if ((nname[0] == '/') && (rtld_flags & RT_FL_EXECNAME) &&
2N/A ((size = resolvepath(nname, path, (PATH_MAX - 1))) > 0)) {
2N/A path[size] = '\0';
2N/A
2N/A if (strcmp(nname, path)) {
2N/A if ((nlmp =
2N/A fpavl_loaded(lml, path, 0)) != NULL) {
2N/A added = 0;
2N/A
2N/A if (append_alias(nlmp, nname,
2N/A &added) == 0)
2N/A return (0);
2N/A /* BEGIN CSTYLED */
2N/A if (added)
2N/A DBG_CALL(Dbg_file_skip(LIST(clmp),
2N/A NAME(nlmp), nname));
2N/A /* END CSTYLED */
2N/A fdesc->fd_nname = nname;
2N/A fdesc->fd_lmp = nlmp;
2N/A return (1);
2N/A }
2N/A
2N/A /*
2N/A * If this pathname hasn't been loaded, save
2N/A * the resolved pathname so that it doesn't
2N/A * have to be recomputed as part of fullpath()
2N/A * processing.
2N/A */
2N/A if ((fdesc->fd_pname = strdup(path)) == NULL)
2N/A return (0);
2N/A resolved = 1;
2N/A } else {
2N/A /*
2N/A * If the resolved name doesn't differ from the
2N/A * original, save it without duplication.
2N/A * Having fd_pname set indicates that no further
2N/A * resolvepath processing is necessary.
2N/A */
2N/A fdesc->fd_pname = nname;
2N/A }
2N/A }
2N/A
2N/A if (nlmp = is_devinode_loaded(&status, lml, nname, flags)) {
2N/A if (flags & FLG_RT_AUDIT) {
2N/A /*
2N/A * If we've been requested to load an auditor,
2N/A * and an auditor of the same name already
2N/A * exists, then the original auditor is used.
2N/A */
2N/A DBG_CALL(Dbg_audit_skip(LIST(clmp),
2N/A NAME(nlmp), LIST(nlmp)->lm_lmidstr));
2N/A } else {
2N/A /*
2N/A * Otherwise, if an alternatively named file
2N/A * has been found for the same dev/inode, add
2N/A * a new name alias, and insert any alias full
2N/A * pathname in the link-map lists AVL tree.
*/
added = 0;
if (append_alias(nlmp, nname, &added) == 0)
return (0);
if (added) {
if ((nname[0] == '/') &&
(fpavl_insert(lml, nlmp,
nname, 0) == 0))
return (0);
DBG_CALL(Dbg_file_skip(LIST(clmp),
NAME(nlmp), nname));
}
}
/*
* Record in the file descriptor the existing object
* that satisfies this open request.
*/
fdesc->fd_nname = nname;
fdesc->fd_lmp = nlmp;
return (1);
}
if ((fd = open(nname, O_RDONLY, 0)) == -1) {
/*
* As the file must exist for the previous stat() to
* have succeeded, record the error condition.
*/
rej->rej_type = SGS_REJ_STR;
rej->rej_str = strerror(errno);
} else {
Fct *ftp;
if ((ftp = are_u_this(rej, fd, &status, nname)) != 0) {
fdesc->fd_nname = nname;
fdesc->fd_ftp = ftp;
fdesc->fd_dev = status.st_dev;
fdesc->fd_ino = status.st_ino;
fdesc->fd_fd = fd;
/*
* Trace that this open has succeeded.
*/
if (lml->lm_flags & LML_FLG_TRC_ENABLE) {
trace_so(clmp, 0, oname, nname,
(fdesc->fd_flags & FLG_FD_ALTER),
0);
}
return (1);
}
(void) close(fd);
}
} else if (errno != ENOENT) {
/*
* If the open() failed for anything other than the file not
* existing, record the error condition.
*/
rej->rej_type = SGS_REJ_STR;
rej->rej_str = strerror(errno);
}
/*
* Indicate any rejection.
*/
if (rej->rej_type) {
/*
* If this pathname was resolved and duplicated, remove the
* allocated name to simplify the cleanup of the callers.
*/
if (resolved) {
free((void *)fdesc->fd_pname);
fdesc->fd_pname = NULL;
}
rej->rej_name = nname;
rej->rej_flag = (fdesc->fd_flags & FLG_FD_ALTER);
DBG_CALL(Dbg_file_rejected(lml, rej));
}
return (0);
}
/*
* Find a full pathname (it contains a "/").
*/
int
find_path(Lm_list *lml, const char *oname, Rt_map *clmp, uint_t flags,
Fdesc *fdesc, Rej_desc *rej)
{
int err = 0;
/*
* If directory configuration exists determine if this path is known.
*/
if (rtld_flags & RT_FL_DIRCFG) {
Rtc_obj *obj;
const char *aname;
if ((obj = elf_config_ent(oname, (Word)elf_hash(oname),
0, &aname)) != 0) {
/*
* If the configuration file states that this path is a
* directory, or the path is explicitly defined as
* non-existent (ie. a unused platform specific
* library), then go no further.
*/
if (obj->co_flags & RTC_OBJ_DIRENT) {
err = EISDIR;
} else if ((obj->co_flags &
(RTC_OBJ_NOEXIST | RTC_OBJ_ALTER)) ==
RTC_OBJ_NOEXIST) {
err = ENOENT;
} else if ((obj->co_flags & RTC_OBJ_ALTER) &&
(rtld_flags & RT_FL_OBJALT) && (lml == &lml_main)) {
int ret;
fdesc->fd_flags |= FLG_FD_ALTER;
/*
* Attempt to open the alternative path. If
* this fails, and the alternative is flagged
* as optional, fall through to open the
* original path.
*/
DBG_CALL(Dbg_libs_found(lml, aname,
FLG_FD_ALTER));
if (((ret = file_open(0, lml, oname, aname,
clmp, flags, fdesc, rej)) != 0) ||
((obj->co_flags & RTC_OBJ_OPTINAL) == 0))
return (ret);
fdesc->fd_flags &= ~FLG_FD_ALTER;
}
}
}
DBG_CALL(Dbg_libs_found(lml, oname, 0));
return (file_open(err, lml, oname, oname, clmp, flags, fdesc, rej));
}
/*
* Find a simple filename (it doesn't contain a "/").
*/
static int
_find_file(Lm_list *lml, const char *oname, const char *nname, Rt_map *clmp,
uint_t flags, Fdesc *fdesc, Rej_desc *rej, Pnode *dir, int aflag)
{
DBG_CALL(Dbg_libs_found(lml, nname, aflag));
if ((lml->lm_flags & LML_FLG_TRC_SEARCH) &&
((FLAGS1(clmp) & FL1_RT_LDDSTUB) == 0)) {
(void) printf(MSG_INTL(MSG_LDD_PTH_TRYING), nname, aflag ?
MSG_INTL(MSG_LDD_FIL_ALTER) : MSG_ORIG(MSG_STR_EMPTY));
}
/*
* If we're being audited tell the audit library of the file we're about
* to go search for. The audit library may offer an alternative
* dependency, or indicate that this dependency should be ignored.
*/
if ((lml->lm_tflags | FLAGS1(clmp)) & LML_TFLG_AUD_OBJSEARCH) {
char *aname = audit_objsearch(clmp, nname, dir->p_orig);
if (aname == 0) {
DBG_CALL(Dbg_audit_terminate(lml, nname));
return (0);
}
/*
* Protect ourselves from auditor mischief, by copying any
* alternative name over the present name (the present name is
* maintained in a static buffer - see elf_get_so());
*/
if (nname != aname)
(void) strncpy((char *)nname, aname, PATH_MAX);
}
return (file_open(0, lml, oname, nname, clmp, flags, fdesc, rej));
}
static int
find_file(Lm_list *lml, const char *oname, Rt_map *clmp, uint_t flags,
Fdesc *fdesc, Rej_desc *rej, Pnode *dir, Word * strhash, size_t olen)
{
static Rtc_obj Obj = { 0 };
Rtc_obj * dobj;
const char *nname = oname;
if (dir->p_name == 0)
return (0);
if (dir->p_info) {
dobj = (Rtc_obj *)dir->p_info;
if ((dobj->co_flags &
(RTC_OBJ_NOEXIST | RTC_OBJ_ALTER)) == RTC_OBJ_NOEXIST)
return (0);
} else
dobj = 0;
/*
* If configuration information exists see if this directory/file
* combination exists.
*/
if ((rtld_flags & RT_FL_DIRCFG) &&
((dobj == 0) || (dobj->co_id != 0))) {
Rtc_obj *fobj;
const char *alt = 0;
/*
* If this pnode has not yet been searched for in the
* configuration file go find it.
*/
if (dobj == 0) {
dobj = elf_config_ent(dir->p_name,
(Word)elf_hash(dir->p_name), 0, 0);
if (dobj == 0)
dobj = &Obj;
dir->p_info = (void *)dobj;
if ((dobj->co_flags & (RTC_OBJ_NOEXIST |
RTC_OBJ_ALTER)) == RTC_OBJ_NOEXIST)
return (0);
}
/*
* If we found a directory search for the file.
*/
if (dobj->co_id != 0) {
if (*strhash == 0)
*strhash = (Word)elf_hash(nname);
fobj = elf_config_ent(nname, *strhash,
dobj->co_id, &alt);
/*
* If this object specifically does not exist, or the
* object can't be found in a know-all-entries
* directory, continue looking. If the object does
* exist determine if an alternative object exists.
*/
if (fobj == 0) {
if (dobj->co_flags & RTC_OBJ_ALLENTS)
return (0);
} else {
if ((fobj->co_flags & (RTC_OBJ_NOEXIST |
RTC_OBJ_ALTER)) == RTC_OBJ_NOEXIST)
return (0);
if ((fobj->co_flags & RTC_OBJ_ALTER) &&
(rtld_flags & RT_FL_OBJALT) &&
(lml == &lml_main)) {
int ret;
fdesc->fd_flags |= FLG_FD_ALTER;
/*
* Attempt to open the alternative path.
* If this fails, and the alternative is
* flagged as optional, fall through to
* open the original path.
*/
ret = _find_file(lml, oname, alt, clmp,
flags, fdesc, rej, dir, 1);
if (ret || ((fobj->co_flags &
RTC_OBJ_OPTINAL) == 0))
return (ret);
fdesc->fd_flags &= ~FLG_FD_ALTER;
}
}
}
}
/*
* Protect ourselves from building an invalid pathname.
*/
if ((olen + dir->p_len + 1) >= PATH_MAX) {
eprintf(lml, ERR_FATAL, MSG_INTL(MSG_SYS_OPEN), nname,
strerror(ENAMETOOLONG));
return (0);
}
if ((nname = (LM_GET_SO(clmp)(dir->p_name, nname))) == 0)
return (0);
return (_find_file(lml, oname, nname, clmp, flags, fdesc, rej, dir, 0));
}
/*
* A unique file has been opened. Create a link-map to represent it, and
* process the various names by which it can be referenced.
*/
static Rt_map *
load_file(Lm_list *lml, Aliste lmco, Fdesc *fdesc)
{
const char *oname = fdesc->fd_oname;
const char *nname = fdesc->fd_nname;
Rt_map *nlmp;
/*
* Typically we call fct_map_so() with the full pathname of the opened
* file (nname) and the name that started the search (oname), thus for
* a typical dependency on libc this would be /usr/lib/libc.so.1 and
* libc.so.1 (DT_NEEDED). The original name is maintained on an ALIAS
* list for comparison when bringing in new dependencies. If the user
* specified name as a full path (from a dlopen() for example) then
* there's no need to create an ALIAS.
*/
if (strcmp(oname, nname) == 0)
oname = 0;
/*
* A new file has been opened, now map it into the process. Close the
* original file so as not to accumulate file descriptors.
*/
nlmp = ((fdesc->fd_ftp)->fct_map_so)(lml, lmco, nname, oname,
fdesc->fd_fd);
(void) close(fdesc->fd_fd);
fdesc->fd_fd = 0;
if (nlmp == 0)
return (0);
/*
* Save the dev/inode information for later comparisons.
*/
STDEV(nlmp) = fdesc->fd_dev;
STINO(nlmp) = fdesc->fd_ino;
/*
* Insert the names of this link-map into the FullpathNode AVL tree.
* Save both the NAME() and PATHNAME() is they differ.
*
* If this is an OBJECT file, don't insert it yet as this is only a
* temporary link-map. During elf_obj_fini() the final link-map is
* created, and its names will be inserted in the FullpathNode AVL
* tree at that time.
*/
if ((FLAGS(nlmp) & FLG_RT_OBJECT) == 0) {
/*
* Update the objects full path information if necessary.
* Note, with pathname expansion in effect, the fd_pname will
* be used as PATHNAME(). This allocated string will be freed
* should this object be deleted. However, without pathname
* expansion, the fd_name should be freed now, as it is no
* longer referenced.
*/
if (FLAGS1(nlmp) & FL1_RT_RELATIVE)
(void) fullpath(nlmp, fdesc->fd_pname);
else if (fdesc->fd_pname != fdesc->fd_nname)
free((void *)fdesc->fd_pname);
fdesc->fd_pname = 0;
if ((NAME(nlmp)[0] == '/') && (fpavl_insert(lml, nlmp,
NAME(nlmp), fdesc->fd_avlwhere) == 0)) {
remove_so(lml, nlmp);
return (0);
}
if (((NAME(nlmp)[0] != '/') ||
(NAME(nlmp) != PATHNAME(nlmp))) &&
(fpavl_insert(lml, nlmp, PATHNAME(nlmp), 0) == 0)) {
remove_so(lml, nlmp);
return (0);
}
}
/*
* If we're processing an alternative object reset the original name
* for possible $ORIGIN processing.
*/
if (fdesc->fd_flags & FLG_FD_ALTER) {
const char *odir;
char *ndir;
size_t olen;
FLAGS(nlmp) |= FLG_RT_ALTER;
/*
* If we were given a pathname containing a slash then the
* original name is still in oname. Otherwise the original
* directory is in dir->p_name (which is all we need for
* $ORIGIN).
*/
if (fdesc->fd_flags & FLG_FD_SLASH) {
char *ofil;
odir = oname;
ofil = strrchr(oname, '/');
olen = ofil - odir + 1;
} else {
odir = fdesc->fd_odir;
olen = strlen(odir) + 1;
}
if ((ndir = (char *)malloc(olen)) == 0) {
remove_so(lml, nlmp);
return (0);
}
(void) strncpy(ndir, odir, olen);
ndir[--olen] = '\0';
ORIGNAME(nlmp) = ndir;
DIRSZ(nlmp) = olen;
}
/*
* Identify this as a new object.
*/
FLAGS(nlmp) |= FLG_RT_NEWLOAD;
return (nlmp);
}
/*
* This function loads the named file and returns a pointer to its link map.
* It is assumed that the caller has already checked that the file is not
* already loaded before calling this function (refer is_so_loaded()).
* Find and open the file, map it into memory, add it to the end of the list
* of link maps and return a pointer to the new link map. Return 0 on error.
*/
static Rt_map *
load_so(Lm_list *lml, Aliste lmco, const char *oname, Rt_map *clmp,
uint_t flags, Fdesc *nfdp, Rej_desc *rej)
{
char *name;
uint_t slash = 0;
size_t olen;
Fdesc fdesc = { 0 };
Pnode *dir;
/*
* If the file is the run time linker then it's already loaded.
*/
if (interp && (strcmp(oname, NAME(lml_rtld.lm_head)) == 0))
return (lml_rtld.lm_head);
/*
* If this isn't a hardware capabilities pathname, which is already a
* full, duplicated pathname, determine whether the pathname contains
* a slash, and if not determine the input filename (for max path
* length verification).
*/
if ((flags & FLG_RT_HWCAP) == 0) {
const char *str;
for (str = oname; *str; str++) {
if (*str == '/') {
slash++;
break;
}
}
if (slash == 0)
olen = (str - oname) + 1;
}
/*
* If we are passed a 'null' link-map this means that this is the first
* object to be loaded on this link-map list. In that case we set the
* link-map to ld.so.1's link-map.
*
* This link-map is referenced to determine what lookup rules to use
* when searching for files. By using ld.so.1's we are defaulting to
* ELF look-up rules.
*
* Note: This case happens when loading the first object onto
* the plt_tracing link-map.
*/
if (clmp == 0)
clmp = lml_rtld.lm_head;
/*
* If this path resulted from a $HWCAP specification, then the best
* hardware capability object has already been establish, and is
* available in the calling file descriptor. Perform some minor book-
* keeping so that we can fall through into common code.
*/
if (flags & FLG_RT_HWCAP) {
/*
* If this object is already loaded, we're done.
*/
if (nfdp->fd_lmp)
return (nfdp->fd_lmp);
/*
* Obtain the avl index for this object.
*/
(void) fpavl_loaded(lml, nfdp->fd_nname, &(nfdp->fd_avlwhere));
/*
* If the name and resolved pathname differ, duplicate the path
* name once more to provide for generic cleanup by the caller.
*/
if (nfdp->fd_pname && (nfdp->fd_nname != nfdp->fd_pname)) {
char *pname;
if ((pname = strdup(nfdp->fd_pname)) == NULL)
return (0);
nfdp->fd_pname = pname;
}
} else if (slash) {
Rej_desc _rej = { 0 };
*nfdp = fdesc;
nfdp->fd_flags = FLG_FD_SLASH;
if (find_path(lml, oname, clmp, flags, nfdp, &_rej) == 0) {
rejection_inherit(rej, &_rej);
return (0);
}
/*
* If this object is already loaded, we're done.
*/
if (nfdp->fd_lmp)
return (nfdp->fd_lmp);
} else {
/*
* No '/' - for each directory on list, make a pathname using
* that directory and filename and try to open that file.
*/
Pnode *dirlist = (Pnode *)0;
Word strhash = 0;
#if !defined(ISSOLOAD_BASENAME_DISABLED)
Rt_map *nlmp;
#endif
DBG_CALL(Dbg_libs_find(lml, oname));
#if !defined(ISSOLOAD_BASENAME_DISABLED)
if ((nlmp = is_so_loaded(lml, oname)))
return (nlmp);
#endif
/*
* Make sure we clear the file descriptor new name in case the
* following directory search doesn't provide any directories
* (odd, but this can be forced with a -znodefaultlib test).
*/
*nfdp = fdesc;
for (dir = get_next_dir(&dirlist, clmp, flags); dir;
dir = get_next_dir(&dirlist, clmp, flags)) {
Rej_desc _rej = { 0 };
*nfdp = fdesc;
/*
* Try and locate this file. Make sure to clean up
* any rejection information should the file have
* been found, but not appropriate.
*/
if (find_file(lml, oname, clmp, flags, nfdp, &_rej,
dir, &strhash, olen) == 0) {
rejection_inherit(rej, &_rej);
continue;
}
/*
* If this object is already loaded, we're done.
*/
if (nfdp->fd_lmp)
return (nfdp->fd_lmp);
nfdp->fd_odir = dir->p_name;
break;
}
/*
* If the file couldn't be loaded, do another comparison of
* loaded files using just the basename. This catches folks
* who may have loaded multiple full pathname files (possibly
* from setxid applications) to satisfy dependency relationships
* (i.e., a file might have a dependency on foo.so.1 which has
* already been opened using its full pathname).
*/
if (nfdp->fd_nname == NULL)
return (is_so_loaded(lml, oname));
}
/*
* Duplicate the file name so that NAME() is available in core files.
* Note, that hardware capability names are already duplicated, but
* they get duplicated once more to insure consistent cleanup in the
* event of an error condition.
*/
if ((name = strdup(nfdp->fd_nname)) == NULL)
return (0);
if (nfdp->fd_nname == nfdp->fd_pname)
nfdp->fd_nname = nfdp->fd_pname = name;
else
nfdp->fd_nname = name;
/*
* Finish mapping the file and return the link-map descriptor. Note,
* if this request originated from a HWCAP request, re-establish the
* fdesc information. For single paged objects, such as filters, the
* original mapping may have been sufficient to capture the file, thus
* this mapping needs to be reset to insure it doesn't mistakenly get
* unmapped as part of HWCAP cleanup.
*/
return (load_file(lml, lmco, nfdp));
}
/*
* Trace an attempt to load an object.
*/
int
load_trace(Lm_list *lml, const char **oname, Rt_map *clmp)
{
const char *name = *oname;
/*
* First generate any ldd(1) diagnostics.
*/
if ((lml->lm_flags & (LML_FLG_TRC_VERBOSE | LML_FLG_TRC_SEARCH)) &&
((FLAGS1(clmp) & FL1_RT_LDDSTUB) == 0))
(void) printf(MSG_INTL(MSG_LDD_FIL_FIND), name, NAME(clmp));
/*
* If we're being audited tell the audit library of the file we're
* about to go search for.
*/
if (((lml->lm_tflags | FLAGS1(clmp)) & LML_TFLG_AUD_ACTIVITY) &&
(lml == LIST(clmp)))
audit_activity(clmp, LA_ACT_ADD);
if ((lml->lm_tflags | FLAGS1(clmp)) & LML_TFLG_AUD_OBJSEARCH) {
char *aname = audit_objsearch(clmp, name, LA_SER_ORIG);
/*
* The auditor can indicate that this object should be ignored.
*/
if (aname == NULL) {
DBG_CALL(Dbg_audit_terminate(lml, name));
return (0);
}
/*
* Protect ourselves from auditor mischief, by duplicating any
* alternative name. The original name has been allocated from
* expand(), so free this allocation before using the audit
* alternative.
*/
if (name != aname) {
if ((aname = strdup(aname)) == NULL) {
eprintf(lml, ERR_FATAL,
MSG_INTL(MSG_GEN_AUDITERM), name);
return (0);
}
free((void *)*oname);
*oname = aname;
}
}
return (1);
}
/*
* Having loaded an object and created a link-map to describe it, finish
* processing this stage, including verifying any versioning requirements,
* updating the objects mode, creating a handle if necessary, and adding this
* object to existing handles if required.
*/
static int
load_finish(Lm_list *lml, const char *name, Rt_map *clmp, int nmode,
uint_t flags, Grp_hdl **hdl, Rt_map *nlmp)
{
Aliste off;
Grp_hdl *ghp, **ghpp;
int promote;
/*
* If this dependency is associated with a required version insure that
* the version is present in the loaded file.
*/
if (((rtld_flags & RT_FL_NOVERSION) == 0) &&
(FCT(clmp) == &elf_fct) && VERNEED(clmp) &&
(LM_VERIFY_VERS(clmp)(name, clmp, nlmp) == 0))
return (0);
/*
* If this object has indicated that it should be isolated as a group
* (DT_FLAGS_1 contains DF_1_GROUP - object was built with -B group),
* or if the callers direct bindings indicate it should be isolated as
* a group (DYNINFO flags contains FLG_DI_GROUP - dependency followed
* -zgroupperm), establish the appropriate mode.
*
* The intent of an object defining itself as a group is to isolate the
* relocation of the group within its own members, however, unless
* opened through dlopen(), in which case we assume dlsym() will be used
* to located symbols in the new object, we still need to associate it
* with the caller for it to be bound with. This is equivalent to a
* dlopen(RTLD_GROUP) and dlsym() using the returned handle.
*/
if ((FLAGS(nlmp) | flags) & FLG_RT_SETGROUP) {
nmode &= ~RTLD_WORLD;
nmode |= RTLD_GROUP;
/*
* If the object wasn't explicitly dlopen()'ed associate it with
* the parent.
*/
if ((flags & FLG_RT_HANDLE) == 0)
nmode |= RTLD_PARENT;
}
/*
* Establish new mode and flags.
*
* For patch backward compatibility, the following use of update_mode()
* is disabled.
*/
#ifdef SIEBEL_DISABLE
if (rtld_flags & RT_FL_DISFIX_1)
promote = MODE(nlmp) |=
(nmode & ~(RTLD_PARENT | RTLD_NOLOAD | RTLD_FIRST));
else
#endif
promote = update_mode(nlmp, MODE(nlmp), nmode);
FLAGS(nlmp) |= flags;
/*
* If this is a global object, ensure the associated link-map list can
* be rescanned for global, lazy dependencies.
*/
if (MODE(nlmp) & RTLD_GLOBAL)
LIST(nlmp)->lm_flags &= ~LML_FLG_NOPENDGLBLAZY;
/*
* If we've been asked to establish a handle create one for this object.
* Or, if this object has already been analyzed, but this reference
* requires that the mode of the object be promoted, also create a
* handle to propagate the new modes to all this objects dependencies.
*/
if (((FLAGS(nlmp) | flags) & FLG_RT_HANDLE) || (promote &&
(FLAGS(nlmp) & FLG_RT_ANALYZED))) {
uint_t oflags, hflags = 0, cdflags;
/*
* Establish any flags for the handle (Grp_hdl).
*
* . Use of the RTLD_FIRST flag indicates that only the first
* dependency on the handle (the new object) can be used
* to satisfy dlsym() requests.
*/
if (nmode & RTLD_FIRST)
hflags = GPH_FIRST;
/*
* Establish the flags for this callers dependency descriptor
* (Grp_desc).
*
* . The creation of a handle associated a descriptor for the
* new object and descriptor for the parent (caller).
* Typically, the handle is created for dlopen() or for
* filtering. A handle may also be created to promote
* the callers modes (RTLD_NOW) to the new object. In this
* latter case, the handle/descriptor are torn down once
* the mode propagation has occurred.
*
* . Use of the RTLD_PARENT flag indicates that the parent
* can be relocated against.
*/
if (((FLAGS(nlmp) | flags) & FLG_RT_HANDLE) == 0)
cdflags = GPD_PROMOTE;
else
cdflags = GPD_PARENT;
if (nmode & RTLD_PARENT)
cdflags |= GPD_RELOC;
/*
* Now that a handle is being created, remove this state from
* the object so that it doesn't mistakenly get inherited by
* a dependency.
*/
oflags = FLAGS(nlmp);
FLAGS(nlmp) &= ~FLG_RT_HANDLE;
DBG_CALL(Dbg_file_hdl_title(DBG_HDL_ADD));
if ((ghp = hdl_create(lml, nlmp, clmp, hflags,
(GPD_DLSYM | GPD_RELOC | GPD_ADDEPS), cdflags)) == 0)
return (0);
/*
* Add any dependencies that are already loaded, to the handle.
*/
if (hdl_initialize(ghp, nlmp, nmode, promote) == 0)
return (0);
if (hdl)
*hdl = ghp;
/*
* If we were asked to create a handle, we're done.
*/
if ((oflags | flags) & FLG_RT_HANDLE)
return (1);
/*
* If the handle was created to promote modes from the parent
* (caller) to the new object, then this relationship needs to
* be removed to ensure the handle doesn't prevent the new
* objects from being deleted if required. If the parent is
* the only dependency on the handle, then the handle can be
* completely removed. However, the handle may have already
* existed, in which case only the parent descriptor can be
* deleted from the handle, or at least the GPD_PROMOTE flag
* removed from the descriptor.
*
* Fall through to carry out any group processing.
*/
free_hdl(ghp, clmp, GPD_PROMOTE);
}
/*
* If the caller isn't part of a group we're done.
*/
if (GROUPS(clmp) == 0)
return (1);
/*
* Determine if our caller is already associated with a handle, if so
* we need to add this object to any handles that already exist.
* Traverse the list of groups our caller is a member of and add this
* new link-map to those groups.
*/
DBG_CALL(Dbg_file_hdl_title(DBG_HDL_ADD));
for (ALIST_TRAVERSE(GROUPS(clmp), off, ghpp)) {
Aliste off1;
Grp_desc *gdp;
int exist;
Rt_map **lmpp;
Alist *lmalp = 0;
ghp = *ghpp;
/*
* If the caller doesn't indicate that its dependencies should
* be added to a handle, ignore it. This case identifies a
* parent of a dlopen(RTLD_PARENT) request.
*/
for (ALIST_TRAVERSE(ghp->gh_depends, off1, gdp)) {
if (gdp->gd_depend == clmp)
break;
}
if ((gdp->gd_flags & GPD_ADDEPS) == 0)
continue;
if ((exist = hdl_add(ghp, nlmp,
(GPD_DLSYM | GPD_RELOC | GPD_ADDEPS))) == 0)
return (0);
/*
* If this member already exists then its dependencies will
* have already been processed.
*/
if (exist == ALE_EXISTS)
continue;
/*
* If the object we've added has just been opened, it will not
* yet have been processed for its dependencies, these will be
* added on later calls to load_one(). If it doesn't have any
* dependencies we're also done.
*/
if (((FLAGS(nlmp) & FLG_RT_ANALYZED) == 0) ||
(DEPENDS(nlmp) == 0))
continue;
/*
* Otherwise, this object exists and has dependencies, so add
* all of its dependencies to the handle were operating on.
*/
if (alist_append(&lmalp, &nlmp, sizeof (Rt_map *),
AL_CNT_DEPCLCT) == 0)
return (0);
for (ALIST_TRAVERSE(lmalp, off1, lmpp)) {
Rt_map * dlmp1 = *lmpp;
Aliste off2;
Bnd_desc ** bdpp;
/*
* Add any dependencies of this dependency to the
* dynamic dependency list so they can be further
* processed.
*/
for (ALIST_TRAVERSE(DEPENDS(dlmp1), off2, bdpp)) {
Bnd_desc * bdp = *bdpp;
Rt_map * dlmp2 = bdp->b_depend;
if ((bdp->b_flags & BND_NEEDED) == 0)
continue;
if (alist_test(&lmalp, dlmp2, sizeof (Rt_map *),
AL_CNT_DEPCLCT) == 0) {
free(lmalp);
return (0);
}
}
if (nlmp == dlmp1)
continue;
if ((exist = hdl_add(ghp, dlmp1,
(GPD_DLSYM | GPD_RELOC | GPD_ADDEPS))) != 0) {
if (exist == ALE_CREATE) {
(void) update_mode(dlmp1, MODE(dlmp1),
nmode);
}
continue;
}
free(lmalp);
return (0);
}
free(lmalp);
}
return (1);
}
/*
* The central routine for loading shared objects. Insures ldd() diagnostics,
* handles and any other related additions are all done in one place.
*/
static Rt_map *
_load_path(Lm_list *lml, Aliste lmco, const char **oname, Rt_map *clmp,
int nmode, uint_t flags, Grp_hdl ** hdl, Fdesc *nfdp, Rej_desc *rej)
{
Rt_map *nlmp;
const char *name = *oname;
if ((nmode & RTLD_NOLOAD) == 0) {
/*
* If this isn't a noload request attempt to load the file.
* Note, the name of the file may be changed by an auditor.
*/
if ((load_trace(lml, oname, clmp)) == 0)
return (0);
name = *oname;
if ((nlmp = load_so(lml, lmco, name, clmp, flags,
nfdp, rej)) == 0)
return (0);
/*
* If we've loaded a library which identifies itself as not
* being dlopen()'able catch it here. Let non-dlopen()'able
* objects through under RTLD_CONFGEN as they're only being
* mapped to be dldump()'ed.
*/
if ((rtld_flags & RT_FL_APPLIC) && ((FLAGS(nlmp) &
(FLG_RT_NOOPEN | FLG_RT_RELOCED)) == FLG_RT_NOOPEN) &&
((nmode & RTLD_CONFGEN) == 0)) {
Rej_desc _rej = { 0 };
_rej.rej_name = name;
_rej.rej_type = SGS_REJ_STR;
_rej.rej_str = MSG_INTL(MSG_GEN_NOOPEN);
DBG_CALL(Dbg_file_rejected(lml, &_rej));
rejection_inherit(rej, &_rej);
remove_so(lml, nlmp);
return (0);
}
} else {
/*
* If it's a NOLOAD request - check to see if the object
* has already been loaded.
*/
/* LINTED */
if (nlmp = is_so_loaded(lml, name)) {
if ((lml->lm_flags & LML_FLG_TRC_VERBOSE) &&
((FLAGS1(clmp) & FL1_RT_LDDSTUB) == 0)) {
(void) printf(MSG_INTL(MSG_LDD_FIL_FIND), name,
NAME(clmp));
/* BEGIN CSTYLED */
if (*name == '/')
(void) printf(MSG_ORIG(MSG_LDD_FIL_PATH),
name, MSG_ORIG(MSG_STR_EMPTY),
MSG_ORIG(MSG_STR_EMPTY));
else
(void) printf(MSG_ORIG(MSG_LDD_FIL_EQUIV),
name, NAME(nlmp),
MSG_ORIG(MSG_STR_EMPTY),
MSG_ORIG(MSG_STR_EMPTY));
/* END CSTYLED */
}
} else {
Rej_desc _rej = { 0 };
_rej.rej_name = name;
_rej.rej_type = SGS_REJ_STR;
_rej.rej_str = strerror(ENOENT);
DBG_CALL(Dbg_file_rejected(lml, &_rej));
rejection_inherit(rej, &_rej);
return (0);
}
}
/*
* Finish processing this loaded object.
*/
if (load_finish(lml, name, clmp, nmode, flags, hdl, nlmp) == 0) {
FLAGS(nlmp) &= ~FLG_RT_NEWLOAD;
/*
* If this object has already been analyzed, then it is in use,
* so even though this operation has failed, it should not be
* torn down.
*/
if ((FLAGS(nlmp) & FLG_RT_ANALYZED) == 0)
remove_so(lml, nlmp);
return (0);
}
/*
* If this object is new, and we're being audited, tell the audit
* library of the file we've just opened. Note, if the new link-map
* requires local auditing of its dependencies we also register its
* opening.
*/
if (FLAGS(nlmp) & FLG_RT_NEWLOAD) {
FLAGS(nlmp) &= ~FLG_RT_NEWLOAD;
if (((lml->lm_tflags | FLAGS1(clmp) | FLAGS1(nlmp)) &
LML_TFLG_AUD_MASK) && (((lml->lm_flags |
LIST(clmp)->lm_flags) & LML_FLG_NOAUDIT) == 0)) {
if (audit_objopen(clmp, nlmp) == 0) {
remove_so(lml, nlmp);
return (0);
}
}
}
return (nlmp);
}
Rt_map *
load_path(Lm_list *lml, Aliste lmco, const char **name, Rt_map *clmp,
int nmode, uint_t flags, Grp_hdl **hdl, Fdesc *cfdp, Rej_desc *rej)
{
Rt_map *lmp;
Fdesc nfdp = { 0 };
/*
* If this path resulted from a $HWCAP specification, then the best
* hardware capability object has already been establish, and is
* available in the calling file descriptor.
*/
if (flags & FLG_RT_HWCAP) {
if (cfdp->fd_lmp == 0) {
/*
* If this object hasn't yet been mapped, re-establish
* the file descriptor structure to reflect this objects
* original initial page mapping. Make sure any present
* file descriptor mapping is removed before overwriting
* the structure.
*/
#if defined(MAP_ALIGN)
if (fmap->fm_maddr &&
((fmap->fm_mflags & MAP_ALIGN) == 0))
#else
if (fmap->fm_maddr)
#endif
(void) munmap(fmap->fm_maddr, fmap->fm_msize);
}
nfdp = *cfdp;
*fmap = cfdp->fd_fmap;
}
lmp = _load_path(lml, lmco, name, clmp, nmode, flags, hdl, &nfdp, rej);
/*
* If this path originated from a $HWCAP specification, re-establish the
* fdesc information. For single paged objects, such as filters, the
* original mapping may have been sufficient to capture the file, thus
* this mapping needs to be reset to insure it doesn't mistakenly get
* unmapped as part of HWCAP cleanup.
*/
if (flags & FLG_RT_HWCAP) {
cfdp->fd_fmap.fm_maddr = fmap->fm_maddr;
cfdp->fd_fmap.fm_mflags = fmap->fm_mflags;
cfdp->fd_fd = nfdp.fd_fd;
}
return (lmp);
}
/*
* Load one object from a possible list of objects. Typically, for requests
* such as NEEDED's, only one object is specified. However, this object could
* be specified using $ISALIST or $HWCAP, in which case only the first object
* that can be loaded is used (ie. the best).
*/
Rt_map *
load_one(Lm_list *lml, Aliste lmco, Pnode *pnp, Rt_map *clmp, int mode,
uint_t flags, Grp_hdl ** hdl)
{
Rej_desc rej = { 0 };
Pnode *tpnp;
const char *name;
for (tpnp = pnp; tpnp && tpnp->p_name; tpnp = tpnp->p_next) {
Rt_map *tlmp;
/*
* A Hardware capabilities requirement can itself expand into
* a number of candidates.
*/
if (tpnp->p_orig & PN_TKN_HWCAP) {
if ((tlmp = load_hwcap(lml, lmco, tpnp->p_name, clmp,
mode, (flags | FLG_RT_HWCAP), hdl, &rej)) != 0) {
remove_rej(&rej);
return (tlmp);
}
} else {
if ((tlmp = load_path(lml, lmco, &tpnp->p_name, clmp,
mode, flags, hdl, 0, &rej)) != 0) {
remove_rej(&rej);
return (tlmp);
}
}
}
/*
* If this pathname originated from an expanded token, use the original
* for any diagnostic output.
*/
if ((name = pnp->p_oname) == 0)
name = pnp->p_name;
file_notfound(lml, name, clmp, flags, &rej);
remove_rej(&rej);
return (0);
}
/*
* Determine whether a symbol is defined as an interposer.
*/
int
is_sym_interposer(Rt_map *lmp, Sym *sym)
{
Syminfo *sip = SYMINFO(lmp);
if (sip) {
ulong_t ndx;
ndx = (((ulong_t)sym - (ulong_t)SYMTAB(lmp)) / SYMENT(lmp));
/* LINTED */
sip = (Syminfo *)((char *)sip + (ndx * SYMINENT(lmp)));
if (sip->si_flags & SYMINFO_FLG_INTERPOSE)
return (1);
}
return (0);
}
/*
* While processing direct or group bindings, determine whether the object to
* which we've bound can be interposed upon. In this context, copy relocations
* are a form of interposition.
*/
static Sym *
lookup_sym_interpose(Slookup *slp, Rt_map **dlmp, uint_t *binfo, Lm_list *lml,
Sym *sym)
{
Rt_map *lmp;
Slookup sl;
/*
* If we've bound to a copy relocation definition then we need to assign
* this binding to the original copy reference. Fabricate an inter-
* position diagnostic, as this is a legitimate form of interposition.
*/
if (FLAGS1(*dlmp) & FL1_RT_COPYTOOK) {
Rel_copy *rcp;
Aliste off;
for (ALIST_TRAVERSE(COPY(*dlmp), off, rcp)) {
if ((sym == rcp->r_dsym) || (sym->st_value &&
(sym->st_value == rcp->r_dsym->st_value))) {
*dlmp = rcp->r_rlmp;
*binfo |=
(DBG_BINFO_INTERPOSE | DBG_BINFO_COPYREF);
return (rcp->r_rsym);
}
}
}
if ((lml->lm_flags & LML_FLG_INTRPOSE) == 0)
return ((Sym *)0);
/*
* Traverse the list of known interposers to determine whether any
* offer the same symbol. Note, the head of the link-map could be
* identified as an interposer. If it is, make sure we only look for
* symbol definitions. Otherwise, skip the head of the link-map, so
* that we don't bind to any .plt references, or copy-relocations
* unintentionally.
*/
lmp = lml->lm_head;
sl = *slp;
if (((FLAGS(lmp) & MSK_RT_INTPOSE) == 0) || (sl.sl_flags & LKUP_COPY))
lmp = (Rt_map *)NEXT(lmp);
else
sl.sl_flags &= ~LKUP_SPEC;
for (; lmp; lmp = (Rt_map *)NEXT(lmp)) {
if (FLAGS(lmp) & FLG_RT_DELETE)
continue;
if ((FLAGS(lmp) & MSK_RT_INTPOSE) == 0)
break;
if (callable(lmp, *dlmp, 0)) {
Rt_map *ilmp;
sl.sl_imap = lmp;
if (sym = SYMINTP(lmp)(&sl, &ilmp, binfo)) {
/*
* If this object provides individual symbol
* interposers, make sure that the symbol we
* have found is tagged as an interposer.
*/
if ((FLAGS(ilmp) & FLG_RT_SYMINTPO) &&
(is_sym_interposer(ilmp, sym) == 0))
continue;
/*
* Indicate this binding has occurred to an
* interposer, and return the symbol.
*/
*binfo |= DBG_BINFO_INTERPOSE;
*dlmp = ilmp;
return (sym);
}
}
}
return ((Sym *)0);
}
/*
* If an object specifies direct bindings (it contains a syminfo structure
* describing where each binding was established during link-editing, and the
* object was built -Bdirect), then look for the symbol in the specific object.
*/
static Sym *
lookup_sym_direct(Slookup *slp, Rt_map **dlmp, uint_t *binfo, Syminfo *sip,
Rt_map *lmp)
{
Rt_map *clmp = slp->sl_cmap;
Sym *sym;
Slookup sl;
/*
* If a direct binding resolves to the definition of a copy relocated
* variable, it must be redirected to the copy (in the executable) that
* will eventually be made. Typically, this redirection occurs in
* lookup_sym_interpose(). But, there's an edge condition. If a
* directly bound executable contains pic code, there may be a
* reference to a definition that will eventually have a copy made.
* However, this copy relocation may not yet have occurred, because
* the relocation making this reference comes before the relocation
* that will create the copy.
* Under direct bindings, the syminfo indicates that a copy will be
* taken (SYMINFO_FLG_COPY). This can only be set in an executable.
* Thus, the caller must be the executable, so bind to the destination
* of the copy within the executable.
*/
if (((slp->sl_flags & LKUP_COPY) == 0) &&
(sip->si_flags & SYMINFO_FLG_COPY)) {
slp->sl_imap = LIST(clmp)->lm_head;
if (sym = SYMINTP(clmp)(slp, dlmp, binfo))
*binfo |= (DBG_BINFO_DIRECT | DBG_BINFO_COPYREF);
return (sym);
}
/*
* If we need to directly bind to our parent, start looking in each
* callers link map.
*/
sl = *slp;
sl.sl_flags |= LKUP_DIRECT;
sym = 0;
if (sip->si_boundto == SYMINFO_BT_PARENT) {
Aliste off1;
Bnd_desc **bdpp;
Grp_hdl **ghpp;
/*
* Determine the parent of this explicit dependency from its
* CALLERS()'s list.
*/
for (ALIST_TRAVERSE(CALLERS(clmp), off1, bdpp)) {
sl.sl_imap = lmp = (*bdpp)->b_caller;
if ((sym = SYMINTP(lmp)(&sl, dlmp, binfo)) != 0)
goto found;
}
/*
* A caller can also be defined as the parent of a dlopen()
* call. Determine whether this object has any handles. The
* dependencies maintained with the handle represent the
* explicit dependencies of the dlopen()'ed object, and the
* calling parent.
*/
for (ALIST_TRAVERSE(HANDLES(clmp), off1, ghpp)) {
Grp_hdl *ghp = *ghpp;
Grp_desc *gdp;
Aliste off2;
for (ALIST_TRAVERSE(ghp->gh_depends, off2, gdp)) {
if ((gdp->gd_flags & GPD_PARENT) == 0)
continue;
sl.sl_imap = lmp = gdp->gd_depend;
if ((sym = SYMINTP(lmp)(&sl, dlmp, binfo)) != 0)
goto found;
}
}
} else {
/*
* If we need to direct bind to anything else look in the
* link map associated with this symbol reference.
*/
if (sip->si_boundto == SYMINFO_BT_SELF)
sl.sl_imap = lmp = clmp;
else
sl.sl_imap = lmp;
if (lmp)
sym = SYMINTP(lmp)(&sl, dlmp, binfo);
}
found:
if (sym)
*binfo |= DBG_BINFO_DIRECT;
/*
* If we've bound to an object, determine whether that object can be
* interposed upon for this symbol.
*/
if (sym && (LIST(*dlmp)->lm_head != *dlmp) &&
(LIST(*dlmp) == LIST(clmp))) {
Sym * isym;
if ((isym = lookup_sym_interpose(slp, dlmp, binfo,
LIST(*dlmp), sym)) != 0)
return (isym);
}
return (sym);
}
static Sym *
_lookup_sym(Rt_map *ilmp, Slookup *slp, Rt_map **dlmp, uint_t *binfo,
Aliste off)
{
Rt_map *lmp;
/*
* Copy relocations should start their search after the head of the
* main link-map control list.
*/
if ((off == ALO_DATA) && (slp->sl_flags & LKUP_COPY) && ilmp)
lmp = (Rt_map *)NEXT(ilmp);
else
lmp = ilmp;
for (; lmp; lmp = (Rt_map *)NEXT(lmp)) {
if (callable(slp->sl_cmap, lmp, 0)) {
Sym *sym;
slp->sl_imap = lmp;
if ((sym = SYMINTP(lmp)(slp, dlmp, binfo)) != 0)
return (sym);
}
}
return (0);
}
static Sym *
_lazy_find_sym(Rt_map *ilmp, Slookup *slp, Rt_map **dlmp, uint_t *binfo)
{
Rt_map *lmp;
for (lmp = ilmp; lmp; lmp = (Rt_map *)NEXT(lmp)) {
if (LAZY(lmp) == 0)
continue;
if (callable(slp->sl_cmap, lmp, 0)) {
Sym *sym;
slp->sl_imap = lmp;
if ((sym = elf_lazy_find_sym(slp, dlmp, binfo)) != 0)
return (sym);
}
}
return (0);
}
/*
* Symbol lookup routine. Takes an ELF symbol name, and a list of link maps to
* search (if the flag indicates LKUP_FIRST only the first link map of the list
* is searched ie. we've been called from dlsym()).
* If successful, return a pointer to the symbol table entry and a pointer to
* the link map of the enclosing object. Else return a null pointer.
*
* To improve elf performance, we first compute the elf hash value and pass
* it to each find_sym() routine. The elf function will use this value to
* locate the symbol, the a.out function will simply ignore it.
*/
Sym *
lookup_sym(Slookup *slp, Rt_map **dlmp, uint_t *binfo)
{
const char *name = slp->sl_name;
Rt_map *clmp = slp->sl_cmap;
Rt_map *ilmp = slp->sl_imap, *lmp;
uint_t flags = slp->sl_flags;
ulong_t rsymndx;
Sym *sym = 0;
Syminfo *sip;
Slookup sl;
if (slp->sl_hash == 0)
slp->sl_hash = elf_hash(name);
*binfo = 0;
/*
* Search the initial link map for the required symbol (this category is
* selected by dlsym(), where individual link maps are searched for a
* required symbol. Therefore, we know we have permission to look at
* the link map).
*/
if (flags & LKUP_FIRST)
return (SYMINTP(ilmp)(slp, dlmp, binfo));
/*
* Determine whether this lookup can be satisfied by an objects direct,
* or lazy binding information. This is triggered by a relocation from
* the object (hence rsymndx is set).
*/
if (((rsymndx = slp->sl_rsymndx) != 0) &&
((sip = SYMINFO(clmp)) != 0)) {
/*
* Find the corresponding Syminfo entry for the original
* referencing symbol.
*/
/* LINTED */
sip = (Syminfo *)((char *)sip + (rsymndx * SYMINENT(clmp)));
/*
* If the symbol information indicates a direct binding,
* determine the link map that is required to satisfy the
* binding. Note, if the dependency can not be found, but a
* direct binding isn't required, we will still fall through
* to perform any default symbol search.
*/
if (sip->si_flags & SYMINFO_FLG_DIRECT) {
uint_t bound = sip->si_boundto;
lmp = 0;
if (bound < SYMINFO_BT_LOWRESERVE)
lmp = elf_lazy_load(clmp, bound, name);
/*
* If direct bindings have been disabled, and this isn't
* a translator, skip any direct binding now that we've
* insured the resolving object has been loaded.
*
* If we need to direct bind to anything, we look in
* ourselves, our parent, or in the link map we've just
* loaded. Otherwise, even though we may have lazily
* loaded an object we still continue to search for
* symbols from the head of the link map list.
*/
if (((FLAGS(clmp) & FLG_RT_TRANS) ||
(!(LIST(clmp)->lm_tflags & LML_TFLG_NODIRECT))) &&
((FLAGS1(clmp) & FL1_RT_DIRECT) ||
(sip->si_flags & SYMINFO_FLG_DIRECTBIND))) {
sym = lookup_sym_direct(slp, dlmp, binfo,
sip, lmp);
/*
* If this direct binding has been disabled
* (presumably because the symbol definition has
* been changed since the referring object was
* built), fall back to a standard symbol
* search.
*/
if ((*binfo & BINFO_DIRECTDIS) == 0)
return (sym);
}
}
}
sl = *slp;
/*
* If the referencing object has the DF_SYMBOLIC flag set, look in the
* referencing object for the symbol first. Failing that, fall back to
* our generic search.
*/
if (FLAGS1(clmp) & FL1_RT_SYMBOLIC) {
sl.sl_imap = clmp;
if (sym = SYMINTP(clmp)(&sl, dlmp, binfo)) {
ulong_t dsymndx = (((ulong_t)sym -
(ulong_t)SYMTAB(*dlmp)) / SYMENT(*dlmp));
/*
* Make sure this symbol hasn't explicitly been defined
* as nodirect.
*/
if (((sip = SYMINFO(*dlmp)) == 0) ||
/* LINTED */
((sip = (Syminfo *)((char *)sip +
(dsymndx * SYMINENT(*dlmp)))) == 0) ||
((sip->si_flags & SYMINFO_FLG_NOEXTDIRECT) == 0))
return (sym);
}
}
/*
* If this lookup originates from a standard relocation, then traverse
* all link-map lists inspecting any object that is available to this
* caller. Otherwise, traverse the link-map list associate with the
* caller.
*/
if (flags & LKUP_ALLCNTLIST) {
Aliste off;
Lm_cntl *lmc;
sym = 0;
for (ALIST_TRAVERSE(LIST(clmp)->lm_lists, off, lmc)) {
if ((sym = _lookup_sym(lmc->lc_head, &sl, dlmp,
binfo, off)) != 0)
break;
}
} else
sym = _lookup_sym(ilmp, &sl, dlmp, binfo, ALO_DATA);
/*
* To allow transitioning into a world of lazy loading dependencies see
* if this link map contains objects that have lazy dependencies still
* outstanding. If so, and we haven't been able to locate a non-weak
* symbol reference, start bringing in any lazy dependencies to see if
* the reference can be satisfied. Use of dlsym(RTLD_PROBE) sets the
* LKUP_NOFALBACK flag, and this flag disables this fall back.
*/
if ((sym == 0) && ((sl.sl_flags & LKUP_NOFALBACK) == 0)) {
if ((lmp = ilmp) == 0)
lmp = LIST(clmp)->lm_head;
if ((flags & LKUP_WEAK) || (LIST(lmp)->lm_lazy == 0))
return ((Sym *)0);
DBG_CALL(Dbg_syms_lazy_rescan(LIST(clmp), name));
/*
* If this request originated from a dlsym(RTLD_NEXT) then start
* looking for dependencies from the caller, otherwise use the
* initial link-map.
*/
if (flags & LKUP_NEXT)
sym = _lazy_find_sym(clmp, &sl, dlmp, binfo);
else {
Aliste off;
Lm_cntl *lmc;
for (ALIST_TRAVERSE(LIST(clmp)->lm_lists, off, lmc)) {
sl.sl_flags |= LKUP_NOFALBACK;
if ((sym = _lazy_find_sym(lmc->lc_head, &sl,
dlmp, binfo)) != 0)
break;
}
}
}
/*
* If the caller is restricted to a symbol search within its group,
* determine if it is necessary to follow a binding from outside of
* the group.
*/
if (sym && ((MODE(clmp) & (RTLD_GROUP | RTLD_WORLD)) == RTLD_GROUP)) {
Sym * isym;
if ((isym = lookup_sym_interpose(slp, dlmp, binfo, LIST(*dlmp),
sym)) != 0)
return (isym);
}
return (sym);
}
/*
* Associate a binding descriptor with a caller and its dependency, or update
* an existing descriptor.
*/
int
bind_one(Rt_map *clmp, Rt_map *dlmp, uint_t flags)
{
Bnd_desc **bdpp, *bdp;
Aliste off;
int found = ALE_CREATE;
/*
* Determine whether a binding descriptor already exists between the
* two objects.
*/
for (ALIST_TRAVERSE(DEPENDS(clmp), off, bdpp)) {
bdp = *bdpp;
if (bdp->b_depend == dlmp) {
found = ALE_EXISTS;
break;
}
}
if (found == ALE_CREATE) {
/*
* Create a new binding descriptor.
*/
if ((bdp = malloc(sizeof (Bnd_desc))) == 0)
return (0);
bdp->b_caller = clmp;
bdp->b_depend = dlmp;
bdp->b_flags = 0;
/*
* Append the binding descriptor to the caller and the
* dependency.
*/
if (alist_append(&DEPENDS(clmp), &bdp,
sizeof (Bnd_desc *), AL_CNT_DEPENDS) == 0)
return (0);
if (alist_append(&CALLERS(dlmp), &bdp,
sizeof (Bnd_desc *), AL_CNT_CALLERS) == 0)
return (0);
}
if ((found == ALE_CREATE) || ((bdp->b_flags & flags) != flags)) {
bdp->b_flags |= flags;
if (flags & BND_REFER)
FLAGS1(dlmp) |= FL1_RT_USED;
DBG_CALL(Dbg_file_bind_entry(LIST(clmp), bdp));
}
return (found);
}
/*
* Cleanup after relocation processing.
*/
int
relocate_finish(Rt_map *lmp, Alist *bound, int textrel, int ret)
{
DBG_CALL(Dbg_reloc_run(lmp, 0, ret, DBG_REL_FINISH));
/*
* Establish bindings to all objects that have been bound to.
*/
if (bound) {
Aliste off;
Rt_map **lmpp;
if (ret) {
for (ALIST_TRAVERSE(bound, off, lmpp)) {
if (bind_one(lmp, *lmpp, BND_REFER) == 0) {
ret = 0;
break;
}
}
}
free(bound);
}
/*
* If we write enabled the text segment to perform these relocations
* re-protect by disabling writes.
*/
if (textrel)
(void) LM_SET_PROT(lmp)(lmp, 0);
return (ret);
}