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 2006 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 * 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 *procname = (const char *)0; 103 const char *rtldname = MSG_ORIG(MSG_FIL_RTLD); 104 105 char *lasterr = (char *)0; /* string describing last error */ 106 /* cleared by each dlerror() */ 107 Interp *interp = 0; /* ELF interpreter info */ 108 List hdl_list[HDLIST_SZ+2]; /* dlopen() handle list */ 109 size_t syspagsz = 0; /* system page size */ 110 unsigned long at_flags = 0; /* machine specific file flags */ 111 char *platform = 0; /* platform name from AT_SUN_PLATFORM */ 112 size_t platform_sz = 0; /* platform string length */ 113 Uts_desc *uts; /* utsname descriptor */ 114 Isa_desc *isa; /* isalist descriptor */ 115 116 uint_t audit_argcnt = 64; /* no. of stack args to copy (default */ 117 /* is all) */ 118 Audit_desc *auditors = 0; /* global auditors (LD_AUDIT) */ 119 120 const char *locale = 0; /* locale environment definition */ 121 122 const char *rpl_audit = 0; /* replaceable LD_AUDIT string */ 123 const char *rpl_debug = 0; /* replaceable LD_DEBUG string */ 124 const char *rpl_ldflags = 0; /* replaceable LD_FLAGS string */ 125 const char *rpl_libpath = 0; /* replaceable LD_LIBRARY_PATH string */ 126 Pnode *rpl_libdirs = 0; /* and associated Pnode list */ 127 const char *rpl_preload = 0; /* replaceable LD_PRELOAD string */ 128 129 const char *prm_audit = 0; /* permanent LD_AUDIT string */ 130 const char *prm_debug = 0; /* permanent LD_DEBUG string */ 131 const char *prm_ldflags = 0; /* permanent LD_FLAGS string */ 132 const char *prm_libpath = 0; /* permanent LD_LIBRARY_PATH string */ 133 Pnode *prm_libdirs = 0; /* and associated Pnode list */ 134 const char *prm_preload = 0; /* permanent LD_PRELOAD string */ 135 136 uint_t env_info = 0; /* information regarding environment */ 137 /* variables */ 138 int killsig = SIGKILL; /* signal sent on fatal exit */ 139 140 /* 141 * Note, the debugging descriptor interposes on the default definition provided 142 * by liblddbg. This is required as ld.so.1 must only have outstanding relative 143 * relocations. 144 */ 145 static Dbg_desc _dbg_desc = {0, 0, 0}; 146 Dbg_desc *dbg_desc = &_dbg_desc; /* debugging descriptor */ 147 const char *dbg_file = 0; /* debugging directed to file */ 148 149 #pragma weak environ = _environ /* environ for PLT tracing - we */ 150 char **_environ = 0; /* supply the pair to satisfy any */ 151 /* libc requirements (hwmuldiv) */ 152 153 const char *profile_name; /* object being profiled */ 154 const char *profile_out; /* profile output file */ 155 const char *profile_lib; /* audit library to perform profile */ 156 157 unsigned char search_rules[] = { /* dependency search rules */ 158 RPLENV, /* replaceable LD_LIBRARY_PATH */ 159 PRMENV, /* permanent LD_LIBRARY_PATH */ 160 RUNPATH, /* callers runpath */ 161 DEFAULT, /* default library path */ 162 0 163 }; 164 165 Dl_argsinfo argsinfo = { 0 }; /* process argument, environment and */ 166 /* auxv information. */ 167 168 /* 169 * Frequently used messages are cached here to reduce _dgettext() overhead and 170 * also provide for resetting should the locale change (see _ld_libc()). 171 */ 172 const char *err_strs[ERR_NUM] = { 0 }; 173 const char *nosym_str = 0; 174 175 176 /* 177 * Rejection error message tables. 178 */ 179 const Msg 180 ldd_reject[] = { 181 MSG_STR_EMPTY, 182 MSG_LDD_REJ_MACH, /* MSG_INTL(MSG_LDD_REJ_MACH) */ 183 MSG_LDD_REJ_CLASS, /* MSG_INTL(MSG_LDD_REJ_CLASS) */ 184 MSG_LDD_REJ_DATA, /* MSG_INTL(MSG_LDD_REJ_DATA) */ 185 MSG_LDD_REJ_TYPE, /* MSG_INTL(MSG_LDD_REJ_TYPE) */ 186 MSG_LDD_REJ_BADFLAG, /* MSG_INTL(MSG_LDD_REJ_BADFLAG) */ 187 MSG_LDD_REJ_MISFLAG, /* MSG_INTL(MSG_LDD_REJ_MISFLAG) */ 188 MSG_LDD_REJ_VERSION, /* MSG_INTL(MSG_LDD_REJ_VERSION) */ 189 MSG_LDD_REJ_HAL, /* MSG_INTL(MSG_LDD_REJ_HAL) */ 190 MSG_LDD_REJ_US3, /* MSG_INTL(MSG_LDD_REJ_US3) */ 191 MSG_LDD_REJ_STR, /* MSG_INTL(MSG_LDD_REJ_STR) */ 192 MSG_LDD_REJ_UNKFILE, /* MSG_INTL(MSG_LDD_REJ_UNKFILE) */ 193 MSG_LDD_REJ_HWCAP_1, /* MSG_INTL(MSG_LDD_REJ_HWCAP_1) */ 194 }; 195 196 197 const Msg 198 err_reject[] = { 199 MSG_STR_EMPTY, 200 MSG_ERR_REJ_MACH, /* MSG_INTL(MSG_ERR_REJ_MACH) */ 201 MSG_ERR_REJ_CLASS, /* MSG_INTL(MSG_ERR_REJ_CLASS) */ 202 MSG_ERR_REJ_DATA, /* MSG_INTL(MSG_ERR_REJ_DATA) */ 203 MSG_ERR_REJ_TYPE, /* MSG_INTL(MSG_ERR_REJ_TYPE) */ 204 MSG_ERR_REJ_BADFLAG, /* MSG_INTL(MSG_ERR_REJ_BADFLAG) */ 205 MSG_ERR_REJ_MISFLAG, /* MSG_INTL(MSG_ERR_REJ_MISFLAG) */ 206 MSG_ERR_REJ_VERSION, /* MSG_INTL(MSG_ERR_REJ_VERSION) */ 207 MSG_ERR_REJ_HAL, /* MSG_INTL(MSG_ERR_REJ_HAL) */ 208 MSG_ERR_REJ_US3, /* MSG_INTL(MSG_ERR_REJ_US3) */ 209 MSG_ERR_REJ_STR, /* MSG_INTL(MSG_ERR_REJ_STR) */ 210 MSG_ERR_REJ_UNKFILE, /* MSG_INTL(MSG_ERR_REJ_UNKFILE) */ 211 MSG_ERR_REJ_HWCAP_1, /* MSG_INTL(MSG_ERR_REJ_HWCAP_1) */ 212 }; 213