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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 1988 AT&T 23 * All Rights Reserved 24 * 25 * 26 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 27 * Use is subject to license terms. 28 */ 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include <sys/types.h> 32 #include <sys/mman.h> 33 #include <signal.h> 34 #include <dlfcn.h> 35 #include <synch.h> 36 #include <debug.h> 37 #include "_rtld.h" 38 39 /* 40 * Declarations of global variables used in ld.so. 41 */ 42 Rt_lock rtldlock; 43 int thr_flg_nolock = 0; 44 int thr_flg_reenter = 0; 45 46 /* 47 * Major link-map lists. 48 */ 49 Lm_list lml_main = { 0 }; /* the `main's link map list */ 50 Lm_list lml_rtld = { 0 }; /* rtld's link map list */ 51 52 /* 53 * Entrance count. Each time ld.so.1 is entered following initial process 54 * setup, this count is bumped. This value serves to identify the present 55 * ld.so.1 operation. 56 * 57 * An ld.so.1 operation can result in many symbol lookup requests (i.e., loading 58 * objects and relocating all symbolic bindings). This count is used to protect 59 * against attempting to re-load a failed lazy load within a single call to 60 * ld.so.1, while allowing such attempts across calls. Should a lazy load fail, 61 * the present operation identifier is saved in the current symbol lookup data 62 * block (Slookup). Should a lazy load fall back operation be triggered, the 63 * identifier in the symbol lookup block is compared to the current ld.so.1 64 * entry count, and if the two are equal the fall back is skipped. 65 * 66 * With this count, there is a danger of wrap-around, although as an unsigned 67 * 32-bit value, it is highly unlikely that any application could usefully make 68 * 4.3 giga-calls into ld.so.1. The worst that can occur is that a fall back 69 * lazy load isn't triggered. However, most lazy loads that fail typically 70 * continue to fail unless the user takes corrective action (adds the necessary 71 * (fixed) dependencies to the system). 72 */ 73 ulong_t ld_entry_cnt = 1; 74 75 /* 76 * BEGIN: Exposed to rtld_db, don't change without a coordinated handshake with 77 * librtld_db (remembering that librtld_db must be able to read old as well as 78 * current core files). 79 */ 80 List dynlm_list = { 0, 0 }; /* dynamic list of link-maps */ 81 /* 82 * END: Exposed to rtld_db 83 */ 84 85 Reglist * reglist = 0; /* list of register symbols */ 86 87 ulong_t hwcap = 0; /* hardware capabilities */ 88 ulong_t sfcap = 0; /* software capabilities */ 89 90 /* 91 * Initialized fmap structure. 92 */ 93 static Fmap _fmap = { 0, 0, 0, 0, 0 }; 94 Fmap * fmap = &_fmap; /* initial file mapping info */ 95 96 /* 97 * Set of integers to track how many of what type of PLT's have been bound. 98 * This is only really interesting for SPARC since ia32 has only one PLT. 99 */ 100 uint32_t pltcnt21d = 0; 101 uint32_t pltcnt24d = 0; 102 uint32_t pltcntu32 = 0; 103 uint32_t pltcntu44 = 0; 104 uint32_t pltcntfull = 0; 105 uint32_t pltcntfar = 0; 106 107 /* 108 * Provide for recording not-found path names. 109 */ 110 avl_tree_t *nfavl = NULL; 111 112 /* 113 * Enable technology (via status flags for RTLD) dependent upon whether we're 114 * in a patch or major release build environment. 115 */ 116 uint_t rtld_flags = 117 #ifdef EXPAND_RELATIVE 118 RT_FL_RELATIVE | 119 #endif 120 #ifdef SIEBEL_DISABLE 121 RT_FL_DISFIX_1 | 122 #endif 123 RT_FL_NOCONCUR; 124 uint_t rtld_flags2 = 0; 125 126 /* 127 * Various other global data. 128 */ 129 Lc_desc glcs[CI_MAX]; /* global external interfaces */ 130 131 const char *procname = (const char *)0; 132 const char *rtldname = MSG_ORIG(MSG_FIL_RTLD); 133 134 char *lasterr = (char *)0; /* string describing last error */ 135 /* cleared by each dlerror() */ 136 Interp *interp = 0; /* ELF interpreter info */ 137 List hdl_list[HDLIST_SZ+2]; /* dlopen() handle list */ 138 size_t syspagsz = 0; /* system page size */ 139 unsigned long at_flags = 0; /* machine specific file flags */ 140 char *platform = 0; /* platform name from AT_SUN_PLATFORM */ 141 size_t platform_sz = 0; /* platform string length */ 142 Uts_desc *uts; /* utsname descriptor */ 143 Isa_desc *isa; /* isalist descriptor */ 144 145 uint_t audit_argcnt = 64; /* no. of stack args to copy (default */ 146 /* is all) */ 147 Audit_desc *auditors = 0; /* global auditors (LD_AUDIT) */ 148 149 const char *rpl_audit = 0; /* replaceable LD_AUDIT string */ 150 const char *rpl_debug = 0; /* replaceable LD_DEBUG string */ 151 const char *rpl_ldflags = 0; /* replaceable LD_FLAGS string */ 152 const char *rpl_libpath = 0; /* replaceable LD_LIBRARY_PATH string */ 153 Pnode *rpl_libdirs = 0; /* and associated Pnode list */ 154 const char *rpl_preload = 0; /* replaceable LD_PRELOAD string */ 155 156 const char *prm_audit = 0; /* permanent LD_AUDIT string */ 157 const char *prm_debug = 0; /* permanent LD_DEBUG string */ 158 const char *prm_ldflags = 0; /* permanent LD_FLAGS string */ 159 const char *prm_libpath = 0; /* permanent LD_LIBRARY_PATH string */ 160 Pnode *prm_libdirs = 0; /* and associated Pnode list */ 161 const char *prm_preload = 0; /* permanent LD_PRELOAD string */ 162 163 uint_t env_info = 0; /* information regarding environment */ 164 /* variables */ 165 int killsig = SIGKILL; /* signal sent on fatal exit */ 166 167 /* 168 * Note, the debugging descriptor interposes on the default definition provided 169 * by liblddbg. This is required as ld.so.1 must only have outstanding relative 170 * relocations. 171 */ 172 static Dbg_desc _dbg_desc = {0, 0, 0}; 173 Dbg_desc *dbg_desc = &_dbg_desc; /* debugging descriptor */ 174 const char *dbg_file = 0; /* debugging directed to file */ 175 176 #pragma weak environ = _environ /* environ for PLT tracing - we */ 177 char **_environ = 0; /* supply the pair to satisfy any */ 178 /* libc requirements (hwmuldiv) */ 179 180 const char *profile_name; /* object being profiled */ 181 const char *profile_out; /* profile output file */ 182 const char *profile_lib; /* audit library to perform profile */ 183 184 unsigned char search_rules[] = { /* dependency search rules */ 185 RPLENV, /* replaceable LD_LIBRARY_PATH */ 186 PRMENV, /* permanent LD_LIBRARY_PATH */ 187 RUNPATH, /* callers runpath */ 188 DEFAULT, /* default library path */ 189 0 190 }; 191 192 Dl_argsinfo argsinfo = { 0 }; /* process argument, environment and */ 193 /* auxv information. */ 194 195 /* 196 * Frequently used messages are cached here to reduce _dgettext() overhead and 197 * also provide for resetting should the locale change (see _ld_libc()). 198 */ 199 const char *err_strs[ERR_NUM] = { 0 }; 200 const char *nosym_str = 0; 201 202 203 /* 204 * Rejection error message tables. 205 */ 206 const Msg 207 ldd_reject[] = { 208 MSG_STR_EMPTY, 209 MSG_LDD_REJ_MACH, /* MSG_INTL(MSG_LDD_REJ_MACH) */ 210 MSG_LDD_REJ_CLASS, /* MSG_INTL(MSG_LDD_REJ_CLASS) */ 211 MSG_LDD_REJ_DATA, /* MSG_INTL(MSG_LDD_REJ_DATA) */ 212 MSG_LDD_REJ_TYPE, /* MSG_INTL(MSG_LDD_REJ_TYPE) */ 213 MSG_LDD_REJ_BADFLAG, /* MSG_INTL(MSG_LDD_REJ_BADFLAG) */ 214 MSG_LDD_REJ_MISFLAG, /* MSG_INTL(MSG_LDD_REJ_MISFLAG) */ 215 MSG_LDD_REJ_VERSION, /* MSG_INTL(MSG_LDD_REJ_VERSION) */ 216 MSG_LDD_REJ_HAL, /* MSG_INTL(MSG_LDD_REJ_HAL) */ 217 MSG_LDD_REJ_US3, /* MSG_INTL(MSG_LDD_REJ_US3) */ 218 MSG_LDD_REJ_STR, /* MSG_INTL(MSG_LDD_REJ_STR) */ 219 MSG_LDD_REJ_UNKFILE, /* MSG_INTL(MSG_LDD_REJ_UNKFILE) */ 220 MSG_LDD_REJ_HWCAP_1, /* MSG_INTL(MSG_LDD_REJ_HWCAP_1) */ 221 }; 222 223 224 const Msg 225 err_reject[] = { 226 MSG_STR_EMPTY, 227 MSG_ERR_REJ_MACH, /* MSG_INTL(MSG_ERR_REJ_MACH) */ 228 MSG_ERR_REJ_CLASS, /* MSG_INTL(MSG_ERR_REJ_CLASS) */ 229 MSG_ERR_REJ_DATA, /* MSG_INTL(MSG_ERR_REJ_DATA) */ 230 MSG_ERR_REJ_TYPE, /* MSG_INTL(MSG_ERR_REJ_TYPE) */ 231 MSG_ERR_REJ_BADFLAG, /* MSG_INTL(MSG_ERR_REJ_BADFLAG) */ 232 MSG_ERR_REJ_MISFLAG, /* MSG_INTL(MSG_ERR_REJ_MISFLAG) */ 233 MSG_ERR_REJ_VERSION, /* MSG_INTL(MSG_ERR_REJ_VERSION) */ 234 MSG_ERR_REJ_HAL, /* MSG_INTL(MSG_ERR_REJ_HAL) */ 235 MSG_ERR_REJ_US3, /* MSG_INTL(MSG_ERR_REJ_US3) */ 236 MSG_ERR_REJ_STR, /* MSG_INTL(MSG_ERR_REJ_STR) */ 237 MSG_ERR_REJ_UNKFILE, /* MSG_INTL(MSG_ERR_REJ_UNKFILE) */ 238 MSG_ERR_REJ_HWCAP_1, /* MSG_INTL(MSG_ERR_REJ_HWCAP_1) */ 239 }; 240