17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55aefb655Srie * Common Development and Distribution License (the "License"). 65aefb655Srie * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21bebb829dSRod Evans 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright (c) 1988 AT&T 247c478bd9Sstevel@tonic-gate * All Rights Reserved 257c478bd9Sstevel@tonic-gate * 26dc0f59e5SAli Bahrami * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/mman.h> 317c478bd9Sstevel@tonic-gate #include <signal.h> 327c478bd9Sstevel@tonic-gate #include <dlfcn.h> 337c478bd9Sstevel@tonic-gate #include <synch.h> 345aefb655Srie #include <debug.h> 357c478bd9Sstevel@tonic-gate #include "_rtld.h" 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate /* 387c478bd9Sstevel@tonic-gate * Declarations of global variables used in ld.so. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate Rt_lock rtldlock; 418cd45542Sraf int thr_flg_nolock = 0; 428cd45542Sraf int thr_flg_reenter = 0; 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* 457c478bd9Sstevel@tonic-gate * Major link-map lists. 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate Lm_list lml_main = { 0 }; /* the `main's link map list */ 487c478bd9Sstevel@tonic-gate Lm_list lml_rtld = { 0 }; /* rtld's link map list */ 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 519aa23310Srie * Entrance count. Each time ld.so.1 is entered following initial process 529aa23310Srie * setup, this count is bumped. This value serves to identify the present 539aa23310Srie * ld.so.1 operation. 549aa23310Srie * 559aa23310Srie * An ld.so.1 operation can result in many symbol lookup requests (i.e., loading 569aa23310Srie * objects and relocating all symbolic bindings). This count is used to protect 579aa23310Srie * against attempting to re-load a failed lazy load within a single call to 589aa23310Srie * ld.so.1, while allowing such attempts across calls. Should a lazy load fail, 599aa23310Srie * the present operation identifier is saved in the current symbol lookup data 6075e7992aSrie * block (Slookup). Should a lazy load fall back operation be triggered, the 6175e7992aSrie * identifier in the symbol lookup block is compared to the current ld.so.1 6275e7992aSrie * entry count, and if the two are equal the fall back is skipped. 6375e7992aSrie * 6475e7992aSrie * With this count, there is a danger of wrap-around, although as an unsigned 6575e7992aSrie * 32-bit value, it is highly unlikely that any application could usefully make 6675e7992aSrie * 4.3 giga-calls into ld.so.1. The worst that can occur is that a fall back 6775e7992aSrie * lazy load isn't triggered. However, most lazy loads that fail typically 6875e7992aSrie * continue to fail unless the user takes corrective action (adds the necessary 699aa23310Srie * (fixed) dependencies to the system). 7075e7992aSrie */ 719aa23310Srie ulong_t ld_entry_cnt = 1; 7275e7992aSrie 7375e7992aSrie /* 747c478bd9Sstevel@tonic-gate * BEGIN: Exposed to rtld_db, don't change without a coordinated handshake with 757c478bd9Sstevel@tonic-gate * librtld_db (remembering that librtld_db must be able to read old as well as 767c478bd9Sstevel@tonic-gate * current core files). 777c478bd9Sstevel@tonic-gate */ 7857ef7aa9SRod Evans APlist *dynlm_list = NULL; /* dynamic list of link-maps */ 797c478bd9Sstevel@tonic-gate /* 807c478bd9Sstevel@tonic-gate * END: Exposed to rtld_db 817c478bd9Sstevel@tonic-gate */ 827c478bd9Sstevel@tonic-gate 8356deab07SRod Evans Reglist *reglist = NULL; /* list of register symbols */ 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /* 869aa23310Srie * Set of integers to track how many of what type of PLT's have been bound. 879aa23310Srie * This is only really interesting for SPARC since ia32 has only one PLT. 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate uint32_t pltcnt21d = 0; 907c478bd9Sstevel@tonic-gate uint32_t pltcnt24d = 0; 917c478bd9Sstevel@tonic-gate uint32_t pltcntu32 = 0; 927c478bd9Sstevel@tonic-gate uint32_t pltcntu44 = 0; 937c478bd9Sstevel@tonic-gate uint32_t pltcntfull = 0; 947c478bd9Sstevel@tonic-gate uint32_t pltcntfar = 0; 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* 9708278a5eSRod Evans * AVL tree pointers. 989aa23310Srie */ 9908278a5eSRod Evans avl_tree_t *capavl = NULL; /* capabilities files */ 10008278a5eSRod Evans avl_tree_t *nfavl = NULL; /* not-found path names */ 10108278a5eSRod Evans avl_tree_t *spavl = NULL; /* secure path names */ 1029aa23310Srie 1039aa23310Srie /* 1047c478bd9Sstevel@tonic-gate * Various other global data. 1057c478bd9Sstevel@tonic-gate */ 10656deab07SRod Evans uint_t rtld_flags = 0; 10756deab07SRod Evans uint_t rtld_flags2 = 0; 10856deab07SRod Evans 10910a4fa49Srie Lc_desc glcs[CI_MAX]; /* global external interfaces */ 11010a4fa49Srie 11156deab07SRod Evans const char *procname = NULL; 11241072f3cSrie const char *rtldname = MSG_ORIG(MSG_FIL_RTLD); 11341072f3cSrie 11456deab07SRod Evans char *lasterr = NULL; /* string describing last error */ 1157c478bd9Sstevel@tonic-gate /* cleared by each dlerror() */ 11656deab07SRod Evans Interp *interp = NULL; /* ELF interpreter info */ 11756deab07SRod Evans APlist *hdl_alp[HDLIST_SZ+2]; /* dlopen() handle list */ 1187c478bd9Sstevel@tonic-gate size_t syspagsz = 0; /* system page size */ 11956deab07SRod Evans ulong_t at_flags = 0; /* machine specific file flags */ 12056deab07SRod Evans Uts_desc *uts = NULL; /* utsname descriptor */ 12156deab07SRod Evans Isa_desc *isa = NULL; /* isalist descriptor */ 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate uint_t audit_argcnt = 64; /* no. of stack args to copy (default */ 1247c478bd9Sstevel@tonic-gate /* is all) */ 12556deab07SRod Evans Audit_desc *auditors = NULL; /* global auditors (LD_AUDIT) */ 1262020b2b6SRod Evans APlist *aud_preinit = NULL; /* list of objects defining local */ 1272020b2b6SRod Evans APlist *aud_activity = NULL; /* preinit and activity auditors */ 1287c478bd9Sstevel@tonic-gate 12956deab07SRod Evans const char *rpl_audit = NULL; /* replaceable LD_AUDIT string */ 13056deab07SRod Evans const char *rpl_debug = NULL; /* replaceable LD_DEBUG string */ 13156deab07SRod Evans const char *rpl_ldflags = NULL; /* replaceable LD_FLAGS string */ 13256deab07SRod Evans const char *rpl_libpath = NULL; /* replaceable LD_LIBRARY_PATH string */ 13356deab07SRod Evans Alist *rpl_libdirs = NULL; /* and associated Pdesc list */ 13456deab07SRod Evans const char *rpl_preload = NULL; /* replaceable LD_PRELOAD string */ 1357c478bd9Sstevel@tonic-gate 13656deab07SRod Evans const char *prm_audit = NULL; /* permanent LD_AUDIT string */ 13756deab07SRod Evans const char *prm_debug = NULL; /* permanent LD_DEBUG string */ 13856deab07SRod Evans const char *prm_ldflags = NULL; /* permanent LD_FLAGS string */ 13956deab07SRod Evans const char *prm_libpath = NULL; /* permanent LD_LIBRARY_PATH string */ 14056deab07SRod Evans Alist *prm_libdirs = NULL; /* and associated Pdesc list */ 14156deab07SRod Evans const char *prm_preload = NULL; /* permanent LD_PRELOAD string */ 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate uint_t env_info = 0; /* information regarding environment */ 1447c478bd9Sstevel@tonic-gate /* variables */ 1457c478bd9Sstevel@tonic-gate int killsig = SIGKILL; /* signal sent on fatal exit */ 14656deab07SRod Evans APlist *free_alp = NULL; /* defragmentation list */ 1475aefb655Srie 1485aefb655Srie /* 14908278a5eSRod Evans * Capabilities are provided by the system. However, users can define an 15008278a5eSRod Evans * alternative set of system capabilities, where they can add, subtract, or 15108278a5eSRod Evans * override the system capabilities for testing purposes. Furthermore, these 15208278a5eSRod Evans * alternative capabilities can be specified such that they only apply to 15308278a5eSRod Evans * specified files rather than to all objects. 154*f3390f39SRobert Mustacchi * 155*f3390f39SRobert Mustacchi * The org_scapset is relied upon by the amd64 version of elf_rtbndr to 156*f3390f39SRobert Mustacchi * determine whether or not AVX registers are present in the system. 15708278a5eSRod Evans */ 15808278a5eSRod Evans static Syscapset scapset = { 0 }; 15908278a5eSRod Evans Syscapset *org_scapset = &scapset; /* original system and */ 16008278a5eSRod Evans Syscapset *alt_scapset = &scapset; /* alternative system */ 16108278a5eSRod Evans /* capabilities */ 16208278a5eSRod Evans 16308278a5eSRod Evans const char *rpl_hwcap = NULL; /* replaceable hwcap str */ 16408278a5eSRod Evans const char *rpl_sfcap = NULL; /* replaceable sfcap str */ 16508278a5eSRod Evans const char *rpl_machcap = NULL; /* replaceable machcap str */ 16608278a5eSRod Evans const char *rpl_platcap = NULL; /* replaceable platcap str */ 16708278a5eSRod Evans const char *rpl_cap_files = NULL; /* associated files */ 16808278a5eSRod Evans 16908278a5eSRod Evans const char *prm_hwcap = NULL; /* permanent hwcap str */ 17008278a5eSRod Evans const char *prm_sfcap = NULL; /* permanent sfcap str */ 17108278a5eSRod Evans const char *prm_machcap = NULL; /* permanent machcap str */ 17208278a5eSRod Evans const char *prm_platcap = NULL; /* permanent platcap str */ 17308278a5eSRod Evans const char *prm_cap_files = NULL; /* associated files */ 17408278a5eSRod Evans 17508278a5eSRod Evans /* 1765aefb655Srie * Note, the debugging descriptor interposes on the default definition provided 1775aefb655Srie * by liblddbg. This is required as ld.so.1 must only have outstanding relative 1785aefb655Srie * relocations. 1795aefb655Srie */ 1805aefb655Srie static Dbg_desc _dbg_desc = {0, 0, 0}; 1815aefb655Srie Dbg_desc *dbg_desc = &_dbg_desc; /* debugging descriptor */ 18256deab07SRod Evans const char *dbg_file = NULL; /* debugging directed to file */ 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate #pragma weak environ = _environ /* environ for PLT tracing - we */ 18556deab07SRod Evans char **_environ = NULL; /* supply the pair to satisfy any */ 1867c478bd9Sstevel@tonic-gate /* libc requirements (hwmuldiv) */ 1877c478bd9Sstevel@tonic-gate 18856deab07SRod Evans const char *profile_name = NULL; /* object being profiled */ 18956deab07SRod Evans const char *profile_out = NULL; /* profile output file */ 19056deab07SRod Evans const char *profile_lib = NULL; /* audit library to perform profile */ 1917c478bd9Sstevel@tonic-gate 19256deab07SRod Evans uchar_t search_rules[] = { /* dependency search rules */ 1937c478bd9Sstevel@tonic-gate RPLENV, /* replaceable LD_LIBRARY_PATH */ 1947c478bd9Sstevel@tonic-gate PRMENV, /* permanent LD_LIBRARY_PATH */ 1957c478bd9Sstevel@tonic-gate RUNPATH, /* callers runpath */ 1967c478bd9Sstevel@tonic-gate DEFAULT, /* default library path */ 1977c478bd9Sstevel@tonic-gate 0 1987c478bd9Sstevel@tonic-gate }; 1997c478bd9Sstevel@tonic-gate 20041072f3cSrie Dl_argsinfo argsinfo = { 0 }; /* process argument, environment and */ 20141072f3cSrie /* auxv information. */ 20241072f3cSrie 2037c478bd9Sstevel@tonic-gate /* 2047c478bd9Sstevel@tonic-gate * Frequently used messages are cached here to reduce _dgettext() overhead and 2057c478bd9Sstevel@tonic-gate * also provide for resetting should the locale change (see _ld_libc()). 2067c478bd9Sstevel@tonic-gate */ 20743d7826aSRod Evans const char *err_strs[ERR_NUM] = { NULL }; 20856deab07SRod Evans const char *nosym_str = NULL; 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate /* 2127c478bd9Sstevel@tonic-gate * Rejection error message tables. 2137c478bd9Sstevel@tonic-gate */ 2147c478bd9Sstevel@tonic-gate const Msg 215dc0f59e5SAli Bahrami ldd_reject[SGS_REJ_NUM] = { 2167c478bd9Sstevel@tonic-gate MSG_STR_EMPTY, 2177c478bd9Sstevel@tonic-gate MSG_LDD_REJ_MACH, /* MSG_INTL(MSG_LDD_REJ_MACH) */ 2187c478bd9Sstevel@tonic-gate MSG_LDD_REJ_CLASS, /* MSG_INTL(MSG_LDD_REJ_CLASS) */ 2197c478bd9Sstevel@tonic-gate MSG_LDD_REJ_DATA, /* MSG_INTL(MSG_LDD_REJ_DATA) */ 2207c478bd9Sstevel@tonic-gate MSG_LDD_REJ_TYPE, /* MSG_INTL(MSG_LDD_REJ_TYPE) */ 2217c478bd9Sstevel@tonic-gate MSG_LDD_REJ_BADFLAG, /* MSG_INTL(MSG_LDD_REJ_BADFLAG) */ 2227c478bd9Sstevel@tonic-gate MSG_LDD_REJ_MISFLAG, /* MSG_INTL(MSG_LDD_REJ_MISFLAG) */ 2237c478bd9Sstevel@tonic-gate MSG_LDD_REJ_VERSION, /* MSG_INTL(MSG_LDD_REJ_VERSION) */ 2247c478bd9Sstevel@tonic-gate MSG_LDD_REJ_HAL, /* MSG_INTL(MSG_LDD_REJ_HAL) */ 2257c478bd9Sstevel@tonic-gate MSG_LDD_REJ_US3, /* MSG_INTL(MSG_LDD_REJ_US3) */ 2267c478bd9Sstevel@tonic-gate MSG_LDD_REJ_STR, /* MSG_INTL(MSG_LDD_REJ_STR) */ 2277c478bd9Sstevel@tonic-gate MSG_LDD_REJ_UNKFILE, /* MSG_INTL(MSG_LDD_REJ_UNKFILE) */ 22808278a5eSRod Evans MSG_LDD_REJ_UNKCAP, /* MSG_INTL(MSG_LDD_REJ_UNKCAP) */ 2297c478bd9Sstevel@tonic-gate MSG_LDD_REJ_HWCAP_1, /* MSG_INTL(MSG_LDD_REJ_HWCAP_1) */ 230bebb829dSRod Evans MSG_LDD_REJ_SFCAP_1, /* MSG_INTL(MSG_LDD_REJ_SFCAP_1) */ 23108278a5eSRod Evans MSG_LDD_REJ_MACHCAP, /* MSG_INTL(MSG_LDD_REJ_MACHCAP) */ 23208278a5eSRod Evans MSG_LDD_REJ_PLATCAP, /* MSG_INTL(MSG_LDD_REJ_PLATCAP) */ 233dc0f59e5SAli Bahrami MSG_LDD_REJ_HWCAP_2, /* MSG_INTL(MSG_LDD_REJ_HWCAP_2) */ 234dc0f59e5SAli Bahrami MSG_LDD_REJ_ARCHIVE /* MSG_INTL(MSG_LDD_REJ_ARCHIVE) */ 2357c478bd9Sstevel@tonic-gate }; 236dc0f59e5SAli Bahrami #if SGS_REJ_NUM != (SGS_REJ_ARCHIVE + 1) 237dc0f59e5SAli Bahrami #error SGS_REJ_NUM has changed 238dc0f59e5SAli Bahrami #endif 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate const Msg 241dc0f59e5SAli Bahrami err_reject[SGS_REJ_NUM] = { 2427c478bd9Sstevel@tonic-gate MSG_STR_EMPTY, 2437c478bd9Sstevel@tonic-gate MSG_ERR_REJ_MACH, /* MSG_INTL(MSG_ERR_REJ_MACH) */ 2447c478bd9Sstevel@tonic-gate MSG_ERR_REJ_CLASS, /* MSG_INTL(MSG_ERR_REJ_CLASS) */ 2457c478bd9Sstevel@tonic-gate MSG_ERR_REJ_DATA, /* MSG_INTL(MSG_ERR_REJ_DATA) */ 2467c478bd9Sstevel@tonic-gate MSG_ERR_REJ_TYPE, /* MSG_INTL(MSG_ERR_REJ_TYPE) */ 2477c478bd9Sstevel@tonic-gate MSG_ERR_REJ_BADFLAG, /* MSG_INTL(MSG_ERR_REJ_BADFLAG) */ 2487c478bd9Sstevel@tonic-gate MSG_ERR_REJ_MISFLAG, /* MSG_INTL(MSG_ERR_REJ_MISFLAG) */ 2497c478bd9Sstevel@tonic-gate MSG_ERR_REJ_VERSION, /* MSG_INTL(MSG_ERR_REJ_VERSION) */ 2507c478bd9Sstevel@tonic-gate MSG_ERR_REJ_HAL, /* MSG_INTL(MSG_ERR_REJ_HAL) */ 2517c478bd9Sstevel@tonic-gate MSG_ERR_REJ_US3, /* MSG_INTL(MSG_ERR_REJ_US3) */ 2527c478bd9Sstevel@tonic-gate MSG_ERR_REJ_STR, /* MSG_INTL(MSG_ERR_REJ_STR) */ 2537c478bd9Sstevel@tonic-gate MSG_ERR_REJ_UNKFILE, /* MSG_INTL(MSG_ERR_REJ_UNKFILE) */ 25408278a5eSRod Evans MSG_ERR_REJ_UNKCAP, /* MSG_INTL(MSG_ERR_REJ_UNKCAP) */ 2557c478bd9Sstevel@tonic-gate MSG_ERR_REJ_HWCAP_1, /* MSG_INTL(MSG_ERR_REJ_HWCAP_1) */ 256bebb829dSRod Evans MSG_ERR_REJ_SFCAP_1, /* MSG_INTL(MSG_ERR_REJ_SFCAP_1) */ 25708278a5eSRod Evans MSG_ERR_REJ_MACHCAP, /* MSG_INTL(MSG_ERR_REJ_MACHCAP) */ 25808278a5eSRod Evans MSG_ERR_REJ_PLATCAP, /* MSG_INTL(MSG_ERR_REJ_PLATCAP) */ 259dc0f59e5SAli Bahrami MSG_ERR_REJ_HWCAP_2, /* MSG_INTL(MSG_ERR_REJ_HWCAP_2) */ 260dc0f59e5SAli Bahrami MSG_ERR_REJ_ARCHIVE, /* MSG_INTL(MSG_ERR_REJ_ARCHIVE) */ 26108278a5eSRod Evans }; 262dc0f59e5SAli Bahrami #if SGS_REJ_NUM != (SGS_REJ_ARCHIVE + 1) 263dc0f59e5SAli Bahrami #error SGS_REJ_NUM has changed 264dc0f59e5SAli Bahrami #endif 26508278a5eSRod Evans 26608278a5eSRod Evans const Msg 267dc0f59e5SAli Bahrami ldd_warn[SGS_REJ_NUM] = { 26808278a5eSRod Evans MSG_STR_EMPTY, 26908278a5eSRod Evans MSG_STR_EMPTY, 27008278a5eSRod Evans MSG_STR_EMPTY, 27108278a5eSRod Evans MSG_STR_EMPTY, 27208278a5eSRod Evans MSG_STR_EMPTY, 27308278a5eSRod Evans MSG_STR_EMPTY, 27408278a5eSRod Evans MSG_STR_EMPTY, 27508278a5eSRod Evans MSG_STR_EMPTY, 27608278a5eSRod Evans MSG_STR_EMPTY, 27708278a5eSRod Evans MSG_STR_EMPTY, 27808278a5eSRod Evans MSG_STR_EMPTY, 27908278a5eSRod Evans MSG_STR_EMPTY, 28008278a5eSRod Evans MSG_LDD_WARN_UNKCAP, /* MSG_INTL(MSG_LDD_WARN_UNKCAP) */ 28108278a5eSRod Evans MSG_LDD_WARN_HWCAP_1, /* MSG_INTL(MSG_LDD_WARN_HWCAP_1) */ 28208278a5eSRod Evans MSG_LDD_WARN_SFCAP_1, /* MSG_INTL(MSG_LDD_WARN_SFCAP_1) */ 28308278a5eSRod Evans MSG_LDD_WARN_MACHCAP, /* MSG_INTL(MSG_LDD_WARN_MACHCAP) */ 28408278a5eSRod Evans MSG_LDD_WARN_PLATCAP, /* MSG_INTL(MSG_LDD_WARN_PLATCAP) */ 285dc0f59e5SAli Bahrami MSG_LDD_WARN_HWCAP_2, /* MSG_INTL(MSG_LDD_WARN_HWCAP_2) */ 286dc0f59e5SAli Bahrami MSG_STR_EMPTY 2877c478bd9Sstevel@tonic-gate }; 288dc0f59e5SAli Bahrami #if SGS_REJ_NUM != (SGS_REJ_ARCHIVE + 1) 289dc0f59e5SAli Bahrami #error SGS_REJ_NUM has changed 290dc0f59e5SAli Bahrami #endif 291