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