1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1988 AT&T 24 * All Rights Reserved 25 * 26 * 27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. 29 */ 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <sys/types.h> 33 #include <sys/mman.h> 34 #include <signal.h> 35 #include <dlfcn.h> 36 #include <synch.h> 37 #include "_rtld.h" 38 39 /* 40 * Declarations of global variables used in ld.so. 41 */ 42 Rt_lock rtldlock; 43 44 /* 45 * Major link-map lists. 46 */ 47 Lm_list lml_main = { 0 }; /* the `main's link map list */ 48 Lm_list lml_rtld = { 0 }; /* rtld's link map list */ 49 50 /* 51 * BEGIN: Exposed to rtld_db, don't change without a coordinated handshake with 52 * librtld_db (remembering that librtld_db must be able to read old as well as 53 * current core files). 54 */ 55 List dynlm_list = { 0, 0 }; /* dynamic list of link-maps */ 56 /* 57 * END: Exposed to rtld_db 58 */ 59 60 Reglist * reglist = 0; /* list of register symbols */ 61 62 void (*thrinit)() = 0; /* thread initialization */ 63 64 ulong_t hwcap = 0; /* hardware capabilities */ 65 ulong_t sfcap = 0; /* software capabilities */ 66 67 /* 68 * Initialized fmap structure. 69 */ 70 static Fmap _fmap = { 0, 0, 0, 0, 0 }; 71 Fmap * fmap = &_fmap; /* initial file mapping info */ 72 73 /* 74 * Set of integers to track how many of what type of 75 * PLT's have been bound. This is only really interesting 76 * for SPARC since ia32 basically just has the one PLT. 77 */ 78 uint32_t pltcnt21d = 0; 79 uint32_t pltcnt24d = 0; 80 uint32_t pltcntu32 = 0; 81 uint32_t pltcntu44 = 0; 82 uint32_t pltcntfull = 0; 83 uint32_t pltcntfar = 0; 84 85 /* 86 * Enable technology (via status flags for RTLD) dependent upon whether we're 87 * in a patch or major release build environment. 88 */ 89 uint_t rtld_flags = 90 #ifdef EXPAND_RELATIVE 91 RT_FL_RELATIVE | 92 #endif 93 #ifdef SIEBEL_DISABLE 94 RT_FL_DISFIX_1 | 95 #endif 96 RT_FL_NOCONCUR; 97 uint_t rtld_flags2 = 0; 98 99 /* 100 * Various other global data. 101 */ 102 const char *pr_name; 103 const char *rt_name; /* the run time linkers name */ 104 char *lasterr = (char *)0; /* string describing last error */ 105 /* cleared by each dlerror() */ 106 Interp *interp = 0; /* ELF interpreter info */ 107 List hdl_list[HDLIST_SZ+2]; /* dlopen() handle list */ 108 size_t syspagsz = 0; /* system page size */ 109 unsigned long at_flags = 0; /* machine specific file flags */ 110 char *platform = 0; /* platform name from AT_SUN_PLATFORM */ 111 size_t platform_sz = 0; /* platform string length */ 112 Uts_desc *uts; /* utsname descriptor */ 113 Isa_desc *isa; /* isalist descriptor */ 114 115 uint_t audit_argcnt = 64; /* no. of stack args to copy (default */ 116 /* is all) */ 117 Audit_desc *auditors = 0; /* global auditors (LD_AUDIT) */ 118 119 const char *locale = 0; /* locale environment definition */ 120 121 const char *rpl_audit = 0; /* replaceable LD_AUDIT string */ 122 const char *rpl_debug = 0; /* replaceable LD_DEBUG string */ 123 const char *rpl_ldflags = 0; /* replaceable LD_FLAGS string */ 124 const char *rpl_libpath = 0; /* replaceable LD_LIBRARY_PATH string */ 125 Pnode *rpl_libdirs = 0; /* and associated Pnode list */ 126 const char *rpl_preload = 0; /* replaceable LD_PRELOAD string */ 127 128 const char *prm_audit = 0; /* permanent LD_AUDIT string */ 129 const char *prm_debug = 0; /* permanent LD_DEBUG string */ 130 const char *prm_ldflags = 0; /* permanent LD_FLAGS string */ 131 const char *prm_libpath = 0; /* permanent LD_LIBRARY_PATH string */ 132 Pnode *prm_libdirs = 0; /* and associated Pnode list */ 133 const char *prm_preload = 0; /* permanent LD_PRELOAD string */ 134 135 uint_t env_info = 0; /* information regarding environment */ 136 /* variables */ 137 int killsig = SIGKILL; /* signal sent on fatal exit */ 138 uint_t dbg_mask; /* debugging classes */ 139 const char *dbg_file = 0; /* debugging directed to file */ 140 141 #pragma weak environ = _environ /* environ for PLT tracing - we */ 142 char **_environ = 0; /* supply the pair to satisfy any */ 143 /* libc requirements (hwmuldiv) */ 144 145 const char *profile_name; /* object being profiled */ 146 const char *profile_out; /* profile output file */ 147 const char *profile_lib; /* audit library to perform profile */ 148 149 unsigned char search_rules[] = { /* dependency search rules */ 150 RPLENV, /* replaceable LD_LIBRARY_PATH */ 151 PRMENV, /* permanent LD_LIBRARY_PATH */ 152 RUNPATH, /* callers runpath */ 153 DEFAULT, /* default library path */ 154 0 155 }; 156 157 /* 158 * Frequently used messages are cached here to reduce _dgettext() overhead and 159 * also provide for resetting should the locale change (see _ld_libc()). 160 */ 161 const char *err_strs[ERR_NUM] = { 0 }; 162 const char *nosym_str = 0; 163 164 165 /* 166 * Rejection error message tables. 167 */ 168 const Msg 169 ldd_reject[] = { 170 MSG_STR_EMPTY, 171 MSG_LDD_REJ_MACH, /* MSG_INTL(MSG_LDD_REJ_MACH) */ 172 MSG_LDD_REJ_CLASS, /* MSG_INTL(MSG_LDD_REJ_CLASS) */ 173 MSG_LDD_REJ_DATA, /* MSG_INTL(MSG_LDD_REJ_DATA) */ 174 MSG_LDD_REJ_TYPE, /* MSG_INTL(MSG_LDD_REJ_TYPE) */ 175 MSG_LDD_REJ_BADFLAG, /* MSG_INTL(MSG_LDD_REJ_BADFLAG) */ 176 MSG_LDD_REJ_MISFLAG, /* MSG_INTL(MSG_LDD_REJ_MISFLAG) */ 177 MSG_LDD_REJ_VERSION, /* MSG_INTL(MSG_LDD_REJ_VERSION) */ 178 MSG_LDD_REJ_HAL, /* MSG_INTL(MSG_LDD_REJ_HAL) */ 179 MSG_LDD_REJ_US3, /* MSG_INTL(MSG_LDD_REJ_US3) */ 180 MSG_LDD_REJ_STR, /* MSG_INTL(MSG_LDD_REJ_STR) */ 181 MSG_LDD_REJ_UNKFILE, /* MSG_INTL(MSG_LDD_REJ_UNKFILE) */ 182 MSG_LDD_REJ_HWCAP_1, /* MSG_INTL(MSG_LDD_REJ_HWCAP_1) */ 183 }; 184 185 186 const Msg 187 err_reject[] = { 188 MSG_STR_EMPTY, 189 MSG_ERR_REJ_MACH, /* MSG_INTL(MSG_ERR_REJ_MACH) */ 190 MSG_ERR_REJ_CLASS, /* MSG_INTL(MSG_ERR_REJ_CLASS) */ 191 MSG_ERR_REJ_DATA, /* MSG_INTL(MSG_ERR_REJ_DATA) */ 192 MSG_ERR_REJ_TYPE, /* MSG_INTL(MSG_ERR_REJ_TYPE) */ 193 MSG_ERR_REJ_BADFLAG, /* MSG_INTL(MSG_ERR_REJ_BADFLAG) */ 194 MSG_ERR_REJ_MISFLAG, /* MSG_INTL(MSG_ERR_REJ_MISFLAG) */ 195 MSG_ERR_REJ_VERSION, /* MSG_INTL(MSG_ERR_REJ_VERSION) */ 196 MSG_ERR_REJ_HAL, /* MSG_INTL(MSG_ERR_REJ_HAL) */ 197 MSG_ERR_REJ_US3, /* MSG_INTL(MSG_ERR_REJ_US3) */ 198 MSG_ERR_REJ_STR, /* MSG_INTL(MSG_ERR_REJ_STR) */ 199 MSG_ERR_REJ_UNKFILE, /* MSG_INTL(MSG_ERR_REJ_UNKFILE) */ 200 MSG_ERR_REJ_HWCAP_1, /* MSG_INTL(MSG_ERR_REJ_HWCAP_1) */ 201 }; 202