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 */ 2111a2bb38Srie 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright (c) 1988 AT&T 247c478bd9Sstevel@tonic-gate * All Rights Reserved 257c478bd9Sstevel@tonic-gate * 26cce0e03bSab * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 277c478bd9Sstevel@tonic-gate * Use is subject to license terms. 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * Object file dependent support for ELF objects. 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate #include "_synonyms.h" 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include <stdio.h> 377c478bd9Sstevel@tonic-gate #include <sys/procfs.h> 387c478bd9Sstevel@tonic-gate #include <sys/mman.h> 397c478bd9Sstevel@tonic-gate #include <sys/debug.h> 407c478bd9Sstevel@tonic-gate #include <string.h> 417c478bd9Sstevel@tonic-gate #include <limits.h> 427c478bd9Sstevel@tonic-gate #include <dlfcn.h> 435aefb655Srie #include <debug.h> 445aefb655Srie #include <conv.h> 457c478bd9Sstevel@tonic-gate #include "_rtld.h" 467c478bd9Sstevel@tonic-gate #include "_audit.h" 477c478bd9Sstevel@tonic-gate #include "_elf.h" 487c478bd9Sstevel@tonic-gate #include "msg.h" 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * Default and secure dependency search paths. 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate static Pnode elf_dflt_dirs[] = { 547c478bd9Sstevel@tonic-gate #if defined(_ELF64) 557c478bd9Sstevel@tonic-gate #ifndef SGS_PRE_UNIFIED_PROCESS 567c478bd9Sstevel@tonic-gate { MSG_ORIG(MSG_PTH_LIB_64), 0, MSG_PTH_LIB_64_SIZE, 577c478bd9Sstevel@tonic-gate LA_SER_DEFAULT, 0, &elf_dflt_dirs[1] }, 587c478bd9Sstevel@tonic-gate #endif 597c478bd9Sstevel@tonic-gate { MSG_ORIG(MSG_PTH_USRLIB_64), 0, MSG_PTH_USRLIB_64_SIZE, 607c478bd9Sstevel@tonic-gate LA_SER_DEFAULT, 0, 0 } 617c478bd9Sstevel@tonic-gate #else 627c478bd9Sstevel@tonic-gate #ifndef SGS_PRE_UNIFIED_PROCESS 637c478bd9Sstevel@tonic-gate { MSG_ORIG(MSG_PTH_LIB), 0, MSG_PTH_LIB_SIZE, 647c478bd9Sstevel@tonic-gate LA_SER_DEFAULT, 0, &elf_dflt_dirs[1] }, 657c478bd9Sstevel@tonic-gate #endif 667c478bd9Sstevel@tonic-gate { MSG_ORIG(MSG_PTH_USRLIB), 0, MSG_PTH_USRLIB_SIZE, 677c478bd9Sstevel@tonic-gate LA_SER_DEFAULT, 0, 0 } 687c478bd9Sstevel@tonic-gate #endif 697c478bd9Sstevel@tonic-gate }; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate static Pnode elf_secure_dirs[] = { 727c478bd9Sstevel@tonic-gate #if defined(_ELF64) 737c478bd9Sstevel@tonic-gate #ifndef SGS_PRE_UNIFIED_PROCESS 747c478bd9Sstevel@tonic-gate { MSG_ORIG(MSG_PTH_LIBSE_64), 0, MSG_PTH_LIBSE_64_SIZE, 757c478bd9Sstevel@tonic-gate LA_SER_SECURE, 0, &elf_secure_dirs[1] }, 767c478bd9Sstevel@tonic-gate #endif 777c478bd9Sstevel@tonic-gate { MSG_ORIG(MSG_PTH_USRLIBSE_64), 0, 787c478bd9Sstevel@tonic-gate MSG_PTH_USRLIBSE_64_SIZE, 797c478bd9Sstevel@tonic-gate LA_SER_SECURE, 0, 0 } 807c478bd9Sstevel@tonic-gate #else 817c478bd9Sstevel@tonic-gate #ifndef SGS_PRE_UNIFIED_PROCESS 827c478bd9Sstevel@tonic-gate { MSG_ORIG(MSG_PTH_LIBSE), 0, MSG_PTH_LIBSE_SIZE, 837c478bd9Sstevel@tonic-gate LA_SER_SECURE, 0, &elf_secure_dirs[1] }, 847c478bd9Sstevel@tonic-gate #endif 857c478bd9Sstevel@tonic-gate { MSG_ORIG(MSG_PTH_USRLIBSE), 0, MSG_PTH_USRLIBSE_SIZE, 867c478bd9Sstevel@tonic-gate LA_SER_SECURE, 0, 0 } 877c478bd9Sstevel@tonic-gate #endif 887c478bd9Sstevel@tonic-gate }; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * Defines for local functions. 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate static Pnode *elf_fix_name(const char *, Rt_map *, uint_t); 947c478bd9Sstevel@tonic-gate static int elf_are_u(Rej_desc *); 957c478bd9Sstevel@tonic-gate static void elf_dladdr(ulong_t, Rt_map *, Dl_info *, void **, int); 967c478bd9Sstevel@tonic-gate static ulong_t elf_entry_pt(void); 977c478bd9Sstevel@tonic-gate static char *elf_get_so(const char *, const char *); 987c478bd9Sstevel@tonic-gate static Rt_map *elf_map_so(Lm_list *, Aliste, const char *, const char *, int); 997c478bd9Sstevel@tonic-gate static int elf_needed(Lm_list *, Aliste, Rt_map *); 1007c478bd9Sstevel@tonic-gate static void elf_unmap_so(Rt_map *); 1017c478bd9Sstevel@tonic-gate static int elf_verify_vers(const char *, Rt_map *, Rt_map *); 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* 1047c478bd9Sstevel@tonic-gate * Functions and data accessed through indirect pointers. 1057c478bd9Sstevel@tonic-gate */ 1067c478bd9Sstevel@tonic-gate Fct elf_fct = { 1077c478bd9Sstevel@tonic-gate elf_are_u, 1087c478bd9Sstevel@tonic-gate elf_entry_pt, 1097c478bd9Sstevel@tonic-gate elf_map_so, 1107c478bd9Sstevel@tonic-gate elf_unmap_so, 1117c478bd9Sstevel@tonic-gate elf_needed, 1127c478bd9Sstevel@tonic-gate lookup_sym, 1137c478bd9Sstevel@tonic-gate elf_reloc, 1147c478bd9Sstevel@tonic-gate elf_dflt_dirs, 1157c478bd9Sstevel@tonic-gate elf_secure_dirs, 1167c478bd9Sstevel@tonic-gate elf_fix_name, 1177c478bd9Sstevel@tonic-gate elf_get_so, 1187c478bd9Sstevel@tonic-gate elf_dladdr, 1197c478bd9Sstevel@tonic-gate dlsym_handle, 1207c478bd9Sstevel@tonic-gate elf_verify_vers, 1217c478bd9Sstevel@tonic-gate elf_set_prot 1227c478bd9Sstevel@tonic-gate }; 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate /* 1267c478bd9Sstevel@tonic-gate * Redefine NEEDED name if necessary. 1277c478bd9Sstevel@tonic-gate */ 1287c478bd9Sstevel@tonic-gate static Pnode * 1297c478bd9Sstevel@tonic-gate elf_fix_name(const char *name, Rt_map *clmp, uint_t orig) 1307c478bd9Sstevel@tonic-gate { 1317c478bd9Sstevel@tonic-gate /* 1327c478bd9Sstevel@tonic-gate * For ABI compliance, if we are asked for ld.so.1, then really give 1337c478bd9Sstevel@tonic-gate * them libsys.so.1 (the SONAME of libsys.so.1 is ld.so.1). 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate if (((*name == '/') && 136a953e2b1Srie /* BEGIN CSTYLED */ 1377c478bd9Sstevel@tonic-gate #if defined(_ELF64) 1387c478bd9Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_PTH_RTLD_64)) == 0)) || 1397c478bd9Sstevel@tonic-gate #else 1407c478bd9Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_PTH_RTLD)) == 0)) || 1417c478bd9Sstevel@tonic-gate #endif 1427c478bd9Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_FIL_RTLD)) == 0)) { 143a953e2b1Srie /* END CSTYLED */ 1447c478bd9Sstevel@tonic-gate Pnode *pnp; 1457c478bd9Sstevel@tonic-gate 1465aefb655Srie DBG_CALL(Dbg_file_fixname(LIST(clmp), name, 1475aefb655Srie MSG_ORIG(MSG_PTH_LIBSYS))); 1487c478bd9Sstevel@tonic-gate if (((pnp = calloc(sizeof (Pnode), 1)) == 0) || 1497c478bd9Sstevel@tonic-gate ((pnp->p_name = strdup(MSG_ORIG(MSG_PTH_LIBSYS))) == 0)) { 1507c478bd9Sstevel@tonic-gate if (pnp) 1517c478bd9Sstevel@tonic-gate free(pnp); 1527c478bd9Sstevel@tonic-gate return (0); 1537c478bd9Sstevel@tonic-gate } 1547c478bd9Sstevel@tonic-gate pnp->p_len = MSG_PTH_LIBSYS_SIZE; 1557c478bd9Sstevel@tonic-gate pnp->p_orig = (orig & PN_SER_MASK); 1567c478bd9Sstevel@tonic-gate return (pnp); 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate return (expand_paths(clmp, name, orig, 0)); 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate /* 1637c478bd9Sstevel@tonic-gate * Determine if we have been given an ELF file and if so determine if the file 1647c478bd9Sstevel@tonic-gate * is compatible. Returns 1 if true, else 0 and sets the reject descriptor 1657c478bd9Sstevel@tonic-gate * with associated error information. 1667c478bd9Sstevel@tonic-gate */ 1677c478bd9Sstevel@tonic-gate static int 1687c478bd9Sstevel@tonic-gate elf_are_u(Rej_desc *rej) 1697c478bd9Sstevel@tonic-gate { 1707c478bd9Sstevel@tonic-gate Ehdr *ehdr; 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate /* 1737c478bd9Sstevel@tonic-gate * Determine if we're an elf file. If not simply return, we don't set 1747c478bd9Sstevel@tonic-gate * any rejection information as this test allows use to scroll through 1757c478bd9Sstevel@tonic-gate * the objects we support (ELF, AOUT). 1767c478bd9Sstevel@tonic-gate */ 1777c478bd9Sstevel@tonic-gate if (fmap->fm_fsize < sizeof (Ehdr) || 1787c478bd9Sstevel@tonic-gate fmap->fm_maddr[EI_MAG0] != ELFMAG0 || 1797c478bd9Sstevel@tonic-gate fmap->fm_maddr[EI_MAG1] != ELFMAG1 || 1807c478bd9Sstevel@tonic-gate fmap->fm_maddr[EI_MAG2] != ELFMAG2 || 1817c478bd9Sstevel@tonic-gate fmap->fm_maddr[EI_MAG3] != ELFMAG3) { 1827c478bd9Sstevel@tonic-gate return (0); 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* 1867c478bd9Sstevel@tonic-gate * Check class and encoding. 1877c478bd9Sstevel@tonic-gate */ 1887c478bd9Sstevel@tonic-gate /* LINTED */ 1897c478bd9Sstevel@tonic-gate ehdr = (Ehdr *)fmap->fm_maddr; 1907c478bd9Sstevel@tonic-gate if (ehdr->e_ident[EI_CLASS] != M_CLASS) { 1917c478bd9Sstevel@tonic-gate rej->rej_type = SGS_REJ_CLASS; 1927c478bd9Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_ident[EI_CLASS]; 1937c478bd9Sstevel@tonic-gate return (0); 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate if (ehdr->e_ident[EI_DATA] != M_DATA) { 1967c478bd9Sstevel@tonic-gate rej->rej_type = SGS_REJ_DATA; 1977c478bd9Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_ident[EI_DATA]; 1987c478bd9Sstevel@tonic-gate return (0); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate if ((ehdr->e_type != ET_REL) && (ehdr->e_type != ET_EXEC) && 2017c478bd9Sstevel@tonic-gate (ehdr->e_type != ET_DYN)) { 2027c478bd9Sstevel@tonic-gate rej->rej_type = SGS_REJ_TYPE; 2037c478bd9Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_type; 2047c478bd9Sstevel@tonic-gate return (0); 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate /* 2087c478bd9Sstevel@tonic-gate * Verify machine specific flags, and hardware capability requirements. 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate if ((elf_mach_flags_check(rej, ehdr) == 0) || 2117c478bd9Sstevel@tonic-gate ((rtld_flags2 & RT_FL2_HWCAP) && (hwcap_check(rej, ehdr) == 0))) 2127c478bd9Sstevel@tonic-gate return (0); 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate /* 2157c478bd9Sstevel@tonic-gate * Verify ELF version. ??? is this too restrictive ??? 2167c478bd9Sstevel@tonic-gate */ 2177c478bd9Sstevel@tonic-gate if (ehdr->e_version > EV_CURRENT) { 2187c478bd9Sstevel@tonic-gate rej->rej_type = SGS_REJ_VERSION; 2197c478bd9Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_version; 2207c478bd9Sstevel@tonic-gate return (0); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate return (1); 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate /* 2267c478bd9Sstevel@tonic-gate * The runtime linker employs lazy loading to provide the libraries needed for 2277c478bd9Sstevel@tonic-gate * debugging, preloading .o's and dldump(). As these are seldom used, the 2287c478bd9Sstevel@tonic-gate * standard startup of ld.so.1 doesn't initialize all the information necessary 2297c478bd9Sstevel@tonic-gate * to perform plt relocation on ld.so.1's link-map. The first time lazy loading 2307c478bd9Sstevel@tonic-gate * is called we get here to perform these initializations: 2317c478bd9Sstevel@tonic-gate * 2327c478bd9Sstevel@tonic-gate * o elf_needed() is called to set up the DYNINFO() indexes for each lazy 2337c478bd9Sstevel@tonic-gate * dependency. Typically, for all other objects, this is called during 2347c478bd9Sstevel@tonic-gate * analyze_so(), but as ld.so.1 is set-contained we skip this processing. 2357c478bd9Sstevel@tonic-gate * 2367c478bd9Sstevel@tonic-gate * o For intel, ld.so.1's JMPSLOT relocations need relative updates. These 2377c478bd9Sstevel@tonic-gate * are by default skipped thus delaying all relative relocation processing 2387c478bd9Sstevel@tonic-gate * on every invocation of ld.so.1. 2397c478bd9Sstevel@tonic-gate */ 2407c478bd9Sstevel@tonic-gate int 2417c478bd9Sstevel@tonic-gate elf_rtld_load() 2427c478bd9Sstevel@tonic-gate { 2437c478bd9Sstevel@tonic-gate Lm_list *lml = &lml_rtld; 2447c478bd9Sstevel@tonic-gate Rt_map *lmp = lml->lm_head; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate if (lml->lm_flags & LML_FLG_PLTREL) 2477c478bd9Sstevel@tonic-gate return (1); 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate /* 2507c478bd9Sstevel@tonic-gate * As we need to refer to the DYNINFO() information, insure that it has 2517c478bd9Sstevel@tonic-gate * been initialized. 2527c478bd9Sstevel@tonic-gate */ 253cce0e03bSab if (elf_needed(lml, ALIST_OFF_DATA, lmp) == 0) 2547c478bd9Sstevel@tonic-gate return (0); 2557c478bd9Sstevel@tonic-gate 25602ca3e02Srie #if defined(__i386) 2577c478bd9Sstevel@tonic-gate /* 2587c478bd9Sstevel@tonic-gate * This is a kludge to give ld.so.1 a performance benefit on i386. 2597c478bd9Sstevel@tonic-gate * It's based around two factors. 2607c478bd9Sstevel@tonic-gate * 2617c478bd9Sstevel@tonic-gate * o JMPSLOT relocations (PLT's) actually need a relative relocation 2627c478bd9Sstevel@tonic-gate * applied to the GOT entry so that they can find PLT0. 2637c478bd9Sstevel@tonic-gate * 2647c478bd9Sstevel@tonic-gate * o ld.so.1 does not exercise *any* PLT's before it has made a call 2657c478bd9Sstevel@tonic-gate * to elf_lazy_load(). This is because all dynamic dependencies 2667c478bd9Sstevel@tonic-gate * are recorded as lazy dependencies. 2677c478bd9Sstevel@tonic-gate */ 2687c478bd9Sstevel@tonic-gate (void) elf_reloc_relacount((ulong_t)JMPREL(lmp), 2697c478bd9Sstevel@tonic-gate (ulong_t)(PLTRELSZ(lmp) / RELENT(lmp)), (ulong_t)RELENT(lmp), 2707c478bd9Sstevel@tonic-gate (ulong_t)ADDR(lmp)); 2717c478bd9Sstevel@tonic-gate #endif 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate lml->lm_flags |= LML_FLG_PLTREL; 2747c478bd9Sstevel@tonic-gate return (1); 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate /* 2787c478bd9Sstevel@tonic-gate * Lazy load an object. 2797c478bd9Sstevel@tonic-gate */ 2807c478bd9Sstevel@tonic-gate Rt_map * 281*75e7992aSrie elf_lazy_load(Rt_map *clmp, Slookup *slp, uint_t ndx, const char *sym) 2827c478bd9Sstevel@tonic-gate { 2837c478bd9Sstevel@tonic-gate Rt_map *nlmp, *hlmp; 284*75e7992aSrie Dyninfo *dip = &DYNINFO(clmp)[ndx], *pdip; 2857c478bd9Sstevel@tonic-gate uint_t flags = 0; 2867c478bd9Sstevel@tonic-gate Pnode *pnp; 2877c478bd9Sstevel@tonic-gate const char *name; 2887c478bd9Sstevel@tonic-gate Lm_list *lml = LIST(clmp); 2897c478bd9Sstevel@tonic-gate Lm_cntl *lmc; 2907c478bd9Sstevel@tonic-gate Aliste lmco; 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate /* 2937c478bd9Sstevel@tonic-gate * If this dependency has already been processed, we're done. 2947c478bd9Sstevel@tonic-gate */ 2957c478bd9Sstevel@tonic-gate if (((nlmp = (Rt_map *)dip->di_info) != 0) || 296*75e7992aSrie (dip->di_flags & FLG_DI_LDD_DONE)) 2977c478bd9Sstevel@tonic-gate return (nlmp); 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate /* 300*75e7992aSrie * If we're running under ldd(1), indicate that this dependency has been 301*75e7992aSrie * processed (see test above). It doesn't matter whether the object is 302*75e7992aSrie * successfully loaded or not, this flag simply ensures that we don't 303*75e7992aSrie * repeatedly attempt to load an object that has already failed to load. 304*75e7992aSrie * To do so would create multiple failure diagnostics for the same 305*75e7992aSrie * object under ldd(1). 306*75e7992aSrie */ 307*75e7992aSrie if (lml->lm_flags & LML_FLG_TRC_ENABLE) 308*75e7992aSrie dip->di_flags |= FLG_DI_LDD_DONE; 309*75e7992aSrie 310*75e7992aSrie /* 311*75e7992aSrie * Determine the initial dependency name. 3127c478bd9Sstevel@tonic-gate */ 3137c478bd9Sstevel@tonic-gate name = STRTAB(clmp) + DYN(clmp)[ndx].d_un.d_val; 3145aefb655Srie DBG_CALL(Dbg_file_lazyload(clmp, name, sym)); 3157c478bd9Sstevel@tonic-gate 316*75e7992aSrie /* 317*75e7992aSrie * If this object needs to establish its own group, make sure a handle 318*75e7992aSrie * is created. 319*75e7992aSrie */ 3207c478bd9Sstevel@tonic-gate if (dip->di_flags & FLG_DI_GROUP) 3217c478bd9Sstevel@tonic-gate flags |= (FLG_RT_SETGROUP | FLG_RT_HANDLE); 3227c478bd9Sstevel@tonic-gate 323*75e7992aSrie /* 324*75e7992aSrie * Lazy dependencies are identified as DT_NEEDED entries with a 325*75e7992aSrie * DF_P1_LAZYLOAD flag in the previous DT_POSFLAG_1 element. The 326*75e7992aSrie * dynamic information element that corresponds to the DT_POSFLAG_1 327*75e7992aSrie * entry is free, and thus used to store the present entrance 328*75e7992aSrie * identifier. This identifier is used to prevent multiple attempts to 329*75e7992aSrie * load a failed lazy loadable dependency within the same runtime linker 330*75e7992aSrie * operation. However, future attempts to reload this dependency are 331*75e7992aSrie * still possible. 332*75e7992aSrie */ 333*75e7992aSrie if (ndx && (pdip = dip - 1) && (pdip->di_flags & FLG_DI_POSFLAG1)) 334*75e7992aSrie pdip->di_info = (void *)slp->sl_id; 335*75e7992aSrie 3367c478bd9Sstevel@tonic-gate /* 3377c478bd9Sstevel@tonic-gate * Expand the requested name if necessary. 3387c478bd9Sstevel@tonic-gate */ 3397c478bd9Sstevel@tonic-gate if ((pnp = elf_fix_name(name, clmp, PN_SER_NEEDED)) == 0) 3407c478bd9Sstevel@tonic-gate return (0); 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate /* 3437c478bd9Sstevel@tonic-gate * Provided the object on the head of the link-map has completed its 3447c478bd9Sstevel@tonic-gate * relocation, create a new link-map control list for this request. 3457c478bd9Sstevel@tonic-gate */ 3467c478bd9Sstevel@tonic-gate hlmp = lml->lm_head; 3477c478bd9Sstevel@tonic-gate if (FLAGS(hlmp) & FLG_RT_RELOCED) { 348cce0e03bSab if ((lmc = alist_append(&lml->lm_lists, 0, sizeof (Lm_cntl), 3497c478bd9Sstevel@tonic-gate AL_CNT_LMLISTS)) == 0) { 3507c478bd9Sstevel@tonic-gate remove_pnode(pnp); 3517c478bd9Sstevel@tonic-gate return (0); 3527c478bd9Sstevel@tonic-gate } 3537c478bd9Sstevel@tonic-gate lmco = (Aliste)((char *)lmc - (char *)lml->lm_lists); 3547c478bd9Sstevel@tonic-gate } else { 3557c478bd9Sstevel@tonic-gate lmc = 0; 356cce0e03bSab lmco = ALIST_OFF_DATA; 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate /* 3607c478bd9Sstevel@tonic-gate * Load the associated object. 3617c478bd9Sstevel@tonic-gate */ 3627c478bd9Sstevel@tonic-gate dip->di_info = nlmp = 3637c478bd9Sstevel@tonic-gate load_one(lml, lmco, pnp, clmp, MODE(clmp), flags, 0); 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate /* 3667c478bd9Sstevel@tonic-gate * Remove any expanded pathname infrastructure. Reduce the pending lazy 3677c478bd9Sstevel@tonic-gate * dependency count of the caller, together with the link-map lists 3687c478bd9Sstevel@tonic-gate * count of objects that still have lazy dependencies pending. 3697c478bd9Sstevel@tonic-gate */ 3707c478bd9Sstevel@tonic-gate remove_pnode(pnp); 3717c478bd9Sstevel@tonic-gate if (--LAZY(clmp) == 0) 3727c478bd9Sstevel@tonic-gate LIST(clmp)->lm_lazy--; 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate /* 37502ca3e02Srie * Finish processing the objects associated with this request, and 37602ca3e02Srie * create an association between the caller and this dependency. 3777c478bd9Sstevel@tonic-gate */ 378*75e7992aSrie if (nlmp && ((bind_one(clmp, nlmp, BND_NEEDED) == 0) || 379*75e7992aSrie (analyze_lmc(lml, lmco, nlmp) == 0) || 380f6acbf7cSrie (relocate_lmc(lml, lmco, clmp, nlmp) == 0))) 3817c478bd9Sstevel@tonic-gate dip->di_info = nlmp = 0; 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate /* 38402ca3e02Srie * If this lazyload has failed, and we've created a new link-map 38502ca3e02Srie * control list to which this request has added objects, then remove 38602ca3e02Srie * all the objects that have been associated to this request. 3877c478bd9Sstevel@tonic-gate */ 38802ca3e02Srie if ((nlmp == 0) && lmc && lmc->lc_head) 38902ca3e02Srie remove_lmc(lml, clmp, lmc, lmco, name); 3907c478bd9Sstevel@tonic-gate 3917c478bd9Sstevel@tonic-gate /* 39202ca3e02Srie * Finally, remove any link-map control list that was created. 3937c478bd9Sstevel@tonic-gate */ 39402ca3e02Srie if (lmc) 3957c478bd9Sstevel@tonic-gate remove_cntl(lml, lmco); 3967c478bd9Sstevel@tonic-gate 397*75e7992aSrie /* 398*75e7992aSrie * If this lazy loading failed, record the fact, and bump the lazy 399*75e7992aSrie * counts. 400*75e7992aSrie */ 401*75e7992aSrie if (nlmp == 0) { 402*75e7992aSrie dip->di_flags |= FLG_DI_LAZYFAIL; 403*75e7992aSrie if (LAZY(clmp)++ == 0) 404*75e7992aSrie LIST(clmp)->lm_lazy++; 405*75e7992aSrie } 406*75e7992aSrie 4077c478bd9Sstevel@tonic-gate return (nlmp); 4087c478bd9Sstevel@tonic-gate } 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate /* 4117c478bd9Sstevel@tonic-gate * Return the entry point of the ELF executable. 4127c478bd9Sstevel@tonic-gate */ 4137c478bd9Sstevel@tonic-gate static ulong_t 4147c478bd9Sstevel@tonic-gate elf_entry_pt(void) 4157c478bd9Sstevel@tonic-gate { 4167c478bd9Sstevel@tonic-gate return (ENTRY(lml_main.lm_head)); 4177c478bd9Sstevel@tonic-gate } 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate /* 4207c478bd9Sstevel@tonic-gate * Unmap a given ELF shared object from the address space. 4217c478bd9Sstevel@tonic-gate */ 4227c478bd9Sstevel@tonic-gate static void 4237c478bd9Sstevel@tonic-gate elf_unmap_so(Rt_map *lmp) 4247c478bd9Sstevel@tonic-gate { 4257c478bd9Sstevel@tonic-gate caddr_t addr; 4267c478bd9Sstevel@tonic-gate size_t size; 4277c478bd9Sstevel@tonic-gate Mmap *mmaps; 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate /* 4307c478bd9Sstevel@tonic-gate * If this link map represents a relocatable object concatenation, then 4317c478bd9Sstevel@tonic-gate * the image was simply generated in allocated memory. Free the memory. 4327c478bd9Sstevel@tonic-gate * 4337c478bd9Sstevel@tonic-gate * Note: the memory was originally allocated in the libelf:_elf_outmap 4347c478bd9Sstevel@tonic-gate * routine and would normally have been free'd in elf_outsync(), but 4357c478bd9Sstevel@tonic-gate * because we 'interpose' on that routine the memory wasn't free'd at 4367c478bd9Sstevel@tonic-gate * that time. 4377c478bd9Sstevel@tonic-gate */ 4387c478bd9Sstevel@tonic-gate if (FLAGS(lmp) & FLG_RT_IMGALLOC) { 4397c478bd9Sstevel@tonic-gate free((void *)ADDR(lmp)); 4407c478bd9Sstevel@tonic-gate return; 4417c478bd9Sstevel@tonic-gate } 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate /* 4447c478bd9Sstevel@tonic-gate * If padding was enabled via rtld_db, then we have at least one page 4457c478bd9Sstevel@tonic-gate * in front of the image - and possibly a trailing page. 4467c478bd9Sstevel@tonic-gate * Unmap the front page first: 4477c478bd9Sstevel@tonic-gate */ 4487c478bd9Sstevel@tonic-gate if (PADSTART(lmp) != ADDR(lmp)) { 4497c478bd9Sstevel@tonic-gate addr = (caddr_t)M_PTRUNC(PADSTART(lmp)); 4507c478bd9Sstevel@tonic-gate size = ADDR(lmp) - (ulong_t)addr; 4517c478bd9Sstevel@tonic-gate (void) munmap(addr, size); 4527c478bd9Sstevel@tonic-gate } 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate /* 4557c478bd9Sstevel@tonic-gate * Unmap any trailing padding. 4567c478bd9Sstevel@tonic-gate */ 4577c478bd9Sstevel@tonic-gate if (M_PROUND((PADSTART(lmp) + PADIMLEN(lmp))) > 4587c478bd9Sstevel@tonic-gate M_PROUND(ADDR(lmp) + MSIZE(lmp))) { 4597c478bd9Sstevel@tonic-gate addr = (caddr_t)M_PROUND(ADDR(lmp) + MSIZE(lmp)); 4607c478bd9Sstevel@tonic-gate size = M_PROUND(PADSTART(lmp) + PADIMLEN(lmp)) - (ulong_t)addr; 4617c478bd9Sstevel@tonic-gate (void) munmap(addr, size); 4627c478bd9Sstevel@tonic-gate } 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate /* 4657c478bd9Sstevel@tonic-gate * Unmmap all mapped segments. 4667c478bd9Sstevel@tonic-gate */ 4677c478bd9Sstevel@tonic-gate for (mmaps = MMAPS(lmp); mmaps->m_vaddr; mmaps++) 4687c478bd9Sstevel@tonic-gate (void) munmap(mmaps->m_vaddr, mmaps->m_msize); 4697c478bd9Sstevel@tonic-gate } 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate /* 4727c478bd9Sstevel@tonic-gate * Determine if a dependency requires a particular version and if so verify 4737c478bd9Sstevel@tonic-gate * that the version exists in the dependency. 4747c478bd9Sstevel@tonic-gate */ 4757c478bd9Sstevel@tonic-gate static int 4767c478bd9Sstevel@tonic-gate elf_verify_vers(const char *name, Rt_map *clmp, Rt_map *nlmp) 4777c478bd9Sstevel@tonic-gate { 4787c478bd9Sstevel@tonic-gate Verneed *vnd = VERNEED(clmp); 4797c478bd9Sstevel@tonic-gate int _num, num = VERNEEDNUM(clmp); 4807c478bd9Sstevel@tonic-gate char *cstrs = (char *)STRTAB(clmp); 4817c478bd9Sstevel@tonic-gate Lm_list *lml = LIST(clmp); 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate /* 4847c478bd9Sstevel@tonic-gate * Traverse the callers version needed information and determine if any 4857c478bd9Sstevel@tonic-gate * specific versions are required from the dependency. 4867c478bd9Sstevel@tonic-gate */ 4875aefb655Srie DBG_CALL(Dbg_ver_need_title(LIST(clmp), NAME(clmp))); 4887c478bd9Sstevel@tonic-gate for (_num = 1; _num <= num; _num++, 4897c478bd9Sstevel@tonic-gate vnd = (Verneed *)((Xword)vnd + vnd->vn_next)) { 4907c478bd9Sstevel@tonic-gate Half cnt = vnd->vn_cnt; 4917c478bd9Sstevel@tonic-gate Vernaux *vnap; 4927c478bd9Sstevel@tonic-gate char *nstrs, *need; 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /* 4957c478bd9Sstevel@tonic-gate * Determine if a needed entry matches this dependency. 4967c478bd9Sstevel@tonic-gate */ 4977c478bd9Sstevel@tonic-gate need = (char *)(cstrs + vnd->vn_file); 4987c478bd9Sstevel@tonic-gate if (strcmp(name, need) != 0) 4997c478bd9Sstevel@tonic-gate continue; 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate if ((lml->lm_flags & LML_FLG_TRC_VERBOSE) && 5027c478bd9Sstevel@tonic-gate ((FLAGS1(clmp) & FL1_RT_LDDSTUB) == 0)) 5037c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_LDD_VER_FIND), name); 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate /* 5067c478bd9Sstevel@tonic-gate * Validate that each version required actually exists in the 5077c478bd9Sstevel@tonic-gate * dependency. 5087c478bd9Sstevel@tonic-gate */ 5097c478bd9Sstevel@tonic-gate nstrs = (char *)STRTAB(nlmp); 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate for (vnap = (Vernaux *)((Xword)vnd + vnd->vn_aux); cnt; 5127c478bd9Sstevel@tonic-gate cnt--, vnap = (Vernaux *)((Xword)vnap + vnap->vna_next)) { 5137c478bd9Sstevel@tonic-gate char *version, *define; 5147c478bd9Sstevel@tonic-gate Verdef *vdf = VERDEF(nlmp); 5157c478bd9Sstevel@tonic-gate ulong_t _num, num = VERDEFNUM(nlmp); 5167c478bd9Sstevel@tonic-gate int found = 0; 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate version = (char *)(cstrs + vnap->vna_name); 5195aefb655Srie DBG_CALL(Dbg_ver_need_entry(lml, 0, need, version)); 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate for (_num = 1; _num <= num; _num++, 5227c478bd9Sstevel@tonic-gate vdf = (Verdef *)((Xword)vdf + vdf->vd_next)) { 5237c478bd9Sstevel@tonic-gate Verdaux *vdap; 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate if (vnap->vna_hash != vdf->vd_hash) 5267c478bd9Sstevel@tonic-gate continue; 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate vdap = (Verdaux *)((Xword)vdf + vdf->vd_aux); 5297c478bd9Sstevel@tonic-gate define = (char *)(nstrs + vdap->vda_name); 5307c478bd9Sstevel@tonic-gate if (strcmp(version, define) != 0) 5317c478bd9Sstevel@tonic-gate continue; 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate found++; 5347c478bd9Sstevel@tonic-gate break; 5357c478bd9Sstevel@tonic-gate } 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate /* 5387c478bd9Sstevel@tonic-gate * If we're being traced print out any matched version 5397c478bd9Sstevel@tonic-gate * when the verbose (-v) option is in effect. Always 5407c478bd9Sstevel@tonic-gate * print any unmatched versions. 5417c478bd9Sstevel@tonic-gate */ 5427c478bd9Sstevel@tonic-gate if (lml->lm_flags & LML_FLG_TRC_ENABLE) { 543a953e2b1Srie /* BEGIN CSTYLED */ 5447c478bd9Sstevel@tonic-gate if (found) { 5457c478bd9Sstevel@tonic-gate if (!(lml->lm_flags & LML_FLG_TRC_VERBOSE)) 5467c478bd9Sstevel@tonic-gate continue; 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate (void) printf(MSG_ORIG(MSG_LDD_VER_FOUND), 5497c478bd9Sstevel@tonic-gate need, version, NAME(nlmp)); 5507c478bd9Sstevel@tonic-gate } else { 5517c478bd9Sstevel@tonic-gate if (rtld_flags & RT_FL_SILENCERR) 5527c478bd9Sstevel@tonic-gate continue; 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_LDD_VER_NFOUND), 5557c478bd9Sstevel@tonic-gate need, version); 5567c478bd9Sstevel@tonic-gate } 557a953e2b1Srie /* END CSTYLED */ 5587c478bd9Sstevel@tonic-gate continue; 5597c478bd9Sstevel@tonic-gate } 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate /* 5627c478bd9Sstevel@tonic-gate * If the version hasn't been found then this is a 5637c478bd9Sstevel@tonic-gate * candidate for a fatal error condition. Weak 5647c478bd9Sstevel@tonic-gate * version definition requirements are silently 5657c478bd9Sstevel@tonic-gate * ignored. Also, if the image inspected for a version 5667c478bd9Sstevel@tonic-gate * definition has no versioning recorded at all then 5677c478bd9Sstevel@tonic-gate * silently ignore this (this provides better backward 5687c478bd9Sstevel@tonic-gate * compatibility to old images created prior to 5697c478bd9Sstevel@tonic-gate * versioning being available). Both of these skipped 5707c478bd9Sstevel@tonic-gate * diagnostics are available under tracing (see above). 5717c478bd9Sstevel@tonic-gate */ 5727c478bd9Sstevel@tonic-gate if ((found == 0) && (num != 0) && 5737c478bd9Sstevel@tonic-gate (!(vnap->vna_flags & VER_FLG_WEAK))) { 5745aefb655Srie eprintf(lml, ERR_FATAL, 5755aefb655Srie MSG_INTL(MSG_VER_NFOUND), need, version, 5765aefb655Srie NAME(clmp)); 5777c478bd9Sstevel@tonic-gate return (0); 5787c478bd9Sstevel@tonic-gate } 5797c478bd9Sstevel@tonic-gate } 5807c478bd9Sstevel@tonic-gate } 5815aefb655Srie DBG_CALL(Dbg_util_nl(lml, DBG_NL_STD)); 5827c478bd9Sstevel@tonic-gate return (1); 5837c478bd9Sstevel@tonic-gate } 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate /* 5867c478bd9Sstevel@tonic-gate * Search through the dynamic section for DT_NEEDED entries and perform one 5877c478bd9Sstevel@tonic-gate * of two functions. If only the first argument is specified then load the 5887c478bd9Sstevel@tonic-gate * defined shared object, otherwise add the link map representing the defined 5897c478bd9Sstevel@tonic-gate * link map the the dlopen list. 5907c478bd9Sstevel@tonic-gate */ 5917c478bd9Sstevel@tonic-gate static int 5927c478bd9Sstevel@tonic-gate elf_needed(Lm_list *lml, Aliste lmco, Rt_map *clmp) 5937c478bd9Sstevel@tonic-gate { 594*75e7992aSrie Dyn *dyn, *pdyn; 5957c478bd9Sstevel@tonic-gate ulong_t ndx = 0; 596*75e7992aSrie uint_t lazy, flags; 5977c478bd9Sstevel@tonic-gate Word lmflags = lml->lm_flags; 5987c478bd9Sstevel@tonic-gate Word lmtflags = lml->lm_tflags; 5997c478bd9Sstevel@tonic-gate 6007c478bd9Sstevel@tonic-gate /* 6017c478bd9Sstevel@tonic-gate * Process each shared object on needed list. 6027c478bd9Sstevel@tonic-gate */ 6037c478bd9Sstevel@tonic-gate if (DYN(clmp) == 0) 6047c478bd9Sstevel@tonic-gate return (1); 6057c478bd9Sstevel@tonic-gate 606*75e7992aSrie for (dyn = (Dyn *)DYN(clmp), pdyn = NULL; dyn->d_tag != DT_NULL; 607*75e7992aSrie pdyn = dyn++, ndx++) { 6087c478bd9Sstevel@tonic-gate Dyninfo *dip = &DYNINFO(clmp)[ndx]; 6097c478bd9Sstevel@tonic-gate Rt_map *nlmp = 0; 6107c478bd9Sstevel@tonic-gate char *name; 6117c478bd9Sstevel@tonic-gate int silent = 0; 6127c478bd9Sstevel@tonic-gate Pnode *pnp; 6137c478bd9Sstevel@tonic-gate 6147c478bd9Sstevel@tonic-gate switch (dyn->d_tag) { 6157c478bd9Sstevel@tonic-gate case DT_POSFLAG_1: 616*75e7992aSrie dip->di_flags |= FLG_DI_POSFLAG1; 6177c478bd9Sstevel@tonic-gate continue; 6187c478bd9Sstevel@tonic-gate case DT_NEEDED: 6197c478bd9Sstevel@tonic-gate case DT_USED: 620*75e7992aSrie lazy = flags = 0; 6217c478bd9Sstevel@tonic-gate dip->di_flags |= FLG_DI_NEEDED; 622*75e7992aSrie 623*75e7992aSrie if (pdyn && (pdyn->d_tag == DT_POSFLAG_1)) { 624*75e7992aSrie if ((pdyn->d_un.d_val & DF_P1_LAZYLOAD) && 625*75e7992aSrie ((lmtflags & LML_TFLG_NOLAZYLD) == 0)) { 626*75e7992aSrie dip->di_flags |= FLG_DI_LAZY; 627*75e7992aSrie lazy = 1; 628*75e7992aSrie } 629*75e7992aSrie if (pdyn->d_un.d_val & DF_P1_GROUPPERM) { 630*75e7992aSrie dip->di_flags |= FLG_DI_GROUP; 631*75e7992aSrie flags = 632*75e7992aSrie (FLG_RT_SETGROUP | FLG_RT_HANDLE); 633*75e7992aSrie } 634*75e7992aSrie } 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate name = (char *)STRTAB(clmp) + dyn->d_un.d_val; 6377c478bd9Sstevel@tonic-gate 6387c478bd9Sstevel@tonic-gate /* 6397c478bd9Sstevel@tonic-gate * NOTE, libc.so.1 can't be lazy loaded. Although a 6407c478bd9Sstevel@tonic-gate * lazy position flag won't be produced when a RTLDINFO 6417c478bd9Sstevel@tonic-gate * .dynamic entry is found (introduced with the UPM in 6427c478bd9Sstevel@tonic-gate * Solaris 10), it was possible to mark libc for lazy 6437c478bd9Sstevel@tonic-gate * loading on previous releases. To reduce the overhead 6447c478bd9Sstevel@tonic-gate * of testing for this occurrence, only carry out this 6457c478bd9Sstevel@tonic-gate * check for the first object on the link-map list 6467c478bd9Sstevel@tonic-gate * (there aren't many applications built without libc). 6477c478bd9Sstevel@tonic-gate */ 6487c478bd9Sstevel@tonic-gate if (lazy && (lml->lm_head == clmp) && 6497c478bd9Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_FIL_LIBC)) == 0)) 6507c478bd9Sstevel@tonic-gate lazy = 0; 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate /* 6537c478bd9Sstevel@tonic-gate * Don't bring in lazy loaded objects yet unless we've 6547c478bd9Sstevel@tonic-gate * been asked to attempt to load all available objects 6557c478bd9Sstevel@tonic-gate * (crle(1) sets LD_FLAGS=loadavail). Even under 6567c478bd9Sstevel@tonic-gate * RTLD_NOW we don't process this - RTLD_NOW will cause 6577c478bd9Sstevel@tonic-gate * relocation processing which in turn might trigger 6587c478bd9Sstevel@tonic-gate * lazy loading, but its possible that the object has a 6597c478bd9Sstevel@tonic-gate * lazy loaded file with no bindings (i.e., it should 6607c478bd9Sstevel@tonic-gate * never have been a dependency in the first place). 6617c478bd9Sstevel@tonic-gate */ 6627c478bd9Sstevel@tonic-gate if (lazy) { 6637c478bd9Sstevel@tonic-gate if ((lmflags & LML_FLG_LOADAVAIL) == 0) { 6647c478bd9Sstevel@tonic-gate LAZY(clmp)++; 6657c478bd9Sstevel@tonic-gate lazy = flags = 0; 6667c478bd9Sstevel@tonic-gate continue; 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate /* 6707c478bd9Sstevel@tonic-gate * Silence any error messages - see description 6717c478bd9Sstevel@tonic-gate * under elf_lookup_filtee(). 6727c478bd9Sstevel@tonic-gate */ 6737c478bd9Sstevel@tonic-gate if ((rtld_flags & RT_FL_SILENCERR) == 0) { 6747c478bd9Sstevel@tonic-gate rtld_flags |= RT_FL_SILENCERR; 6757c478bd9Sstevel@tonic-gate silent = 1; 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate } 6787c478bd9Sstevel@tonic-gate break; 6797c478bd9Sstevel@tonic-gate case DT_AUXILIARY: 6807c478bd9Sstevel@tonic-gate dip->di_flags |= FLG_DI_AUXFLTR; 6817c478bd9Sstevel@tonic-gate continue; 6827c478bd9Sstevel@tonic-gate case DT_SUNW_AUXILIARY: 6837c478bd9Sstevel@tonic-gate dip->di_flags |= (FLG_DI_AUXFLTR | FLG_DI_SYMFLTR); 6847c478bd9Sstevel@tonic-gate continue; 6857c478bd9Sstevel@tonic-gate case DT_FILTER: 6867c478bd9Sstevel@tonic-gate dip->di_flags |= FLG_DI_STDFLTR; 6877c478bd9Sstevel@tonic-gate continue; 6887c478bd9Sstevel@tonic-gate case DT_SUNW_FILTER: 6897c478bd9Sstevel@tonic-gate dip->di_flags |= (FLG_DI_STDFLTR | FLG_DI_SYMFLTR); 6907c478bd9Sstevel@tonic-gate continue; 6917c478bd9Sstevel@tonic-gate default: 6927c478bd9Sstevel@tonic-gate continue; 6937c478bd9Sstevel@tonic-gate } 6947c478bd9Sstevel@tonic-gate 6955aefb655Srie DBG_CALL(Dbg_file_needed(clmp, name)); 696*75e7992aSrie 697*75e7992aSrie /* 698*75e7992aSrie * If we're running under ldd(1), indicate that this dependency 699*75e7992aSrie * has been processed. It doesn't matter whether the object is 700*75e7992aSrie * successfully loaded or not, this flag simply ensures that we 701*75e7992aSrie * don't repeatedly attempt to load an object that has already 702*75e7992aSrie * failed to load. To do so would create multiple failure 703*75e7992aSrie * diagnostics for the same object under ldd(1). 704*75e7992aSrie */ 7057c478bd9Sstevel@tonic-gate if (lml->lm_flags & LML_FLG_TRC_ENABLE) 706*75e7992aSrie dip->di_flags |= FLG_DI_LDD_DONE; 7077c478bd9Sstevel@tonic-gate 7087c478bd9Sstevel@tonic-gate /* 7097c478bd9Sstevel@tonic-gate * Establish the objects name, load it and establish a binding 7107c478bd9Sstevel@tonic-gate * with the caller. 7117c478bd9Sstevel@tonic-gate */ 7127c478bd9Sstevel@tonic-gate if (((pnp = elf_fix_name(name, clmp, PN_SER_NEEDED)) == 0) || 7137c478bd9Sstevel@tonic-gate ((nlmp = load_one(lml, lmco, pnp, clmp, MODE(clmp), 7147c478bd9Sstevel@tonic-gate flags, 0)) == 0) || (bind_one(clmp, nlmp, BND_NEEDED) == 0)) 7157c478bd9Sstevel@tonic-gate nlmp = 0; 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate /* 7187c478bd9Sstevel@tonic-gate * Clean up any infrastructure, including the removal of the 7197c478bd9Sstevel@tonic-gate * error suppression state, if it had been previously set in 7207c478bd9Sstevel@tonic-gate * this routine. 7217c478bd9Sstevel@tonic-gate */ 7227c478bd9Sstevel@tonic-gate if (pnp) 7237c478bd9Sstevel@tonic-gate remove_pnode(pnp); 7247c478bd9Sstevel@tonic-gate if (silent) 7257c478bd9Sstevel@tonic-gate rtld_flags &= ~RT_FL_SILENCERR; 726*75e7992aSrie 7277c478bd9Sstevel@tonic-gate if ((dip->di_info = (void *)nlmp) == 0) { 7287c478bd9Sstevel@tonic-gate /* 7297c478bd9Sstevel@tonic-gate * If the object could not be mapped, continue if error 7307c478bd9Sstevel@tonic-gate * suppression is established or we're here with ldd(1). 7317c478bd9Sstevel@tonic-gate */ 7327c478bd9Sstevel@tonic-gate if ((MODE(clmp) & RTLD_CONFGEN) || (lmflags & 7337c478bd9Sstevel@tonic-gate (LML_FLG_LOADAVAIL | LML_FLG_TRC_ENABLE))) 7347c478bd9Sstevel@tonic-gate continue; 7357c478bd9Sstevel@tonic-gate else 7367c478bd9Sstevel@tonic-gate return (0); 7377c478bd9Sstevel@tonic-gate } 7387c478bd9Sstevel@tonic-gate } 7397c478bd9Sstevel@tonic-gate 7407c478bd9Sstevel@tonic-gate if (LAZY(clmp)) 7417c478bd9Sstevel@tonic-gate lml->lm_lazy++; 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate return (1); 7447c478bd9Sstevel@tonic-gate } 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate static int 7475aefb655Srie elf_map_check(Lm_list *lml, const char *name, caddr_t vaddr, Off size) 7487c478bd9Sstevel@tonic-gate { 7497c478bd9Sstevel@tonic-gate prmap_t *maps, *_maps; 7507c478bd9Sstevel@tonic-gate int pfd, num, _num; 7517c478bd9Sstevel@tonic-gate caddr_t eaddr = vaddr + size; 7527c478bd9Sstevel@tonic-gate int err; 7537c478bd9Sstevel@tonic-gate 7547c478bd9Sstevel@tonic-gate /* 7557c478bd9Sstevel@tonic-gate * If memory reservations have been established for alternative objects 7567c478bd9Sstevel@tonic-gate * determine if this object falls within the reservation, if it does no 7577c478bd9Sstevel@tonic-gate * further checking is required. 7587c478bd9Sstevel@tonic-gate */ 7597c478bd9Sstevel@tonic-gate if (rtld_flags & RT_FL_MEMRESV) { 7607c478bd9Sstevel@tonic-gate Rtc_head *head = (Rtc_head *)config->c_bgn; 7617c478bd9Sstevel@tonic-gate 7627c478bd9Sstevel@tonic-gate if ((vaddr >= (caddr_t)(uintptr_t)head->ch_resbgn) && 7637c478bd9Sstevel@tonic-gate (eaddr <= (caddr_t)(uintptr_t)head->ch_resend)) 7647c478bd9Sstevel@tonic-gate return (0); 7657c478bd9Sstevel@tonic-gate } 7667c478bd9Sstevel@tonic-gate 7677c478bd9Sstevel@tonic-gate /* 7687c478bd9Sstevel@tonic-gate * Determine the mappings presently in use by this process. 7697c478bd9Sstevel@tonic-gate */ 7705aefb655Srie if ((pfd = pr_open(lml)) == FD_UNAVAIL) 7717c478bd9Sstevel@tonic-gate return (1); 7727c478bd9Sstevel@tonic-gate 7737c478bd9Sstevel@tonic-gate if (ioctl(pfd, PIOCNMAP, (void *)&num) == -1) { 7747c478bd9Sstevel@tonic-gate err = errno; 7755aefb655Srie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_SYS_PROC), name, 7765aefb655Srie strerror(err)); 7777c478bd9Sstevel@tonic-gate return (1); 7787c478bd9Sstevel@tonic-gate } 7797c478bd9Sstevel@tonic-gate 7807c478bd9Sstevel@tonic-gate if ((maps = malloc((num + 1) * sizeof (prmap_t))) == 0) 7817c478bd9Sstevel@tonic-gate return (1); 7827c478bd9Sstevel@tonic-gate 7837c478bd9Sstevel@tonic-gate if (ioctl(pfd, PIOCMAP, (void *)maps) == -1) { 7847c478bd9Sstevel@tonic-gate err = errno; 7855aefb655Srie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_SYS_PROC), name, 7865aefb655Srie strerror(err)); 7877c478bd9Sstevel@tonic-gate free(maps); 7887c478bd9Sstevel@tonic-gate return (1); 7897c478bd9Sstevel@tonic-gate } 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate /* 7927c478bd9Sstevel@tonic-gate * Determine if the supplied address clashes with any of the present 7937c478bd9Sstevel@tonic-gate * process mappings. 7947c478bd9Sstevel@tonic-gate */ 7957c478bd9Sstevel@tonic-gate for (_num = 0, _maps = maps; _num < num; _num++, _maps++) { 7967c478bd9Sstevel@tonic-gate caddr_t _eaddr = _maps->pr_vaddr + _maps->pr_size; 7977c478bd9Sstevel@tonic-gate Rt_map *lmp; 7987c478bd9Sstevel@tonic-gate const char *str; 7997c478bd9Sstevel@tonic-gate 8007c478bd9Sstevel@tonic-gate if ((eaddr < _maps->pr_vaddr) || (vaddr >= _eaddr)) 8017c478bd9Sstevel@tonic-gate continue; 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate /* 8047c478bd9Sstevel@tonic-gate * We have a memory clash. See if one of the known dynamic 8057c478bd9Sstevel@tonic-gate * dependency mappings represents this space so as to provide 8067c478bd9Sstevel@tonic-gate * the user a more meaningful message. 8077c478bd9Sstevel@tonic-gate */ 8087c478bd9Sstevel@tonic-gate if ((lmp = _caller(vaddr, 0)) != 0) 8097c478bd9Sstevel@tonic-gate str = NAME(lmp); 8107c478bd9Sstevel@tonic-gate else 8117c478bd9Sstevel@tonic-gate str = MSG_INTL(MSG_STR_UNKNOWN); 8127c478bd9Sstevel@tonic-gate 8135aefb655Srie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_GEN_MAPINUSE), name, 8145aefb655Srie EC_NATPTR(vaddr), EC_OFF(size), str); 8157c478bd9Sstevel@tonic-gate return (1); 8167c478bd9Sstevel@tonic-gate } 8177c478bd9Sstevel@tonic-gate free(maps); 8187c478bd9Sstevel@tonic-gate return (0); 8197c478bd9Sstevel@tonic-gate } 8207c478bd9Sstevel@tonic-gate 8217c478bd9Sstevel@tonic-gate /* 8227c478bd9Sstevel@tonic-gate * Obtain a memory reservation. On newer systems, both MAP_ANON and MAP_ALIGN 8237c478bd9Sstevel@tonic-gate * are used to obtained an aligned reservation from anonymous memory. If 8247c478bd9Sstevel@tonic-gate * MAP_ANON isn't available, then MAP_ALIGN isn't either, so obtain a standard 8257c478bd9Sstevel@tonic-gate * reservation using the file as backing. 8267c478bd9Sstevel@tonic-gate */ 8277c478bd9Sstevel@tonic-gate static Am_ret 8285aefb655Srie elf_map_reserve(Lm_list *lml, const char *name, caddr_t *maddr, Off msize, 8295aefb655Srie int mperm, int fd, Xword align) 8307c478bd9Sstevel@tonic-gate { 8317c478bd9Sstevel@tonic-gate Am_ret amret; 8327c478bd9Sstevel@tonic-gate int mflag = MAP_PRIVATE | MAP_NORESERVE; 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate #if defined(MAP_ALIGN) 8357c478bd9Sstevel@tonic-gate if ((rtld_flags2 & RT_FL2_NOMALIGN) == 0) { 8367c478bd9Sstevel@tonic-gate mflag |= MAP_ALIGN; 8377c478bd9Sstevel@tonic-gate *maddr = (caddr_t)align; 8387c478bd9Sstevel@tonic-gate } 8397c478bd9Sstevel@tonic-gate #endif 8405aefb655Srie if ((amret = anon_map(lml, maddr, msize, PROT_NONE, mflag)) == AM_ERROR) 8417c478bd9Sstevel@tonic-gate return (amret); 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate if (amret == AM_OK) 8447c478bd9Sstevel@tonic-gate return (AM_OK); 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate /* 8477c478bd9Sstevel@tonic-gate * If an anonymous memory request failed (which should only be the 8487c478bd9Sstevel@tonic-gate * case if it is unsupported on the system we're running on), establish 8497c478bd9Sstevel@tonic-gate * the initial mapping directly from the file. 8507c478bd9Sstevel@tonic-gate */ 8517c478bd9Sstevel@tonic-gate *maddr = 0; 8527c478bd9Sstevel@tonic-gate if ((*maddr = mmap(*maddr, msize, mperm, MAP_PRIVATE, 8537c478bd9Sstevel@tonic-gate fd, 0)) == MAP_FAILED) { 8547c478bd9Sstevel@tonic-gate int err = errno; 8555aefb655Srie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_SYS_MMAP), name, 8565aefb655Srie strerror(err)); 8577c478bd9Sstevel@tonic-gate return (AM_ERROR); 8587c478bd9Sstevel@tonic-gate } 8597c478bd9Sstevel@tonic-gate return (AM_NOSUP); 8607c478bd9Sstevel@tonic-gate } 8617c478bd9Sstevel@tonic-gate 8627c478bd9Sstevel@tonic-gate static void * 8637c478bd9Sstevel@tonic-gate elf_map_textdata(caddr_t addr, Off flen, int mperm, int phdr_mperm, int mflag, 8647c478bd9Sstevel@tonic-gate int fd, Off foff) 8657c478bd9Sstevel@tonic-gate { 8667c478bd9Sstevel@tonic-gate #if defined(MAP_TEXT) && defined(MAP_INITDATA) 8677c478bd9Sstevel@tonic-gate static int notd = 0; 8687c478bd9Sstevel@tonic-gate 8697c478bd9Sstevel@tonic-gate /* 8707c478bd9Sstevel@tonic-gate * If MAP_TEXT and MAP_INITDATA are available, select the appropriate 8717c478bd9Sstevel@tonic-gate * flag. 8727c478bd9Sstevel@tonic-gate */ 8737c478bd9Sstevel@tonic-gate if (notd == 0) { 8747c478bd9Sstevel@tonic-gate if ((phdr_mperm & (PROT_WRITE | PROT_EXEC)) == PROT_EXEC) 8757c478bd9Sstevel@tonic-gate mflag |= MAP_TEXT; 8767c478bd9Sstevel@tonic-gate else 8777c478bd9Sstevel@tonic-gate mflag |= MAP_INITDATA; 8787c478bd9Sstevel@tonic-gate } 8797c478bd9Sstevel@tonic-gate #endif 8807c478bd9Sstevel@tonic-gate if (mmap((caddr_t)addr, flen, mperm, mflag, fd, foff) != MAP_FAILED) 8817c478bd9Sstevel@tonic-gate return (0); 8827c478bd9Sstevel@tonic-gate 8837c478bd9Sstevel@tonic-gate #if defined(MAP_TEXT) && defined(MAP_INITDATA) 8847c478bd9Sstevel@tonic-gate if ((notd == 0) && (errno == EINVAL)) { 8857c478bd9Sstevel@tonic-gate /* 8867c478bd9Sstevel@tonic-gate * MAP_TEXT and MAP_INITDATA may not be supported on this 8877c478bd9Sstevel@tonic-gate * platform, try again without. 8887c478bd9Sstevel@tonic-gate */ 8897c478bd9Sstevel@tonic-gate notd = 1; 8907c478bd9Sstevel@tonic-gate mflag &= ~(MAP_TEXT | MAP_INITDATA); 8917c478bd9Sstevel@tonic-gate 8927c478bd9Sstevel@tonic-gate return (mmap((caddr_t)addr, flen, mperm, mflag, fd, foff)); 8937c478bd9Sstevel@tonic-gate } 8947c478bd9Sstevel@tonic-gate #endif 8957c478bd9Sstevel@tonic-gate return (MAP_FAILED); 8967c478bd9Sstevel@tonic-gate } 8977c478bd9Sstevel@tonic-gate 8987c478bd9Sstevel@tonic-gate /* 8997c478bd9Sstevel@tonic-gate * Map in a file. 9007c478bd9Sstevel@tonic-gate */ 9017c478bd9Sstevel@tonic-gate static caddr_t 9027c478bd9Sstevel@tonic-gate elf_map_it( 9035aefb655Srie Lm_list *lml, /* link-map list */ 9047c478bd9Sstevel@tonic-gate const char *name, /* actual name stored for pathname */ 9057c478bd9Sstevel@tonic-gate Off fsize, /* total mapping claim of the file */ 9067c478bd9Sstevel@tonic-gate Ehdr *ehdr, /* ELF header of file */ 9077c478bd9Sstevel@tonic-gate Phdr *fphdr, /* first loadable Phdr */ 9087c478bd9Sstevel@tonic-gate Phdr *lphdr, /* last loadable Phdr */ 9097c478bd9Sstevel@tonic-gate Phdr **rrphdr, /* return first Phdr in reservation */ 9107c478bd9Sstevel@tonic-gate caddr_t *rraddr, /* return start of reservation */ 9117c478bd9Sstevel@tonic-gate Off *rrsize, /* return total size of reservation */ 9127c478bd9Sstevel@tonic-gate int fixed, /* image is resolved to a fixed addr */ 9137c478bd9Sstevel@tonic-gate int fd, /* images file descriptor */ 9147c478bd9Sstevel@tonic-gate Xword align, /* image segments maximum alignment */ 9157c478bd9Sstevel@tonic-gate Mmap *mmaps, /* mmap information array and */ 9167c478bd9Sstevel@tonic-gate uint_t *mmapcnt) /* mapping count */ 9177c478bd9Sstevel@tonic-gate { 9187c478bd9Sstevel@tonic-gate caddr_t raddr; /* reservation address */ 9197c478bd9Sstevel@tonic-gate Off rsize; /* reservation size */ 9207c478bd9Sstevel@tonic-gate Phdr *phdr; /* working program header poiner */ 9217c478bd9Sstevel@tonic-gate caddr_t maddr; /* working mmap address */ 9227c478bd9Sstevel@tonic-gate caddr_t faddr; /* working file address */ 9237c478bd9Sstevel@tonic-gate size_t padsize; /* object padding requirement */ 9247c478bd9Sstevel@tonic-gate size_t padpsize = 0; /* padding size rounded to next page */ 9257c478bd9Sstevel@tonic-gate size_t padmsize = 0; /* padding size rounded for alignment */ 9267c478bd9Sstevel@tonic-gate int skipfseg; /* skip mapping first segment */ 9277c478bd9Sstevel@tonic-gate int mperm; /* segment permissions */ 9287c478bd9Sstevel@tonic-gate Am_ret amret = AM_NOSUP; 9297c478bd9Sstevel@tonic-gate 9307c478bd9Sstevel@tonic-gate /* 9317c478bd9Sstevel@tonic-gate * If padding is required extend both the front and rear of the image. 9327c478bd9Sstevel@tonic-gate * To insure the image itself is mapped at the correct alignment the 9337c478bd9Sstevel@tonic-gate * initial padding is rounded up to the nearest page. Once the image is 9347c478bd9Sstevel@tonic-gate * mapped the excess can be pruned to the nearest page required for the 9357c478bd9Sstevel@tonic-gate * actual padding itself. 9367c478bd9Sstevel@tonic-gate */ 9377c478bd9Sstevel@tonic-gate if ((padsize = r_debug.rtd_objpad) != 0) { 9387c478bd9Sstevel@tonic-gate padpsize = M_PROUND(padsize); 9397c478bd9Sstevel@tonic-gate if (fixed) 9407c478bd9Sstevel@tonic-gate padmsize = padpsize; 9417c478bd9Sstevel@tonic-gate else 9427c478bd9Sstevel@tonic-gate padmsize = S_ROUND(padsize, align); 9437c478bd9Sstevel@tonic-gate } 9447c478bd9Sstevel@tonic-gate 9457c478bd9Sstevel@tonic-gate /* 9467c478bd9Sstevel@tonic-gate * Determine the initial permissions used to map in the first segment. 9477c478bd9Sstevel@tonic-gate * If this segments memsz is greater that its filesz then the difference 9487c478bd9Sstevel@tonic-gate * must be zeroed. Make sure this segment is writable. 9497c478bd9Sstevel@tonic-gate */ 9507c478bd9Sstevel@tonic-gate mperm = 0; 9517c478bd9Sstevel@tonic-gate if (fphdr->p_flags & PF_R) 9527c478bd9Sstevel@tonic-gate mperm |= PROT_READ; 9537c478bd9Sstevel@tonic-gate if (fphdr->p_flags & PF_X) 9547c478bd9Sstevel@tonic-gate mperm |= PROT_EXEC; 9557c478bd9Sstevel@tonic-gate if ((fphdr->p_flags & PF_W) || (fphdr->p_memsz > fphdr->p_filesz)) 9567c478bd9Sstevel@tonic-gate mperm |= PROT_WRITE; 9577c478bd9Sstevel@tonic-gate 9587c478bd9Sstevel@tonic-gate /* 9597c478bd9Sstevel@tonic-gate * Determine whether or not to let system reserve address space based on 9607c478bd9Sstevel@tonic-gate * whether this is a dynamic executable (addresses in object are fixed) 9617c478bd9Sstevel@tonic-gate * or a shared object (addresses in object are relative to the objects' 9627c478bd9Sstevel@tonic-gate * base). 9637c478bd9Sstevel@tonic-gate */ 9647c478bd9Sstevel@tonic-gate if (fixed) { 9657c478bd9Sstevel@tonic-gate /* 9667c478bd9Sstevel@tonic-gate * Determine the reservation address and size, and insure that 9677c478bd9Sstevel@tonic-gate * this reservation isn't already in use. 9687c478bd9Sstevel@tonic-gate */ 9697c478bd9Sstevel@tonic-gate faddr = maddr = (caddr_t)M_PTRUNC((ulong_t)fphdr->p_vaddr); 9707c478bd9Sstevel@tonic-gate raddr = maddr - padpsize; 9717c478bd9Sstevel@tonic-gate rsize = fsize + padpsize + padsize; 9727c478bd9Sstevel@tonic-gate 9737c478bd9Sstevel@tonic-gate if (lml_main.lm_head) { 9745aefb655Srie if (elf_map_check(lml, name, raddr, rsize) != 0) 9757c478bd9Sstevel@tonic-gate return (0); 9767c478bd9Sstevel@tonic-gate } 9777c478bd9Sstevel@tonic-gate 9787c478bd9Sstevel@tonic-gate /* 9797c478bd9Sstevel@tonic-gate * As this is a fixed image, all segments must be individually 9807c478bd9Sstevel@tonic-gate * mapped. 9817c478bd9Sstevel@tonic-gate */ 9827c478bd9Sstevel@tonic-gate skipfseg = 0; 9837c478bd9Sstevel@tonic-gate 9847c478bd9Sstevel@tonic-gate } else { 9857c478bd9Sstevel@tonic-gate size_t esize; 9867c478bd9Sstevel@tonic-gate 9877c478bd9Sstevel@tonic-gate /* 9887c478bd9Sstevel@tonic-gate * If this isn't a fixed image, reserve enough address space for 9897c478bd9Sstevel@tonic-gate * the entire image to be mapped. The amount of reservation is 9907c478bd9Sstevel@tonic-gate * the range between the beginning of the first, and end of the 9917c478bd9Sstevel@tonic-gate * last loadable segment, together with any padding, plus the 9927c478bd9Sstevel@tonic-gate * alignment of the first segment. 9937c478bd9Sstevel@tonic-gate * 9947c478bd9Sstevel@tonic-gate * The optimal reservation is made as a no-reserve mapping from 9957c478bd9Sstevel@tonic-gate * anonymous memory. Each segment is then mapped into this 9967c478bd9Sstevel@tonic-gate * reservation. If the anonymous mapping capability isn't 9977c478bd9Sstevel@tonic-gate * available, the reservation is obtained from the file itself. 9987c478bd9Sstevel@tonic-gate * In this case the first segment of the image is mapped as part 9997c478bd9Sstevel@tonic-gate * of the reservation, thus only the following segments need to 10007c478bd9Sstevel@tonic-gate * be remapped. 10017c478bd9Sstevel@tonic-gate */ 10027c478bd9Sstevel@tonic-gate rsize = fsize + padmsize + padsize; 10035aefb655Srie if ((amret = elf_map_reserve(lml, name, &raddr, rsize, mperm, 10047c478bd9Sstevel@tonic-gate fd, align)) == AM_ERROR) 10057c478bd9Sstevel@tonic-gate return (0); 10067c478bd9Sstevel@tonic-gate maddr = raddr + padmsize; 10077c478bd9Sstevel@tonic-gate faddr = (caddr_t)S_ROUND((Off)maddr, align); 10087c478bd9Sstevel@tonic-gate 10097c478bd9Sstevel@tonic-gate /* 10107c478bd9Sstevel@tonic-gate * If this reservation has been obtained from anonymous memory, 10117c478bd9Sstevel@tonic-gate * then all segments must be individually mapped. Otherwise, 10127c478bd9Sstevel@tonic-gate * the first segment heads the reservation. 10137c478bd9Sstevel@tonic-gate */ 10147c478bd9Sstevel@tonic-gate if (amret == AM_OK) 10157c478bd9Sstevel@tonic-gate skipfseg = 0; 10167c478bd9Sstevel@tonic-gate else 10177c478bd9Sstevel@tonic-gate skipfseg = 1; 10187c478bd9Sstevel@tonic-gate 10197c478bd9Sstevel@tonic-gate /* 10207c478bd9Sstevel@tonic-gate * For backward compatibility (where MAP_ALIGN isn't available), 10217c478bd9Sstevel@tonic-gate * insure the alignment of the reservation is adequate for this 10227c478bd9Sstevel@tonic-gate * object, and if not remap the object to obtain the correct 10237c478bd9Sstevel@tonic-gate * alignment. 10247c478bd9Sstevel@tonic-gate */ 10257c478bd9Sstevel@tonic-gate if (faddr != maddr) { 10267c478bd9Sstevel@tonic-gate (void) munmap(raddr, rsize); 10277c478bd9Sstevel@tonic-gate 10287c478bd9Sstevel@tonic-gate rsize += align; 10295aefb655Srie if ((amret = elf_map_reserve(lml, name, &raddr, rsize, 10305aefb655Srie mperm, fd, align)) == AM_ERROR) 10317c478bd9Sstevel@tonic-gate return (0); 10327c478bd9Sstevel@tonic-gate 10337c478bd9Sstevel@tonic-gate maddr = faddr = (caddr_t)S_ROUND((Off)(raddr + 10347c478bd9Sstevel@tonic-gate padpsize), align); 10357c478bd9Sstevel@tonic-gate 10367c478bd9Sstevel@tonic-gate esize = maddr - raddr + padpsize; 10377c478bd9Sstevel@tonic-gate 10387c478bd9Sstevel@tonic-gate /* 10397c478bd9Sstevel@tonic-gate * As ths image has been realigned, the first segment 10407c478bd9Sstevel@tonic-gate * of the file needs to be remapped to its correct 10417c478bd9Sstevel@tonic-gate * location. 10427c478bd9Sstevel@tonic-gate */ 10437c478bd9Sstevel@tonic-gate skipfseg = 0; 10447c478bd9Sstevel@tonic-gate } else 10457c478bd9Sstevel@tonic-gate esize = padmsize - padpsize; 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate /* 10487c478bd9Sstevel@tonic-gate * If this reservation included padding, remove any excess for 10497c478bd9Sstevel@tonic-gate * the start of the image (the padding was adjusted to insure 10507c478bd9Sstevel@tonic-gate * the image was aligned appropriately). 10517c478bd9Sstevel@tonic-gate */ 10527c478bd9Sstevel@tonic-gate if (esize) { 10537c478bd9Sstevel@tonic-gate (void) munmap(raddr, esize); 10547c478bd9Sstevel@tonic-gate raddr += esize; 10557c478bd9Sstevel@tonic-gate rsize -= esize; 10567c478bd9Sstevel@tonic-gate } 10577c478bd9Sstevel@tonic-gate } 10587c478bd9Sstevel@tonic-gate 10597c478bd9Sstevel@tonic-gate /* 10607c478bd9Sstevel@tonic-gate * At this point we know the initial location of the image, and its 10617c478bd9Sstevel@tonic-gate * size. Pass these back to the caller for inclusion in the link-map 10627c478bd9Sstevel@tonic-gate * that will eventually be created. 10637c478bd9Sstevel@tonic-gate */ 10647c478bd9Sstevel@tonic-gate *rraddr = raddr; 10657c478bd9Sstevel@tonic-gate *rrsize = rsize; 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate /* 10687c478bd9Sstevel@tonic-gate * The first loadable segment is now pointed to by maddr. This segment 10697c478bd9Sstevel@tonic-gate * will eventually contain the elf header and program headers, so reset 10707c478bd9Sstevel@tonic-gate * the program header. Pass this back to the caller for inclusion in 10717c478bd9Sstevel@tonic-gate * the link-map so it can be used for later unmapping operations. 10727c478bd9Sstevel@tonic-gate */ 10737c478bd9Sstevel@tonic-gate /* LINTED */ 10747c478bd9Sstevel@tonic-gate *rrphdr = (Phdr *)((char *)maddr + ehdr->e_phoff); 10757c478bd9Sstevel@tonic-gate 10767c478bd9Sstevel@tonic-gate /* 10777c478bd9Sstevel@tonic-gate * If padding is required at the front of the image, obtain that now. 10787c478bd9Sstevel@tonic-gate * Note, if we've already obtained a reservation from anonymous memory 10797c478bd9Sstevel@tonic-gate * then this reservation will already include suitable padding. 10807c478bd9Sstevel@tonic-gate * Otherwise this reservation is backed by the file, or in the case of 10817c478bd9Sstevel@tonic-gate * a fixed image, doesn't yet exist. Map the padding so that it is 10827c478bd9Sstevel@tonic-gate * suitably protected (PROT_NONE), and insure the first segment of the 10837c478bd9Sstevel@tonic-gate * file is mapped to its correct location. 10847c478bd9Sstevel@tonic-gate */ 10857c478bd9Sstevel@tonic-gate if (padsize) { 10867c478bd9Sstevel@tonic-gate if (amret == AM_NOSUP) { 10875aefb655Srie if (dz_map(lml, raddr, padpsize, PROT_NONE, 10885aefb655Srie (MAP_PRIVATE | MAP_FIXED | MAP_NORESERVE)) == 10895aefb655Srie MAP_FAILED) 10907c478bd9Sstevel@tonic-gate return (0); 10917c478bd9Sstevel@tonic-gate 10927c478bd9Sstevel@tonic-gate skipfseg = 0; 10937c478bd9Sstevel@tonic-gate } 10947c478bd9Sstevel@tonic-gate rsize -= padpsize; 10957c478bd9Sstevel@tonic-gate } 10967c478bd9Sstevel@tonic-gate 10977c478bd9Sstevel@tonic-gate /* 10987c478bd9Sstevel@tonic-gate * Map individual segments. For a fixed image, these will each be 10997c478bd9Sstevel@tonic-gate * unique mappings. For a reservation these will fill in the 11007c478bd9Sstevel@tonic-gate * reservation. 11017c478bd9Sstevel@tonic-gate */ 11027c478bd9Sstevel@tonic-gate for (phdr = fphdr; phdr <= lphdr; 11037c478bd9Sstevel@tonic-gate phdr = (Phdr *)((Off)phdr + ehdr->e_phentsize)) { 11047c478bd9Sstevel@tonic-gate caddr_t addr; 11057c478bd9Sstevel@tonic-gate Off mlen, flen; 11067c478bd9Sstevel@tonic-gate size_t size; 11077c478bd9Sstevel@tonic-gate 11087c478bd9Sstevel@tonic-gate /* 11097c478bd9Sstevel@tonic-gate * Skip non-loadable segments or segments that don't occupy 11107c478bd9Sstevel@tonic-gate * any memory. 11117c478bd9Sstevel@tonic-gate */ 11127c478bd9Sstevel@tonic-gate if (((phdr->p_type != PT_LOAD) && 11137c478bd9Sstevel@tonic-gate (phdr->p_type != PT_SUNWBSS)) || (phdr->p_memsz == 0)) 11147c478bd9Sstevel@tonic-gate continue; 11157c478bd9Sstevel@tonic-gate 11167c478bd9Sstevel@tonic-gate /* 11177c478bd9Sstevel@tonic-gate * Establish this segments address relative to our base. 11187c478bd9Sstevel@tonic-gate */ 11197c478bd9Sstevel@tonic-gate addr = (caddr_t)M_PTRUNC((ulong_t)(phdr->p_vaddr + 11207c478bd9Sstevel@tonic-gate (fixed ? 0 : faddr))); 11217c478bd9Sstevel@tonic-gate 11227c478bd9Sstevel@tonic-gate /* 11237c478bd9Sstevel@tonic-gate * Determine the mapping protection from the segment attributes. 11247c478bd9Sstevel@tonic-gate * Also determine the etext address from the last loadable 11257c478bd9Sstevel@tonic-gate * segment which has permissions but no write access. 11267c478bd9Sstevel@tonic-gate */ 11277c478bd9Sstevel@tonic-gate mperm = 0; 11287c478bd9Sstevel@tonic-gate if (phdr->p_flags) { 11297c478bd9Sstevel@tonic-gate if (phdr->p_flags & PF_R) 11307c478bd9Sstevel@tonic-gate mperm |= PROT_READ; 11317c478bd9Sstevel@tonic-gate if (phdr->p_flags & PF_X) 11327c478bd9Sstevel@tonic-gate mperm |= PROT_EXEC; 11337c478bd9Sstevel@tonic-gate if (phdr->p_flags & PF_W) 11347c478bd9Sstevel@tonic-gate mperm |= PROT_WRITE; 11357c478bd9Sstevel@tonic-gate else 11367c478bd9Sstevel@tonic-gate fmap->fm_etext = phdr->p_vaddr + phdr->p_memsz + 11377c478bd9Sstevel@tonic-gate (ulong_t)(fixed ? 0 : faddr); 11387c478bd9Sstevel@tonic-gate } 11397c478bd9Sstevel@tonic-gate 11407c478bd9Sstevel@tonic-gate /* 11417c478bd9Sstevel@tonic-gate * Determine the type of mapping required. 11427c478bd9Sstevel@tonic-gate */ 11437c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_SUNWBSS) { 11447c478bd9Sstevel@tonic-gate /* 11457c478bd9Sstevel@tonic-gate * Potentially, we can defer the loading of any SUNWBSS 11467c478bd9Sstevel@tonic-gate * segment, depending on whether the symbols it provides 11477c478bd9Sstevel@tonic-gate * have been bound to. In this manner, large segments 11487c478bd9Sstevel@tonic-gate * that are interposed upon between shared libraries 11497c478bd9Sstevel@tonic-gate * may not require mapping. Note, that the mapping 11507c478bd9Sstevel@tonic-gate * information is recorded in our mapping descriptor at 11517c478bd9Sstevel@tonic-gate * this time. 11527c478bd9Sstevel@tonic-gate */ 11537c478bd9Sstevel@tonic-gate mlen = phdr->p_memsz; 11547c478bd9Sstevel@tonic-gate flen = 0; 11557c478bd9Sstevel@tonic-gate 11567c478bd9Sstevel@tonic-gate } else if ((phdr->p_filesz == 0) && (phdr->p_flags == 0)) { 11577c478bd9Sstevel@tonic-gate /* 11587c478bd9Sstevel@tonic-gate * If this segment has no backing file and no flags 11597c478bd9Sstevel@tonic-gate * specified, then it defines a reservation. At this 11607c478bd9Sstevel@tonic-gate * point all standard loadable segments will have been 11617c478bd9Sstevel@tonic-gate * processed. The segment reservation is mapped 11627c478bd9Sstevel@tonic-gate * directly from /dev/null. 11637c478bd9Sstevel@tonic-gate */ 11645aefb655Srie if (nu_map(lml, (caddr_t)addr, phdr->p_memsz, PROT_NONE, 11657c478bd9Sstevel@tonic-gate MAP_FIXED | MAP_PRIVATE) == MAP_FAILED) 11667c478bd9Sstevel@tonic-gate return (0); 11677c478bd9Sstevel@tonic-gate 11687c478bd9Sstevel@tonic-gate mlen = phdr->p_memsz; 11697c478bd9Sstevel@tonic-gate flen = 0; 11707c478bd9Sstevel@tonic-gate 11717c478bd9Sstevel@tonic-gate } else if (phdr->p_filesz == 0) { 11727c478bd9Sstevel@tonic-gate /* 11737c478bd9Sstevel@tonic-gate * If this segment has no backing file then it defines a 11747c478bd9Sstevel@tonic-gate * nobits segment and is mapped directly from /dev/zero. 11757c478bd9Sstevel@tonic-gate */ 11765aefb655Srie if (dz_map(lml, (caddr_t)addr, phdr->p_memsz, mperm, 11777c478bd9Sstevel@tonic-gate MAP_FIXED | MAP_PRIVATE) == MAP_FAILED) 11787c478bd9Sstevel@tonic-gate return (0); 11797c478bd9Sstevel@tonic-gate 11807c478bd9Sstevel@tonic-gate mlen = phdr->p_memsz; 11817c478bd9Sstevel@tonic-gate flen = 0; 11827c478bd9Sstevel@tonic-gate 11837c478bd9Sstevel@tonic-gate } else { 11847c478bd9Sstevel@tonic-gate Off foff; 11857c478bd9Sstevel@tonic-gate 11867c478bd9Sstevel@tonic-gate /* 11877c478bd9Sstevel@tonic-gate * This mapping originates from the file. Determine the 11887c478bd9Sstevel@tonic-gate * file offset to which the mapping will be directed 11897c478bd9Sstevel@tonic-gate * (must be aligned) and how much to map (might be more 11907c478bd9Sstevel@tonic-gate * than the file in the case of .bss). 11917c478bd9Sstevel@tonic-gate */ 11927c478bd9Sstevel@tonic-gate foff = M_PTRUNC((ulong_t)phdr->p_offset); 11937c478bd9Sstevel@tonic-gate mlen = phdr->p_memsz + (phdr->p_offset - foff); 11947c478bd9Sstevel@tonic-gate flen = phdr->p_filesz + (phdr->p_offset - foff); 11957c478bd9Sstevel@tonic-gate 11967c478bd9Sstevel@tonic-gate /* 11977c478bd9Sstevel@tonic-gate * If this is a non-fixed, non-anonymous mapping, and no 11987c478bd9Sstevel@tonic-gate * padding is involved, then the first loadable segment 11997c478bd9Sstevel@tonic-gate * is already part of the initial reservation. In this 12007c478bd9Sstevel@tonic-gate * case there is no need to remap this segment. 12017c478bd9Sstevel@tonic-gate */ 12027c478bd9Sstevel@tonic-gate if ((skipfseg == 0) || (phdr != fphdr)) { 12037c478bd9Sstevel@tonic-gate int phdr_mperm = mperm; 12047c478bd9Sstevel@tonic-gate /* 12057c478bd9Sstevel@tonic-gate * If this segments memsz is greater that its 12067c478bd9Sstevel@tonic-gate * filesz then the difference must be zeroed. 12077c478bd9Sstevel@tonic-gate * Make sure this segment is writable. 12087c478bd9Sstevel@tonic-gate */ 12097c478bd9Sstevel@tonic-gate if (phdr->p_memsz > phdr->p_filesz) 12107c478bd9Sstevel@tonic-gate mperm |= PROT_WRITE; 12117c478bd9Sstevel@tonic-gate 12127c478bd9Sstevel@tonic-gate if (elf_map_textdata((caddr_t)addr, flen, 12137c478bd9Sstevel@tonic-gate mperm, phdr_mperm, 12147c478bd9Sstevel@tonic-gate (MAP_FIXED | MAP_PRIVATE), fd, foff) == 12157c478bd9Sstevel@tonic-gate MAP_FAILED) { 12167c478bd9Sstevel@tonic-gate int err = errno; 12175aefb655Srie eprintf(lml, ERR_FATAL, 12187c478bd9Sstevel@tonic-gate MSG_INTL(MSG_SYS_MMAP), name, 12197c478bd9Sstevel@tonic-gate strerror(err)); 12207c478bd9Sstevel@tonic-gate return (0); 12217c478bd9Sstevel@tonic-gate } 12227c478bd9Sstevel@tonic-gate } 12237c478bd9Sstevel@tonic-gate 12247c478bd9Sstevel@tonic-gate /* 12257c478bd9Sstevel@tonic-gate * If the memory occupancy of the segment overflows the 12267c478bd9Sstevel@tonic-gate * definition in the file, we need to "zero out" the end 12277c478bd9Sstevel@tonic-gate * of the mapping we've established, and if necessary, 12287c478bd9Sstevel@tonic-gate * map some more space from /dev/zero. Note, zero'ed 12297c478bd9Sstevel@tonic-gate * memory must end on a double word boundary to satisfy 12307c478bd9Sstevel@tonic-gate * zero(). 12317c478bd9Sstevel@tonic-gate */ 12327c478bd9Sstevel@tonic-gate if (phdr->p_memsz > phdr->p_filesz) { 12337c478bd9Sstevel@tonic-gate caddr_t zaddr; 12347c478bd9Sstevel@tonic-gate size_t zlen, zplen; 12357c478bd9Sstevel@tonic-gate Off fend; 12367c478bd9Sstevel@tonic-gate 12377c478bd9Sstevel@tonic-gate foff = (Off)(phdr->p_vaddr + phdr->p_filesz + 12387c478bd9Sstevel@tonic-gate (fixed ? 0 : faddr)); 12397c478bd9Sstevel@tonic-gate zaddr = (caddr_t)M_PROUND(foff); 12407c478bd9Sstevel@tonic-gate zplen = (size_t)(zaddr - foff); 12417c478bd9Sstevel@tonic-gate 12427c478bd9Sstevel@tonic-gate fend = (Off)S_DROUND((size_t)(phdr->p_vaddr + 12437c478bd9Sstevel@tonic-gate phdr->p_memsz + (fixed ? 0 : faddr))); 12447c478bd9Sstevel@tonic-gate zlen = (size_t)(fend - foff); 12457c478bd9Sstevel@tonic-gate 12467c478bd9Sstevel@tonic-gate /* 12477c478bd9Sstevel@tonic-gate * Determine whether the number of bytes that 12487c478bd9Sstevel@tonic-gate * must be zero'ed overflow to the next page. 12497c478bd9Sstevel@tonic-gate * If not, simply clear the exact bytes 12507c478bd9Sstevel@tonic-gate * (filesz to memsz) from this page. Otherwise, 12517c478bd9Sstevel@tonic-gate * clear the remaining bytes of this page, and 12527c478bd9Sstevel@tonic-gate * map an following pages from /dev/zero. 12537c478bd9Sstevel@tonic-gate */ 12547c478bd9Sstevel@tonic-gate if (zlen < zplen) 12557c478bd9Sstevel@tonic-gate zero((caddr_t)foff, (long)zlen); 12567c478bd9Sstevel@tonic-gate else { 12577c478bd9Sstevel@tonic-gate zero((caddr_t)foff, (long)zplen); 12587c478bd9Sstevel@tonic-gate 12597c478bd9Sstevel@tonic-gate if ((zlen = (fend - (Off)zaddr)) > 0) { 12605aefb655Srie if (dz_map(lml, zaddr, zlen, 12615aefb655Srie mperm, 12627c478bd9Sstevel@tonic-gate MAP_FIXED | MAP_PRIVATE) == 12637c478bd9Sstevel@tonic-gate MAP_FAILED) 12647c478bd9Sstevel@tonic-gate return (0); 12657c478bd9Sstevel@tonic-gate } 12667c478bd9Sstevel@tonic-gate } 12677c478bd9Sstevel@tonic-gate } 12687c478bd9Sstevel@tonic-gate } 12697c478bd9Sstevel@tonic-gate 12707c478bd9Sstevel@tonic-gate /* 12717c478bd9Sstevel@tonic-gate * Unmap anything from the last mapping address to this one and 12727c478bd9Sstevel@tonic-gate * update the mapping claim pointer. 12737c478bd9Sstevel@tonic-gate */ 12747c478bd9Sstevel@tonic-gate if ((fixed == 0) && ((size = addr - maddr) != 0)) { 12757c478bd9Sstevel@tonic-gate (void) munmap(maddr, size); 12767c478bd9Sstevel@tonic-gate rsize -= size; 12777c478bd9Sstevel@tonic-gate } 12787c478bd9Sstevel@tonic-gate 12797c478bd9Sstevel@tonic-gate /* 12807c478bd9Sstevel@tonic-gate * Retain this segments mapping information. 12817c478bd9Sstevel@tonic-gate */ 12827c478bd9Sstevel@tonic-gate mmaps[*mmapcnt].m_vaddr = addr; 12837c478bd9Sstevel@tonic-gate mmaps[*mmapcnt].m_msize = mlen; 12847c478bd9Sstevel@tonic-gate mmaps[*mmapcnt].m_fsize = flen; 12857c478bd9Sstevel@tonic-gate mmaps[*mmapcnt].m_perm = mperm; 12867c478bd9Sstevel@tonic-gate (*mmapcnt)++; 12877c478bd9Sstevel@tonic-gate 12887c478bd9Sstevel@tonic-gate maddr = addr + M_PROUND(mlen); 12897c478bd9Sstevel@tonic-gate rsize -= M_PROUND(mlen); 12907c478bd9Sstevel@tonic-gate } 12917c478bd9Sstevel@tonic-gate 12927c478bd9Sstevel@tonic-gate /* 12937c478bd9Sstevel@tonic-gate * If padding is required at the end of the image, obtain that now. 12947c478bd9Sstevel@tonic-gate * Note, if we've already obtained a reservation from anonymous memory 12957c478bd9Sstevel@tonic-gate * then this reservation will already include suitable padding. 12967c478bd9Sstevel@tonic-gate */ 12977c478bd9Sstevel@tonic-gate if (padsize) { 12987c478bd9Sstevel@tonic-gate if (amret == AM_NOSUP) { 12997c478bd9Sstevel@tonic-gate /* 13007c478bd9Sstevel@tonic-gate * maddr is currently page aligned from the last segment 13017c478bd9Sstevel@tonic-gate * mapping. 13027c478bd9Sstevel@tonic-gate */ 13035aefb655Srie if (dz_map(lml, maddr, padsize, PROT_NONE, 13045aefb655Srie (MAP_PRIVATE | MAP_FIXED | MAP_NORESERVE)) == 13055aefb655Srie MAP_FAILED) 13067c478bd9Sstevel@tonic-gate return (0); 13077c478bd9Sstevel@tonic-gate } 13087c478bd9Sstevel@tonic-gate maddr += padsize; 13097c478bd9Sstevel@tonic-gate rsize -= padsize; 13107c478bd9Sstevel@tonic-gate } 13117c478bd9Sstevel@tonic-gate 13127c478bd9Sstevel@tonic-gate /* 13137c478bd9Sstevel@tonic-gate * Unmap any final reservation. 13147c478bd9Sstevel@tonic-gate */ 13157c478bd9Sstevel@tonic-gate if ((fixed == 0) && (rsize != 0)) 13167c478bd9Sstevel@tonic-gate (void) munmap(maddr, rsize); 13177c478bd9Sstevel@tonic-gate 13187c478bd9Sstevel@tonic-gate return (faddr); 13197c478bd9Sstevel@tonic-gate } 13207c478bd9Sstevel@tonic-gate 13217c478bd9Sstevel@tonic-gate /* 13227c478bd9Sstevel@tonic-gate * A null symbol interpretor. Used if a filter has no associated filtees. 13237c478bd9Sstevel@tonic-gate */ 13247c478bd9Sstevel@tonic-gate /* ARGSUSED0 */ 13257c478bd9Sstevel@tonic-gate static Sym * 13267c478bd9Sstevel@tonic-gate elf_null_find_sym(Slookup *slp, Rt_map **dlmp, uint_t *binfo) 13277c478bd9Sstevel@tonic-gate { 13287c478bd9Sstevel@tonic-gate return ((Sym *)0); 13297c478bd9Sstevel@tonic-gate } 13307c478bd9Sstevel@tonic-gate 13317c478bd9Sstevel@tonic-gate /* 13327c478bd9Sstevel@tonic-gate * Disable filtee use. 13337c478bd9Sstevel@tonic-gate */ 13347c478bd9Sstevel@tonic-gate static void 13359a411307Srie elf_disable_filtee(Rt_map *lmp, Dyninfo *dip) 13367c478bd9Sstevel@tonic-gate { 13377c478bd9Sstevel@tonic-gate dip->di_info = 0; 13387c478bd9Sstevel@tonic-gate 13397c478bd9Sstevel@tonic-gate if ((dip->di_flags & FLG_DI_SYMFLTR) == 0) { 13407c478bd9Sstevel@tonic-gate /* 13417c478bd9Sstevel@tonic-gate * If this is an object filter, free the filtee's duplication. 13427c478bd9Sstevel@tonic-gate */ 13437c478bd9Sstevel@tonic-gate if (OBJFLTRNDX(lmp) != FLTR_DISABLED) { 13447c478bd9Sstevel@tonic-gate free(REFNAME(lmp)); 13457c478bd9Sstevel@tonic-gate REFNAME(lmp) = (char *)0; 13467c478bd9Sstevel@tonic-gate OBJFLTRNDX(lmp) = FLTR_DISABLED; 13477c478bd9Sstevel@tonic-gate 13487c478bd9Sstevel@tonic-gate /* 13497c478bd9Sstevel@tonic-gate * Indicate that this filtee is no longer available. 13507c478bd9Sstevel@tonic-gate */ 13517c478bd9Sstevel@tonic-gate if (dip->di_flags & FLG_DI_STDFLTR) 13527c478bd9Sstevel@tonic-gate SYMINTP(lmp) = elf_null_find_sym; 13537c478bd9Sstevel@tonic-gate 13547c478bd9Sstevel@tonic-gate } 13557c478bd9Sstevel@tonic-gate } else if (dip->di_flags & FLG_DI_STDFLTR) { 13567c478bd9Sstevel@tonic-gate /* 13577c478bd9Sstevel@tonic-gate * Indicate that this standard filtee is no longer available. 13587c478bd9Sstevel@tonic-gate */ 13597c478bd9Sstevel@tonic-gate if (SYMSFLTRCNT(lmp)) 13607c478bd9Sstevel@tonic-gate SYMSFLTRCNT(lmp)--; 13617c478bd9Sstevel@tonic-gate } else { 13627c478bd9Sstevel@tonic-gate /* 13637c478bd9Sstevel@tonic-gate * Indicate that this auxiliary filtee is no longer available. 13647c478bd9Sstevel@tonic-gate */ 13657c478bd9Sstevel@tonic-gate if (SYMAFLTRCNT(lmp)) 13667c478bd9Sstevel@tonic-gate SYMAFLTRCNT(lmp)--; 13677c478bd9Sstevel@tonic-gate } 13687c478bd9Sstevel@tonic-gate dip->di_flags &= ~MSK_DI_FILTER; 13697c478bd9Sstevel@tonic-gate } 13707c478bd9Sstevel@tonic-gate 13717c478bd9Sstevel@tonic-gate /* 13727c478bd9Sstevel@tonic-gate * Find symbol interpreter - filters. 13737c478bd9Sstevel@tonic-gate * This function is called when the symbols from a shared object should 13747c478bd9Sstevel@tonic-gate * be resolved from the shared objects filtees instead of from within itself. 13757c478bd9Sstevel@tonic-gate * 13767c478bd9Sstevel@tonic-gate * A symbol name of 0 is used to trigger filtee loading. 13777c478bd9Sstevel@tonic-gate */ 13787c478bd9Sstevel@tonic-gate static Sym * 13797c478bd9Sstevel@tonic-gate _elf_lookup_filtee(Slookup *slp, Rt_map **dlmp, uint_t *binfo, uint_t ndx) 13807c478bd9Sstevel@tonic-gate { 13817c478bd9Sstevel@tonic-gate const char *name = slp->sl_name, *filtees; 13827c478bd9Sstevel@tonic-gate Rt_map *clmp = slp->sl_cmap; 13837c478bd9Sstevel@tonic-gate Rt_map *ilmp = slp->sl_imap; 13847c478bd9Sstevel@tonic-gate Pnode *pnp, **pnpp; 13857c478bd9Sstevel@tonic-gate int any; 13867c478bd9Sstevel@tonic-gate Dyninfo *dip = &DYNINFO(ilmp)[ndx]; 13877c478bd9Sstevel@tonic-gate Lm_list *lml = LIST(ilmp); 13887c478bd9Sstevel@tonic-gate 13897c478bd9Sstevel@tonic-gate /* 13907c478bd9Sstevel@tonic-gate * Indicate that the filter has been used. If a binding already exists 13917c478bd9Sstevel@tonic-gate * to the caller, indicate that this object is referenced. This insures 13927c478bd9Sstevel@tonic-gate * we don't generate false unreferenced diagnostics from ldd -u/U or 13937c478bd9Sstevel@tonic-gate * debugging. Don't create a binding regardless, as this filter may 13947c478bd9Sstevel@tonic-gate * have been dlopen()'ed. 13957c478bd9Sstevel@tonic-gate */ 13967c478bd9Sstevel@tonic-gate if (name && (ilmp != clmp)) { 13977c478bd9Sstevel@tonic-gate Word tracing = (LIST(clmp)->lm_flags & 13987c478bd9Sstevel@tonic-gate (LML_FLG_TRC_UNREF | LML_FLG_TRC_UNUSED)); 13997c478bd9Sstevel@tonic-gate 14005aefb655Srie if (tracing || DBG_ENABLED) { 1401cce0e03bSab Bnd_desc *bdp; 1402cce0e03bSab Aliste idx; 14037c478bd9Sstevel@tonic-gate 14047c478bd9Sstevel@tonic-gate FLAGS1(ilmp) |= FL1_RT_USED; 14057c478bd9Sstevel@tonic-gate 14065aefb655Srie if ((tracing & LML_FLG_TRC_UNREF) || DBG_ENABLED) { 1407cce0e03bSab for (APLIST_TRAVERSE(CALLERS(ilmp), idx, bdp)) { 14087c478bd9Sstevel@tonic-gate if (bdp->b_caller == clmp) { 14097c478bd9Sstevel@tonic-gate bdp->b_flags |= BND_REFER; 14107c478bd9Sstevel@tonic-gate break; 14117c478bd9Sstevel@tonic-gate } 14127c478bd9Sstevel@tonic-gate } 14137c478bd9Sstevel@tonic-gate } 14147c478bd9Sstevel@tonic-gate } 14157c478bd9Sstevel@tonic-gate } 14167c478bd9Sstevel@tonic-gate 14177c478bd9Sstevel@tonic-gate /* 14187c478bd9Sstevel@tonic-gate * If this is the first call to process this filter, establish the 14197c478bd9Sstevel@tonic-gate * filtee list. If a configuration file exists, determine if any 14207c478bd9Sstevel@tonic-gate * filtee associations for this filter, and its filtee reference, are 14217c478bd9Sstevel@tonic-gate * defined. Otherwise, process the filtee reference. Any token 14227c478bd9Sstevel@tonic-gate * expansion is also completed at this point (i.e., $PLATFORM). 14237c478bd9Sstevel@tonic-gate */ 14247c478bd9Sstevel@tonic-gate filtees = (char *)STRTAB(ilmp) + DYN(ilmp)[ndx].d_un.d_val; 14257c478bd9Sstevel@tonic-gate if (dip->di_info == 0) { 14267c478bd9Sstevel@tonic-gate if (rtld_flags2 & RT_FL2_FLTCFG) 14275aefb655Srie dip->di_info = elf_config_flt(lml, PATHNAME(ilmp), 14285aefb655Srie filtees); 14297c478bd9Sstevel@tonic-gate 14307c478bd9Sstevel@tonic-gate if (dip->di_info == 0) { 14315aefb655Srie DBG_CALL(Dbg_file_filter(lml, NAME(ilmp), filtees, 0)); 14327c478bd9Sstevel@tonic-gate if ((lml->lm_flags & 14337c478bd9Sstevel@tonic-gate (LML_FLG_TRC_VERBOSE | LML_FLG_TRC_SEARCH)) && 14347c478bd9Sstevel@tonic-gate ((FLAGS1(ilmp) & FL1_RT_LDDSTUB) == 0)) 14357c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_LDD_FIL_FILTER), 14367c478bd9Sstevel@tonic-gate NAME(ilmp), filtees); 14377c478bd9Sstevel@tonic-gate 14387c478bd9Sstevel@tonic-gate if ((dip->di_info = (void *)expand_paths(ilmp, 14397c478bd9Sstevel@tonic-gate filtees, PN_SER_FILTEE, 0)) == 0) { 14407c478bd9Sstevel@tonic-gate elf_disable_filtee(ilmp, dip); 14417c478bd9Sstevel@tonic-gate return ((Sym *)0); 14427c478bd9Sstevel@tonic-gate } 14437c478bd9Sstevel@tonic-gate } 14447c478bd9Sstevel@tonic-gate } 14457c478bd9Sstevel@tonic-gate 14467c478bd9Sstevel@tonic-gate /* 14477c478bd9Sstevel@tonic-gate * Traverse the filtee list, dlopen()'ing any objects specified and 14487c478bd9Sstevel@tonic-gate * using their group handle to lookup the symbol. 14497c478bd9Sstevel@tonic-gate */ 14507c478bd9Sstevel@tonic-gate for (any = 0, pnpp = (Pnode **)&(dip->di_info), pnp = *pnpp; pnp; 14519a411307Srie pnpp = &pnp->p_next, pnp = *pnpp) { 14527c478bd9Sstevel@tonic-gate int mode; 14537c478bd9Sstevel@tonic-gate Grp_hdl *ghp; 14547c478bd9Sstevel@tonic-gate Rt_map *nlmp = 0; 14557c478bd9Sstevel@tonic-gate 14567c478bd9Sstevel@tonic-gate if (pnp->p_len == 0) 14577c478bd9Sstevel@tonic-gate continue; 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate /* 14607c478bd9Sstevel@tonic-gate * Establish the mode of the filtee from the filter. As filtees 14617c478bd9Sstevel@tonic-gate * are loaded via a dlopen(), make sure that RTLD_GROUP is set 14627c478bd9Sstevel@tonic-gate * and the filtees aren't global. It would be nice to have 14637c478bd9Sstevel@tonic-gate * RTLD_FIRST used here also, but as filters got out long before 14647c478bd9Sstevel@tonic-gate * RTLD_FIRST was introduced it's a little too late now. 14657c478bd9Sstevel@tonic-gate */ 14667c478bd9Sstevel@tonic-gate mode = MODE(ilmp) | RTLD_GROUP; 14677c478bd9Sstevel@tonic-gate mode &= ~RTLD_GLOBAL; 14687c478bd9Sstevel@tonic-gate 14697c478bd9Sstevel@tonic-gate /* 14707c478bd9Sstevel@tonic-gate * Insure that any auxiliary filter can locate symbols from its 14717c478bd9Sstevel@tonic-gate * caller. 14727c478bd9Sstevel@tonic-gate */ 14737c478bd9Sstevel@tonic-gate if (dip->di_flags & FLG_DI_AUXFLTR) 14747c478bd9Sstevel@tonic-gate mode |= RTLD_PARENT; 14757c478bd9Sstevel@tonic-gate 14767c478bd9Sstevel@tonic-gate /* 14777c478bd9Sstevel@tonic-gate * Process any hardware capability directory. Establish a new 14787c478bd9Sstevel@tonic-gate * link-map control list from which to analyze any newly added 147924a6229eSrie * objects. 14807c478bd9Sstevel@tonic-gate */ 14817c478bd9Sstevel@tonic-gate if ((pnp->p_info == 0) && (pnp->p_orig & PN_TKN_HWCAP)) { 148211a2bb38Srie Lm_cntl *lmc; 148311a2bb38Srie Aliste lmco; 148411a2bb38Srie 148524a6229eSrie if (FLAGS(lml->lm_head) & FLG_RT_RELOCED) { 1486cce0e03bSab if ((lmc = alist_append(&lml->lm_lists, 0, 148724a6229eSrie sizeof (Lm_cntl), AL_CNT_LMLISTS)) == 0) 148824a6229eSrie return ((Sym *)0); 14897c478bd9Sstevel@tonic-gate lmco = (Aliste)((char *)lmc - 14907c478bd9Sstevel@tonic-gate (char *)lml->lm_lists); 149124a6229eSrie } else { 149224a6229eSrie lmc = 0; 1493cce0e03bSab lmco = ALIST_OFF_DATA; 149424a6229eSrie } 14957c478bd9Sstevel@tonic-gate 149602ca3e02Srie pnp = hwcap_filtees(pnpp, lmco, lmc, dip, ilmp, filtees, 14977c478bd9Sstevel@tonic-gate mode, (FLG_RT_HANDLE | FLG_RT_HWCAP)); 149811a2bb38Srie 149911a2bb38Srie /* 150011a2bb38Srie * Now that any hardware capability objects have been 150111a2bb38Srie * processed, remove any link-map control list. 150211a2bb38Srie */ 150302ca3e02Srie if (lmc) 150411a2bb38Srie remove_cntl(lml, lmco); 15057c478bd9Sstevel@tonic-gate } 15067c478bd9Sstevel@tonic-gate 15077c478bd9Sstevel@tonic-gate if (pnp->p_len == 0) 15087c478bd9Sstevel@tonic-gate continue; 15097c478bd9Sstevel@tonic-gate 15107c478bd9Sstevel@tonic-gate /* 15117c478bd9Sstevel@tonic-gate * Process an individual filtee. 15127c478bd9Sstevel@tonic-gate */ 15137c478bd9Sstevel@tonic-gate if (pnp->p_info == 0) { 15147c478bd9Sstevel@tonic-gate const char *filtee = pnp->p_name; 15157c478bd9Sstevel@tonic-gate int audit = 0; 15167c478bd9Sstevel@tonic-gate 15175aefb655Srie DBG_CALL(Dbg_file_filtee(lml, NAME(ilmp), filtee, 0)); 15187c478bd9Sstevel@tonic-gate 15197c478bd9Sstevel@tonic-gate ghp = 0; 15207c478bd9Sstevel@tonic-gate 15217c478bd9Sstevel@tonic-gate /* 15227c478bd9Sstevel@tonic-gate * Determine if the reference link map is already 15237c478bd9Sstevel@tonic-gate * loaded. As an optimization compare the filtee with 15247c478bd9Sstevel@tonic-gate * our interpretor. The most common filter is 15257c478bd9Sstevel@tonic-gate * libdl.so.1, which is a filter on ld.so.1. 15267c478bd9Sstevel@tonic-gate */ 15277c478bd9Sstevel@tonic-gate #if defined(_ELF64) 15287c478bd9Sstevel@tonic-gate if (strcmp(filtee, MSG_ORIG(MSG_PTH_RTLD_64)) == 0) { 15297c478bd9Sstevel@tonic-gate #else 15307c478bd9Sstevel@tonic-gate if (strcmp(filtee, MSG_ORIG(MSG_PTH_RTLD)) == 0) { 15317c478bd9Sstevel@tonic-gate #endif 15327c478bd9Sstevel@tonic-gate /* 15338af2c5b9Srie * Create an association between ld.so.1 and the 15348af2c5b9Srie * filter. As an optimization, a handle for 15358af2c5b9Srie * ld.so.1 itself (required for the dlopen() 15368af2c5b9Srie * family filtering mechanism) shouldn't search 15378af2c5b9Srie * any dependencies of ld.so.1. Omitting 15388af2c5b9Srie * GPD_ADDEPS prevents the addition of any 15398af2c5b9Srie * ld.so.1 dependencies to this handle. 15407c478bd9Sstevel@tonic-gate */ 15417c478bd9Sstevel@tonic-gate nlmp = lml_rtld.lm_head; 15427c478bd9Sstevel@tonic-gate if ((ghp = hdl_create(&lml_rtld, nlmp, ilmp, 15438af2c5b9Srie (GPH_LDSO | GPH_FIRST | GPH_FILTEE), 15448af2c5b9Srie (GPD_DLSYM | GPD_RELOC), GPD_PARENT)) == 0) 15457c478bd9Sstevel@tonic-gate nlmp = 0; 15467c478bd9Sstevel@tonic-gate 15477c478bd9Sstevel@tonic-gate /* 15487c478bd9Sstevel@tonic-gate * Establish the filter handle to prevent any 15497c478bd9Sstevel@tonic-gate * recursion. 15507c478bd9Sstevel@tonic-gate */ 15517c478bd9Sstevel@tonic-gate if (nlmp && ghp) 15527c478bd9Sstevel@tonic-gate pnp->p_info = (void *)ghp; 15537c478bd9Sstevel@tonic-gate 15547c478bd9Sstevel@tonic-gate /* 15557c478bd9Sstevel@tonic-gate * Audit the filter/filtee established. Ignore 15567c478bd9Sstevel@tonic-gate * any return from the auditor, as we can't 15577c478bd9Sstevel@tonic-gate * allow ignore filtering to ld.so.1, otherwise 15587c478bd9Sstevel@tonic-gate * nothing is going to work. 15597c478bd9Sstevel@tonic-gate */ 156002ca3e02Srie if (nlmp && ((lml->lm_tflags | FLAGS1(ilmp)) & 156102ca3e02Srie LML_TFLG_AUD_OBJFILTER)) 15627c478bd9Sstevel@tonic-gate (void) audit_objfilter(ilmp, filtees, 15637c478bd9Sstevel@tonic-gate nlmp, 0); 15647c478bd9Sstevel@tonic-gate 15657c478bd9Sstevel@tonic-gate } else { 15667c478bd9Sstevel@tonic-gate Rej_desc rej = { 0 }; 156711a2bb38Srie Lm_cntl *lmc; 156811a2bb38Srie Aliste lmco; 15697c478bd9Sstevel@tonic-gate 15707c478bd9Sstevel@tonic-gate /* 15717c478bd9Sstevel@tonic-gate * Establish a new link-map control list from 15727c478bd9Sstevel@tonic-gate * which to analyze any newly added objects. 15737c478bd9Sstevel@tonic-gate */ 157424a6229eSrie if (FLAGS(lml->lm_head) & FLG_RT_RELOCED) { 157524a6229eSrie if ((lmc = 1576cce0e03bSab alist_append(&lml->lm_lists, 0, 157724a6229eSrie sizeof (Lm_cntl), 157824a6229eSrie AL_CNT_LMLISTS)) == 0) 157924a6229eSrie return ((Sym *)0); 15807c478bd9Sstevel@tonic-gate lmco = (Aliste)((char *)lmc - 15817c478bd9Sstevel@tonic-gate (char *)lml->lm_lists); 158224a6229eSrie } else { 158324a6229eSrie lmc = 0; 1584cce0e03bSab lmco = ALIST_OFF_DATA; 158524a6229eSrie } 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate /* 15887247f888Srie * Load the filtee. Note, an auditor can 15897247f888Srie * provide an alternative name. 15907c478bd9Sstevel@tonic-gate */ 15917247f888Srie if ((nlmp = load_path(lml, lmco, &(pnp->p_name), 15927247f888Srie ilmp, mode, FLG_RT_HANDLE, &ghp, 0, 15937247f888Srie &rej)) == 0) { 15947c478bd9Sstevel@tonic-gate file_notfound(LIST(ilmp), filtee, ilmp, 15957c478bd9Sstevel@tonic-gate FLG_RT_HANDLE, &rej); 15967c478bd9Sstevel@tonic-gate remove_rej(&rej); 15977c478bd9Sstevel@tonic-gate } 15987247f888Srie filtee = pnp->p_name; 15997c478bd9Sstevel@tonic-gate 16007c478bd9Sstevel@tonic-gate /* 16017c478bd9Sstevel@tonic-gate * Establish the filter handle to prevent any 16027c478bd9Sstevel@tonic-gate * recursion. 16037c478bd9Sstevel@tonic-gate */ 16047c478bd9Sstevel@tonic-gate if (nlmp && ghp) { 16057c478bd9Sstevel@tonic-gate ghp->gh_flags |= GPH_FILTEE; 16067c478bd9Sstevel@tonic-gate pnp->p_info = (void *)ghp; 16077c478bd9Sstevel@tonic-gate } 16087c478bd9Sstevel@tonic-gate 16097c478bd9Sstevel@tonic-gate /* 16107c478bd9Sstevel@tonic-gate * Audit the filter/filtee established. A 16117c478bd9Sstevel@tonic-gate * return of 0 indicates the auditor wishes to 16127c478bd9Sstevel@tonic-gate * ignore this filtee. 16137c478bd9Sstevel@tonic-gate */ 16147c478bd9Sstevel@tonic-gate if (nlmp && ((lml->lm_tflags | FLAGS1(ilmp)) & 16157c478bd9Sstevel@tonic-gate LML_TFLG_AUD_OBJFILTER)) { 16167c478bd9Sstevel@tonic-gate if (audit_objfilter(ilmp, filtees, 16177c478bd9Sstevel@tonic-gate nlmp, 0) == 0) { 16187c478bd9Sstevel@tonic-gate audit = 1; 16197c478bd9Sstevel@tonic-gate nlmp = 0; 16207c478bd9Sstevel@tonic-gate } 16217c478bd9Sstevel@tonic-gate } 16227c478bd9Sstevel@tonic-gate 16237c478bd9Sstevel@tonic-gate /* 16247c478bd9Sstevel@tonic-gate * Finish processing the objects associated with 16257c478bd9Sstevel@tonic-gate * this request. Create an association between 16267c478bd9Sstevel@tonic-gate * this object and the originating filter to 16277c478bd9Sstevel@tonic-gate * provide sufficient information to tear down 16287c478bd9Sstevel@tonic-gate * this filtee if necessary. 16297c478bd9Sstevel@tonic-gate */ 16307c478bd9Sstevel@tonic-gate if (nlmp && ghp && 16317c478bd9Sstevel@tonic-gate ((analyze_lmc(lml, lmco, nlmp) == 0) || 163202ca3e02Srie (relocate_lmc(lml, lmco, ilmp, nlmp) == 0))) 16337c478bd9Sstevel@tonic-gate nlmp = 0; 16347c478bd9Sstevel@tonic-gate 16357c478bd9Sstevel@tonic-gate /* 16367c478bd9Sstevel@tonic-gate * If the filtee has been successfully 163702ca3e02Srie * processed, then create an association 163802ca3e02Srie * between the filter and filtee. This 163902ca3e02Srie * association provides sufficient information 164002ca3e02Srie * to tear down the filter and filtee if 164102ca3e02Srie * necessary. 16427c478bd9Sstevel@tonic-gate */ 16438af2c5b9Srie DBG_CALL(Dbg_file_hdl_title(DBG_HDL_ADD)); 164402ca3e02Srie if (nlmp && ghp && 16457c478bd9Sstevel@tonic-gate (hdl_add(ghp, ilmp, GPD_FILTER) == 0)) 16467c478bd9Sstevel@tonic-gate nlmp = 0; 164711a2bb38Srie 164811a2bb38Srie /* 164902ca3e02Srie * If this filtee loading has failed, and we've 165002ca3e02Srie * created a new link-map control list to which 165102ca3e02Srie * this request has added objects, then remove 165202ca3e02Srie * all the objects that have been associated to 165302ca3e02Srie * this request. 165411a2bb38Srie */ 165502ca3e02Srie if ((nlmp == 0) && lmc && lmc->lc_head) 165602ca3e02Srie remove_lmc(lml, clmp, lmc, lmco, name); 165702ca3e02Srie 165802ca3e02Srie /* 165902ca3e02Srie * Remove any link-map control list that was 166002ca3e02Srie * created. 166102ca3e02Srie */ 166202ca3e02Srie if (lmc) 166311a2bb38Srie remove_cntl(lml, lmco); 16647c478bd9Sstevel@tonic-gate } 16657c478bd9Sstevel@tonic-gate 16667c478bd9Sstevel@tonic-gate /* 16677c478bd9Sstevel@tonic-gate * Generate a diagnostic if the filtee couldn't be 16687c478bd9Sstevel@tonic-gate * loaded, null out the pnode entry, and continue 16697c478bd9Sstevel@tonic-gate * the search. Otherwise, retain this group handle 16707c478bd9Sstevel@tonic-gate * for future symbol searches. 16717c478bd9Sstevel@tonic-gate */ 16727c478bd9Sstevel@tonic-gate if (nlmp == 0) { 16735aefb655Srie DBG_CALL(Dbg_file_filtee(lml, 0, filtee, 16745aefb655Srie audit)); 16757c478bd9Sstevel@tonic-gate 167602ca3e02Srie pnp->p_info = 0; 16777c478bd9Sstevel@tonic-gate pnp->p_len = 0; 16787c478bd9Sstevel@tonic-gate continue; 16797c478bd9Sstevel@tonic-gate } 16807c478bd9Sstevel@tonic-gate } 16817c478bd9Sstevel@tonic-gate 16827c478bd9Sstevel@tonic-gate ghp = (Grp_hdl *)pnp->p_info; 16837c478bd9Sstevel@tonic-gate 16847c478bd9Sstevel@tonic-gate /* 16857c478bd9Sstevel@tonic-gate * If we're just here to trigger filtee loading skip the symbol 16867c478bd9Sstevel@tonic-gate * lookup so we'll continue looking for additional filtees. 16877c478bd9Sstevel@tonic-gate */ 16887c478bd9Sstevel@tonic-gate if (name) { 16897c478bd9Sstevel@tonic-gate Grp_desc *gdp; 16907c478bd9Sstevel@tonic-gate Sym *sym = 0; 1691cce0e03bSab Aliste idx; 16927c478bd9Sstevel@tonic-gate Slookup sl = *slp; 16937c478bd9Sstevel@tonic-gate 16947c478bd9Sstevel@tonic-gate sl.sl_flags |= LKUP_FIRST; 16957c478bd9Sstevel@tonic-gate any++; 16967c478bd9Sstevel@tonic-gate 16977c478bd9Sstevel@tonic-gate /* 16987c478bd9Sstevel@tonic-gate * Look for the symbol in the handles dependencies. 16997c478bd9Sstevel@tonic-gate */ 1700cce0e03bSab for (ALIST_TRAVERSE(ghp->gh_depends, idx, gdp)) { 1701efb9e8b8Srie if ((gdp->gd_flags & GPD_DLSYM) == 0) 17027c478bd9Sstevel@tonic-gate continue; 17037c478bd9Sstevel@tonic-gate 17047c478bd9Sstevel@tonic-gate /* 17057c478bd9Sstevel@tonic-gate * If our parent is a dependency don't look at 17067c478bd9Sstevel@tonic-gate * it (otherwise we are in a recursive loop). 17077c478bd9Sstevel@tonic-gate * This situation can occur with auxiliary 17087c478bd9Sstevel@tonic-gate * filters if the filtee has a dependency on the 17097c478bd9Sstevel@tonic-gate * filter. This dependency isn't necessary as 17107c478bd9Sstevel@tonic-gate * auxiliary filters are opened RTLD_PARENT, but 17117c478bd9Sstevel@tonic-gate * users may still unknowingly add an explicit 17127c478bd9Sstevel@tonic-gate * dependency to the parent. 17137c478bd9Sstevel@tonic-gate */ 17147c478bd9Sstevel@tonic-gate if ((sl.sl_imap = gdp->gd_depend) == ilmp) 17157c478bd9Sstevel@tonic-gate continue; 17167c478bd9Sstevel@tonic-gate 17177c478bd9Sstevel@tonic-gate if (((sym = SYMINTP(sl.sl_imap)(&sl, dlmp, 17187c478bd9Sstevel@tonic-gate binfo)) != 0) || 17197c478bd9Sstevel@tonic-gate (ghp->gh_flags & GPH_FIRST)) 17207c478bd9Sstevel@tonic-gate break; 17217c478bd9Sstevel@tonic-gate } 17227c478bd9Sstevel@tonic-gate 17237c478bd9Sstevel@tonic-gate /* 172402ca3e02Srie * If a symbol has been found, indicate the binding 172502ca3e02Srie * and return the symbol. 17267c478bd9Sstevel@tonic-gate */ 17277c478bd9Sstevel@tonic-gate if (sym) { 17287c478bd9Sstevel@tonic-gate *binfo |= DBG_BINFO_FILTEE; 17297c478bd9Sstevel@tonic-gate return (sym); 17307c478bd9Sstevel@tonic-gate } 17317c478bd9Sstevel@tonic-gate } 17327c478bd9Sstevel@tonic-gate 17337c478bd9Sstevel@tonic-gate /* 17347c478bd9Sstevel@tonic-gate * If this object is tagged to terminate filtee processing we're 17357c478bd9Sstevel@tonic-gate * done. 17367c478bd9Sstevel@tonic-gate */ 17375aefb655Srie if (FLAGS1(ghp->gh_ownlmp) & FL1_RT_ENDFILTE) 17387c478bd9Sstevel@tonic-gate break; 17397c478bd9Sstevel@tonic-gate } 17407c478bd9Sstevel@tonic-gate 17417c478bd9Sstevel@tonic-gate /* 17427c478bd9Sstevel@tonic-gate * If we're just here to trigger filtee loading then we're done. 17437c478bd9Sstevel@tonic-gate */ 17447c478bd9Sstevel@tonic-gate if (name == 0) 17457c478bd9Sstevel@tonic-gate return ((Sym *)0); 17467c478bd9Sstevel@tonic-gate 17477c478bd9Sstevel@tonic-gate /* 17487c478bd9Sstevel@tonic-gate * If no filtees have been found for a filter, clean up any Pnode 17497c478bd9Sstevel@tonic-gate * structures and disable their search completely. For auxiliary 17507c478bd9Sstevel@tonic-gate * filters we can reselect the symbol search function so that we never 17517c478bd9Sstevel@tonic-gate * enter this routine again for this object. For standard filters we 17527c478bd9Sstevel@tonic-gate * use the null symbol routine. 17537c478bd9Sstevel@tonic-gate */ 17547c478bd9Sstevel@tonic-gate if (any == 0) { 17557c478bd9Sstevel@tonic-gate remove_pnode((Pnode *)dip->di_info); 17567c478bd9Sstevel@tonic-gate elf_disable_filtee(ilmp, dip); 17577c478bd9Sstevel@tonic-gate return ((Sym *)0); 17587c478bd9Sstevel@tonic-gate } 17597c478bd9Sstevel@tonic-gate 17607c478bd9Sstevel@tonic-gate return ((Sym *)0); 17617c478bd9Sstevel@tonic-gate } 17627c478bd9Sstevel@tonic-gate 17637c478bd9Sstevel@tonic-gate /* 17647c478bd9Sstevel@tonic-gate * Focal point for disabling error messages for auxiliary filters. As an 17657c478bd9Sstevel@tonic-gate * auxiliary filter allows for filtee use, but provides a fallback should a 17667c478bd9Sstevel@tonic-gate * filtee not exist (or fail to load), any errors generated as a consequence of 17677c478bd9Sstevel@tonic-gate * trying to load the filtees are typically suppressed. Setting RT_FL_SILENCERR 17687c478bd9Sstevel@tonic-gate * suppresses errors generated by eprint(), but insures a debug diagnostic is 17697c478bd9Sstevel@tonic-gate * produced. ldd(1) employs printf(), and here, the selection of whether to 17707c478bd9Sstevel@tonic-gate * print a diagnostic in regards to auxiliary filters is a little more complex. 17717c478bd9Sstevel@tonic-gate * 17727c478bd9Sstevel@tonic-gate * . The determination of whether to produce an ldd message, or a fatal 17737c478bd9Sstevel@tonic-gate * error message is driven by LML_FLG_TRC_ENABLE. 17747c478bd9Sstevel@tonic-gate * . More detailed ldd messages may also be driven off of LML_FLG_TRC_WARN, 17757c478bd9Sstevel@tonic-gate * (ldd -d/-r), LML_FLG_TRC_VERBOSE (ldd -v), LML_FLG_TRC_SEARCH (ldd -s), 17767c478bd9Sstevel@tonic-gate * and LML_FLG_TRC_UNREF/LML_FLG_TRC_UNUSED (ldd -U/-u). 17777c478bd9Sstevel@tonic-gate * 17787c478bd9Sstevel@tonic-gate * . If the calling object is lddstub, then several classes of message are 17797c478bd9Sstevel@tonic-gate * suppressed. The user isn't trying to diagnose lddstub, this is simply 17807c478bd9Sstevel@tonic-gate * a stub executable employed to preload a user specified library against. 17817c478bd9Sstevel@tonic-gate * 17827c478bd9Sstevel@tonic-gate * . If RT_FL_SILENCERR is in effect then any generic ldd() messages should 17837c478bd9Sstevel@tonic-gate * be suppressed. All detailed ldd messages should still be produced. 17847c478bd9Sstevel@tonic-gate */ 17857c478bd9Sstevel@tonic-gate Sym * 17867c478bd9Sstevel@tonic-gate elf_lookup_filtee(Slookup *slp, Rt_map **dlmp, uint_t *binfo, uint_t ndx) 17877c478bd9Sstevel@tonic-gate { 17887c478bd9Sstevel@tonic-gate Sym *sym; 17897c478bd9Sstevel@tonic-gate Dyninfo *dip = &DYNINFO(slp->sl_imap)[ndx]; 17907c478bd9Sstevel@tonic-gate int silent = 0; 17917c478bd9Sstevel@tonic-gate 17927c478bd9Sstevel@tonic-gate /* 17937c478bd9Sstevel@tonic-gate * Make sure this entry is still acting as a filter. We may have tried 17947c478bd9Sstevel@tonic-gate * to process this previously, and disabled it if the filtee couldn't 17957c478bd9Sstevel@tonic-gate * be processed. However, other entries may provide different filtees 17967c478bd9Sstevel@tonic-gate * that are yet to be completed. 17977c478bd9Sstevel@tonic-gate */ 17987c478bd9Sstevel@tonic-gate if (dip->di_flags == 0) 17997c478bd9Sstevel@tonic-gate return ((Sym *)0); 18007c478bd9Sstevel@tonic-gate 18017c478bd9Sstevel@tonic-gate /* 18027c478bd9Sstevel@tonic-gate * Indicate whether an error message is required should this filtee not 18037c478bd9Sstevel@tonic-gate * be found, based on the type of filter. 18047c478bd9Sstevel@tonic-gate */ 18057c478bd9Sstevel@tonic-gate if ((dip->di_flags & FLG_DI_AUXFLTR) && 18067c478bd9Sstevel@tonic-gate ((rtld_flags & (RT_FL_WARNFLTR | RT_FL_SILENCERR)) == 0)) { 18077c478bd9Sstevel@tonic-gate rtld_flags |= RT_FL_SILENCERR; 18087c478bd9Sstevel@tonic-gate silent = 1; 18097c478bd9Sstevel@tonic-gate } 18107c478bd9Sstevel@tonic-gate 18117c478bd9Sstevel@tonic-gate sym = _elf_lookup_filtee(slp, dlmp, binfo, ndx); 18127c478bd9Sstevel@tonic-gate 18137c478bd9Sstevel@tonic-gate if (silent) 18147c478bd9Sstevel@tonic-gate rtld_flags &= ~RT_FL_SILENCERR; 18157c478bd9Sstevel@tonic-gate 18167c478bd9Sstevel@tonic-gate return (sym); 18177c478bd9Sstevel@tonic-gate } 18187c478bd9Sstevel@tonic-gate 18197c478bd9Sstevel@tonic-gate /* 18207c478bd9Sstevel@tonic-gate * Compute the elf hash value (as defined in the ELF access library). 18217c478bd9Sstevel@tonic-gate * The form of the hash table is: 18227c478bd9Sstevel@tonic-gate * 18237c478bd9Sstevel@tonic-gate * |--------------| 18247c478bd9Sstevel@tonic-gate * | # of buckets | 18257c478bd9Sstevel@tonic-gate * |--------------| 18267c478bd9Sstevel@tonic-gate * | # of chains | 18277c478bd9Sstevel@tonic-gate * |--------------| 18287c478bd9Sstevel@tonic-gate * | bucket[] | 18297c478bd9Sstevel@tonic-gate * |--------------| 18307c478bd9Sstevel@tonic-gate * | chain[] | 18317c478bd9Sstevel@tonic-gate * |--------------| 18327c478bd9Sstevel@tonic-gate */ 18337c478bd9Sstevel@tonic-gate ulong_t 18347c478bd9Sstevel@tonic-gate elf_hash(const char *name) 18357c478bd9Sstevel@tonic-gate { 18367c478bd9Sstevel@tonic-gate uint_t hval = 0; 18377c478bd9Sstevel@tonic-gate 18387c478bd9Sstevel@tonic-gate while (*name) { 18397c478bd9Sstevel@tonic-gate uint_t g; 18407c478bd9Sstevel@tonic-gate hval = (hval << 4) + *name++; 18417c478bd9Sstevel@tonic-gate if ((g = (hval & 0xf0000000)) != 0) 18427c478bd9Sstevel@tonic-gate hval ^= g >> 24; 18437c478bd9Sstevel@tonic-gate hval &= ~g; 18447c478bd9Sstevel@tonic-gate } 18457c478bd9Sstevel@tonic-gate return ((ulong_t)hval); 18467c478bd9Sstevel@tonic-gate } 18477c478bd9Sstevel@tonic-gate 18487c478bd9Sstevel@tonic-gate /* 18497c478bd9Sstevel@tonic-gate * If flag argument has LKUP_SPEC set, we treat undefined symbols of type 18507c478bd9Sstevel@tonic-gate * function specially in the executable - if they have a value, even though 18517c478bd9Sstevel@tonic-gate * undefined, we use that value. This allows us to associate all references 18527c478bd9Sstevel@tonic-gate * to a function's address to a single place in the process: the plt entry 18537c478bd9Sstevel@tonic-gate * for that function in the executable. Calls to lookup from plt binding 18547c478bd9Sstevel@tonic-gate * routines do NOT set LKUP_SPEC in the flag. 18557c478bd9Sstevel@tonic-gate */ 18567c478bd9Sstevel@tonic-gate Sym * 18577c478bd9Sstevel@tonic-gate elf_find_sym(Slookup *slp, Rt_map **dlmp, uint_t *binfo) 18587c478bd9Sstevel@tonic-gate { 18597c478bd9Sstevel@tonic-gate const char *name = slp->sl_name; 18607c478bd9Sstevel@tonic-gate Rt_map *ilmp = slp->sl_imap; 18617c478bd9Sstevel@tonic-gate ulong_t hash = slp->sl_hash; 18627c478bd9Sstevel@tonic-gate uint_t ndx, htmp, buckets, *chainptr; 18637c478bd9Sstevel@tonic-gate Sym *sym, *symtabptr; 18647c478bd9Sstevel@tonic-gate char *strtabptr, *strtabname; 18657c478bd9Sstevel@tonic-gate uint_t flags1; 18667c478bd9Sstevel@tonic-gate Syminfo *sip; 18677c478bd9Sstevel@tonic-gate 1868660acd81Srie /* 1869660acd81Srie * If we're only here to establish a symbols index, skip the diagnostic 1870660acd81Srie * used to trace a symbol search. 1871660acd81Srie */ 18725aefb655Srie if ((slp->sl_flags & LKUP_SYMNDX) == 0) 18735aefb655Srie DBG_CALL(Dbg_syms_lookup(ilmp, name, MSG_ORIG(MSG_STR_ELF))); 18747c478bd9Sstevel@tonic-gate 18757c478bd9Sstevel@tonic-gate if (HASH(ilmp) == 0) 18767c478bd9Sstevel@tonic-gate return ((Sym *)0); 18777c478bd9Sstevel@tonic-gate 18787c478bd9Sstevel@tonic-gate buckets = HASH(ilmp)[0]; 18797c478bd9Sstevel@tonic-gate /* LINTED */ 18807c478bd9Sstevel@tonic-gate htmp = (uint_t)hash % buckets; 18817c478bd9Sstevel@tonic-gate 18827c478bd9Sstevel@tonic-gate /* 18837c478bd9Sstevel@tonic-gate * Get the first symbol on hash chain and initialize the string 18847c478bd9Sstevel@tonic-gate * and symbol table pointers. 18857c478bd9Sstevel@tonic-gate */ 18867c478bd9Sstevel@tonic-gate if ((ndx = HASH(ilmp)[htmp + 2]) == 0) 18877c478bd9Sstevel@tonic-gate return ((Sym *)0); 18887c478bd9Sstevel@tonic-gate 18897c478bd9Sstevel@tonic-gate chainptr = HASH(ilmp) + 2 + buckets; 18907c478bd9Sstevel@tonic-gate strtabptr = STRTAB(ilmp); 18917c478bd9Sstevel@tonic-gate symtabptr = SYMTAB(ilmp); 18927c478bd9Sstevel@tonic-gate 18937c478bd9Sstevel@tonic-gate while (ndx) { 18947c478bd9Sstevel@tonic-gate sym = symtabptr + ndx; 18957c478bd9Sstevel@tonic-gate strtabname = strtabptr + sym->st_name; 18967c478bd9Sstevel@tonic-gate 18977c478bd9Sstevel@tonic-gate /* 18987c478bd9Sstevel@tonic-gate * Compare the symbol found with the name required. If the 18997c478bd9Sstevel@tonic-gate * names don't match continue with the next hash entry. 19007c478bd9Sstevel@tonic-gate */ 19017c478bd9Sstevel@tonic-gate if ((*strtabname++ != *name) || strcmp(strtabname, &name[1])) { 19027c478bd9Sstevel@tonic-gate if ((ndx = chainptr[ndx]) != 0) 19037c478bd9Sstevel@tonic-gate continue; 19047c478bd9Sstevel@tonic-gate return ((Sym *)0); 19057c478bd9Sstevel@tonic-gate } 19067c478bd9Sstevel@tonic-gate 19073b41b08bSab /* 1908d840867fSab * The Solaris ld does not put DT_VERSYM in the dynamic 1909d840867fSab * section, but the GNU ld does. The GNU runtime linker 1910d840867fSab * interprets the top bit of the 16-bit Versym value 1911d840867fSab * (0x8000) as the "hidden" bit. If this bit is set, 1912d840867fSab * the linker is supposed to act as if that symbol does 1913d840867fSab * not exist. The hidden bit supports their versioning 1914d840867fSab * scheme, which allows multiple incompatible functions 1915d840867fSab * with the same name to exist at different versions 1916d840867fSab * within an object. The Solaris linker does not support this 1917d840867fSab * mechanism, or the model of interface evolution that 1918d840867fSab * it allows, but we honor the hidden bit in GNU ld 1919d840867fSab * produced objects in order to interoperate with them. 19203b41b08bSab */ 1921d840867fSab if ((VERSYM(ilmp) != NULL) && 1922d840867fSab ((VERSYM(ilmp)[ndx] & 0x8000) != 0)) { 1923d840867fSab DBG_CALL(Dbg_syms_ignore_gnuver(ilmp, name, 19243b41b08bSab ndx, VERSYM(ilmp)[ndx])); 19253b41b08bSab if ((ndx = chainptr[ndx]) != 0) 19263b41b08bSab continue; 19273b41b08bSab return ((Sym *)0); 19283b41b08bSab } 19293b41b08bSab 1930660acd81Srie /* 1931660acd81Srie * If we're only here to establish a symbols index, we're done. 1932660acd81Srie */ 1933660acd81Srie if (slp->sl_flags & LKUP_SYMNDX) 1934660acd81Srie return (sym); 1935660acd81Srie 19367c478bd9Sstevel@tonic-gate /* 19377c478bd9Sstevel@tonic-gate * If we find a match and the symbol is defined, return the 19387c478bd9Sstevel@tonic-gate * symbol pointer and the link map in which it was found. 19397c478bd9Sstevel@tonic-gate */ 19407c478bd9Sstevel@tonic-gate if (sym->st_shndx != SHN_UNDEF) { 19417c478bd9Sstevel@tonic-gate *dlmp = ilmp; 19427c478bd9Sstevel@tonic-gate *binfo |= DBG_BINFO_FOUND; 19439a411307Srie if ((FLAGS(ilmp) & FLG_RT_OBJINTPO) || 19449a411307Srie ((FLAGS(ilmp) & FLG_RT_SYMINTPO) && 19459a411307Srie is_sym_interposer(ilmp, sym))) 19467c478bd9Sstevel@tonic-gate *binfo |= DBG_BINFO_INTERPOSE; 19477c478bd9Sstevel@tonic-gate break; 19487c478bd9Sstevel@tonic-gate 19497c478bd9Sstevel@tonic-gate /* 19507c478bd9Sstevel@tonic-gate * If we find a match and the symbol is undefined, the 19517c478bd9Sstevel@tonic-gate * symbol type is a function, and the value of the symbol 19527c478bd9Sstevel@tonic-gate * is non zero, then this is a special case. This allows 19537c478bd9Sstevel@tonic-gate * the resolution of a function address to the plt[] entry. 19547c478bd9Sstevel@tonic-gate * See SPARC ABI, Dynamic Linking, Function Addresses for 19557c478bd9Sstevel@tonic-gate * more details. 19567c478bd9Sstevel@tonic-gate */ 1957660acd81Srie } else if ((slp->sl_flags & LKUP_SPEC) && 19587c478bd9Sstevel@tonic-gate (FLAGS(ilmp) & FLG_RT_ISMAIN) && (sym->st_value != 0) && 19597c478bd9Sstevel@tonic-gate (ELF_ST_TYPE(sym->st_info) == STT_FUNC)) { 19607c478bd9Sstevel@tonic-gate *dlmp = ilmp; 19617c478bd9Sstevel@tonic-gate *binfo |= (DBG_BINFO_FOUND | DBG_BINFO_PLTADDR); 19629a411307Srie if ((FLAGS(ilmp) & FLG_RT_OBJINTPO) || 19639a411307Srie ((FLAGS(ilmp) & FLG_RT_SYMINTPO) && 19649a411307Srie is_sym_interposer(ilmp, sym))) 19657c478bd9Sstevel@tonic-gate *binfo |= DBG_BINFO_INTERPOSE; 19667c478bd9Sstevel@tonic-gate return (sym); 19677c478bd9Sstevel@tonic-gate } 19687c478bd9Sstevel@tonic-gate 19697c478bd9Sstevel@tonic-gate /* 19707c478bd9Sstevel@tonic-gate * Undefined symbol. 19717c478bd9Sstevel@tonic-gate */ 19727c478bd9Sstevel@tonic-gate return ((Sym *)0); 19737c478bd9Sstevel@tonic-gate } 19747c478bd9Sstevel@tonic-gate 19757c478bd9Sstevel@tonic-gate /* 19767c478bd9Sstevel@tonic-gate * We've found a match. Determine if the defining object contains 19777c478bd9Sstevel@tonic-gate * symbol binding information. 19787c478bd9Sstevel@tonic-gate */ 19797c478bd9Sstevel@tonic-gate if ((sip = SYMINFO(ilmp)) != 0) 19809039eeafSab sip += ndx; 19817c478bd9Sstevel@tonic-gate 198260758829Srie /* 198360758829Srie * If this definition is a singleton, and we haven't followed a default 198460758829Srie * symbol search knowing that we're looking for a singleton (presumably 198560758829Srie * because the symbol definition has been changed since the referring 198660758829Srie * object was built), then reject this binding so that the caller can 198760758829Srie * fall back to a standard symbol search. 198860758829Srie */ 198960758829Srie if ((ELF_ST_VISIBILITY(sym->st_other) == STV_SINGLETON) && 199060758829Srie (((slp->sl_flags & LKUP_STANDARD) == 0) || 199160758829Srie (((slp->sl_flags & LKUP_SINGLETON) == 0) && 199260758829Srie (LIST(ilmp)->lm_flags & LML_FLG_GROUPSEXIST)))) { 199360758829Srie DBG_CALL(Dbg_bind_reject(slp->sl_cmap, ilmp, name, 199460758829Srie DBG_BNDREJ_SINGLE)); 199560758829Srie *binfo |= BINFO_REJSINGLE; 199660758829Srie *binfo &= ~DBG_BINFO_MSK; 199760758829Srie return ((Sym *)0); 199860758829Srie } 199960758829Srie 20007c478bd9Sstevel@tonic-gate /* 20017c478bd9Sstevel@tonic-gate * If this is a direct binding request, but the symbol definition has 20027c478bd9Sstevel@tonic-gate * disabled directly binding to it (presumably because the symbol 20037c478bd9Sstevel@tonic-gate * definition has been changed since the referring object was built), 20047c478bd9Sstevel@tonic-gate * indicate this failure so that the caller can fall back to a standard 200560758829Srie * symbol search. 20067c478bd9Sstevel@tonic-gate */ 20077c478bd9Sstevel@tonic-gate if (sip && (slp->sl_flags & LKUP_DIRECT) && 20087c478bd9Sstevel@tonic-gate (sip->si_flags & SYMINFO_FLG_NOEXTDIRECT)) { 200960758829Srie DBG_CALL(Dbg_bind_reject(slp->sl_cmap, ilmp, name, 201060758829Srie DBG_BNDREJ_NODIR)); 201160758829Srie *binfo |= BINFO_REJDIRECT; 20127c478bd9Sstevel@tonic-gate *binfo &= ~DBG_BINFO_MSK; 20137c478bd9Sstevel@tonic-gate return ((Sym *)0); 20147c478bd9Sstevel@tonic-gate } 20157c478bd9Sstevel@tonic-gate 20167c478bd9Sstevel@tonic-gate /* 20177c478bd9Sstevel@tonic-gate * Determine whether this object is acting as a filter. 20187c478bd9Sstevel@tonic-gate */ 20197c478bd9Sstevel@tonic-gate if (((flags1 = FLAGS1(ilmp)) & MSK_RT_FILTER) == 0) 20207c478bd9Sstevel@tonic-gate return (sym); 20217c478bd9Sstevel@tonic-gate 20227c478bd9Sstevel@tonic-gate /* 20237c478bd9Sstevel@tonic-gate * Determine if this object offers per-symbol filtering, and if so, 20247c478bd9Sstevel@tonic-gate * whether this symbol references a filtee. 20257c478bd9Sstevel@tonic-gate */ 20267c478bd9Sstevel@tonic-gate if (sip && (flags1 & (FL1_RT_SYMSFLTR | FL1_RT_SYMAFLTR))) { 20277c478bd9Sstevel@tonic-gate /* 20287c478bd9Sstevel@tonic-gate * If this is a standard filter reference, and no standard 20297c478bd9Sstevel@tonic-gate * filtees remain to be inspected, we're done. If this is an 20307c478bd9Sstevel@tonic-gate * auxiliary filter reference, and no auxiliary filtees remain, 20317c478bd9Sstevel@tonic-gate * we'll fall through in case any object filtering is available. 20327c478bd9Sstevel@tonic-gate */ 20337c478bd9Sstevel@tonic-gate if ((sip->si_flags & SYMINFO_FLG_FILTER) && 20347c478bd9Sstevel@tonic-gate (SYMSFLTRCNT(ilmp) == 0)) 20357c478bd9Sstevel@tonic-gate return ((Sym *)0); 20367c478bd9Sstevel@tonic-gate 20377c478bd9Sstevel@tonic-gate if ((sip->si_flags & SYMINFO_FLG_FILTER) || 20387c478bd9Sstevel@tonic-gate ((sip->si_flags & SYMINFO_FLG_AUXILIARY) && 20397c478bd9Sstevel@tonic-gate SYMAFLTRCNT(ilmp))) { 2040*75e7992aSrie Sym *fsym; 20417c478bd9Sstevel@tonic-gate 20427c478bd9Sstevel@tonic-gate /* 20437c478bd9Sstevel@tonic-gate * This symbol has an associated filtee. Lookup the 20447c478bd9Sstevel@tonic-gate * symbol in the filtee, and if it is found return it. 20457c478bd9Sstevel@tonic-gate * If the symbol doesn't exist, and this is a standard 20467c478bd9Sstevel@tonic-gate * filter, return an error, otherwise fall through to 20477c478bd9Sstevel@tonic-gate * catch any object filtering that may be available. 20487c478bd9Sstevel@tonic-gate */ 20497c478bd9Sstevel@tonic-gate if ((fsym = elf_lookup_filtee(slp, dlmp, binfo, 20507c478bd9Sstevel@tonic-gate sip->si_boundto)) != 0) 20517c478bd9Sstevel@tonic-gate return (fsym); 20527c478bd9Sstevel@tonic-gate if (sip->si_flags & SYMINFO_FLG_FILTER) 20537c478bd9Sstevel@tonic-gate return ((Sym *)0); 20547c478bd9Sstevel@tonic-gate } 20557c478bd9Sstevel@tonic-gate } 20567c478bd9Sstevel@tonic-gate 20577c478bd9Sstevel@tonic-gate /* 20587c478bd9Sstevel@tonic-gate * Determine if this object provides global filtering. 20597c478bd9Sstevel@tonic-gate */ 20607c478bd9Sstevel@tonic-gate if (flags1 & (FL1_RT_OBJSFLTR | FL1_RT_OBJAFLTR)) { 2061*75e7992aSrie Sym *fsym; 20627c478bd9Sstevel@tonic-gate 20637c478bd9Sstevel@tonic-gate if (OBJFLTRNDX(ilmp) != FLTR_DISABLED) { 20647c478bd9Sstevel@tonic-gate /* 20657c478bd9Sstevel@tonic-gate * This object has an associated filtee. Lookup the 20667c478bd9Sstevel@tonic-gate * symbol in the filtee, and if it is found return it. 20677c478bd9Sstevel@tonic-gate * If the symbol doesn't exist, and this is a standard 20687c478bd9Sstevel@tonic-gate * filter, return and error, otherwise return the symbol 20697c478bd9Sstevel@tonic-gate * within the filter itself. 20707c478bd9Sstevel@tonic-gate */ 20717c478bd9Sstevel@tonic-gate if ((fsym = elf_lookup_filtee(slp, dlmp, binfo, 20727c478bd9Sstevel@tonic-gate OBJFLTRNDX(ilmp))) != 0) 20737c478bd9Sstevel@tonic-gate return (fsym); 20747c478bd9Sstevel@tonic-gate } 20757c478bd9Sstevel@tonic-gate 20767c478bd9Sstevel@tonic-gate if (flags1 & FL1_RT_OBJSFLTR) 20777c478bd9Sstevel@tonic-gate return ((Sym *)0); 20787c478bd9Sstevel@tonic-gate } 20797c478bd9Sstevel@tonic-gate return (sym); 20807c478bd9Sstevel@tonic-gate } 20817c478bd9Sstevel@tonic-gate 20827c478bd9Sstevel@tonic-gate /* 20837c478bd9Sstevel@tonic-gate * Create a new Rt_map structure for an ELF object and initialize 20847c478bd9Sstevel@tonic-gate * all values. 20857c478bd9Sstevel@tonic-gate */ 20867c478bd9Sstevel@tonic-gate Rt_map * 20877c478bd9Sstevel@tonic-gate elf_new_lm(Lm_list *lml, const char *pname, const char *oname, Dyn *ld, 20887c478bd9Sstevel@tonic-gate ulong_t addr, ulong_t etext, Aliste lmco, ulong_t msize, ulong_t entry, 20897c478bd9Sstevel@tonic-gate ulong_t paddr, ulong_t padimsize, Mmap *mmaps, uint_t mmapcnt) 20907c478bd9Sstevel@tonic-gate { 20917c478bd9Sstevel@tonic-gate Rt_map *lmp; 20927c478bd9Sstevel@tonic-gate ulong_t base, fltr = 0, audit = 0, cfile = 0, crle = 0; 20937c478bd9Sstevel@tonic-gate Xword rpath = 0; 20947c478bd9Sstevel@tonic-gate Ehdr *ehdr = (Ehdr *)addr; 20957c478bd9Sstevel@tonic-gate 20965aefb655Srie DBG_CALL(Dbg_file_elf(lml, pname, (ulong_t)ld, addr, msize, entry, 20975aefb655Srie lml->lm_lmidstr, lmco)); 20987c478bd9Sstevel@tonic-gate 20997c478bd9Sstevel@tonic-gate /* 21007c478bd9Sstevel@tonic-gate * Allocate space for the link-map and private elf information. Once 21017c478bd9Sstevel@tonic-gate * these are allocated and initialized, we can use remove_so(0, lmp) to 21027c478bd9Sstevel@tonic-gate * tear down the link-map should any failures occur. 21037c478bd9Sstevel@tonic-gate */ 21047c478bd9Sstevel@tonic-gate if ((lmp = calloc(sizeof (Rt_map), 1)) == 0) 21057c478bd9Sstevel@tonic-gate return (0); 21067c478bd9Sstevel@tonic-gate if ((ELFPRV(lmp) = calloc(sizeof (Rt_elfp), 1)) == 0) { 21077c478bd9Sstevel@tonic-gate free(lmp); 21087c478bd9Sstevel@tonic-gate return (0); 21097c478bd9Sstevel@tonic-gate } 21107c478bd9Sstevel@tonic-gate 21117c478bd9Sstevel@tonic-gate /* 21127c478bd9Sstevel@tonic-gate * All fields not filled in were set to 0 by calloc. 21137c478bd9Sstevel@tonic-gate */ 21147c478bd9Sstevel@tonic-gate ORIGNAME(lmp) = PATHNAME(lmp) = NAME(lmp) = (char *)pname; 21157c478bd9Sstevel@tonic-gate DYN(lmp) = ld; 21167c478bd9Sstevel@tonic-gate ADDR(lmp) = addr; 21177c478bd9Sstevel@tonic-gate MSIZE(lmp) = msize; 21187c478bd9Sstevel@tonic-gate ENTRY(lmp) = (Addr)entry; 21197c478bd9Sstevel@tonic-gate SYMINTP(lmp) = elf_find_sym; 21207c478bd9Sstevel@tonic-gate ETEXT(lmp) = etext; 21217c478bd9Sstevel@tonic-gate FCT(lmp) = &elf_fct; 21227c478bd9Sstevel@tonic-gate LIST(lmp) = lml; 21237c478bd9Sstevel@tonic-gate PADSTART(lmp) = paddr; 21247c478bd9Sstevel@tonic-gate PADIMLEN(lmp) = padimsize; 21257c478bd9Sstevel@tonic-gate THREADID(lmp) = rt_thr_self(); 21267c478bd9Sstevel@tonic-gate OBJFLTRNDX(lmp) = FLTR_DISABLED; 2127dffec89cSrie SORTVAL(lmp) = -1; 21287c478bd9Sstevel@tonic-gate 21297c478bd9Sstevel@tonic-gate MMAPS(lmp) = mmaps; 21307c478bd9Sstevel@tonic-gate MMAPCNT(lmp) = mmapcnt; 21317c478bd9Sstevel@tonic-gate ASSERT(mmapcnt != 0); 21327c478bd9Sstevel@tonic-gate 21337c478bd9Sstevel@tonic-gate /* 21347c478bd9Sstevel@tonic-gate * If this is a shared object, add the base address to each address. 21357c478bd9Sstevel@tonic-gate * if this is an executable, use address as is. 21367c478bd9Sstevel@tonic-gate */ 21377c478bd9Sstevel@tonic-gate if (ehdr->e_type == ET_EXEC) { 21387c478bd9Sstevel@tonic-gate base = 0; 21397c478bd9Sstevel@tonic-gate FLAGS(lmp) |= FLG_RT_FIXED; 21407c478bd9Sstevel@tonic-gate } else 21417c478bd9Sstevel@tonic-gate base = addr; 21427c478bd9Sstevel@tonic-gate 21437c478bd9Sstevel@tonic-gate /* 21447c478bd9Sstevel@tonic-gate * Fill in rest of the link map entries with information from the file's 21457c478bd9Sstevel@tonic-gate * dynamic structure. 21467c478bd9Sstevel@tonic-gate */ 21477c478bd9Sstevel@tonic-gate if (ld) { 2148*75e7992aSrie uint_t dynndx = 0; 214910a4fa49Srie Xword pltpadsz = 0; 215010a4fa49Srie Rti_desc *rti; 21517c478bd9Sstevel@tonic-gate 21527c478bd9Sstevel@tonic-gate /* CSTYLED */ 2153*75e7992aSrie for ( ; ld->d_tag != DT_NULL; ++ld, dynndx++) { 21547c478bd9Sstevel@tonic-gate switch ((Xword)ld->d_tag) { 21557c478bd9Sstevel@tonic-gate case DT_SYMTAB: 21567c478bd9Sstevel@tonic-gate SYMTAB(lmp) = (void *)(ld->d_un.d_ptr + base); 21577c478bd9Sstevel@tonic-gate break; 21589039eeafSab case DT_SUNW_SYMTAB: 21599039eeafSab SUNWSYMTAB(lmp) = 21609039eeafSab (void *)(ld->d_un.d_ptr + base); 21619039eeafSab break; 21629039eeafSab case DT_SUNW_SYMSZ: 21639039eeafSab SUNWSYMSZ(lmp) = ld->d_un.d_val; 21649039eeafSab break; 21657c478bd9Sstevel@tonic-gate case DT_STRTAB: 21667c478bd9Sstevel@tonic-gate STRTAB(lmp) = (void *)(ld->d_un.d_ptr + base); 21677c478bd9Sstevel@tonic-gate break; 21687c478bd9Sstevel@tonic-gate case DT_SYMENT: 21697c478bd9Sstevel@tonic-gate SYMENT(lmp) = ld->d_un.d_val; 21707c478bd9Sstevel@tonic-gate break; 21717c478bd9Sstevel@tonic-gate case DT_FEATURE_1: 21727c478bd9Sstevel@tonic-gate ld->d_un.d_val |= DTF_1_PARINIT; 21737c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DTF_1_CONFEXP) 21747c478bd9Sstevel@tonic-gate crle = 1; 21757c478bd9Sstevel@tonic-gate break; 21767c478bd9Sstevel@tonic-gate case DT_MOVESZ: 21777c478bd9Sstevel@tonic-gate MOVESZ(lmp) = ld->d_un.d_val; 21787c478bd9Sstevel@tonic-gate FLAGS(lmp) |= FLG_RT_MOVE; 21797c478bd9Sstevel@tonic-gate break; 21807c478bd9Sstevel@tonic-gate case DT_MOVEENT: 21817c478bd9Sstevel@tonic-gate MOVEENT(lmp) = ld->d_un.d_val; 21827c478bd9Sstevel@tonic-gate break; 21837c478bd9Sstevel@tonic-gate case DT_MOVETAB: 21847c478bd9Sstevel@tonic-gate MOVETAB(lmp) = (void *)(ld->d_un.d_ptr + base); 21857c478bd9Sstevel@tonic-gate break; 21867c478bd9Sstevel@tonic-gate case DT_REL: 21877c478bd9Sstevel@tonic-gate case DT_RELA: 21887c478bd9Sstevel@tonic-gate /* 2189*75e7992aSrie * At this time, ld.so. can only handle one 2190*75e7992aSrie * type of relocation per object. 21917c478bd9Sstevel@tonic-gate */ 21927c478bd9Sstevel@tonic-gate REL(lmp) = (void *)(ld->d_un.d_ptr + base); 21937c478bd9Sstevel@tonic-gate break; 21947c478bd9Sstevel@tonic-gate case DT_RELSZ: 21957c478bd9Sstevel@tonic-gate case DT_RELASZ: 21967c478bd9Sstevel@tonic-gate RELSZ(lmp) = ld->d_un.d_val; 21977c478bd9Sstevel@tonic-gate break; 21987c478bd9Sstevel@tonic-gate case DT_RELENT: 21997c478bd9Sstevel@tonic-gate case DT_RELAENT: 22007c478bd9Sstevel@tonic-gate RELENT(lmp) = ld->d_un.d_val; 22017c478bd9Sstevel@tonic-gate break; 22027c478bd9Sstevel@tonic-gate case DT_RELCOUNT: 22037c478bd9Sstevel@tonic-gate case DT_RELACOUNT: 22047c478bd9Sstevel@tonic-gate RELACOUNT(lmp) = (uint_t)ld->d_un.d_val; 22057c478bd9Sstevel@tonic-gate break; 22067c478bd9Sstevel@tonic-gate case DT_TEXTREL: 22077c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_TEXTREL; 22087c478bd9Sstevel@tonic-gate break; 22097c478bd9Sstevel@tonic-gate case DT_HASH: 22107c478bd9Sstevel@tonic-gate HASH(lmp) = (uint_t *)(ld->d_un.d_ptr + base); 22117c478bd9Sstevel@tonic-gate break; 22127c478bd9Sstevel@tonic-gate case DT_PLTGOT: 22137c478bd9Sstevel@tonic-gate PLTGOT(lmp) = (uint_t *)(ld->d_un.d_ptr + base); 22147c478bd9Sstevel@tonic-gate break; 22157c478bd9Sstevel@tonic-gate case DT_PLTRELSZ: 22167c478bd9Sstevel@tonic-gate PLTRELSZ(lmp) = ld->d_un.d_val; 22177c478bd9Sstevel@tonic-gate break; 22187c478bd9Sstevel@tonic-gate case DT_JMPREL: 22197c478bd9Sstevel@tonic-gate JMPREL(lmp) = (void *)(ld->d_un.d_ptr + base); 22207c478bd9Sstevel@tonic-gate break; 22217c478bd9Sstevel@tonic-gate case DT_INIT: 22225b59e4caSab if (ld->d_un.d_ptr != NULL) 22235b59e4caSab INIT(lmp) = 22245b59e4caSab (void (*)())(ld->d_un.d_ptr + base); 22257c478bd9Sstevel@tonic-gate break; 22267c478bd9Sstevel@tonic-gate case DT_FINI: 22275b59e4caSab if (ld->d_un.d_ptr != NULL) 22285b59e4caSab FINI(lmp) = 22295b59e4caSab (void (*)())(ld->d_un.d_ptr + base); 22307c478bd9Sstevel@tonic-gate break; 22317c478bd9Sstevel@tonic-gate case DT_INIT_ARRAY: 22327c478bd9Sstevel@tonic-gate INITARRAY(lmp) = (Addr *)(ld->d_un.d_ptr + 22337c478bd9Sstevel@tonic-gate base); 22347c478bd9Sstevel@tonic-gate break; 22357c478bd9Sstevel@tonic-gate case DT_INIT_ARRAYSZ: 22367c478bd9Sstevel@tonic-gate INITARRAYSZ(lmp) = (uint_t)ld->d_un.d_val; 22377c478bd9Sstevel@tonic-gate break; 22387c478bd9Sstevel@tonic-gate case DT_FINI_ARRAY: 22397c478bd9Sstevel@tonic-gate FINIARRAY(lmp) = (Addr *)(ld->d_un.d_ptr + 22407c478bd9Sstevel@tonic-gate base); 22417c478bd9Sstevel@tonic-gate break; 22427c478bd9Sstevel@tonic-gate case DT_FINI_ARRAYSZ: 22437c478bd9Sstevel@tonic-gate FINIARRAYSZ(lmp) = (uint_t)ld->d_un.d_val; 22447c478bd9Sstevel@tonic-gate break; 22457c478bd9Sstevel@tonic-gate case DT_PREINIT_ARRAY: 22467c478bd9Sstevel@tonic-gate PREINITARRAY(lmp) = (Addr *)(ld->d_un.d_ptr + 22477c478bd9Sstevel@tonic-gate base); 22487c478bd9Sstevel@tonic-gate break; 22497c478bd9Sstevel@tonic-gate case DT_PREINIT_ARRAYSZ: 22507c478bd9Sstevel@tonic-gate PREINITARRAYSZ(lmp) = (uint_t)ld->d_un.d_val; 22517c478bd9Sstevel@tonic-gate break; 22527c478bd9Sstevel@tonic-gate case DT_RPATH: 22537c478bd9Sstevel@tonic-gate case DT_RUNPATH: 22547c478bd9Sstevel@tonic-gate rpath = ld->d_un.d_val; 22557c478bd9Sstevel@tonic-gate break; 22567c478bd9Sstevel@tonic-gate case DT_FILTER: 22577c478bd9Sstevel@tonic-gate fltr = ld->d_un.d_val; 2258*75e7992aSrie OBJFLTRNDX(lmp) = dynndx; 22597c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_OBJSFLTR; 22607c478bd9Sstevel@tonic-gate break; 22617c478bd9Sstevel@tonic-gate case DT_AUXILIARY: 22627c478bd9Sstevel@tonic-gate if (!(rtld_flags & RT_FL_NOAUXFLTR)) { 22637c478bd9Sstevel@tonic-gate fltr = ld->d_un.d_val; 2264*75e7992aSrie OBJFLTRNDX(lmp) = dynndx; 22657c478bd9Sstevel@tonic-gate } 22667c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_OBJAFLTR; 22677c478bd9Sstevel@tonic-gate break; 22687c478bd9Sstevel@tonic-gate case DT_SUNW_FILTER: 22697c478bd9Sstevel@tonic-gate SYMSFLTRCNT(lmp)++; 22707c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_SYMSFLTR; 22717c478bd9Sstevel@tonic-gate break; 22727c478bd9Sstevel@tonic-gate case DT_SUNW_AUXILIARY: 22737c478bd9Sstevel@tonic-gate if (!(rtld_flags & RT_FL_NOAUXFLTR)) { 22747c478bd9Sstevel@tonic-gate SYMAFLTRCNT(lmp)++; 22757c478bd9Sstevel@tonic-gate } 22767c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_SYMAFLTR; 22777c478bd9Sstevel@tonic-gate break; 22787c478bd9Sstevel@tonic-gate case DT_DEPAUDIT: 22797c478bd9Sstevel@tonic-gate if (!(rtld_flags & RT_FL_NOAUDIT)) 22807c478bd9Sstevel@tonic-gate audit = ld->d_un.d_val; 22817c478bd9Sstevel@tonic-gate break; 22827c478bd9Sstevel@tonic-gate case DT_CONFIG: 22837c478bd9Sstevel@tonic-gate cfile = ld->d_un.d_val; 22847c478bd9Sstevel@tonic-gate break; 22857c478bd9Sstevel@tonic-gate case DT_DEBUG: 22867c478bd9Sstevel@tonic-gate /* 22877c478bd9Sstevel@tonic-gate * DT_DEBUG entries are only created in 22887c478bd9Sstevel@tonic-gate * dynamic objects that require an interpretor 22897c478bd9Sstevel@tonic-gate * (ie. all dynamic executables and some shared 22907c478bd9Sstevel@tonic-gate * objects), and provide for a hand-shake with 22917c478bd9Sstevel@tonic-gate * debuggers. This entry is initialized to 22927c478bd9Sstevel@tonic-gate * zero by the link-editor. If a debugger has 22937c478bd9Sstevel@tonic-gate * us and updated this entry set the debugger 22947c478bd9Sstevel@tonic-gate * flag, and finish initializing the debugging 22957c478bd9Sstevel@tonic-gate * structure (see setup() also). Switch off any 22967c478bd9Sstevel@tonic-gate * configuration object use as most debuggers 22977c478bd9Sstevel@tonic-gate * can't handle fixed dynamic executables as 22987c478bd9Sstevel@tonic-gate * dependencies, and we can't handle requests 22997c478bd9Sstevel@tonic-gate * like object padding for alternative objects. 23007c478bd9Sstevel@tonic-gate */ 23017c478bd9Sstevel@tonic-gate if (ld->d_un.d_ptr) 23027c478bd9Sstevel@tonic-gate rtld_flags |= 23037c478bd9Sstevel@tonic-gate (RT_FL_DEBUGGER | RT_FL_NOOBJALT); 23047c478bd9Sstevel@tonic-gate ld->d_un.d_ptr = (Addr)&r_debug; 23057c478bd9Sstevel@tonic-gate break; 23067c478bd9Sstevel@tonic-gate case DT_VERNEED: 23077c478bd9Sstevel@tonic-gate VERNEED(lmp) = (Verneed *)(ld->d_un.d_ptr + 23087c478bd9Sstevel@tonic-gate base); 23097c478bd9Sstevel@tonic-gate break; 23107c478bd9Sstevel@tonic-gate case DT_VERNEEDNUM: 23117c478bd9Sstevel@tonic-gate /* LINTED */ 23127c478bd9Sstevel@tonic-gate VERNEEDNUM(lmp) = (int)ld->d_un.d_val; 23137c478bd9Sstevel@tonic-gate break; 23147c478bd9Sstevel@tonic-gate case DT_VERDEF: 23157c478bd9Sstevel@tonic-gate VERDEF(lmp) = (Verdef *)(ld->d_un.d_ptr + base); 23167c478bd9Sstevel@tonic-gate break; 23177c478bd9Sstevel@tonic-gate case DT_VERDEFNUM: 23187c478bd9Sstevel@tonic-gate /* LINTED */ 23197c478bd9Sstevel@tonic-gate VERDEFNUM(lmp) = (int)ld->d_un.d_val; 23207c478bd9Sstevel@tonic-gate break; 23213b41b08bSab case DT_VERSYM: 2322d840867fSab /* 2323d840867fSab * The Solaris ld does not produce DT_VERSYM, 2324d840867fSab * but the GNU ld does, in order to support 2325d840867fSab * their style of versioning, which differs 2326d840867fSab * from ours in some ways, while using the 2327d840867fSab * same data structures. The presence of 2328d840867fSab * DT_VERSYM therefore means that GNU 2329d840867fSab * versioning rules apply to the given file. 2330d840867fSab * If DT_VERSYM is not present, then Solaris 2331d840867fSab * versioning rules apply. 2332d840867fSab */ 23333b41b08bSab VERSYM(lmp) = (Versym *)(ld->d_un.d_ptr + base); 23343b41b08bSab break; 23357c478bd9Sstevel@tonic-gate case DT_BIND_NOW: 2336dffec89cSrie if ((ld->d_un.d_val & DF_BIND_NOW) && 2337dffec89cSrie ((rtld_flags2 & RT_FL2_BINDLAZY) == 0)) { 23387c478bd9Sstevel@tonic-gate MODE(lmp) |= RTLD_NOW; 23397c478bd9Sstevel@tonic-gate MODE(lmp) &= ~RTLD_LAZY; 23407c478bd9Sstevel@tonic-gate } 23417c478bd9Sstevel@tonic-gate break; 23427c478bd9Sstevel@tonic-gate case DT_FLAGS: 23437c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_SYMBOLIC) 23447c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_SYMBOLIC; 23457c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_TEXTREL) 23467c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_TEXTREL; 2347dffec89cSrie if ((ld->d_un.d_val & DF_BIND_NOW) && 2348dffec89cSrie ((rtld_flags2 & RT_FL2_BINDLAZY) == 0)) { 23497c478bd9Sstevel@tonic-gate MODE(lmp) |= RTLD_NOW; 23507c478bd9Sstevel@tonic-gate MODE(lmp) &= ~RTLD_LAZY; 23517c478bd9Sstevel@tonic-gate } 2352d326b23bSrie /* 2353d326b23bSrie * Capture any static TLS use, and enforce that 2354d326b23bSrie * this object be non-deletable. 2355d326b23bSrie */ 2356d326b23bSrie if (ld->d_un.d_val & DF_STATIC_TLS) { 2357d326b23bSrie FLAGS1(lmp) |= FL1_RT_TLSSTAT; 2358d326b23bSrie MODE(lmp) |= RTLD_NODELETE; 2359d326b23bSrie } 23607c478bd9Sstevel@tonic-gate break; 23617c478bd9Sstevel@tonic-gate case DT_FLAGS_1: 23627c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_DISPRELPND) 23637c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_DISPREL; 23647c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_GROUP) 23657c478bd9Sstevel@tonic-gate FLAGS(lmp) |= 23667c478bd9Sstevel@tonic-gate (FLG_RT_SETGROUP | FLG_RT_HANDLE); 2367dffec89cSrie if ((ld->d_un.d_val & DF_1_NOW) && 2368dffec89cSrie ((rtld_flags2 & RT_FL2_BINDLAZY) == 0)) { 23697c478bd9Sstevel@tonic-gate MODE(lmp) |= RTLD_NOW; 23707c478bd9Sstevel@tonic-gate MODE(lmp) &= ~RTLD_LAZY; 23717c478bd9Sstevel@tonic-gate } 23727c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_NODELETE) 23737c478bd9Sstevel@tonic-gate MODE(lmp) |= RTLD_NODELETE; 23747c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_INITFIRST) 23757c478bd9Sstevel@tonic-gate FLAGS(lmp) |= FLG_RT_INITFRST; 23767c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_NOOPEN) 23777c478bd9Sstevel@tonic-gate FLAGS(lmp) |= FLG_RT_NOOPEN; 23787c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_LOADFLTR) 23797c478bd9Sstevel@tonic-gate FLAGS(lmp) |= FLG_RT_LOADFLTR; 23807c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_NODUMP) 23817c478bd9Sstevel@tonic-gate FLAGS(lmp) |= FLG_RT_NODUMP; 23827c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_CONFALT) 23837c478bd9Sstevel@tonic-gate crle = 1; 23847c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_DIRECT) 23859a411307Srie FLAGS1(lmp) |= FL1_RT_DIRECT; 23867c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_NODEFLIB) 23877c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_NODEFLIB; 23887c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_ENDFILTEE) 23897c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_ENDFILTE; 23907c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_TRANS) 23917c478bd9Sstevel@tonic-gate FLAGS(lmp) |= FLG_RT_TRANS; 23927c478bd9Sstevel@tonic-gate #ifndef EXPAND_RELATIVE 23937c478bd9Sstevel@tonic-gate if (ld->d_un.d_val & DF_1_ORIGIN) 23947c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_RELATIVE; 23957c478bd9Sstevel@tonic-gate #endif 23967247f888Srie /* 23977247f888Srie * Global auditing is only meaningful when 23987247f888Srie * specified by the initiating object of the 23997247f888Srie * process - typically the dynamic executable. 24007247f888Srie * If this is the initiaiting object, its link- 24017247f888Srie * map will not yet have been added to the 24027247f888Srie * link-map list, and consequently the link-map 24037247f888Srie * list is empty. (see setup()). 24047247f888Srie */ 24057247f888Srie if (ld->d_un.d_val & DF_1_GLOBAUDIT) { 24067247f888Srie if (lml_main.lm_head == 0) 24077247f888Srie FLAGS1(lmp) |= FL1_RT_GLOBAUD; 24087247f888Srie else 24097247f888Srie DBG_CALL(Dbg_audit_ignore(lmp)); 24107247f888Srie } 24117247f888Srie 24127c478bd9Sstevel@tonic-gate /* 24137c478bd9Sstevel@tonic-gate * If this object identifies itself as an 24147c478bd9Sstevel@tonic-gate * interposer, but relocation processing has 24157c478bd9Sstevel@tonic-gate * already started, then demote it. It's too 24167c478bd9Sstevel@tonic-gate * late to guarantee complete interposition. 24177c478bd9Sstevel@tonic-gate */ 2418a953e2b1Srie /* BEGIN CSTYLED */ 24199a411307Srie if (ld->d_un.d_val & 24209a411307Srie (DF_1_INTERPOSE | DF_1_SYMINTPOSE)) { 24219a411307Srie if (lml->lm_flags & LML_FLG_STARTREL) { 24225aefb655Srie DBG_CALL(Dbg_util_intoolate(lmp)); 24237c478bd9Sstevel@tonic-gate if (lml->lm_flags & LML_FLG_TRC_ENABLE) 24247c478bd9Sstevel@tonic-gate (void) printf( 24257c478bd9Sstevel@tonic-gate MSG_INTL(MSG_LDD_REL_ERR2), 24267c478bd9Sstevel@tonic-gate NAME(lmp)); 24279a411307Srie } else if (ld->d_un.d_val & DF_1_INTERPOSE) 24289a411307Srie FLAGS(lmp) |= FLG_RT_OBJINTPO; 24299a411307Srie else 24309a411307Srie FLAGS(lmp) |= FLG_RT_SYMINTPO; 24317c478bd9Sstevel@tonic-gate } 2432a953e2b1Srie /* END CSTYLED */ 24337c478bd9Sstevel@tonic-gate break; 24347c478bd9Sstevel@tonic-gate case DT_SYMINFO: 24357c478bd9Sstevel@tonic-gate SYMINFO(lmp) = (Syminfo *)(ld->d_un.d_ptr + 24367c478bd9Sstevel@tonic-gate base); 24377c478bd9Sstevel@tonic-gate break; 24387c478bd9Sstevel@tonic-gate case DT_SYMINENT: 24397c478bd9Sstevel@tonic-gate SYMINENT(lmp) = ld->d_un.d_val; 24407c478bd9Sstevel@tonic-gate break; 24417c478bd9Sstevel@tonic-gate case DT_PLTPAD: 24427c478bd9Sstevel@tonic-gate PLTPAD(lmp) = (void *)(ld->d_un.d_ptr + base); 24437c478bd9Sstevel@tonic-gate break; 24447c478bd9Sstevel@tonic-gate case DT_PLTPADSZ: 24457c478bd9Sstevel@tonic-gate pltpadsz = ld->d_un.d_val; 24467c478bd9Sstevel@tonic-gate break; 24477c478bd9Sstevel@tonic-gate case DT_SUNW_RTLDINF: 24487c478bd9Sstevel@tonic-gate /* 244910a4fa49Srie * Maintain a list of RTLDINFO structures. 245010a4fa49Srie * Typically, libc is the only supplier, and 245110a4fa49Srie * only one structure is provided. However, 245210a4fa49Srie * multiple suppliers and multiple structures 245310a4fa49Srie * are supported. For example, one structure 245410a4fa49Srie * may provide thread_init, and another 245510a4fa49Srie * structure may provide atexit reservations. 24567c478bd9Sstevel@tonic-gate */ 245710a4fa49Srie if ((rti = alist_append(&lml->lm_rti, 0, 245810a4fa49Srie sizeof (Rti_desc), AL_CNT_RTLDINFO)) == 0) { 24597c478bd9Sstevel@tonic-gate remove_so(0, lmp); 24607c478bd9Sstevel@tonic-gate return (0); 24617c478bd9Sstevel@tonic-gate } 246210a4fa49Srie rti->rti_lmp = lmp; 246310a4fa49Srie rti->rti_info = (void *)(ld->d_un.d_ptr + base); 24647c478bd9Sstevel@tonic-gate break; 2465d579eb63Sab case DT_SUNW_SORTENT: 2466d579eb63Sab SUNWSORTENT(lmp) = ld->d_un.d_val; 2467d579eb63Sab break; 2468d579eb63Sab case DT_SUNW_SYMSORT: 2469d579eb63Sab SUNWSYMSORT(lmp) = 2470d579eb63Sab (void *)(ld->d_un.d_ptr + base); 2471d579eb63Sab break; 2472d579eb63Sab case DT_SUNW_SYMSORTSZ: 2473d579eb63Sab SUNWSYMSORTSZ(lmp) = ld->d_un.d_val; 2474d579eb63Sab break; 24757c478bd9Sstevel@tonic-gate case DT_DEPRECATED_SPARC_REGISTER: 24767c478bd9Sstevel@tonic-gate case M_DT_REGISTER: 24777c478bd9Sstevel@tonic-gate FLAGS(lmp) |= FLG_RT_REGSYMS; 24787c478bd9Sstevel@tonic-gate break; 24797c478bd9Sstevel@tonic-gate case M_DT_PLTRESERVE: 24807c478bd9Sstevel@tonic-gate PLTRESERVE(lmp) = (void *)(ld->d_un.d_ptr + 24817c478bd9Sstevel@tonic-gate base); 24827c478bd9Sstevel@tonic-gate break; 24837c478bd9Sstevel@tonic-gate } 24847c478bd9Sstevel@tonic-gate } 24857c478bd9Sstevel@tonic-gate 24867c478bd9Sstevel@tonic-gate if (PLTPAD(lmp)) { 24877c478bd9Sstevel@tonic-gate if (pltpadsz == (Xword)0) 24887c478bd9Sstevel@tonic-gate PLTPAD(lmp) = 0; 24897c478bd9Sstevel@tonic-gate else 24907c478bd9Sstevel@tonic-gate PLTPADEND(lmp) = (void *)((Addr)PLTPAD(lmp) + 24917c478bd9Sstevel@tonic-gate pltpadsz); 24927c478bd9Sstevel@tonic-gate } 24937c478bd9Sstevel@tonic-gate 24947c478bd9Sstevel@tonic-gate /* 2495*75e7992aSrie * Allocate a Dynamic Info structure. 24967c478bd9Sstevel@tonic-gate */ 2497*75e7992aSrie if ((DYNINFO(lmp) = calloc((size_t)dynndx, 24987c478bd9Sstevel@tonic-gate sizeof (Dyninfo))) == 0) { 24997c478bd9Sstevel@tonic-gate remove_so(0, lmp); 25007c478bd9Sstevel@tonic-gate return (0); 25017c478bd9Sstevel@tonic-gate } 2502*75e7992aSrie DYNINFOCNT(lmp) = dynndx; 25037c478bd9Sstevel@tonic-gate } 25047c478bd9Sstevel@tonic-gate 25059039eeafSab /* 25069039eeafSab * A dynsym contains only global functions. We want to have 25079039eeafSab * a version of it that also includes local functions, so that 25089039eeafSab * dladdr() will be able to report names for local functions 25099039eeafSab * when used to generate a stack trace for a stripped file. 25109039eeafSab * This version of the dynsym is provided via DT_SUNW_SYMTAB. 25119039eeafSab * 25129039eeafSab * In producing DT_SUNW_SYMTAB, ld uses a non-obvious trick 25139039eeafSab * in order to avoid having to have two copies of the global 25149039eeafSab * symbols held in DT_SYMTAB: The local symbols are placed in 25159039eeafSab * a separate section than the globals in the dynsym, but the 25169039eeafSab * linker conspires to put the data for these two sections adjacent 25179039eeafSab * to each other. DT_SUNW_SYMTAB points at the top of the local 25189039eeafSab * symbols, and DT_SUNW_SYMSZ is the combined length of both tables. 25199039eeafSab * 25209039eeafSab * If the two sections are not adjacent, then something went wrong 25219039eeafSab * at link time. We use ASSERT to kill the process if this is 25229039eeafSab * a debug build. In a production build, we will silently ignore 25239039eeafSab * the presence of the .ldynsym and proceed. We can detect this 25249039eeafSab * situation by checking to see that DT_SYMTAB lies in 25259039eeafSab * the range given by DT_SUNW_SYMTAB/DT_SUNW_SYMSZ. 25269039eeafSab */ 25279039eeafSab if ((SUNWSYMTAB(lmp) != NULL) && 25289039eeafSab (((char *)SYMTAB(lmp) <= (char *)SUNWSYMTAB(lmp)) || 25299039eeafSab (((char *)SYMTAB(lmp) >= 25309039eeafSab (SUNWSYMSZ(lmp) + (char *)SUNWSYMTAB(lmp)))))) { 25319039eeafSab ASSERT(0); 25329039eeafSab SUNWSYMTAB(lmp) = NULL; 25339039eeafSab SUNWSYMSZ(lmp) = 0; 25349039eeafSab } 25359039eeafSab 25367c478bd9Sstevel@tonic-gate /* 25377c478bd9Sstevel@tonic-gate * If configuration file use hasn't been disabled, and a configuration 25387c478bd9Sstevel@tonic-gate * file hasn't already been set via an environment variable, see if any 25397c478bd9Sstevel@tonic-gate * application specific configuration file is specified. An LD_CONFIG 25407c478bd9Sstevel@tonic-gate * setting is used first, but if this image was generated via crle(1) 25417c478bd9Sstevel@tonic-gate * then a default configuration file is a fall-back. 25427c478bd9Sstevel@tonic-gate */ 25437c478bd9Sstevel@tonic-gate if ((!(rtld_flags & RT_FL_NOCFG)) && (config->c_name == 0)) { 25447c478bd9Sstevel@tonic-gate if (cfile) 25457c478bd9Sstevel@tonic-gate config->c_name = (const char *)(cfile + 25467c478bd9Sstevel@tonic-gate (char *)STRTAB(lmp)); 25477c478bd9Sstevel@tonic-gate else if (crle) { 25487c478bd9Sstevel@tonic-gate rtld_flags |= RT_FL_CONFAPP; 25497c478bd9Sstevel@tonic-gate #ifndef EXPAND_RELATIVE 25507c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_RELATIVE; 25517c478bd9Sstevel@tonic-gate #endif 25527c478bd9Sstevel@tonic-gate } 25537c478bd9Sstevel@tonic-gate } 25547c478bd9Sstevel@tonic-gate 25557c478bd9Sstevel@tonic-gate if (rpath) 25567c478bd9Sstevel@tonic-gate RPATH(lmp) = (char *)(rpath + (char *)STRTAB(lmp)); 25577c478bd9Sstevel@tonic-gate if (fltr) { 25587c478bd9Sstevel@tonic-gate /* 25597c478bd9Sstevel@tonic-gate * If this object is a global filter, duplicate the filtee 25607c478bd9Sstevel@tonic-gate * string name(s) so that REFNAME() is available in core files. 25617c478bd9Sstevel@tonic-gate * This cludge was useful for debuggers at one point, but only 25627c478bd9Sstevel@tonic-gate * when the filtee name was an individual full path. 25637c478bd9Sstevel@tonic-gate */ 25647c478bd9Sstevel@tonic-gate if ((REFNAME(lmp) = strdup(fltr + (char *)STRTAB(lmp))) == 0) { 25657c478bd9Sstevel@tonic-gate remove_so(0, lmp); 25667c478bd9Sstevel@tonic-gate return (0); 25677c478bd9Sstevel@tonic-gate } 25687c478bd9Sstevel@tonic-gate } 25697c478bd9Sstevel@tonic-gate 25707c478bd9Sstevel@tonic-gate if (rtld_flags & RT_FL_RELATIVE) 25717c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= FL1_RT_RELATIVE; 25727c478bd9Sstevel@tonic-gate 25737c478bd9Sstevel@tonic-gate /* 25747c478bd9Sstevel@tonic-gate * For Intel ABI compatibility. It's possible that a JMPREL can be 25757c478bd9Sstevel@tonic-gate * specified without any other relocations (e.g. a dynamic executable 25767c478bd9Sstevel@tonic-gate * normally only contains .plt relocations). If this is the case then 25777c478bd9Sstevel@tonic-gate * no REL, RELSZ or RELENT will have been created. For us to be able 25787c478bd9Sstevel@tonic-gate * to traverse the .plt relocations under LD_BIND_NOW we need to know 25797c478bd9Sstevel@tonic-gate * the RELENT for these relocations. Refer to elf_reloc() for more 25807c478bd9Sstevel@tonic-gate * details. 25817c478bd9Sstevel@tonic-gate */ 25827c478bd9Sstevel@tonic-gate if (!RELENT(lmp) && JMPREL(lmp)) 25837c478bd9Sstevel@tonic-gate RELENT(lmp) = sizeof (Rel); 25847c478bd9Sstevel@tonic-gate 25857c478bd9Sstevel@tonic-gate /* 25867c478bd9Sstevel@tonic-gate * Establish any per-object auditing. If we're establishing `main's 25877c478bd9Sstevel@tonic-gate * link-map its too early to go searching for audit objects so just 25887c478bd9Sstevel@tonic-gate * hold the object name for later (see setup()). 25897c478bd9Sstevel@tonic-gate */ 25907c478bd9Sstevel@tonic-gate if (audit) { 25917c478bd9Sstevel@tonic-gate char *cp = audit + (char *)STRTAB(lmp); 25927c478bd9Sstevel@tonic-gate 25937c478bd9Sstevel@tonic-gate if (*cp) { 25947c478bd9Sstevel@tonic-gate if (((AUDITORS(lmp) = 25957c478bd9Sstevel@tonic-gate calloc(1, sizeof (Audit_desc))) == 0) || 25967c478bd9Sstevel@tonic-gate ((AUDITORS(lmp)->ad_name = strdup(cp)) == 0)) { 25977c478bd9Sstevel@tonic-gate remove_so(0, lmp); 25987c478bd9Sstevel@tonic-gate return (0); 25997c478bd9Sstevel@tonic-gate } 260041072f3cSrie if (lml_main.lm_head) { 260156d7adc6Srie if (audit_setup(lmp, AUDITORS(lmp), 0) == 0) { 26027c478bd9Sstevel@tonic-gate remove_so(0, lmp); 26037c478bd9Sstevel@tonic-gate return (0); 26047c478bd9Sstevel@tonic-gate } 26057c478bd9Sstevel@tonic-gate FLAGS1(lmp) |= AUDITORS(lmp)->ad_flags; 26067c478bd9Sstevel@tonic-gate lml->lm_flags |= LML_FLG_LOCAUDIT; 26077c478bd9Sstevel@tonic-gate } 26087c478bd9Sstevel@tonic-gate } 26097c478bd9Sstevel@tonic-gate } 26107c478bd9Sstevel@tonic-gate 26117c478bd9Sstevel@tonic-gate if ((CONDVAR(lmp) = rt_cond_create()) == 0) { 26127c478bd9Sstevel@tonic-gate remove_so(0, lmp); 26137c478bd9Sstevel@tonic-gate return (0); 26147c478bd9Sstevel@tonic-gate } 26157c478bd9Sstevel@tonic-gate if (oname && ((append_alias(lmp, oname, 0)) == 0)) { 26167c478bd9Sstevel@tonic-gate remove_so(0, lmp); 26177c478bd9Sstevel@tonic-gate return (0); 26187c478bd9Sstevel@tonic-gate } 26197c478bd9Sstevel@tonic-gate 26207c478bd9Sstevel@tonic-gate /* 26217c478bd9Sstevel@tonic-gate * Add the mapped object to the end of the link map list. 26227c478bd9Sstevel@tonic-gate */ 26237c478bd9Sstevel@tonic-gate lm_append(lml, lmco, lmp); 26247c478bd9Sstevel@tonic-gate return (lmp); 26257c478bd9Sstevel@tonic-gate } 26267c478bd9Sstevel@tonic-gate 26277c478bd9Sstevel@tonic-gate /* 26287c478bd9Sstevel@tonic-gate * Assign hardware/software capabilities. 26297c478bd9Sstevel@tonic-gate */ 26307c478bd9Sstevel@tonic-gate void 26317c478bd9Sstevel@tonic-gate cap_assign(Cap *cap, Rt_map *lmp) 26327c478bd9Sstevel@tonic-gate { 26337c478bd9Sstevel@tonic-gate while (cap->c_tag != CA_SUNW_NULL) { 26347c478bd9Sstevel@tonic-gate switch (cap->c_tag) { 26357c478bd9Sstevel@tonic-gate case CA_SUNW_HW_1: 26367c478bd9Sstevel@tonic-gate HWCAP(lmp) = cap->c_un.c_val; 26377c478bd9Sstevel@tonic-gate break; 26387c478bd9Sstevel@tonic-gate case CA_SUNW_SF_1: 26397c478bd9Sstevel@tonic-gate SFCAP(lmp) = cap->c_un.c_val; 26407c478bd9Sstevel@tonic-gate } 26417c478bd9Sstevel@tonic-gate cap++; 26427c478bd9Sstevel@tonic-gate } 26437c478bd9Sstevel@tonic-gate } 26447c478bd9Sstevel@tonic-gate 26457c478bd9Sstevel@tonic-gate /* 26467c478bd9Sstevel@tonic-gate * Map in an ELF object. 26477c478bd9Sstevel@tonic-gate * Takes an open file descriptor for the object to map and its pathname; returns 26487c478bd9Sstevel@tonic-gate * a pointer to a Rt_map structure for this object, or 0 on error. 26497c478bd9Sstevel@tonic-gate */ 26507c478bd9Sstevel@tonic-gate static Rt_map * 26517c478bd9Sstevel@tonic-gate elf_map_so(Lm_list *lml, Aliste lmco, const char *pname, const char *oname, 26527c478bd9Sstevel@tonic-gate int fd) 26537c478bd9Sstevel@tonic-gate { 26547c478bd9Sstevel@tonic-gate int i; /* general temporary */ 26557c478bd9Sstevel@tonic-gate Off memsize = 0; /* total memory size of pathname */ 26567c478bd9Sstevel@tonic-gate Off mentry; /* entry point */ 26577c478bd9Sstevel@tonic-gate Ehdr *ehdr; /* ELF header of ld.so */ 26587c478bd9Sstevel@tonic-gate Phdr *phdr; /* first Phdr in file */ 26597c478bd9Sstevel@tonic-gate Phdr *phdr0; /* Saved first Phdr in file */ 26607c478bd9Sstevel@tonic-gate Phdr *pptr; /* working Phdr */ 26617c478bd9Sstevel@tonic-gate Phdr *fph = 0; /* first loadable Phdr */ 26627c478bd9Sstevel@tonic-gate Phdr *lph; /* last loadable Phdr */ 26637c478bd9Sstevel@tonic-gate Phdr *lfph = 0; /* last loadable (filesz != 0) Phdr */ 26647c478bd9Sstevel@tonic-gate Phdr *lmph = 0; /* last loadable (memsz != 0) Phdr */ 26657c478bd9Sstevel@tonic-gate Phdr *swph = 0; /* program header for SUNWBSS */ 26667c478bd9Sstevel@tonic-gate Phdr *tlph = 0; /* program header for PT_TLS */ 26677c478bd9Sstevel@tonic-gate Phdr *unwindph = 0; /* program header for PT_SUNW_UNWIND */ 26687c478bd9Sstevel@tonic-gate Cap *cap = 0; /* program header for SUNWCAP */ 26697c478bd9Sstevel@tonic-gate Dyn *mld = 0; /* DYNAMIC structure for pathname */ 26707c478bd9Sstevel@tonic-gate size_t size; /* size of elf and program headers */ 26717c478bd9Sstevel@tonic-gate caddr_t faddr = 0; /* mapping address of pathname */ 26727c478bd9Sstevel@tonic-gate Rt_map *lmp; /* link map created */ 26737c478bd9Sstevel@tonic-gate caddr_t paddr; /* start of padded image */ 26747c478bd9Sstevel@tonic-gate Off plen; /* size of image including padding */ 26757c478bd9Sstevel@tonic-gate Half etype; 26767c478bd9Sstevel@tonic-gate int fixed; 26777c478bd9Sstevel@tonic-gate Mmap *mmaps; 26787c478bd9Sstevel@tonic-gate uint_t mmapcnt = 0; 26797c478bd9Sstevel@tonic-gate Xword align = 0; 26807c478bd9Sstevel@tonic-gate 26817c478bd9Sstevel@tonic-gate /* LINTED */ 26827c478bd9Sstevel@tonic-gate ehdr = (Ehdr *)fmap->fm_maddr; 26837c478bd9Sstevel@tonic-gate 26847c478bd9Sstevel@tonic-gate /* 26857c478bd9Sstevel@tonic-gate * If this a relocatable object then special processing is required. 26867c478bd9Sstevel@tonic-gate */ 26877c478bd9Sstevel@tonic-gate if ((etype = ehdr->e_type) == ET_REL) 268841072f3cSrie return (elf_obj_file(lml, lmco, pname, fd)); 26897c478bd9Sstevel@tonic-gate 26907c478bd9Sstevel@tonic-gate /* 26917c478bd9Sstevel@tonic-gate * If this isn't a dynamic executable or shared object we can't process 26927c478bd9Sstevel@tonic-gate * it. If this is a dynamic executable then all addresses are fixed. 26937c478bd9Sstevel@tonic-gate */ 2694de777a60Sab if (etype == ET_EXEC) { 26957c478bd9Sstevel@tonic-gate fixed = 1; 2696de777a60Sab } else if (etype == ET_DYN) { 26977c478bd9Sstevel@tonic-gate fixed = 0; 2698de777a60Sab } else { 2699de777a60Sab Conv_inv_buf_t inv_buf; 2700de777a60Sab 27015aefb655Srie eprintf(lml, ERR_ELF, MSG_INTL(MSG_GEN_BADTYPE), pname, 2702de777a60Sab conv_ehdr_type(etype, 0, &inv_buf)); 27037c478bd9Sstevel@tonic-gate return (0); 27047c478bd9Sstevel@tonic-gate } 27057c478bd9Sstevel@tonic-gate 27067c478bd9Sstevel@tonic-gate /* 27077c478bd9Sstevel@tonic-gate * If our original mapped page was not large enough to hold all the 27087c478bd9Sstevel@tonic-gate * program headers remap them. 27097c478bd9Sstevel@tonic-gate */ 27107c478bd9Sstevel@tonic-gate size = (size_t)((char *)ehdr->e_phoff + 2711a953e2b1Srie (ehdr->e_phnum * ehdr->e_phentsize)); 27127c478bd9Sstevel@tonic-gate if (size > fmap->fm_fsize) { 27135aefb655Srie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_GEN_CORTRUNC), pname); 27147c478bd9Sstevel@tonic-gate return (0); 27157c478bd9Sstevel@tonic-gate } 27167c478bd9Sstevel@tonic-gate if (size > fmap->fm_msize) { 27177c478bd9Sstevel@tonic-gate fmap_setup(); 27187c478bd9Sstevel@tonic-gate if ((fmap->fm_maddr = mmap(fmap->fm_maddr, size, PROT_READ, 27197c478bd9Sstevel@tonic-gate fmap->fm_mflags, fd, 0)) == MAP_FAILED) { 27207c478bd9Sstevel@tonic-gate int err = errno; 27215aefb655Srie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_SYS_MMAP), pname, 27227c478bd9Sstevel@tonic-gate strerror(err)); 27237c478bd9Sstevel@tonic-gate return (0); 27247c478bd9Sstevel@tonic-gate } 27257c478bd9Sstevel@tonic-gate fmap->fm_msize = size; 27267c478bd9Sstevel@tonic-gate /* LINTED */ 27277c478bd9Sstevel@tonic-gate ehdr = (Ehdr *)fmap->fm_maddr; 27287c478bd9Sstevel@tonic-gate } 27297c478bd9Sstevel@tonic-gate /* LINTED */ 27307c478bd9Sstevel@tonic-gate phdr0 = phdr = (Phdr *)((char *)ehdr + ehdr->e_ehsize); 27317c478bd9Sstevel@tonic-gate 27327c478bd9Sstevel@tonic-gate /* 27337c478bd9Sstevel@tonic-gate * Get entry point. 27347c478bd9Sstevel@tonic-gate */ 27357c478bd9Sstevel@tonic-gate mentry = ehdr->e_entry; 27367c478bd9Sstevel@tonic-gate 27377c478bd9Sstevel@tonic-gate /* 27387c478bd9Sstevel@tonic-gate * Point at program headers and perform some basic validation. 27397c478bd9Sstevel@tonic-gate */ 27407c478bd9Sstevel@tonic-gate for (i = 0, pptr = phdr; i < (int)ehdr->e_phnum; i++, 27417c478bd9Sstevel@tonic-gate pptr = (Phdr *)((Off)pptr + ehdr->e_phentsize)) { 27427c478bd9Sstevel@tonic-gate if ((pptr->p_type == PT_LOAD) || 27437c478bd9Sstevel@tonic-gate (pptr->p_type == PT_SUNWBSS)) { 27447c478bd9Sstevel@tonic-gate 27457c478bd9Sstevel@tonic-gate if (fph == 0) { 27467c478bd9Sstevel@tonic-gate fph = pptr; 27477c478bd9Sstevel@tonic-gate /* LINTED argument lph is initialized in first pass */ 27487c478bd9Sstevel@tonic-gate } else if (pptr->p_vaddr <= lph->p_vaddr) { 27495aefb655Srie eprintf(lml, ERR_ELF, 27505aefb655Srie MSG_INTL(MSG_GEN_INVPRGHDR), pname); 27517c478bd9Sstevel@tonic-gate return (0); 27527c478bd9Sstevel@tonic-gate } 27537c478bd9Sstevel@tonic-gate 27547c478bd9Sstevel@tonic-gate lph = pptr; 27557c478bd9Sstevel@tonic-gate 27567c478bd9Sstevel@tonic-gate if (pptr->p_memsz) 27577c478bd9Sstevel@tonic-gate lmph = pptr; 27587c478bd9Sstevel@tonic-gate if (pptr->p_filesz) 27597c478bd9Sstevel@tonic-gate lfph = pptr; 27607c478bd9Sstevel@tonic-gate if (pptr->p_type == PT_SUNWBSS) 27617c478bd9Sstevel@tonic-gate swph = pptr; 27627c478bd9Sstevel@tonic-gate if (pptr->p_align > align) 27637c478bd9Sstevel@tonic-gate align = pptr->p_align; 27647c478bd9Sstevel@tonic-gate 276510a4fa49Srie } else if (pptr->p_type == PT_DYNAMIC) { 27667c478bd9Sstevel@tonic-gate mld = (Dyn *)(pptr->p_vaddr); 276710a4fa49Srie } else if ((pptr->p_type == PT_TLS) && pptr->p_memsz) { 27687c478bd9Sstevel@tonic-gate tlph = pptr; 276910a4fa49Srie } else if (pptr->p_type == PT_SUNWCAP) { 27707c478bd9Sstevel@tonic-gate cap = (Cap *)(pptr->p_vaddr); 277110a4fa49Srie } else if (pptr->p_type == PT_SUNW_UNWIND) { 27727c478bd9Sstevel@tonic-gate unwindph = pptr; 277310a4fa49Srie } 27747c478bd9Sstevel@tonic-gate } 27757c478bd9Sstevel@tonic-gate 27767c478bd9Sstevel@tonic-gate #if defined(MAP_ALIGN) 27777c478bd9Sstevel@tonic-gate /* 2778a953e2b1Srie * Make sure the maximum page alignment is a power of 2 >= the default 2779a953e2b1Srie * segment alignment, for use with MAP_ALIGN. 27807c478bd9Sstevel@tonic-gate */ 2781a953e2b1Srie align = S_ROUND(align, M_SEGM_ALIGN); 27827c478bd9Sstevel@tonic-gate #endif 27837c478bd9Sstevel@tonic-gate 27847c478bd9Sstevel@tonic-gate /* 27857c478bd9Sstevel@tonic-gate * We'd better have at least one loadable segment, together with some 27867c478bd9Sstevel@tonic-gate * specified file and memory size. 27877c478bd9Sstevel@tonic-gate */ 27887c478bd9Sstevel@tonic-gate if ((fph == 0) || (lmph == 0) || (lfph == 0)) { 27895aefb655Srie eprintf(lml, ERR_ELF, MSG_INTL(MSG_GEN_NOLOADSEG), pname); 27907c478bd9Sstevel@tonic-gate return (0); 27917c478bd9Sstevel@tonic-gate } 27927c478bd9Sstevel@tonic-gate 27937c478bd9Sstevel@tonic-gate /* 27947c478bd9Sstevel@tonic-gate * Check that the files size accounts for the loadable sections 27957c478bd9Sstevel@tonic-gate * we're going to map in (failure to do this may cause spurious 27967c478bd9Sstevel@tonic-gate * bus errors if we're given a truncated file). 27977c478bd9Sstevel@tonic-gate */ 27987c478bd9Sstevel@tonic-gate if (fmap->fm_fsize < ((size_t)lfph->p_offset + lfph->p_filesz)) { 27995aefb655Srie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_GEN_CORTRUNC), pname); 28007c478bd9Sstevel@tonic-gate return (0); 28017c478bd9Sstevel@tonic-gate } 28027c478bd9Sstevel@tonic-gate 28037c478bd9Sstevel@tonic-gate /* 28047c478bd9Sstevel@tonic-gate * Memsize must be page rounded so that if we add object padding 28057c478bd9Sstevel@tonic-gate * at the end it will start at the beginning of a page. 28067c478bd9Sstevel@tonic-gate */ 28077c478bd9Sstevel@tonic-gate plen = memsize = M_PROUND((lmph->p_vaddr + lmph->p_memsz) - 28087c478bd9Sstevel@tonic-gate M_PTRUNC((ulong_t)fph->p_vaddr)); 28097c478bd9Sstevel@tonic-gate 28107c478bd9Sstevel@tonic-gate /* 28117c478bd9Sstevel@tonic-gate * Determine if an existing mapping is acceptable. 28127c478bd9Sstevel@tonic-gate */ 28137c478bd9Sstevel@tonic-gate if (interp && (lml->lm_flags & LML_FLG_BASELM) && 281441072f3cSrie (strcmp(pname, interp->i_name) == 0)) { 28157c478bd9Sstevel@tonic-gate /* 28167c478bd9Sstevel@tonic-gate * If this is the interpreter then it has already been mapped 28177c478bd9Sstevel@tonic-gate * and we have the address so don't map it again. Note that 28187c478bd9Sstevel@tonic-gate * the common occurrence of a reference to the interpretor 28197c478bd9Sstevel@tonic-gate * (libdl -> ld.so.1) will have been caught during filter 28207c478bd9Sstevel@tonic-gate * initialization (see elf_lookup_filtee()). However, some 28217c478bd9Sstevel@tonic-gate * ELF implementations are known to record libc.so.1 as the 28227c478bd9Sstevel@tonic-gate * interpretor, and thus this test catches this behavior. 28237c478bd9Sstevel@tonic-gate */ 28247c478bd9Sstevel@tonic-gate paddr = faddr = interp->i_faddr; 28257c478bd9Sstevel@tonic-gate 28267c478bd9Sstevel@tonic-gate } else if ((fixed == 0) && (r_debug.rtd_objpad == 0) && 28277c478bd9Sstevel@tonic-gate (memsize <= fmap->fm_msize) && ((fph->p_flags & PF_W) == 0) && 2828a953e2b1Srie (fph == lph) && (fph->p_filesz == fph->p_memsz) && 28297c478bd9Sstevel@tonic-gate (((Xword)fmap->fm_maddr % align) == 0)) { 2830a953e2b1Srie size_t rsize; 2831a953e2b1Srie 28327c478bd9Sstevel@tonic-gate /* 2833a953e2b1Srie * If the file contains a single segment, and the mapping 2834a953e2b1Srie * required has already been established from the initial fmap 2835a953e2b1Srie * mapping, then we don't need to do anything more. Reset the 2836a953e2b1Srie * fmap address so that any later files start a new fmap. This 2837a953e2b1Srie * is really an optimization for filters, such as libdl.so, 2838a953e2b1Srie * libthread, etc. that are constructed to be a single text 2839a953e2b1Srie * segment. 28407c478bd9Sstevel@tonic-gate */ 28417c478bd9Sstevel@tonic-gate paddr = faddr = fmap->fm_maddr; 2842a953e2b1Srie 2843a953e2b1Srie /* 2844a953e2b1Srie * Free any unused mapping by assigning the fmap buffer to the 2845a953e2b1Srie * unused region. fmap_setup() will unmap this area and 2846a953e2b1Srie * establish defaults for future mappings. 2847a953e2b1Srie */ 2848a953e2b1Srie rsize = M_PROUND(fph->p_filesz); 2849a953e2b1Srie fmap->fm_maddr += rsize; 2850a953e2b1Srie fmap->fm_msize -= rsize; 28517c478bd9Sstevel@tonic-gate fmap_setup(); 28527c478bd9Sstevel@tonic-gate } 28537c478bd9Sstevel@tonic-gate 28547c478bd9Sstevel@tonic-gate /* 28557c478bd9Sstevel@tonic-gate * Allocate a mapping array to retain mapped segment information. 28567c478bd9Sstevel@tonic-gate */ 28577c478bd9Sstevel@tonic-gate if ((mmaps = calloc(ehdr->e_phnum, sizeof (Mmap))) == 0) 28587c478bd9Sstevel@tonic-gate return (0); 28597c478bd9Sstevel@tonic-gate 28607c478bd9Sstevel@tonic-gate /* 28617c478bd9Sstevel@tonic-gate * If we're reusing an existing mapping determine the objects etext 28627c478bd9Sstevel@tonic-gate * address. Otherwise map the file (which will calculate the etext 28637c478bd9Sstevel@tonic-gate * address as part of the mapping process). 28647c478bd9Sstevel@tonic-gate */ 28657c478bd9Sstevel@tonic-gate if (faddr) { 28667c478bd9Sstevel@tonic-gate caddr_t base; 28677c478bd9Sstevel@tonic-gate 28687c478bd9Sstevel@tonic-gate if (fixed) 28697c478bd9Sstevel@tonic-gate base = 0; 28707c478bd9Sstevel@tonic-gate else 28717c478bd9Sstevel@tonic-gate base = faddr; 28727c478bd9Sstevel@tonic-gate 28737c478bd9Sstevel@tonic-gate /* LINTED */ 28747c478bd9Sstevel@tonic-gate phdr0 = phdr = (Phdr *)((char *)faddr + ehdr->e_ehsize); 28757c478bd9Sstevel@tonic-gate 28767c478bd9Sstevel@tonic-gate for (i = 0, pptr = phdr; i < (int)ehdr->e_phnum; i++, 28777c478bd9Sstevel@tonic-gate pptr = (Phdr *)((Off)pptr + ehdr->e_phentsize)) { 28787c478bd9Sstevel@tonic-gate if (pptr->p_type != PT_LOAD) 28797c478bd9Sstevel@tonic-gate continue; 28807c478bd9Sstevel@tonic-gate 28817c478bd9Sstevel@tonic-gate mmaps[mmapcnt].m_vaddr = (pptr->p_vaddr + base); 28827c478bd9Sstevel@tonic-gate mmaps[mmapcnt].m_msize = pptr->p_memsz; 28837c478bd9Sstevel@tonic-gate mmaps[mmapcnt].m_fsize = pptr->p_filesz; 28847c478bd9Sstevel@tonic-gate mmaps[mmapcnt].m_perm = (PROT_READ | PROT_EXEC); 28857c478bd9Sstevel@tonic-gate mmapcnt++; 28867c478bd9Sstevel@tonic-gate 28877c478bd9Sstevel@tonic-gate if (!(pptr->p_flags & PF_W)) { 28887c478bd9Sstevel@tonic-gate fmap->fm_etext = (ulong_t)pptr->p_vaddr + 28897c478bd9Sstevel@tonic-gate (ulong_t)pptr->p_memsz + 28907c478bd9Sstevel@tonic-gate (ulong_t)(fixed ? 0 : faddr); 28917c478bd9Sstevel@tonic-gate } 28927c478bd9Sstevel@tonic-gate } 28937c478bd9Sstevel@tonic-gate } else { 28947c478bd9Sstevel@tonic-gate /* 28957c478bd9Sstevel@tonic-gate * Map the file. 28967c478bd9Sstevel@tonic-gate */ 28975aefb655Srie if (!(faddr = elf_map_it(lml, pname, memsize, ehdr, fph, lph, 28987c478bd9Sstevel@tonic-gate &phdr, &paddr, &plen, fixed, fd, align, mmaps, &mmapcnt))) 28997c478bd9Sstevel@tonic-gate return (0); 29007c478bd9Sstevel@tonic-gate } 29017c478bd9Sstevel@tonic-gate 29027c478bd9Sstevel@tonic-gate /* 29037c478bd9Sstevel@tonic-gate * Calculate absolute base addresses and entry points. 29047c478bd9Sstevel@tonic-gate */ 29057c478bd9Sstevel@tonic-gate if (!fixed) { 29067c478bd9Sstevel@tonic-gate if (mld) 29077c478bd9Sstevel@tonic-gate /* LINTED */ 29087c478bd9Sstevel@tonic-gate mld = (Dyn *)((Off)mld + faddr); 29097c478bd9Sstevel@tonic-gate if (cap) 29107c478bd9Sstevel@tonic-gate /* LINTED */ 29117c478bd9Sstevel@tonic-gate cap = (Cap *)((Off)cap + faddr); 29127c478bd9Sstevel@tonic-gate mentry += (Off)faddr; 29137c478bd9Sstevel@tonic-gate } 29147c478bd9Sstevel@tonic-gate 29157c478bd9Sstevel@tonic-gate /* 29167c478bd9Sstevel@tonic-gate * Create new link map structure for newly mapped shared object. 29177c478bd9Sstevel@tonic-gate */ 29187c478bd9Sstevel@tonic-gate if (!(lmp = elf_new_lm(lml, pname, oname, mld, (ulong_t)faddr, 29197c478bd9Sstevel@tonic-gate fmap->fm_etext, lmco, memsize, mentry, (ulong_t)paddr, plen, mmaps, 29207c478bd9Sstevel@tonic-gate mmapcnt))) { 29217c478bd9Sstevel@tonic-gate (void) munmap((caddr_t)faddr, memsize); 29227c478bd9Sstevel@tonic-gate return (0); 29237c478bd9Sstevel@tonic-gate } 29247c478bd9Sstevel@tonic-gate 29257c478bd9Sstevel@tonic-gate /* 29267c478bd9Sstevel@tonic-gate * Start the system loading in the ELF information we'll be processing. 29277c478bd9Sstevel@tonic-gate */ 29287c478bd9Sstevel@tonic-gate if (REL(lmp)) { 29297c478bd9Sstevel@tonic-gate (void) madvise((void *)ADDR(lmp), (uintptr_t)REL(lmp) + 29307c478bd9Sstevel@tonic-gate (uintptr_t)RELSZ(lmp) - (uintptr_t)ADDR(lmp), 29317c478bd9Sstevel@tonic-gate MADV_WILLNEED); 29327c478bd9Sstevel@tonic-gate } 29337c478bd9Sstevel@tonic-gate 29347c478bd9Sstevel@tonic-gate /* 2935d326b23bSrie * If this shared object contains any special segments, record them. 29367c478bd9Sstevel@tonic-gate */ 29377c478bd9Sstevel@tonic-gate if (swph) { 29387c478bd9Sstevel@tonic-gate FLAGS(lmp) |= FLG_RT_SUNWBSS; 29397c478bd9Sstevel@tonic-gate SUNWBSS(lmp) = phdr + (swph - phdr0); 29407c478bd9Sstevel@tonic-gate } 2941d326b23bSrie if (tlph && (tls_assign(lml, lmp, (phdr + (tlph - phdr0))) == 0)) { 2942d326b23bSrie remove_so(lml, lmp); 2943d326b23bSrie return (0); 29447c478bd9Sstevel@tonic-gate } 29457c478bd9Sstevel@tonic-gate 29467c478bd9Sstevel@tonic-gate if (unwindph) 29477c478bd9Sstevel@tonic-gate PTUNWIND(lmp) = phdr + (unwindph - phdr0); 29487c478bd9Sstevel@tonic-gate 29497c478bd9Sstevel@tonic-gate if (cap) 29507c478bd9Sstevel@tonic-gate cap_assign(cap, lmp); 29517c478bd9Sstevel@tonic-gate 29527c478bd9Sstevel@tonic-gate return (lmp); 29537c478bd9Sstevel@tonic-gate } 29547c478bd9Sstevel@tonic-gate 29557c478bd9Sstevel@tonic-gate /* 29567c478bd9Sstevel@tonic-gate * Function to correct protection settings. Segments are all mapped initially 29577c478bd9Sstevel@tonic-gate * with permissions as given in the segment header. We need to turn on write 29587c478bd9Sstevel@tonic-gate * permissions on a text segment if there are any relocations against that 29597c478bd9Sstevel@tonic-gate * segment, and them turn write permission back off again before returning 29607c478bd9Sstevel@tonic-gate * control to the user. This function turns the permission on or off depending 29617c478bd9Sstevel@tonic-gate * on the value of the argument. 29627c478bd9Sstevel@tonic-gate */ 29637c478bd9Sstevel@tonic-gate int 29645aefb655Srie elf_set_prot(Rt_map *lmp, int permission) 29657c478bd9Sstevel@tonic-gate { 29667c478bd9Sstevel@tonic-gate Mmap *mmaps; 29677c478bd9Sstevel@tonic-gate 29687c478bd9Sstevel@tonic-gate /* 29697c478bd9Sstevel@tonic-gate * If this is an allocated image (ie. a relocatable object) we can't 29707c478bd9Sstevel@tonic-gate * mprotect() anything. 29717c478bd9Sstevel@tonic-gate */ 29727c478bd9Sstevel@tonic-gate if (FLAGS(lmp) & FLG_RT_IMGALLOC) 29737c478bd9Sstevel@tonic-gate return (1); 29747c478bd9Sstevel@tonic-gate 29755aefb655Srie DBG_CALL(Dbg_file_prot(lmp, permission)); 29767c478bd9Sstevel@tonic-gate 29777c478bd9Sstevel@tonic-gate for (mmaps = MMAPS(lmp); mmaps->m_vaddr; mmaps++) { 29787c478bd9Sstevel@tonic-gate if (mmaps->m_perm & PROT_WRITE) 29797c478bd9Sstevel@tonic-gate continue; 29807c478bd9Sstevel@tonic-gate 29817c478bd9Sstevel@tonic-gate if (mprotect(mmaps->m_vaddr, mmaps->m_msize, 29827c478bd9Sstevel@tonic-gate (mmaps->m_perm | permission)) == -1) { 29837c478bd9Sstevel@tonic-gate int err = errno; 29845aefb655Srie eprintf(LIST(lmp), ERR_FATAL, MSG_INTL(MSG_SYS_MPROT), 29857c478bd9Sstevel@tonic-gate NAME(lmp), strerror(err)); 29867c478bd9Sstevel@tonic-gate return (0); 29877c478bd9Sstevel@tonic-gate } 29887c478bd9Sstevel@tonic-gate } 29897c478bd9Sstevel@tonic-gate return (1); 29907c478bd9Sstevel@tonic-gate } 29917c478bd9Sstevel@tonic-gate 29927c478bd9Sstevel@tonic-gate /* 29937c478bd9Sstevel@tonic-gate * Build full pathname of shared object from given directory name and filename. 29947c478bd9Sstevel@tonic-gate */ 29957c478bd9Sstevel@tonic-gate static char * 29967c478bd9Sstevel@tonic-gate elf_get_so(const char *dir, const char *file) 29977c478bd9Sstevel@tonic-gate { 29987c478bd9Sstevel@tonic-gate static char pname[PATH_MAX]; 29997c478bd9Sstevel@tonic-gate 30007c478bd9Sstevel@tonic-gate (void) snprintf(pname, PATH_MAX, MSG_ORIG(MSG_FMT_PATH), dir, file); 30017c478bd9Sstevel@tonic-gate return (pname); 30027c478bd9Sstevel@tonic-gate } 30037c478bd9Sstevel@tonic-gate 30047c478bd9Sstevel@tonic-gate /* 30057c478bd9Sstevel@tonic-gate * The copy relocation is recorded in a copy structure which will be applied 30067c478bd9Sstevel@tonic-gate * after all other relocations are carried out. This provides for copying data 30077c478bd9Sstevel@tonic-gate * that must be relocated itself (ie. pointers in shared objects). This 30087c478bd9Sstevel@tonic-gate * structure also provides a means of binding RTLD_GROUP dependencies to any 30097c478bd9Sstevel@tonic-gate * copy relocations that have been taken from any group members. 30107c478bd9Sstevel@tonic-gate * 30117c478bd9Sstevel@tonic-gate * If the size of the .bss area available for the copy information is not the 30127c478bd9Sstevel@tonic-gate * same as the source of the data inform the user if we're under ldd(1) control 30137c478bd9Sstevel@tonic-gate * (this checking was only established in 5.3, so by only issuing an error via 30147c478bd9Sstevel@tonic-gate * ldd(1) we maintain the standard set by previous releases). 30157c478bd9Sstevel@tonic-gate */ 30167c478bd9Sstevel@tonic-gate int 30177c478bd9Sstevel@tonic-gate elf_copy_reloc(char *name, Sym *rsym, Rt_map *rlmp, void *radd, Sym *dsym, 30187c478bd9Sstevel@tonic-gate Rt_map *dlmp, const void *dadd) 30197c478bd9Sstevel@tonic-gate { 30207c478bd9Sstevel@tonic-gate Rel_copy rc; 30217c478bd9Sstevel@tonic-gate Lm_list *lml = LIST(rlmp); 30227c478bd9Sstevel@tonic-gate 30237c478bd9Sstevel@tonic-gate rc.r_name = name; 30247c478bd9Sstevel@tonic-gate rc.r_rsym = rsym; /* the new reference symbol and its */ 30257c478bd9Sstevel@tonic-gate rc.r_rlmp = rlmp; /* associated link-map */ 30267c478bd9Sstevel@tonic-gate rc.r_dlmp = dlmp; /* the defining link-map */ 30277c478bd9Sstevel@tonic-gate rc.r_dsym = dsym; /* the original definition */ 30287c478bd9Sstevel@tonic-gate rc.r_radd = radd; 30297c478bd9Sstevel@tonic-gate rc.r_dadd = dadd; 30307c478bd9Sstevel@tonic-gate 30317c478bd9Sstevel@tonic-gate if (rsym->st_size > dsym->st_size) 30327c478bd9Sstevel@tonic-gate rc.r_size = (size_t)dsym->st_size; 30337c478bd9Sstevel@tonic-gate else 30347c478bd9Sstevel@tonic-gate rc.r_size = (size_t)rsym->st_size; 30357c478bd9Sstevel@tonic-gate 3036cce0e03bSab if (alist_append(©_R(dlmp), &rc, sizeof (Rel_copy), 30377c478bd9Sstevel@tonic-gate AL_CNT_COPYREL) == 0) { 30387c478bd9Sstevel@tonic-gate if (!(lml->lm_flags & LML_FLG_TRC_WARN)) 30397c478bd9Sstevel@tonic-gate return (0); 30407c478bd9Sstevel@tonic-gate else 30417c478bd9Sstevel@tonic-gate return (1); 30427c478bd9Sstevel@tonic-gate } 30437c478bd9Sstevel@tonic-gate if (!(FLAGS1(dlmp) & FL1_RT_COPYTOOK)) { 3044cce0e03bSab if (aplist_append(©_S(rlmp), dlmp, 3045cce0e03bSab AL_CNT_COPYREL) == NULL) { 30467c478bd9Sstevel@tonic-gate if (!(lml->lm_flags & LML_FLG_TRC_WARN)) 30477c478bd9Sstevel@tonic-gate return (0); 30487c478bd9Sstevel@tonic-gate else 30497c478bd9Sstevel@tonic-gate return (1); 30507c478bd9Sstevel@tonic-gate } 30517c478bd9Sstevel@tonic-gate FLAGS1(dlmp) |= FL1_RT_COPYTOOK; 30527c478bd9Sstevel@tonic-gate } 30537c478bd9Sstevel@tonic-gate 30547c478bd9Sstevel@tonic-gate /* 30557c478bd9Sstevel@tonic-gate * If we are tracing (ldd), warn the user if 30567c478bd9Sstevel@tonic-gate * 1) the size from the reference symbol differs from the 30577c478bd9Sstevel@tonic-gate * copy definition. We can only copy as much data as the 30587c478bd9Sstevel@tonic-gate * reference (dynamic executables) entry allows. 30597c478bd9Sstevel@tonic-gate * 2) the copy definition has STV_PROTECTED visibility. 30607c478bd9Sstevel@tonic-gate */ 30617c478bd9Sstevel@tonic-gate if (lml->lm_flags & LML_FLG_TRC_WARN) { 30627c478bd9Sstevel@tonic-gate if (rsym->st_size != dsym->st_size) { 30637c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_LDD_CPY_SIZDIF), 30645aefb655Srie _conv_reloc_type(M_R_COPY), demangle(name), 30657c478bd9Sstevel@tonic-gate NAME(rlmp), EC_XWORD(rsym->st_size), 30667c478bd9Sstevel@tonic-gate NAME(dlmp), EC_XWORD(dsym->st_size)); 30677c478bd9Sstevel@tonic-gate if (rsym->st_size > dsym->st_size) 30687c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_LDD_CPY_INSDATA), 30697c478bd9Sstevel@tonic-gate NAME(dlmp)); 30707c478bd9Sstevel@tonic-gate else 30717c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_LDD_CPY_DATRUNC), 30727c478bd9Sstevel@tonic-gate NAME(rlmp)); 30737c478bd9Sstevel@tonic-gate } 30747c478bd9Sstevel@tonic-gate 30757c478bd9Sstevel@tonic-gate if (ELF_ST_VISIBILITY(dsym->st_other) == STV_PROTECTED) { 30767c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_LDD_CPY_PROT), 30775aefb655Srie _conv_reloc_type(M_R_COPY), demangle(name), 3078a953e2b1Srie NAME(dlmp)); 30797c478bd9Sstevel@tonic-gate } 30807c478bd9Sstevel@tonic-gate } 30817c478bd9Sstevel@tonic-gate 30825aefb655Srie DBG_CALL(Dbg_reloc_apply_val(lml, ELF_DBG_RTLD, (Xword)radd, 30835aefb655Srie (Xword)rc.r_size)); 30847c478bd9Sstevel@tonic-gate return (1); 30857c478bd9Sstevel@tonic-gate } 30867c478bd9Sstevel@tonic-gate 30877c478bd9Sstevel@tonic-gate /* 30887c478bd9Sstevel@tonic-gate * Determine the symbol location of an address within a link-map. Look for 30897c478bd9Sstevel@tonic-gate * the nearest symbol (whose value is less than or equal to the required 30907c478bd9Sstevel@tonic-gate * address). This is the object specific part of dladdr(). 30917c478bd9Sstevel@tonic-gate */ 30927c478bd9Sstevel@tonic-gate static void 30937c478bd9Sstevel@tonic-gate elf_dladdr(ulong_t addr, Rt_map *lmp, Dl_info *dlip, void **info, int flags) 30947c478bd9Sstevel@tonic-gate { 30957c478bd9Sstevel@tonic-gate ulong_t ndx, cnt, base, _value; 30966221fe92Sab Sym *sym, *_sym = NULL; 30977c478bd9Sstevel@tonic-gate const char *str; 30985343e1b3Sab int _flags; 3099d579eb63Sab uint_t *dynaddr_ndx; 3100d579eb63Sab uint_t dynaddr_n = 0; 3101d579eb63Sab ulong_t value; 31027c478bd9Sstevel@tonic-gate 31037c478bd9Sstevel@tonic-gate /* 31049039eeafSab * If SUNWSYMTAB() is non-NULL, then it sees a special version of 31059039eeafSab * the dynsym that starts with any local function symbols that exist in 31069039eeafSab * the library and then moves to the data held in SYMTAB(). In this 31079039eeafSab * case, SUNWSYMSZ tells us how long the symbol table is. The 31089039eeafSab * availability of local function symbols will enhance the results 31099039eeafSab * we can provide. 31109039eeafSab * 3111d579eb63Sab * If SUNWSYMTAB() is non-NULL, then there might also be a 3112d579eb63Sab * SUNWSYMSORT() vector associated with it. SUNWSYMSORT() contains 3113d579eb63Sab * an array of indices into SUNWSYMTAB, sorted by increasing 3114d579eb63Sab * address. We can use this to do an O(log N) search instead of a 3115d579eb63Sab * brute force search. 3116d579eb63Sab * 31179039eeafSab * If SUNWSYMTAB() is NULL, then SYMTAB() references a dynsym that 31189039eeafSab * contains only global symbols. In that case, the length of 31199039eeafSab * the symbol table comes from the nchain field of the related 31209039eeafSab * symbol lookup hash table. 31217c478bd9Sstevel@tonic-gate */ 31227c478bd9Sstevel@tonic-gate str = STRTAB(lmp); 31239039eeafSab if (SUNWSYMSZ(lmp) == NULL) { 31249039eeafSab sym = SYMTAB(lmp); 31259039eeafSab /* 31269039eeafSab * If we don't have a .hash table there are no symbols 31279039eeafSab * to look at. 31289039eeafSab */ 31299039eeafSab if (HASH(lmp) == 0) 31309039eeafSab return; 31319039eeafSab cnt = HASH(lmp)[1]; 31329039eeafSab } else { 31339039eeafSab sym = SUNWSYMTAB(lmp); 31349039eeafSab cnt = SUNWSYMSZ(lmp) / SYMENT(lmp); 3135d579eb63Sab dynaddr_ndx = SUNWSYMSORT(lmp); 3136d579eb63Sab if (dynaddr_ndx != NULL) 3137d579eb63Sab dynaddr_n = SUNWSYMSORTSZ(lmp) / SUNWSORTENT(lmp); 31389039eeafSab } 31397c478bd9Sstevel@tonic-gate 31407c478bd9Sstevel@tonic-gate if (FLAGS(lmp) & FLG_RT_FIXED) 31417c478bd9Sstevel@tonic-gate base = 0; 31427c478bd9Sstevel@tonic-gate else 31437c478bd9Sstevel@tonic-gate base = ADDR(lmp); 31447c478bd9Sstevel@tonic-gate 3145d579eb63Sab if (dynaddr_n > 0) { /* Binary search */ 3146d579eb63Sab long low = 0, low_bnd; 3147d579eb63Sab long high = dynaddr_n - 1, high_bnd; 3148d579eb63Sab long mid; 3149d579eb63Sab Sym *mid_sym; 31507c478bd9Sstevel@tonic-gate 31519039eeafSab /* 3152d579eb63Sab * Note that SUNWSYMSORT only contains symbols types that 3153d579eb63Sab * supply memory addresses, so there's no need to check and 3154d579eb63Sab * filter out any other types. 31559039eeafSab */ 3156d579eb63Sab low_bnd = low; 3157d579eb63Sab high_bnd = high; 3158d579eb63Sab while (low <= high) { 3159d579eb63Sab mid = (low + high) / 2; 3160d579eb63Sab mid_sym = &sym[dynaddr_ndx[mid]]; 3161d579eb63Sab value = mid_sym->st_value + base; 3162d579eb63Sab if (addr < value) { 3163d579eb63Sab if ((sym[dynaddr_ndx[high]].st_value + base) >= 3164d579eb63Sab addr) 3165d579eb63Sab high_bnd = high; 3166d579eb63Sab high = mid - 1; 3167d579eb63Sab } else if (addr > value) { 3168d579eb63Sab if ((sym[dynaddr_ndx[low]].st_value + base) <= 3169d579eb63Sab addr) 3170d579eb63Sab low_bnd = low; 3171d579eb63Sab low = mid + 1; 3172d579eb63Sab } else { 3173d579eb63Sab _sym = mid_sym; 3174d579eb63Sab _value = value; 3175d579eb63Sab break; 3176d579eb63Sab } 3177d579eb63Sab } 3178d579eb63Sab /* 3179d579eb63Sab * If the above didn't find it exactly, then we must 3180d579eb63Sab * return the closest symbol with a value that doesn't 3181d579eb63Sab * exceed the one we are looking for. If that symbol exists, 3182d579eb63Sab * it will lie in the range bounded by low_bnd and 3183d579eb63Sab * high_bnd. This is a linear search, but a short one. 3184d579eb63Sab */ 3185d579eb63Sab if (_sym == NULL) { 3186d579eb63Sab for (mid = low_bnd; mid <= high_bnd; mid++) { 3187d579eb63Sab mid_sym = &sym[dynaddr_ndx[mid]]; 3188d579eb63Sab value = mid_sym->st_value + base; 3189d579eb63Sab if (addr >= value) { 3190d579eb63Sab _sym = mid_sym; 3191d579eb63Sab _value = value; 3192d579eb63Sab } else { 3193d579eb63Sab break; 3194d579eb63Sab } 3195d579eb63Sab } 3196d579eb63Sab } 3197d579eb63Sab } else { /* Linear search */ 3198d579eb63Sab for (_value = 0, sym++, ndx = 1; ndx < cnt; ndx++, sym++) { 3199d579eb63Sab /* 3200d579eb63Sab * Skip expected symbol types that are not functions 3201d579eb63Sab * or data: 3202d579eb63Sab * - A symbol table starts with an undefined symbol 3203d579eb63Sab * in slot 0. If we are using SUNWSYMTAB(), 3204d579eb63Sab * there will be a second undefined symbol 3205d579eb63Sab * right before the globals. 3206d579eb63Sab * - The local part of SUNWSYMTAB() contains a 3207d579eb63Sab * series of function symbols. Each section 3208d579eb63Sab * starts with an initial STT_FILE symbol. 3209d579eb63Sab */ 3210d579eb63Sab if ((sym->st_shndx == SHN_UNDEF) || 3211d579eb63Sab (ELF_ST_TYPE(sym->st_info) == STT_FILE)) 3212d579eb63Sab continue; 32137c478bd9Sstevel@tonic-gate 3214d579eb63Sab value = sym->st_value + base; 3215d579eb63Sab if (value > addr) 3216d579eb63Sab continue; 3217d579eb63Sab if (value < _value) 3218d579eb63Sab continue; 32197c478bd9Sstevel@tonic-gate 3220d579eb63Sab _sym = sym; 3221d579eb63Sab _value = value; 32227c478bd9Sstevel@tonic-gate 3223d579eb63Sab /* 3224d579eb63Sab * Note, because we accept local and global symbols 3225d579eb63Sab * we could find a section symbol that matches the 3226d579eb63Sab * associated address, which means that the symbol 3227d579eb63Sab * name will be null. In this case continue the 3228d579eb63Sab * search in case we can find a global symbol of 3229d579eb63Sab * the same value. 3230d579eb63Sab */ 3231d579eb63Sab if ((value == addr) && 3232d579eb63Sab (ELF_ST_TYPE(sym->st_info) != STT_SECTION)) 3233d579eb63Sab break; 3234d579eb63Sab } 32357c478bd9Sstevel@tonic-gate } 32367c478bd9Sstevel@tonic-gate 32375343e1b3Sab _flags = flags & RTLD_DL_MASK; 32387c478bd9Sstevel@tonic-gate if (_sym) { 32397c478bd9Sstevel@tonic-gate if (_flags == RTLD_DL_SYMENT) 32407c478bd9Sstevel@tonic-gate *info = (void *)_sym; 32417c478bd9Sstevel@tonic-gate else if (_flags == RTLD_DL_LINKMAP) 32427c478bd9Sstevel@tonic-gate *info = (void *)lmp; 32437c478bd9Sstevel@tonic-gate 32447c478bd9Sstevel@tonic-gate dlip->dli_sname = str + _sym->st_name; 32457c478bd9Sstevel@tonic-gate dlip->dli_saddr = (void *)_value; 32465343e1b3Sab } else { 32475343e1b3Sab /* 32485343e1b3Sab * addr lies between the beginning of the mapped segment and 32495343e1b3Sab * the first global symbol. We have no symbol to return 32505343e1b3Sab * and the caller requires one. We use _START_, the base 32515343e1b3Sab * address of the mapping. 32525343e1b3Sab */ 32535343e1b3Sab 32545343e1b3Sab if (_flags == RTLD_DL_SYMENT) { 32555343e1b3Sab /* 32565343e1b3Sab * An actual symbol struct is needed, so we 32575343e1b3Sab * construct one for _START_. To do this in a 32585343e1b3Sab * fully accurate way requires a different symbol 32595343e1b3Sab * for each mapped segment. This requires the 32605343e1b3Sab * use of dynamic memory and a mutex. That's too much 32615343e1b3Sab * plumbing for a fringe case of limited importance. 32625343e1b3Sab * 32635343e1b3Sab * Fortunately, we can simplify: 32645343e1b3Sab * - Only the st_size and st_info fields are useful 32655343e1b3Sab * outside of the linker internals. The others 32665343e1b3Sab * reference things that outside code cannot see, 32675343e1b3Sab * and can be set to 0. 32685343e1b3Sab * - It's just a label and there is no size 32695343e1b3Sab * to report. So, the size should be 0. 32705343e1b3Sab * This means that only st_info needs a non-zero 32715343e1b3Sab * (constant) value. A static struct will suffice. 32725343e1b3Sab * It must be const (readonly) so the caller can't 32735343e1b3Sab * change its meaning for subsequent callers. 32745343e1b3Sab */ 32755343e1b3Sab static const Sym fsym = { 0, 0, 0, 32765343e1b3Sab ELF_ST_INFO(STB_LOCAL, STT_OBJECT) }; 32775343e1b3Sab *info = (void *) &fsym; 32785343e1b3Sab } 32795343e1b3Sab 32805343e1b3Sab dlip->dli_sname = MSG_ORIG(MSG_SYM_START); 32815343e1b3Sab dlip->dli_saddr = (void *) ADDR(lmp); 32827c478bd9Sstevel@tonic-gate } 32837c478bd9Sstevel@tonic-gate } 32847c478bd9Sstevel@tonic-gate 32857c478bd9Sstevel@tonic-gate static void 3286cce0e03bSab elf_lazy_cleanup(APlist *alp) 32877c478bd9Sstevel@tonic-gate { 3288cce0e03bSab Rt_map *lmp; 3289cce0e03bSab Aliste idx; 32907c478bd9Sstevel@tonic-gate 32917c478bd9Sstevel@tonic-gate /* 32927c478bd9Sstevel@tonic-gate * Cleanup any link-maps added to this dynamic list and free it. 32937c478bd9Sstevel@tonic-gate */ 3294cce0e03bSab for (APLIST_TRAVERSE(alp, idx, lmp)) 3295*75e7992aSrie FLAGS(lmp) &= ~FLG_RT_TMPLIST; 32967c478bd9Sstevel@tonic-gate free(alp); 32977c478bd9Sstevel@tonic-gate } 32987c478bd9Sstevel@tonic-gate 32997c478bd9Sstevel@tonic-gate /* 3300*75e7992aSrie * This routine is called as a last fall-back to search for a symbol from a 3301*75e7992aSrie * standard relocation. To maintain lazy loadings goal of reducing the number 33027c478bd9Sstevel@tonic-gate * of objects mapped, any symbol search is first carried out using the objects 33037c478bd9Sstevel@tonic-gate * that already exist in the process (either on a link-map list or handle). 33047c478bd9Sstevel@tonic-gate * If a symbol can't be found, and lazy dependencies are still pending, this 33057c478bd9Sstevel@tonic-gate * routine loads the dependencies in an attempt to locate the symbol. 33067c478bd9Sstevel@tonic-gate * 33077c478bd9Sstevel@tonic-gate * Only new objects are inspected as we will have already inspected presently 33087c478bd9Sstevel@tonic-gate * loaded objects before calling this routine. However, a new object may not 33097c478bd9Sstevel@tonic-gate * be new - although the di_lmp might be zero, the object may have been mapped 33107c478bd9Sstevel@tonic-gate * as someone elses dependency. Thus there's a possibility of some symbol 33117c478bd9Sstevel@tonic-gate * search duplication. 33127c478bd9Sstevel@tonic-gate */ 33137c478bd9Sstevel@tonic-gate Sym * 33147c478bd9Sstevel@tonic-gate elf_lazy_find_sym(Slookup *slp, Rt_map **_lmp, uint_t *binfo) 33157c478bd9Sstevel@tonic-gate { 33167c478bd9Sstevel@tonic-gate Sym *sym = 0; 3317cce0e03bSab APlist *alist = NULL; 3318cce0e03bSab Aliste idx; 3319cce0e03bSab Rt_map *lmp1, *lmp = slp->sl_imap; 33207c478bd9Sstevel@tonic-gate const char *name = slp->sl_name; 33217c478bd9Sstevel@tonic-gate 3322*75e7992aSrie /* 3323*75e7992aSrie * Generate a local list of new objects to process. This list can grow 3324*75e7992aSrie * as each object supplies its own lazy dependencies. 3325*75e7992aSrie */ 3326cce0e03bSab if (aplist_append(&alist, lmp, AL_CNT_LAZYFIND) == NULL) 3327cce0e03bSab return (NULL); 3328*75e7992aSrie FLAGS(lmp) |= FLG_RT_TMPLIST; 33297c478bd9Sstevel@tonic-gate 3330cce0e03bSab for (APLIST_TRAVERSE(alist, idx, lmp1)) { 33317c478bd9Sstevel@tonic-gate uint_t cnt = 0; 33327c478bd9Sstevel@tonic-gate Slookup sl = *slp; 3333*75e7992aSrie Dyninfo *dip, *pdip; 33347c478bd9Sstevel@tonic-gate 33357c478bd9Sstevel@tonic-gate /* 3336*75e7992aSrie * Discard any relocation index from further symbol searches. 3337*75e7992aSrie * This index will have already been used to trigger any 3338*75e7992aSrie * necessary lazy-loads, and it might be because one of these 3339*75e7992aSrie * lazy loads have failed that we're here performing this 3340*75e7992aSrie * fallback. By removing the relocation index we don't try 3341*75e7992aSrie * and perform the same failed lazy loading activity again. 3342*75e7992aSrie */ 3343*75e7992aSrie sl.sl_rsymndx = 0; 3344*75e7992aSrie 3345*75e7992aSrie /* 3346*75e7992aSrie * Loop through the lazy DT_NEEDED entries examining each object 3347*75e7992aSrie * for the required symbol. If the symbol is not found, the 3348*75e7992aSrie * object is in turn added to the local alist, so that the 3349*75e7992aSrie * objects lazy DT_NEEDED entries can be examined. 33507c478bd9Sstevel@tonic-gate */ 3351cce0e03bSab lmp = lmp1; 3352*75e7992aSrie for (dip = DYNINFO(lmp), pdip = NULL; cnt < DYNINFOCNT(lmp); 3353*75e7992aSrie cnt++, pdip = dip++) { 33547c478bd9Sstevel@tonic-gate Rt_map *nlmp; 33557c478bd9Sstevel@tonic-gate 3356*75e7992aSrie if (((dip->di_flags & FLG_DI_LAZY) == 0) || 33577c478bd9Sstevel@tonic-gate dip->di_info) 33587c478bd9Sstevel@tonic-gate continue; 33597c478bd9Sstevel@tonic-gate 33607c478bd9Sstevel@tonic-gate /* 3361*75e7992aSrie * If this object has already failed to lazy load, and 3362*75e7992aSrie * we're still processing the same runtime linker 3363*75e7992aSrie * operation that produced the failure, don't bother 3364*75e7992aSrie * to try and load the object again. 3365*75e7992aSrie */ 3366*75e7992aSrie if ((dip->di_flags & FLG_DI_LAZYFAIL) && pdip && 3367*75e7992aSrie (pdip->di_flags & FLG_DI_POSFLAG1)) { 3368*75e7992aSrie if (pdip->di_info == (void *)ld_entry_cnt) 3369*75e7992aSrie continue; 3370*75e7992aSrie 3371*75e7992aSrie dip->di_flags &= ~FLG_DI_LAZYFAIL; 3372*75e7992aSrie pdip->di_info = NULL; 3373*75e7992aSrie } 3374*75e7992aSrie 3375*75e7992aSrie /* 3376*75e7992aSrie * Try loading this lazy dependency. If the object 3377*75e7992aSrie * can't be loaded, consider this non-fatal and continue 3378*75e7992aSrie * the search. Lazy loaded dependencies need not exist 3379*75e7992aSrie * and their loading should only turn out to be fatal 3380*75e7992aSrie * if they are required to satisfy a relocation. 33817c478bd9Sstevel@tonic-gate * 33827c478bd9Sstevel@tonic-gate * If the file is already loaded and relocated we must 33837c478bd9Sstevel@tonic-gate * still inspect it for symbols, even though it might 33847c478bd9Sstevel@tonic-gate * have already been searched. This lazy load operation 33857c478bd9Sstevel@tonic-gate * might have promoted the permissions of the object, 33867c478bd9Sstevel@tonic-gate * and thus made the object applicable for this symbol 33877c478bd9Sstevel@tonic-gate * search, whereas before the object might have been 33887c478bd9Sstevel@tonic-gate * skipped. 33897c478bd9Sstevel@tonic-gate */ 3390*75e7992aSrie if ((nlmp = elf_lazy_load(lmp, &sl, cnt, name)) == 0) 33917c478bd9Sstevel@tonic-gate continue; 33927c478bd9Sstevel@tonic-gate 33937c478bd9Sstevel@tonic-gate /* 33947c478bd9Sstevel@tonic-gate * If this object isn't yet a part of the dynamic list 33957c478bd9Sstevel@tonic-gate * then inspect it for the symbol. If the symbol isn't 33967c478bd9Sstevel@tonic-gate * found add the object to the dynamic list so that we 33977c478bd9Sstevel@tonic-gate * can inspect its dependencies. 33987c478bd9Sstevel@tonic-gate */ 3399*75e7992aSrie if (FLAGS(nlmp) & FLG_RT_TMPLIST) 34007c478bd9Sstevel@tonic-gate continue; 34017c478bd9Sstevel@tonic-gate 34027c478bd9Sstevel@tonic-gate sl.sl_imap = nlmp; 34037c478bd9Sstevel@tonic-gate if (sym = LM_LOOKUP_SYM(sl.sl_cmap)(&sl, _lmp, binfo)) 34047c478bd9Sstevel@tonic-gate break; 34057c478bd9Sstevel@tonic-gate 34067c478bd9Sstevel@tonic-gate /* 34077c478bd9Sstevel@tonic-gate * Some dlsym() operations are already traversing a 34087c478bd9Sstevel@tonic-gate * link-map (dlopen(0)), and thus there's no need to 34097c478bd9Sstevel@tonic-gate * build our own dynamic dependency list. 34107c478bd9Sstevel@tonic-gate */ 34117c478bd9Sstevel@tonic-gate if ((sl.sl_flags & LKUP_NODESCENT) == 0) { 3412cce0e03bSab if (aplist_append(&alist, nlmp, 3413cce0e03bSab AL_CNT_LAZYFIND) == 0) { 34147c478bd9Sstevel@tonic-gate elf_lazy_cleanup(alist); 34157c478bd9Sstevel@tonic-gate return (0); 34167c478bd9Sstevel@tonic-gate } 3417*75e7992aSrie FLAGS(nlmp) |= FLG_RT_TMPLIST; 34187c478bd9Sstevel@tonic-gate } 34197c478bd9Sstevel@tonic-gate } 34207c478bd9Sstevel@tonic-gate if (sym) 34217c478bd9Sstevel@tonic-gate break; 34227c478bd9Sstevel@tonic-gate } 34237c478bd9Sstevel@tonic-gate 34247c478bd9Sstevel@tonic-gate elf_lazy_cleanup(alist); 34257c478bd9Sstevel@tonic-gate return (sym); 34267c478bd9Sstevel@tonic-gate } 34277c478bd9Sstevel@tonic-gate 34287c478bd9Sstevel@tonic-gate /* 34297c478bd9Sstevel@tonic-gate * Warning message for bad r_offset. 34307c478bd9Sstevel@tonic-gate */ 34317c478bd9Sstevel@tonic-gate void 34327c478bd9Sstevel@tonic-gate elf_reloc_bad(Rt_map *lmp, void *rel, uchar_t rtype, ulong_t roffset, 34337c478bd9Sstevel@tonic-gate ulong_t rsymndx) 34347c478bd9Sstevel@tonic-gate { 34357c478bd9Sstevel@tonic-gate const char *name = (char *)0; 34365aefb655Srie Lm_list *lml = LIST(lmp); 34377c478bd9Sstevel@tonic-gate int trace; 34387c478bd9Sstevel@tonic-gate 34395aefb655Srie if ((lml->lm_flags & LML_FLG_TRC_ENABLE) && 34407c478bd9Sstevel@tonic-gate (((rtld_flags & RT_FL_SILENCERR) == 0) || 34415aefb655Srie (lml->lm_flags & LML_FLG_TRC_VERBOSE))) 34427c478bd9Sstevel@tonic-gate trace = 1; 34437c478bd9Sstevel@tonic-gate else 34447c478bd9Sstevel@tonic-gate trace = 0; 34457c478bd9Sstevel@tonic-gate 34465aefb655Srie if ((trace == 0) && (DBG_ENABLED == 0)) 34477c478bd9Sstevel@tonic-gate return; 34487c478bd9Sstevel@tonic-gate 34497c478bd9Sstevel@tonic-gate if (rsymndx) { 34507c478bd9Sstevel@tonic-gate Sym *symref = (Sym *)((ulong_t)SYMTAB(lmp) + 3451a953e2b1Srie (rsymndx * SYMENT(lmp))); 34527c478bd9Sstevel@tonic-gate 34537c478bd9Sstevel@tonic-gate if (ELF_ST_BIND(symref->st_info) != STB_LOCAL) 34547c478bd9Sstevel@tonic-gate name = (char *)(STRTAB(lmp) + symref->st_name); 34557c478bd9Sstevel@tonic-gate } 34567c478bd9Sstevel@tonic-gate 34577c478bd9Sstevel@tonic-gate if (name == 0) 34587c478bd9Sstevel@tonic-gate name = MSG_ORIG(MSG_STR_EMPTY); 34597c478bd9Sstevel@tonic-gate 34607c478bd9Sstevel@tonic-gate if (trace) { 34617c478bd9Sstevel@tonic-gate const char *rstr; 34627c478bd9Sstevel@tonic-gate 34635aefb655Srie rstr = _conv_reloc_type((uint_t)rtype); 34647c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_LDD_REL_ERR1), rstr, name, 34657c478bd9Sstevel@tonic-gate EC_ADDR(roffset)); 34667c478bd9Sstevel@tonic-gate return; 34677c478bd9Sstevel@tonic-gate } 34687c478bd9Sstevel@tonic-gate 34695aefb655Srie Dbg_reloc_error(lml, ELF_DBG_RTLD, M_MACH, M_REL_SHT_TYPE, rel, name); 34707c478bd9Sstevel@tonic-gate } 3471d326b23bSrie 3472d326b23bSrie /* 3473d326b23bSrie * Resolve a static TLS relocation. 3474d326b23bSrie */ 3475d326b23bSrie long 3476d326b23bSrie elf_static_tls(Rt_map *lmp, Sym *sym, void *rel, uchar_t rtype, char *name, 3477d326b23bSrie ulong_t roffset, long value) 3478d326b23bSrie { 3479d326b23bSrie Lm_list *lml = LIST(lmp); 3480d326b23bSrie 3481d326b23bSrie /* 3482d326b23bSrie * Relocations against a static TLS block have limited support once 3483d326b23bSrie * process initialization has completed. Any error condition should be 3484d326b23bSrie * discovered by testing for DF_STATIC_TLS as part of loading an object, 3485d326b23bSrie * however individual relocations are tested in case the dynamic flag 3486d326b23bSrie * had not been set when this object was built. 3487d326b23bSrie */ 3488d326b23bSrie if (PTTLS(lmp) == 0) { 3489d326b23bSrie DBG_CALL(Dbg_reloc_in(lml, ELF_DBG_RTLD, M_MACH, 3490d326b23bSrie M_REL_SHT_TYPE, rel, NULL, name)); 3491d326b23bSrie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_BADTLS), 3492d326b23bSrie _conv_reloc_type((uint_t)rtype), NAME(lmp), 3493d326b23bSrie name ? demangle(name) : MSG_INTL(MSG_STR_UNKNOWN)); 3494d326b23bSrie return (0); 3495d326b23bSrie } 3496d326b23bSrie 3497d326b23bSrie /* 3498d326b23bSrie * If no static TLS has been set aside for this object, determine if 3499d326b23bSrie * any can be obtained. Enforce that any object using static TLS is 3500d326b23bSrie * non-deletable. 3501d326b23bSrie */ 3502d326b23bSrie if (TLSSTATOFF(lmp) == 0) { 3503d326b23bSrie FLAGS1(lmp) |= FL1_RT_TLSSTAT; 3504d326b23bSrie MODE(lmp) |= RTLD_NODELETE; 3505d326b23bSrie 3506d326b23bSrie if (tls_assign(lml, lmp, PTTLS(lmp)) == 0) { 3507d326b23bSrie DBG_CALL(Dbg_reloc_in(lml, ELF_DBG_RTLD, M_MACH, 3508d326b23bSrie M_REL_SHT_TYPE, rel, NULL, name)); 3509d326b23bSrie eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_BADTLS), 3510d326b23bSrie _conv_reloc_type((uint_t)rtype), NAME(lmp), 3511d326b23bSrie name ? demangle(name) : MSG_INTL(MSG_STR_UNKNOWN)); 3512d326b23bSrie return (0); 3513d326b23bSrie } 3514d326b23bSrie } 3515d326b23bSrie 3516d326b23bSrie /* 3517d326b23bSrie * Typically, a static TLS offset is maintained as a symbols value. 3518d326b23bSrie * For local symbols that are not apart of the dynamic symbol table, 3519d326b23bSrie * the TLS relocation points to a section symbol, and the static TLS 3520d326b23bSrie * offset was deposited in the associated GOT table. Make sure the GOT 3521d326b23bSrie * is cleared, so that the value isn't reused in do_reloc(). 3522d326b23bSrie */ 3523d326b23bSrie if (ELF_ST_BIND(sym->st_info) == STB_LOCAL) { 3524d326b23bSrie if ((ELF_ST_TYPE(sym->st_info) == STT_SECTION)) { 3525d326b23bSrie value = *(long *)roffset; 3526d326b23bSrie *(long *)roffset = 0; 3527d326b23bSrie } else { 3528d326b23bSrie value = sym->st_value; 3529d326b23bSrie } 3530d326b23bSrie } 3531d326b23bSrie return (-(TLSSTATOFF(lmp) - value)); 3532d326b23bSrie } 3533