10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51618Srie * Common Development and Distribution License (the "License"). 61618Srie * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211109Srie 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright (c) 1988 AT&T 240Sstevel@tonic-gate * All Rights Reserved 250Sstevel@tonic-gate * 268501SRod.Evans@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 270Sstevel@tonic-gate * Use is subject to license terms. 280Sstevel@tonic-gate */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate /* 310Sstevel@tonic-gate * Processing of relocatable objects and shared objects. 320Sstevel@tonic-gate */ 336206Sab196087 346206Sab196087 #define ELF_TARGET_AMD64 356206Sab196087 #define ELF_TARGET_SPARC 366206Sab196087 370Sstevel@tonic-gate #include <stdio.h> 380Sstevel@tonic-gate #include <string.h> 390Sstevel@tonic-gate #include <fcntl.h> 400Sstevel@tonic-gate #include <unistd.h> 410Sstevel@tonic-gate #include <link.h> 420Sstevel@tonic-gate #include <limits.h> 430Sstevel@tonic-gate #include <sys/stat.h> 440Sstevel@tonic-gate #include <sys/systeminfo.h> 450Sstevel@tonic-gate #include <debug.h> 460Sstevel@tonic-gate #include <msg.h> 470Sstevel@tonic-gate #include <_libld.h> 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * Decide if we can link against this input file. 510Sstevel@tonic-gate */ 520Sstevel@tonic-gate static int 537463SRod.Evans@Sun.COM ifl_verify(Ehdr *ehdr, Ofl_desc *ofl, Rej_desc *rej) 540Sstevel@tonic-gate { 550Sstevel@tonic-gate /* 560Sstevel@tonic-gate * Check the validity of the elf header information for compatibility 570Sstevel@tonic-gate * with this machine and our own internal elf library. 580Sstevel@tonic-gate */ 596206Sab196087 if ((ehdr->e_machine != ld_targ.t_m.m_mach) && 606206Sab196087 ((ehdr->e_machine != ld_targ.t_m.m_machplus) && 616206Sab196087 ((ehdr->e_flags & ld_targ.t_m.m_flagsplus) == 0))) { 620Sstevel@tonic-gate rej->rej_type = SGS_REJ_MACH; 630Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_machine; 640Sstevel@tonic-gate return (0); 650Sstevel@tonic-gate } 666206Sab196087 if (ehdr->e_ident[EI_DATA] != ld_targ.t_m.m_data) { 670Sstevel@tonic-gate rej->rej_type = SGS_REJ_DATA; 680Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_ident[EI_DATA]; 690Sstevel@tonic-gate return (0); 700Sstevel@tonic-gate } 711618Srie if (ehdr->e_version > ofl->ofl_dehdr->e_version) { 720Sstevel@tonic-gate rej->rej_type = SGS_REJ_VERSION; 730Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_version; 740Sstevel@tonic-gate return (0); 750Sstevel@tonic-gate } 760Sstevel@tonic-gate return (1); 770Sstevel@tonic-gate } 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* 800Sstevel@tonic-gate * Check sanity of file header and allocate an infile descriptor 810Sstevel@tonic-gate * for the file being processed. 820Sstevel@tonic-gate */ 831618Srie static Ifl_desc * 844716Sab196087 ifl_setup(const char *name, Ehdr *ehdr, Elf *elf, Word flags, Ofl_desc *ofl, 850Sstevel@tonic-gate Rej_desc *rej) 860Sstevel@tonic-gate { 870Sstevel@tonic-gate Ifl_desc *ifl; 880Sstevel@tonic-gate List *list; 890Sstevel@tonic-gate Rej_desc _rej = { 0 }; 900Sstevel@tonic-gate 910Sstevel@tonic-gate if (ifl_verify(ehdr, ofl, &_rej) == 0) { 920Sstevel@tonic-gate _rej.rej_name = name; 936206Sab196087 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej, 946206Sab196087 ld_targ.t_m.m_mach)); 950Sstevel@tonic-gate if (rej->rej_type == 0) { 960Sstevel@tonic-gate *rej = _rej; 970Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name); 980Sstevel@tonic-gate } 990Sstevel@tonic-gate return (0); 1000Sstevel@tonic-gate } 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate if ((ifl = libld_calloc(1, sizeof (Ifl_desc))) == 0) 1030Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR); 1040Sstevel@tonic-gate ifl->ifl_name = name; 1050Sstevel@tonic-gate ifl->ifl_ehdr = ehdr; 1060Sstevel@tonic-gate ifl->ifl_elf = elf; 1070Sstevel@tonic-gate ifl->ifl_flags = flags; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * Is this file using 'extended Section Indexes'. If so, use the 1110Sstevel@tonic-gate * e_shnum & e_shstrndx which can be found at: 1120Sstevel@tonic-gate * 1130Sstevel@tonic-gate * e_shnum == Shdr[0].sh_size 1140Sstevel@tonic-gate * e_shstrndx == Shdr[0].sh_link 1150Sstevel@tonic-gate */ 1160Sstevel@tonic-gate if ((ehdr->e_shnum == 0) && (ehdr->e_shoff != 0)) { 1170Sstevel@tonic-gate Elf_Scn *scn; 1180Sstevel@tonic-gate Shdr *shdr0; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate if ((scn = elf_getscn(elf, 0)) == NULL) { 1211618Srie eprintf(ofl->ofl_lml, ERR_ELF, 1221618Srie MSG_INTL(MSG_ELF_GETSCN), name); 1230Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 1240Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR); 1250Sstevel@tonic-gate } 1260Sstevel@tonic-gate if ((shdr0 = elf_getshdr(scn)) == NULL) { 1271618Srie eprintf(ofl->ofl_lml, ERR_ELF, 1281618Srie MSG_INTL(MSG_ELF_GETSHDR), name); 1290Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 1300Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR); 1310Sstevel@tonic-gate } 1320Sstevel@tonic-gate ifl->ifl_shnum = (Word)shdr0->sh_size; 1330Sstevel@tonic-gate if (ehdr->e_shstrndx == SHN_XINDEX) 1340Sstevel@tonic-gate ifl->ifl_shstrndx = shdr0->sh_link; 1350Sstevel@tonic-gate else 1360Sstevel@tonic-gate ifl->ifl_shstrndx = ehdr->e_shstrndx; 1370Sstevel@tonic-gate } else { 1380Sstevel@tonic-gate ifl->ifl_shnum = ehdr->e_shnum; 1390Sstevel@tonic-gate ifl->ifl_shstrndx = ehdr->e_shstrndx; 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate if ((ifl->ifl_isdesc = libld_calloc(ifl->ifl_shnum, 1430Sstevel@tonic-gate sizeof (Is_desc *))) == 0) 1440Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR); 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate /* 1470Sstevel@tonic-gate * Record this new input file on the shared object or relocatable 1480Sstevel@tonic-gate * object input file list. 1490Sstevel@tonic-gate */ 1500Sstevel@tonic-gate if (ifl->ifl_ehdr->e_type == ET_DYN) { 1510Sstevel@tonic-gate list = &ofl->ofl_sos; 1520Sstevel@tonic-gate } else { 1530Sstevel@tonic-gate list = &ofl->ofl_objs; 1540Sstevel@tonic-gate } 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate if (list_appendc(list, ifl) == 0) 1570Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR); 1580Sstevel@tonic-gate return (ifl); 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate /* 1620Sstevel@tonic-gate * Process a generic section. The appropriate section information is added 1630Sstevel@tonic-gate * to the files input descriptor list. 1640Sstevel@tonic-gate */ 1651618Srie static uintptr_t 1660Sstevel@tonic-gate process_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 1670Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 1680Sstevel@tonic-gate { 1690Sstevel@tonic-gate Is_desc *isp; 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate /* 1720Sstevel@tonic-gate * Create a new input section descriptor. If this is a NOBITS 1730Sstevel@tonic-gate * section elf_getdata() will still create a data buffer (the buffer 1740Sstevel@tonic-gate * will be null and the size will reflect the actual memory size). 1750Sstevel@tonic-gate */ 1760Sstevel@tonic-gate if ((isp = libld_calloc(sizeof (Is_desc), 1)) == 0) 1770Sstevel@tonic-gate return (S_ERROR); 1780Sstevel@tonic-gate isp->is_shdr = shdr; 1790Sstevel@tonic-gate isp->is_file = ifl; 1800Sstevel@tonic-gate isp->is_name = name; 1810Sstevel@tonic-gate isp->is_scnndx = ndx; 182574Sseizo isp->is_flags = FLG_IS_EXTERNAL; 1837463SRod.Evans@Sun.COM isp->is_keyident = ident; 1847463SRod.Evans@Sun.COM 1850Sstevel@tonic-gate if ((isp->is_indata = elf_getdata(scn, NULL)) == NULL) { 1861618Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_GETDATA), 1871618Srie ifl->ifl_name); 1880Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 1890Sstevel@tonic-gate return (0); 1900Sstevel@tonic-gate } 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate if ((shdr->sh_flags & SHF_EXCLUDE) && 1930Sstevel@tonic-gate ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0)) { 1940Sstevel@tonic-gate isp->is_flags |= FLG_IS_DISCARD; 1950Sstevel@tonic-gate } 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate /* 1980Sstevel@tonic-gate * Add the new input section to the files input section list and 1997463SRod.Evans@Sun.COM * flag whether the section needs placing in an output section. This 2007463SRod.Evans@Sun.COM * placement is deferred until all input section processing has been 2017463SRod.Evans@Sun.COM * completed, as SHT_GROUP sections can provide information that will 2027463SRod.Evans@Sun.COM * affect how other sections within the file should be placed. 2030Sstevel@tonic-gate */ 2040Sstevel@tonic-gate ifl->ifl_isdesc[ndx] = isp; 2050Sstevel@tonic-gate 2067463SRod.Evans@Sun.COM if (ident) { 2077463SRod.Evans@Sun.COM if (shdr->sh_flags & ALL_SHF_ORDER) { 2087463SRod.Evans@Sun.COM isp->is_flags |= FLG_IS_ORDERED; 2097463SRod.Evans@Sun.COM ifl->ifl_flags |= FLG_IF_ORDERED; 2102647Srie } 2117463SRod.Evans@Sun.COM isp->is_flags |= FLG_IS_PLACE; 2120Sstevel@tonic-gate } 2130Sstevel@tonic-gate return (1); 2140Sstevel@tonic-gate } 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate /* 2170Sstevel@tonic-gate * Determine the software capabilities of the object being built from the 2180Sstevel@tonic-gate * capabilities of the input relocatable objects. One software capability 2190Sstevel@tonic-gate * is presently recognized, and represented with the following (sys/elf.h): 2200Sstevel@tonic-gate * 2210Sstevel@tonic-gate * SF1_SUNW_FPKNWN use/non-use of frame pointer is known, and 2220Sstevel@tonic-gate * SF1_SUNW_FPUSED the frame pointer is in use. 2230Sstevel@tonic-gate * 2240Sstevel@tonic-gate * The resolution of the present fame pointer state, and the capabilities 2250Sstevel@tonic-gate * provided by a new input relocatable object are: 2260Sstevel@tonic-gate * 2270Sstevel@tonic-gate * new input relocatable object 2280Sstevel@tonic-gate * 2290Sstevel@tonic-gate * present | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown> 2300Sstevel@tonic-gate * state | SF1_SUNW_FPUSED | | 2310Sstevel@tonic-gate * --------------------------------------------------------------------------- 2320Sstevel@tonic-gate * SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN 2330Sstevel@tonic-gate * SF1_SUNW_FPUSED | SF1_SUNW_FPUSED | | SF1_SUNW_FPUSED 2340Sstevel@tonic-gate * --------------------------------------------------------------------------- 2350Sstevel@tonic-gate * SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN 2360Sstevel@tonic-gate * | | | 2370Sstevel@tonic-gate * --------------------------------------------------------------------------- 2380Sstevel@tonic-gate * <unknown> | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown> 2390Sstevel@tonic-gate * | SF1_SUNW_FPUSED | | 2400Sstevel@tonic-gate */ 2410Sstevel@tonic-gate static void 2420Sstevel@tonic-gate sf1_cap(Ofl_desc *ofl, Xword val, Ifl_desc *ifl, const char *name) 2430Sstevel@tonic-gate { 2440Sstevel@tonic-gate Xword badval; 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate /* 2470Sstevel@tonic-gate * If a mapfile has established definitions to override any input 2480Sstevel@tonic-gate * capabilities, ignore any new input capabilities. 2490Sstevel@tonic-gate */ 2500Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_OVSFCAP) { 2511618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_IGNORE, CA_SUNW_SF_1, 2526206Sab196087 val, ld_targ.t_m.m_mach); 2530Sstevel@tonic-gate return; 2540Sstevel@tonic-gate } 2550Sstevel@tonic-gate 2567833SRod.Evans@Sun.COM #if !defined(_ELF64) 2577833SRod.Evans@Sun.COM if (ifl->ifl_ehdr->e_type == ET_REL) { 2587833SRod.Evans@Sun.COM /* 2597833SRod.Evans@Sun.COM * The SF1_SUNW_ADDR32 is only meaningful when building a 64-bit 2607833SRod.Evans@Sun.COM * object. Warn the user, and remove the setting, if we're 2617833SRod.Evans@Sun.COM * building a 32-bit object. 2627833SRod.Evans@Sun.COM */ 2637833SRod.Evans@Sun.COM if (val & SF1_SUNW_ADDR32) { 2647833SRod.Evans@Sun.COM eprintf(ofl->ofl_lml, ERR_WARNING, 2657833SRod.Evans@Sun.COM MSG_INTL(MSG_FIL_INADDR32SF1), ifl->ifl_name, name); 2667833SRod.Evans@Sun.COM val &= ~SF1_SUNW_ADDR32; 2677833SRod.Evans@Sun.COM } 2687833SRod.Evans@Sun.COM } 2697833SRod.Evans@Sun.COM #endif 2700Sstevel@tonic-gate /* 2710Sstevel@tonic-gate * If this object doesn't specify any capabilities, ignore it, and 2720Sstevel@tonic-gate * leave the state as is. 2730Sstevel@tonic-gate */ 2740Sstevel@tonic-gate if (val == 0) 2750Sstevel@tonic-gate return; 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate /* 2780Sstevel@tonic-gate * Make sure we only accept known software capabilities. Note, that 2790Sstevel@tonic-gate * an F1_SUNW_FPUSED by itself is viewed as bad practice. 2800Sstevel@tonic-gate */ 2810Sstevel@tonic-gate if ((badval = (val & ~SF1_SUNW_MASK)) != 0) { 2821618Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1), 2830Sstevel@tonic-gate ifl->ifl_name, name, EC_XWORD(badval)); 2840Sstevel@tonic-gate val &= SF1_SUNW_MASK; 2850Sstevel@tonic-gate } 2867833SRod.Evans@Sun.COM if ((val & (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)) == SF1_SUNW_FPUSED) { 2871618Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1), 2880Sstevel@tonic-gate ifl->ifl_name, name, EC_XWORD(val)); 2890Sstevel@tonic-gate return; 2900Sstevel@tonic-gate } 2910Sstevel@tonic-gate 2927833SRod.Evans@Sun.COM /* 2937833SRod.Evans@Sun.COM * If the input file is not a relocatable object, then we're only here 2947833SRod.Evans@Sun.COM * to warn the user of any questionable capabilities. 2957833SRod.Evans@Sun.COM */ 2967833SRod.Evans@Sun.COM if (ifl->ifl_ehdr->e_type != ET_REL) { 2977833SRod.Evans@Sun.COM #if defined(_ELF64) 2987833SRod.Evans@Sun.COM /* 2997833SRod.Evans@Sun.COM * If we're building a 64-bit executable, and we come across a 3007833SRod.Evans@Sun.COM * dependency that requires a restricted address space, then 3017833SRod.Evans@Sun.COM * that dependencies requirement can only be satisfied if the 3027833SRod.Evans@Sun.COM * executable triggers the restricted address space. This is a 3037833SRod.Evans@Sun.COM * warning rather than a fatal error, as the possibility exists 3047833SRod.Evans@Sun.COM * that an appropriate dependency will be provided at runtime. 3057833SRod.Evans@Sun.COM * The runtime linker will refuse to use this dependency. 3067833SRod.Evans@Sun.COM */ 3077833SRod.Evans@Sun.COM if ((val & SF1_SUNW_ADDR32) && (ofl->ofl_flags & FLG_OF_EXEC) && 3087833SRod.Evans@Sun.COM ((ofl->ofl_sfcap_1 & SF1_SUNW_ADDR32) == 0)) { 3097833SRod.Evans@Sun.COM eprintf(ofl->ofl_lml, ERR_WARNING, 3107833SRod.Evans@Sun.COM MSG_INTL(MSG_FIL_EXADDR32SF1), ifl->ifl_name, name); 3117833SRod.Evans@Sun.COM } 3127833SRod.Evans@Sun.COM #endif 3137833SRod.Evans@Sun.COM return; 3147833SRod.Evans@Sun.COM } 3157833SRod.Evans@Sun.COM 3161618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_OLD, CA_SUNW_SF_1, 3176206Sab196087 ofl->ofl_sfcap_1, ld_targ.t_m.m_mach); 3181618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_NEW, CA_SUNW_SF_1, 3196206Sab196087 val, ld_targ.t_m.m_mach); 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate /* 3220Sstevel@tonic-gate * Determine the resolution of the present frame pointer and the 3230Sstevel@tonic-gate * new input relocatable objects frame pointer. 3240Sstevel@tonic-gate */ 3250Sstevel@tonic-gate if ((ofl->ofl_sfcap_1 & (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)) == 3260Sstevel@tonic-gate (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)) { 3270Sstevel@tonic-gate /* 3280Sstevel@tonic-gate * If the new relocatable object isn't using a frame pointer, 3290Sstevel@tonic-gate * reduce the present state to unused. 3300Sstevel@tonic-gate */ 3310Sstevel@tonic-gate if ((val & (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)) != 3320Sstevel@tonic-gate (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)) 3330Sstevel@tonic-gate ofl->ofl_sfcap_1 &= ~SF1_SUNW_FPUSED; 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate } else if ((ofl->ofl_sfcap_1 & SF1_SUNW_FPKNWN) == 0) { 3360Sstevel@tonic-gate /* 3370Sstevel@tonic-gate * If the present state is unknown, take the new relocatable 3380Sstevel@tonic-gate * object frame pointer usage. 3390Sstevel@tonic-gate */ 3400Sstevel@tonic-gate ofl->ofl_sfcap_1 = val; 3410Sstevel@tonic-gate } 3420Sstevel@tonic-gate 3431618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_RESOLVED, CA_SUNW_SF_1, 3446206Sab196087 ofl->ofl_sfcap_1, ld_targ.t_m.m_mach); 3450Sstevel@tonic-gate } 3460Sstevel@tonic-gate 3470Sstevel@tonic-gate /* 3480Sstevel@tonic-gate * Determine the hardware capabilities of the object being built from the 3490Sstevel@tonic-gate * capabilities of the input relocatable objects. There's really little to 3500Sstevel@tonic-gate * do here, other than to offer diagnostics, hardware capabilities are simply 3510Sstevel@tonic-gate * additive. 3520Sstevel@tonic-gate */ 3530Sstevel@tonic-gate static void 3540Sstevel@tonic-gate hw1_cap(Ofl_desc *ofl, Xword val) 3550Sstevel@tonic-gate { 3560Sstevel@tonic-gate /* 3570Sstevel@tonic-gate * If a mapfile has established definitions to override any input 3580Sstevel@tonic-gate * capabilities, ignore any new input capabilities. 3590Sstevel@tonic-gate */ 3600Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_OVHWCAP) { 3611618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_IGNORE, CA_SUNW_HW_1, 3626206Sab196087 val, ld_targ.t_m.m_mach); 3630Sstevel@tonic-gate return; 3640Sstevel@tonic-gate } 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate /* 3670Sstevel@tonic-gate * If this object doesn't specify any capabilities, ignore it, and 3680Sstevel@tonic-gate * leave the state as is. 3690Sstevel@tonic-gate */ 3700Sstevel@tonic-gate if (val == 0) 3710Sstevel@tonic-gate return; 3720Sstevel@tonic-gate 3731618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_OLD, CA_SUNW_HW_1, 3746206Sab196087 ofl->ofl_hwcap_1, ld_targ.t_m.m_mach); 3756206Sab196087 Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_NEW, CA_SUNW_HW_1, val, 3766206Sab196087 ld_targ.t_m.m_mach); 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate ofl->ofl_hwcap_1 |= val; 3790Sstevel@tonic-gate 3801618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_RESOLVED, CA_SUNW_HW_1, 3816206Sab196087 ofl->ofl_hwcap_1, ld_targ.t_m.m_mach); 3820Sstevel@tonic-gate } 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate /* 3850Sstevel@tonic-gate * Process a hardware/software capabilities section. Traverse the section 3860Sstevel@tonic-gate * updating the global capabilities variables as necessary. 3870Sstevel@tonic-gate */ 3880Sstevel@tonic-gate static void 3893617Srie process_cap(Ifl_desc *ifl, Is_desc *cisp, Ofl_desc *ofl) 3900Sstevel@tonic-gate { 3911618Srie Cap *cdata; 3923617Srie Word ndx, cnum; 3930Sstevel@tonic-gate 3948501SRod.Evans@Sun.COM DBG_CALL(Dbg_cap_sec_title(ofl->ofl_lml, ifl->ifl_name)); 3950Sstevel@tonic-gate 3963617Srie /* 3973617Srie * The capabilities are supposed to be terminated with a CA_SUNW_NULL 3983617Srie * entry. However, the compilers have been known to not follow this 3993617Srie * convention. Use the section information to determine the number 4003617Srie * of capabilities, and skip any CA_SUNW_NULL entries. 4013617Srie */ 4023617Srie cdata = (Cap *)cisp->is_indata->d_buf; 4033617Srie cnum = (Word)(cisp->is_shdr->sh_size / cisp->is_shdr->sh_entsize); 4043617Srie 4053617Srie for (ndx = 0; ndx < cnum; cdata++, ndx++) { 4060Sstevel@tonic-gate switch (cdata->c_tag) { 4070Sstevel@tonic-gate case CA_SUNW_HW_1: 4087833SRod.Evans@Sun.COM /* 4097833SRod.Evans@Sun.COM * Only the hardware capabilities that are 4107833SRod.Evans@Sun.COM * defined in a relocatable object become part 4117833SRod.Evans@Sun.COM * of the hardware capabilities in the output 4127833SRod.Evans@Sun.COM * file. 4137833SRod.Evans@Sun.COM */ 4147833SRod.Evans@Sun.COM if (ifl->ifl_ehdr->e_type == ET_REL) 4157833SRod.Evans@Sun.COM hw1_cap(ofl, cdata->c_un.c_val); 4160Sstevel@tonic-gate break; 4170Sstevel@tonic-gate case CA_SUNW_SF_1: 4187833SRod.Evans@Sun.COM /* 4197833SRod.Evans@Sun.COM * Only the software capabilities that are 4207833SRod.Evans@Sun.COM * defined in a relocatable object become part 4217833SRod.Evans@Sun.COM * of the software capabilities in the output 4227833SRod.Evans@Sun.COM * file. However, check the validity of the 4237833SRod.Evans@Sun.COM * software capabilities of any dependencies. 4247833SRod.Evans@Sun.COM */ 4253617Srie sf1_cap(ofl, cdata->c_un.c_val, ifl, 4263617Srie cisp->is_name); 4273617Srie break; 4283617Srie case CA_SUNW_NULL: 4290Sstevel@tonic-gate break; 4300Sstevel@tonic-gate default: 4311618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 4321618Srie MSG_INTL(MSG_FIL_UNKCAP), 4333617Srie ifl->ifl_name, cisp->is_name, cdata->c_tag); 4340Sstevel@tonic-gate } 4350Sstevel@tonic-gate } 4360Sstevel@tonic-gate } 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate /* 4390Sstevel@tonic-gate * Simply process the section so that we have pointers to the data for use 4400Sstevel@tonic-gate * in later routines, however don't add the section to the output section 4410Sstevel@tonic-gate * list as we will be creating our own replacement sections later (ie. 4420Sstevel@tonic-gate * symtab and relocation). 4430Sstevel@tonic-gate */ 4441618Srie static uintptr_t 4450Sstevel@tonic-gate /* ARGSUSED5 */ 4460Sstevel@tonic-gate process_input(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 4477463SRod.Evans@Sun.COM Word ndx, int ident, Ofl_desc *ofl) 4480Sstevel@tonic-gate { 4496206Sab196087 return (process_section(name, ifl, shdr, scn, ndx, 4506206Sab196087 ld_targ.t_id.id_null, ofl)); 4510Sstevel@tonic-gate } 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate /* 4540Sstevel@tonic-gate * Keep a running count of relocation entries from input relocatable objects for 4550Sstevel@tonic-gate * sizing relocation buckets later. If we're building an executable, save any 4560Sstevel@tonic-gate * relocations from shared objects to determine if any copy relocation symbol 4570Sstevel@tonic-gate * has a displacement relocation against it. 4580Sstevel@tonic-gate */ 4591618Srie static uintptr_t 4600Sstevel@tonic-gate /* ARGSUSED5 */ 4610Sstevel@tonic-gate process_reloc(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 4627463SRod.Evans@Sun.COM Word ndx, int ident, Ofl_desc *ofl) 4630Sstevel@tonic-gate { 4640Sstevel@tonic-gate if (process_section(name, ifl, 4656206Sab196087 shdr, scn, ndx, ld_targ.t_id.id_null, ofl) == S_ERROR) 4660Sstevel@tonic-gate return (S_ERROR); 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate if (ifl->ifl_ehdr->e_type == ET_REL) { 4690Sstevel@tonic-gate if (shdr->sh_entsize && (shdr->sh_entsize <= shdr->sh_size)) 4700Sstevel@tonic-gate /* LINTED */ 4710Sstevel@tonic-gate ofl->ofl_relocincnt += 4720Sstevel@tonic-gate (Word)(shdr->sh_size / shdr->sh_entsize); 4730Sstevel@tonic-gate } else if (ofl->ofl_flags & FLG_OF_EXEC) { 4740Sstevel@tonic-gate if (list_appendc(&ifl->ifl_relsect, ifl->ifl_isdesc[ndx]) == 0) 4750Sstevel@tonic-gate return (S_ERROR); 4760Sstevel@tonic-gate } 4770Sstevel@tonic-gate return (1); 4780Sstevel@tonic-gate } 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate /* 4820Sstevel@tonic-gate * Process a string table section. A valid section contains an initial and 4830Sstevel@tonic-gate * final null byte. 4840Sstevel@tonic-gate */ 4851618Srie static uintptr_t 4860Sstevel@tonic-gate process_strtab(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 4877463SRod.Evans@Sun.COM Word ndx, int ident, Ofl_desc *ofl) 4880Sstevel@tonic-gate { 4890Sstevel@tonic-gate char *data; 4900Sstevel@tonic-gate size_t size; 4910Sstevel@tonic-gate Is_desc *isp; 4920Sstevel@tonic-gate uintptr_t error; 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate /* 4950Sstevel@tonic-gate * Never include .stab.excl sections in any output file. 4960Sstevel@tonic-gate * If the -s flag has been specified strip any .stab sections. 4970Sstevel@tonic-gate */ 4980Sstevel@tonic-gate if (((ofl->ofl_flags & FLG_OF_STRIP) && ident && 4990Sstevel@tonic-gate (strncmp(name, MSG_ORIG(MSG_SCN_STAB), MSG_SCN_STAB_SIZE) == 0)) || 5000Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_STABEXCL)) == 0) && ident) 5010Sstevel@tonic-gate return (1); 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate /* 5040Sstevel@tonic-gate * If we got here to process a .shstrtab or .dynstr table, `ident' will 5050Sstevel@tonic-gate * be null. Otherwise make sure we don't have a .strtab section as this 5060Sstevel@tonic-gate * should not be added to the output section list either. 5070Sstevel@tonic-gate */ 5086206Sab196087 if ((ident != ld_targ.t_id.id_null) && 5090Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_STRTAB)) == 0)) 5106206Sab196087 ident = ld_targ.t_id.id_null; 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate error = process_section(name, ifl, shdr, scn, ndx, ident, ofl); 5130Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR)) 5140Sstevel@tonic-gate return (error); 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate /* 5170Sstevel@tonic-gate * String tables should start and end with a NULL byte. Note, it has 5180Sstevel@tonic-gate * been known for the assembler to create empty string tables, so check 5190Sstevel@tonic-gate * the size before attempting to verify the data itself. 5200Sstevel@tonic-gate */ 5210Sstevel@tonic-gate isp = ifl->ifl_isdesc[ndx]; 5220Sstevel@tonic-gate size = isp->is_indata->d_size; 5230Sstevel@tonic-gate if (size) { 5240Sstevel@tonic-gate data = isp->is_indata->d_buf; 5250Sstevel@tonic-gate if (data[0] != '\0' || data[size - 1] != '\0') 5261618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 5271618Srie MSG_INTL(MSG_FIL_MALSTR), ifl->ifl_name, name); 5280Sstevel@tonic-gate } else 5290Sstevel@tonic-gate isp->is_indata->d_buf = (void *)MSG_ORIG(MSG_STR_EMPTY); 5300Sstevel@tonic-gate 5310Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_HSTRTAB; 5320Sstevel@tonic-gate return (1); 5330Sstevel@tonic-gate } 5340Sstevel@tonic-gate 5350Sstevel@tonic-gate /* 5360Sstevel@tonic-gate * Invalid sections produce a warning and are skipped. 5370Sstevel@tonic-gate */ 5381618Srie static uintptr_t 5390Sstevel@tonic-gate /* ARGSUSED3 */ 5400Sstevel@tonic-gate invalid_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 5410Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 5420Sstevel@tonic-gate { 5434734Sab196087 Conv_inv_buf_t inv_buf; 5444734Sab196087 5451618Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_INVALSEC), 5461618Srie ifl->ifl_name, name, conv_sec_type(ifl->ifl_ehdr->e_machine, 5474734Sab196087 shdr->sh_type, 0, &inv_buf)); 5480Sstevel@tonic-gate return (1); 5490Sstevel@tonic-gate } 5500Sstevel@tonic-gate 5510Sstevel@tonic-gate /* 5520Sstevel@tonic-gate * Process a progbits section. 5530Sstevel@tonic-gate */ 5541618Srie static uintptr_t 5550Sstevel@tonic-gate process_progbits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 5560Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 5570Sstevel@tonic-gate { 558*9085SAli.Bahrami@Sun.COM int stab_index = 0; 559*9085SAli.Bahrami@Sun.COM Word is_flags = 0; 560*9085SAli.Bahrami@Sun.COM uintptr_t r; 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate /* 5630Sstevel@tonic-gate * Never include .stab.excl sections in any output file. 5640Sstevel@tonic-gate * If the -s flag has been specified strip any .stab sections. 5650Sstevel@tonic-gate */ 5660Sstevel@tonic-gate if (ident && (strncmp(name, MSG_ORIG(MSG_SCN_STAB), 5670Sstevel@tonic-gate MSG_SCN_STAB_SIZE) == 0)) { 5680Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STRIP) || 5690Sstevel@tonic-gate (strcmp((name + MSG_SCN_STAB_SIZE), 5704716Sab196087 MSG_ORIG(MSG_SCN_EXCL)) == 0)) 5710Sstevel@tonic-gate return (1); 5720Sstevel@tonic-gate 5730Sstevel@tonic-gate if (strcmp((name + MSG_SCN_STAB_SIZE), 5740Sstevel@tonic-gate MSG_ORIG(MSG_SCN_INDEX)) == 0) 5750Sstevel@tonic-gate stab_index = 1; 5760Sstevel@tonic-gate } 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STRIP) && ident) { 5790Sstevel@tonic-gate if ((strncmp(name, MSG_ORIG(MSG_SCN_DEBUG), 5800Sstevel@tonic-gate MSG_SCN_DEBUG_SIZE) == 0) || 5810Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_LINE)) == 0)) 5820Sstevel@tonic-gate return (1); 5830Sstevel@tonic-gate } 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate /* 5860Sstevel@tonic-gate * Update the ident to reflect the type of section we've got. 5870Sstevel@tonic-gate * 5880Sstevel@tonic-gate * If there is any .plt or .got section to generate we'll be creating 5890Sstevel@tonic-gate * our own version, so don't allow any input sections of these types to 5900Sstevel@tonic-gate * be added to the output section list (why a relocatable object would 5910Sstevel@tonic-gate * have a .plt or .got is a mystery, but stranger things have occurred). 592*9085SAli.Bahrami@Sun.COM * 593*9085SAli.Bahrami@Sun.COM * If there are any unwind sections, and this is a platform that uses 594*9085SAli.Bahrami@Sun.COM * SHT_PROGBITS for unwind sections, then set their ident to reflect 595*9085SAli.Bahrami@Sun.COM * that. 5960Sstevel@tonic-gate */ 5970Sstevel@tonic-gate if (ident) { 598*9085SAli.Bahrami@Sun.COM if (shdr->sh_flags & SHF_TLS) { 5996206Sab196087 ident = ld_targ.t_id.id_tls; 600*9085SAli.Bahrami@Sun.COM } else if ((shdr->sh_flags & ~ALL_SHF_IGNORE) == 601*9085SAli.Bahrami@Sun.COM (SHF_ALLOC | SHF_EXECINSTR)) { 6026206Sab196087 ident = ld_targ.t_id.id_text; 603*9085SAli.Bahrami@Sun.COM } else if (shdr->sh_flags & SHF_ALLOC) { 604*9085SAli.Bahrami@Sun.COM int done = 0; 605*9085SAli.Bahrami@Sun.COM 606*9085SAli.Bahrami@Sun.COM if (name[0] == '.') { 607*9085SAli.Bahrami@Sun.COM switch (name[1]) { 608*9085SAli.Bahrami@Sun.COM case 'e': 609*9085SAli.Bahrami@Sun.COM if ((ld_targ.t_m.m_sht_unwind == 610*9085SAli.Bahrami@Sun.COM SHT_PROGBITS) && 611*9085SAli.Bahrami@Sun.COM (strcmp(name, 612*9085SAli.Bahrami@Sun.COM MSG_ORIG(MSG_SCN_EHFRAME)) == 0)) { 613*9085SAli.Bahrami@Sun.COM ident = ld_targ.t_id.id_unwind; 614*9085SAli.Bahrami@Sun.COM is_flags = FLG_IS_EHFRAME; 615*9085SAli.Bahrami@Sun.COM done = 1; 616*9085SAli.Bahrami@Sun.COM } 617*9085SAli.Bahrami@Sun.COM break; 618*9085SAli.Bahrami@Sun.COM case 'g': 619*9085SAli.Bahrami@Sun.COM if (strcmp(name, 620*9085SAli.Bahrami@Sun.COM MSG_ORIG(MSG_SCN_GOT)) == 0) { 621*9085SAli.Bahrami@Sun.COM ident = ld_targ.t_id.id_null; 622*9085SAli.Bahrami@Sun.COM done = 1; 623*9085SAli.Bahrami@Sun.COM break; 624*9085SAli.Bahrami@Sun.COM } 625*9085SAli.Bahrami@Sun.COM if ((ld_targ.t_m.m_sht_unwind == 626*9085SAli.Bahrami@Sun.COM SHT_PROGBITS)&& 627*9085SAli.Bahrami@Sun.COM (strcmp(name, 628*9085SAli.Bahrami@Sun.COM MSG_ORIG(MSG_SCN_GCC_X_TBL)) == 629*9085SAli.Bahrami@Sun.COM 0)) { 630*9085SAli.Bahrami@Sun.COM ident = ld_targ.t_id.id_unwind; 631*9085SAli.Bahrami@Sun.COM done = 1; 632*9085SAli.Bahrami@Sun.COM break; 633*9085SAli.Bahrami@Sun.COM } 634*9085SAli.Bahrami@Sun.COM break; 635*9085SAli.Bahrami@Sun.COM case 'p': 636*9085SAli.Bahrami@Sun.COM if (strcmp(name, 637*9085SAli.Bahrami@Sun.COM MSG_ORIG(MSG_SCN_PLT)) == 0) { 638*9085SAli.Bahrami@Sun.COM ident = ld_targ.t_id.id_null; 639*9085SAli.Bahrami@Sun.COM done = 1; 640*9085SAli.Bahrami@Sun.COM } 641*9085SAli.Bahrami@Sun.COM break; 642*9085SAli.Bahrami@Sun.COM } 643*9085SAli.Bahrami@Sun.COM } 644*9085SAli.Bahrami@Sun.COM if (!done) { 645*9085SAli.Bahrami@Sun.COM if (stab_index) { 646*9085SAli.Bahrami@Sun.COM /* 647*9085SAli.Bahrami@Sun.COM * This is a work-around for x86 648*9085SAli.Bahrami@Sun.COM * compilers that have set SHF_ALLOC 649*9085SAli.Bahrami@Sun.COM * for the .stab.index section. 650*9085SAli.Bahrami@Sun.COM * 651*9085SAli.Bahrami@Sun.COM * Because of this, make sure that the 652*9085SAli.Bahrami@Sun.COM * .stab.index does not end up as the 653*9085SAli.Bahrami@Sun.COM * last section in the text segment. 654*9085SAli.Bahrami@Sun.COM * Older linkers can produce 655*9085SAli.Bahrami@Sun.COM * segmentation violations when they 656*9085SAli.Bahrami@Sun.COM * strip (ld -s) against a shared 657*9085SAli.Bahrami@Sun.COM * object whose last section in the 658*9085SAli.Bahrami@Sun.COM * text segment is a .stab. 659*9085SAli.Bahrami@Sun.COM */ 660*9085SAli.Bahrami@Sun.COM ident = ld_targ.t_id.id_interp; 661*9085SAli.Bahrami@Sun.COM } else { 662*9085SAli.Bahrami@Sun.COM ident = ld_targ.t_id.id_data; 663*9085SAli.Bahrami@Sun.COM } 664*9085SAli.Bahrami@Sun.COM } 6650Sstevel@tonic-gate } else 6666206Sab196087 ident = ld_targ.t_id.id_note; 6670Sstevel@tonic-gate } 668*9085SAli.Bahrami@Sun.COM 669*9085SAli.Bahrami@Sun.COM r = process_section(name, ifl, shdr, scn, ndx, ident, ofl); 670*9085SAli.Bahrami@Sun.COM 671*9085SAli.Bahrami@Sun.COM /* 672*9085SAli.Bahrami@Sun.COM * On success, process_section() creates an input section descriptor. 673*9085SAli.Bahrami@Sun.COM * Now that it exists, we can add any pending input section flags. 674*9085SAli.Bahrami@Sun.COM */ 675*9085SAli.Bahrami@Sun.COM if ((is_flags != 0) && (r == 1)) 676*9085SAli.Bahrami@Sun.COM ifl->ifl_isdesc[ndx]->is_flags |= is_flags; 677*9085SAli.Bahrami@Sun.COM 678*9085SAli.Bahrami@Sun.COM return (r); 6790Sstevel@tonic-gate } 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate /* 6820Sstevel@tonic-gate * Handles the SHT_SUNW_{DEBUG,DEBUGSTR) sections. 6830Sstevel@tonic-gate */ 6841618Srie static uintptr_t 6850Sstevel@tonic-gate process_debug(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 6860Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 6870Sstevel@tonic-gate { 6880Sstevel@tonic-gate /* 6890Sstevel@tonic-gate * Debug information is discarded when the 'ld -s' flag is invoked. 6900Sstevel@tonic-gate */ 6910Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_STRIP) { 6920Sstevel@tonic-gate return (1); 6930Sstevel@tonic-gate } 6940Sstevel@tonic-gate return (process_progbits(name, ifl, shdr, scn, ndx, ident, ofl)); 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate /* 6980Sstevel@tonic-gate * Process a nobits section. 6990Sstevel@tonic-gate */ 7001618Srie static uintptr_t 7010Sstevel@tonic-gate process_nobits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 7020Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 7030Sstevel@tonic-gate { 7040Sstevel@tonic-gate if (ident) { 7050Sstevel@tonic-gate if (shdr->sh_flags & SHF_TLS) 7066206Sab196087 ident = ld_targ.t_id.id_tlsbss; 7076206Sab196087 #if defined(_ELF64) 7086206Sab196087 else if ((shdr->sh_flags & SHF_AMD64_LARGE) && 7096206Sab196087 (ld_targ.t_m.m_mach == EM_AMD64)) 7106206Sab196087 ident = ld_targ.t_id.id_lbss; 711574Sseizo #endif 7120Sstevel@tonic-gate else 7136206Sab196087 ident = ld_targ.t_id.id_bss; 7140Sstevel@tonic-gate } 7150Sstevel@tonic-gate return (process_section(name, ifl, shdr, scn, ndx, ident, ofl)); 7160Sstevel@tonic-gate } 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate /* 7190Sstevel@tonic-gate * Process a SHT_*_ARRAY section. 7200Sstevel@tonic-gate */ 7211618Srie static uintptr_t 7220Sstevel@tonic-gate process_array(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 7230Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 7240Sstevel@tonic-gate { 7257463SRod.Evans@Sun.COM uintptr_t error; 7260Sstevel@tonic-gate 7270Sstevel@tonic-gate if (ident) 7286206Sab196087 ident = ld_targ.t_id.id_array; 7290Sstevel@tonic-gate 7307463SRod.Evans@Sun.COM error = process_section(name, ifl, shdr, scn, ndx, ident, ofl); 7317463SRod.Evans@Sun.COM if ((error == 0) || (error == S_ERROR)) 7327463SRod.Evans@Sun.COM return (error); 7337463SRod.Evans@Sun.COM 7347463SRod.Evans@Sun.COM return (1); 7357463SRod.Evans@Sun.COM } 7360Sstevel@tonic-gate 7377463SRod.Evans@Sun.COM static uintptr_t 7387463SRod.Evans@Sun.COM /* ARGSUSED1 */ 7397463SRod.Evans@Sun.COM array_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl) 7407463SRod.Evans@Sun.COM { 7417463SRod.Evans@Sun.COM Os_desc *osp; 7427463SRod.Evans@Sun.COM Shdr *shdr; 7437463SRod.Evans@Sun.COM 7447463SRod.Evans@Sun.COM if ((isc == NULL) || ((osp = isc->is_osdesc) == NULL)) 7450Sstevel@tonic-gate return (0); 7460Sstevel@tonic-gate 7477463SRod.Evans@Sun.COM shdr = isc->is_shdr; 7487463SRod.Evans@Sun.COM 7490Sstevel@tonic-gate if ((shdr->sh_type == SHT_FINI_ARRAY) && 7507463SRod.Evans@Sun.COM (ofl->ofl_osfiniarray == NULL)) 7510Sstevel@tonic-gate ofl->ofl_osfiniarray = osp; 7520Sstevel@tonic-gate else if ((shdr->sh_type == SHT_INIT_ARRAY) && 7537463SRod.Evans@Sun.COM (ofl->ofl_osinitarray == NULL)) 7540Sstevel@tonic-gate ofl->ofl_osinitarray = osp; 7550Sstevel@tonic-gate else if ((shdr->sh_type == SHT_PREINIT_ARRAY) && 7567463SRod.Evans@Sun.COM (ofl->ofl_ospreinitarray == NULL)) 7570Sstevel@tonic-gate ofl->ofl_ospreinitarray = osp; 7580Sstevel@tonic-gate 7590Sstevel@tonic-gate return (1); 7600Sstevel@tonic-gate } 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate /* 7630Sstevel@tonic-gate * Process a SHT_SYMTAB_SHNDX section. 7640Sstevel@tonic-gate */ 7651618Srie static uintptr_t 7660Sstevel@tonic-gate process_sym_shndx(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 7670Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 7680Sstevel@tonic-gate { 7690Sstevel@tonic-gate if (process_input(name, ifl, shdr, scn, ndx, ident, ofl) == S_ERROR) 7700Sstevel@tonic-gate return (S_ERROR); 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate /* 7730Sstevel@tonic-gate * Have we already seen the related SYMTAB - if so verify it now. 7740Sstevel@tonic-gate */ 7750Sstevel@tonic-gate if (shdr->sh_link < ndx) { 7760Sstevel@tonic-gate Is_desc *isp = ifl->ifl_isdesc[shdr->sh_link]; 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate if ((isp == 0) || ((isp->is_shdr->sh_type != SHT_SYMTAB) && 7790Sstevel@tonic-gate (isp->is_shdr->sh_type != SHT_DYNSYM))) { 7801618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 7811618Srie MSG_INTL(MSG_FIL_INVSHLINK), ifl->ifl_name, name, 7821618Srie EC_XWORD(shdr->sh_link)); 7830Sstevel@tonic-gate return (S_ERROR); 7840Sstevel@tonic-gate } 7850Sstevel@tonic-gate isp->is_symshndx = ifl->ifl_isdesc[ndx]; 7860Sstevel@tonic-gate } 7870Sstevel@tonic-gate return (1); 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate /* 7910Sstevel@tonic-gate * Final processing for SHT_SYMTAB_SHNDX section. 7920Sstevel@tonic-gate */ 7931618Srie static uintptr_t 7940Sstevel@tonic-gate /* ARGSUSED2 */ 7950Sstevel@tonic-gate sym_shndx_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl) 7960Sstevel@tonic-gate { 7970Sstevel@tonic-gate if (isc->is_shdr->sh_link > isc->is_scnndx) { 7980Sstevel@tonic-gate Is_desc *isp = ifl->ifl_isdesc[isc->is_shdr->sh_link]; 7990Sstevel@tonic-gate 8000Sstevel@tonic-gate if ((isp == 0) || ((isp->is_shdr->sh_type != SHT_SYMTAB) && 8010Sstevel@tonic-gate (isp->is_shdr->sh_type != SHT_DYNSYM))) { 8021618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 8031618Srie MSG_INTL(MSG_FIL_INVSHLINK), isc->is_file->ifl_name, 8041618Srie isc->is_name, EC_XWORD(isc->is_shdr->sh_link)); 8050Sstevel@tonic-gate return (S_ERROR); 8060Sstevel@tonic-gate } 8070Sstevel@tonic-gate isp->is_symshndx = isc; 8080Sstevel@tonic-gate } 8090Sstevel@tonic-gate return (1); 8100Sstevel@tonic-gate } 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate /* 8130Sstevel@tonic-gate * Process .dynamic section from a relocatable object. 8140Sstevel@tonic-gate * 8150Sstevel@tonic-gate * Note: That the .dynamic section is only considered interesting when 8160Sstevel@tonic-gate * dlopen()ing a relocatable object (thus FLG_OF1_RELDYN can only get 8170Sstevel@tonic-gate * set when libld is called from ld.so.1). 8180Sstevel@tonic-gate */ 8190Sstevel@tonic-gate /*ARGSUSED*/ 8201618Srie static uintptr_t 8210Sstevel@tonic-gate process_rel_dynamic(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 8220Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 8230Sstevel@tonic-gate { 8240Sstevel@tonic-gate Dyn *dyn; 8250Sstevel@tonic-gate Elf_Scn *strscn; 8260Sstevel@tonic-gate Elf_Data *dp; 8270Sstevel@tonic-gate char *str; 8280Sstevel@tonic-gate 8290Sstevel@tonic-gate /* 8300Sstevel@tonic-gate * Process .dynamic sections from relocatable objects ? 8310Sstevel@tonic-gate */ 8320Sstevel@tonic-gate if ((ofl->ofl_flags1 & FLG_OF1_RELDYN) == 0) 8330Sstevel@tonic-gate return (1); 8340Sstevel@tonic-gate 8350Sstevel@tonic-gate /* 8360Sstevel@tonic-gate * Find the string section associated with the .dynamic section. 8370Sstevel@tonic-gate */ 8380Sstevel@tonic-gate if ((strscn = elf_getscn(ifl->ifl_elf, shdr->sh_link)) == NULL) { 8391618Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN), 8401618Srie ifl->ifl_name); 8410Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 8420Sstevel@tonic-gate return (0); 8430Sstevel@tonic-gate } 8440Sstevel@tonic-gate dp = elf_getdata(strscn, NULL); 8450Sstevel@tonic-gate str = (char *)dp->d_buf; 8460Sstevel@tonic-gate 8470Sstevel@tonic-gate /* 8480Sstevel@tonic-gate * And get the .dynamic data 8490Sstevel@tonic-gate */ 8500Sstevel@tonic-gate dp = elf_getdata(scn, NULL); 8510Sstevel@tonic-gate 8520Sstevel@tonic-gate for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) { 8531109Srie Ifl_desc *difl; 8540Sstevel@tonic-gate 8550Sstevel@tonic-gate switch (dyn->d_tag) { 8560Sstevel@tonic-gate case DT_NEEDED: 8570Sstevel@tonic-gate case DT_USED: 8581109Srie if (((difl = 8591109Srie libld_calloc(1, sizeof (Ifl_desc))) == 0) || 8601109Srie (list_appendc(&ofl->ofl_sos, difl) == 0)) 8610Sstevel@tonic-gate return (S_ERROR); 8621109Srie 8631109Srie difl->ifl_name = MSG_ORIG(MSG_STR_DYNAMIC); 8641109Srie difl->ifl_soname = str + (size_t)dyn->d_un.d_val; 8651109Srie difl->ifl_flags = FLG_IF_NEEDSTR; 8660Sstevel@tonic-gate break; 8670Sstevel@tonic-gate case DT_RPATH: 8680Sstevel@tonic-gate case DT_RUNPATH: 8690Sstevel@tonic-gate if ((ofl->ofl_rpath = add_string(ofl->ofl_rpath, 8700Sstevel@tonic-gate (str + (size_t)dyn->d_un.d_val))) == 8710Sstevel@tonic-gate (const char *)S_ERROR) 8720Sstevel@tonic-gate return (S_ERROR); 8730Sstevel@tonic-gate break; 8744716Sab196087 case DT_VERSYM: 8754716Sab196087 /* 8764716Sab196087 * The Solaris ld does not put DT_VERSYM in the 8774716Sab196087 * dynamic section. If the object has DT_VERSYM, 8784716Sab196087 * then it must have been produced by the GNU ld, 8794716Sab196087 * and is using the GNU style of versioning. 8804716Sab196087 */ 8814716Sab196087 ifl->ifl_flags |= FLG_IF_GNUVER; 8824716Sab196087 break; 8830Sstevel@tonic-gate } 8840Sstevel@tonic-gate } 8850Sstevel@tonic-gate return (1); 8860Sstevel@tonic-gate } 8870Sstevel@tonic-gate 8880Sstevel@tonic-gate /* 8890Sstevel@tonic-gate * Expand implicit references. Dependencies can be specified in terms of the 8900Sstevel@tonic-gate * $ORIGIN, $PLATFORM, $OSREL and $OSNAME tokens, either from their needed name, 8910Sstevel@tonic-gate * or via a runpath. In addition runpaths may also specify the $ISALIST token. 8920Sstevel@tonic-gate * 8931109Srie * Probably the most common reference to explicit dependencies (via -L) will be 8940Sstevel@tonic-gate * sufficient to find any associated implicit dependencies, but just in case we 8950Sstevel@tonic-gate * expand any occurrence of these known tokens here. 8960Sstevel@tonic-gate * 8970Sstevel@tonic-gate * Note, if any errors occur we simply return the original name. 8980Sstevel@tonic-gate * 8990Sstevel@tonic-gate * This code is remarkably similar to expand() in rtld/common/paths.c. 9000Sstevel@tonic-gate */ 9010Sstevel@tonic-gate static char *platform = 0; 9020Sstevel@tonic-gate static size_t platform_sz = 0; 9030Sstevel@tonic-gate static Isa_desc *isa = 0; 9040Sstevel@tonic-gate static Uts_desc *uts = 0; 9050Sstevel@tonic-gate 9060Sstevel@tonic-gate static char * 9070Sstevel@tonic-gate expand(const char *parent, const char *name, char **next) 9080Sstevel@tonic-gate { 9090Sstevel@tonic-gate char _name[PATH_MAX], *nptr, *_next; 9100Sstevel@tonic-gate const char *optr; 9110Sstevel@tonic-gate size_t nrem = PATH_MAX - 1; 9120Sstevel@tonic-gate int expanded = 0, _expanded, isaflag = 0; 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate optr = name; 9150Sstevel@tonic-gate nptr = _name; 9160Sstevel@tonic-gate 9170Sstevel@tonic-gate while (*optr) { 9180Sstevel@tonic-gate if (nrem == 0) 9190Sstevel@tonic-gate return ((char *)name); 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate if (*optr != '$') { 9220Sstevel@tonic-gate *nptr++ = *optr++, nrem--; 9230Sstevel@tonic-gate continue; 9240Sstevel@tonic-gate } 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate _expanded = 0; 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate if (strncmp(optr, MSG_ORIG(MSG_STR_ORIGIN), 9290Sstevel@tonic-gate MSG_STR_ORIGIN_SIZE) == 0) { 9300Sstevel@tonic-gate char *eptr; 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate /* 9330Sstevel@tonic-gate * For $ORIGIN, expansion is really just a concatenation 9340Sstevel@tonic-gate * of the parents directory name. For example, an 9351109Srie * explicit dependency foo/bar/lib1.so with a dependency 9360Sstevel@tonic-gate * on $ORIGIN/lib2.so would be expanded to 9370Sstevel@tonic-gate * foo/bar/lib2.so. 9380Sstevel@tonic-gate */ 9390Sstevel@tonic-gate if ((eptr = strrchr(parent, '/')) == 0) { 9400Sstevel@tonic-gate *nptr++ = '.'; 9410Sstevel@tonic-gate nrem--; 9420Sstevel@tonic-gate } else { 9430Sstevel@tonic-gate size_t len = eptr - parent; 9440Sstevel@tonic-gate 9450Sstevel@tonic-gate if (len >= nrem) 9460Sstevel@tonic-gate return ((char *)name); 9470Sstevel@tonic-gate 9480Sstevel@tonic-gate (void) strncpy(nptr, parent, len); 9490Sstevel@tonic-gate nptr = nptr + len; 9500Sstevel@tonic-gate nrem -= len; 9510Sstevel@tonic-gate } 9520Sstevel@tonic-gate optr += MSG_STR_ORIGIN_SIZE; 9530Sstevel@tonic-gate expanded = _expanded = 1; 9540Sstevel@tonic-gate 9550Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_PLATFORM), 9560Sstevel@tonic-gate MSG_STR_PLATFORM_SIZE) == 0) { 9570Sstevel@tonic-gate /* 9580Sstevel@tonic-gate * Establish the platform from sysconf - like uname -i. 9590Sstevel@tonic-gate */ 9600Sstevel@tonic-gate if ((platform == 0) && (platform_sz == 0)) { 9610Sstevel@tonic-gate char info[SYS_NMLN]; 9620Sstevel@tonic-gate long size; 9630Sstevel@tonic-gate 9640Sstevel@tonic-gate size = sysinfo(SI_PLATFORM, info, SYS_NMLN); 9650Sstevel@tonic-gate if ((size != -1) && 9660Sstevel@tonic-gate (platform = libld_malloc((size_t)size))) { 9670Sstevel@tonic-gate (void) strcpy(platform, info); 9680Sstevel@tonic-gate platform_sz = (size_t)size - 1; 9690Sstevel@tonic-gate } else 9700Sstevel@tonic-gate platform_sz = 1; 9710Sstevel@tonic-gate } 9720Sstevel@tonic-gate if (platform != 0) { 9730Sstevel@tonic-gate if (platform_sz >= nrem) 9740Sstevel@tonic-gate return ((char *)name); 9750Sstevel@tonic-gate 9760Sstevel@tonic-gate (void) strncpy(nptr, platform, platform_sz); 9770Sstevel@tonic-gate nptr = nptr + platform_sz; 9780Sstevel@tonic-gate nrem -= platform_sz; 9790Sstevel@tonic-gate 9800Sstevel@tonic-gate optr += MSG_STR_PLATFORM_SIZE; 9810Sstevel@tonic-gate expanded = _expanded = 1; 9820Sstevel@tonic-gate } 9830Sstevel@tonic-gate 9840Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_OSNAME), 9850Sstevel@tonic-gate MSG_STR_OSNAME_SIZE) == 0) { 9860Sstevel@tonic-gate /* 9870Sstevel@tonic-gate * Establish the os name - like uname -s. 9880Sstevel@tonic-gate */ 9890Sstevel@tonic-gate if (uts == 0) 9900Sstevel@tonic-gate uts = conv_uts(); 9910Sstevel@tonic-gate 9920Sstevel@tonic-gate if (uts && uts->uts_osnamesz) { 9930Sstevel@tonic-gate if (uts->uts_osnamesz >= nrem) 9940Sstevel@tonic-gate return ((char *)name); 9950Sstevel@tonic-gate 9960Sstevel@tonic-gate (void) strncpy(nptr, uts->uts_osname, 9970Sstevel@tonic-gate uts->uts_osnamesz); 9980Sstevel@tonic-gate nptr = nptr + uts->uts_osnamesz; 9990Sstevel@tonic-gate nrem -= uts->uts_osnamesz; 10000Sstevel@tonic-gate 10010Sstevel@tonic-gate optr += MSG_STR_OSNAME_SIZE; 10020Sstevel@tonic-gate expanded = _expanded = 1; 10030Sstevel@tonic-gate } 10040Sstevel@tonic-gate 10050Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_OSREL), 10060Sstevel@tonic-gate MSG_STR_OSREL_SIZE) == 0) { 10070Sstevel@tonic-gate /* 10080Sstevel@tonic-gate * Establish the os release - like uname -r. 10090Sstevel@tonic-gate */ 10100Sstevel@tonic-gate if (uts == 0) 10110Sstevel@tonic-gate uts = conv_uts(); 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate if (uts && uts->uts_osrelsz) { 10140Sstevel@tonic-gate if (uts->uts_osrelsz >= nrem) 10150Sstevel@tonic-gate return ((char *)name); 10160Sstevel@tonic-gate 10170Sstevel@tonic-gate (void) strncpy(nptr, uts->uts_osrel, 10180Sstevel@tonic-gate uts->uts_osrelsz); 10190Sstevel@tonic-gate nptr = nptr + uts->uts_osrelsz; 10200Sstevel@tonic-gate nrem -= uts->uts_osrelsz; 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate optr += MSG_STR_OSREL_SIZE; 10230Sstevel@tonic-gate expanded = _expanded = 1; 10240Sstevel@tonic-gate } 10250Sstevel@tonic-gate 10260Sstevel@tonic-gate } else if ((strncmp(optr, MSG_ORIG(MSG_STR_ISALIST), 10270Sstevel@tonic-gate MSG_STR_ISALIST_SIZE) == 0) && next && (isaflag++ == 0)) { 10280Sstevel@tonic-gate /* 10290Sstevel@tonic-gate * Establish instruction sets from sysconf. Note that 10300Sstevel@tonic-gate * this is only meaningful from runpaths. 10310Sstevel@tonic-gate */ 10320Sstevel@tonic-gate if (isa == 0) 10330Sstevel@tonic-gate isa = conv_isalist(); 10340Sstevel@tonic-gate 10350Sstevel@tonic-gate if (isa && isa->isa_listsz && 10360Sstevel@tonic-gate (nrem > isa->isa_opt->isa_namesz)) { 10370Sstevel@tonic-gate size_t mlen, tlen, hlen = optr - name; 10380Sstevel@tonic-gate size_t no; 10390Sstevel@tonic-gate char *lptr; 10400Sstevel@tonic-gate Isa_opt *opt = isa->isa_opt; 10410Sstevel@tonic-gate 10420Sstevel@tonic-gate (void) strncpy(nptr, opt->isa_name, 10430Sstevel@tonic-gate opt->isa_namesz); 10440Sstevel@tonic-gate nptr = nptr + opt->isa_namesz; 10450Sstevel@tonic-gate nrem -= opt->isa_namesz; 10460Sstevel@tonic-gate 10470Sstevel@tonic-gate optr += MSG_STR_ISALIST_SIZE; 10480Sstevel@tonic-gate expanded = _expanded = 1; 10490Sstevel@tonic-gate 10500Sstevel@tonic-gate tlen = strlen(optr); 10510Sstevel@tonic-gate 10520Sstevel@tonic-gate /* 10530Sstevel@tonic-gate * As ISALIST expands to a number of elements, 10540Sstevel@tonic-gate * establish a new list to return to the caller. 10550Sstevel@tonic-gate * This will contain the present path being 10560Sstevel@tonic-gate * processed redefined for each isalist option, 10570Sstevel@tonic-gate * plus the original remaining list entries. 10580Sstevel@tonic-gate */ 10590Sstevel@tonic-gate mlen = ((hlen + tlen) * (isa->isa_optno - 1)) + 10600Sstevel@tonic-gate isa->isa_listsz - opt->isa_namesz; 10610Sstevel@tonic-gate if (*next) 10624716Sab196087 mlen += strlen(*next); 10630Sstevel@tonic-gate if ((_next = lptr = libld_malloc(mlen)) == 0) 10640Sstevel@tonic-gate return (0); 10650Sstevel@tonic-gate 10660Sstevel@tonic-gate for (no = 1, opt++; no < isa->isa_optno; 10670Sstevel@tonic-gate no++, opt++) { 10680Sstevel@tonic-gate (void) strncpy(lptr, name, hlen); 10690Sstevel@tonic-gate lptr = lptr + hlen; 10700Sstevel@tonic-gate (void) strncpy(lptr, opt->isa_name, 10710Sstevel@tonic-gate opt->isa_namesz); 10720Sstevel@tonic-gate lptr = lptr + opt->isa_namesz; 10730Sstevel@tonic-gate (void) strncpy(lptr, optr, tlen); 10740Sstevel@tonic-gate lptr = lptr + tlen; 10750Sstevel@tonic-gate *lptr++ = ':'; 10760Sstevel@tonic-gate } 10770Sstevel@tonic-gate if (*next) 10780Sstevel@tonic-gate (void) strcpy(lptr, *next); 10790Sstevel@tonic-gate else 10800Sstevel@tonic-gate *--lptr = '\0'; 10810Sstevel@tonic-gate } 10820Sstevel@tonic-gate } 10830Sstevel@tonic-gate 10840Sstevel@tonic-gate /* 10850Sstevel@tonic-gate * If no expansion occurred skip the $ and continue. 10860Sstevel@tonic-gate */ 10870Sstevel@tonic-gate if (_expanded == 0) 10880Sstevel@tonic-gate *nptr++ = *optr++, nrem--; 10890Sstevel@tonic-gate } 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate /* 10920Sstevel@tonic-gate * If any ISALIST processing has occurred not only do we return the 10930Sstevel@tonic-gate * expanded node we're presently working on, but we must also update the 10940Sstevel@tonic-gate * remaining list so that it is effectively prepended with this node 10950Sstevel@tonic-gate * expanded to all remaining isalist options. Note that we can only 10960Sstevel@tonic-gate * handle one ISALIST per node. For more than one ISALIST to be 10970Sstevel@tonic-gate * processed we'd need a better algorithm than above to replace the 10980Sstevel@tonic-gate * newly generated list. Whether we want to encourage the number of 10990Sstevel@tonic-gate * pathname permutations this would provide is another question. So, for 11000Sstevel@tonic-gate * now if more than one ISALIST is encountered we return the original 11010Sstevel@tonic-gate * node untouched. 11020Sstevel@tonic-gate */ 11030Sstevel@tonic-gate if (isaflag) { 11040Sstevel@tonic-gate if (isaflag == 1) 11050Sstevel@tonic-gate *next = _next; 11060Sstevel@tonic-gate else 11070Sstevel@tonic-gate return ((char *)name); 11080Sstevel@tonic-gate } 11090Sstevel@tonic-gate 11100Sstevel@tonic-gate *nptr = '\0'; 11110Sstevel@tonic-gate 11120Sstevel@tonic-gate if (expanded) { 11130Sstevel@tonic-gate if ((nptr = libld_malloc(strlen(_name) + 1)) == 0) 11140Sstevel@tonic-gate return ((char *)name); 11150Sstevel@tonic-gate (void) strcpy(nptr, _name); 11160Sstevel@tonic-gate return (nptr); 11170Sstevel@tonic-gate } 11180Sstevel@tonic-gate return ((char *)name); 11190Sstevel@tonic-gate } 11200Sstevel@tonic-gate 11210Sstevel@tonic-gate /* 11224716Sab196087 * The Solaris ld does not put DT_VERSYM in the dynamic section, but the 11234716Sab196087 * GNU ld does, and it is used by the runtime linker to implement their 11244716Sab196087 * versioning scheme. Use this fact to determine if the sharable object 11254716Sab196087 * was produced by the GNU ld rather than the Solaris one, and to set 11264716Sab196087 * FLG_IF_GNUVER if so. This needs to be done before the symbols are 11274716Sab196087 * processed, since the answer determines whether we interpret the 11284716Sab196087 * symbols versions according to Solaris or GNU rules. 11294716Sab196087 */ 11304716Sab196087 /*ARGSUSED*/ 11314716Sab196087 static uintptr_t 11324716Sab196087 process_dynamic_isgnu(const char *name, Ifl_desc *ifl, Shdr *shdr, 11334716Sab196087 Elf_Scn *scn, Word ndx, int ident, Ofl_desc *ofl) 11344716Sab196087 { 11354716Sab196087 Dyn *dyn; 11364716Sab196087 Elf_Data *dp; 11377463SRod.Evans@Sun.COM uintptr_t error; 11384716Sab196087 11397463SRod.Evans@Sun.COM error = process_section(name, ifl, shdr, scn, ndx, ident, ofl); 11407463SRod.Evans@Sun.COM if ((error == 0) || (error == S_ERROR)) 11417463SRod.Evans@Sun.COM return (error); 11424716Sab196087 11434716Sab196087 /* Get the .dynamic data */ 11444716Sab196087 dp = elf_getdata(scn, NULL); 11454716Sab196087 11464716Sab196087 for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) { 11474716Sab196087 if (dyn->d_tag == DT_VERSYM) { 11484716Sab196087 ifl->ifl_flags |= FLG_IF_GNUVER; 11494716Sab196087 break; 11504716Sab196087 } 11514716Sab196087 } 11524716Sab196087 return (1); 11534716Sab196087 } 11544716Sab196087 11554716Sab196087 /* 11560Sstevel@tonic-gate * Process a dynamic section. If we are processing an explicit shared object 11570Sstevel@tonic-gate * then we need to determine if it has a recorded SONAME, if so, this name will 11580Sstevel@tonic-gate * be recorded in the output file being generated as the NEEDED entry rather 11590Sstevel@tonic-gate * than the shared objects filename itself. 11600Sstevel@tonic-gate * If the mode of the link-edit indicates that no undefined symbols should 11610Sstevel@tonic-gate * remain, then we also need to build up a list of any additional shared object 11620Sstevel@tonic-gate * dependencies this object may have. In this case save any NEEDED entries 11630Sstevel@tonic-gate * together with any associated run-path specifications. This information is 11640Sstevel@tonic-gate * recorded on the `ofl_soneed' list and will be analyzed after all explicit 11650Sstevel@tonic-gate * file processing has been completed (refer finish_libs()). 11660Sstevel@tonic-gate */ 11671618Srie static uintptr_t 11680Sstevel@tonic-gate process_dynamic(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl) 11690Sstevel@tonic-gate { 11700Sstevel@tonic-gate Dyn *data, *dyn; 11710Sstevel@tonic-gate char *str, *rpath = NULL; 11720Sstevel@tonic-gate const char *soname, *needed; 11730Sstevel@tonic-gate Sdf_desc *sdf; 11740Sstevel@tonic-gate Listnode *lnp; 11750Sstevel@tonic-gate 11760Sstevel@tonic-gate data = (Dyn *)isc->is_indata->d_buf; 11770Sstevel@tonic-gate str = (char *)ifl->ifl_isdesc[isc->is_shdr->sh_link]->is_indata->d_buf; 11780Sstevel@tonic-gate 11790Sstevel@tonic-gate /* 11800Sstevel@tonic-gate * First loop through the dynamic section looking for a run path. 11810Sstevel@tonic-gate */ 11820Sstevel@tonic-gate if (ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)) { 11830Sstevel@tonic-gate for (dyn = data; dyn->d_tag != DT_NULL; dyn++) { 11840Sstevel@tonic-gate if ((dyn->d_tag != DT_RPATH) && 11850Sstevel@tonic-gate (dyn->d_tag != DT_RUNPATH)) 11860Sstevel@tonic-gate continue; 11870Sstevel@tonic-gate if ((rpath = str + (size_t)dyn->d_un.d_val) == NULL) 11880Sstevel@tonic-gate continue; 11890Sstevel@tonic-gate break; 11900Sstevel@tonic-gate } 11910Sstevel@tonic-gate } 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate /* 11940Sstevel@tonic-gate * Now look for any needed dependencies (which may use the rpath) 11950Sstevel@tonic-gate * or a new SONAME. 11960Sstevel@tonic-gate */ 11970Sstevel@tonic-gate for (dyn = data; dyn->d_tag != DT_NULL; dyn++) { 11980Sstevel@tonic-gate if (dyn->d_tag == DT_SONAME) { 11990Sstevel@tonic-gate if ((soname = str + (size_t)dyn->d_un.d_val) == NULL) 12000Sstevel@tonic-gate continue; 12010Sstevel@tonic-gate 12020Sstevel@tonic-gate /* 12030Sstevel@tonic-gate * Update the input file structure with this new name. 12040Sstevel@tonic-gate */ 12050Sstevel@tonic-gate ifl->ifl_soname = soname; 12060Sstevel@tonic-gate 12070Sstevel@tonic-gate } else if ((dyn->d_tag == DT_NEEDED) || 12080Sstevel@tonic-gate (dyn->d_tag == DT_USED)) { 12090Sstevel@tonic-gate if (!(ofl->ofl_flags & 12100Sstevel@tonic-gate (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC))) 12110Sstevel@tonic-gate continue; 12120Sstevel@tonic-gate if ((needed = str + (size_t)dyn->d_un.d_val) == NULL) 12130Sstevel@tonic-gate continue; 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate /* 12160Sstevel@tonic-gate * Determine if this needed entry is already recorded on 12170Sstevel@tonic-gate * the shared object needed list, if not create a new 12180Sstevel@tonic-gate * definition for later processing (see finish_libs()). 12190Sstevel@tonic-gate */ 12200Sstevel@tonic-gate needed = expand(ifl->ifl_name, needed, (char **)0); 12210Sstevel@tonic-gate 12220Sstevel@tonic-gate if ((sdf = sdf_find(needed, &ofl->ofl_soneed)) == 0) { 12230Sstevel@tonic-gate if ((sdf = sdf_add(needed, 12240Sstevel@tonic-gate &ofl->ofl_soneed)) == (Sdf_desc *)S_ERROR) 12250Sstevel@tonic-gate return (S_ERROR); 12260Sstevel@tonic-gate sdf->sdf_rfile = ifl->ifl_name; 12270Sstevel@tonic-gate } 12280Sstevel@tonic-gate 12290Sstevel@tonic-gate /* 12300Sstevel@tonic-gate * Record the runpath (Note that we take the first 12310Sstevel@tonic-gate * runpath which is exactly what ld.so.1 would do during 12320Sstevel@tonic-gate * its dependency processing). 12330Sstevel@tonic-gate */ 12340Sstevel@tonic-gate if (rpath && (sdf->sdf_rpath == 0)) 12350Sstevel@tonic-gate sdf->sdf_rpath = rpath; 12360Sstevel@tonic-gate 12370Sstevel@tonic-gate } else if (dyn->d_tag == DT_FLAGS_1) { 12380Sstevel@tonic-gate if (dyn->d_un.d_val & (DF_1_INITFIRST | DF_1_INTERPOSE)) 12390Sstevel@tonic-gate ifl->ifl_flags &= ~FLG_IF_LAZYLD; 12400Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_DISPRELPND) 12410Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DISPPEND; 12420Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_DISPRELDNE) 12430Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DISPDONE; 12440Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_NODIRECT) 12450Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_NODIRECT; 12460Sstevel@tonic-gate 12470Sstevel@tonic-gate } else if ((dyn->d_tag == DT_AUDIT) && 12480Sstevel@tonic-gate (ifl->ifl_flags & FLG_IF_NEEDED)) { 12490Sstevel@tonic-gate /* 12500Sstevel@tonic-gate * Record audit string as DT_DEPAUDIT. 12510Sstevel@tonic-gate */ 12520Sstevel@tonic-gate if ((ofl->ofl_depaudit = add_string(ofl->ofl_depaudit, 12530Sstevel@tonic-gate (str + (size_t)dyn->d_un.d_val))) == 12540Sstevel@tonic-gate (const char *)S_ERROR) 12550Sstevel@tonic-gate return (S_ERROR); 12560Sstevel@tonic-gate 12570Sstevel@tonic-gate } else if (dyn->d_tag == DT_SUNW_RTLDINF) { 12580Sstevel@tonic-gate /* 12590Sstevel@tonic-gate * If a library has the SUNW_RTLDINF .dynamic entry 12600Sstevel@tonic-gate * then we must not permit lazyloading of this library. 12610Sstevel@tonic-gate * This is because critical startup information (TLS 12620Sstevel@tonic-gate * routines) are provided as part of these interfaces 12630Sstevel@tonic-gate * and we must have them as part of process startup. 12640Sstevel@tonic-gate */ 12650Sstevel@tonic-gate ifl->ifl_flags &= ~FLG_IF_LAZYLD; 12660Sstevel@tonic-gate } 12670Sstevel@tonic-gate } 12680Sstevel@tonic-gate 12690Sstevel@tonic-gate /* 12700Sstevel@tonic-gate * Perform some SONAME sanity checks. 12710Sstevel@tonic-gate */ 12720Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_NEEDED) { 12737463SRod.Evans@Sun.COM Ifl_desc *sifl; 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate /* 12760Sstevel@tonic-gate * Determine if anyone else will cause the same SONAME to be 12770Sstevel@tonic-gate * used (this is either caused by two different files having the 12780Sstevel@tonic-gate * same SONAME, or by one file SONAME actually matching another 12790Sstevel@tonic-gate * file basename (if no SONAME is specified within a shared 12800Sstevel@tonic-gate * library its basename will be used)). Probably rare, but some 12810Sstevel@tonic-gate * idiot will do it. 12820Sstevel@tonic-gate */ 12830Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_sos, lnp, sifl)) { 12840Sstevel@tonic-gate if ((strcmp(ifl->ifl_soname, sifl->ifl_soname) == 0) && 12850Sstevel@tonic-gate (ifl != sifl)) { 12860Sstevel@tonic-gate const char *hint, *iflb, *siflb; 12870Sstevel@tonic-gate 12880Sstevel@tonic-gate /* 12890Sstevel@tonic-gate * Determine the basename of each file. Perhaps 12900Sstevel@tonic-gate * there are multiple copies of the same file 12910Sstevel@tonic-gate * being brought in using different -L search 12920Sstevel@tonic-gate * paths, and if so give an extra hint in the 12930Sstevel@tonic-gate * error message. 12940Sstevel@tonic-gate */ 12950Sstevel@tonic-gate iflb = strrchr(ifl->ifl_name, '/'); 12960Sstevel@tonic-gate if (iflb == NULL) 12970Sstevel@tonic-gate iflb = ifl->ifl_name; 12980Sstevel@tonic-gate else 12990Sstevel@tonic-gate iflb++; 13000Sstevel@tonic-gate 13010Sstevel@tonic-gate siflb = strrchr(sifl->ifl_name, '/'); 13020Sstevel@tonic-gate if (siflb == NULL) 13030Sstevel@tonic-gate siflb = sifl->ifl_name; 13040Sstevel@tonic-gate else 13050Sstevel@tonic-gate siflb++; 13060Sstevel@tonic-gate 13070Sstevel@tonic-gate if (strcmp(iflb, siflb) == 0) 13080Sstevel@tonic-gate hint = MSG_INTL(MSG_REC_CNFLTHINT); 13090Sstevel@tonic-gate else 13100Sstevel@tonic-gate hint = MSG_ORIG(MSG_STR_EMPTY); 13110Sstevel@tonic-gate 13121618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 13131618Srie MSG_INTL(MSG_REC_OBJCNFLT), sifl->ifl_name, 13141618Srie ifl->ifl_name, sifl->ifl_soname, hint); 13150Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 13160Sstevel@tonic-gate return (0); 13170Sstevel@tonic-gate } 13180Sstevel@tonic-gate } 13190Sstevel@tonic-gate 13200Sstevel@tonic-gate /* 13210Sstevel@tonic-gate * If the SONAME is the same as the name the user wishes to 13220Sstevel@tonic-gate * record when building a dynamic library (refer -h option), 13230Sstevel@tonic-gate * we also have a name clash. 13240Sstevel@tonic-gate */ 13250Sstevel@tonic-gate if (ofl->ofl_soname && 13260Sstevel@tonic-gate (strcmp(ofl->ofl_soname, ifl->ifl_soname) == 0)) { 13271618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 13281618Srie MSG_INTL(MSG_REC_OPTCNFLT), ifl->ifl_name, 13297983SAli.Bahrami@Sun.COM MSG_INTL(MSG_MARG_SONAME), ifl->ifl_soname); 13300Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 13310Sstevel@tonic-gate return (0); 13320Sstevel@tonic-gate } 13330Sstevel@tonic-gate } 13340Sstevel@tonic-gate return (1); 13350Sstevel@tonic-gate } 13360Sstevel@tonic-gate 13370Sstevel@tonic-gate /* 1338*9085SAli.Bahrami@Sun.COM * Process a progbits section from a relocatable object (ET_REL). 1339*9085SAli.Bahrami@Sun.COM * This is used on non-amd64 objects to recognize .eh_frame sections. 1340*9085SAli.Bahrami@Sun.COM */ 1341*9085SAli.Bahrami@Sun.COM /*ARGSUSED1*/ 1342*9085SAli.Bahrami@Sun.COM static uintptr_t 1343*9085SAli.Bahrami@Sun.COM process_progbits_final(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl) 1344*9085SAli.Bahrami@Sun.COM { 1345*9085SAli.Bahrami@Sun.COM if (isc->is_osdesc && (isc->is_flags & FLG_IS_EHFRAME) && 1346*9085SAli.Bahrami@Sun.COM (ld_unwind_register(isc->is_osdesc, ofl) == S_ERROR)) 1347*9085SAli.Bahrami@Sun.COM return (S_ERROR); 1348*9085SAli.Bahrami@Sun.COM 1349*9085SAli.Bahrami@Sun.COM return (1); 1350*9085SAli.Bahrami@Sun.COM } 1351*9085SAli.Bahrami@Sun.COM 1352*9085SAli.Bahrami@Sun.COM /* 13537463SRod.Evans@Sun.COM * Process a group section. 13547463SRod.Evans@Sun.COM */ 13557463SRod.Evans@Sun.COM static uintptr_t 13567463SRod.Evans@Sun.COM process_group(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 13577463SRod.Evans@Sun.COM Word ndx, int ident, Ofl_desc *ofl) 13587463SRod.Evans@Sun.COM { 13597463SRod.Evans@Sun.COM uintptr_t error; 13607463SRod.Evans@Sun.COM 13617463SRod.Evans@Sun.COM error = process_section(name, ifl, shdr, scn, ndx, ident, ofl); 13627463SRod.Evans@Sun.COM if ((error == 0) || (error == S_ERROR)) 13637463SRod.Evans@Sun.COM return (error); 13647463SRod.Evans@Sun.COM 13657463SRod.Evans@Sun.COM /* 13667463SRod.Evans@Sun.COM * Indicate that this input file has groups to process. Groups are 13677463SRod.Evans@Sun.COM * processed after all input sections have been processed. 13687463SRod.Evans@Sun.COM */ 13697463SRod.Evans@Sun.COM ifl->ifl_flags |= FLG_IS_GROUPS; 13707463SRod.Evans@Sun.COM 13717463SRod.Evans@Sun.COM return (1); 13727463SRod.Evans@Sun.COM } 13737463SRod.Evans@Sun.COM 13747463SRod.Evans@Sun.COM /* 13750Sstevel@tonic-gate * Process a relocation entry. At this point all input sections from this 13760Sstevel@tonic-gate * input file have been assigned an input section descriptor which is saved 13770Sstevel@tonic-gate * in the `ifl_isdesc' array. 13780Sstevel@tonic-gate */ 13791618Srie static uintptr_t 13800Sstevel@tonic-gate rel_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl) 13810Sstevel@tonic-gate { 13820Sstevel@tonic-gate Word rndx; 13830Sstevel@tonic-gate Is_desc *risc; 13840Sstevel@tonic-gate Os_desc *osp; 13850Sstevel@tonic-gate Shdr *shdr = isc->is_shdr; 13864734Sab196087 Conv_inv_buf_t inv_buf; 13870Sstevel@tonic-gate 13880Sstevel@tonic-gate /* 13890Sstevel@tonic-gate * Make sure this is a valid relocation we can handle. 13900Sstevel@tonic-gate */ 13916206Sab196087 if (shdr->sh_type != ld_targ.t_m.m_rel_sht_type) { 13921618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_FIL_INVALSEC), 13931618Srie ifl->ifl_name, isc->is_name, 13944734Sab196087 conv_sec_type(ifl->ifl_ehdr->e_machine, 13954734Sab196087 shdr->sh_type, 0, &inv_buf)); 13960Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 13970Sstevel@tonic-gate return (0); 13980Sstevel@tonic-gate } 13990Sstevel@tonic-gate 14000Sstevel@tonic-gate /* 14010Sstevel@tonic-gate * From the relocation section header information determine which 14020Sstevel@tonic-gate * section needs the actual relocation. Determine which output section 14030Sstevel@tonic-gate * this input section has been assigned to and add to its relocation 14040Sstevel@tonic-gate * list. Note that the relocation section may be null if it is not 14050Sstevel@tonic-gate * required (ie. .debug, .stabs, etc). 14060Sstevel@tonic-gate */ 14070Sstevel@tonic-gate rndx = shdr->sh_info; 14080Sstevel@tonic-gate if (rndx >= ifl->ifl_shnum) { 14090Sstevel@tonic-gate /* 14100Sstevel@tonic-gate * Broken input file. 14110Sstevel@tonic-gate */ 14121618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHINFO), 14134716Sab196087 ifl->ifl_name, isc->is_name, EC_XWORD(rndx)); 14140Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 14150Sstevel@tonic-gate return (0); 14160Sstevel@tonic-gate } 14170Sstevel@tonic-gate if (rndx == 0) { 14180Sstevel@tonic-gate if (list_appendc(&ofl->ofl_extrarels, isc) == 0) 14190Sstevel@tonic-gate return (S_ERROR); 14200Sstevel@tonic-gate } else if ((risc = ifl->ifl_isdesc[rndx]) != 0) { 14210Sstevel@tonic-gate /* 14220Sstevel@tonic-gate * Discard relocations if they are against a section 14230Sstevel@tonic-gate * which has been discarded. 14240Sstevel@tonic-gate */ 14250Sstevel@tonic-gate if (risc->is_flags & FLG_IS_DISCARD) 14260Sstevel@tonic-gate return (1); 14270Sstevel@tonic-gate if ((osp = risc->is_osdesc) == 0) { 14280Sstevel@tonic-gate if (risc->is_shdr->sh_type == SHT_SUNW_move) { 14290Sstevel@tonic-gate /* 14300Sstevel@tonic-gate * This section is processed later 14310Sstevel@tonic-gate * in sunwmove_preprocess() and 14320Sstevel@tonic-gate * reloc_init(). 14330Sstevel@tonic-gate */ 14340Sstevel@tonic-gate if (list_appendc(&ofl->ofl_mvrelisdescs, 14350Sstevel@tonic-gate isc) == 0) 14360Sstevel@tonic-gate return (S_ERROR); 14370Sstevel@tonic-gate return (1); 14380Sstevel@tonic-gate } 14391618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 14401618Srie MSG_INTL(MSG_FIL_INVRELOC1), ifl->ifl_name, 14411618Srie isc->is_name, risc->is_name); 14420Sstevel@tonic-gate return (0); 14430Sstevel@tonic-gate } 14448608SAli.Bahrami@Sun.COM if (aplist_append(&osp->os_relisdescs, isc, 14458608SAli.Bahrami@Sun.COM AL_CNT_OS_RELISDESCS) == NULL) 14460Sstevel@tonic-gate return (S_ERROR); 14470Sstevel@tonic-gate } 14480Sstevel@tonic-gate return (1); 14490Sstevel@tonic-gate } 14500Sstevel@tonic-gate 14510Sstevel@tonic-gate /* 14520Sstevel@tonic-gate * SHF_EXCLUDE flags is set for this section. 14530Sstevel@tonic-gate */ 14540Sstevel@tonic-gate static uintptr_t 14550Sstevel@tonic-gate process_exclude(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 14560Sstevel@tonic-gate Word ndx, Ofl_desc *ofl) 14570Sstevel@tonic-gate { 14580Sstevel@tonic-gate /* 14590Sstevel@tonic-gate * Sections SHT_SYMTAB and SHT_DYNDYM, even if SHF_EXCLUDE is on, might 14600Sstevel@tonic-gate * be needed for ld processing. These sections need to be in the 14610Sstevel@tonic-gate * internal table. Later it will be determined whether they can be 14620Sstevel@tonic-gate * eliminated or not. 14630Sstevel@tonic-gate */ 14640Sstevel@tonic-gate if (shdr->sh_type == SHT_SYMTAB || shdr->sh_type == SHT_DYNSYM) 14650Sstevel@tonic-gate return (0); 14660Sstevel@tonic-gate 14670Sstevel@tonic-gate /* 14680Sstevel@tonic-gate * Other checks 14690Sstevel@tonic-gate */ 14700Sstevel@tonic-gate if (shdr->sh_flags & SHF_ALLOC) { 14710Sstevel@tonic-gate /* 14720Sstevel@tonic-gate * A conflict, issue an warning message, and ignore the section. 14730Sstevel@tonic-gate */ 14741618Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_EXCLUDE), 14750Sstevel@tonic-gate ifl->ifl_name, name); 14760Sstevel@tonic-gate return (0); 14770Sstevel@tonic-gate } 14780Sstevel@tonic-gate 14790Sstevel@tonic-gate /* 14800Sstevel@tonic-gate * This sections is not going to the output file. 14810Sstevel@tonic-gate */ 14820Sstevel@tonic-gate return (process_section(name, ifl, shdr, scn, ndx, 0, ofl)); 14830Sstevel@tonic-gate } 14840Sstevel@tonic-gate 14850Sstevel@tonic-gate /* 14860Sstevel@tonic-gate * Section processing state table. `Initial' describes the required initial 14870Sstevel@tonic-gate * procedure to be called (if any), `Final' describes the final processing 14880Sstevel@tonic-gate * procedure (ie. things that can only be done when all required sections 14890Sstevel@tonic-gate * have been collected). 14900Sstevel@tonic-gate */ 1491*9085SAli.Bahrami@Sun.COM typedef uintptr_t (* initial_func_t)(const char *, Ifl_desc *, Shdr *, 1492*9085SAli.Bahrami@Sun.COM Elf_Scn *, Word, int, Ofl_desc *); 14930Sstevel@tonic-gate 1494*9085SAli.Bahrami@Sun.COM static initial_func_t Initial[SHT_NUM][2] = { 14950Sstevel@tonic-gate /* ET_REL ET_DYN */ 14960Sstevel@tonic-gate 14970Sstevel@tonic-gate /* SHT_NULL */ invalid_section, invalid_section, 14980Sstevel@tonic-gate /* SHT_PROGBITS */ process_progbits, process_progbits, 14990Sstevel@tonic-gate /* SHT_SYMTAB */ process_input, process_input, 15000Sstevel@tonic-gate /* SHT_STRTAB */ process_strtab, process_strtab, 15010Sstevel@tonic-gate /* SHT_RELA */ process_reloc, process_reloc, 15020Sstevel@tonic-gate /* SHT_HASH */ invalid_section, NULL, 15034716Sab196087 /* SHT_DYNAMIC */ process_rel_dynamic, process_dynamic_isgnu, 15040Sstevel@tonic-gate /* SHT_NOTE */ process_section, NULL, 15050Sstevel@tonic-gate /* SHT_NOBITS */ process_nobits, process_nobits, 15060Sstevel@tonic-gate /* SHT_REL */ process_reloc, process_reloc, 15070Sstevel@tonic-gate /* SHT_SHLIB */ process_section, invalid_section, 15080Sstevel@tonic-gate /* SHT_DYNSYM */ invalid_section, process_input, 15090Sstevel@tonic-gate /* SHT_UNKNOWN12 */ process_progbits, process_progbits, 15100Sstevel@tonic-gate /* SHT_UNKNOWN13 */ process_progbits, process_progbits, 15110Sstevel@tonic-gate /* SHT_INIT_ARRAY */ process_array, NULL, 15120Sstevel@tonic-gate /* SHT_FINI_ARRAY */ process_array, NULL, 15130Sstevel@tonic-gate /* SHT_PREINIT_ARRAY */ process_array, NULL, 15147463SRod.Evans@Sun.COM /* SHT_GROUP */ process_group, invalid_section, 15150Sstevel@tonic-gate /* SHT_SYMTAB_SHNDX */ process_sym_shndx, NULL 15160Sstevel@tonic-gate }; 15170Sstevel@tonic-gate 1518*9085SAli.Bahrami@Sun.COM typedef uintptr_t (* final_func_t)(Is_desc *, Ifl_desc *, Ofl_desc *); 1519*9085SAli.Bahrami@Sun.COM 1520*9085SAli.Bahrami@Sun.COM static final_func_t Final[SHT_NUM][2] = { 1521*9085SAli.Bahrami@Sun.COM /* ET_REL ET_DYN */ 15220Sstevel@tonic-gate 15230Sstevel@tonic-gate /* SHT_NULL */ NULL, NULL, 1524*9085SAli.Bahrami@Sun.COM /* SHT_PROGBITS */ process_progbits_final, NULL, 15251618Srie /* SHT_SYMTAB */ ld_sym_process, ld_sym_process, 15260Sstevel@tonic-gate /* SHT_STRTAB */ NULL, NULL, 15270Sstevel@tonic-gate /* SHT_RELA */ rel_process, NULL, 15280Sstevel@tonic-gate /* SHT_HASH */ NULL, NULL, 15290Sstevel@tonic-gate /* SHT_DYNAMIC */ NULL, process_dynamic, 15300Sstevel@tonic-gate /* SHT_NOTE */ NULL, NULL, 15310Sstevel@tonic-gate /* SHT_NOBITS */ NULL, NULL, 15320Sstevel@tonic-gate /* SHT_REL */ rel_process, NULL, 15330Sstevel@tonic-gate /* SHT_SHLIB */ NULL, NULL, 15341618Srie /* SHT_DYNSYM */ NULL, ld_sym_process, 15350Sstevel@tonic-gate /* SHT_UNKNOWN12 */ NULL, NULL, 15360Sstevel@tonic-gate /* SHT_UNKNOWN13 */ NULL, NULL, 15377463SRod.Evans@Sun.COM /* SHT_INIT_ARRAY */ array_process, NULL, 15387463SRod.Evans@Sun.COM /* SHT_FINI_ARRAY */ array_process, NULL, 15397463SRod.Evans@Sun.COM /* SHT_PREINIT_ARRAY */ array_process, NULL, 15400Sstevel@tonic-gate /* SHT_GROUP */ NULL, NULL, 15410Sstevel@tonic-gate /* SHT_SYMTAB_SHNDX */ sym_shndx_process, NULL 15420Sstevel@tonic-gate }; 15430Sstevel@tonic-gate 15440Sstevel@tonic-gate #define MAXNDXSIZE 10 15450Sstevel@tonic-gate 15460Sstevel@tonic-gate /* 15470Sstevel@tonic-gate * Process an elf file. Each section is compared against the section state 15480Sstevel@tonic-gate * table to determine whether it should be processed (saved), ignored, or 15490Sstevel@tonic-gate * is invalid for the type of input file being processed. 15500Sstevel@tonic-gate */ 15511618Srie static uintptr_t 15520Sstevel@tonic-gate process_elf(Ifl_desc *ifl, Elf *elf, Ofl_desc *ofl) 15530Sstevel@tonic-gate { 15540Sstevel@tonic-gate Elf_Scn *scn; 15550Sstevel@tonic-gate Shdr *shdr; 15567463SRod.Evans@Sun.COM Word ndx, sndx, ordndx = 0, ordcnt = 0; 15570Sstevel@tonic-gate char *str, *name, _name[MAXNDXSIZE]; 15580Sstevel@tonic-gate Word row, column; 15590Sstevel@tonic-gate int ident; 15600Sstevel@tonic-gate uintptr_t error; 15613617Srie Is_desc *vdfisp, *vndisp, *vsyisp, *sifisp, *capisp; 15620Sstevel@tonic-gate Sdf_desc *sdf; 15630Sstevel@tonic-gate 15640Sstevel@tonic-gate /* 15650Sstevel@tonic-gate * First process the .shstrtab section so that later sections can 15660Sstevel@tonic-gate * reference their name. 15670Sstevel@tonic-gate */ 15681618Srie ld_sup_file(ofl, ifl->ifl_name, elf_kind(elf), ifl->ifl_flags, elf); 15690Sstevel@tonic-gate 15700Sstevel@tonic-gate sndx = ifl->ifl_shstrndx; 15710Sstevel@tonic-gate if ((scn = elf_getscn(elf, (size_t)sndx)) == NULL) { 15721618Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN), 15731618Srie ifl->ifl_name); 15740Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 15750Sstevel@tonic-gate return (0); 15760Sstevel@tonic-gate } 15770Sstevel@tonic-gate if ((shdr = elf_getshdr(scn)) == NULL) { 15781618Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR), 15791618Srie ifl->ifl_name); 15800Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 15810Sstevel@tonic-gate return (0); 15820Sstevel@tonic-gate } 15830Sstevel@tonic-gate if ((name = elf_strptr(elf, (size_t)sndx, (size_t)shdr->sh_name)) == 15840Sstevel@tonic-gate NULL) { 15851618Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR), 15861618Srie ifl->ifl_name); 15870Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 15880Sstevel@tonic-gate return (0); 15890Sstevel@tonic-gate } 15900Sstevel@tonic-gate 15912647Srie if (ld_sup_input_section(ofl, ifl, name, &shdr, sndx, scn, 15922647Srie elf) == S_ERROR) 15930Sstevel@tonic-gate return (S_ERROR); 15940Sstevel@tonic-gate 15950Sstevel@tonic-gate /* 15960Sstevel@tonic-gate * Reset the name since the shdr->sh_name could have been changed as 15971618Srie * part of ld_sup_input_section(). If there is no name, fabricate one 15980Sstevel@tonic-gate * using the section index. 15990Sstevel@tonic-gate */ 16000Sstevel@tonic-gate if (shdr->sh_name == 0) { 16010Sstevel@tonic-gate (void) snprintf(_name, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INDEX), 16020Sstevel@tonic-gate EC_XWORD(sndx)); 16030Sstevel@tonic-gate if ((name = libld_malloc(strlen(_name) + 1)) == 0) 16040Sstevel@tonic-gate return (S_ERROR); 16050Sstevel@tonic-gate (void) strcpy(name, _name); 16060Sstevel@tonic-gate 16070Sstevel@tonic-gate } else if ((name = elf_strptr(elf, (size_t)sndx, 16080Sstevel@tonic-gate (size_t)shdr->sh_name)) == NULL) { 16091618Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR), 16101618Srie ifl->ifl_name); 16110Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 16120Sstevel@tonic-gate return (0); 16130Sstevel@tonic-gate } 16140Sstevel@tonic-gate 16150Sstevel@tonic-gate error = process_strtab(name, ifl, shdr, scn, sndx, FALSE, ofl); 16160Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR)) 16170Sstevel@tonic-gate return (error); 16180Sstevel@tonic-gate str = ifl->ifl_isdesc[sndx]->is_indata->d_buf; 16190Sstevel@tonic-gate 16200Sstevel@tonic-gate /* 16210Sstevel@tonic-gate * Determine the state table column from the input file type. Note, 16220Sstevel@tonic-gate * shared library sections are not added to the output section list. 16230Sstevel@tonic-gate */ 16240Sstevel@tonic-gate if (ifl->ifl_ehdr->e_type == ET_DYN) { 16250Sstevel@tonic-gate column = 1; 16260Sstevel@tonic-gate ofl->ofl_soscnt++; 16276206Sab196087 ident = ld_targ.t_id.id_null; 16280Sstevel@tonic-gate } else { 16290Sstevel@tonic-gate column = 0; 16300Sstevel@tonic-gate ofl->ofl_objscnt++; 16316206Sab196087 ident = ld_targ.t_id.id_unknown; 16320Sstevel@tonic-gate } 16330Sstevel@tonic-gate 16341618Srie DBG_CALL(Dbg_file_generic(ofl->ofl_lml, ifl)); 16350Sstevel@tonic-gate ndx = 0; 16360Sstevel@tonic-gate vdfisp = vndisp = vsyisp = sifisp = capisp = 0; 16370Sstevel@tonic-gate scn = NULL; 16380Sstevel@tonic-gate while (scn = elf_nextscn(elf, scn)) { 16390Sstevel@tonic-gate ndx++; 16407463SRod.Evans@Sun.COM 16410Sstevel@tonic-gate /* 16420Sstevel@tonic-gate * As we've already processed the .shstrtab don't do it again. 16430Sstevel@tonic-gate */ 16440Sstevel@tonic-gate if (ndx == sndx) 16450Sstevel@tonic-gate continue; 16460Sstevel@tonic-gate 16470Sstevel@tonic-gate if ((shdr = elf_getshdr(scn)) == NULL) { 16481618Srie eprintf(ofl->ofl_lml, ERR_ELF, 16491618Srie MSG_INTL(MSG_ELF_GETSHDR), ifl->ifl_name); 16500Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 16510Sstevel@tonic-gate return (0); 16520Sstevel@tonic-gate } 16530Sstevel@tonic-gate name = str + (size_t)(shdr->sh_name); 16540Sstevel@tonic-gate 16552647Srie if (ld_sup_input_section(ofl, ifl, name, &shdr, ndx, scn, 16562647Srie elf) == S_ERROR) 16570Sstevel@tonic-gate return (S_ERROR); 16580Sstevel@tonic-gate 16590Sstevel@tonic-gate /* 16600Sstevel@tonic-gate * Reset the name since the shdr->sh_name could have been 16611618Srie * changed as part of ld_sup_input_section(). If there is no 16621618Srie * name, fabricate one using the section index. 16630Sstevel@tonic-gate */ 16640Sstevel@tonic-gate if (shdr->sh_name == 0) { 16650Sstevel@tonic-gate (void) snprintf(_name, MAXNDXSIZE, 16660Sstevel@tonic-gate MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(ndx)); 16670Sstevel@tonic-gate if ((name = libld_malloc(strlen(_name) + 1)) == 0) 16680Sstevel@tonic-gate return (S_ERROR); 16690Sstevel@tonic-gate (void) strcpy(name, _name); 16700Sstevel@tonic-gate } else 16710Sstevel@tonic-gate name = str + (size_t)(shdr->sh_name); 16720Sstevel@tonic-gate 16730Sstevel@tonic-gate row = shdr->sh_type; 16740Sstevel@tonic-gate 16750Sstevel@tonic-gate /* 16760Sstevel@tonic-gate * If the section has the SHF_EXCLUDE flag on, and we're not 16770Sstevel@tonic-gate * generating a relocatable object, exclude the section. 16780Sstevel@tonic-gate */ 16790Sstevel@tonic-gate if (((shdr->sh_flags & SHF_EXCLUDE) != 0) && 16800Sstevel@tonic-gate ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0)) { 16810Sstevel@tonic-gate if ((error = process_exclude(name, ifl, shdr, scn, 16820Sstevel@tonic-gate ndx, ofl)) == S_ERROR) 16830Sstevel@tonic-gate return (S_ERROR); 16840Sstevel@tonic-gate if (error == 1) 16850Sstevel@tonic-gate continue; 16860Sstevel@tonic-gate } 16870Sstevel@tonic-gate 16880Sstevel@tonic-gate /* 16890Sstevel@tonic-gate * If this is a standard section type process it via the 16900Sstevel@tonic-gate * appropriate action routine. 16910Sstevel@tonic-gate */ 16920Sstevel@tonic-gate if (row < SHT_NUM) { 16930Sstevel@tonic-gate if (Initial[row][column] != NULL) { 16940Sstevel@tonic-gate if (Initial[row][column](name, ifl, shdr, scn, 16950Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR) 16960Sstevel@tonic-gate return (S_ERROR); 16970Sstevel@tonic-gate } 16980Sstevel@tonic-gate } else { 16990Sstevel@tonic-gate /* 17000Sstevel@tonic-gate * If this section is below SHT_LOSUNW then we don't 17010Sstevel@tonic-gate * really know what to do with it, issue a warning 17020Sstevel@tonic-gate * message but do the basic section processing anyway. 17030Sstevel@tonic-gate */ 17044734Sab196087 if (row < (Word)SHT_LOSUNW) { 17054734Sab196087 Conv_inv_buf_t inv_buf; 17064734Sab196087 17071618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 17081618Srie MSG_INTL(MSG_FIL_INVALSEC), ifl->ifl_name, 17091618Srie name, 17101618Srie conv_sec_type(ifl->ifl_ehdr->e_machine, 17114734Sab196087 shdr->sh_type, 0, &inv_buf)); 17124734Sab196087 } 17130Sstevel@tonic-gate 17140Sstevel@tonic-gate /* 17150Sstevel@tonic-gate * Handle sections greater than SHT_LOSUNW. 17160Sstevel@tonic-gate */ 17170Sstevel@tonic-gate switch (row) { 17180Sstevel@tonic-gate case SHT_SUNW_dof: 17190Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn, 17200Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR) 17210Sstevel@tonic-gate return (S_ERROR); 17220Sstevel@tonic-gate break; 17230Sstevel@tonic-gate case SHT_SUNW_cap: 1724*9085SAli.Bahrami@Sun.COM if (process_section(name, ifl, shdr, scn, ndx, 1725*9085SAli.Bahrami@Sun.COM ld_targ.t_id.id_null, ofl) == S_ERROR) 17260Sstevel@tonic-gate return (S_ERROR); 17270Sstevel@tonic-gate capisp = ifl->ifl_isdesc[ndx]; 17280Sstevel@tonic-gate break; 17290Sstevel@tonic-gate case SHT_SUNW_DEBUGSTR: 17300Sstevel@tonic-gate case SHT_SUNW_DEBUG: 17310Sstevel@tonic-gate if (process_debug(name, ifl, shdr, scn, 17320Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR) 17330Sstevel@tonic-gate return (S_ERROR); 17340Sstevel@tonic-gate break; 17350Sstevel@tonic-gate case SHT_SUNW_move: 1736*9085SAli.Bahrami@Sun.COM if (process_section(name, ifl, shdr, scn, ndx, 1737*9085SAli.Bahrami@Sun.COM ld_targ.t_id.id_null, ofl) == S_ERROR) 17380Sstevel@tonic-gate return (S_ERROR); 17390Sstevel@tonic-gate break; 17400Sstevel@tonic-gate case SHT_SUNW_syminfo: 1741*9085SAli.Bahrami@Sun.COM if (process_section(name, ifl, shdr, scn, ndx, 1742*9085SAli.Bahrami@Sun.COM ld_targ.t_id.id_null, ofl) == S_ERROR) 17430Sstevel@tonic-gate return (S_ERROR); 17440Sstevel@tonic-gate sifisp = ifl->ifl_isdesc[ndx]; 17450Sstevel@tonic-gate break; 17460Sstevel@tonic-gate case SHT_SUNW_ANNOTATE: 17477463SRod.Evans@Sun.COM if (process_progbits(name, ifl, shdr, scn, 17487463SRod.Evans@Sun.COM ndx, ident, ofl) == S_ERROR) 17497463SRod.Evans@Sun.COM return (S_ERROR); 17507463SRod.Evans@Sun.COM break; 17510Sstevel@tonic-gate case SHT_SUNW_COMDAT: 17520Sstevel@tonic-gate if (process_progbits(name, ifl, shdr, scn, 17530Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR) 17540Sstevel@tonic-gate return (S_ERROR); 17557463SRod.Evans@Sun.COM ifl->ifl_isdesc[ndx]->is_flags |= FLG_IS_COMDAT; 17560Sstevel@tonic-gate break; 17570Sstevel@tonic-gate case SHT_SUNW_verdef: 1758*9085SAli.Bahrami@Sun.COM if (process_section(name, ifl, shdr, scn, ndx, 1759*9085SAli.Bahrami@Sun.COM ld_targ.t_id.id_null, ofl) == S_ERROR) 17600Sstevel@tonic-gate return (S_ERROR); 17610Sstevel@tonic-gate vdfisp = ifl->ifl_isdesc[ndx]; 17620Sstevel@tonic-gate break; 17630Sstevel@tonic-gate case SHT_SUNW_verneed: 1764*9085SAli.Bahrami@Sun.COM if (process_section(name, ifl, shdr, scn, ndx, 1765*9085SAli.Bahrami@Sun.COM ld_targ.t_id.id_null, ofl) == S_ERROR) 17660Sstevel@tonic-gate return (S_ERROR); 17670Sstevel@tonic-gate vndisp = ifl->ifl_isdesc[ndx]; 17680Sstevel@tonic-gate break; 17690Sstevel@tonic-gate case SHT_SUNW_versym: 1770*9085SAli.Bahrami@Sun.COM if (process_section(name, ifl, shdr, scn, ndx, 1771*9085SAli.Bahrami@Sun.COM ld_targ.t_id.id_null, ofl) == S_ERROR) 17720Sstevel@tonic-gate return (S_ERROR); 17730Sstevel@tonic-gate vsyisp = ifl->ifl_isdesc[ndx]; 17740Sstevel@tonic-gate break; 17750Sstevel@tonic-gate case SHT_SPARC_GOTDATA: 17766206Sab196087 /* 17776206Sab196087 * SHT_SPARC_GOTDATA (0x70000000) is in the 17786206Sab196087 * SHT_LOPROC - SHT_HIPROC range reserved 17796206Sab196087 * for processor-specific semantics. It is 17806206Sab196087 * only meaningful for sparc targets. 17816206Sab196087 */ 17826206Sab196087 if (ld_targ.t_m.m_mach != 17836206Sab196087 LD_TARG_BYCLASS(EM_SPARC, EM_SPARCV9)) 17846206Sab196087 goto do_default; 1785*9085SAli.Bahrami@Sun.COM if (process_section(name, ifl, shdr, scn, ndx, 1786*9085SAli.Bahrami@Sun.COM ld_targ.t_id.id_gotdata, ofl) == S_ERROR) 17870Sstevel@tonic-gate return (S_ERROR); 17880Sstevel@tonic-gate break; 17896206Sab196087 #if defined(_ELF64) 17900Sstevel@tonic-gate case SHT_AMD64_UNWIND: 17916206Sab196087 /* 17926206Sab196087 * SHT_AMD64_UNWIND (0x70000001) is in the 17936206Sab196087 * SHT_LOPROC - SHT_HIPROC range reserved 17946206Sab196087 * for processor-specific semantics. It is 17956206Sab196087 * only meaningful for amd64 targets. 17966206Sab196087 */ 17976206Sab196087 if (ld_targ.t_m.m_mach != EM_AMD64) 17986206Sab196087 goto do_default; 17997463SRod.Evans@Sun.COM 18006206Sab196087 /* 18016206Sab196087 * Target is x86, so this really is 18026206Sab196087 * SHT_AMD64_UNWIND 18036206Sab196087 */ 18040Sstevel@tonic-gate if (column == 0) { 18050Sstevel@tonic-gate /* 18060Sstevel@tonic-gate * column == ET_REL 18070Sstevel@tonic-gate */ 18087463SRod.Evans@Sun.COM if (process_section(name, ifl, shdr, 18097463SRod.Evans@Sun.COM scn, ndx, ld_targ.t_id.id_unwind, 18107463SRod.Evans@Sun.COM ofl) == S_ERROR) 18110Sstevel@tonic-gate return (S_ERROR); 1812*9085SAli.Bahrami@Sun.COM ifl->ifl_isdesc[ndx]->is_flags |= 1813*9085SAli.Bahrami@Sun.COM FLG_IS_EHFRAME; 18140Sstevel@tonic-gate } 18150Sstevel@tonic-gate break; 18160Sstevel@tonic-gate #endif 18170Sstevel@tonic-gate default: 18186206Sab196087 do_default: 1819*9085SAli.Bahrami@Sun.COM if (process_section(name, ifl, shdr, scn, ndx, 1820*9085SAli.Bahrami@Sun.COM ((ident == ld_targ.t_id.id_null) ? 1821*9085SAli.Bahrami@Sun.COM ident : ld_targ.t_id.id_user), ofl) == 1822*9085SAli.Bahrami@Sun.COM S_ERROR) 18230Sstevel@tonic-gate return (S_ERROR); 18240Sstevel@tonic-gate break; 18250Sstevel@tonic-gate } 18260Sstevel@tonic-gate } 18277463SRod.Evans@Sun.COM } 18280Sstevel@tonic-gate 18297463SRod.Evans@Sun.COM /* 18307463SRod.Evans@Sun.COM * Now that all input sections have been analyzed, and prior to placing 18317463SRod.Evans@Sun.COM * any input sections to their output sections, process any groups. 18327463SRod.Evans@Sun.COM * Groups can contribute COMDAT items, which may get discarded as part 18337463SRod.Evans@Sun.COM * of placement. In addition, COMDAT names may require transformation 18347463SRod.Evans@Sun.COM * to indicate different output section placement. 18357463SRod.Evans@Sun.COM */ 18367463SRod.Evans@Sun.COM if (ifl->ifl_flags & FLG_IS_GROUPS) { 18377463SRod.Evans@Sun.COM for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) { 18387463SRod.Evans@Sun.COM Is_desc *isp; 18397463SRod.Evans@Sun.COM 18407463SRod.Evans@Sun.COM if (((isp = ifl->ifl_isdesc[ndx]) == NULL) || 18417463SRod.Evans@Sun.COM (isp->is_shdr->sh_type != SHT_GROUP)) 18427463SRod.Evans@Sun.COM continue; 18437463SRod.Evans@Sun.COM 18447463SRod.Evans@Sun.COM if (ld_group_process(isp, ofl) == S_ERROR) 18457463SRod.Evans@Sun.COM return (S_ERROR); 18460Sstevel@tonic-gate } 18470Sstevel@tonic-gate } 18480Sstevel@tonic-gate 18490Sstevel@tonic-gate /* 18507463SRod.Evans@Sun.COM * Now that all of input sections have been processed, place them 18517463SRod.Evans@Sun.COM * in the appropriate output sections. 18520Sstevel@tonic-gate */ 18537463SRod.Evans@Sun.COM for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) { 18547463SRod.Evans@Sun.COM Is_desc *isp; 18557463SRod.Evans@Sun.COM Shdr *shdr; 18567463SRod.Evans@Sun.COM 18577463SRod.Evans@Sun.COM if (((isp = ifl->ifl_isdesc[ndx]) == NULL) || 18587463SRod.Evans@Sun.COM ((isp->is_flags & FLG_IS_PLACE) == 0)) 18597463SRod.Evans@Sun.COM continue; 18607463SRod.Evans@Sun.COM 18617463SRod.Evans@Sun.COM shdr = isp->is_shdr; 18620Sstevel@tonic-gate 18637463SRod.Evans@Sun.COM /* 18647463SRod.Evans@Sun.COM * Place all non-ordered sections within their appropriate 18657463SRod.Evans@Sun.COM * output section. 18667463SRod.Evans@Sun.COM * 18677463SRod.Evans@Sun.COM * Ordered sections are sorted based on the relative ordering 18687463SRod.Evans@Sun.COM * of the section pointed to by the sh_info entry. An ordered 18697463SRod.Evans@Sun.COM * section, whose sh_link points to itself, must also be placed 18707463SRod.Evans@Sun.COM * in the output image so as to control the ordered processing 18717463SRod.Evans@Sun.COM * that follows (see FLG_IF_ORDERED below). 18727463SRod.Evans@Sun.COM */ 18737463SRod.Evans@Sun.COM if (((isp->is_flags & FLG_IS_ORDERED) == 0) || 18747463SRod.Evans@Sun.COM ((ndx == shdr->sh_link) && 18757463SRod.Evans@Sun.COM (shdr->sh_flags & SHF_ORDERED))) { 18767463SRod.Evans@Sun.COM if (ld_place_section(ofl, isp, 18777463SRod.Evans@Sun.COM isp->is_keyident, 0) == (Os_desc *)S_ERROR) 18787463SRod.Evans@Sun.COM return (S_ERROR); 18797463SRod.Evans@Sun.COM } 18807463SRod.Evans@Sun.COM 18817463SRod.Evans@Sun.COM /* 18827463SRod.Evans@Sun.COM * If a section requires ordered processing, keep track of the 18837463SRod.Evans@Sun.COM * section index and count to optimize later section traversal. 18847463SRod.Evans@Sun.COM */ 18857463SRod.Evans@Sun.COM if (isp->is_flags & FLG_IS_ORDERED) { 18867463SRod.Evans@Sun.COM ordcnt++; 18877463SRod.Evans@Sun.COM if (ordndx == 0) 18887463SRod.Evans@Sun.COM ordndx = ndx; 18897463SRod.Evans@Sun.COM } 18907463SRod.Evans@Sun.COM } 18917463SRod.Evans@Sun.COM 18927463SRod.Evans@Sun.COM /* 18937463SRod.Evans@Sun.COM * Some sections have special ordering requirements, that are based off 18947463SRod.Evans@Sun.COM * of the section pointed to by their sh_info entry. This controlling 18957463SRod.Evans@Sun.COM * section will have been placed (above), and thus any ordered sections 18967463SRod.Evans@Sun.COM * can now be processed. 18977463SRod.Evans@Sun.COM */ 18987463SRod.Evans@Sun.COM if (ifl->ifl_flags & FLG_IF_ORDERED) { 18997463SRod.Evans@Sun.COM Word cnt = 0; 19007463SRod.Evans@Sun.COM 19017463SRod.Evans@Sun.COM for (ndx = ordndx; 19027463SRod.Evans@Sun.COM (ndx < ifl->ifl_shnum) && (cnt < ordcnt); ndx++) { 19030Sstevel@tonic-gate Is_desc *isp; 19040Sstevel@tonic-gate 19057463SRod.Evans@Sun.COM if (((isp = ifl->ifl_isdesc[ndx]) == NULL) || 19067463SRod.Evans@Sun.COM ((isp->is_flags & FLG_IS_ORDERED) == 0)) 19070Sstevel@tonic-gate continue; 19080Sstevel@tonic-gate 19097463SRod.Evans@Sun.COM if (ld_process_ordered(ifl, ofl, ndx, 19107463SRod.Evans@Sun.COM ifl->ifl_shnum) == S_ERROR) 19110Sstevel@tonic-gate return (S_ERROR); 19120Sstevel@tonic-gate } 19130Sstevel@tonic-gate } 19140Sstevel@tonic-gate 19150Sstevel@tonic-gate /* 19161109Srie * If this is an explicit shared object determine if the user has 19170Sstevel@tonic-gate * specified a control definition. This descriptor may specify which 19180Sstevel@tonic-gate * version definitions can be used from this object (it may also update 19190Sstevel@tonic-gate * the dependency to USED and supply an alternative SONAME). 19200Sstevel@tonic-gate */ 19210Sstevel@tonic-gate sdf = 0; 19220Sstevel@tonic-gate if (column && (ifl->ifl_flags & FLG_IF_NEEDED)) { 19230Sstevel@tonic-gate const char *base; 19240Sstevel@tonic-gate 19250Sstevel@tonic-gate /* 19260Sstevel@tonic-gate * Use the basename of the input file (typically this is the 19270Sstevel@tonic-gate * compilation environment name, ie. libfoo.so). 19280Sstevel@tonic-gate */ 19290Sstevel@tonic-gate if ((base = strrchr(ifl->ifl_name, '/')) == NULL) 19300Sstevel@tonic-gate base = ifl->ifl_name; 19310Sstevel@tonic-gate else 19320Sstevel@tonic-gate base++; 19330Sstevel@tonic-gate 19340Sstevel@tonic-gate if ((sdf = sdf_find(base, &ofl->ofl_socntl)) != 0) { 19350Sstevel@tonic-gate sdf->sdf_file = ifl; 19360Sstevel@tonic-gate ifl->ifl_sdfdesc = sdf; 19370Sstevel@tonic-gate } 19380Sstevel@tonic-gate } 19390Sstevel@tonic-gate 19400Sstevel@tonic-gate /* 19417833SRod.Evans@Sun.COM * Process any hardware/software capabilities sections. Only the 19427833SRod.Evans@Sun.COM * capabilities for input relocatable objects are propagated. If the 19437833SRod.Evans@Sun.COM * relocatable objects don't contain any capabilities, any capability 19447833SRod.Evans@Sun.COM * state that has already been gathered will prevail. 19450Sstevel@tonic-gate */ 19467833SRod.Evans@Sun.COM if (capisp) 19473617Srie process_cap(ifl, capisp, ofl); 19480Sstevel@tonic-gate 19490Sstevel@tonic-gate /* 19500Sstevel@tonic-gate * Process any version dependencies. These will establish shared object 19510Sstevel@tonic-gate * `needed' entries in the same manner as will be generated from the 19520Sstevel@tonic-gate * .dynamic's NEEDED entries. 19530Sstevel@tonic-gate */ 19540Sstevel@tonic-gate if (vndisp && (ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC))) 19551618Srie if (ld_vers_need_process(vndisp, ifl, ofl) == S_ERROR) 19560Sstevel@tonic-gate return (S_ERROR); 19570Sstevel@tonic-gate 19580Sstevel@tonic-gate /* 19590Sstevel@tonic-gate * Before processing any symbol resolution or relocations process any 19600Sstevel@tonic-gate * version sections. 19610Sstevel@tonic-gate */ 19620Sstevel@tonic-gate if (vsyisp) 19631618Srie (void) ld_vers_sym_process(ofl->ofl_lml, vsyisp, ifl); 19640Sstevel@tonic-gate 19650Sstevel@tonic-gate if (ifl->ifl_versym && 19660Sstevel@tonic-gate (vdfisp || (sdf && (sdf->sdf_flags & FLG_SDF_SELECT)))) 19671618Srie if (ld_vers_def_process(vdfisp, ifl, ofl) == S_ERROR) 19680Sstevel@tonic-gate return (S_ERROR); 19690Sstevel@tonic-gate 19700Sstevel@tonic-gate /* 19710Sstevel@tonic-gate * Having collected the appropriate sections carry out any additional 19720Sstevel@tonic-gate * processing if necessary. 19730Sstevel@tonic-gate */ 19740Sstevel@tonic-gate for (ndx = 0; ndx < ifl->ifl_shnum; ndx++) { 19757463SRod.Evans@Sun.COM Is_desc *isp; 19760Sstevel@tonic-gate 19770Sstevel@tonic-gate if ((isp = ifl->ifl_isdesc[ndx]) == 0) 19780Sstevel@tonic-gate continue; 19790Sstevel@tonic-gate row = isp->is_shdr->sh_type; 19800Sstevel@tonic-gate 19810Sstevel@tonic-gate if ((isp->is_flags & FLG_IS_DISCARD) == 0) 19821618Srie ld_sup_section(ofl, isp->is_name, isp->is_shdr, ndx, 19831618Srie isp->is_indata, elf); 19840Sstevel@tonic-gate 19850Sstevel@tonic-gate /* 19860Sstevel@tonic-gate * If this is a ST_SUNW_move section from a 19870Sstevel@tonic-gate * a relocatable file, keep the input section. 19880Sstevel@tonic-gate */ 19890Sstevel@tonic-gate if ((row == SHT_SUNW_move) && (column == 0)) { 19900Sstevel@tonic-gate if (list_appendc(&(ofl->ofl_ismove), isp) == 0) 19910Sstevel@tonic-gate return (S_ERROR); 19920Sstevel@tonic-gate } 19930Sstevel@tonic-gate 19940Sstevel@tonic-gate /* 19950Sstevel@tonic-gate * If this is a standard section type process it via the 19960Sstevel@tonic-gate * appropriate action routine. 19970Sstevel@tonic-gate */ 19980Sstevel@tonic-gate if (row < SHT_NUM) { 19997463SRod.Evans@Sun.COM if (Final[row][column] != NULL) { 20007463SRod.Evans@Sun.COM if (Final[row][column](isp, ifl, 20017463SRod.Evans@Sun.COM ofl) == S_ERROR) 20020Sstevel@tonic-gate return (S_ERROR); 20037463SRod.Evans@Sun.COM } 20047463SRod.Evans@Sun.COM #if defined(_ELF64) 20057463SRod.Evans@Sun.COM } else if ((row == SHT_AMD64_UNWIND) && (column == 0)) { 20067463SRod.Evans@Sun.COM Os_desc *osp = isp->is_osdesc; 20077463SRod.Evans@Sun.COM 20087463SRod.Evans@Sun.COM /* 20097463SRod.Evans@Sun.COM * SHT_AMD64_UNWIND (0x70000001) is in the SHT_LOPROC - 20107463SRod.Evans@Sun.COM * SHT_HIPROC range reserved for processor-specific 20117463SRod.Evans@Sun.COM * semantics, and is only meaningful for amd64 targets. 20127463SRod.Evans@Sun.COM * 20137463SRod.Evans@Sun.COM * Only process unwind contents from relocatable 20147463SRod.Evans@Sun.COM * objects. 20157463SRod.Evans@Sun.COM */ 20167463SRod.Evans@Sun.COM if (osp && (ld_targ.t_m.m_mach == EM_AMD64) && 2017*9085SAli.Bahrami@Sun.COM (ld_unwind_register(osp, ofl) == S_ERROR)) 20187463SRod.Evans@Sun.COM return (S_ERROR); 20197463SRod.Evans@Sun.COM #endif 20200Sstevel@tonic-gate } 20210Sstevel@tonic-gate } 20220Sstevel@tonic-gate 20230Sstevel@tonic-gate /* 20240Sstevel@tonic-gate * After processing any symbol resolution, and if this dependency 20250Sstevel@tonic-gate * indicates it contains symbols that can't be directly bound to, 20260Sstevel@tonic-gate * set the symbols appropriately. 20270Sstevel@tonic-gate */ 20280Sstevel@tonic-gate if (sifisp && ((ifl->ifl_flags & (FLG_IF_NEEDED | FLG_IF_NODIRECT)) == 20290Sstevel@tonic-gate (FLG_IF_NEEDED | FLG_IF_NODIRECT))) 20301618Srie (void) ld_sym_nodirect(sifisp, ifl, ofl); 20310Sstevel@tonic-gate 20320Sstevel@tonic-gate return (1); 20330Sstevel@tonic-gate } 20340Sstevel@tonic-gate 20350Sstevel@tonic-gate /* 20360Sstevel@tonic-gate * Process the current input file. There are basically three types of files 20370Sstevel@tonic-gate * that come through here: 20380Sstevel@tonic-gate * 20390Sstevel@tonic-gate * o files explicitly defined on the command line (ie. foo.o or bar.so), 20400Sstevel@tonic-gate * in this case only the `name' field is valid. 20410Sstevel@tonic-gate * 20420Sstevel@tonic-gate * o libraries determined from the -l command line option (ie. -lbar), 20430Sstevel@tonic-gate * in this case the `soname' field contains the basename of the located 20440Sstevel@tonic-gate * file. 20450Sstevel@tonic-gate * 20460Sstevel@tonic-gate * Any shared object specified via the above two conventions must be recorded 20470Sstevel@tonic-gate * as a needed dependency. 20480Sstevel@tonic-gate * 20490Sstevel@tonic-gate * o libraries specified as dependencies of those libraries already obtained 20500Sstevel@tonic-gate * via the command line (ie. bar.so has a DT_NEEDED entry of fred.so.1), 20510Sstevel@tonic-gate * in this case the `soname' field contains either a full pathname (if the 20520Sstevel@tonic-gate * needed entry contained a `/'), or the basename of the located file. 20530Sstevel@tonic-gate * These libraries are processed to verify symbol binding but are not 20540Sstevel@tonic-gate * recorded as dependencies of the output file being generated. 20550Sstevel@tonic-gate */ 20560Sstevel@tonic-gate Ifl_desc * 20571618Srie ld_process_ifl(const char *name, const char *soname, int fd, Elf *elf, 20587359SRod.Evans@Sun.COM Word flags, Ofl_desc *ofl, Rej_desc *rej) 20590Sstevel@tonic-gate { 20600Sstevel@tonic-gate Ifl_desc *ifl; 20610Sstevel@tonic-gate Ehdr *ehdr; 20620Sstevel@tonic-gate Listnode *lnp; 20630Sstevel@tonic-gate uintptr_t error = 0; 20640Sstevel@tonic-gate struct stat status; 20650Sstevel@tonic-gate Ar_desc *adp; 20660Sstevel@tonic-gate Rej_desc _rej; 20670Sstevel@tonic-gate 20680Sstevel@tonic-gate /* 20690Sstevel@tonic-gate * If this file was not extracted from an archive obtain its device 20700Sstevel@tonic-gate * information. This will be used to determine if the file has already 20710Sstevel@tonic-gate * been processed (rather than simply comparing filenames, the device 20720Sstevel@tonic-gate * information provides a quicker comparison and detects linked files). 20730Sstevel@tonic-gate */ 20748598SRod.Evans@Sun.COM if (fd && ((flags & FLG_IF_EXTRACT) == 0)) 20750Sstevel@tonic-gate (void) fstat(fd, &status); 20760Sstevel@tonic-gate else { 20770Sstevel@tonic-gate status.st_dev = 0; 20780Sstevel@tonic-gate status.st_ino = 0; 20790Sstevel@tonic-gate } 20800Sstevel@tonic-gate 20810Sstevel@tonic-gate switch (elf_kind(elf)) { 20820Sstevel@tonic-gate case ELF_K_AR: 20830Sstevel@tonic-gate /* 20840Sstevel@tonic-gate * Determine if we've already come across this archive file. 20850Sstevel@tonic-gate */ 20860Sstevel@tonic-gate if (!(flags & FLG_IF_EXTRACT)) { 20870Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_ars, lnp, adp)) { 20880Sstevel@tonic-gate if ((adp->ad_stdev != status.st_dev) || 20890Sstevel@tonic-gate (adp->ad_stino != status.st_ino)) 20900Sstevel@tonic-gate continue; 20910Sstevel@tonic-gate 20920Sstevel@tonic-gate /* 20930Sstevel@tonic-gate * We've seen this file before so reuse the 20940Sstevel@tonic-gate * original archive descriptor and discard the 20957359SRod.Evans@Sun.COM * new elf descriptor. Note that a file 20967359SRod.Evans@Sun.COM * descriptor is unnecessary, as the file is 20977359SRod.Evans@Sun.COM * already available in memory. 20980Sstevel@tonic-gate */ 20991618Srie DBG_CALL(Dbg_file_reuse(ofl->ofl_lml, name, 21001618Srie adp->ad_name)); 21010Sstevel@tonic-gate (void) elf_end(elf); 21027359SRod.Evans@Sun.COM return ((Ifl_desc *)ld_process_archive(name, -1, 21030Sstevel@tonic-gate adp, ofl)); 21040Sstevel@tonic-gate } 21050Sstevel@tonic-gate } 21060Sstevel@tonic-gate 21070Sstevel@tonic-gate /* 21080Sstevel@tonic-gate * As we haven't processed this file before establish a new 21090Sstevel@tonic-gate * archive descriptor. 21100Sstevel@tonic-gate */ 21111618Srie adp = ld_ar_setup(name, elf, ofl); 21120Sstevel@tonic-gate if ((adp == 0) || (adp == (Ar_desc *)S_ERROR)) 21130Sstevel@tonic-gate return ((Ifl_desc *)adp); 21140Sstevel@tonic-gate adp->ad_stdev = status.st_dev; 21150Sstevel@tonic-gate adp->ad_stino = status.st_ino; 21160Sstevel@tonic-gate 21171618Srie ld_sup_file(ofl, name, ELF_K_AR, flags, elf); 21180Sstevel@tonic-gate 21197359SRod.Evans@Sun.COM /* 21207359SRod.Evans@Sun.COM * Indicate that the ELF descriptor no longer requires a file 21217359SRod.Evans@Sun.COM * descriptor by reading the entire file. The file is already 21227359SRod.Evans@Sun.COM * read via the initial mmap(2) behind elf_begin(3elf), thus 21237359SRod.Evans@Sun.COM * this operation is effectively a no-op. However, a side- 21247359SRod.Evans@Sun.COM * effect is that the internal file descriptor, maintained in 21257359SRod.Evans@Sun.COM * the ELF descriptor, is set to -1. This setting will not 21267359SRod.Evans@Sun.COM * be compared with any file descriptor that is passed to 21277359SRod.Evans@Sun.COM * elf_begin(), should this archive, or one of the archive 21287359SRod.Evans@Sun.COM * members, be processed again from the command line or 21297359SRod.Evans@Sun.COM * because of a -z rescan. 21307359SRod.Evans@Sun.COM */ 21317359SRod.Evans@Sun.COM if (elf_cntl(elf, ELF_C_FDREAD) == -1) { 21327359SRod.Evans@Sun.COM eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_CNTL), 21337359SRod.Evans@Sun.COM name); 21347359SRod.Evans@Sun.COM ofl->ofl_flags |= FLG_OF_FATAL; 21357359SRod.Evans@Sun.COM return (NULL); 21367359SRod.Evans@Sun.COM } 21377359SRod.Evans@Sun.COM 21387359SRod.Evans@Sun.COM return ((Ifl_desc *)ld_process_archive(name, -1, adp, ofl)); 21390Sstevel@tonic-gate 21400Sstevel@tonic-gate case ELF_K_ELF: 21410Sstevel@tonic-gate /* 21420Sstevel@tonic-gate * Obtain the elf header so that we can determine what type of 21430Sstevel@tonic-gate * elf ELF_K_ELF file this is. 21440Sstevel@tonic-gate */ 21450Sstevel@tonic-gate if ((ehdr = elf_getehdr(elf)) == NULL) { 21460Sstevel@tonic-gate int _class = gelf_getclass(elf); 21470Sstevel@tonic-gate 21480Sstevel@tonic-gate /* 21490Sstevel@tonic-gate * Failure could occur for a number of reasons at this 21500Sstevel@tonic-gate * point. Typically the files class is incorrect (ie. 21510Sstevel@tonic-gate * user is building 64-bit but managed to pint at 32-bit 21520Sstevel@tonic-gate * libraries). However any number of elf errors can 21530Sstevel@tonic-gate * also occur, such as from a truncated or corrupt file. 21540Sstevel@tonic-gate * Here we try and get the best error message possible. 21550Sstevel@tonic-gate */ 21566206Sab196087 if (ld_targ.t_m.m_class != _class) { 21570Sstevel@tonic-gate _rej.rej_type = SGS_REJ_CLASS; 21580Sstevel@tonic-gate _rej.rej_info = (uint_t)_class; 21590Sstevel@tonic-gate } else { 21600Sstevel@tonic-gate _rej.rej_type = SGS_REJ_STR; 21610Sstevel@tonic-gate _rej.rej_str = elf_errmsg(-1); 21620Sstevel@tonic-gate } 21630Sstevel@tonic-gate _rej.rej_name = name; 21646206Sab196087 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej, 21656206Sab196087 ld_targ.t_m.m_mach)); 21660Sstevel@tonic-gate if (rej->rej_type == 0) { 21670Sstevel@tonic-gate *rej = _rej; 21680Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name); 21690Sstevel@tonic-gate } 21707359SRod.Evans@Sun.COM return (NULL); 21710Sstevel@tonic-gate } 21720Sstevel@tonic-gate 21730Sstevel@tonic-gate /* 21740Sstevel@tonic-gate * Determine if we've already come across this file. 21750Sstevel@tonic-gate */ 21760Sstevel@tonic-gate if (!(flags & FLG_IF_EXTRACT)) { 21777463SRod.Evans@Sun.COM List *lst; 21780Sstevel@tonic-gate 21790Sstevel@tonic-gate if (ehdr->e_type == ET_REL) 21800Sstevel@tonic-gate lst = &ofl->ofl_objs; 21810Sstevel@tonic-gate else 21820Sstevel@tonic-gate lst = &ofl->ofl_sos; 21830Sstevel@tonic-gate 21840Sstevel@tonic-gate /* 21850Sstevel@tonic-gate * Traverse the appropriate file list and determine if 21860Sstevel@tonic-gate * a dev/inode match is found. 21870Sstevel@tonic-gate */ 21880Sstevel@tonic-gate for (LIST_TRAVERSE(lst, lnp, ifl)) { 21890Sstevel@tonic-gate /* 21900Sstevel@tonic-gate * Ifl_desc generated via -Nneed, therefore no 21910Sstevel@tonic-gate * actual file behind it. 21920Sstevel@tonic-gate */ 21930Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_NEEDSTR) 21940Sstevel@tonic-gate continue; 21950Sstevel@tonic-gate 21960Sstevel@tonic-gate if ((ifl->ifl_stino != status.st_ino) || 21970Sstevel@tonic-gate (ifl->ifl_stdev != status.st_dev)) 21980Sstevel@tonic-gate continue; 21990Sstevel@tonic-gate 22000Sstevel@tonic-gate /* 22010Sstevel@tonic-gate * Disregard (skip) this image. 22020Sstevel@tonic-gate */ 22031618Srie DBG_CALL(Dbg_file_skip(ofl->ofl_lml, 22041618Srie ifl->ifl_name, name)); 22050Sstevel@tonic-gate (void) elf_end(elf); 22060Sstevel@tonic-gate 22070Sstevel@tonic-gate /* 22080Sstevel@tonic-gate * If the file was explicitly defined on the 22090Sstevel@tonic-gate * command line (this is always the case for 22100Sstevel@tonic-gate * relocatable objects, and is true for shared 22110Sstevel@tonic-gate * objects when they weren't specified via -l or 22120Sstevel@tonic-gate * were dragged in as an implicit dependency), 22130Sstevel@tonic-gate * then warn the user. 22140Sstevel@tonic-gate */ 22150Sstevel@tonic-gate if ((flags & FLG_IF_CMDLINE) || 22160Sstevel@tonic-gate (ifl->ifl_flags & FLG_IF_CMDLINE)) { 22170Sstevel@tonic-gate const char *errmsg; 22180Sstevel@tonic-gate 22190Sstevel@tonic-gate /* 22200Sstevel@tonic-gate * Determine whether this is the same 22210Sstevel@tonic-gate * file name as originally encountered 22220Sstevel@tonic-gate * so as to provide the most 22230Sstevel@tonic-gate * descriptive diagnostic. 22240Sstevel@tonic-gate */ 22254734Sab196087 errmsg = 22264734Sab196087 (strcmp(name, ifl->ifl_name) == 0) ? 22274734Sab196087 MSG_INTL(MSG_FIL_MULINC_1) : 22284734Sab196087 MSG_INTL(MSG_FIL_MULINC_2); 22291618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 22301618Srie errmsg, name, ifl->ifl_name); 22310Sstevel@tonic-gate } 22320Sstevel@tonic-gate return (ifl); 22330Sstevel@tonic-gate } 22340Sstevel@tonic-gate } 22350Sstevel@tonic-gate 22360Sstevel@tonic-gate /* 22370Sstevel@tonic-gate * At this point, we know we need the file. Establish an input 22380Sstevel@tonic-gate * file descriptor and continue processing. 22390Sstevel@tonic-gate */ 22400Sstevel@tonic-gate ifl = ifl_setup(name, ehdr, elf, flags, ofl, rej); 22410Sstevel@tonic-gate if ((ifl == 0) || (ifl == (Ifl_desc *)S_ERROR)) 22420Sstevel@tonic-gate return (ifl); 22430Sstevel@tonic-gate ifl->ifl_stdev = status.st_dev; 22440Sstevel@tonic-gate ifl->ifl_stino = status.st_ino; 22450Sstevel@tonic-gate 22460Sstevel@tonic-gate /* 22470Sstevel@tonic-gate * If -zignore is in effect, mark this file as a potential 22480Sstevel@tonic-gate * candidate (the files use isn't actually determined until 22490Sstevel@tonic-gate * symbol resolution and relocation processing are completed). 22500Sstevel@tonic-gate */ 22510Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_IGNORE) 22520Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_IGNORE; 22530Sstevel@tonic-gate 22540Sstevel@tonic-gate switch (ehdr->e_type) { 22550Sstevel@tonic-gate case ET_REL: 22566206Sab196087 (*ld_targ.t_mr.mr_mach_eflags)(ehdr, ofl); 22570Sstevel@tonic-gate error = process_elf(ifl, elf, ofl); 22580Sstevel@tonic-gate break; 22590Sstevel@tonic-gate case ET_DYN: 22600Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STATIC) || 22610Sstevel@tonic-gate !(ofl->ofl_flags & FLG_OF_DYNLIBS)) { 22621618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 22631618Srie MSG_INTL(MSG_FIL_SOINSTAT), name); 22640Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 22657359SRod.Evans@Sun.COM return (NULL); 22660Sstevel@tonic-gate } 22670Sstevel@tonic-gate 22680Sstevel@tonic-gate /* 22690Sstevel@tonic-gate * Record any additional shared object information. 22700Sstevel@tonic-gate * If no soname is specified (eg. this file was 22710Sstevel@tonic-gate * derived from a explicit filename declaration on the 22720Sstevel@tonic-gate * command line, ie. bar.so) use the pathname. 22730Sstevel@tonic-gate * This entry may be overridden if the files dynamic 22740Sstevel@tonic-gate * section specifies an DT_SONAME value. 22750Sstevel@tonic-gate */ 22760Sstevel@tonic-gate if (soname == NULL) 22770Sstevel@tonic-gate ifl->ifl_soname = ifl->ifl_name; 22780Sstevel@tonic-gate else 22790Sstevel@tonic-gate ifl->ifl_soname = soname; 22800Sstevel@tonic-gate 22810Sstevel@tonic-gate /* 22820Sstevel@tonic-gate * If direct bindings, lazy loading, or group 22830Sstevel@tonic-gate * permissions need to be established, mark this object. 22840Sstevel@tonic-gate */ 22850Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_ZDIRECT) 22860Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DIRECT; 22870Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_LAZYLD) 22880Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_LAZYLD; 22890Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_GRPPRM) 22900Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_GRPPRM; 22910Sstevel@tonic-gate error = process_elf(ifl, elf, ofl); 22920Sstevel@tonic-gate 22930Sstevel@tonic-gate /* 22940Sstevel@tonic-gate * At this point we know if this file will be 22950Sstevel@tonic-gate * lazyloaded, or whether bindings to it must be direct. 22960Sstevel@tonic-gate * In either case, a syminfo section is required. 22970Sstevel@tonic-gate */ 22980Sstevel@tonic-gate if (ifl->ifl_flags & (FLG_IF_LAZYLD | FLG_IF_DIRECT)) 22990Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_SYMINFO; 23000Sstevel@tonic-gate 23010Sstevel@tonic-gate break; 23020Sstevel@tonic-gate default: 23030Sstevel@tonic-gate (void) elf_errno(); 23040Sstevel@tonic-gate _rej.rej_type = SGS_REJ_UNKFILE; 23050Sstevel@tonic-gate _rej.rej_name = name; 23066206Sab196087 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej, 23076206Sab196087 ld_targ.t_m.m_mach)); 23080Sstevel@tonic-gate if (rej->rej_type == 0) { 23090Sstevel@tonic-gate *rej = _rej; 23100Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name); 23110Sstevel@tonic-gate } 23127359SRod.Evans@Sun.COM return (NULL); 23130Sstevel@tonic-gate } 23140Sstevel@tonic-gate break; 23150Sstevel@tonic-gate default: 23160Sstevel@tonic-gate (void) elf_errno(); 23170Sstevel@tonic-gate _rej.rej_type = SGS_REJ_UNKFILE; 23180Sstevel@tonic-gate _rej.rej_name = name; 23196206Sab196087 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej, 23206206Sab196087 ld_targ.t_m.m_mach)); 23210Sstevel@tonic-gate if (rej->rej_type == 0) { 23220Sstevel@tonic-gate *rej = _rej; 23230Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name); 23240Sstevel@tonic-gate } 23257359SRod.Evans@Sun.COM return (NULL); 23260Sstevel@tonic-gate } 23270Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR)) 23280Sstevel@tonic-gate return ((Ifl_desc *)error); 23290Sstevel@tonic-gate else 23300Sstevel@tonic-gate return (ifl); 23310Sstevel@tonic-gate } 23320Sstevel@tonic-gate 23330Sstevel@tonic-gate /* 23340Sstevel@tonic-gate * Having successfully opened a file, set up the necessary elf structures to 23350Sstevel@tonic-gate * process it further. This small section of processing is slightly different 23360Sstevel@tonic-gate * from the elf initialization required to process a relocatable object from an 23372850Srie * archive (see libs.c: ld_process_archive()). 23380Sstevel@tonic-gate */ 23390Sstevel@tonic-gate Ifl_desc * 23402978Srie ld_process_open(const char *opath, const char *ofile, int *fd, Ofl_desc *ofl, 23414716Sab196087 Word flags, Rej_desc *rej) 23420Sstevel@tonic-gate { 23432978Srie Elf *elf; 23442978Srie const char *npath = opath; 23452978Srie const char *nfile = ofile; 23460Sstevel@tonic-gate 23472978Srie if ((elf = elf_begin(*fd, ELF_C_READ, NULL)) == NULL) { 23482978Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_BEGIN), npath); 23490Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 23507359SRod.Evans@Sun.COM return (NULL); 23510Sstevel@tonic-gate } 23520Sstevel@tonic-gate 23532978Srie /* 23542978Srie * Determine whether the support library wishes to process this open. 23552978Srie * The support library may return: 23562978Srie * . a different ELF descriptor (in which case they should have 23572978Srie * closed the original) 23582978Srie * . a different file descriptor (in which case they should have 23592978Srie * closed the original) 23602978Srie * . a different path and file name (presumably associated with 23612978Srie * a different file descriptor) 23622978Srie * 23632978Srie * A file descriptor of -1, or and ELF descriptor of zero indicates 23642978Srie * the file should be ignored. 23652978Srie */ 23662978Srie ld_sup_open(ofl, &npath, &nfile, fd, flags, &elf, NULL, 0, 23672978Srie elf_kind(elf)); 23682978Srie 23692978Srie if ((*fd == -1) || (elf == NULL)) 23707359SRod.Evans@Sun.COM return (NULL); 23712978Srie 23722978Srie return (ld_process_ifl(npath, nfile, *fd, elf, flags, ofl, rej)); 23730Sstevel@tonic-gate } 23740Sstevel@tonic-gate 23750Sstevel@tonic-gate /* 23768598SRod.Evans@Sun.COM * Having successfully mapped a file, set up the necessary elf structures to 23778598SRod.Evans@Sun.COM * process it further. This routine is patterned after ld_process_open() and 23788598SRod.Evans@Sun.COM * is only called by ld.so.1(1) to process a relocatable object. 23798598SRod.Evans@Sun.COM */ 23808598SRod.Evans@Sun.COM Ifl_desc * 23818598SRod.Evans@Sun.COM ld_process_mem(const char *path, const char *file, char *addr, size_t size, 23828598SRod.Evans@Sun.COM Ofl_desc *ofl, Rej_desc *rej) 23838598SRod.Evans@Sun.COM { 23848598SRod.Evans@Sun.COM Elf *elf; 23858598SRod.Evans@Sun.COM 23868598SRod.Evans@Sun.COM if ((elf = elf_memory(addr, size)) == NULL) { 23878598SRod.Evans@Sun.COM eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_MEMORY), path); 23888598SRod.Evans@Sun.COM ofl->ofl_flags |= FLG_OF_FATAL; 23898598SRod.Evans@Sun.COM return (0); 23908598SRod.Evans@Sun.COM } 23918598SRod.Evans@Sun.COM 23928598SRod.Evans@Sun.COM return (ld_process_ifl(path, file, 0, elf, 0, ofl, rej)); 23938598SRod.Evans@Sun.COM } 23948598SRod.Evans@Sun.COM 23958598SRod.Evans@Sun.COM /* 23960Sstevel@tonic-gate * Process a required library (i.e. the dependency of a shared object). 23970Sstevel@tonic-gate * Combine the directory and filename, check the resultant path size, and try 23980Sstevel@tonic-gate * opening the pathname. 23990Sstevel@tonic-gate */ 24001618Srie static Ifl_desc * 24010Sstevel@tonic-gate process_req_lib(Sdf_desc *sdf, const char *dir, const char *file, 24027463SRod.Evans@Sun.COM Ofl_desc *ofl, Rej_desc *rej) 24030Sstevel@tonic-gate { 24040Sstevel@tonic-gate size_t dlen, plen; 24050Sstevel@tonic-gate int fd; 24060Sstevel@tonic-gate char path[PATH_MAX]; 24070Sstevel@tonic-gate const char *_dir = dir; 24080Sstevel@tonic-gate 24090Sstevel@tonic-gate /* 24100Sstevel@tonic-gate * Determine the sizes of the directory and filename to insure we don't 24110Sstevel@tonic-gate * exceed our buffer. 24120Sstevel@tonic-gate */ 24130Sstevel@tonic-gate if ((dlen = strlen(dir)) == 0) { 24140Sstevel@tonic-gate _dir = MSG_ORIG(MSG_STR_DOT); 24150Sstevel@tonic-gate dlen = 1; 24160Sstevel@tonic-gate } 24170Sstevel@tonic-gate dlen++; 24180Sstevel@tonic-gate plen = dlen + strlen(file) + 1; 24190Sstevel@tonic-gate if (plen > PATH_MAX) { 24201618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_FIL_PTHTOLONG), 24211618Srie _dir, file); 24220Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 24230Sstevel@tonic-gate return (0); 24240Sstevel@tonic-gate } 24250Sstevel@tonic-gate 24260Sstevel@tonic-gate /* 24270Sstevel@tonic-gate * Build the entire pathname and try and open the file. 24280Sstevel@tonic-gate */ 24290Sstevel@tonic-gate (void) strcpy(path, _dir); 24300Sstevel@tonic-gate (void) strcat(path, MSG_ORIG(MSG_STR_SLASH)); 24310Sstevel@tonic-gate (void) strcat(path, file); 24321618Srie DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name, 24331618Srie sdf->sdf_rfile, path)); 24340Sstevel@tonic-gate 24350Sstevel@tonic-gate if ((fd = open(path, O_RDONLY)) == -1) 24360Sstevel@tonic-gate return (0); 24370Sstevel@tonic-gate else { 24380Sstevel@tonic-gate Ifl_desc *ifl; 24390Sstevel@tonic-gate char *_path; 24400Sstevel@tonic-gate 24410Sstevel@tonic-gate if ((_path = libld_malloc(strlen(path) + 1)) == 0) 24420Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR); 24430Sstevel@tonic-gate (void) strcpy(_path, path); 24444716Sab196087 ifl = ld_process_open(_path, &_path[dlen], &fd, ofl, 0, rej); 24452978Srie if (fd != -1) 24462978Srie (void) close(fd); 24470Sstevel@tonic-gate return (ifl); 24480Sstevel@tonic-gate } 24490Sstevel@tonic-gate } 24500Sstevel@tonic-gate 24510Sstevel@tonic-gate /* 24520Sstevel@tonic-gate * Finish any library processing. Walk the list of so's that have been listed 24530Sstevel@tonic-gate * as "included" by shared objects we have previously processed. Examine them, 24540Sstevel@tonic-gate * without adding them as explicit dependents of this program, in order to 24550Sstevel@tonic-gate * complete our symbol definition process. The search path rules are: 24560Sstevel@tonic-gate * 24570Sstevel@tonic-gate * o use any user supplied paths, i.e. LD_LIBRARY_PATH and -L, then 24580Sstevel@tonic-gate * 24590Sstevel@tonic-gate * o use any RPATH defined within the parent shared object, then 24600Sstevel@tonic-gate * 24610Sstevel@tonic-gate * o use the default directories, i.e. LIBPATH or -YP. 24620Sstevel@tonic-gate */ 24630Sstevel@tonic-gate uintptr_t 24641618Srie ld_finish_libs(Ofl_desc *ofl) 24650Sstevel@tonic-gate { 24660Sstevel@tonic-gate Listnode *lnp1; 24670Sstevel@tonic-gate Sdf_desc *sdf; 24680Sstevel@tonic-gate Rej_desc rej = { 0 }; 24690Sstevel@tonic-gate 24700Sstevel@tonic-gate /* 24710Sstevel@tonic-gate * Make sure we are back in dynamic mode. 24720Sstevel@tonic-gate */ 24730Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_DYNLIBS; 24740Sstevel@tonic-gate 24750Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_soneed, lnp1, sdf)) { 24760Sstevel@tonic-gate Listnode *lnp2; 24772850Srie char *path, *slash = NULL; 24780Sstevel@tonic-gate int fd; 24790Sstevel@tonic-gate Ifl_desc *ifl; 24802850Srie char *file = (char *)sdf->sdf_name; 24810Sstevel@tonic-gate 24820Sstevel@tonic-gate /* 24830Sstevel@tonic-gate * See if this file has already been processed. At the time 24840Sstevel@tonic-gate * this implicit dependency was determined there may still have 24851109Srie * been more explicit dependencies to process. Note, if we ever 24860Sstevel@tonic-gate * do parse the command line three times we would be able to 24871109Srie * do all this checking when processing the dynamic section. 24880Sstevel@tonic-gate */ 24890Sstevel@tonic-gate if (sdf->sdf_file) 24900Sstevel@tonic-gate continue; 24910Sstevel@tonic-gate 24920Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_sos, lnp2, ifl)) { 24930Sstevel@tonic-gate if (!(ifl->ifl_flags & FLG_IF_NEEDSTR) && 24940Sstevel@tonic-gate (strcmp(file, ifl->ifl_soname) == 0)) { 24950Sstevel@tonic-gate sdf->sdf_file = ifl; 24960Sstevel@tonic-gate break; 24970Sstevel@tonic-gate } 24980Sstevel@tonic-gate } 24990Sstevel@tonic-gate if (sdf->sdf_file) 25000Sstevel@tonic-gate continue; 25010Sstevel@tonic-gate 25020Sstevel@tonic-gate /* 25032850Srie * If the current path name element embeds a "/", then it's to 25042850Srie * be taken "as is", with no searching involved. Process all 25052850Srie * "/" occurrences, so that we can deduce the base file name. 25060Sstevel@tonic-gate */ 25072850Srie for (path = file; *path; path++) { 25080Sstevel@tonic-gate if (*path == '/') 25092850Srie slash = path; 25102850Srie } 25112850Srie if (slash) { 25121618Srie DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name, 25131618Srie sdf->sdf_rfile, file)); 25140Sstevel@tonic-gate if ((fd = open(file, O_RDONLY)) == -1) { 25151618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 25161618Srie MSG_INTL(MSG_FIL_NOTFOUND), file, 25171618Srie sdf->sdf_rfile); 25180Sstevel@tonic-gate } else { 25190Sstevel@tonic-gate Rej_desc _rej = { 0 }; 25200Sstevel@tonic-gate 25212978Srie ifl = ld_process_open(file, ++slash, &fd, ofl, 25224716Sab196087 0, &_rej); 25232978Srie if (fd != -1) 25242978Srie (void) close(fd); 25257359SRod.Evans@Sun.COM if (ifl == (Ifl_desc *)S_ERROR) 25267359SRod.Evans@Sun.COM return (S_ERROR); 25270Sstevel@tonic-gate 25280Sstevel@tonic-gate if (_rej.rej_type) { 25294734Sab196087 Conv_reject_desc_buf_t rej_buf; 25304734Sab196087 25311618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 25320Sstevel@tonic-gate MSG_INTL(reject[_rej.rej_type]), 25330Sstevel@tonic-gate _rej.rej_name ? rej.rej_name : 25340Sstevel@tonic-gate MSG_INTL(MSG_STR_UNKNOWN), 25356206Sab196087 conv_reject_desc(&_rej, &rej_buf, 25366206Sab196087 ld_targ.t_m.m_mach)); 25370Sstevel@tonic-gate } else 25380Sstevel@tonic-gate sdf->sdf_file = ifl; 25390Sstevel@tonic-gate } 25400Sstevel@tonic-gate continue; 25410Sstevel@tonic-gate } 25420Sstevel@tonic-gate 25430Sstevel@tonic-gate /* 25440Sstevel@tonic-gate * Now search for this file in any user defined directories. 25450Sstevel@tonic-gate */ 25460Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_ulibdirs, lnp2, path)) { 25470Sstevel@tonic-gate Rej_desc _rej = { 0 }; 25480Sstevel@tonic-gate 25490Sstevel@tonic-gate ifl = process_req_lib(sdf, path, file, ofl, &_rej); 25500Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) { 25510Sstevel@tonic-gate return (S_ERROR); 25520Sstevel@tonic-gate } 25530Sstevel@tonic-gate if (_rej.rej_type) { 25540Sstevel@tonic-gate if (rej.rej_type == 0) { 25550Sstevel@tonic-gate rej = _rej; 25560Sstevel@tonic-gate rej.rej_name = strdup(_rej.rej_name); 25570Sstevel@tonic-gate } 25580Sstevel@tonic-gate } 25590Sstevel@tonic-gate if (ifl) { 25600Sstevel@tonic-gate sdf->sdf_file = ifl; 25610Sstevel@tonic-gate break; 25620Sstevel@tonic-gate } 25630Sstevel@tonic-gate } 25640Sstevel@tonic-gate if (sdf->sdf_file) 25650Sstevel@tonic-gate continue; 25660Sstevel@tonic-gate 25670Sstevel@tonic-gate /* 25680Sstevel@tonic-gate * Next use the local rules defined within the parent shared 25690Sstevel@tonic-gate * object. 25700Sstevel@tonic-gate */ 25710Sstevel@tonic-gate if (sdf->sdf_rpath != NULL) { 25720Sstevel@tonic-gate char *rpath, *next; 25730Sstevel@tonic-gate 25740Sstevel@tonic-gate rpath = libld_malloc(strlen(sdf->sdf_rpath) + 1); 25750Sstevel@tonic-gate if (rpath == 0) 25760Sstevel@tonic-gate return (S_ERROR); 25770Sstevel@tonic-gate (void) strcpy(rpath, sdf->sdf_rpath); 25781618Srie DBG_CALL(Dbg_libs_path(ofl->ofl_lml, rpath, 25791618Srie LA_SER_RUNPATH, sdf->sdf_rfile)); 25800Sstevel@tonic-gate if ((path = strtok_r(rpath, 25810Sstevel@tonic-gate MSG_ORIG(MSG_STR_COLON), &next)) != NULL) { 25820Sstevel@tonic-gate do { 25830Sstevel@tonic-gate Rej_desc _rej = { 0 }; 25840Sstevel@tonic-gate 25850Sstevel@tonic-gate path = expand(sdf->sdf_rfile, path, 25860Sstevel@tonic-gate &next); 25870Sstevel@tonic-gate 25880Sstevel@tonic-gate ifl = process_req_lib(sdf, path, 25894716Sab196087 file, ofl, &_rej); 25900Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) { 25910Sstevel@tonic-gate return (S_ERROR); 25920Sstevel@tonic-gate } 25934716Sab196087 if ((_rej.rej_type) && 25944716Sab196087 (rej.rej_type == 0)) { 25954716Sab196087 rej = _rej; 25964716Sab196087 rej.rej_name = 25974716Sab196087 strdup(_rej.rej_name); 25980Sstevel@tonic-gate } 25990Sstevel@tonic-gate if (ifl) { 26000Sstevel@tonic-gate sdf->sdf_file = ifl; 26010Sstevel@tonic-gate break; 26020Sstevel@tonic-gate } 26030Sstevel@tonic-gate } while ((path = strtok_r(NULL, 26040Sstevel@tonic-gate MSG_ORIG(MSG_STR_COLON), &next)) != NULL); 26050Sstevel@tonic-gate } 26060Sstevel@tonic-gate } 26070Sstevel@tonic-gate if (sdf->sdf_file) 26080Sstevel@tonic-gate continue; 26090Sstevel@tonic-gate 26100Sstevel@tonic-gate /* 26110Sstevel@tonic-gate * Finally try the default library search directories. 26120Sstevel@tonic-gate */ 26130Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_dlibdirs, lnp2, path)) { 26140Sstevel@tonic-gate Rej_desc _rej = { 0 }; 26150Sstevel@tonic-gate 26160Sstevel@tonic-gate ifl = process_req_lib(sdf, path, file, ofl, &rej); 26170Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) { 26180Sstevel@tonic-gate return (S_ERROR); 26190Sstevel@tonic-gate } 26200Sstevel@tonic-gate if (_rej.rej_type) { 26210Sstevel@tonic-gate if (rej.rej_type == 0) { 26220Sstevel@tonic-gate rej = _rej; 26230Sstevel@tonic-gate rej.rej_name = strdup(_rej.rej_name); 26240Sstevel@tonic-gate } 26250Sstevel@tonic-gate } 26260Sstevel@tonic-gate if (ifl) { 26270Sstevel@tonic-gate sdf->sdf_file = ifl; 26280Sstevel@tonic-gate break; 26290Sstevel@tonic-gate } 26300Sstevel@tonic-gate } 26310Sstevel@tonic-gate if (sdf->sdf_file) 26320Sstevel@tonic-gate continue; 26330Sstevel@tonic-gate 26340Sstevel@tonic-gate /* 26350Sstevel@tonic-gate * If we've got this far we haven't found the shared object. 26360Sstevel@tonic-gate * If an object was found, but was rejected for some reason, 26370Sstevel@tonic-gate * print a diagnostic to that effect, otherwise generate a 26380Sstevel@tonic-gate * generic "not found" diagnostic. 26390Sstevel@tonic-gate */ 26400Sstevel@tonic-gate if (rej.rej_type) { 26414734Sab196087 Conv_reject_desc_buf_t rej_buf; 26424734Sab196087 26431618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 26441618Srie MSG_INTL(reject[rej.rej_type]), 26450Sstevel@tonic-gate rej.rej_name ? rej.rej_name : 26464734Sab196087 MSG_INTL(MSG_STR_UNKNOWN), 26476206Sab196087 conv_reject_desc(&rej, &rej_buf, 26486206Sab196087 ld_targ.t_m.m_mach)); 26490Sstevel@tonic-gate } else { 26501618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 26511618Srie MSG_INTL(MSG_FIL_NOTFOUND), file, sdf->sdf_rfile); 26520Sstevel@tonic-gate } 26530Sstevel@tonic-gate } 26540Sstevel@tonic-gate 26550Sstevel@tonic-gate /* 26560Sstevel@tonic-gate * Finally, now that all objects have been input, make sure any version 26570Sstevel@tonic-gate * requirements have been met. 26580Sstevel@tonic-gate */ 26591618Srie return (ld_vers_verify(ofl)); 26600Sstevel@tonic-gate } 2661