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 * 266206Sab196087 * Copyright 2008 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 53*7463SRod.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; 183*7463SRod.Evans@Sun.COM isp->is_keyident = ident; 184*7463SRod.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 199*7463SRod.Evans@Sun.COM * flag whether the section needs placing in an output section. This 200*7463SRod.Evans@Sun.COM * placement is deferred until all input section processing has been 201*7463SRod.Evans@Sun.COM * completed, as SHT_GROUP sections can provide information that will 202*7463SRod.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 206*7463SRod.Evans@Sun.COM if (ident) { 207*7463SRod.Evans@Sun.COM if (shdr->sh_flags & ALL_SHF_ORDER) { 208*7463SRod.Evans@Sun.COM isp->is_flags |= FLG_IS_ORDERED; 209*7463SRod.Evans@Sun.COM ifl->ifl_flags |= FLG_IF_ORDERED; 2102647Srie } 211*7463SRod.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 2560Sstevel@tonic-gate /* 2570Sstevel@tonic-gate * If this object doesn't specify any capabilities, ignore it, and 2580Sstevel@tonic-gate * leave the state as is. 2590Sstevel@tonic-gate */ 2600Sstevel@tonic-gate if (val == 0) 2610Sstevel@tonic-gate return; 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate /* 2640Sstevel@tonic-gate * Make sure we only accept known software capabilities. Note, that 2650Sstevel@tonic-gate * an F1_SUNW_FPUSED by itself is viewed as bad practice. 2660Sstevel@tonic-gate */ 2670Sstevel@tonic-gate if ((badval = (val & ~SF1_SUNW_MASK)) != 0) { 2681618Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1), 2690Sstevel@tonic-gate ifl->ifl_name, name, EC_XWORD(badval)); 2700Sstevel@tonic-gate val &= SF1_SUNW_MASK; 2710Sstevel@tonic-gate } 2720Sstevel@tonic-gate if (val == SF1_SUNW_FPUSED) { 2731618Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1), 2740Sstevel@tonic-gate ifl->ifl_name, name, EC_XWORD(val)); 2750Sstevel@tonic-gate return; 2760Sstevel@tonic-gate } 2770Sstevel@tonic-gate 2781618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_OLD, CA_SUNW_SF_1, 2796206Sab196087 ofl->ofl_sfcap_1, ld_targ.t_m.m_mach); 2801618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_NEW, CA_SUNW_SF_1, 2816206Sab196087 val, ld_targ.t_m.m_mach); 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate /* 2840Sstevel@tonic-gate * Determine the resolution of the present frame pointer and the 2850Sstevel@tonic-gate * new input relocatable objects frame pointer. 2860Sstevel@tonic-gate */ 2870Sstevel@tonic-gate if ((ofl->ofl_sfcap_1 & (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)) == 2880Sstevel@tonic-gate (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)) { 2890Sstevel@tonic-gate /* 2900Sstevel@tonic-gate * If the new relocatable object isn't using a frame pointer, 2910Sstevel@tonic-gate * reduce the present state to unused. 2920Sstevel@tonic-gate */ 2930Sstevel@tonic-gate if ((val & (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)) != 2940Sstevel@tonic-gate (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)) 2950Sstevel@tonic-gate ofl->ofl_sfcap_1 &= ~SF1_SUNW_FPUSED; 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate } else if ((ofl->ofl_sfcap_1 & SF1_SUNW_FPKNWN) == 0) { 2980Sstevel@tonic-gate /* 2990Sstevel@tonic-gate * If the present state is unknown, take the new relocatable 3000Sstevel@tonic-gate * object frame pointer usage. 3010Sstevel@tonic-gate */ 3020Sstevel@tonic-gate ofl->ofl_sfcap_1 = val; 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate 3051618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_RESOLVED, CA_SUNW_SF_1, 3066206Sab196087 ofl->ofl_sfcap_1, ld_targ.t_m.m_mach); 3070Sstevel@tonic-gate } 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate /* 3100Sstevel@tonic-gate * Determine the hardware capabilities of the object being built from the 3110Sstevel@tonic-gate * capabilities of the input relocatable objects. There's really little to 3120Sstevel@tonic-gate * do here, other than to offer diagnostics, hardware capabilities are simply 3130Sstevel@tonic-gate * additive. 3140Sstevel@tonic-gate */ 3150Sstevel@tonic-gate static void 3160Sstevel@tonic-gate hw1_cap(Ofl_desc *ofl, Xword val) 3170Sstevel@tonic-gate { 3180Sstevel@tonic-gate /* 3190Sstevel@tonic-gate * If a mapfile has established definitions to override any input 3200Sstevel@tonic-gate * capabilities, ignore any new input capabilities. 3210Sstevel@tonic-gate */ 3220Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_OVHWCAP) { 3231618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_IGNORE, CA_SUNW_HW_1, 3246206Sab196087 val, ld_targ.t_m.m_mach); 3250Sstevel@tonic-gate return; 3260Sstevel@tonic-gate } 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate /* 3290Sstevel@tonic-gate * If this object doesn't specify any capabilities, ignore it, and 3300Sstevel@tonic-gate * leave the state as is. 3310Sstevel@tonic-gate */ 3320Sstevel@tonic-gate if (val == 0) 3330Sstevel@tonic-gate return; 3340Sstevel@tonic-gate 3351618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_OLD, CA_SUNW_HW_1, 3366206Sab196087 ofl->ofl_hwcap_1, ld_targ.t_m.m_mach); 3376206Sab196087 Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_NEW, CA_SUNW_HW_1, val, 3386206Sab196087 ld_targ.t_m.m_mach); 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate ofl->ofl_hwcap_1 |= val; 3410Sstevel@tonic-gate 3421618Srie Dbg_cap_sec_entry(ofl->ofl_lml, DBG_CAP_RESOLVED, CA_SUNW_HW_1, 3436206Sab196087 ofl->ofl_hwcap_1, ld_targ.t_m.m_mach); 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /* 3470Sstevel@tonic-gate * Process a hardware/software capabilities section. Traverse the section 3480Sstevel@tonic-gate * updating the global capabilities variables as necessary. 3490Sstevel@tonic-gate */ 3500Sstevel@tonic-gate static void 3513617Srie process_cap(Ifl_desc *ifl, Is_desc *cisp, Ofl_desc *ofl) 3520Sstevel@tonic-gate { 3531618Srie Cap *cdata; 3543617Srie Word ndx, cnum; 3550Sstevel@tonic-gate 3561824Srie DBG_CALL(Dbg_cap_sec_title(ofl)); 3570Sstevel@tonic-gate 3583617Srie /* 3593617Srie * The capabilities are supposed to be terminated with a CA_SUNW_NULL 3603617Srie * entry. However, the compilers have been known to not follow this 3613617Srie * convention. Use the section information to determine the number 3623617Srie * of capabilities, and skip any CA_SUNW_NULL entries. 3633617Srie */ 3643617Srie cdata = (Cap *)cisp->is_indata->d_buf; 3653617Srie cnum = (Word)(cisp->is_shdr->sh_size / cisp->is_shdr->sh_entsize); 3663617Srie 3673617Srie for (ndx = 0; ndx < cnum; cdata++, ndx++) { 3680Sstevel@tonic-gate switch (cdata->c_tag) { 3690Sstevel@tonic-gate case CA_SUNW_HW_1: 3700Sstevel@tonic-gate hw1_cap(ofl, cdata->c_un.c_val); 3710Sstevel@tonic-gate break; 3720Sstevel@tonic-gate case CA_SUNW_SF_1: 3733617Srie sf1_cap(ofl, cdata->c_un.c_val, ifl, 3743617Srie cisp->is_name); 3753617Srie break; 3763617Srie case CA_SUNW_NULL: 3770Sstevel@tonic-gate break; 3780Sstevel@tonic-gate default: 3791618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 3801618Srie MSG_INTL(MSG_FIL_UNKCAP), 3813617Srie ifl->ifl_name, cisp->is_name, cdata->c_tag); 3820Sstevel@tonic-gate } 3830Sstevel@tonic-gate } 3840Sstevel@tonic-gate } 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate /* 3870Sstevel@tonic-gate * Simply process the section so that we have pointers to the data for use 3880Sstevel@tonic-gate * in later routines, however don't add the section to the output section 3890Sstevel@tonic-gate * list as we will be creating our own replacement sections later (ie. 3900Sstevel@tonic-gate * symtab and relocation). 3910Sstevel@tonic-gate */ 3921618Srie static uintptr_t 3930Sstevel@tonic-gate /* ARGSUSED5 */ 3940Sstevel@tonic-gate process_input(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 395*7463SRod.Evans@Sun.COM Word ndx, int ident, Ofl_desc *ofl) 3960Sstevel@tonic-gate { 3976206Sab196087 return (process_section(name, ifl, shdr, scn, ndx, 3986206Sab196087 ld_targ.t_id.id_null, ofl)); 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate /* 4020Sstevel@tonic-gate * Keep a running count of relocation entries from input relocatable objects for 4030Sstevel@tonic-gate * sizing relocation buckets later. If we're building an executable, save any 4040Sstevel@tonic-gate * relocations from shared objects to determine if any copy relocation symbol 4050Sstevel@tonic-gate * has a displacement relocation against it. 4060Sstevel@tonic-gate */ 4071618Srie static uintptr_t 4080Sstevel@tonic-gate /* ARGSUSED5 */ 4090Sstevel@tonic-gate process_reloc(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 410*7463SRod.Evans@Sun.COM Word ndx, int ident, Ofl_desc *ofl) 4110Sstevel@tonic-gate { 4120Sstevel@tonic-gate if (process_section(name, ifl, 4136206Sab196087 shdr, scn, ndx, ld_targ.t_id.id_null, ofl) == S_ERROR) 4140Sstevel@tonic-gate return (S_ERROR); 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate if (ifl->ifl_ehdr->e_type == ET_REL) { 4170Sstevel@tonic-gate if (shdr->sh_entsize && (shdr->sh_entsize <= shdr->sh_size)) 4180Sstevel@tonic-gate /* LINTED */ 4190Sstevel@tonic-gate ofl->ofl_relocincnt += 4200Sstevel@tonic-gate (Word)(shdr->sh_size / shdr->sh_entsize); 4210Sstevel@tonic-gate } else if (ofl->ofl_flags & FLG_OF_EXEC) { 4220Sstevel@tonic-gate if (list_appendc(&ifl->ifl_relsect, ifl->ifl_isdesc[ndx]) == 0) 4230Sstevel@tonic-gate return (S_ERROR); 4240Sstevel@tonic-gate } 4250Sstevel@tonic-gate return (1); 4260Sstevel@tonic-gate } 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate /* 4300Sstevel@tonic-gate * Process a string table section. A valid section contains an initial and 4310Sstevel@tonic-gate * final null byte. 4320Sstevel@tonic-gate */ 4331618Srie static uintptr_t 4340Sstevel@tonic-gate process_strtab(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 435*7463SRod.Evans@Sun.COM Word ndx, int ident, Ofl_desc *ofl) 4360Sstevel@tonic-gate { 4370Sstevel@tonic-gate char *data; 4380Sstevel@tonic-gate size_t size; 4390Sstevel@tonic-gate Is_desc *isp; 4400Sstevel@tonic-gate uintptr_t error; 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate /* 4430Sstevel@tonic-gate * Never include .stab.excl sections in any output file. 4440Sstevel@tonic-gate * If the -s flag has been specified strip any .stab sections. 4450Sstevel@tonic-gate */ 4460Sstevel@tonic-gate if (((ofl->ofl_flags & FLG_OF_STRIP) && ident && 4470Sstevel@tonic-gate (strncmp(name, MSG_ORIG(MSG_SCN_STAB), MSG_SCN_STAB_SIZE) == 0)) || 4480Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_STABEXCL)) == 0) && ident) 4490Sstevel@tonic-gate return (1); 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate /* 4520Sstevel@tonic-gate * If we got here to process a .shstrtab or .dynstr table, `ident' will 4530Sstevel@tonic-gate * be null. Otherwise make sure we don't have a .strtab section as this 4540Sstevel@tonic-gate * should not be added to the output section list either. 4550Sstevel@tonic-gate */ 4566206Sab196087 if ((ident != ld_targ.t_id.id_null) && 4570Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_STRTAB)) == 0)) 4586206Sab196087 ident = ld_targ.t_id.id_null; 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate error = process_section(name, ifl, shdr, scn, ndx, ident, ofl); 4610Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR)) 4620Sstevel@tonic-gate return (error); 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate /* 4650Sstevel@tonic-gate * String tables should start and end with a NULL byte. Note, it has 4660Sstevel@tonic-gate * been known for the assembler to create empty string tables, so check 4670Sstevel@tonic-gate * the size before attempting to verify the data itself. 4680Sstevel@tonic-gate */ 4690Sstevel@tonic-gate isp = ifl->ifl_isdesc[ndx]; 4700Sstevel@tonic-gate size = isp->is_indata->d_size; 4710Sstevel@tonic-gate if (size) { 4720Sstevel@tonic-gate data = isp->is_indata->d_buf; 4730Sstevel@tonic-gate if (data[0] != '\0' || data[size - 1] != '\0') 4741618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 4751618Srie MSG_INTL(MSG_FIL_MALSTR), ifl->ifl_name, name); 4760Sstevel@tonic-gate } else 4770Sstevel@tonic-gate isp->is_indata->d_buf = (void *)MSG_ORIG(MSG_STR_EMPTY); 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_HSTRTAB; 4800Sstevel@tonic-gate return (1); 4810Sstevel@tonic-gate } 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate /* 4840Sstevel@tonic-gate * Invalid sections produce a warning and are skipped. 4850Sstevel@tonic-gate */ 4861618Srie static uintptr_t 4870Sstevel@tonic-gate /* ARGSUSED3 */ 4880Sstevel@tonic-gate invalid_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 4890Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 4900Sstevel@tonic-gate { 4914734Sab196087 Conv_inv_buf_t inv_buf; 4924734Sab196087 4931618Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_INVALSEC), 4941618Srie ifl->ifl_name, name, conv_sec_type(ifl->ifl_ehdr->e_machine, 4954734Sab196087 shdr->sh_type, 0, &inv_buf)); 4960Sstevel@tonic-gate return (1); 4970Sstevel@tonic-gate } 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate /* 5000Sstevel@tonic-gate * Process a progbits section. 5010Sstevel@tonic-gate */ 5021618Srie static uintptr_t 5030Sstevel@tonic-gate process_progbits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 5040Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 5050Sstevel@tonic-gate { 5060Sstevel@tonic-gate int stab_index = 0; 5070Sstevel@tonic-gate 5080Sstevel@tonic-gate /* 5090Sstevel@tonic-gate * Never include .stab.excl sections in any output file. 5100Sstevel@tonic-gate * If the -s flag has been specified strip any .stab sections. 5110Sstevel@tonic-gate */ 5120Sstevel@tonic-gate if (ident && (strncmp(name, MSG_ORIG(MSG_SCN_STAB), 5130Sstevel@tonic-gate MSG_SCN_STAB_SIZE) == 0)) { 5140Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STRIP) || 5150Sstevel@tonic-gate (strcmp((name + MSG_SCN_STAB_SIZE), 5164716Sab196087 MSG_ORIG(MSG_SCN_EXCL)) == 0)) 5170Sstevel@tonic-gate return (1); 5180Sstevel@tonic-gate 5190Sstevel@tonic-gate if (strcmp((name + MSG_SCN_STAB_SIZE), 5200Sstevel@tonic-gate MSG_ORIG(MSG_SCN_INDEX)) == 0) 5210Sstevel@tonic-gate stab_index = 1; 5220Sstevel@tonic-gate } 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STRIP) && ident) { 5250Sstevel@tonic-gate if ((strncmp(name, MSG_ORIG(MSG_SCN_DEBUG), 5260Sstevel@tonic-gate MSG_SCN_DEBUG_SIZE) == 0) || 5270Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_LINE)) == 0)) 5280Sstevel@tonic-gate return (1); 5290Sstevel@tonic-gate } 5300Sstevel@tonic-gate 5310Sstevel@tonic-gate /* 5320Sstevel@tonic-gate * Update the ident to reflect the type of section we've got. 5330Sstevel@tonic-gate * 5340Sstevel@tonic-gate * If there is any .plt or .got section to generate we'll be creating 5350Sstevel@tonic-gate * our own version, so don't allow any input sections of these types to 5360Sstevel@tonic-gate * be added to the output section list (why a relocatable object would 5370Sstevel@tonic-gate * have a .plt or .got is a mystery, but stranger things have occurred). 5380Sstevel@tonic-gate */ 5390Sstevel@tonic-gate if (ident) { 5400Sstevel@tonic-gate if (shdr->sh_flags & SHF_TLS) 5416206Sab196087 ident = ld_targ.t_id.id_tls; 5420Sstevel@tonic-gate else if ((shdr->sh_flags & ~ALL_SHF_IGNORE) == 5430Sstevel@tonic-gate (SHF_ALLOC | SHF_EXECINSTR)) 5446206Sab196087 ident = ld_targ.t_id.id_text; 5450Sstevel@tonic-gate else if (shdr->sh_flags & SHF_ALLOC) { 5460Sstevel@tonic-gate if ((strcmp(name, MSG_ORIG(MSG_SCN_PLT)) == 0) || 5470Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_GOT)) == 0)) 5486206Sab196087 ident = ld_targ.t_id.id_null; 5490Sstevel@tonic-gate else if (stab_index) { 5500Sstevel@tonic-gate /* 5510Sstevel@tonic-gate * This is a work-around for x86 compilers that 5520Sstevel@tonic-gate * have set SHF_ALLOC for the .stab.index 5530Sstevel@tonic-gate * section. 5540Sstevel@tonic-gate * 5550Sstevel@tonic-gate * Because of this, make sure that the 5560Sstevel@tonic-gate * .stab.index does not end up as the last 5570Sstevel@tonic-gate * section in the text segment. Older linkers 5580Sstevel@tonic-gate * can produce segmentation violations when they 5590Sstevel@tonic-gate * strip (ld -s) against a shared object whose 5600Sstevel@tonic-gate * last section in the text segment is a .stab. 5610Sstevel@tonic-gate */ 5626206Sab196087 ident = ld_targ.t_id.id_interp; 5630Sstevel@tonic-gate } else 5646206Sab196087 ident = ld_targ.t_id.id_data; 5650Sstevel@tonic-gate } else 5666206Sab196087 ident = ld_targ.t_id.id_note; 5670Sstevel@tonic-gate } 5680Sstevel@tonic-gate return (process_section(name, ifl, shdr, scn, ndx, ident, ofl)); 5690Sstevel@tonic-gate } 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate /* 5720Sstevel@tonic-gate * Handles the SHT_SUNW_{DEBUG,DEBUGSTR) sections. 5730Sstevel@tonic-gate */ 5741618Srie static uintptr_t 5750Sstevel@tonic-gate process_debug(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 5760Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 5770Sstevel@tonic-gate { 5780Sstevel@tonic-gate /* 5790Sstevel@tonic-gate * Debug information is discarded when the 'ld -s' flag is invoked. 5800Sstevel@tonic-gate */ 5810Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_STRIP) { 5820Sstevel@tonic-gate return (1); 5830Sstevel@tonic-gate } 5840Sstevel@tonic-gate return (process_progbits(name, ifl, shdr, scn, ndx, ident, ofl)); 5850Sstevel@tonic-gate } 5860Sstevel@tonic-gate 5870Sstevel@tonic-gate /* 5880Sstevel@tonic-gate * Process a nobits section. 5890Sstevel@tonic-gate */ 5901618Srie static uintptr_t 5910Sstevel@tonic-gate process_nobits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 5920Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 5930Sstevel@tonic-gate { 5940Sstevel@tonic-gate if (ident) { 5950Sstevel@tonic-gate if (shdr->sh_flags & SHF_TLS) 5966206Sab196087 ident = ld_targ.t_id.id_tlsbss; 5976206Sab196087 #if defined(_ELF64) 5986206Sab196087 else if ((shdr->sh_flags & SHF_AMD64_LARGE) && 5996206Sab196087 (ld_targ.t_m.m_mach == EM_AMD64)) 6006206Sab196087 ident = ld_targ.t_id.id_lbss; 601574Sseizo #endif 6020Sstevel@tonic-gate else 6036206Sab196087 ident = ld_targ.t_id.id_bss; 6040Sstevel@tonic-gate } 6050Sstevel@tonic-gate return (process_section(name, ifl, shdr, scn, ndx, ident, ofl)); 6060Sstevel@tonic-gate } 6070Sstevel@tonic-gate 6080Sstevel@tonic-gate /* 6090Sstevel@tonic-gate * Process a SHT_*_ARRAY section. 6100Sstevel@tonic-gate */ 6111618Srie static uintptr_t 6120Sstevel@tonic-gate process_array(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 6130Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 6140Sstevel@tonic-gate { 615*7463SRod.Evans@Sun.COM uintptr_t error; 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate if (ident) 6186206Sab196087 ident = ld_targ.t_id.id_array; 6190Sstevel@tonic-gate 620*7463SRod.Evans@Sun.COM error = process_section(name, ifl, shdr, scn, ndx, ident, ofl); 621*7463SRod.Evans@Sun.COM if ((error == 0) || (error == S_ERROR)) 622*7463SRod.Evans@Sun.COM return (error); 623*7463SRod.Evans@Sun.COM 624*7463SRod.Evans@Sun.COM return (1); 625*7463SRod.Evans@Sun.COM } 6260Sstevel@tonic-gate 627*7463SRod.Evans@Sun.COM static uintptr_t 628*7463SRod.Evans@Sun.COM /* ARGSUSED1 */ 629*7463SRod.Evans@Sun.COM array_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl) 630*7463SRod.Evans@Sun.COM { 631*7463SRod.Evans@Sun.COM Os_desc *osp; 632*7463SRod.Evans@Sun.COM Shdr *shdr; 633*7463SRod.Evans@Sun.COM 634*7463SRod.Evans@Sun.COM if ((isc == NULL) || ((osp = isc->is_osdesc) == NULL)) 6350Sstevel@tonic-gate return (0); 6360Sstevel@tonic-gate 637*7463SRod.Evans@Sun.COM shdr = isc->is_shdr; 638*7463SRod.Evans@Sun.COM 6390Sstevel@tonic-gate if ((shdr->sh_type == SHT_FINI_ARRAY) && 640*7463SRod.Evans@Sun.COM (ofl->ofl_osfiniarray == NULL)) 6410Sstevel@tonic-gate ofl->ofl_osfiniarray = osp; 6420Sstevel@tonic-gate else if ((shdr->sh_type == SHT_INIT_ARRAY) && 643*7463SRod.Evans@Sun.COM (ofl->ofl_osinitarray == NULL)) 6440Sstevel@tonic-gate ofl->ofl_osinitarray = osp; 6450Sstevel@tonic-gate else if ((shdr->sh_type == SHT_PREINIT_ARRAY) && 646*7463SRod.Evans@Sun.COM (ofl->ofl_ospreinitarray == NULL)) 6470Sstevel@tonic-gate ofl->ofl_ospreinitarray = osp; 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate return (1); 6500Sstevel@tonic-gate } 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate /* 6530Sstevel@tonic-gate * Process a SHT_SYMTAB_SHNDX section. 6540Sstevel@tonic-gate */ 6551618Srie static uintptr_t 6560Sstevel@tonic-gate process_sym_shndx(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 6570Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 6580Sstevel@tonic-gate { 6590Sstevel@tonic-gate if (process_input(name, ifl, shdr, scn, ndx, ident, ofl) == S_ERROR) 6600Sstevel@tonic-gate return (S_ERROR); 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate /* 6630Sstevel@tonic-gate * Have we already seen the related SYMTAB - if so verify it now. 6640Sstevel@tonic-gate */ 6650Sstevel@tonic-gate if (shdr->sh_link < ndx) { 6660Sstevel@tonic-gate Is_desc *isp = ifl->ifl_isdesc[shdr->sh_link]; 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate if ((isp == 0) || ((isp->is_shdr->sh_type != SHT_SYMTAB) && 6690Sstevel@tonic-gate (isp->is_shdr->sh_type != SHT_DYNSYM))) { 6701618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 6711618Srie MSG_INTL(MSG_FIL_INVSHLINK), ifl->ifl_name, name, 6721618Srie EC_XWORD(shdr->sh_link)); 6730Sstevel@tonic-gate return (S_ERROR); 6740Sstevel@tonic-gate } 6750Sstevel@tonic-gate isp->is_symshndx = ifl->ifl_isdesc[ndx]; 6760Sstevel@tonic-gate } 6770Sstevel@tonic-gate return (1); 6780Sstevel@tonic-gate } 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate /* 6810Sstevel@tonic-gate * Final processing for SHT_SYMTAB_SHNDX section. 6820Sstevel@tonic-gate */ 6831618Srie static uintptr_t 6840Sstevel@tonic-gate /* ARGSUSED2 */ 6850Sstevel@tonic-gate sym_shndx_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl) 6860Sstevel@tonic-gate { 6870Sstevel@tonic-gate if (isc->is_shdr->sh_link > isc->is_scnndx) { 6880Sstevel@tonic-gate Is_desc *isp = ifl->ifl_isdesc[isc->is_shdr->sh_link]; 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate if ((isp == 0) || ((isp->is_shdr->sh_type != SHT_SYMTAB) && 6910Sstevel@tonic-gate (isp->is_shdr->sh_type != SHT_DYNSYM))) { 6921618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 6931618Srie MSG_INTL(MSG_FIL_INVSHLINK), isc->is_file->ifl_name, 6941618Srie isc->is_name, EC_XWORD(isc->is_shdr->sh_link)); 6950Sstevel@tonic-gate return (S_ERROR); 6960Sstevel@tonic-gate } 6970Sstevel@tonic-gate isp->is_symshndx = isc; 6980Sstevel@tonic-gate } 6990Sstevel@tonic-gate return (1); 7000Sstevel@tonic-gate } 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate /* 7030Sstevel@tonic-gate * Process .dynamic section from a relocatable object. 7040Sstevel@tonic-gate * 7050Sstevel@tonic-gate * Note: That the .dynamic section is only considered interesting when 7060Sstevel@tonic-gate * dlopen()ing a relocatable object (thus FLG_OF1_RELDYN can only get 7070Sstevel@tonic-gate * set when libld is called from ld.so.1). 7080Sstevel@tonic-gate */ 7090Sstevel@tonic-gate /*ARGSUSED*/ 7101618Srie static uintptr_t 7110Sstevel@tonic-gate process_rel_dynamic(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 7120Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl) 7130Sstevel@tonic-gate { 7140Sstevel@tonic-gate Dyn *dyn; 7150Sstevel@tonic-gate Elf_Scn *strscn; 7160Sstevel@tonic-gate Elf_Data *dp; 7170Sstevel@tonic-gate char *str; 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate /* 7200Sstevel@tonic-gate * Process .dynamic sections from relocatable objects ? 7210Sstevel@tonic-gate */ 7220Sstevel@tonic-gate if ((ofl->ofl_flags1 & FLG_OF1_RELDYN) == 0) 7230Sstevel@tonic-gate return (1); 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate /* 7260Sstevel@tonic-gate * Find the string section associated with the .dynamic section. 7270Sstevel@tonic-gate */ 7280Sstevel@tonic-gate if ((strscn = elf_getscn(ifl->ifl_elf, shdr->sh_link)) == NULL) { 7291618Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN), 7301618Srie ifl->ifl_name); 7310Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 7320Sstevel@tonic-gate return (0); 7330Sstevel@tonic-gate } 7340Sstevel@tonic-gate dp = elf_getdata(strscn, NULL); 7350Sstevel@tonic-gate str = (char *)dp->d_buf; 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate /* 7380Sstevel@tonic-gate * And get the .dynamic data 7390Sstevel@tonic-gate */ 7400Sstevel@tonic-gate dp = elf_getdata(scn, NULL); 7410Sstevel@tonic-gate 7420Sstevel@tonic-gate for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) { 7431109Srie Ifl_desc *difl; 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate switch (dyn->d_tag) { 7460Sstevel@tonic-gate case DT_NEEDED: 7470Sstevel@tonic-gate case DT_USED: 7481109Srie if (((difl = 7491109Srie libld_calloc(1, sizeof (Ifl_desc))) == 0) || 7501109Srie (list_appendc(&ofl->ofl_sos, difl) == 0)) 7510Sstevel@tonic-gate return (S_ERROR); 7521109Srie 7531109Srie difl->ifl_name = MSG_ORIG(MSG_STR_DYNAMIC); 7541109Srie difl->ifl_soname = str + (size_t)dyn->d_un.d_val; 7551109Srie difl->ifl_flags = FLG_IF_NEEDSTR; 7560Sstevel@tonic-gate break; 7570Sstevel@tonic-gate case DT_RPATH: 7580Sstevel@tonic-gate case DT_RUNPATH: 7590Sstevel@tonic-gate if ((ofl->ofl_rpath = add_string(ofl->ofl_rpath, 7600Sstevel@tonic-gate (str + (size_t)dyn->d_un.d_val))) == 7610Sstevel@tonic-gate (const char *)S_ERROR) 7620Sstevel@tonic-gate return (S_ERROR); 7630Sstevel@tonic-gate break; 7644716Sab196087 case DT_VERSYM: 7654716Sab196087 /* 7664716Sab196087 * The Solaris ld does not put DT_VERSYM in the 7674716Sab196087 * dynamic section. If the object has DT_VERSYM, 7684716Sab196087 * then it must have been produced by the GNU ld, 7694716Sab196087 * and is using the GNU style of versioning. 7704716Sab196087 */ 7714716Sab196087 ifl->ifl_flags |= FLG_IF_GNUVER; 7724716Sab196087 break; 7730Sstevel@tonic-gate } 7740Sstevel@tonic-gate } 7750Sstevel@tonic-gate return (1); 7760Sstevel@tonic-gate } 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate /* 7790Sstevel@tonic-gate * Expand implicit references. Dependencies can be specified in terms of the 7800Sstevel@tonic-gate * $ORIGIN, $PLATFORM, $OSREL and $OSNAME tokens, either from their needed name, 7810Sstevel@tonic-gate * or via a runpath. In addition runpaths may also specify the $ISALIST token. 7820Sstevel@tonic-gate * 7831109Srie * Probably the most common reference to explicit dependencies (via -L) will be 7840Sstevel@tonic-gate * sufficient to find any associated implicit dependencies, but just in case we 7850Sstevel@tonic-gate * expand any occurrence of these known tokens here. 7860Sstevel@tonic-gate * 7870Sstevel@tonic-gate * Note, if any errors occur we simply return the original name. 7880Sstevel@tonic-gate * 7890Sstevel@tonic-gate * This code is remarkably similar to expand() in rtld/common/paths.c. 7900Sstevel@tonic-gate */ 7910Sstevel@tonic-gate static char *platform = 0; 7920Sstevel@tonic-gate static size_t platform_sz = 0; 7930Sstevel@tonic-gate static Isa_desc *isa = 0; 7940Sstevel@tonic-gate static Uts_desc *uts = 0; 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate static char * 7970Sstevel@tonic-gate expand(const char *parent, const char *name, char **next) 7980Sstevel@tonic-gate { 7990Sstevel@tonic-gate char _name[PATH_MAX], *nptr, *_next; 8000Sstevel@tonic-gate const char *optr; 8010Sstevel@tonic-gate size_t nrem = PATH_MAX - 1; 8020Sstevel@tonic-gate int expanded = 0, _expanded, isaflag = 0; 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate optr = name; 8050Sstevel@tonic-gate nptr = _name; 8060Sstevel@tonic-gate 8070Sstevel@tonic-gate while (*optr) { 8080Sstevel@tonic-gate if (nrem == 0) 8090Sstevel@tonic-gate return ((char *)name); 8100Sstevel@tonic-gate 8110Sstevel@tonic-gate if (*optr != '$') { 8120Sstevel@tonic-gate *nptr++ = *optr++, nrem--; 8130Sstevel@tonic-gate continue; 8140Sstevel@tonic-gate } 8150Sstevel@tonic-gate 8160Sstevel@tonic-gate _expanded = 0; 8170Sstevel@tonic-gate 8180Sstevel@tonic-gate if (strncmp(optr, MSG_ORIG(MSG_STR_ORIGIN), 8190Sstevel@tonic-gate MSG_STR_ORIGIN_SIZE) == 0) { 8200Sstevel@tonic-gate char *eptr; 8210Sstevel@tonic-gate 8220Sstevel@tonic-gate /* 8230Sstevel@tonic-gate * For $ORIGIN, expansion is really just a concatenation 8240Sstevel@tonic-gate * of the parents directory name. For example, an 8251109Srie * explicit dependency foo/bar/lib1.so with a dependency 8260Sstevel@tonic-gate * on $ORIGIN/lib2.so would be expanded to 8270Sstevel@tonic-gate * foo/bar/lib2.so. 8280Sstevel@tonic-gate */ 8290Sstevel@tonic-gate if ((eptr = strrchr(parent, '/')) == 0) { 8300Sstevel@tonic-gate *nptr++ = '.'; 8310Sstevel@tonic-gate nrem--; 8320Sstevel@tonic-gate } else { 8330Sstevel@tonic-gate size_t len = eptr - parent; 8340Sstevel@tonic-gate 8350Sstevel@tonic-gate if (len >= nrem) 8360Sstevel@tonic-gate return ((char *)name); 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate (void) strncpy(nptr, parent, len); 8390Sstevel@tonic-gate nptr = nptr + len; 8400Sstevel@tonic-gate nrem -= len; 8410Sstevel@tonic-gate } 8420Sstevel@tonic-gate optr += MSG_STR_ORIGIN_SIZE; 8430Sstevel@tonic-gate expanded = _expanded = 1; 8440Sstevel@tonic-gate 8450Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_PLATFORM), 8460Sstevel@tonic-gate MSG_STR_PLATFORM_SIZE) == 0) { 8470Sstevel@tonic-gate /* 8480Sstevel@tonic-gate * Establish the platform from sysconf - like uname -i. 8490Sstevel@tonic-gate */ 8500Sstevel@tonic-gate if ((platform == 0) && (platform_sz == 0)) { 8510Sstevel@tonic-gate char info[SYS_NMLN]; 8520Sstevel@tonic-gate long size; 8530Sstevel@tonic-gate 8540Sstevel@tonic-gate size = sysinfo(SI_PLATFORM, info, SYS_NMLN); 8550Sstevel@tonic-gate if ((size != -1) && 8560Sstevel@tonic-gate (platform = libld_malloc((size_t)size))) { 8570Sstevel@tonic-gate (void) strcpy(platform, info); 8580Sstevel@tonic-gate platform_sz = (size_t)size - 1; 8590Sstevel@tonic-gate } else 8600Sstevel@tonic-gate platform_sz = 1; 8610Sstevel@tonic-gate } 8620Sstevel@tonic-gate if (platform != 0) { 8630Sstevel@tonic-gate if (platform_sz >= nrem) 8640Sstevel@tonic-gate return ((char *)name); 8650Sstevel@tonic-gate 8660Sstevel@tonic-gate (void) strncpy(nptr, platform, platform_sz); 8670Sstevel@tonic-gate nptr = nptr + platform_sz; 8680Sstevel@tonic-gate nrem -= platform_sz; 8690Sstevel@tonic-gate 8700Sstevel@tonic-gate optr += MSG_STR_PLATFORM_SIZE; 8710Sstevel@tonic-gate expanded = _expanded = 1; 8720Sstevel@tonic-gate } 8730Sstevel@tonic-gate 8740Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_OSNAME), 8750Sstevel@tonic-gate MSG_STR_OSNAME_SIZE) == 0) { 8760Sstevel@tonic-gate /* 8770Sstevel@tonic-gate * Establish the os name - like uname -s. 8780Sstevel@tonic-gate */ 8790Sstevel@tonic-gate if (uts == 0) 8800Sstevel@tonic-gate uts = conv_uts(); 8810Sstevel@tonic-gate 8820Sstevel@tonic-gate if (uts && uts->uts_osnamesz) { 8830Sstevel@tonic-gate if (uts->uts_osnamesz >= nrem) 8840Sstevel@tonic-gate return ((char *)name); 8850Sstevel@tonic-gate 8860Sstevel@tonic-gate (void) strncpy(nptr, uts->uts_osname, 8870Sstevel@tonic-gate uts->uts_osnamesz); 8880Sstevel@tonic-gate nptr = nptr + uts->uts_osnamesz; 8890Sstevel@tonic-gate nrem -= uts->uts_osnamesz; 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate optr += MSG_STR_OSNAME_SIZE; 8920Sstevel@tonic-gate expanded = _expanded = 1; 8930Sstevel@tonic-gate } 8940Sstevel@tonic-gate 8950Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_OSREL), 8960Sstevel@tonic-gate MSG_STR_OSREL_SIZE) == 0) { 8970Sstevel@tonic-gate /* 8980Sstevel@tonic-gate * Establish the os release - like uname -r. 8990Sstevel@tonic-gate */ 9000Sstevel@tonic-gate if (uts == 0) 9010Sstevel@tonic-gate uts = conv_uts(); 9020Sstevel@tonic-gate 9030Sstevel@tonic-gate if (uts && uts->uts_osrelsz) { 9040Sstevel@tonic-gate if (uts->uts_osrelsz >= nrem) 9050Sstevel@tonic-gate return ((char *)name); 9060Sstevel@tonic-gate 9070Sstevel@tonic-gate (void) strncpy(nptr, uts->uts_osrel, 9080Sstevel@tonic-gate uts->uts_osrelsz); 9090Sstevel@tonic-gate nptr = nptr + uts->uts_osrelsz; 9100Sstevel@tonic-gate nrem -= uts->uts_osrelsz; 9110Sstevel@tonic-gate 9120Sstevel@tonic-gate optr += MSG_STR_OSREL_SIZE; 9130Sstevel@tonic-gate expanded = _expanded = 1; 9140Sstevel@tonic-gate } 9150Sstevel@tonic-gate 9160Sstevel@tonic-gate } else if ((strncmp(optr, MSG_ORIG(MSG_STR_ISALIST), 9170Sstevel@tonic-gate MSG_STR_ISALIST_SIZE) == 0) && next && (isaflag++ == 0)) { 9180Sstevel@tonic-gate /* 9190Sstevel@tonic-gate * Establish instruction sets from sysconf. Note that 9200Sstevel@tonic-gate * this is only meaningful from runpaths. 9210Sstevel@tonic-gate */ 9220Sstevel@tonic-gate if (isa == 0) 9230Sstevel@tonic-gate isa = conv_isalist(); 9240Sstevel@tonic-gate 9250Sstevel@tonic-gate if (isa && isa->isa_listsz && 9260Sstevel@tonic-gate (nrem > isa->isa_opt->isa_namesz)) { 9270Sstevel@tonic-gate size_t mlen, tlen, hlen = optr - name; 9280Sstevel@tonic-gate size_t no; 9290Sstevel@tonic-gate char *lptr; 9300Sstevel@tonic-gate Isa_opt *opt = isa->isa_opt; 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate (void) strncpy(nptr, opt->isa_name, 9330Sstevel@tonic-gate opt->isa_namesz); 9340Sstevel@tonic-gate nptr = nptr + opt->isa_namesz; 9350Sstevel@tonic-gate nrem -= opt->isa_namesz; 9360Sstevel@tonic-gate 9370Sstevel@tonic-gate optr += MSG_STR_ISALIST_SIZE; 9380Sstevel@tonic-gate expanded = _expanded = 1; 9390Sstevel@tonic-gate 9400Sstevel@tonic-gate tlen = strlen(optr); 9410Sstevel@tonic-gate 9420Sstevel@tonic-gate /* 9430Sstevel@tonic-gate * As ISALIST expands to a number of elements, 9440Sstevel@tonic-gate * establish a new list to return to the caller. 9450Sstevel@tonic-gate * This will contain the present path being 9460Sstevel@tonic-gate * processed redefined for each isalist option, 9470Sstevel@tonic-gate * plus the original remaining list entries. 9480Sstevel@tonic-gate */ 9490Sstevel@tonic-gate mlen = ((hlen + tlen) * (isa->isa_optno - 1)) + 9500Sstevel@tonic-gate isa->isa_listsz - opt->isa_namesz; 9510Sstevel@tonic-gate if (*next) 9524716Sab196087 mlen += strlen(*next); 9530Sstevel@tonic-gate if ((_next = lptr = libld_malloc(mlen)) == 0) 9540Sstevel@tonic-gate return (0); 9550Sstevel@tonic-gate 9560Sstevel@tonic-gate for (no = 1, opt++; no < isa->isa_optno; 9570Sstevel@tonic-gate no++, opt++) { 9580Sstevel@tonic-gate (void) strncpy(lptr, name, hlen); 9590Sstevel@tonic-gate lptr = lptr + hlen; 9600Sstevel@tonic-gate (void) strncpy(lptr, opt->isa_name, 9610Sstevel@tonic-gate opt->isa_namesz); 9620Sstevel@tonic-gate lptr = lptr + opt->isa_namesz; 9630Sstevel@tonic-gate (void) strncpy(lptr, optr, tlen); 9640Sstevel@tonic-gate lptr = lptr + tlen; 9650Sstevel@tonic-gate *lptr++ = ':'; 9660Sstevel@tonic-gate } 9670Sstevel@tonic-gate if (*next) 9680Sstevel@tonic-gate (void) strcpy(lptr, *next); 9690Sstevel@tonic-gate else 9700Sstevel@tonic-gate *--lptr = '\0'; 9710Sstevel@tonic-gate } 9720Sstevel@tonic-gate } 9730Sstevel@tonic-gate 9740Sstevel@tonic-gate /* 9750Sstevel@tonic-gate * If no expansion occurred skip the $ and continue. 9760Sstevel@tonic-gate */ 9770Sstevel@tonic-gate if (_expanded == 0) 9780Sstevel@tonic-gate *nptr++ = *optr++, nrem--; 9790Sstevel@tonic-gate } 9800Sstevel@tonic-gate 9810Sstevel@tonic-gate /* 9820Sstevel@tonic-gate * If any ISALIST processing has occurred not only do we return the 9830Sstevel@tonic-gate * expanded node we're presently working on, but we must also update the 9840Sstevel@tonic-gate * remaining list so that it is effectively prepended with this node 9850Sstevel@tonic-gate * expanded to all remaining isalist options. Note that we can only 9860Sstevel@tonic-gate * handle one ISALIST per node. For more than one ISALIST to be 9870Sstevel@tonic-gate * processed we'd need a better algorithm than above to replace the 9880Sstevel@tonic-gate * newly generated list. Whether we want to encourage the number of 9890Sstevel@tonic-gate * pathname permutations this would provide is another question. So, for 9900Sstevel@tonic-gate * now if more than one ISALIST is encountered we return the original 9910Sstevel@tonic-gate * node untouched. 9920Sstevel@tonic-gate */ 9930Sstevel@tonic-gate if (isaflag) { 9940Sstevel@tonic-gate if (isaflag == 1) 9950Sstevel@tonic-gate *next = _next; 9960Sstevel@tonic-gate else 9970Sstevel@tonic-gate return ((char *)name); 9980Sstevel@tonic-gate } 9990Sstevel@tonic-gate 10000Sstevel@tonic-gate *nptr = '\0'; 10010Sstevel@tonic-gate 10020Sstevel@tonic-gate if (expanded) { 10030Sstevel@tonic-gate if ((nptr = libld_malloc(strlen(_name) + 1)) == 0) 10040Sstevel@tonic-gate return ((char *)name); 10050Sstevel@tonic-gate (void) strcpy(nptr, _name); 10060Sstevel@tonic-gate return (nptr); 10070Sstevel@tonic-gate } 10080Sstevel@tonic-gate return ((char *)name); 10090Sstevel@tonic-gate } 10100Sstevel@tonic-gate 10110Sstevel@tonic-gate /* 10124716Sab196087 * The Solaris ld does not put DT_VERSYM in the dynamic section, but the 10134716Sab196087 * GNU ld does, and it is used by the runtime linker to implement their 10144716Sab196087 * versioning scheme. Use this fact to determine if the sharable object 10154716Sab196087 * was produced by the GNU ld rather than the Solaris one, and to set 10164716Sab196087 * FLG_IF_GNUVER if so. This needs to be done before the symbols are 10174716Sab196087 * processed, since the answer determines whether we interpret the 10184716Sab196087 * symbols versions according to Solaris or GNU rules. 10194716Sab196087 */ 10204716Sab196087 /*ARGSUSED*/ 10214716Sab196087 static uintptr_t 10224716Sab196087 process_dynamic_isgnu(const char *name, Ifl_desc *ifl, Shdr *shdr, 10234716Sab196087 Elf_Scn *scn, Word ndx, int ident, Ofl_desc *ofl) 10244716Sab196087 { 10254716Sab196087 Dyn *dyn; 10264716Sab196087 Elf_Data *dp; 1027*7463SRod.Evans@Sun.COM uintptr_t error; 10284716Sab196087 1029*7463SRod.Evans@Sun.COM error = process_section(name, ifl, shdr, scn, ndx, ident, ofl); 1030*7463SRod.Evans@Sun.COM if ((error == 0) || (error == S_ERROR)) 1031*7463SRod.Evans@Sun.COM return (error); 10324716Sab196087 10334716Sab196087 /* Get the .dynamic data */ 10344716Sab196087 dp = elf_getdata(scn, NULL); 10354716Sab196087 10364716Sab196087 for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) { 10374716Sab196087 if (dyn->d_tag == DT_VERSYM) { 10384716Sab196087 ifl->ifl_flags |= FLG_IF_GNUVER; 10394716Sab196087 break; 10404716Sab196087 } 10414716Sab196087 } 10424716Sab196087 return (1); 10434716Sab196087 } 10444716Sab196087 10454716Sab196087 /* 10460Sstevel@tonic-gate * Process a dynamic section. If we are processing an explicit shared object 10470Sstevel@tonic-gate * then we need to determine if it has a recorded SONAME, if so, this name will 10480Sstevel@tonic-gate * be recorded in the output file being generated as the NEEDED entry rather 10490Sstevel@tonic-gate * than the shared objects filename itself. 10500Sstevel@tonic-gate * If the mode of the link-edit indicates that no undefined symbols should 10510Sstevel@tonic-gate * remain, then we also need to build up a list of any additional shared object 10520Sstevel@tonic-gate * dependencies this object may have. In this case save any NEEDED entries 10530Sstevel@tonic-gate * together with any associated run-path specifications. This information is 10540Sstevel@tonic-gate * recorded on the `ofl_soneed' list and will be analyzed after all explicit 10550Sstevel@tonic-gate * file processing has been completed (refer finish_libs()). 10560Sstevel@tonic-gate */ 10571618Srie static uintptr_t 10580Sstevel@tonic-gate process_dynamic(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl) 10590Sstevel@tonic-gate { 10600Sstevel@tonic-gate Dyn *data, *dyn; 10610Sstevel@tonic-gate char *str, *rpath = NULL; 10620Sstevel@tonic-gate const char *soname, *needed; 10630Sstevel@tonic-gate Sdf_desc *sdf; 10640Sstevel@tonic-gate Listnode *lnp; 10650Sstevel@tonic-gate 10660Sstevel@tonic-gate data = (Dyn *)isc->is_indata->d_buf; 10670Sstevel@tonic-gate str = (char *)ifl->ifl_isdesc[isc->is_shdr->sh_link]->is_indata->d_buf; 10680Sstevel@tonic-gate 10690Sstevel@tonic-gate /* 10700Sstevel@tonic-gate * First loop through the dynamic section looking for a run path. 10710Sstevel@tonic-gate */ 10720Sstevel@tonic-gate if (ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)) { 10730Sstevel@tonic-gate for (dyn = data; dyn->d_tag != DT_NULL; dyn++) { 10740Sstevel@tonic-gate if ((dyn->d_tag != DT_RPATH) && 10750Sstevel@tonic-gate (dyn->d_tag != DT_RUNPATH)) 10760Sstevel@tonic-gate continue; 10770Sstevel@tonic-gate if ((rpath = str + (size_t)dyn->d_un.d_val) == NULL) 10780Sstevel@tonic-gate continue; 10790Sstevel@tonic-gate break; 10800Sstevel@tonic-gate } 10810Sstevel@tonic-gate } 10820Sstevel@tonic-gate 10830Sstevel@tonic-gate /* 10840Sstevel@tonic-gate * Now look for any needed dependencies (which may use the rpath) 10850Sstevel@tonic-gate * or a new SONAME. 10860Sstevel@tonic-gate */ 10870Sstevel@tonic-gate for (dyn = data; dyn->d_tag != DT_NULL; dyn++) { 10880Sstevel@tonic-gate if (dyn->d_tag == DT_SONAME) { 10890Sstevel@tonic-gate if ((soname = str + (size_t)dyn->d_un.d_val) == NULL) 10900Sstevel@tonic-gate continue; 10910Sstevel@tonic-gate 10920Sstevel@tonic-gate /* 10930Sstevel@tonic-gate * Update the input file structure with this new name. 10940Sstevel@tonic-gate */ 10950Sstevel@tonic-gate ifl->ifl_soname = soname; 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate } else if ((dyn->d_tag == DT_NEEDED) || 10980Sstevel@tonic-gate (dyn->d_tag == DT_USED)) { 10990Sstevel@tonic-gate if (!(ofl->ofl_flags & 11000Sstevel@tonic-gate (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC))) 11010Sstevel@tonic-gate continue; 11020Sstevel@tonic-gate if ((needed = str + (size_t)dyn->d_un.d_val) == NULL) 11030Sstevel@tonic-gate continue; 11040Sstevel@tonic-gate 11050Sstevel@tonic-gate /* 11060Sstevel@tonic-gate * Determine if this needed entry is already recorded on 11070Sstevel@tonic-gate * the shared object needed list, if not create a new 11080Sstevel@tonic-gate * definition for later processing (see finish_libs()). 11090Sstevel@tonic-gate */ 11100Sstevel@tonic-gate needed = expand(ifl->ifl_name, needed, (char **)0); 11110Sstevel@tonic-gate 11120Sstevel@tonic-gate if ((sdf = sdf_find(needed, &ofl->ofl_soneed)) == 0) { 11130Sstevel@tonic-gate if ((sdf = sdf_add(needed, 11140Sstevel@tonic-gate &ofl->ofl_soneed)) == (Sdf_desc *)S_ERROR) 11150Sstevel@tonic-gate return (S_ERROR); 11160Sstevel@tonic-gate sdf->sdf_rfile = ifl->ifl_name; 11170Sstevel@tonic-gate } 11180Sstevel@tonic-gate 11190Sstevel@tonic-gate /* 11200Sstevel@tonic-gate * Record the runpath (Note that we take the first 11210Sstevel@tonic-gate * runpath which is exactly what ld.so.1 would do during 11220Sstevel@tonic-gate * its dependency processing). 11230Sstevel@tonic-gate */ 11240Sstevel@tonic-gate if (rpath && (sdf->sdf_rpath == 0)) 11250Sstevel@tonic-gate sdf->sdf_rpath = rpath; 11260Sstevel@tonic-gate 11270Sstevel@tonic-gate } else if (dyn->d_tag == DT_FLAGS_1) { 11280Sstevel@tonic-gate if (dyn->d_un.d_val & (DF_1_INITFIRST | DF_1_INTERPOSE)) 11290Sstevel@tonic-gate ifl->ifl_flags &= ~FLG_IF_LAZYLD; 11300Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_DISPRELPND) 11310Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DISPPEND; 11320Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_DISPRELDNE) 11330Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DISPDONE; 11340Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_NODIRECT) 11350Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_NODIRECT; 11360Sstevel@tonic-gate 11370Sstevel@tonic-gate } else if ((dyn->d_tag == DT_AUDIT) && 11380Sstevel@tonic-gate (ifl->ifl_flags & FLG_IF_NEEDED)) { 11390Sstevel@tonic-gate /* 11400Sstevel@tonic-gate * Record audit string as DT_DEPAUDIT. 11410Sstevel@tonic-gate */ 11420Sstevel@tonic-gate if ((ofl->ofl_depaudit = add_string(ofl->ofl_depaudit, 11430Sstevel@tonic-gate (str + (size_t)dyn->d_un.d_val))) == 11440Sstevel@tonic-gate (const char *)S_ERROR) 11450Sstevel@tonic-gate return (S_ERROR); 11460Sstevel@tonic-gate 11470Sstevel@tonic-gate } else if (dyn->d_tag == DT_SUNW_RTLDINF) { 11480Sstevel@tonic-gate /* 11490Sstevel@tonic-gate * If a library has the SUNW_RTLDINF .dynamic entry 11500Sstevel@tonic-gate * then we must not permit lazyloading of this library. 11510Sstevel@tonic-gate * This is because critical startup information (TLS 11520Sstevel@tonic-gate * routines) are provided as part of these interfaces 11530Sstevel@tonic-gate * and we must have them as part of process startup. 11540Sstevel@tonic-gate */ 11550Sstevel@tonic-gate ifl->ifl_flags &= ~FLG_IF_LAZYLD; 11560Sstevel@tonic-gate } 11570Sstevel@tonic-gate } 11580Sstevel@tonic-gate 11590Sstevel@tonic-gate /* 11600Sstevel@tonic-gate * Perform some SONAME sanity checks. 11610Sstevel@tonic-gate */ 11620Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_NEEDED) { 1163*7463SRod.Evans@Sun.COM Ifl_desc *sifl; 11640Sstevel@tonic-gate 11650Sstevel@tonic-gate /* 11660Sstevel@tonic-gate * Determine if anyone else will cause the same SONAME to be 11670Sstevel@tonic-gate * used (this is either caused by two different files having the 11680Sstevel@tonic-gate * same SONAME, or by one file SONAME actually matching another 11690Sstevel@tonic-gate * file basename (if no SONAME is specified within a shared 11700Sstevel@tonic-gate * library its basename will be used)). Probably rare, but some 11710Sstevel@tonic-gate * idiot will do it. 11720Sstevel@tonic-gate */ 11730Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_sos, lnp, sifl)) { 11740Sstevel@tonic-gate if ((strcmp(ifl->ifl_soname, sifl->ifl_soname) == 0) && 11750Sstevel@tonic-gate (ifl != sifl)) { 11760Sstevel@tonic-gate const char *hint, *iflb, *siflb; 11770Sstevel@tonic-gate 11780Sstevel@tonic-gate /* 11790Sstevel@tonic-gate * Determine the basename of each file. Perhaps 11800Sstevel@tonic-gate * there are multiple copies of the same file 11810Sstevel@tonic-gate * being brought in using different -L search 11820Sstevel@tonic-gate * paths, and if so give an extra hint in the 11830Sstevel@tonic-gate * error message. 11840Sstevel@tonic-gate */ 11850Sstevel@tonic-gate iflb = strrchr(ifl->ifl_name, '/'); 11860Sstevel@tonic-gate if (iflb == NULL) 11870Sstevel@tonic-gate iflb = ifl->ifl_name; 11880Sstevel@tonic-gate else 11890Sstevel@tonic-gate iflb++; 11900Sstevel@tonic-gate 11910Sstevel@tonic-gate siflb = strrchr(sifl->ifl_name, '/'); 11920Sstevel@tonic-gate if (siflb == NULL) 11930Sstevel@tonic-gate siflb = sifl->ifl_name; 11940Sstevel@tonic-gate else 11950Sstevel@tonic-gate siflb++; 11960Sstevel@tonic-gate 11970Sstevel@tonic-gate if (strcmp(iflb, siflb) == 0) 11980Sstevel@tonic-gate hint = MSG_INTL(MSG_REC_CNFLTHINT); 11990Sstevel@tonic-gate else 12000Sstevel@tonic-gate hint = MSG_ORIG(MSG_STR_EMPTY); 12010Sstevel@tonic-gate 12021618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 12031618Srie MSG_INTL(MSG_REC_OBJCNFLT), sifl->ifl_name, 12041618Srie ifl->ifl_name, sifl->ifl_soname, hint); 12050Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 12060Sstevel@tonic-gate return (0); 12070Sstevel@tonic-gate } 12080Sstevel@tonic-gate } 12090Sstevel@tonic-gate 12100Sstevel@tonic-gate /* 12110Sstevel@tonic-gate * If the SONAME is the same as the name the user wishes to 12120Sstevel@tonic-gate * record when building a dynamic library (refer -h option), 12130Sstevel@tonic-gate * we also have a name clash. 12140Sstevel@tonic-gate */ 12150Sstevel@tonic-gate if (ofl->ofl_soname && 12160Sstevel@tonic-gate (strcmp(ofl->ofl_soname, ifl->ifl_soname) == 0)) { 12171618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 12181618Srie MSG_INTL(MSG_REC_OPTCNFLT), ifl->ifl_name, 12191618Srie ifl->ifl_soname); 12200Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 12210Sstevel@tonic-gate return (0); 12220Sstevel@tonic-gate } 12230Sstevel@tonic-gate } 12240Sstevel@tonic-gate return (1); 12250Sstevel@tonic-gate } 12260Sstevel@tonic-gate 12270Sstevel@tonic-gate /* 1228*7463SRod.Evans@Sun.COM * Process a group section. 1229*7463SRod.Evans@Sun.COM */ 1230*7463SRod.Evans@Sun.COM static uintptr_t 1231*7463SRod.Evans@Sun.COM process_group(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 1232*7463SRod.Evans@Sun.COM Word ndx, int ident, Ofl_desc *ofl) 1233*7463SRod.Evans@Sun.COM { 1234*7463SRod.Evans@Sun.COM uintptr_t error; 1235*7463SRod.Evans@Sun.COM 1236*7463SRod.Evans@Sun.COM error = process_section(name, ifl, shdr, scn, ndx, ident, ofl); 1237*7463SRod.Evans@Sun.COM if ((error == 0) || (error == S_ERROR)) 1238*7463SRod.Evans@Sun.COM return (error); 1239*7463SRod.Evans@Sun.COM 1240*7463SRod.Evans@Sun.COM /* 1241*7463SRod.Evans@Sun.COM * Indicate that this input file has groups to process. Groups are 1242*7463SRod.Evans@Sun.COM * processed after all input sections have been processed. 1243*7463SRod.Evans@Sun.COM */ 1244*7463SRod.Evans@Sun.COM ifl->ifl_flags |= FLG_IS_GROUPS; 1245*7463SRod.Evans@Sun.COM 1246*7463SRod.Evans@Sun.COM return (1); 1247*7463SRod.Evans@Sun.COM } 1248*7463SRod.Evans@Sun.COM 1249*7463SRod.Evans@Sun.COM /* 12500Sstevel@tonic-gate * Process a relocation entry. At this point all input sections from this 12510Sstevel@tonic-gate * input file have been assigned an input section descriptor which is saved 12520Sstevel@tonic-gate * in the `ifl_isdesc' array. 12530Sstevel@tonic-gate */ 12541618Srie static uintptr_t 12550Sstevel@tonic-gate rel_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl) 12560Sstevel@tonic-gate { 12570Sstevel@tonic-gate Word rndx; 12580Sstevel@tonic-gate Is_desc *risc; 12590Sstevel@tonic-gate Os_desc *osp; 12600Sstevel@tonic-gate Shdr *shdr = isc->is_shdr; 12614734Sab196087 Conv_inv_buf_t inv_buf; 12620Sstevel@tonic-gate 12630Sstevel@tonic-gate /* 12640Sstevel@tonic-gate * Make sure this is a valid relocation we can handle. 12650Sstevel@tonic-gate */ 12666206Sab196087 if (shdr->sh_type != ld_targ.t_m.m_rel_sht_type) { 12671618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_FIL_INVALSEC), 12681618Srie ifl->ifl_name, isc->is_name, 12694734Sab196087 conv_sec_type(ifl->ifl_ehdr->e_machine, 12704734Sab196087 shdr->sh_type, 0, &inv_buf)); 12710Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 12720Sstevel@tonic-gate return (0); 12730Sstevel@tonic-gate } 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate /* 12760Sstevel@tonic-gate * From the relocation section header information determine which 12770Sstevel@tonic-gate * section needs the actual relocation. Determine which output section 12780Sstevel@tonic-gate * this input section has been assigned to and add to its relocation 12790Sstevel@tonic-gate * list. Note that the relocation section may be null if it is not 12800Sstevel@tonic-gate * required (ie. .debug, .stabs, etc). 12810Sstevel@tonic-gate */ 12820Sstevel@tonic-gate rndx = shdr->sh_info; 12830Sstevel@tonic-gate if (rndx >= ifl->ifl_shnum) { 12840Sstevel@tonic-gate /* 12850Sstevel@tonic-gate * Broken input file. 12860Sstevel@tonic-gate */ 12871618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHINFO), 12884716Sab196087 ifl->ifl_name, isc->is_name, EC_XWORD(rndx)); 12890Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 12900Sstevel@tonic-gate return (0); 12910Sstevel@tonic-gate } 12920Sstevel@tonic-gate if (rndx == 0) { 12930Sstevel@tonic-gate if (list_appendc(&ofl->ofl_extrarels, isc) == 0) 12940Sstevel@tonic-gate return (S_ERROR); 12950Sstevel@tonic-gate } else if ((risc = ifl->ifl_isdesc[rndx]) != 0) { 12960Sstevel@tonic-gate /* 12970Sstevel@tonic-gate * Discard relocations if they are against a section 12980Sstevel@tonic-gate * which has been discarded. 12990Sstevel@tonic-gate */ 13000Sstevel@tonic-gate if (risc->is_flags & FLG_IS_DISCARD) 13010Sstevel@tonic-gate return (1); 13020Sstevel@tonic-gate if ((osp = risc->is_osdesc) == 0) { 13030Sstevel@tonic-gate if (risc->is_shdr->sh_type == SHT_SUNW_move) { 13040Sstevel@tonic-gate /* 13050Sstevel@tonic-gate * This section is processed later 13060Sstevel@tonic-gate * in sunwmove_preprocess() and 13070Sstevel@tonic-gate * reloc_init(). 13080Sstevel@tonic-gate */ 13090Sstevel@tonic-gate if (list_appendc(&ofl->ofl_mvrelisdescs, 13100Sstevel@tonic-gate isc) == 0) 13110Sstevel@tonic-gate return (S_ERROR); 13120Sstevel@tonic-gate return (1); 13130Sstevel@tonic-gate } 13141618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 13151618Srie MSG_INTL(MSG_FIL_INVRELOC1), ifl->ifl_name, 13161618Srie isc->is_name, risc->is_name); 13170Sstevel@tonic-gate return (0); 13180Sstevel@tonic-gate } 13190Sstevel@tonic-gate if (list_appendc(&osp->os_relisdescs, isc) == 0) 13200Sstevel@tonic-gate return (S_ERROR); 13210Sstevel@tonic-gate } 13220Sstevel@tonic-gate return (1); 13230Sstevel@tonic-gate } 13240Sstevel@tonic-gate 13250Sstevel@tonic-gate /* 13260Sstevel@tonic-gate * SHF_EXCLUDE flags is set for this section. 13270Sstevel@tonic-gate */ 13280Sstevel@tonic-gate static uintptr_t 13290Sstevel@tonic-gate process_exclude(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn, 13300Sstevel@tonic-gate Word ndx, Ofl_desc *ofl) 13310Sstevel@tonic-gate { 13320Sstevel@tonic-gate /* 13330Sstevel@tonic-gate * Sections SHT_SYMTAB and SHT_DYNDYM, even if SHF_EXCLUDE is on, might 13340Sstevel@tonic-gate * be needed for ld processing. These sections need to be in the 13350Sstevel@tonic-gate * internal table. Later it will be determined whether they can be 13360Sstevel@tonic-gate * eliminated or not. 13370Sstevel@tonic-gate */ 13380Sstevel@tonic-gate if (shdr->sh_type == SHT_SYMTAB || shdr->sh_type == SHT_DYNSYM) 13390Sstevel@tonic-gate return (0); 13400Sstevel@tonic-gate 13410Sstevel@tonic-gate /* 13420Sstevel@tonic-gate * Other checks 13430Sstevel@tonic-gate */ 13440Sstevel@tonic-gate if (shdr->sh_flags & SHF_ALLOC) { 13450Sstevel@tonic-gate /* 13460Sstevel@tonic-gate * A conflict, issue an warning message, and ignore the section. 13470Sstevel@tonic-gate */ 13481618Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_EXCLUDE), 13490Sstevel@tonic-gate ifl->ifl_name, name); 13500Sstevel@tonic-gate return (0); 13510Sstevel@tonic-gate } 13520Sstevel@tonic-gate 13530Sstevel@tonic-gate /* 13540Sstevel@tonic-gate * This sections is not going to the output file. 13550Sstevel@tonic-gate */ 13560Sstevel@tonic-gate return (process_section(name, ifl, shdr, scn, ndx, 0, ofl)); 13570Sstevel@tonic-gate } 13580Sstevel@tonic-gate 13590Sstevel@tonic-gate /* 13600Sstevel@tonic-gate * Section processing state table. `Initial' describes the required initial 13610Sstevel@tonic-gate * procedure to be called (if any), `Final' describes the final processing 13620Sstevel@tonic-gate * procedure (ie. things that can only be done when all required sections 13630Sstevel@tonic-gate * have been collected). 13640Sstevel@tonic-gate */ 13650Sstevel@tonic-gate static uintptr_t (*Initial[SHT_NUM][2])() = { 13660Sstevel@tonic-gate 13670Sstevel@tonic-gate /* ET_REL ET_DYN */ 13680Sstevel@tonic-gate 13690Sstevel@tonic-gate /* SHT_NULL */ invalid_section, invalid_section, 13700Sstevel@tonic-gate /* SHT_PROGBITS */ process_progbits, process_progbits, 13710Sstevel@tonic-gate /* SHT_SYMTAB */ process_input, process_input, 13720Sstevel@tonic-gate /* SHT_STRTAB */ process_strtab, process_strtab, 13730Sstevel@tonic-gate /* SHT_RELA */ process_reloc, process_reloc, 13740Sstevel@tonic-gate /* SHT_HASH */ invalid_section, NULL, 13754716Sab196087 /* SHT_DYNAMIC */ process_rel_dynamic, process_dynamic_isgnu, 13760Sstevel@tonic-gate /* SHT_NOTE */ process_section, NULL, 13770Sstevel@tonic-gate /* SHT_NOBITS */ process_nobits, process_nobits, 13780Sstevel@tonic-gate /* SHT_REL */ process_reloc, process_reloc, 13790Sstevel@tonic-gate /* SHT_SHLIB */ process_section, invalid_section, 13800Sstevel@tonic-gate /* SHT_DYNSYM */ invalid_section, process_input, 13810Sstevel@tonic-gate /* SHT_UNKNOWN12 */ process_progbits, process_progbits, 13820Sstevel@tonic-gate /* SHT_UNKNOWN13 */ process_progbits, process_progbits, 13830Sstevel@tonic-gate /* SHT_INIT_ARRAY */ process_array, NULL, 13840Sstevel@tonic-gate /* SHT_FINI_ARRAY */ process_array, NULL, 13850Sstevel@tonic-gate /* SHT_PREINIT_ARRAY */ process_array, NULL, 1386*7463SRod.Evans@Sun.COM /* SHT_GROUP */ process_group, invalid_section, 13870Sstevel@tonic-gate /* SHT_SYMTAB_SHNDX */ process_sym_shndx, NULL 13880Sstevel@tonic-gate }; 13890Sstevel@tonic-gate 13900Sstevel@tonic-gate static uintptr_t (*Final[SHT_NUM][2])() = { 13910Sstevel@tonic-gate 13920Sstevel@tonic-gate /* SHT_NULL */ NULL, NULL, 13930Sstevel@tonic-gate /* SHT_PROGBITS */ NULL, NULL, 13941618Srie /* SHT_SYMTAB */ ld_sym_process, ld_sym_process, 13950Sstevel@tonic-gate /* SHT_STRTAB */ NULL, NULL, 13960Sstevel@tonic-gate /* SHT_RELA */ rel_process, NULL, 13970Sstevel@tonic-gate /* SHT_HASH */ NULL, NULL, 13980Sstevel@tonic-gate /* SHT_DYNAMIC */ NULL, process_dynamic, 13990Sstevel@tonic-gate /* SHT_NOTE */ NULL, NULL, 14000Sstevel@tonic-gate /* SHT_NOBITS */ NULL, NULL, 14010Sstevel@tonic-gate /* SHT_REL */ rel_process, NULL, 14020Sstevel@tonic-gate /* SHT_SHLIB */ NULL, NULL, 14031618Srie /* SHT_DYNSYM */ NULL, ld_sym_process, 14040Sstevel@tonic-gate /* SHT_UNKNOWN12 */ NULL, NULL, 14050Sstevel@tonic-gate /* SHT_UNKNOWN13 */ NULL, NULL, 1406*7463SRod.Evans@Sun.COM /* SHT_INIT_ARRAY */ array_process, NULL, 1407*7463SRod.Evans@Sun.COM /* SHT_FINI_ARRAY */ array_process, NULL, 1408*7463SRod.Evans@Sun.COM /* SHT_PREINIT_ARRAY */ array_process, NULL, 14090Sstevel@tonic-gate /* SHT_GROUP */ NULL, NULL, 14100Sstevel@tonic-gate /* SHT_SYMTAB_SHNDX */ sym_shndx_process, NULL 14110Sstevel@tonic-gate }; 14120Sstevel@tonic-gate 14130Sstevel@tonic-gate #define MAXNDXSIZE 10 14140Sstevel@tonic-gate 14150Sstevel@tonic-gate /* 14160Sstevel@tonic-gate * Process an elf file. Each section is compared against the section state 14170Sstevel@tonic-gate * table to determine whether it should be processed (saved), ignored, or 14180Sstevel@tonic-gate * is invalid for the type of input file being processed. 14190Sstevel@tonic-gate */ 14201618Srie static uintptr_t 14210Sstevel@tonic-gate process_elf(Ifl_desc *ifl, Elf *elf, Ofl_desc *ofl) 14220Sstevel@tonic-gate { 14230Sstevel@tonic-gate Elf_Scn *scn; 14240Sstevel@tonic-gate Shdr *shdr; 1425*7463SRod.Evans@Sun.COM Word ndx, sndx, ordndx = 0, ordcnt = 0; 14260Sstevel@tonic-gate char *str, *name, _name[MAXNDXSIZE]; 14270Sstevel@tonic-gate Word row, column; 14280Sstevel@tonic-gate int ident; 14290Sstevel@tonic-gate uintptr_t error; 14303617Srie Is_desc *vdfisp, *vndisp, *vsyisp, *sifisp, *capisp; 14310Sstevel@tonic-gate Sdf_desc *sdf; 14320Sstevel@tonic-gate 14330Sstevel@tonic-gate /* 14340Sstevel@tonic-gate * First process the .shstrtab section so that later sections can 14350Sstevel@tonic-gate * reference their name. 14360Sstevel@tonic-gate */ 14371618Srie ld_sup_file(ofl, ifl->ifl_name, elf_kind(elf), ifl->ifl_flags, elf); 14380Sstevel@tonic-gate 14390Sstevel@tonic-gate sndx = ifl->ifl_shstrndx; 14400Sstevel@tonic-gate if ((scn = elf_getscn(elf, (size_t)sndx)) == NULL) { 14411618Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN), 14421618Srie ifl->ifl_name); 14430Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 14440Sstevel@tonic-gate return (0); 14450Sstevel@tonic-gate } 14460Sstevel@tonic-gate if ((shdr = elf_getshdr(scn)) == NULL) { 14471618Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR), 14481618Srie ifl->ifl_name); 14490Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 14500Sstevel@tonic-gate return (0); 14510Sstevel@tonic-gate } 14520Sstevel@tonic-gate if ((name = elf_strptr(elf, (size_t)sndx, (size_t)shdr->sh_name)) == 14530Sstevel@tonic-gate NULL) { 14541618Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR), 14551618Srie ifl->ifl_name); 14560Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 14570Sstevel@tonic-gate return (0); 14580Sstevel@tonic-gate } 14590Sstevel@tonic-gate 14602647Srie if (ld_sup_input_section(ofl, ifl, name, &shdr, sndx, scn, 14612647Srie elf) == S_ERROR) 14620Sstevel@tonic-gate return (S_ERROR); 14630Sstevel@tonic-gate 14640Sstevel@tonic-gate /* 14650Sstevel@tonic-gate * Reset the name since the shdr->sh_name could have been changed as 14661618Srie * part of ld_sup_input_section(). If there is no name, fabricate one 14670Sstevel@tonic-gate * using the section index. 14680Sstevel@tonic-gate */ 14690Sstevel@tonic-gate if (shdr->sh_name == 0) { 14700Sstevel@tonic-gate (void) snprintf(_name, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INDEX), 14710Sstevel@tonic-gate EC_XWORD(sndx)); 14720Sstevel@tonic-gate if ((name = libld_malloc(strlen(_name) + 1)) == 0) 14730Sstevel@tonic-gate return (S_ERROR); 14740Sstevel@tonic-gate (void) strcpy(name, _name); 14750Sstevel@tonic-gate 14760Sstevel@tonic-gate } else if ((name = elf_strptr(elf, (size_t)sndx, 14770Sstevel@tonic-gate (size_t)shdr->sh_name)) == NULL) { 14781618Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR), 14791618Srie ifl->ifl_name); 14800Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 14810Sstevel@tonic-gate return (0); 14820Sstevel@tonic-gate } 14830Sstevel@tonic-gate 14840Sstevel@tonic-gate error = process_strtab(name, ifl, shdr, scn, sndx, FALSE, ofl); 14850Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR)) 14860Sstevel@tonic-gate return (error); 14870Sstevel@tonic-gate str = ifl->ifl_isdesc[sndx]->is_indata->d_buf; 14880Sstevel@tonic-gate 14890Sstevel@tonic-gate /* 14900Sstevel@tonic-gate * Determine the state table column from the input file type. Note, 14910Sstevel@tonic-gate * shared library sections are not added to the output section list. 14920Sstevel@tonic-gate */ 14930Sstevel@tonic-gate if (ifl->ifl_ehdr->e_type == ET_DYN) { 14940Sstevel@tonic-gate column = 1; 14950Sstevel@tonic-gate ofl->ofl_soscnt++; 14966206Sab196087 ident = ld_targ.t_id.id_null; 14970Sstevel@tonic-gate } else { 14980Sstevel@tonic-gate column = 0; 14990Sstevel@tonic-gate ofl->ofl_objscnt++; 15006206Sab196087 ident = ld_targ.t_id.id_unknown; 15010Sstevel@tonic-gate } 15020Sstevel@tonic-gate 15031618Srie DBG_CALL(Dbg_file_generic(ofl->ofl_lml, ifl)); 15040Sstevel@tonic-gate ndx = 0; 15050Sstevel@tonic-gate vdfisp = vndisp = vsyisp = sifisp = capisp = 0; 15060Sstevel@tonic-gate scn = NULL; 15070Sstevel@tonic-gate while (scn = elf_nextscn(elf, scn)) { 15080Sstevel@tonic-gate ndx++; 1509*7463SRod.Evans@Sun.COM 15100Sstevel@tonic-gate /* 15110Sstevel@tonic-gate * As we've already processed the .shstrtab don't do it again. 15120Sstevel@tonic-gate */ 15130Sstevel@tonic-gate if (ndx == sndx) 15140Sstevel@tonic-gate continue; 15150Sstevel@tonic-gate 15160Sstevel@tonic-gate if ((shdr = elf_getshdr(scn)) == NULL) { 15171618Srie eprintf(ofl->ofl_lml, ERR_ELF, 15181618Srie MSG_INTL(MSG_ELF_GETSHDR), ifl->ifl_name); 15190Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 15200Sstevel@tonic-gate return (0); 15210Sstevel@tonic-gate } 15220Sstevel@tonic-gate name = str + (size_t)(shdr->sh_name); 15230Sstevel@tonic-gate 15242647Srie if (ld_sup_input_section(ofl, ifl, name, &shdr, ndx, scn, 15252647Srie elf) == S_ERROR) 15260Sstevel@tonic-gate return (S_ERROR); 15270Sstevel@tonic-gate 15280Sstevel@tonic-gate /* 15290Sstevel@tonic-gate * Reset the name since the shdr->sh_name could have been 15301618Srie * changed as part of ld_sup_input_section(). If there is no 15311618Srie * name, fabricate one using the section index. 15320Sstevel@tonic-gate */ 15330Sstevel@tonic-gate if (shdr->sh_name == 0) { 15340Sstevel@tonic-gate (void) snprintf(_name, MAXNDXSIZE, 15350Sstevel@tonic-gate MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(ndx)); 15360Sstevel@tonic-gate if ((name = libld_malloc(strlen(_name) + 1)) == 0) 15370Sstevel@tonic-gate return (S_ERROR); 15380Sstevel@tonic-gate (void) strcpy(name, _name); 15390Sstevel@tonic-gate } else 15400Sstevel@tonic-gate name = str + (size_t)(shdr->sh_name); 15410Sstevel@tonic-gate 15420Sstevel@tonic-gate row = shdr->sh_type; 15430Sstevel@tonic-gate 15440Sstevel@tonic-gate /* 15450Sstevel@tonic-gate * If the section has the SHF_EXCLUDE flag on, and we're not 15460Sstevel@tonic-gate * generating a relocatable object, exclude the section. 15470Sstevel@tonic-gate */ 15480Sstevel@tonic-gate if (((shdr->sh_flags & SHF_EXCLUDE) != 0) && 15490Sstevel@tonic-gate ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0)) { 15500Sstevel@tonic-gate if ((error = process_exclude(name, ifl, shdr, scn, 15510Sstevel@tonic-gate ndx, ofl)) == S_ERROR) 15520Sstevel@tonic-gate return (S_ERROR); 15530Sstevel@tonic-gate if (error == 1) 15540Sstevel@tonic-gate continue; 15550Sstevel@tonic-gate } 15560Sstevel@tonic-gate 15570Sstevel@tonic-gate /* 15580Sstevel@tonic-gate * If this is a standard section type process it via the 15590Sstevel@tonic-gate * appropriate action routine. 15600Sstevel@tonic-gate */ 15610Sstevel@tonic-gate if (row < SHT_NUM) { 15620Sstevel@tonic-gate if (Initial[row][column] != NULL) { 15630Sstevel@tonic-gate if (Initial[row][column](name, ifl, shdr, scn, 15640Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR) 15650Sstevel@tonic-gate return (S_ERROR); 15660Sstevel@tonic-gate } 15670Sstevel@tonic-gate } else { 15680Sstevel@tonic-gate /* 15690Sstevel@tonic-gate * If this section is below SHT_LOSUNW then we don't 15700Sstevel@tonic-gate * really know what to do with it, issue a warning 15710Sstevel@tonic-gate * message but do the basic section processing anyway. 15720Sstevel@tonic-gate */ 15734734Sab196087 if (row < (Word)SHT_LOSUNW) { 15744734Sab196087 Conv_inv_buf_t inv_buf; 15754734Sab196087 15761618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 15771618Srie MSG_INTL(MSG_FIL_INVALSEC), ifl->ifl_name, 15781618Srie name, 15791618Srie conv_sec_type(ifl->ifl_ehdr->e_machine, 15804734Sab196087 shdr->sh_type, 0, &inv_buf)); 15814734Sab196087 } 15820Sstevel@tonic-gate 15830Sstevel@tonic-gate /* 15840Sstevel@tonic-gate * Handle sections greater than SHT_LOSUNW. 15850Sstevel@tonic-gate */ 15860Sstevel@tonic-gate switch (row) { 15870Sstevel@tonic-gate case SHT_SUNW_dof: 15880Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn, 15890Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR) 15900Sstevel@tonic-gate return (S_ERROR); 15910Sstevel@tonic-gate break; 15920Sstevel@tonic-gate case SHT_SUNW_cap: 15930Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn, 15946206Sab196087 ndx, ld_targ.t_id.id_null, ofl) == S_ERROR) 15950Sstevel@tonic-gate return (S_ERROR); 15960Sstevel@tonic-gate capisp = ifl->ifl_isdesc[ndx]; 15970Sstevel@tonic-gate break; 15980Sstevel@tonic-gate case SHT_SUNW_DEBUGSTR: 15990Sstevel@tonic-gate case SHT_SUNW_DEBUG: 16000Sstevel@tonic-gate if (process_debug(name, ifl, shdr, scn, 16010Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR) 16020Sstevel@tonic-gate return (S_ERROR); 16030Sstevel@tonic-gate break; 16040Sstevel@tonic-gate case SHT_SUNW_move: 16050Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn, 16066206Sab196087 ndx, ld_targ.t_id.id_null, ofl) == S_ERROR) 16070Sstevel@tonic-gate return (S_ERROR); 16080Sstevel@tonic-gate break; 16090Sstevel@tonic-gate case SHT_SUNW_syminfo: 16100Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn, 16116206Sab196087 ndx, ld_targ.t_id.id_null, ofl) == S_ERROR) 16120Sstevel@tonic-gate return (S_ERROR); 16130Sstevel@tonic-gate sifisp = ifl->ifl_isdesc[ndx]; 16140Sstevel@tonic-gate break; 16150Sstevel@tonic-gate case SHT_SUNW_ANNOTATE: 1616*7463SRod.Evans@Sun.COM if (process_progbits(name, ifl, shdr, scn, 1617*7463SRod.Evans@Sun.COM ndx, ident, ofl) == S_ERROR) 1618*7463SRod.Evans@Sun.COM return (S_ERROR); 1619*7463SRod.Evans@Sun.COM break; 16200Sstevel@tonic-gate case SHT_SUNW_COMDAT: 16210Sstevel@tonic-gate if (process_progbits(name, ifl, shdr, scn, 16220Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR) 16230Sstevel@tonic-gate return (S_ERROR); 1624*7463SRod.Evans@Sun.COM ifl->ifl_isdesc[ndx]->is_flags |= FLG_IS_COMDAT; 16250Sstevel@tonic-gate break; 16260Sstevel@tonic-gate case SHT_SUNW_verdef: 16270Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn, 16286206Sab196087 ndx, ld_targ.t_id.id_null, ofl) == S_ERROR) 16290Sstevel@tonic-gate return (S_ERROR); 16300Sstevel@tonic-gate vdfisp = ifl->ifl_isdesc[ndx]; 16310Sstevel@tonic-gate break; 16320Sstevel@tonic-gate case SHT_SUNW_verneed: 16330Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn, 16346206Sab196087 ndx, ld_targ.t_id.id_null, ofl) == S_ERROR) 16350Sstevel@tonic-gate return (S_ERROR); 16360Sstevel@tonic-gate vndisp = ifl->ifl_isdesc[ndx]; 16370Sstevel@tonic-gate break; 16380Sstevel@tonic-gate case SHT_SUNW_versym: 16390Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn, 16406206Sab196087 ndx, ld_targ.t_id.id_null, ofl) == S_ERROR) 16410Sstevel@tonic-gate return (S_ERROR); 16420Sstevel@tonic-gate vsyisp = ifl->ifl_isdesc[ndx]; 16430Sstevel@tonic-gate break; 16440Sstevel@tonic-gate case SHT_SPARC_GOTDATA: 16456206Sab196087 /* 16466206Sab196087 * SHT_SPARC_GOTDATA (0x70000000) is in the 16476206Sab196087 * SHT_LOPROC - SHT_HIPROC range reserved 16486206Sab196087 * for processor-specific semantics. It is 16496206Sab196087 * only meaningful for sparc targets. 16506206Sab196087 */ 16516206Sab196087 if (ld_targ.t_m.m_mach != 16526206Sab196087 LD_TARG_BYCLASS(EM_SPARC, EM_SPARCV9)) 16536206Sab196087 goto do_default; 16540Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn, 16556206Sab196087 ndx, ld_targ.t_id.id_gotdata, ofl) == 16566206Sab196087 S_ERROR) 16570Sstevel@tonic-gate return (S_ERROR); 16580Sstevel@tonic-gate break; 16596206Sab196087 #if defined(_ELF64) 16600Sstevel@tonic-gate case SHT_AMD64_UNWIND: 16616206Sab196087 /* 16626206Sab196087 * SHT_AMD64_UNWIND (0x70000001) is in the 16636206Sab196087 * SHT_LOPROC - SHT_HIPROC range reserved 16646206Sab196087 * for processor-specific semantics. It is 16656206Sab196087 * only meaningful for amd64 targets. 16666206Sab196087 */ 16676206Sab196087 if (ld_targ.t_m.m_mach != EM_AMD64) 16686206Sab196087 goto do_default; 1669*7463SRod.Evans@Sun.COM 16706206Sab196087 /* 16716206Sab196087 * Target is x86, so this really is 16726206Sab196087 * SHT_AMD64_UNWIND 16736206Sab196087 */ 16740Sstevel@tonic-gate if (column == 0) { 16750Sstevel@tonic-gate /* 16760Sstevel@tonic-gate * column == ET_REL 16770Sstevel@tonic-gate */ 1678*7463SRod.Evans@Sun.COM if (process_section(name, ifl, shdr, 1679*7463SRod.Evans@Sun.COM scn, ndx, ld_targ.t_id.id_unwind, 1680*7463SRod.Evans@Sun.COM ofl) == S_ERROR) 16810Sstevel@tonic-gate return (S_ERROR); 16820Sstevel@tonic-gate } 16830Sstevel@tonic-gate break; 16840Sstevel@tonic-gate #endif 16850Sstevel@tonic-gate default: 16866206Sab196087 do_default: 16876206Sab196087 if (ident != ld_targ.t_id.id_null) 16886206Sab196087 ident = ld_targ.t_id.id_user; 16890Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn, 16900Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR) 16910Sstevel@tonic-gate return (S_ERROR); 16920Sstevel@tonic-gate break; 16930Sstevel@tonic-gate } 16940Sstevel@tonic-gate } 1695*7463SRod.Evans@Sun.COM } 16960Sstevel@tonic-gate 1697*7463SRod.Evans@Sun.COM /* 1698*7463SRod.Evans@Sun.COM * Now that all input sections have been analyzed, and prior to placing 1699*7463SRod.Evans@Sun.COM * any input sections to their output sections, process any groups. 1700*7463SRod.Evans@Sun.COM * Groups can contribute COMDAT items, which may get discarded as part 1701*7463SRod.Evans@Sun.COM * of placement. In addition, COMDAT names may require transformation 1702*7463SRod.Evans@Sun.COM * to indicate different output section placement. 1703*7463SRod.Evans@Sun.COM */ 1704*7463SRod.Evans@Sun.COM if (ifl->ifl_flags & FLG_IS_GROUPS) { 1705*7463SRod.Evans@Sun.COM for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) { 1706*7463SRod.Evans@Sun.COM Is_desc *isp; 1707*7463SRod.Evans@Sun.COM 1708*7463SRod.Evans@Sun.COM if (((isp = ifl->ifl_isdesc[ndx]) == NULL) || 1709*7463SRod.Evans@Sun.COM (isp->is_shdr->sh_type != SHT_GROUP)) 1710*7463SRod.Evans@Sun.COM continue; 1711*7463SRod.Evans@Sun.COM 1712*7463SRod.Evans@Sun.COM if (ld_group_process(isp, ofl) == S_ERROR) 1713*7463SRod.Evans@Sun.COM return (S_ERROR); 17140Sstevel@tonic-gate } 17150Sstevel@tonic-gate } 17160Sstevel@tonic-gate 17170Sstevel@tonic-gate /* 1718*7463SRod.Evans@Sun.COM * Now that all of input sections have been processed, place them 1719*7463SRod.Evans@Sun.COM * in the appropriate output sections. 17200Sstevel@tonic-gate */ 1721*7463SRod.Evans@Sun.COM for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) { 1722*7463SRod.Evans@Sun.COM Is_desc *isp; 1723*7463SRod.Evans@Sun.COM Shdr *shdr; 1724*7463SRod.Evans@Sun.COM 1725*7463SRod.Evans@Sun.COM if (((isp = ifl->ifl_isdesc[ndx]) == NULL) || 1726*7463SRod.Evans@Sun.COM ((isp->is_flags & FLG_IS_PLACE) == 0)) 1727*7463SRod.Evans@Sun.COM continue; 1728*7463SRod.Evans@Sun.COM 1729*7463SRod.Evans@Sun.COM shdr = isp->is_shdr; 17300Sstevel@tonic-gate 1731*7463SRod.Evans@Sun.COM /* 1732*7463SRod.Evans@Sun.COM * Place all non-ordered sections within their appropriate 1733*7463SRod.Evans@Sun.COM * output section. 1734*7463SRod.Evans@Sun.COM * 1735*7463SRod.Evans@Sun.COM * Ordered sections are sorted based on the relative ordering 1736*7463SRod.Evans@Sun.COM * of the section pointed to by the sh_info entry. An ordered 1737*7463SRod.Evans@Sun.COM * section, whose sh_link points to itself, must also be placed 1738*7463SRod.Evans@Sun.COM * in the output image so as to control the ordered processing 1739*7463SRod.Evans@Sun.COM * that follows (see FLG_IF_ORDERED below). 1740*7463SRod.Evans@Sun.COM */ 1741*7463SRod.Evans@Sun.COM if (((isp->is_flags & FLG_IS_ORDERED) == 0) || 1742*7463SRod.Evans@Sun.COM ((ndx == shdr->sh_link) && 1743*7463SRod.Evans@Sun.COM (shdr->sh_flags & SHF_ORDERED))) { 1744*7463SRod.Evans@Sun.COM if (ld_place_section(ofl, isp, 1745*7463SRod.Evans@Sun.COM isp->is_keyident, 0) == (Os_desc *)S_ERROR) 1746*7463SRod.Evans@Sun.COM return (S_ERROR); 1747*7463SRod.Evans@Sun.COM } 1748*7463SRod.Evans@Sun.COM 1749*7463SRod.Evans@Sun.COM /* 1750*7463SRod.Evans@Sun.COM * If a section requires ordered processing, keep track of the 1751*7463SRod.Evans@Sun.COM * section index and count to optimize later section traversal. 1752*7463SRod.Evans@Sun.COM */ 1753*7463SRod.Evans@Sun.COM if (isp->is_flags & FLG_IS_ORDERED) { 1754*7463SRod.Evans@Sun.COM ordcnt++; 1755*7463SRod.Evans@Sun.COM if (ordndx == 0) 1756*7463SRod.Evans@Sun.COM ordndx = ndx; 1757*7463SRod.Evans@Sun.COM } 1758*7463SRod.Evans@Sun.COM } 1759*7463SRod.Evans@Sun.COM 1760*7463SRod.Evans@Sun.COM /* 1761*7463SRod.Evans@Sun.COM * Some sections have special ordering requirements, that are based off 1762*7463SRod.Evans@Sun.COM * of the section pointed to by their sh_info entry. This controlling 1763*7463SRod.Evans@Sun.COM * section will have been placed (above), and thus any ordered sections 1764*7463SRod.Evans@Sun.COM * can now be processed. 1765*7463SRod.Evans@Sun.COM */ 1766*7463SRod.Evans@Sun.COM if (ifl->ifl_flags & FLG_IF_ORDERED) { 1767*7463SRod.Evans@Sun.COM Word cnt = 0; 1768*7463SRod.Evans@Sun.COM 1769*7463SRod.Evans@Sun.COM for (ndx = ordndx; 1770*7463SRod.Evans@Sun.COM (ndx < ifl->ifl_shnum) && (cnt < ordcnt); ndx++) { 17710Sstevel@tonic-gate Is_desc *isp; 17720Sstevel@tonic-gate 1773*7463SRod.Evans@Sun.COM if (((isp = ifl->ifl_isdesc[ndx]) == NULL) || 1774*7463SRod.Evans@Sun.COM ((isp->is_flags & FLG_IS_ORDERED) == 0)) 17750Sstevel@tonic-gate continue; 17760Sstevel@tonic-gate 1777*7463SRod.Evans@Sun.COM if (ld_process_ordered(ifl, ofl, ndx, 1778*7463SRod.Evans@Sun.COM ifl->ifl_shnum) == S_ERROR) 17790Sstevel@tonic-gate return (S_ERROR); 17800Sstevel@tonic-gate } 17810Sstevel@tonic-gate } 17820Sstevel@tonic-gate 17830Sstevel@tonic-gate /* 17841109Srie * If this is an explicit shared object determine if the user has 17850Sstevel@tonic-gate * specified a control definition. This descriptor may specify which 17860Sstevel@tonic-gate * version definitions can be used from this object (it may also update 17870Sstevel@tonic-gate * the dependency to USED and supply an alternative SONAME). 17880Sstevel@tonic-gate */ 17890Sstevel@tonic-gate sdf = 0; 17900Sstevel@tonic-gate if (column && (ifl->ifl_flags & FLG_IF_NEEDED)) { 17910Sstevel@tonic-gate const char *base; 17920Sstevel@tonic-gate 17930Sstevel@tonic-gate /* 17940Sstevel@tonic-gate * Use the basename of the input file (typically this is the 17950Sstevel@tonic-gate * compilation environment name, ie. libfoo.so). 17960Sstevel@tonic-gate */ 17970Sstevel@tonic-gate if ((base = strrchr(ifl->ifl_name, '/')) == NULL) 17980Sstevel@tonic-gate base = ifl->ifl_name; 17990Sstevel@tonic-gate else 18000Sstevel@tonic-gate base++; 18010Sstevel@tonic-gate 18020Sstevel@tonic-gate if ((sdf = sdf_find(base, &ofl->ofl_socntl)) != 0) { 18030Sstevel@tonic-gate sdf->sdf_file = ifl; 18040Sstevel@tonic-gate ifl->ifl_sdfdesc = sdf; 18050Sstevel@tonic-gate } 18060Sstevel@tonic-gate } 18070Sstevel@tonic-gate 18080Sstevel@tonic-gate /* 18090Sstevel@tonic-gate * Process any hardware/software capabilities sections. Only propagate 18100Sstevel@tonic-gate * capabilities for input relocatable objects. If the object doesn't 18110Sstevel@tonic-gate * contain any capabilities, any capability state that has already been 18120Sstevel@tonic-gate * gathered will prevail. 18130Sstevel@tonic-gate */ 18140Sstevel@tonic-gate if (capisp && (ifl->ifl_ehdr->e_type == ET_REL)) 18153617Srie process_cap(ifl, capisp, ofl); 18160Sstevel@tonic-gate 18170Sstevel@tonic-gate /* 18180Sstevel@tonic-gate * Process any version dependencies. These will establish shared object 18190Sstevel@tonic-gate * `needed' entries in the same manner as will be generated from the 18200Sstevel@tonic-gate * .dynamic's NEEDED entries. 18210Sstevel@tonic-gate */ 18220Sstevel@tonic-gate if (vndisp && (ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC))) 18231618Srie if (ld_vers_need_process(vndisp, ifl, ofl) == S_ERROR) 18240Sstevel@tonic-gate return (S_ERROR); 18250Sstevel@tonic-gate 18260Sstevel@tonic-gate /* 18270Sstevel@tonic-gate * Before processing any symbol resolution or relocations process any 18280Sstevel@tonic-gate * version sections. 18290Sstevel@tonic-gate */ 18300Sstevel@tonic-gate if (vsyisp) 18311618Srie (void) ld_vers_sym_process(ofl->ofl_lml, vsyisp, ifl); 18320Sstevel@tonic-gate 18330Sstevel@tonic-gate if (ifl->ifl_versym && 18340Sstevel@tonic-gate (vdfisp || (sdf && (sdf->sdf_flags & FLG_SDF_SELECT)))) 18351618Srie if (ld_vers_def_process(vdfisp, ifl, ofl) == S_ERROR) 18360Sstevel@tonic-gate return (S_ERROR); 18370Sstevel@tonic-gate 18380Sstevel@tonic-gate /* 18390Sstevel@tonic-gate * Having collected the appropriate sections carry out any additional 18400Sstevel@tonic-gate * processing if necessary. 18410Sstevel@tonic-gate */ 18420Sstevel@tonic-gate for (ndx = 0; ndx < ifl->ifl_shnum; ndx++) { 1843*7463SRod.Evans@Sun.COM Is_desc *isp; 18440Sstevel@tonic-gate 18450Sstevel@tonic-gate if ((isp = ifl->ifl_isdesc[ndx]) == 0) 18460Sstevel@tonic-gate continue; 18470Sstevel@tonic-gate row = isp->is_shdr->sh_type; 18480Sstevel@tonic-gate 18490Sstevel@tonic-gate if ((isp->is_flags & FLG_IS_DISCARD) == 0) 18501618Srie ld_sup_section(ofl, isp->is_name, isp->is_shdr, ndx, 18511618Srie isp->is_indata, elf); 18520Sstevel@tonic-gate 18530Sstevel@tonic-gate /* 18540Sstevel@tonic-gate * If this is a ST_SUNW_move section from a 18550Sstevel@tonic-gate * a relocatable file, keep the input section. 18560Sstevel@tonic-gate */ 18570Sstevel@tonic-gate if ((row == SHT_SUNW_move) && (column == 0)) { 18580Sstevel@tonic-gate if (list_appendc(&(ofl->ofl_ismove), isp) == 0) 18590Sstevel@tonic-gate return (S_ERROR); 18600Sstevel@tonic-gate } 18610Sstevel@tonic-gate 18620Sstevel@tonic-gate /* 18630Sstevel@tonic-gate * If this is a standard section type process it via the 18640Sstevel@tonic-gate * appropriate action routine. 18650Sstevel@tonic-gate */ 18660Sstevel@tonic-gate if (row < SHT_NUM) { 1867*7463SRod.Evans@Sun.COM if (Final[row][column] != NULL) { 1868*7463SRod.Evans@Sun.COM if (Final[row][column](isp, ifl, 1869*7463SRod.Evans@Sun.COM ofl) == S_ERROR) 18700Sstevel@tonic-gate return (S_ERROR); 1871*7463SRod.Evans@Sun.COM } 1872*7463SRod.Evans@Sun.COM #if defined(_ELF64) 1873*7463SRod.Evans@Sun.COM } else if ((row == SHT_AMD64_UNWIND) && (column == 0)) { 1874*7463SRod.Evans@Sun.COM Os_desc *osp = isp->is_osdesc; 1875*7463SRod.Evans@Sun.COM 1876*7463SRod.Evans@Sun.COM /* 1877*7463SRod.Evans@Sun.COM * SHT_AMD64_UNWIND (0x70000001) is in the SHT_LOPROC - 1878*7463SRod.Evans@Sun.COM * SHT_HIPROC range reserved for processor-specific 1879*7463SRod.Evans@Sun.COM * semantics, and is only meaningful for amd64 targets. 1880*7463SRod.Evans@Sun.COM * 1881*7463SRod.Evans@Sun.COM * Only process unwind contents from relocatable 1882*7463SRod.Evans@Sun.COM * objects. 1883*7463SRod.Evans@Sun.COM */ 1884*7463SRod.Evans@Sun.COM if (osp && (ld_targ.t_m.m_mach == EM_AMD64) && 1885*7463SRod.Evans@Sun.COM (ld_targ.t_uw.uw_append_unwind != NULL) && 1886*7463SRod.Evans@Sun.COM ((*ld_targ.t_uw.uw_append_unwind)(osp, ofl) == 1887*7463SRod.Evans@Sun.COM S_ERROR)) 1888*7463SRod.Evans@Sun.COM return (S_ERROR); 1889*7463SRod.Evans@Sun.COM #endif 18900Sstevel@tonic-gate } 18910Sstevel@tonic-gate } 18920Sstevel@tonic-gate 18930Sstevel@tonic-gate /* 18940Sstevel@tonic-gate * After processing any symbol resolution, and if this dependency 18950Sstevel@tonic-gate * indicates it contains symbols that can't be directly bound to, 18960Sstevel@tonic-gate * set the symbols appropriately. 18970Sstevel@tonic-gate */ 18980Sstevel@tonic-gate if (sifisp && ((ifl->ifl_flags & (FLG_IF_NEEDED | FLG_IF_NODIRECT)) == 18990Sstevel@tonic-gate (FLG_IF_NEEDED | FLG_IF_NODIRECT))) 19001618Srie (void) ld_sym_nodirect(sifisp, ifl, ofl); 19010Sstevel@tonic-gate 19020Sstevel@tonic-gate return (1); 19030Sstevel@tonic-gate } 19040Sstevel@tonic-gate 19050Sstevel@tonic-gate /* 19060Sstevel@tonic-gate * Process the current input file. There are basically three types of files 19070Sstevel@tonic-gate * that come through here: 19080Sstevel@tonic-gate * 19090Sstevel@tonic-gate * o files explicitly defined on the command line (ie. foo.o or bar.so), 19100Sstevel@tonic-gate * in this case only the `name' field is valid. 19110Sstevel@tonic-gate * 19120Sstevel@tonic-gate * o libraries determined from the -l command line option (ie. -lbar), 19130Sstevel@tonic-gate * in this case the `soname' field contains the basename of the located 19140Sstevel@tonic-gate * file. 19150Sstevel@tonic-gate * 19160Sstevel@tonic-gate * Any shared object specified via the above two conventions must be recorded 19170Sstevel@tonic-gate * as a needed dependency. 19180Sstevel@tonic-gate * 19190Sstevel@tonic-gate * o libraries specified as dependencies of those libraries already obtained 19200Sstevel@tonic-gate * via the command line (ie. bar.so has a DT_NEEDED entry of fred.so.1), 19210Sstevel@tonic-gate * in this case the `soname' field contains either a full pathname (if the 19220Sstevel@tonic-gate * needed entry contained a `/'), or the basename of the located file. 19230Sstevel@tonic-gate * These libraries are processed to verify symbol binding but are not 19240Sstevel@tonic-gate * recorded as dependencies of the output file being generated. 19250Sstevel@tonic-gate */ 19260Sstevel@tonic-gate Ifl_desc * 19271618Srie ld_process_ifl(const char *name, const char *soname, int fd, Elf *elf, 19287359SRod.Evans@Sun.COM Word flags, Ofl_desc *ofl, Rej_desc *rej) 19290Sstevel@tonic-gate { 19300Sstevel@tonic-gate Ifl_desc *ifl; 19310Sstevel@tonic-gate Ehdr *ehdr; 19320Sstevel@tonic-gate Listnode *lnp; 19330Sstevel@tonic-gate uintptr_t error = 0; 19340Sstevel@tonic-gate struct stat status; 19350Sstevel@tonic-gate Ar_desc *adp; 19360Sstevel@tonic-gate Rej_desc _rej; 19370Sstevel@tonic-gate 19380Sstevel@tonic-gate /* 19390Sstevel@tonic-gate * If this file was not extracted from an archive obtain its device 19400Sstevel@tonic-gate * information. This will be used to determine if the file has already 19410Sstevel@tonic-gate * been processed (rather than simply comparing filenames, the device 19420Sstevel@tonic-gate * information provides a quicker comparison and detects linked files). 19430Sstevel@tonic-gate */ 19440Sstevel@tonic-gate if (!(flags & FLG_IF_EXTRACT)) 19450Sstevel@tonic-gate (void) fstat(fd, &status); 19460Sstevel@tonic-gate else { 19470Sstevel@tonic-gate status.st_dev = 0; 19480Sstevel@tonic-gate status.st_ino = 0; 19490Sstevel@tonic-gate } 19500Sstevel@tonic-gate 19510Sstevel@tonic-gate switch (elf_kind(elf)) { 19520Sstevel@tonic-gate case ELF_K_AR: 19530Sstevel@tonic-gate /* 19540Sstevel@tonic-gate * Determine if we've already come across this archive file. 19550Sstevel@tonic-gate */ 19560Sstevel@tonic-gate if (!(flags & FLG_IF_EXTRACT)) { 19570Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_ars, lnp, adp)) { 19580Sstevel@tonic-gate if ((adp->ad_stdev != status.st_dev) || 19590Sstevel@tonic-gate (adp->ad_stino != status.st_ino)) 19600Sstevel@tonic-gate continue; 19610Sstevel@tonic-gate 19620Sstevel@tonic-gate /* 19630Sstevel@tonic-gate * We've seen this file before so reuse the 19640Sstevel@tonic-gate * original archive descriptor and discard the 19657359SRod.Evans@Sun.COM * new elf descriptor. Note that a file 19667359SRod.Evans@Sun.COM * descriptor is unnecessary, as the file is 19677359SRod.Evans@Sun.COM * already available in memory. 19680Sstevel@tonic-gate */ 19691618Srie DBG_CALL(Dbg_file_reuse(ofl->ofl_lml, name, 19701618Srie adp->ad_name)); 19710Sstevel@tonic-gate (void) elf_end(elf); 19727359SRod.Evans@Sun.COM return ((Ifl_desc *)ld_process_archive(name, -1, 19730Sstevel@tonic-gate adp, ofl)); 19740Sstevel@tonic-gate } 19750Sstevel@tonic-gate } 19760Sstevel@tonic-gate 19770Sstevel@tonic-gate /* 19780Sstevel@tonic-gate * As we haven't processed this file before establish a new 19790Sstevel@tonic-gate * archive descriptor. 19800Sstevel@tonic-gate */ 19811618Srie adp = ld_ar_setup(name, elf, ofl); 19820Sstevel@tonic-gate if ((adp == 0) || (adp == (Ar_desc *)S_ERROR)) 19830Sstevel@tonic-gate return ((Ifl_desc *)adp); 19840Sstevel@tonic-gate adp->ad_stdev = status.st_dev; 19850Sstevel@tonic-gate adp->ad_stino = status.st_ino; 19860Sstevel@tonic-gate 19871618Srie ld_sup_file(ofl, name, ELF_K_AR, flags, elf); 19880Sstevel@tonic-gate 19897359SRod.Evans@Sun.COM /* 19907359SRod.Evans@Sun.COM * Indicate that the ELF descriptor no longer requires a file 19917359SRod.Evans@Sun.COM * descriptor by reading the entire file. The file is already 19927359SRod.Evans@Sun.COM * read via the initial mmap(2) behind elf_begin(3elf), thus 19937359SRod.Evans@Sun.COM * this operation is effectively a no-op. However, a side- 19947359SRod.Evans@Sun.COM * effect is that the internal file descriptor, maintained in 19957359SRod.Evans@Sun.COM * the ELF descriptor, is set to -1. This setting will not 19967359SRod.Evans@Sun.COM * be compared with any file descriptor that is passed to 19977359SRod.Evans@Sun.COM * elf_begin(), should this archive, or one of the archive 19987359SRod.Evans@Sun.COM * members, be processed again from the command line or 19997359SRod.Evans@Sun.COM * because of a -z rescan. 20007359SRod.Evans@Sun.COM */ 20017359SRod.Evans@Sun.COM if (elf_cntl(elf, ELF_C_FDREAD) == -1) { 20027359SRod.Evans@Sun.COM eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_CNTL), 20037359SRod.Evans@Sun.COM name); 20047359SRod.Evans@Sun.COM ofl->ofl_flags |= FLG_OF_FATAL; 20057359SRod.Evans@Sun.COM return (NULL); 20067359SRod.Evans@Sun.COM } 20077359SRod.Evans@Sun.COM 20087359SRod.Evans@Sun.COM return ((Ifl_desc *)ld_process_archive(name, -1, adp, ofl)); 20090Sstevel@tonic-gate 20100Sstevel@tonic-gate case ELF_K_ELF: 20110Sstevel@tonic-gate /* 20120Sstevel@tonic-gate * Obtain the elf header so that we can determine what type of 20130Sstevel@tonic-gate * elf ELF_K_ELF file this is. 20140Sstevel@tonic-gate */ 20150Sstevel@tonic-gate if ((ehdr = elf_getehdr(elf)) == NULL) { 20160Sstevel@tonic-gate int _class = gelf_getclass(elf); 20170Sstevel@tonic-gate 20180Sstevel@tonic-gate /* 20190Sstevel@tonic-gate * Failure could occur for a number of reasons at this 20200Sstevel@tonic-gate * point. Typically the files class is incorrect (ie. 20210Sstevel@tonic-gate * user is building 64-bit but managed to pint at 32-bit 20220Sstevel@tonic-gate * libraries). However any number of elf errors can 20230Sstevel@tonic-gate * also occur, such as from a truncated or corrupt file. 20240Sstevel@tonic-gate * Here we try and get the best error message possible. 20250Sstevel@tonic-gate */ 20266206Sab196087 if (ld_targ.t_m.m_class != _class) { 20270Sstevel@tonic-gate _rej.rej_type = SGS_REJ_CLASS; 20280Sstevel@tonic-gate _rej.rej_info = (uint_t)_class; 20290Sstevel@tonic-gate } else { 20300Sstevel@tonic-gate _rej.rej_type = SGS_REJ_STR; 20310Sstevel@tonic-gate _rej.rej_str = elf_errmsg(-1); 20320Sstevel@tonic-gate } 20330Sstevel@tonic-gate _rej.rej_name = name; 20346206Sab196087 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej, 20356206Sab196087 ld_targ.t_m.m_mach)); 20360Sstevel@tonic-gate if (rej->rej_type == 0) { 20370Sstevel@tonic-gate *rej = _rej; 20380Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name); 20390Sstevel@tonic-gate } 20407359SRod.Evans@Sun.COM return (NULL); 20410Sstevel@tonic-gate } 20420Sstevel@tonic-gate 20430Sstevel@tonic-gate /* 20440Sstevel@tonic-gate * Determine if we've already come across this file. 20450Sstevel@tonic-gate */ 20460Sstevel@tonic-gate if (!(flags & FLG_IF_EXTRACT)) { 2047*7463SRod.Evans@Sun.COM List *lst; 20480Sstevel@tonic-gate 20490Sstevel@tonic-gate if (ehdr->e_type == ET_REL) 20500Sstevel@tonic-gate lst = &ofl->ofl_objs; 20510Sstevel@tonic-gate else 20520Sstevel@tonic-gate lst = &ofl->ofl_sos; 20530Sstevel@tonic-gate 20540Sstevel@tonic-gate /* 20550Sstevel@tonic-gate * Traverse the appropriate file list and determine if 20560Sstevel@tonic-gate * a dev/inode match is found. 20570Sstevel@tonic-gate */ 20580Sstevel@tonic-gate for (LIST_TRAVERSE(lst, lnp, ifl)) { 20590Sstevel@tonic-gate /* 20600Sstevel@tonic-gate * Ifl_desc generated via -Nneed, therefore no 20610Sstevel@tonic-gate * actual file behind it. 20620Sstevel@tonic-gate */ 20630Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_NEEDSTR) 20640Sstevel@tonic-gate continue; 20650Sstevel@tonic-gate 20660Sstevel@tonic-gate if ((ifl->ifl_stino != status.st_ino) || 20670Sstevel@tonic-gate (ifl->ifl_stdev != status.st_dev)) 20680Sstevel@tonic-gate continue; 20690Sstevel@tonic-gate 20700Sstevel@tonic-gate /* 20710Sstevel@tonic-gate * Disregard (skip) this image. 20720Sstevel@tonic-gate */ 20731618Srie DBG_CALL(Dbg_file_skip(ofl->ofl_lml, 20741618Srie ifl->ifl_name, name)); 20750Sstevel@tonic-gate (void) elf_end(elf); 20760Sstevel@tonic-gate 20770Sstevel@tonic-gate /* 20780Sstevel@tonic-gate * If the file was explicitly defined on the 20790Sstevel@tonic-gate * command line (this is always the case for 20800Sstevel@tonic-gate * relocatable objects, and is true for shared 20810Sstevel@tonic-gate * objects when they weren't specified via -l or 20820Sstevel@tonic-gate * were dragged in as an implicit dependency), 20830Sstevel@tonic-gate * then warn the user. 20840Sstevel@tonic-gate */ 20850Sstevel@tonic-gate if ((flags & FLG_IF_CMDLINE) || 20860Sstevel@tonic-gate (ifl->ifl_flags & FLG_IF_CMDLINE)) { 20870Sstevel@tonic-gate const char *errmsg; 20880Sstevel@tonic-gate 20890Sstevel@tonic-gate /* 20900Sstevel@tonic-gate * Determine whether this is the same 20910Sstevel@tonic-gate * file name as originally encountered 20920Sstevel@tonic-gate * so as to provide the most 20930Sstevel@tonic-gate * descriptive diagnostic. 20940Sstevel@tonic-gate */ 20954734Sab196087 errmsg = 20964734Sab196087 (strcmp(name, ifl->ifl_name) == 0) ? 20974734Sab196087 MSG_INTL(MSG_FIL_MULINC_1) : 20984734Sab196087 MSG_INTL(MSG_FIL_MULINC_2); 20991618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 21001618Srie errmsg, name, ifl->ifl_name); 21010Sstevel@tonic-gate } 21020Sstevel@tonic-gate return (ifl); 21030Sstevel@tonic-gate } 21040Sstevel@tonic-gate } 21050Sstevel@tonic-gate 21060Sstevel@tonic-gate /* 21070Sstevel@tonic-gate * At this point, we know we need the file. Establish an input 21080Sstevel@tonic-gate * file descriptor and continue processing. 21090Sstevel@tonic-gate */ 21100Sstevel@tonic-gate ifl = ifl_setup(name, ehdr, elf, flags, ofl, rej); 21110Sstevel@tonic-gate if ((ifl == 0) || (ifl == (Ifl_desc *)S_ERROR)) 21120Sstevel@tonic-gate return (ifl); 21130Sstevel@tonic-gate ifl->ifl_stdev = status.st_dev; 21140Sstevel@tonic-gate ifl->ifl_stino = status.st_ino; 21150Sstevel@tonic-gate 21160Sstevel@tonic-gate /* 21170Sstevel@tonic-gate * If -zignore is in effect, mark this file as a potential 21180Sstevel@tonic-gate * candidate (the files use isn't actually determined until 21190Sstevel@tonic-gate * symbol resolution and relocation processing are completed). 21200Sstevel@tonic-gate */ 21210Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_IGNORE) 21220Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_IGNORE; 21230Sstevel@tonic-gate 21240Sstevel@tonic-gate switch (ehdr->e_type) { 21250Sstevel@tonic-gate case ET_REL: 21266206Sab196087 (*ld_targ.t_mr.mr_mach_eflags)(ehdr, ofl); 21270Sstevel@tonic-gate error = process_elf(ifl, elf, ofl); 21280Sstevel@tonic-gate break; 21290Sstevel@tonic-gate case ET_DYN: 21300Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STATIC) || 21310Sstevel@tonic-gate !(ofl->ofl_flags & FLG_OF_DYNLIBS)) { 21321618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 21331618Srie MSG_INTL(MSG_FIL_SOINSTAT), name); 21340Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 21357359SRod.Evans@Sun.COM return (NULL); 21360Sstevel@tonic-gate } 21370Sstevel@tonic-gate 21380Sstevel@tonic-gate /* 21390Sstevel@tonic-gate * Record any additional shared object information. 21400Sstevel@tonic-gate * If no soname is specified (eg. this file was 21410Sstevel@tonic-gate * derived from a explicit filename declaration on the 21420Sstevel@tonic-gate * command line, ie. bar.so) use the pathname. 21430Sstevel@tonic-gate * This entry may be overridden if the files dynamic 21440Sstevel@tonic-gate * section specifies an DT_SONAME value. 21450Sstevel@tonic-gate */ 21460Sstevel@tonic-gate if (soname == NULL) 21470Sstevel@tonic-gate ifl->ifl_soname = ifl->ifl_name; 21480Sstevel@tonic-gate else 21490Sstevel@tonic-gate ifl->ifl_soname = soname; 21500Sstevel@tonic-gate 21510Sstevel@tonic-gate /* 21520Sstevel@tonic-gate * If direct bindings, lazy loading, or group 21530Sstevel@tonic-gate * permissions need to be established, mark this object. 21540Sstevel@tonic-gate */ 21550Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_ZDIRECT) 21560Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DIRECT; 21570Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_LAZYLD) 21580Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_LAZYLD; 21590Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_GRPPRM) 21600Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_GRPPRM; 21610Sstevel@tonic-gate error = process_elf(ifl, elf, ofl); 21620Sstevel@tonic-gate 21630Sstevel@tonic-gate /* 21640Sstevel@tonic-gate * At this point we know if this file will be 21650Sstevel@tonic-gate * lazyloaded, or whether bindings to it must be direct. 21660Sstevel@tonic-gate * In either case, a syminfo section is required. 21670Sstevel@tonic-gate */ 21680Sstevel@tonic-gate if (ifl->ifl_flags & (FLG_IF_LAZYLD | FLG_IF_DIRECT)) 21690Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_SYMINFO; 21700Sstevel@tonic-gate 21710Sstevel@tonic-gate break; 21720Sstevel@tonic-gate default: 21730Sstevel@tonic-gate (void) elf_errno(); 21740Sstevel@tonic-gate _rej.rej_type = SGS_REJ_UNKFILE; 21750Sstevel@tonic-gate _rej.rej_name = name; 21766206Sab196087 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej, 21776206Sab196087 ld_targ.t_m.m_mach)); 21780Sstevel@tonic-gate if (rej->rej_type == 0) { 21790Sstevel@tonic-gate *rej = _rej; 21800Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name); 21810Sstevel@tonic-gate } 21827359SRod.Evans@Sun.COM return (NULL); 21830Sstevel@tonic-gate } 21840Sstevel@tonic-gate break; 21850Sstevel@tonic-gate default: 21860Sstevel@tonic-gate (void) elf_errno(); 21870Sstevel@tonic-gate _rej.rej_type = SGS_REJ_UNKFILE; 21880Sstevel@tonic-gate _rej.rej_name = name; 21896206Sab196087 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej, 21906206Sab196087 ld_targ.t_m.m_mach)); 21910Sstevel@tonic-gate if (rej->rej_type == 0) { 21920Sstevel@tonic-gate *rej = _rej; 21930Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name); 21940Sstevel@tonic-gate } 21957359SRod.Evans@Sun.COM return (NULL); 21960Sstevel@tonic-gate } 21970Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR)) 21980Sstevel@tonic-gate return ((Ifl_desc *)error); 21990Sstevel@tonic-gate else 22000Sstevel@tonic-gate return (ifl); 22010Sstevel@tonic-gate } 22020Sstevel@tonic-gate 22030Sstevel@tonic-gate /* 22040Sstevel@tonic-gate * Having successfully opened a file, set up the necessary elf structures to 22050Sstevel@tonic-gate * process it further. This small section of processing is slightly different 22060Sstevel@tonic-gate * from the elf initialization required to process a relocatable object from an 22072850Srie * archive (see libs.c: ld_process_archive()). 22080Sstevel@tonic-gate */ 22090Sstevel@tonic-gate Ifl_desc * 22102978Srie ld_process_open(const char *opath, const char *ofile, int *fd, Ofl_desc *ofl, 22114716Sab196087 Word flags, Rej_desc *rej) 22120Sstevel@tonic-gate { 22132978Srie Elf *elf; 22142978Srie const char *npath = opath; 22152978Srie const char *nfile = ofile; 22160Sstevel@tonic-gate 22172978Srie if ((elf = elf_begin(*fd, ELF_C_READ, NULL)) == NULL) { 22182978Srie eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_BEGIN), npath); 22190Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 22207359SRod.Evans@Sun.COM return (NULL); 22210Sstevel@tonic-gate } 22220Sstevel@tonic-gate 22232978Srie /* 22242978Srie * Determine whether the support library wishes to process this open. 22252978Srie * The support library may return: 22262978Srie * . a different ELF descriptor (in which case they should have 22272978Srie * closed the original) 22282978Srie * . a different file descriptor (in which case they should have 22292978Srie * closed the original) 22302978Srie * . a different path and file name (presumably associated with 22312978Srie * a different file descriptor) 22322978Srie * 22332978Srie * A file descriptor of -1, or and ELF descriptor of zero indicates 22342978Srie * the file should be ignored. 22352978Srie */ 22362978Srie ld_sup_open(ofl, &npath, &nfile, fd, flags, &elf, NULL, 0, 22372978Srie elf_kind(elf)); 22382978Srie 22392978Srie if ((*fd == -1) || (elf == NULL)) 22407359SRod.Evans@Sun.COM return (NULL); 22412978Srie 22422978Srie return (ld_process_ifl(npath, nfile, *fd, elf, flags, ofl, rej)); 22430Sstevel@tonic-gate } 22440Sstevel@tonic-gate 22450Sstevel@tonic-gate /* 22460Sstevel@tonic-gate * Process a required library (i.e. the dependency of a shared object). 22470Sstevel@tonic-gate * Combine the directory and filename, check the resultant path size, and try 22480Sstevel@tonic-gate * opening the pathname. 22490Sstevel@tonic-gate */ 22501618Srie static Ifl_desc * 22510Sstevel@tonic-gate process_req_lib(Sdf_desc *sdf, const char *dir, const char *file, 2252*7463SRod.Evans@Sun.COM Ofl_desc *ofl, Rej_desc *rej) 22530Sstevel@tonic-gate { 22540Sstevel@tonic-gate size_t dlen, plen; 22550Sstevel@tonic-gate int fd; 22560Sstevel@tonic-gate char path[PATH_MAX]; 22570Sstevel@tonic-gate const char *_dir = dir; 22580Sstevel@tonic-gate 22590Sstevel@tonic-gate /* 22600Sstevel@tonic-gate * Determine the sizes of the directory and filename to insure we don't 22610Sstevel@tonic-gate * exceed our buffer. 22620Sstevel@tonic-gate */ 22630Sstevel@tonic-gate if ((dlen = strlen(dir)) == 0) { 22640Sstevel@tonic-gate _dir = MSG_ORIG(MSG_STR_DOT); 22650Sstevel@tonic-gate dlen = 1; 22660Sstevel@tonic-gate } 22670Sstevel@tonic-gate dlen++; 22680Sstevel@tonic-gate plen = dlen + strlen(file) + 1; 22690Sstevel@tonic-gate if (plen > PATH_MAX) { 22701618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_FIL_PTHTOLONG), 22711618Srie _dir, file); 22720Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_FATAL; 22730Sstevel@tonic-gate return (0); 22740Sstevel@tonic-gate } 22750Sstevel@tonic-gate 22760Sstevel@tonic-gate /* 22770Sstevel@tonic-gate * Build the entire pathname and try and open the file. 22780Sstevel@tonic-gate */ 22790Sstevel@tonic-gate (void) strcpy(path, _dir); 22800Sstevel@tonic-gate (void) strcat(path, MSG_ORIG(MSG_STR_SLASH)); 22810Sstevel@tonic-gate (void) strcat(path, file); 22821618Srie DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name, 22831618Srie sdf->sdf_rfile, path)); 22840Sstevel@tonic-gate 22850Sstevel@tonic-gate if ((fd = open(path, O_RDONLY)) == -1) 22860Sstevel@tonic-gate return (0); 22870Sstevel@tonic-gate else { 22880Sstevel@tonic-gate Ifl_desc *ifl; 22890Sstevel@tonic-gate char *_path; 22900Sstevel@tonic-gate 22910Sstevel@tonic-gate if ((_path = libld_malloc(strlen(path) + 1)) == 0) 22920Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR); 22930Sstevel@tonic-gate (void) strcpy(_path, path); 22944716Sab196087 ifl = ld_process_open(_path, &_path[dlen], &fd, ofl, 0, rej); 22952978Srie if (fd != -1) 22962978Srie (void) close(fd); 22970Sstevel@tonic-gate return (ifl); 22980Sstevel@tonic-gate } 22990Sstevel@tonic-gate } 23000Sstevel@tonic-gate 23010Sstevel@tonic-gate /* 23020Sstevel@tonic-gate * Finish any library processing. Walk the list of so's that have been listed 23030Sstevel@tonic-gate * as "included" by shared objects we have previously processed. Examine them, 23040Sstevel@tonic-gate * without adding them as explicit dependents of this program, in order to 23050Sstevel@tonic-gate * complete our symbol definition process. The search path rules are: 23060Sstevel@tonic-gate * 23070Sstevel@tonic-gate * o use any user supplied paths, i.e. LD_LIBRARY_PATH and -L, then 23080Sstevel@tonic-gate * 23090Sstevel@tonic-gate * o use any RPATH defined within the parent shared object, then 23100Sstevel@tonic-gate * 23110Sstevel@tonic-gate * o use the default directories, i.e. LIBPATH or -YP. 23120Sstevel@tonic-gate */ 23130Sstevel@tonic-gate uintptr_t 23141618Srie ld_finish_libs(Ofl_desc *ofl) 23150Sstevel@tonic-gate { 23160Sstevel@tonic-gate Listnode *lnp1; 23170Sstevel@tonic-gate Sdf_desc *sdf; 23180Sstevel@tonic-gate Rej_desc rej = { 0 }; 23190Sstevel@tonic-gate 23200Sstevel@tonic-gate /* 23210Sstevel@tonic-gate * Make sure we are back in dynamic mode. 23220Sstevel@tonic-gate */ 23230Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_DYNLIBS; 23240Sstevel@tonic-gate 23250Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_soneed, lnp1, sdf)) { 23260Sstevel@tonic-gate Listnode *lnp2; 23272850Srie char *path, *slash = NULL; 23280Sstevel@tonic-gate int fd; 23290Sstevel@tonic-gate Ifl_desc *ifl; 23302850Srie char *file = (char *)sdf->sdf_name; 23310Sstevel@tonic-gate 23320Sstevel@tonic-gate /* 23330Sstevel@tonic-gate * See if this file has already been processed. At the time 23340Sstevel@tonic-gate * this implicit dependency was determined there may still have 23351109Srie * been more explicit dependencies to process. Note, if we ever 23360Sstevel@tonic-gate * do parse the command line three times we would be able to 23371109Srie * do all this checking when processing the dynamic section. 23380Sstevel@tonic-gate */ 23390Sstevel@tonic-gate if (sdf->sdf_file) 23400Sstevel@tonic-gate continue; 23410Sstevel@tonic-gate 23420Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_sos, lnp2, ifl)) { 23430Sstevel@tonic-gate if (!(ifl->ifl_flags & FLG_IF_NEEDSTR) && 23440Sstevel@tonic-gate (strcmp(file, ifl->ifl_soname) == 0)) { 23450Sstevel@tonic-gate sdf->sdf_file = ifl; 23460Sstevel@tonic-gate break; 23470Sstevel@tonic-gate } 23480Sstevel@tonic-gate } 23490Sstevel@tonic-gate if (sdf->sdf_file) 23500Sstevel@tonic-gate continue; 23510Sstevel@tonic-gate 23520Sstevel@tonic-gate /* 23532850Srie * If the current path name element embeds a "/", then it's to 23542850Srie * be taken "as is", with no searching involved. Process all 23552850Srie * "/" occurrences, so that we can deduce the base file name. 23560Sstevel@tonic-gate */ 23572850Srie for (path = file; *path; path++) { 23580Sstevel@tonic-gate if (*path == '/') 23592850Srie slash = path; 23602850Srie } 23612850Srie if (slash) { 23621618Srie DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name, 23631618Srie sdf->sdf_rfile, file)); 23640Sstevel@tonic-gate if ((fd = open(file, O_RDONLY)) == -1) { 23651618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 23661618Srie MSG_INTL(MSG_FIL_NOTFOUND), file, 23671618Srie sdf->sdf_rfile); 23680Sstevel@tonic-gate } else { 23690Sstevel@tonic-gate Rej_desc _rej = { 0 }; 23700Sstevel@tonic-gate 23712978Srie ifl = ld_process_open(file, ++slash, &fd, ofl, 23724716Sab196087 0, &_rej); 23732978Srie if (fd != -1) 23742978Srie (void) close(fd); 23757359SRod.Evans@Sun.COM if (ifl == (Ifl_desc *)S_ERROR) 23767359SRod.Evans@Sun.COM return (S_ERROR); 23770Sstevel@tonic-gate 23780Sstevel@tonic-gate if (_rej.rej_type) { 23794734Sab196087 Conv_reject_desc_buf_t rej_buf; 23804734Sab196087 23811618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 23820Sstevel@tonic-gate MSG_INTL(reject[_rej.rej_type]), 23830Sstevel@tonic-gate _rej.rej_name ? rej.rej_name : 23840Sstevel@tonic-gate MSG_INTL(MSG_STR_UNKNOWN), 23856206Sab196087 conv_reject_desc(&_rej, &rej_buf, 23866206Sab196087 ld_targ.t_m.m_mach)); 23870Sstevel@tonic-gate } else 23880Sstevel@tonic-gate sdf->sdf_file = ifl; 23890Sstevel@tonic-gate } 23900Sstevel@tonic-gate continue; 23910Sstevel@tonic-gate } 23920Sstevel@tonic-gate 23930Sstevel@tonic-gate /* 23940Sstevel@tonic-gate * Now search for this file in any user defined directories. 23950Sstevel@tonic-gate */ 23960Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_ulibdirs, lnp2, path)) { 23970Sstevel@tonic-gate Rej_desc _rej = { 0 }; 23980Sstevel@tonic-gate 23990Sstevel@tonic-gate ifl = process_req_lib(sdf, path, file, ofl, &_rej); 24000Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) { 24010Sstevel@tonic-gate return (S_ERROR); 24020Sstevel@tonic-gate } 24030Sstevel@tonic-gate if (_rej.rej_type) { 24040Sstevel@tonic-gate if (rej.rej_type == 0) { 24050Sstevel@tonic-gate rej = _rej; 24060Sstevel@tonic-gate rej.rej_name = strdup(_rej.rej_name); 24070Sstevel@tonic-gate } 24080Sstevel@tonic-gate } 24090Sstevel@tonic-gate if (ifl) { 24100Sstevel@tonic-gate sdf->sdf_file = ifl; 24110Sstevel@tonic-gate break; 24120Sstevel@tonic-gate } 24130Sstevel@tonic-gate } 24140Sstevel@tonic-gate if (sdf->sdf_file) 24150Sstevel@tonic-gate continue; 24160Sstevel@tonic-gate 24170Sstevel@tonic-gate /* 24180Sstevel@tonic-gate * Next use the local rules defined within the parent shared 24190Sstevel@tonic-gate * object. 24200Sstevel@tonic-gate */ 24210Sstevel@tonic-gate if (sdf->sdf_rpath != NULL) { 24220Sstevel@tonic-gate char *rpath, *next; 24230Sstevel@tonic-gate 24240Sstevel@tonic-gate rpath = libld_malloc(strlen(sdf->sdf_rpath) + 1); 24250Sstevel@tonic-gate if (rpath == 0) 24260Sstevel@tonic-gate return (S_ERROR); 24270Sstevel@tonic-gate (void) strcpy(rpath, sdf->sdf_rpath); 24281618Srie DBG_CALL(Dbg_libs_path(ofl->ofl_lml, rpath, 24291618Srie LA_SER_RUNPATH, sdf->sdf_rfile)); 24300Sstevel@tonic-gate if ((path = strtok_r(rpath, 24310Sstevel@tonic-gate MSG_ORIG(MSG_STR_COLON), &next)) != NULL) { 24320Sstevel@tonic-gate do { 24330Sstevel@tonic-gate Rej_desc _rej = { 0 }; 24340Sstevel@tonic-gate 24350Sstevel@tonic-gate path = expand(sdf->sdf_rfile, path, 24360Sstevel@tonic-gate &next); 24370Sstevel@tonic-gate 24380Sstevel@tonic-gate ifl = process_req_lib(sdf, path, 24394716Sab196087 file, ofl, &_rej); 24400Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) { 24410Sstevel@tonic-gate return (S_ERROR); 24420Sstevel@tonic-gate } 24434716Sab196087 if ((_rej.rej_type) && 24444716Sab196087 (rej.rej_type == 0)) { 24454716Sab196087 rej = _rej; 24464716Sab196087 rej.rej_name = 24474716Sab196087 strdup(_rej.rej_name); 24480Sstevel@tonic-gate } 24490Sstevel@tonic-gate if (ifl) { 24500Sstevel@tonic-gate sdf->sdf_file = ifl; 24510Sstevel@tonic-gate break; 24520Sstevel@tonic-gate } 24530Sstevel@tonic-gate } while ((path = strtok_r(NULL, 24540Sstevel@tonic-gate MSG_ORIG(MSG_STR_COLON), &next)) != NULL); 24550Sstevel@tonic-gate } 24560Sstevel@tonic-gate } 24570Sstevel@tonic-gate if (sdf->sdf_file) 24580Sstevel@tonic-gate continue; 24590Sstevel@tonic-gate 24600Sstevel@tonic-gate /* 24610Sstevel@tonic-gate * Finally try the default library search directories. 24620Sstevel@tonic-gate */ 24630Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_dlibdirs, lnp2, path)) { 24640Sstevel@tonic-gate Rej_desc _rej = { 0 }; 24650Sstevel@tonic-gate 24660Sstevel@tonic-gate ifl = process_req_lib(sdf, path, file, ofl, &rej); 24670Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) { 24680Sstevel@tonic-gate return (S_ERROR); 24690Sstevel@tonic-gate } 24700Sstevel@tonic-gate if (_rej.rej_type) { 24710Sstevel@tonic-gate if (rej.rej_type == 0) { 24720Sstevel@tonic-gate rej = _rej; 24730Sstevel@tonic-gate rej.rej_name = strdup(_rej.rej_name); 24740Sstevel@tonic-gate } 24750Sstevel@tonic-gate } 24760Sstevel@tonic-gate if (ifl) { 24770Sstevel@tonic-gate sdf->sdf_file = ifl; 24780Sstevel@tonic-gate break; 24790Sstevel@tonic-gate } 24800Sstevel@tonic-gate } 24810Sstevel@tonic-gate if (sdf->sdf_file) 24820Sstevel@tonic-gate continue; 24830Sstevel@tonic-gate 24840Sstevel@tonic-gate /* 24850Sstevel@tonic-gate * If we've got this far we haven't found the shared object. 24860Sstevel@tonic-gate * If an object was found, but was rejected for some reason, 24870Sstevel@tonic-gate * print a diagnostic to that effect, otherwise generate a 24880Sstevel@tonic-gate * generic "not found" diagnostic. 24890Sstevel@tonic-gate */ 24900Sstevel@tonic-gate if (rej.rej_type) { 24914734Sab196087 Conv_reject_desc_buf_t rej_buf; 24924734Sab196087 24931618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 24941618Srie MSG_INTL(reject[rej.rej_type]), 24950Sstevel@tonic-gate rej.rej_name ? rej.rej_name : 24964734Sab196087 MSG_INTL(MSG_STR_UNKNOWN), 24976206Sab196087 conv_reject_desc(&rej, &rej_buf, 24986206Sab196087 ld_targ.t_m.m_mach)); 24990Sstevel@tonic-gate } else { 25001618Srie eprintf(ofl->ofl_lml, ERR_WARNING, 25011618Srie MSG_INTL(MSG_FIL_NOTFOUND), file, sdf->sdf_rfile); 25020Sstevel@tonic-gate } 25030Sstevel@tonic-gate } 25040Sstevel@tonic-gate 25050Sstevel@tonic-gate /* 25060Sstevel@tonic-gate * Finally, now that all objects have been input, make sure any version 25070Sstevel@tonic-gate * requirements have been met. 25080Sstevel@tonic-gate */ 25091618Srie return (ld_vers_verify(ofl)); 25100Sstevel@tonic-gate } 2511