xref: /onnv-gate/usr/src/cmd/sgs/libld/common/files.c (revision 12254)
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  *
26*12254SAli.Bahrami@Oracle.COM  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * Processing of relocatable objects and shared objects.
310Sstevel@tonic-gate  */
326206Sab196087 
336206Sab196087 #define	ELF_TARGET_AMD64
346206Sab196087 #define	ELF_TARGET_SPARC
356206Sab196087 
360Sstevel@tonic-gate #include	<stdio.h>
370Sstevel@tonic-gate #include	<string.h>
380Sstevel@tonic-gate #include	<fcntl.h>
390Sstevel@tonic-gate #include	<unistd.h>
400Sstevel@tonic-gate #include	<link.h>
410Sstevel@tonic-gate #include	<limits.h>
420Sstevel@tonic-gate #include	<sys/stat.h>
430Sstevel@tonic-gate #include	<sys/systeminfo.h>
440Sstevel@tonic-gate #include	<debug.h>
450Sstevel@tonic-gate #include	<msg.h>
460Sstevel@tonic-gate #include	<_libld.h>
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate  * Decide if we can link against this input file.
500Sstevel@tonic-gate  */
510Sstevel@tonic-gate static int
527463SRod.Evans@Sun.COM ifl_verify(Ehdr *ehdr, Ofl_desc *ofl, Rej_desc *rej)
530Sstevel@tonic-gate {
540Sstevel@tonic-gate 	/*
550Sstevel@tonic-gate 	 * Check the validity of the elf header information for compatibility
560Sstevel@tonic-gate 	 * with this machine and our own internal elf library.
570Sstevel@tonic-gate 	 */
586206Sab196087 	if ((ehdr->e_machine != ld_targ.t_m.m_mach) &&
596206Sab196087 	    ((ehdr->e_machine != ld_targ.t_m.m_machplus) &&
606206Sab196087 	    ((ehdr->e_flags & ld_targ.t_m.m_flagsplus) == 0))) {
610Sstevel@tonic-gate 		rej->rej_type = SGS_REJ_MACH;
620Sstevel@tonic-gate 		rej->rej_info = (uint_t)ehdr->e_machine;
630Sstevel@tonic-gate 		return (0);
640Sstevel@tonic-gate 	}
656206Sab196087 	if (ehdr->e_ident[EI_DATA] != ld_targ.t_m.m_data) {
660Sstevel@tonic-gate 		rej->rej_type = SGS_REJ_DATA;
670Sstevel@tonic-gate 		rej->rej_info = (uint_t)ehdr->e_ident[EI_DATA];
680Sstevel@tonic-gate 		return (0);
690Sstevel@tonic-gate 	}
701618Srie 	if (ehdr->e_version > ofl->ofl_dehdr->e_version) {
710Sstevel@tonic-gate 		rej->rej_type = SGS_REJ_VERSION;
720Sstevel@tonic-gate 		rej->rej_info = (uint_t)ehdr->e_version;
730Sstevel@tonic-gate 		return (0);
740Sstevel@tonic-gate 	}
750Sstevel@tonic-gate 	return (1);
760Sstevel@tonic-gate }
770Sstevel@tonic-gate 
780Sstevel@tonic-gate /*
790Sstevel@tonic-gate  * Check sanity of file header and allocate an infile descriptor
800Sstevel@tonic-gate  * for the file being processed.
810Sstevel@tonic-gate  */
821618Srie static Ifl_desc *
834716Sab196087 ifl_setup(const char *name, Ehdr *ehdr, Elf *elf, Word flags, Ofl_desc *ofl,
840Sstevel@tonic-gate     Rej_desc *rej)
850Sstevel@tonic-gate {
860Sstevel@tonic-gate 	Ifl_desc	*ifl;
870Sstevel@tonic-gate 	Rej_desc	_rej = { 0 };
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	if (ifl_verify(ehdr, ofl, &_rej) == 0) {
900Sstevel@tonic-gate 		_rej.rej_name = name;
916206Sab196087 		DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
926206Sab196087 		    ld_targ.t_m.m_mach));
930Sstevel@tonic-gate 		if (rej->rej_type == 0) {
940Sstevel@tonic-gate 			*rej = _rej;
950Sstevel@tonic-gate 			rej->rej_name = strdup(_rej.rej_name);
960Sstevel@tonic-gate 		}
970Sstevel@tonic-gate 		return (0);
980Sstevel@tonic-gate 	}
990Sstevel@tonic-gate 
10010792SRod.Evans@Sun.COM 	if ((ifl = libld_calloc(1, sizeof (Ifl_desc))) == NULL)
1010Sstevel@tonic-gate 		return ((Ifl_desc *)S_ERROR);
1020Sstevel@tonic-gate 	ifl->ifl_name = name;
1030Sstevel@tonic-gate 	ifl->ifl_ehdr = ehdr;
1040Sstevel@tonic-gate 	ifl->ifl_elf = elf;
1050Sstevel@tonic-gate 	ifl->ifl_flags = flags;
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	/*
1080Sstevel@tonic-gate 	 * Is this file using 'extended Section Indexes'.  If so, use the
1090Sstevel@tonic-gate 	 * e_shnum & e_shstrndx which can be found at:
1100Sstevel@tonic-gate 	 *
1110Sstevel@tonic-gate 	 *	e_shnum == Shdr[0].sh_size
1120Sstevel@tonic-gate 	 *	e_shstrndx == Shdr[0].sh_link
1130Sstevel@tonic-gate 	 */
1140Sstevel@tonic-gate 	if ((ehdr->e_shnum == 0) && (ehdr->e_shoff != 0)) {
1150Sstevel@tonic-gate 		Elf_Scn	*scn;
1160Sstevel@tonic-gate 		Shdr	*shdr0;
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 		if ((scn = elf_getscn(elf, 0)) == NULL) {
1191618Srie 			eprintf(ofl->ofl_lml, ERR_ELF,
1201618Srie 			    MSG_INTL(MSG_ELF_GETSCN), name);
1210Sstevel@tonic-gate 			ofl->ofl_flags |= FLG_OF_FATAL;
1220Sstevel@tonic-gate 			return ((Ifl_desc *)S_ERROR);
1230Sstevel@tonic-gate 		}
1240Sstevel@tonic-gate 		if ((shdr0 = elf_getshdr(scn)) == NULL) {
1251618Srie 			eprintf(ofl->ofl_lml, ERR_ELF,
1261618Srie 			    MSG_INTL(MSG_ELF_GETSHDR), name);
1270Sstevel@tonic-gate 			ofl->ofl_flags |= FLG_OF_FATAL;
1280Sstevel@tonic-gate 			return ((Ifl_desc *)S_ERROR);
1290Sstevel@tonic-gate 		}
1300Sstevel@tonic-gate 		ifl->ifl_shnum = (Word)shdr0->sh_size;
1310Sstevel@tonic-gate 		if (ehdr->e_shstrndx == SHN_XINDEX)
1320Sstevel@tonic-gate 			ifl->ifl_shstrndx = shdr0->sh_link;
1330Sstevel@tonic-gate 		else
1340Sstevel@tonic-gate 			ifl->ifl_shstrndx = ehdr->e_shstrndx;
1350Sstevel@tonic-gate 	} else {
1360Sstevel@tonic-gate 		ifl->ifl_shnum = ehdr->e_shnum;
1370Sstevel@tonic-gate 		ifl->ifl_shstrndx = ehdr->e_shstrndx;
1380Sstevel@tonic-gate 	}
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	if ((ifl->ifl_isdesc = libld_calloc(ifl->ifl_shnum,
14110792SRod.Evans@Sun.COM 	    sizeof (Is_desc *))) == NULL)
1420Sstevel@tonic-gate 		return ((Ifl_desc *)S_ERROR);
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	/*
1450Sstevel@tonic-gate 	 * Record this new input file on the shared object or relocatable
1460Sstevel@tonic-gate 	 * object input file list.
1470Sstevel@tonic-gate 	 */
1480Sstevel@tonic-gate 	if (ifl->ifl_ehdr->e_type == ET_DYN) {
1499131SRod.Evans@Sun.COM 		if (aplist_append(&ofl->ofl_sos, ifl, AL_CNT_OFL_LIBS) == NULL)
1509131SRod.Evans@Sun.COM 			return ((Ifl_desc *)S_ERROR);
1510Sstevel@tonic-gate 	} else {
1529131SRod.Evans@Sun.COM 		if (aplist_append(&ofl->ofl_objs, ifl, AL_CNT_OFL_OBJS) == NULL)
1539131SRod.Evans@Sun.COM 			return ((Ifl_desc *)S_ERROR);
1540Sstevel@tonic-gate 	}
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	return (ifl);
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate /*
1600Sstevel@tonic-gate  * Process a generic section.  The appropriate section information is added
1610Sstevel@tonic-gate  * to the files input descriptor list.
1620Sstevel@tonic-gate  */
1631618Srie static uintptr_t
1640Sstevel@tonic-gate process_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1650Sstevel@tonic-gate     Word ndx, int ident, Ofl_desc *ofl)
1660Sstevel@tonic-gate {
1670Sstevel@tonic-gate 	Is_desc	*isp;
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate 	/*
1700Sstevel@tonic-gate 	 * Create a new input section descriptor.  If this is a NOBITS
1710Sstevel@tonic-gate 	 * section elf_getdata() will still create a data buffer (the buffer
1720Sstevel@tonic-gate 	 * will be null and the size will reflect the actual memory size).
1730Sstevel@tonic-gate 	 */
17410792SRod.Evans@Sun.COM 	if ((isp = libld_calloc(sizeof (Is_desc), 1)) == NULL)
1750Sstevel@tonic-gate 		return (S_ERROR);
1760Sstevel@tonic-gate 	isp->is_shdr = shdr;
1770Sstevel@tonic-gate 	isp->is_file = ifl;
1780Sstevel@tonic-gate 	isp->is_name = name;
1790Sstevel@tonic-gate 	isp->is_scnndx = ndx;
180574Sseizo 	isp->is_flags = FLG_IS_EXTERNAL;
1817463SRod.Evans@Sun.COM 	isp->is_keyident = ident;
1827463SRod.Evans@Sun.COM 
1830Sstevel@tonic-gate 	if ((isp->is_indata = elf_getdata(scn, NULL)) == NULL) {
1841618Srie 		eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_GETDATA),
1851618Srie 		    ifl->ifl_name);
1860Sstevel@tonic-gate 		ofl->ofl_flags |= FLG_OF_FATAL;
1870Sstevel@tonic-gate 		return (0);
1880Sstevel@tonic-gate 	}
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate 	if ((shdr->sh_flags & SHF_EXCLUDE) &&
1910Sstevel@tonic-gate 	    ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0)) {
1920Sstevel@tonic-gate 		isp->is_flags |= FLG_IS_DISCARD;
1930Sstevel@tonic-gate 	}
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate 	/*
1960Sstevel@tonic-gate 	 * Add the new input section to the files input section list and
1977463SRod.Evans@Sun.COM 	 * flag whether the section needs placing in an output section.  This
1987463SRod.Evans@Sun.COM 	 * placement is deferred until all input section processing has been
1997463SRod.Evans@Sun.COM 	 * completed, as SHT_GROUP sections can provide information that will
2007463SRod.Evans@Sun.COM 	 * affect how other sections within the file should be placed.
2010Sstevel@tonic-gate 	 */
2020Sstevel@tonic-gate 	ifl->ifl_isdesc[ndx] = isp;
2030Sstevel@tonic-gate 
2047463SRod.Evans@Sun.COM 	if (ident) {
2057463SRod.Evans@Sun.COM 		if (shdr->sh_flags & ALL_SHF_ORDER) {
2067463SRod.Evans@Sun.COM 			isp->is_flags |= FLG_IS_ORDERED;
2077463SRod.Evans@Sun.COM 			ifl->ifl_flags |= FLG_IF_ORDERED;
2082647Srie 		}
2097463SRod.Evans@Sun.COM 		isp->is_flags |= FLG_IS_PLACE;
2100Sstevel@tonic-gate 	}
2110Sstevel@tonic-gate 	return (1);
2120Sstevel@tonic-gate }
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate /*
2150Sstevel@tonic-gate  * Determine the software capabilities of the object being built from the
2160Sstevel@tonic-gate  * capabilities of the input relocatable objects.   One software capability
2170Sstevel@tonic-gate  * is presently recognized, and represented with the following (sys/elf.h):
2180Sstevel@tonic-gate  *
2190Sstevel@tonic-gate  *   SF1_SUNW_FPKNWN	use/non-use of frame pointer is known, and
2200Sstevel@tonic-gate  *   SF1_SUNW_FPUSED    the frame pointer is in use.
2210Sstevel@tonic-gate  *
2220Sstevel@tonic-gate  * The resolution of the present fame pointer state, and the capabilities
2230Sstevel@tonic-gate  * provided by a new input relocatable object are:
2240Sstevel@tonic-gate  *
2250Sstevel@tonic-gate  *                              new input relocatable object
2260Sstevel@tonic-gate  *
2270Sstevel@tonic-gate  *      present      |  SF1_SUNW_FPKNWN  |  SF1_SUNW_FPKNWN  |    <unknown>
2280Sstevel@tonic-gate  *       state       |  SF1_SUNW_FPUSED  |                   |
2290Sstevel@tonic-gate  *  ---------------------------------------------------------------------------
2300Sstevel@tonic-gate  *  SF1_SUNW_FPKNWN  |  SF1_SUNW_FPKNWN  |  SF1_SUNW_FPKNWN  |  SF1_SUNW_FPKNWN
2310Sstevel@tonic-gate  *  SF1_SUNW_FPUSED  |  SF1_SUNW_FPUSED  |                   |  SF1_SUNW_FPUSED
2320Sstevel@tonic-gate  *  ---------------------------------------------------------------------------
2330Sstevel@tonic-gate  *  SF1_SUNW_FPKNWN  |  SF1_SUNW_FPKNWN  |  SF1_SUNW_FPKNWN  |  SF1_SUNW_FPKNWN
2340Sstevel@tonic-gate  *                   |                   |                   |
2350Sstevel@tonic-gate  *  ---------------------------------------------------------------------------
2360Sstevel@tonic-gate  *     <unknown>     |  SF1_SUNW_FPKNWN  |  SF1_SUNW_FPKNWN  |    <unknown>
2370Sstevel@tonic-gate  *                   |  SF1_SUNW_FPUSED  |                   |
2380Sstevel@tonic-gate  */
2390Sstevel@tonic-gate static void
2409878SAli.Bahrami@Sun.COM sf1_cap(Ofl_desc *ofl, Xword val, Ifl_desc *ifl, Is_desc *cisp)
2410Sstevel@tonic-gate {
24211734SAli.Bahrami@Sun.COM #define	FP_FLAGS	(SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)
24311734SAli.Bahrami@Sun.COM 
2440Sstevel@tonic-gate 	Xword	badval;
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate 	/*
24711827SRod.Evans@Sun.COM 	 * If a mapfile has established definitions to override any object
24811827SRod.Evans@Sun.COM 	 * capabilities, ignore any new object capabilities.
2490Sstevel@tonic-gate 	 */
25011734SAli.Bahrami@Sun.COM 	if (ofl->ofl_flags1 & FLG_OF1_OVSFCAP1) {
25111827SRod.Evans@Sun.COM 		DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
25211734SAli.Bahrami@Sun.COM 		    CA_SUNW_SF_1, val, ld_targ.t_m.m_mach));
2530Sstevel@tonic-gate 		return;
2540Sstevel@tonic-gate 	}
2550Sstevel@tonic-gate 
2567833SRod.Evans@Sun.COM #if	!defined(_ELF64)
25711827SRod.Evans@Sun.COM 	if (ifl && (ifl->ifl_ehdr->e_type == ET_REL)) {
2587833SRod.Evans@Sun.COM 		/*
2597833SRod.Evans@Sun.COM 		 * The SF1_SUNW_ADDR32 is only meaningful when building a 64-bit
2607833SRod.Evans@Sun.COM 		 * object.  Warn the user, and remove the setting, if we're
2617833SRod.Evans@Sun.COM 		 * building a 32-bit object.
2627833SRod.Evans@Sun.COM 		 */
2637833SRod.Evans@Sun.COM 		if (val & SF1_SUNW_ADDR32) {
2647833SRod.Evans@Sun.COM 			eprintf(ofl->ofl_lml, ERR_WARNING,
2659878SAli.Bahrami@Sun.COM 			    MSG_INTL(MSG_FIL_INADDR32SF1), ifl->ifl_name,
2669878SAli.Bahrami@Sun.COM 			    EC_WORD(cisp->is_scnndx), cisp->is_name);
2677833SRod.Evans@Sun.COM 			val &= ~SF1_SUNW_ADDR32;
2687833SRod.Evans@Sun.COM 		}
2697833SRod.Evans@Sun.COM 	}
2707833SRod.Evans@Sun.COM #endif
2710Sstevel@tonic-gate 	/*
2720Sstevel@tonic-gate 	 * If this object doesn't specify any capabilities, ignore it, and
2730Sstevel@tonic-gate 	 * leave the state as is.
2740Sstevel@tonic-gate 	 */
2750Sstevel@tonic-gate 	if (val == 0)
2760Sstevel@tonic-gate 		return;
2770Sstevel@tonic-gate 
2780Sstevel@tonic-gate 	/*
2790Sstevel@tonic-gate 	 * Make sure we only accept known software capabilities.  Note, that
2800Sstevel@tonic-gate 	 * an F1_SUNW_FPUSED by itself is viewed as bad practice.
2810Sstevel@tonic-gate 	 */
2820Sstevel@tonic-gate 	if ((badval = (val & ~SF1_SUNW_MASK)) != 0) {
2831618Srie 		eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1),
2849878SAli.Bahrami@Sun.COM 		    ifl->ifl_name, EC_WORD(cisp->is_scnndx), cisp->is_name,
2859878SAli.Bahrami@Sun.COM 		    EC_XWORD(badval));
2860Sstevel@tonic-gate 		val &= SF1_SUNW_MASK;
2870Sstevel@tonic-gate 	}
28811734SAli.Bahrami@Sun.COM 	if ((val & FP_FLAGS) == SF1_SUNW_FPUSED) {
2891618Srie 		eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1),
2909878SAli.Bahrami@Sun.COM 		    ifl->ifl_name, EC_WORD(cisp->is_scnndx), cisp->is_name,
2919878SAli.Bahrami@Sun.COM 		    EC_XWORD(val));
2920Sstevel@tonic-gate 		return;
2930Sstevel@tonic-gate 	}
2940Sstevel@tonic-gate 
2957833SRod.Evans@Sun.COM 	/*
2967833SRod.Evans@Sun.COM 	 * If the input file is not a relocatable object, then we're only here
2977833SRod.Evans@Sun.COM 	 * to warn the user of any questionable capabilities.
2987833SRod.Evans@Sun.COM 	 */
2997833SRod.Evans@Sun.COM 	if (ifl->ifl_ehdr->e_type != ET_REL) {
3007833SRod.Evans@Sun.COM #if	defined(_ELF64)
3017833SRod.Evans@Sun.COM 		/*
3027833SRod.Evans@Sun.COM 		 * If we're building a 64-bit executable, and we come across a
3037833SRod.Evans@Sun.COM 		 * dependency that requires a restricted address space, then
3047833SRod.Evans@Sun.COM 		 * that dependencies requirement can only be satisfied if the
3057833SRod.Evans@Sun.COM 		 * executable triggers the restricted address space.  This is a
3067833SRod.Evans@Sun.COM 		 * warning rather than a fatal error, as the possibility exists
3077833SRod.Evans@Sun.COM 		 * that an appropriate dependency will be provided at runtime.
3087833SRod.Evans@Sun.COM 		 * The runtime linker will refuse to use this dependency.
3097833SRod.Evans@Sun.COM 		 */
3107833SRod.Evans@Sun.COM 		if ((val & SF1_SUNW_ADDR32) && (ofl->ofl_flags & FLG_OF_EXEC) &&
31111827SRod.Evans@Sun.COM 		    ((ofl->ofl_ocapset.oc_sf_1.cm_val &
31211734SAli.Bahrami@Sun.COM 		    SF1_SUNW_ADDR32) == 0)) {
3137833SRod.Evans@Sun.COM 			eprintf(ofl->ofl_lml, ERR_WARNING,
3149878SAli.Bahrami@Sun.COM 			    MSG_INTL(MSG_FIL_EXADDR32SF1), ifl->ifl_name,
3159878SAli.Bahrami@Sun.COM 			    EC_WORD(cisp->is_scnndx), cisp->is_name);
3167833SRod.Evans@Sun.COM 		}
3177833SRod.Evans@Sun.COM #endif
3187833SRod.Evans@Sun.COM 		return;
3197833SRod.Evans@Sun.COM 	}
3207833SRod.Evans@Sun.COM 
32111734SAli.Bahrami@Sun.COM 	if (DBG_ENABLED) {
32211827SRod.Evans@Sun.COM 		Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_CURRENT, CA_SUNW_SF_1,
32311827SRod.Evans@Sun.COM 		    ofl->ofl_ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach);
32411827SRod.Evans@Sun.COM 		Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_NEW, CA_SUNW_SF_1,
32511734SAli.Bahrami@Sun.COM 		    val, ld_targ.t_m.m_mach);
32611734SAli.Bahrami@Sun.COM 	}
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 	/*
3290Sstevel@tonic-gate 	 * Determine the resolution of the present frame pointer and the
3300Sstevel@tonic-gate 	 * new input relocatable objects frame pointer.
3310Sstevel@tonic-gate 	 */
33211827SRod.Evans@Sun.COM 	if ((ofl->ofl_ocapset.oc_sf_1.cm_val & FP_FLAGS) == FP_FLAGS) {
3330Sstevel@tonic-gate 		/*
3340Sstevel@tonic-gate 		 * If the new relocatable object isn't using a frame pointer,
3350Sstevel@tonic-gate 		 * reduce the present state to unused.
3360Sstevel@tonic-gate 		 */
33711734SAli.Bahrami@Sun.COM 		if ((val & FP_FLAGS) != FP_FLAGS)
33811827SRod.Evans@Sun.COM 			ofl->ofl_ocapset.oc_sf_1.cm_val &= ~SF1_SUNW_FPUSED;
33911734SAli.Bahrami@Sun.COM 
34011734SAli.Bahrami@Sun.COM 		/*
34111734SAli.Bahrami@Sun.COM 		 * Having processed the frame pointer bits, remove them from
34211734SAli.Bahrami@Sun.COM 		 * the value so they don't get OR'd in below.
34311734SAli.Bahrami@Sun.COM 		 */
34411734SAli.Bahrami@Sun.COM 		val &= ~FP_FLAGS;
3450Sstevel@tonic-gate 
34611827SRod.Evans@Sun.COM 	} else if ((ofl->ofl_ocapset.oc_sf_1.cm_val & SF1_SUNW_FPKNWN) == 0) {
3470Sstevel@tonic-gate 		/*
34811734SAli.Bahrami@Sun.COM 		 * If the present frame pointer state is unknown, mask it out
34911734SAli.Bahrami@Sun.COM 		 * and allow the values from the new relocatable object
35011734SAli.Bahrami@Sun.COM 		 * to overwrite them.
3510Sstevel@tonic-gate 		 */
35211827SRod.Evans@Sun.COM 		ofl->ofl_ocapset.oc_sf_1.cm_val &= ~FP_FLAGS;
35311734SAli.Bahrami@Sun.COM 	} else {
35411734SAli.Bahrami@Sun.COM 		/* Do not take the frame pointer flags from the object */
35511734SAli.Bahrami@Sun.COM 		val &= ~FP_FLAGS;
3560Sstevel@tonic-gate 	}
3570Sstevel@tonic-gate 
35811827SRod.Evans@Sun.COM 	ofl->ofl_ocapset.oc_sf_1.cm_val |= val;
35911827SRod.Evans@Sun.COM 
36011827SRod.Evans@Sun.COM 	DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_RESOLVED,
36111827SRod.Evans@Sun.COM 	    CA_SUNW_SF_1, ofl->ofl_ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach));
36211734SAli.Bahrami@Sun.COM 
36311734SAli.Bahrami@Sun.COM #undef FP_FLAGS
3640Sstevel@tonic-gate }
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate /*
3670Sstevel@tonic-gate  * Determine the hardware capabilities of the object being built from the
3680Sstevel@tonic-gate  * capabilities of the input relocatable objects.  There's really little to
3690Sstevel@tonic-gate  * do here, other than to offer diagnostics, hardware capabilities are simply
3700Sstevel@tonic-gate  * additive.
3710Sstevel@tonic-gate  */
3720Sstevel@tonic-gate static void
37311827SRod.Evans@Sun.COM hw_cap(Ofl_desc *ofl, Xword tag, Xword val)
3740Sstevel@tonic-gate {
37511827SRod.Evans@Sun.COM 	elfcap_mask_t	*hwcap;
37611827SRod.Evans@Sun.COM 	ofl_flag_t	flags1;
37711827SRod.Evans@Sun.COM 
37811827SRod.Evans@Sun.COM 	if (tag == CA_SUNW_HW_1) {
37911827SRod.Evans@Sun.COM 		hwcap = &ofl->ofl_ocapset.oc_hw_1.cm_val;
38011827SRod.Evans@Sun.COM 		flags1 = FLG_OF1_OVHWCAP1;
38111827SRod.Evans@Sun.COM 	} else {
38211827SRod.Evans@Sun.COM 		hwcap = &ofl->ofl_ocapset.oc_hw_2.cm_val;
38311827SRod.Evans@Sun.COM 		flags1 = FLG_OF1_OVHWCAP2;
38411827SRod.Evans@Sun.COM 	}
38511827SRod.Evans@Sun.COM 
3860Sstevel@tonic-gate 	/*
38711827SRod.Evans@Sun.COM 	 * If a mapfile has established definitions to override any object
38811827SRod.Evans@Sun.COM 	 * capabilities, ignore any new object capabilities.
3890Sstevel@tonic-gate 	 */
39011827SRod.Evans@Sun.COM 	if (ofl->ofl_flags1 & flags1) {
39111827SRod.Evans@Sun.COM 		DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
39211827SRod.Evans@Sun.COM 		    tag, val, ld_targ.t_m.m_mach));
3930Sstevel@tonic-gate 		return;
3940Sstevel@tonic-gate 	}
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate 	/*
3970Sstevel@tonic-gate 	 * If this object doesn't specify any capabilities, ignore it, and
3980Sstevel@tonic-gate 	 * leave the state as is.
3990Sstevel@tonic-gate 	 */
4000Sstevel@tonic-gate 	if (val == 0)
4010Sstevel@tonic-gate 		return;
4020Sstevel@tonic-gate 
40311734SAli.Bahrami@Sun.COM 	if (DBG_ENABLED) {
40411827SRod.Evans@Sun.COM 		Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_CURRENT, CA_SUNW_HW_1,
40511827SRod.Evans@Sun.COM 		    ofl->ofl_ocapset.oc_hw_1.cm_val, ld_targ.t_m.m_mach);
40611827SRod.Evans@Sun.COM 		Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_NEW, CA_SUNW_HW_1,
40711827SRod.Evans@Sun.COM 		    val, ld_targ.t_m.m_mach);
40811827SRod.Evans@Sun.COM 	}
40911827SRod.Evans@Sun.COM 
41011827SRod.Evans@Sun.COM 	*hwcap |= val;
41111827SRod.Evans@Sun.COM 
41211827SRod.Evans@Sun.COM 	DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_RESOLVED, tag,
41311827SRod.Evans@Sun.COM 	    *hwcap, ld_targ.t_m.m_mach));
41411827SRod.Evans@Sun.COM }
41511827SRod.Evans@Sun.COM 
41611827SRod.Evans@Sun.COM /*
41711827SRod.Evans@Sun.COM  * Promote a machine capability or platform capability to the output file.
41811827SRod.Evans@Sun.COM  * Multiple instances of these names can be defined.
41911827SRod.Evans@Sun.COM  */
42011827SRod.Evans@Sun.COM static void
42111827SRod.Evans@Sun.COM str_cap(Ofl_desc *ofl, char *pstr, ofl_flag_t flags, Xword tag, Caplist *list)
42211827SRod.Evans@Sun.COM {
42311827SRod.Evans@Sun.COM 	Capstr		*capstr;
42411827SRod.Evans@Sun.COM 	Aliste		idx;
42511827SRod.Evans@Sun.COM 	Boolean		found = FALSE;
42611827SRod.Evans@Sun.COM 
42711827SRod.Evans@Sun.COM 	/*
42811827SRod.Evans@Sun.COM 	 * If a mapfile has established definitions to override this capability,
42911827SRod.Evans@Sun.COM 	 * ignore any new capability.
43011827SRod.Evans@Sun.COM 	 */
43111827SRod.Evans@Sun.COM 	if (ofl->ofl_flags1 & flags) {
43211827SRod.Evans@Sun.COM 		DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
43311827SRod.Evans@Sun.COM 		    tag, pstr));
43411827SRod.Evans@Sun.COM 		return;
43511827SRod.Evans@Sun.COM 	}
43611827SRod.Evans@Sun.COM 
43711827SRod.Evans@Sun.COM 	for (ALIST_TRAVERSE(list->cl_val, idx, capstr)) {
43811827SRod.Evans@Sun.COM 		DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
43911827SRod.Evans@Sun.COM 		    DBG_STATE_CURRENT, tag, capstr->cs_str));
44011827SRod.Evans@Sun.COM 		if (strcmp(capstr->cs_str, pstr) == 0)
44111827SRod.Evans@Sun.COM 			found = TRUE;
44211827SRod.Evans@Sun.COM 	}
44311827SRod.Evans@Sun.COM 
44411827SRod.Evans@Sun.COM 	DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_NEW, tag, pstr));
44511827SRod.Evans@Sun.COM 
44611827SRod.Evans@Sun.COM 	if (found == FALSE) {
44711827SRod.Evans@Sun.COM 		if ((capstr = alist_append(&list->cl_val, NULL,
44811827SRod.Evans@Sun.COM 		    sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL) {
44911827SRod.Evans@Sun.COM 			ofl->ofl_flags |= FLG_OF_FATAL;
45011827SRod.Evans@Sun.COM 			return;
45111827SRod.Evans@Sun.COM 		}
45211827SRod.Evans@Sun.COM 		capstr->cs_str = pstr;
45311827SRod.Evans@Sun.COM 	}
45411827SRod.Evans@Sun.COM 
45511827SRod.Evans@Sun.COM 	if (DBG_ENABLED) {
45611827SRod.Evans@Sun.COM 		for (ALIST_TRAVERSE(list->cl_val, idx, capstr)) {
45711827SRod.Evans@Sun.COM 			DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
45811827SRod.Evans@Sun.COM 			    DBG_STATE_RESOLVED, tag, capstr->cs_str));
45911827SRod.Evans@Sun.COM 		}
46011734SAli.Bahrami@Sun.COM 	}
46111827SRod.Evans@Sun.COM }
46211827SRod.Evans@Sun.COM 
46311827SRod.Evans@Sun.COM /*
46411827SRod.Evans@Sun.COM  * Promote a capability identifier to the output file.  A capability group can
46511827SRod.Evans@Sun.COM  * only have one identifier, and thus only the first identifier seen from any
46611827SRod.Evans@Sun.COM  * input relocatable objects is retained.  An explicit user defined identifier,
46711827SRod.Evans@Sun.COM  * rather than an an identifier fabricated by ld(1) with -z symbcap processing,
46811827SRod.Evans@Sun.COM  * takes precedence.  Note, a user may have defined an identifier via a mapfile,
46911827SRod.Evans@Sun.COM  * in which case the mapfile identifier is retained.
47011827SRod.Evans@Sun.COM  */
47111827SRod.Evans@Sun.COM static void
47211827SRod.Evans@Sun.COM id_cap(Ofl_desc *ofl, char *pstr, oc_flag_t flags)
47311827SRod.Evans@Sun.COM {
47411827SRod.Evans@Sun.COM 	Objcapset	*ocapset = &ofl->ofl_ocapset;
47511827SRod.Evans@Sun.COM 
47611827SRod.Evans@Sun.COM 	if (ocapset->oc_id.cs_str) {
47711827SRod.Evans@Sun.COM 		DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_CURRENT,
47811827SRod.Evans@Sun.COM 		    CA_SUNW_ID, ocapset->oc_id.cs_str));
47911827SRod.Evans@Sun.COM 
48011827SRod.Evans@Sun.COM 		if ((ocapset->oc_flags & FLG_OCS_USRDEFID) ||
48111827SRod.Evans@Sun.COM 		    ((flags & FLG_OCS_USRDEFID) == 0)) {
48211827SRod.Evans@Sun.COM 			DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
48311827SRod.Evans@Sun.COM 			    DBG_STATE_IGNORED, CA_SUNW_ID, pstr));
48411827SRod.Evans@Sun.COM 			return;
48511827SRod.Evans@Sun.COM 		}
48611827SRod.Evans@Sun.COM 	}
48711827SRod.Evans@Sun.COM 
48811827SRod.Evans@Sun.COM 	DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_NEW,
48911827SRod.Evans@Sun.COM 	    CA_SUNW_ID, pstr));
49011827SRod.Evans@Sun.COM 
49111827SRod.Evans@Sun.COM 	ocapset->oc_id.cs_str = pstr;
49211827SRod.Evans@Sun.COM 	ocapset->oc_flags |= flags;
49311827SRod.Evans@Sun.COM 
49411827SRod.Evans@Sun.COM 	DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_RESOLVED,
49511827SRod.Evans@Sun.COM 	    CA_SUNW_ID, pstr));
49611827SRod.Evans@Sun.COM }
49711827SRod.Evans@Sun.COM 
49811827SRod.Evans@Sun.COM /*
49911827SRod.Evans@Sun.COM  * Promote a capabilities group to the object capabilities.  This catches a
50011827SRod.Evans@Sun.COM  * corner case.  An object capabilities file can be converted to symbol
50111827SRod.Evans@Sun.COM  * capabilities with -z symbolcap.  However, if the user has indicated that all
50211827SRod.Evans@Sun.COM  * the symbols should be demoted, we'd be left with a symbol capabilities file,
50311827SRod.Evans@Sun.COM  * with no associated symbols.  Catch this case by promoting the symbol
50411827SRod.Evans@Sun.COM  * capabilities back to object capabilities.
50511827SRod.Evans@Sun.COM  */
50611827SRod.Evans@Sun.COM void
50711827SRod.Evans@Sun.COM ld_cap_move_symtoobj(Ofl_desc *ofl)
50811827SRod.Evans@Sun.COM {
50911827SRod.Evans@Sun.COM 	Cap_group	*cgp;
51011827SRod.Evans@Sun.COM 	Aliste		idx1;
51111827SRod.Evans@Sun.COM 
51211827SRod.Evans@Sun.COM 	for (APLIST_TRAVERSE(ofl->ofl_capgroups, idx1, cgp)) {
51311827SRod.Evans@Sun.COM 		Objcapset	*scapset = &cgp->cg_set;
51411827SRod.Evans@Sun.COM 		Capstr		*capstr;
51511827SRod.Evans@Sun.COM 		Aliste		idx2;
51611827SRod.Evans@Sun.COM 
51711827SRod.Evans@Sun.COM 		if (scapset->oc_id.cs_str) {
51811827SRod.Evans@Sun.COM 			if (scapset->oc_flags & FLG_OCS_USRDEFID)
51911827SRod.Evans@Sun.COM 				id_cap(ofl, scapset->oc_id.cs_str,
52011827SRod.Evans@Sun.COM 				    scapset->oc_flags);
52111827SRod.Evans@Sun.COM 		}
52211827SRod.Evans@Sun.COM 		if (scapset->oc_plat.cl_val) {
52311827SRod.Evans@Sun.COM 			for (ALIST_TRAVERSE(scapset->oc_plat.cl_val, idx2,
52411827SRod.Evans@Sun.COM 			    capstr)) {
52511827SRod.Evans@Sun.COM 				str_cap(ofl, capstr->cs_str, FLG_OF1_OVPLATCAP,
52611827SRod.Evans@Sun.COM 				    CA_SUNW_PLAT, &ofl->ofl_ocapset.oc_plat);
52711827SRod.Evans@Sun.COM 			}
52811827SRod.Evans@Sun.COM 		}
52911827SRod.Evans@Sun.COM 		if (scapset->oc_mach.cl_val) {
53011827SRod.Evans@Sun.COM 			for (ALIST_TRAVERSE(scapset->oc_mach.cl_val, idx2,
53111827SRod.Evans@Sun.COM 			    capstr)) {
53211827SRod.Evans@Sun.COM 				str_cap(ofl, capstr->cs_str, FLG_OF1_OVMACHCAP,
53311827SRod.Evans@Sun.COM 				    CA_SUNW_MACH, &ofl->ofl_ocapset.oc_mach);
53411827SRod.Evans@Sun.COM 			}
53511827SRod.Evans@Sun.COM 		}
53611827SRod.Evans@Sun.COM 		if (scapset->oc_hw_2.cm_val)
53711827SRod.Evans@Sun.COM 			hw_cap(ofl, CA_SUNW_HW_2, scapset->oc_hw_2.cm_val);
53811827SRod.Evans@Sun.COM 
53911827SRod.Evans@Sun.COM 		if (scapset->oc_hw_1.cm_val)
54011827SRod.Evans@Sun.COM 			hw_cap(ofl, CA_SUNW_HW_1, scapset->oc_hw_1.cm_val);
54111827SRod.Evans@Sun.COM 
54211827SRod.Evans@Sun.COM 		if (scapset->oc_sf_1.cm_val)
54311827SRod.Evans@Sun.COM 			sf1_cap(ofl, scapset->oc_sf_1.cm_val, NULL, NULL);
54411827SRod.Evans@Sun.COM 	}
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate /*
54811827SRod.Evans@Sun.COM  * Determine whether a capabilities group already exists that describes this
54911827SRod.Evans@Sun.COM  * new capabilities group.
55011827SRod.Evans@Sun.COM  *
55111827SRod.Evans@Sun.COM  * Note, a capability group identifier, CA_SUNW_ID, isn't used as part of the
55211827SRod.Evans@Sun.COM  * comparison.  This attribute simply assigns a diagnostic name to the group,
55311827SRod.Evans@Sun.COM  * and in the case of multiple identifiers, the first will be taken.
5540Sstevel@tonic-gate  */
55511827SRod.Evans@Sun.COM static Cap_group *
55611827SRod.Evans@Sun.COM get_cap_group(Objcapset *ocapset, Word cnum, Ofl_desc *ofl, Is_desc *isp)
5570Sstevel@tonic-gate {
55811827SRod.Evans@Sun.COM 	Aliste		idx;
55911827SRod.Evans@Sun.COM 	Cap_group	*cgp;
56011827SRod.Evans@Sun.COM 	Word		ccnum = cnum;
56111827SRod.Evans@Sun.COM 
56211827SRod.Evans@Sun.COM 	/*
56311827SRod.Evans@Sun.COM 	 * If the new capabilities contains a CA_SUNW_ID, drop the count of the
56411827SRod.Evans@Sun.COM 	 * number of comparable items.
56511827SRod.Evans@Sun.COM 	 */
56611827SRod.Evans@Sun.COM 	if (ocapset->oc_id.cs_str)
56711827SRod.Evans@Sun.COM 		ccnum--;
56811827SRod.Evans@Sun.COM 
56911827SRod.Evans@Sun.COM 	/*
57011827SRod.Evans@Sun.COM 	 * Traverse the existing symbols capabilities groups.
57111827SRod.Evans@Sun.COM 	 */
57211827SRod.Evans@Sun.COM 	for (APLIST_TRAVERSE(ofl->ofl_capgroups, idx, cgp)) {
57311827SRod.Evans@Sun.COM 		Word	onum = cgp->cg_num;
57411827SRod.Evans@Sun.COM 		Alist	*calp, *oalp;
57511827SRod.Evans@Sun.COM 
57611827SRod.Evans@Sun.COM 		if (cgp->cg_set.oc_id.cs_str)
57711827SRod.Evans@Sun.COM 			onum--;
57811827SRod.Evans@Sun.COM 
57911827SRod.Evans@Sun.COM 		if (onum != ccnum)
58011827SRod.Evans@Sun.COM 			continue;
58111827SRod.Evans@Sun.COM 
58211827SRod.Evans@Sun.COM 		if (cgp->cg_set.oc_hw_1.cm_val != ocapset->oc_hw_1.cm_val)
58311827SRod.Evans@Sun.COM 			continue;
58411827SRod.Evans@Sun.COM 		if (cgp->cg_set.oc_sf_1.cm_val != ocapset->oc_sf_1.cm_val)
58511827SRod.Evans@Sun.COM 			continue;
58611827SRod.Evans@Sun.COM 		if (cgp->cg_set.oc_hw_2.cm_val != ocapset->oc_hw_2.cm_val)
58711827SRod.Evans@Sun.COM 			continue;
58811827SRod.Evans@Sun.COM 
58911827SRod.Evans@Sun.COM 		calp = cgp->cg_set.oc_plat.cl_val;
59011827SRod.Evans@Sun.COM 		oalp = ocapset->oc_plat.cl_val;
59111827SRod.Evans@Sun.COM 		if ((calp == NULL) && oalp)
59211827SRod.Evans@Sun.COM 			continue;
59311827SRod.Evans@Sun.COM 		if (calp && ((oalp == NULL) || cap_names_match(calp, oalp)))
59411827SRod.Evans@Sun.COM 			continue;
59511827SRod.Evans@Sun.COM 
59611827SRod.Evans@Sun.COM 		calp = cgp->cg_set.oc_mach.cl_val;
59711827SRod.Evans@Sun.COM 		oalp = ocapset->oc_mach.cl_val;
59811827SRod.Evans@Sun.COM 		if ((calp == NULL) && oalp)
59911827SRod.Evans@Sun.COM 			continue;
60011827SRod.Evans@Sun.COM 		if (calp && ((oalp == NULL) || cap_names_match(calp, oalp)))
60111827SRod.Evans@Sun.COM 			continue;
60211827SRod.Evans@Sun.COM 
60311827SRod.Evans@Sun.COM 		/*
60411827SRod.Evans@Sun.COM 		 * If a matching group is found, then this new group has
60511827SRod.Evans@Sun.COM 		 * already been supplied by a previous file, and hence the
60611827SRod.Evans@Sun.COM 		 * existing group can be used.  Record this new input section,
60711827SRod.Evans@Sun.COM 		 * from which we can also derive the input file name, on the
60811827SRod.Evans@Sun.COM 		 * existing groups input sections.
60911827SRod.Evans@Sun.COM 		 */
61011827SRod.Evans@Sun.COM 		if (aplist_append(&(cgp->cg_secs), isp,
61111827SRod.Evans@Sun.COM 		    AL_CNT_CAP_SECS) == NULL)
61211827SRod.Evans@Sun.COM 			return (NULL);
61311827SRod.Evans@Sun.COM 		return (cgp);
61411827SRod.Evans@Sun.COM 	}
61511827SRod.Evans@Sun.COM 
61611827SRod.Evans@Sun.COM 	/*
61711827SRod.Evans@Sun.COM 	 * If a capabilities group is not found, create a new one.
61811827SRod.Evans@Sun.COM 	 */
61911827SRod.Evans@Sun.COM 	if (((cgp = libld_calloc(sizeof (Cap_group), 1)) == NULL) ||
62011827SRod.Evans@Sun.COM 	    (aplist_append(&(ofl->ofl_capgroups), cgp,
62111827SRod.Evans@Sun.COM 	    AL_CNT_CAP_DESCS) == NULL))
62211827SRod.Evans@Sun.COM 		return (NULL);
62311827SRod.Evans@Sun.COM 
62411827SRod.Evans@Sun.COM 	/*
62511827SRod.Evans@Sun.COM 	 * If we're converting object capabilities to symbol capabilities and
62611827SRod.Evans@Sun.COM 	 * no CA_SUNW_ID is defined, fabricate one.  This identifier is appended
62711827SRod.Evans@Sun.COM 	 * to all symbol names that are converted into capabilities symbols,
62811827SRod.Evans@Sun.COM 	 * see ld_sym_process().
62911827SRod.Evans@Sun.COM 	 */
63011827SRod.Evans@Sun.COM 	if ((isp->is_file->ifl_flags & FLG_IF_OTOSCAP) &&
63111827SRod.Evans@Sun.COM 	    (ocapset->oc_id.cs_str == NULL)) {
63211827SRod.Evans@Sun.COM 		size_t	len;
63311827SRod.Evans@Sun.COM 
63411827SRod.Evans@Sun.COM 		/*
63511827SRod.Evans@Sun.COM 		 * Create an identifier using the group number together with a
63611827SRod.Evans@Sun.COM 		 * default template.  We allocate a buffer large enough for any
63711827SRod.Evans@Sun.COM 		 * possible number of items (way more than we need).
63811827SRod.Evans@Sun.COM 		 */
63911827SRod.Evans@Sun.COM 		len = MSG_STR_CAPGROUPID_SIZE + CONV_INV_BUFSIZE;
64011827SRod.Evans@Sun.COM 		if ((ocapset->oc_id.cs_str = libld_malloc(len)) == NULL)
64111827SRod.Evans@Sun.COM 			return (NULL);
64211827SRod.Evans@Sun.COM 
64311827SRod.Evans@Sun.COM 		(void) snprintf(ocapset->oc_id.cs_str, len,
64411827SRod.Evans@Sun.COM 		    MSG_ORIG(MSG_STR_CAPGROUPID),
64511827SRod.Evans@Sun.COM 		    aplist_nitems(ofl->ofl_capgroups));
64611827SRod.Evans@Sun.COM 		cnum++;
64711827SRod.Evans@Sun.COM 	}
64811827SRod.Evans@Sun.COM 
64911827SRod.Evans@Sun.COM 	cgp->cg_set = *ocapset;
65011827SRod.Evans@Sun.COM 	cgp->cg_num = cnum;
65111827SRod.Evans@Sun.COM 
65211827SRod.Evans@Sun.COM 	/*
65311827SRod.Evans@Sun.COM 	 * Null the callers alist's as they've effectively been transferred
65411827SRod.Evans@Sun.COM 	 * to this new Cap_group.
65511827SRod.Evans@Sun.COM 	 */
65611827SRod.Evans@Sun.COM 	ocapset->oc_plat.cl_val = ocapset->oc_mach.cl_val = NULL;
65711827SRod.Evans@Sun.COM 
65811827SRod.Evans@Sun.COM 	/*
65911827SRod.Evans@Sun.COM 	 * Keep track of which input section, and hence input file, established
66011827SRod.Evans@Sun.COM 	 * this group.
66111827SRod.Evans@Sun.COM 	 */
66211827SRod.Evans@Sun.COM 	if (aplist_append(&(cgp->cg_secs), isp, AL_CNT_CAP_SECS) == NULL)
66311827SRod.Evans@Sun.COM 		return (NULL);
66411827SRod.Evans@Sun.COM 
66511827SRod.Evans@Sun.COM 	/*
66611827SRod.Evans@Sun.COM 	 * Keep track of the number of symbol capabilities entries that will be
66711827SRod.Evans@Sun.COM 	 * required in the output file.  Each group requires a terminating
66811827SRod.Evans@Sun.COM 	 * CA_SUNW_NULL.
66911827SRod.Evans@Sun.COM 	 */
67011827SRod.Evans@Sun.COM 	ofl->ofl_capsymcnt += (cnum + 1);
67111827SRod.Evans@Sun.COM 	return (cgp);
67211827SRod.Evans@Sun.COM }
67311827SRod.Evans@Sun.COM 
67411827SRod.Evans@Sun.COM /*
67511827SRod.Evans@Sun.COM  * Capture symbol capability family information.  This data structure is focal
67611827SRod.Evans@Sun.COM  * in maintaining all symbol capability relationships, and provides for the
67711827SRod.Evans@Sun.COM  * eventual creation of a capabilities information section, and possibly a
67811827SRod.Evans@Sun.COM  * capabilities chain section.
67911827SRod.Evans@Sun.COM  *
68011827SRod.Evans@Sun.COM  * Capabilities families are lead by a CAPINFO_SUNW_GLOB symbol.  This symbol
68111827SRod.Evans@Sun.COM  * provides the visible global symbol that is referenced by all external
68211827SRod.Evans@Sun.COM  * callers.  This symbol may have aliases.  For example, a weak/global symbol
68311827SRod.Evans@Sun.COM  * pair, such as memcpy()/_memcpy() may lead the same capabilities family.
68411827SRod.Evans@Sun.COM  * Each family contains one or more local symbol members.  These members provide
68511827SRod.Evans@Sun.COM  * the capabilities specific functions, and are associated to a capabilities
68611827SRod.Evans@Sun.COM  * group.  For example, the capability members memcpy%sun4u and memcpy%sun4v
68711827SRod.Evans@Sun.COM  * might be associated with the memcpy() capability family.
68811827SRod.Evans@Sun.COM  *
68911827SRod.Evans@Sun.COM  * This routine is called when a relocatable object that provides object
69011827SRod.Evans@Sun.COM  * capabilities is transformed into a symbol capabilities object, using the
69111827SRod.Evans@Sun.COM  * -z symbolcap option.
69211827SRod.Evans@Sun.COM  *
69311827SRod.Evans@Sun.COM  * This routine is also called to collect the SUNW_capinfo section information
69411827SRod.Evans@Sun.COM  * of a relocatable object that contains symbol capability definitions.
69511827SRod.Evans@Sun.COM  */
69611827SRod.Evans@Sun.COM uintptr_t
69711827SRod.Evans@Sun.COM ld_cap_add_family(Ofl_desc *ofl, Sym_desc *lsdp, Sym_desc *csdp, Cap_group *cgp,
69811827SRod.Evans@Sun.COM     APlist **csyms)
69911827SRod.Evans@Sun.COM {
70011827SRod.Evans@Sun.COM 	Cap_avlnode	qcav, *cav;
70111827SRod.Evans@Sun.COM 	avl_tree_t	*avlt;
70211827SRod.Evans@Sun.COM 	avl_index_t	where = 0;
70311827SRod.Evans@Sun.COM 	Cap_sym		*mcsp;
70411827SRod.Evans@Sun.COM 	Aliste		idx;
70511827SRod.Evans@Sun.COM 
70611827SRod.Evans@Sun.COM 	/*
70711827SRod.Evans@Sun.COM 	 * Make sure the capability families have an initialized AVL tree.
70811827SRod.Evans@Sun.COM 	 */
70911827SRod.Evans@Sun.COM 	if ((avlt = ofl->ofl_capfamilies) == NULL) {
71011827SRod.Evans@Sun.COM 		if ((avlt = libld_calloc(sizeof (avl_tree_t), 1)) == NULL)
71111827SRod.Evans@Sun.COM 			return (S_ERROR);
71211827SRod.Evans@Sun.COM 		avl_create(avlt, &ld_sym_avl_comp, sizeof (Cap_avlnode),
71311827SRod.Evans@Sun.COM 		    SGSOFFSETOF(Cap_avlnode, cn_symavlnode.sav_node));
71411827SRod.Evans@Sun.COM 		ofl->ofl_capfamilies = avlt;
71511827SRod.Evans@Sun.COM 
71611827SRod.Evans@Sun.COM 		/*
71711827SRod.Evans@Sun.COM 		 * When creating a dynamic object, capability family members
71811827SRod.Evans@Sun.COM 		 * are maintained in a .SUNW_capchain, the first entry of
71911827SRod.Evans@Sun.COM 		 * which is the version number of the chain.
72011827SRod.Evans@Sun.COM 		 */
72111827SRod.Evans@Sun.COM 		ofl->ofl_capchaincnt = 1;
72211827SRod.Evans@Sun.COM 	}
72311827SRod.Evans@Sun.COM 
72411827SRod.Evans@Sun.COM 	/*
72511827SRod.Evans@Sun.COM 	 * Determine whether a family already exists, and if not, create one
72611827SRod.Evans@Sun.COM 	 * using the lead family symbol.
72711827SRod.Evans@Sun.COM 	 */
72811827SRod.Evans@Sun.COM 	qcav.cn_symavlnode.sav_hash = (Word)elf_hash(lsdp->sd_name);
72911827SRod.Evans@Sun.COM 	qcav.cn_symavlnode.sav_name = lsdp->sd_name;
73011827SRod.Evans@Sun.COM 
73111827SRod.Evans@Sun.COM 	if ((cav = avl_find(avlt, &qcav, &where)) == NULL) {
73211827SRod.Evans@Sun.COM 		if ((cav = libld_calloc(sizeof (Cap_avlnode), 1)) == NULL)
73311827SRod.Evans@Sun.COM 			return (S_ERROR);
73411827SRod.Evans@Sun.COM 		cav->cn_symavlnode.sav_hash = qcav.cn_symavlnode.sav_hash;
73511827SRod.Evans@Sun.COM 		cav->cn_symavlnode.sav_name = qcav.cn_symavlnode.sav_name;
73611827SRod.Evans@Sun.COM 		cav->cn_symavlnode.sav_sdp = lsdp;
73711827SRod.Evans@Sun.COM 
73811827SRod.Evans@Sun.COM 		avl_insert(avlt, cav, where);
73911827SRod.Evans@Sun.COM 
74011827SRod.Evans@Sun.COM 		/*
74111827SRod.Evans@Sun.COM 		 * When creating a dynamic object, capability family members
74211827SRod.Evans@Sun.COM 		 * are maintained in a .SUNW_capchain, each family starts with
74311827SRod.Evans@Sun.COM 		 * this lead symbol, and is terminated with a 0 element.
74411827SRod.Evans@Sun.COM 		 */
74511827SRod.Evans@Sun.COM 		ofl->ofl_capchaincnt += 2;
74611827SRod.Evans@Sun.COM 	}
74711827SRod.Evans@Sun.COM 
74811827SRod.Evans@Sun.COM 	/*
74911827SRod.Evans@Sun.COM 	 * If no group information is provided then this request is to add a
75011827SRod.Evans@Sun.COM 	 * lead capability symbol, or lead symbol alias.  If this is the lead
75111827SRod.Evans@Sun.COM 	 * symbol there's nothing more to do.  Otherwise save the alias.
75211827SRod.Evans@Sun.COM 	 */
75311827SRod.Evans@Sun.COM 	if (cgp == NULL) {
75411827SRod.Evans@Sun.COM 		if ((lsdp != csdp) && (aplist_append(&cav->cn_aliases, csdp,
75511827SRod.Evans@Sun.COM 		    AL_CNT_CAP_ALIASES) == NULL))
75611827SRod.Evans@Sun.COM 			return (S_ERROR);
75711827SRod.Evans@Sun.COM 
75811827SRod.Evans@Sun.COM 		return (0);
75911827SRod.Evans@Sun.COM 	}
76011827SRod.Evans@Sun.COM 
76111827SRod.Evans@Sun.COM 	/*
76211827SRod.Evans@Sun.COM 	 * Determine whether a member of the same group as this new member is
76311827SRod.Evans@Sun.COM 	 * already defined within this family.  If so, we have a multiply
76411827SRod.Evans@Sun.COM 	 * defined symbol.
76511827SRod.Evans@Sun.COM 	 */
76611827SRod.Evans@Sun.COM 	for (APLIST_TRAVERSE(cav->cn_members, idx, mcsp)) {
76711827SRod.Evans@Sun.COM 		Sym_desc	*msdp;
76811827SRod.Evans@Sun.COM 
76911827SRod.Evans@Sun.COM 		if (cgp != mcsp->cs_group)
77011827SRod.Evans@Sun.COM 			continue;
77111827SRod.Evans@Sun.COM 
77211827SRod.Evans@Sun.COM 		/*
77311827SRod.Evans@Sun.COM 		 * Diagnose that a multiple symbol definition exists.
77411827SRod.Evans@Sun.COM 		 */
77511827SRod.Evans@Sun.COM 		msdp = mcsp->cs_sdp;
77611827SRod.Evans@Sun.COM 
77711827SRod.Evans@Sun.COM 		eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_CAP_MULDEF),
77811827SRod.Evans@Sun.COM 		    demangle(lsdp->sd_name));
77911827SRod.Evans@Sun.COM 		eprintf(ofl->ofl_lml, ERR_NONE, MSG_INTL(MSG_CAP_MULDEFSYMS),
78011827SRod.Evans@Sun.COM 		    msdp->sd_file->ifl_name, msdp->sd_name,
78111827SRod.Evans@Sun.COM 		    csdp->sd_file->ifl_name, csdp->sd_name);
78211827SRod.Evans@Sun.COM 		ofl->ofl_flags |= FLG_OF_FATAL;
78311827SRod.Evans@Sun.COM 	}
78411827SRod.Evans@Sun.COM 
78511827SRod.Evans@Sun.COM 	/*
78611827SRod.Evans@Sun.COM 	 * Add this capabilities symbol member to the family.
78711827SRod.Evans@Sun.COM 	 */
78811827SRod.Evans@Sun.COM 	if (((mcsp = libld_malloc(sizeof (Cap_sym))) == NULL) ||
78911827SRod.Evans@Sun.COM 	    (aplist_append(&cav->cn_members, mcsp, AL_CNT_CAP_MEMS) == NULL))
79011827SRod.Evans@Sun.COM 		return (S_ERROR);
79111827SRod.Evans@Sun.COM 
79211827SRod.Evans@Sun.COM 	mcsp->cs_sdp = csdp;
79311827SRod.Evans@Sun.COM 	mcsp->cs_group = cgp;
79411827SRod.Evans@Sun.COM 
79511827SRod.Evans@Sun.COM 	/*
79611827SRod.Evans@Sun.COM 	 * When creating a dynamic object, capability family members are
79711827SRod.Evans@Sun.COM 	 * maintained in a .SUNW_capchain.  Account for this family member.
79811827SRod.Evans@Sun.COM 	 */
79911827SRod.Evans@Sun.COM 	ofl->ofl_capchaincnt++;
80011827SRod.Evans@Sun.COM 
80111827SRod.Evans@Sun.COM 	/*
80211827SRod.Evans@Sun.COM 	 * If this input file is undergoing object capabilities to symbol
80311827SRod.Evans@Sun.COM 	 * capabilities conversion, then this member is a new local symbol
80411827SRod.Evans@Sun.COM 	 * that has been generated from an original global symbol.  Keep track
80511827SRod.Evans@Sun.COM 	 * of this symbol so that the output file symbol table can be populated
80611827SRod.Evans@Sun.COM 	 * with these new symbol entries.
80711827SRod.Evans@Sun.COM 	 */
80811827SRod.Evans@Sun.COM 	if (csyms && (aplist_append(csyms, mcsp, AL_CNT_CAP_SYMS) == NULL))
80911827SRod.Evans@Sun.COM 		return (S_ERROR);
81011827SRod.Evans@Sun.COM 
81111827SRod.Evans@Sun.COM 	return (0);
81211827SRod.Evans@Sun.COM }
81311827SRod.Evans@Sun.COM 
81411827SRod.Evans@Sun.COM /*
81511827SRod.Evans@Sun.COM  * Process a SHT_SUNW_cap capabilities section.
81611827SRod.Evans@Sun.COM  */
81711827SRod.Evans@Sun.COM static uintptr_t
81811827SRod.Evans@Sun.COM process_cap(Ofl_desc *ofl, Ifl_desc *ifl, Is_desc *cisp)
81911827SRod.Evans@Sun.COM {
82011827SRod.Evans@Sun.COM 	Objcapset	ocapset = { 0 };
82111827SRod.Evans@Sun.COM 	Cap_desc	*cdp;
82211827SRod.Evans@Sun.COM 	Cap		*data, *cdata;
82311827SRod.Evans@Sun.COM 	char		*strs;
82411827SRod.Evans@Sun.COM 	Word		ndx, cnum;
82511827SRod.Evans@Sun.COM 	int		objcapndx, descapndx, symcapndx;
82611827SRod.Evans@Sun.COM 	int		nulls, capstrs = 0;
82711827SRod.Evans@Sun.COM 
82811827SRod.Evans@Sun.COM 	/*
82911827SRod.Evans@Sun.COM 	 * Determine the capabilities data and size.
83011827SRod.Evans@Sun.COM 	 */
83111827SRod.Evans@Sun.COM 	cdata = (Cap *)cisp->is_indata->d_buf;
83211827SRod.Evans@Sun.COM 	cnum = (Word)(cisp->is_shdr->sh_size / cisp->is_shdr->sh_entsize);
83311827SRod.Evans@Sun.COM 
83411827SRod.Evans@Sun.COM 	if ((cdata == NULL) || (cnum == 0))
83511827SRod.Evans@Sun.COM 		return (0);
8360Sstevel@tonic-gate 
8378501SRod.Evans@Sun.COM 	DBG_CALL(Dbg_cap_sec_title(ofl->ofl_lml, ifl->ifl_name));
8380Sstevel@tonic-gate 
8393617Srie 	/*
84011827SRod.Evans@Sun.COM 	 * Traverse the section to determine what capabilities groups are
84111827SRod.Evans@Sun.COM 	 * available.
84211827SRod.Evans@Sun.COM 	 *
84311827SRod.Evans@Sun.COM 	 * A capabilities section can contain one or more, CA_SUNW_NULL
84411827SRod.Evans@Sun.COM 	 * terminated groups.
84511827SRod.Evans@Sun.COM 	 *
84611827SRod.Evans@Sun.COM 	 *  -	The first group defines the object capabilities.
84711827SRod.Evans@Sun.COM 	 *  -	Additional groups define symbol capabilities.
84811827SRod.Evans@Sun.COM 	 *  -	Since the initial group is always reserved for object
84911827SRod.Evans@Sun.COM 	 *	capabilities, any object with symbol capabilities must also
85011827SRod.Evans@Sun.COM 	 *	have an object capabilities group.  If the object has no object
85111827SRod.Evans@Sun.COM 	 *	capabilities, an empty object group is defined, consisting of a
85211827SRod.Evans@Sun.COM 	 *	CA_SUNW_NULL element in index [0].
85311827SRod.Evans@Sun.COM 	 *  -	If any capabilities require references to a named string, then
85411827SRod.Evans@Sun.COM 	 *	the section header sh_info points to the associated string
85511827SRod.Evans@Sun.COM 	 *	table.
85611827SRod.Evans@Sun.COM 	 *  -	If an object contains symbol capability groups, then the
85711827SRod.Evans@Sun.COM 	 *	section header sh_link points to the associated capinfo table.
8583617Srie 	 */
85911827SRod.Evans@Sun.COM 	objcapndx = 0;
86011827SRod.Evans@Sun.COM 	descapndx = symcapndx = -1;
86111827SRod.Evans@Sun.COM 	nulls = 0;
86211827SRod.Evans@Sun.COM 
86311827SRod.Evans@Sun.COM 	for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
86411827SRod.Evans@Sun.COM 		switch (data->c_tag) {
86511827SRod.Evans@Sun.COM 		case CA_SUNW_NULL:
86611827SRod.Evans@Sun.COM 			/*
86711827SRod.Evans@Sun.COM 			 * If this is the first CA_SUNW_NULL entry, and no
86811827SRod.Evans@Sun.COM 			 * capabilities group has been found, then this object
86911827SRod.Evans@Sun.COM 			 * does not define any object capabilities.
87011827SRod.Evans@Sun.COM 			 */
87111827SRod.Evans@Sun.COM 			if (nulls++ == 0) {
87211827SRod.Evans@Sun.COM 				if (ndx == 0)
87311827SRod.Evans@Sun.COM 					objcapndx = -1;
87411827SRod.Evans@Sun.COM 			} else if ((symcapndx == -1) && (descapndx != -1))
87511827SRod.Evans@Sun.COM 				symcapndx = descapndx;
87611827SRod.Evans@Sun.COM 
87711827SRod.Evans@Sun.COM 			break;
87811827SRod.Evans@Sun.COM 
87911827SRod.Evans@Sun.COM 		case CA_SUNW_PLAT:
88011827SRod.Evans@Sun.COM 		case CA_SUNW_MACH:
88111827SRod.Evans@Sun.COM 		case CA_SUNW_ID:
88211827SRod.Evans@Sun.COM 			capstrs++;
88311827SRod.Evans@Sun.COM 			/* FALLTHROUGH */
88411827SRod.Evans@Sun.COM 
88511827SRod.Evans@Sun.COM 		case CA_SUNW_HW_1:
88611827SRod.Evans@Sun.COM 		case CA_SUNW_SF_1:
88711827SRod.Evans@Sun.COM 		case CA_SUNW_HW_2:
88811827SRod.Evans@Sun.COM 			/*
88911827SRod.Evans@Sun.COM 			 * If this is the start of a new group, save it.
89011827SRod.Evans@Sun.COM 			 */
89111827SRod.Evans@Sun.COM 			if (descapndx == -1)
89211827SRod.Evans@Sun.COM 				descapndx = ndx;
89311827SRod.Evans@Sun.COM 			break;
89411827SRod.Evans@Sun.COM 
89511827SRod.Evans@Sun.COM 		default:
89611827SRod.Evans@Sun.COM 			eprintf(ofl->ofl_lml, ERR_WARNING,
89711827SRod.Evans@Sun.COM 			    MSG_INTL(MSG_FIL_UNKCAP), ifl->ifl_name,
89811827SRod.Evans@Sun.COM 			    EC_WORD(cisp->is_scnndx), cisp->is_name,
89911827SRod.Evans@Sun.COM 			    data->c_tag);
9000Sstevel@tonic-gate 		}
9010Sstevel@tonic-gate 	}
90211827SRod.Evans@Sun.COM 
90311827SRod.Evans@Sun.COM 	/*
90411827SRod.Evans@Sun.COM 	 * If a string capabilities entry has been found, the capabilities
90511827SRod.Evans@Sun.COM 	 * section must reference the associated string table.
90611827SRod.Evans@Sun.COM 	 */
90711827SRod.Evans@Sun.COM 	if (capstrs) {
90811827SRod.Evans@Sun.COM 		Word	info = cisp->is_shdr->sh_info;
90911827SRod.Evans@Sun.COM 
91011827SRod.Evans@Sun.COM 		if ((info == 0) || (info > ifl->ifl_shnum)) {
91111827SRod.Evans@Sun.COM 			eprintf(ofl->ofl_lml, ERR_FATAL,
91211827SRod.Evans@Sun.COM 			    MSG_INTL(MSG_FIL_INVSHINFO), ifl->ifl_name,
91311827SRod.Evans@Sun.COM 			    EC_WORD(cisp->is_scnndx), cisp->is_name,
91411827SRod.Evans@Sun.COM 			    EC_XWORD(info));
91511827SRod.Evans@Sun.COM 			ofl->ofl_flags |= FLG_OF_FATAL;
91611827SRod.Evans@Sun.COM 			return (S_ERROR);
91711827SRod.Evans@Sun.COM 		}
91811827SRod.Evans@Sun.COM 		strs = (char *)ifl->ifl_isdesc[info]->is_indata->d_buf;
91911827SRod.Evans@Sun.COM 	}
92011827SRod.Evans@Sun.COM 
92111827SRod.Evans@Sun.COM 	/*
92211827SRod.Evans@Sun.COM 	 * The processing of capabilities groups is as follows:
92311827SRod.Evans@Sun.COM 	 *
92411827SRod.Evans@Sun.COM 	 *  -	if a relocatable object provides only object capabilities, and
92511827SRod.Evans@Sun.COM 	 *	the -z symbolcap option is in effect, then the object
92611827SRod.Evans@Sun.COM 	 *	capabilities are transformed into symbol capabilities and the
92711827SRod.Evans@Sun.COM 	 *	symbol capabilities are carried over to the output file.
92811827SRod.Evans@Sun.COM 	 *  -	in all other cases, any capabilities present in an input
92911827SRod.Evans@Sun.COM 	 *	relocatable object are carried from the input object to the
93011827SRod.Evans@Sun.COM 	 *	output without any transformation or conversion.
93111827SRod.Evans@Sun.COM 	 *
93211827SRod.Evans@Sun.COM 	 * Capture any object capabilities that are to be carried over to the
93311827SRod.Evans@Sun.COM 	 * output file.
93411827SRod.Evans@Sun.COM 	 */
93511827SRod.Evans@Sun.COM 	if ((objcapndx == 0) &&
93611827SRod.Evans@Sun.COM 	    ((symcapndx != -1) || ((ofl->ofl_flags & FLG_OF_OTOSCAP) == 0))) {
93711827SRod.Evans@Sun.COM 		for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
93811827SRod.Evans@Sun.COM 			/*
93911827SRod.Evans@Sun.COM 			 * Object capabilities end at the first null.
94011827SRod.Evans@Sun.COM 			 */
94111827SRod.Evans@Sun.COM 			if (data->c_tag == CA_SUNW_NULL)
94211827SRod.Evans@Sun.COM 				break;
94311827SRod.Evans@Sun.COM 
94411827SRod.Evans@Sun.COM 			/*
94511827SRod.Evans@Sun.COM 			 * Only the object software capabilities that are
94611827SRod.Evans@Sun.COM 			 * defined in a relocatable object become part of the
94711827SRod.Evans@Sun.COM 			 * object software capabilities in the output file.
94811827SRod.Evans@Sun.COM 			 * However, check the validity of any object software
94911827SRod.Evans@Sun.COM 			 * capabilities of any dependencies.
95011827SRod.Evans@Sun.COM 			 */
95111827SRod.Evans@Sun.COM 			if (data->c_tag == CA_SUNW_SF_1) {
95211827SRod.Evans@Sun.COM 				sf1_cap(ofl, data->c_un.c_val, ifl, cisp);
95311827SRod.Evans@Sun.COM 				continue;
95411827SRod.Evans@Sun.COM 			}
95511827SRod.Evans@Sun.COM 
95611827SRod.Evans@Sun.COM 			/*
95711827SRod.Evans@Sun.COM 			 * The remaining capability types must come from a
95811827SRod.Evans@Sun.COM 			 * relocatable object in order to contribute to the
95911827SRod.Evans@Sun.COM 			 * output.
96011827SRod.Evans@Sun.COM 			 */
96111827SRod.Evans@Sun.COM 			if (ifl->ifl_ehdr->e_type != ET_REL)
96211827SRod.Evans@Sun.COM 				continue;
96311827SRod.Evans@Sun.COM 
96411827SRod.Evans@Sun.COM 			switch (data->c_tag) {
96511827SRod.Evans@Sun.COM 			case CA_SUNW_HW_1:
96611827SRod.Evans@Sun.COM 			case CA_SUNW_HW_2:
96711827SRod.Evans@Sun.COM 				hw_cap(ofl, data->c_tag, data->c_un.c_val);
96811827SRod.Evans@Sun.COM 				break;
96911827SRod.Evans@Sun.COM 
97011827SRod.Evans@Sun.COM 			case CA_SUNW_PLAT:
97111827SRod.Evans@Sun.COM 				str_cap(ofl, strs + data->c_un.c_ptr,
97211827SRod.Evans@Sun.COM 				    FLG_OF1_OVPLATCAP, CA_SUNW_PLAT,
97311827SRod.Evans@Sun.COM 				    &ofl->ofl_ocapset.oc_plat);
97411827SRod.Evans@Sun.COM 				break;
97511827SRod.Evans@Sun.COM 
97611827SRod.Evans@Sun.COM 			case CA_SUNW_MACH:
97711827SRod.Evans@Sun.COM 				str_cap(ofl, strs + data->c_un.c_ptr,
97811827SRod.Evans@Sun.COM 				    FLG_OF1_OVMACHCAP, CA_SUNW_MACH,
97911827SRod.Evans@Sun.COM 				    &ofl->ofl_ocapset.oc_mach);
98011827SRod.Evans@Sun.COM 				break;
98111827SRod.Evans@Sun.COM 
98211827SRod.Evans@Sun.COM 			case CA_SUNW_ID:
98311827SRod.Evans@Sun.COM 				id_cap(ofl, strs + data->c_un.c_ptr,
98411827SRod.Evans@Sun.COM 				    FLG_OCS_USRDEFID);
98511827SRod.Evans@Sun.COM 				break;
98611827SRod.Evans@Sun.COM 
98711827SRod.Evans@Sun.COM 			default:
98811827SRod.Evans@Sun.COM 				assert(0);	/* Unknown capability type */
98911827SRod.Evans@Sun.COM 			}
99011827SRod.Evans@Sun.COM 		}
99111827SRod.Evans@Sun.COM 
99211827SRod.Evans@Sun.COM 		/*
99311827SRod.Evans@Sun.COM 		 * If there are no symbol capabilities, or this objects
99411827SRod.Evans@Sun.COM 		 * capabilities aren't being transformed into a symbol
99511827SRod.Evans@Sun.COM 		 * capabilities, then we're done.
99611827SRod.Evans@Sun.COM 		 */
99711827SRod.Evans@Sun.COM 		if ((symcapndx == -1) &&
99811827SRod.Evans@Sun.COM 		    ((ofl->ofl_flags & FLG_OF_OTOSCAP) == 0))
99911827SRod.Evans@Sun.COM 			return (1);
100011827SRod.Evans@Sun.COM 	}
100111827SRod.Evans@Sun.COM 
100211827SRod.Evans@Sun.COM 	/*
100311827SRod.Evans@Sun.COM 	 * If these capabilities don't originate from a relocatable object
100411827SRod.Evans@Sun.COM 	 * there's no further processing required.
100511827SRod.Evans@Sun.COM 	 */
100611827SRod.Evans@Sun.COM 	if (ifl->ifl_ehdr->e_type != ET_REL)
100711827SRod.Evans@Sun.COM 		return (1);
100811827SRod.Evans@Sun.COM 
100911827SRod.Evans@Sun.COM 	/*
101011827SRod.Evans@Sun.COM 	 * If this object only defines an object capabilities group, and the
101111827SRod.Evans@Sun.COM 	 * -z symbolcap option is in effect, then all global function symbols
101211827SRod.Evans@Sun.COM 	 * and initialized global data symbols are renamed and assigned to the
101311827SRod.Evans@Sun.COM 	 * transformed symbol capabilities group.
101411827SRod.Evans@Sun.COM 	 */
101511827SRod.Evans@Sun.COM 	if ((objcapndx == 0) &&
101611827SRod.Evans@Sun.COM 	    (symcapndx == -1) && (ofl->ofl_flags & FLG_OF_OTOSCAP))
101711827SRod.Evans@Sun.COM 		ifl->ifl_flags |= FLG_IF_OTOSCAP;
101811827SRod.Evans@Sun.COM 
101911827SRod.Evans@Sun.COM 	/*
102011827SRod.Evans@Sun.COM 	 * Allocate a capabilities descriptor to collect the capabilities data
102111827SRod.Evans@Sun.COM 	 * for this input file.  Allocate a mirror of the raw capabilities data
102211827SRod.Evans@Sun.COM 	 * that points to the individual symbol capabilities groups.  An APlist
102311827SRod.Evans@Sun.COM 	 * is used, although it will be sparsely populated, as the list provides
102411827SRod.Evans@Sun.COM 	 * a convenient mechanism for traversal later.
102511827SRod.Evans@Sun.COM 	 */
102611827SRod.Evans@Sun.COM 	if (((cdp = libld_calloc(sizeof (Cap_desc), 1)) == NULL) ||
102711827SRod.Evans@Sun.COM 	    (aplist_append(&(cdp->ca_groups), NULL, cnum) == NULL))
102811827SRod.Evans@Sun.COM 		return (S_ERROR);
102911827SRod.Evans@Sun.COM 
103011827SRod.Evans@Sun.COM 	/*
103111827SRod.Evans@Sun.COM 	 * Clear the allocated APlist data array, and assign the number of
103211827SRod.Evans@Sun.COM 	 * items as the total number of array items.
103311827SRod.Evans@Sun.COM 	 */
103411827SRod.Evans@Sun.COM 	(void) memset(&cdp->ca_groups->apl_data[0], 0,
103511827SRod.Evans@Sun.COM 	    (cnum * sizeof (void *)));
103611827SRod.Evans@Sun.COM 	cdp->ca_groups->apl_nitems = cnum;
103711827SRod.Evans@Sun.COM 
103811827SRod.Evans@Sun.COM 	ifl->ifl_caps = cdp;
103911827SRod.Evans@Sun.COM 
104011827SRod.Evans@Sun.COM 	/*
104111827SRod.Evans@Sun.COM 	 * Traverse the capabilities data, unpacking the data into a
104211827SRod.Evans@Sun.COM 	 * capabilities set.  Process each capabilities set as a unique group.
104311827SRod.Evans@Sun.COM 	 */
104411827SRod.Evans@Sun.COM 	descapndx = -1;
104511827SRod.Evans@Sun.COM 	nulls = 0;
104611827SRod.Evans@Sun.COM 
104711827SRod.Evans@Sun.COM 	for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
104811827SRod.Evans@Sun.COM 		Capstr	*capstr;
104911827SRod.Evans@Sun.COM 
105011827SRod.Evans@Sun.COM 		switch (data->c_tag) {
105111827SRod.Evans@Sun.COM 		case CA_SUNW_NULL:
105211827SRod.Evans@Sun.COM 			nulls++;
105311827SRod.Evans@Sun.COM 
105411827SRod.Evans@Sun.COM 			/*
105511827SRod.Evans@Sun.COM 			 * Process the capabilities group that this null entry
105611827SRod.Evans@Sun.COM 			 * terminates.  The capabilities group that is returned
105711827SRod.Evans@Sun.COM 			 * will either point to this file's data, or to a
105811827SRod.Evans@Sun.COM 			 * matching capabilities group that has already been
105911827SRod.Evans@Sun.COM 			 * processed.
106011827SRod.Evans@Sun.COM 			 *
106111827SRod.Evans@Sun.COM 			 * Note, if this object defines object capabilities,
106211827SRod.Evans@Sun.COM 			 * the first group descriptor points to these object
106311827SRod.Evans@Sun.COM 			 * capabilities.  It is only necessary to save this
106411827SRod.Evans@Sun.COM 			 * descriptor when object capabilities are being
106511827SRod.Evans@Sun.COM 			 * transformed into symbol capabilities (-z symbolcap).
106611827SRod.Evans@Sun.COM 			 */
106711827SRod.Evans@Sun.COM 			if (descapndx != -1) {
106811827SRod.Evans@Sun.COM 				if ((nulls > 1) ||
106911827SRod.Evans@Sun.COM 				    (ifl->ifl_flags & FLG_IF_OTOSCAP)) {
107011827SRod.Evans@Sun.COM 					APlist	*alp = cdp->ca_groups;
107111827SRod.Evans@Sun.COM 
107211827SRod.Evans@Sun.COM 					if ((alp->apl_data[descapndx] =
107311827SRod.Evans@Sun.COM 					    get_cap_group(&ocapset,
107411827SRod.Evans@Sun.COM 					    (ndx - descapndx), ofl,
107511827SRod.Evans@Sun.COM 					    cisp)) == NULL)
107611827SRod.Evans@Sun.COM 						return (S_ERROR);
107711827SRod.Evans@Sun.COM 				}
107811827SRod.Evans@Sun.COM 
107911827SRod.Evans@Sun.COM 				/*
108011827SRod.Evans@Sun.COM 				 * Clean up the capabilities data in preparation
108111827SRod.Evans@Sun.COM 				 * for processing additional groups.  If the
108211827SRod.Evans@Sun.COM 				 * collected capabilities strings were used to
108311827SRod.Evans@Sun.COM 				 * establish a new output group, they will have
108411827SRod.Evans@Sun.COM 				 * been saved in get_cap_group().  If these
108511827SRod.Evans@Sun.COM 				 * descriptors still exist, then an existing
108611827SRod.Evans@Sun.COM 				 * descriptor has been used to associate with
108711827SRod.Evans@Sun.COM 				 * this file, and these string descriptors can
108811827SRod.Evans@Sun.COM 				 * be freed.
108911827SRod.Evans@Sun.COM 				 */
109011827SRod.Evans@Sun.COM 				ocapset.oc_hw_1.cm_val =
109111827SRod.Evans@Sun.COM 				    ocapset.oc_sf_1.cm_val =
109211827SRod.Evans@Sun.COM 				    ocapset.oc_hw_2.cm_val = 0;
109311827SRod.Evans@Sun.COM 				if (ocapset.oc_plat.cl_val) {
109411827SRod.Evans@Sun.COM 					free((void *)ocapset.oc_plat.cl_val);
109511827SRod.Evans@Sun.COM 					ocapset.oc_plat.cl_val = NULL;
109611827SRod.Evans@Sun.COM 				}
109711827SRod.Evans@Sun.COM 				if (ocapset.oc_mach.cl_val) {
109811827SRod.Evans@Sun.COM 					free((void *)ocapset.oc_mach.cl_val);
109911827SRod.Evans@Sun.COM 					ocapset.oc_mach.cl_val = NULL;
110011827SRod.Evans@Sun.COM 				}
110111827SRod.Evans@Sun.COM 				descapndx = -1;
110211827SRod.Evans@Sun.COM 			}
110311827SRod.Evans@Sun.COM 			continue;
110411827SRod.Evans@Sun.COM 
110511827SRod.Evans@Sun.COM 		case CA_SUNW_HW_1:
110611827SRod.Evans@Sun.COM 			ocapset.oc_hw_1.cm_val = data->c_un.c_val;
110711827SRod.Evans@Sun.COM 			DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
110811827SRod.Evans@Sun.COM 			    DBG_STATE_ORIGINAL, CA_SUNW_HW_1,
110911827SRod.Evans@Sun.COM 			    ocapset.oc_hw_1.cm_val, ld_targ.t_m.m_mach));
111011827SRod.Evans@Sun.COM 			break;
111111827SRod.Evans@Sun.COM 
111211827SRod.Evans@Sun.COM 		case CA_SUNW_SF_1:
111311827SRod.Evans@Sun.COM 			ocapset.oc_sf_1.cm_val = data->c_un.c_val;
111411827SRod.Evans@Sun.COM 			DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
111511827SRod.Evans@Sun.COM 			    DBG_STATE_ORIGINAL, CA_SUNW_SF_1,
111611827SRod.Evans@Sun.COM 			    ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach));
111711827SRod.Evans@Sun.COM 			break;
111811827SRod.Evans@Sun.COM 
111911827SRod.Evans@Sun.COM 		case CA_SUNW_HW_2:
112011827SRod.Evans@Sun.COM 			ocapset.oc_hw_2.cm_val = data->c_un.c_val;
112111827SRod.Evans@Sun.COM 			DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
112211827SRod.Evans@Sun.COM 			    DBG_STATE_ORIGINAL, CA_SUNW_HW_2,
112311827SRod.Evans@Sun.COM 			    ocapset.oc_hw_2.cm_val, ld_targ.t_m.m_mach));
112411827SRod.Evans@Sun.COM 			break;
112511827SRod.Evans@Sun.COM 
112611827SRod.Evans@Sun.COM 		case CA_SUNW_PLAT:
112711827SRod.Evans@Sun.COM 			if ((capstr = alist_append(&ocapset.oc_plat.cl_val,
112811827SRod.Evans@Sun.COM 			    NULL, sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL)
112911827SRod.Evans@Sun.COM 				return (S_ERROR);
113011827SRod.Evans@Sun.COM 			capstr->cs_str = strs + data->c_un.c_ptr;
113111827SRod.Evans@Sun.COM 			DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
113211827SRod.Evans@Sun.COM 			    DBG_STATE_ORIGINAL, CA_SUNW_PLAT, capstr->cs_str));
113311827SRod.Evans@Sun.COM 			break;
113411827SRod.Evans@Sun.COM 
113511827SRod.Evans@Sun.COM 		case CA_SUNW_MACH:
113611827SRod.Evans@Sun.COM 			if ((capstr = alist_append(&ocapset.oc_mach.cl_val,
113711827SRod.Evans@Sun.COM 			    NULL, sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL)
113811827SRod.Evans@Sun.COM 				return (S_ERROR);
113911827SRod.Evans@Sun.COM 			capstr->cs_str = strs + data->c_un.c_ptr;
114011827SRod.Evans@Sun.COM 			DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
114111827SRod.Evans@Sun.COM 			    DBG_STATE_ORIGINAL, CA_SUNW_MACH, capstr->cs_str));
114211827SRod.Evans@Sun.COM 			break;
114311827SRod.Evans@Sun.COM 
114411827SRod.Evans@Sun.COM 		case CA_SUNW_ID:
114511827SRod.Evans@Sun.COM 			ocapset.oc_id.cs_str = strs + data->c_un.c_ptr;
114611827SRod.Evans@Sun.COM 			DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
114711827SRod.Evans@Sun.COM 			    DBG_STATE_ORIGINAL, CA_SUNW_ID,
114811827SRod.Evans@Sun.COM 			    ocapset.oc_id.cs_str));
114911827SRod.Evans@Sun.COM 			break;
115011827SRod.Evans@Sun.COM 		}
115111827SRod.Evans@Sun.COM 
115211827SRod.Evans@Sun.COM 		/*
115311827SRod.Evans@Sun.COM 		 * Save the start of this new group.
115411827SRod.Evans@Sun.COM 		 */
115511827SRod.Evans@Sun.COM 		if (descapndx == -1)
115611827SRod.Evans@Sun.COM 			descapndx = ndx;
115711827SRod.Evans@Sun.COM 	}
115811827SRod.Evans@Sun.COM 	return (1);
115911827SRod.Evans@Sun.COM }
116011827SRod.Evans@Sun.COM 
116111827SRod.Evans@Sun.COM /*
116211827SRod.Evans@Sun.COM  * Capture any symbol capabilities symbols.  An object file that contains symbol
116311827SRod.Evans@Sun.COM  * capabilities has an associated .SUNW_capinfo section.  This section
116411827SRod.Evans@Sun.COM  * identifies which symbols are associated to which capabilities, together with
116511827SRod.Evans@Sun.COM  * their associated lead symbol.  Each of these symbol pairs are recorded for
116611827SRod.Evans@Sun.COM  * processing later.
116711827SRod.Evans@Sun.COM  */
116811827SRod.Evans@Sun.COM static uintptr_t
116911827SRod.Evans@Sun.COM process_capinfo(Ofl_desc *ofl, Ifl_desc *ifl, Is_desc *isp)
117011827SRod.Evans@Sun.COM {
117111827SRod.Evans@Sun.COM 	Cap_desc	*cdp = ifl->ifl_caps;
117211827SRod.Evans@Sun.COM 	Capinfo		*capinfo = isp->is_indata->d_buf;
117311827SRod.Evans@Sun.COM 	Shdr		*shdr = isp->is_shdr;
117411827SRod.Evans@Sun.COM 	Word		cndx, capinfonum;
117511827SRod.Evans@Sun.COM 
117611827SRod.Evans@Sun.COM 	capinfonum = (Word)(shdr->sh_size / shdr->sh_entsize);
117711827SRod.Evans@Sun.COM 
117811827SRod.Evans@Sun.COM 	if ((cdp == NULL) || (capinfo == NULL) || (capinfonum == 0))
117911827SRod.Evans@Sun.COM 		return (0);
118011827SRod.Evans@Sun.COM 
118111827SRod.Evans@Sun.COM 	for (cndx = 1, capinfo++; cndx < capinfonum; cndx++, capinfo++) {
118211827SRod.Evans@Sun.COM 		Sym_desc	*sdp, *lsdp;
118311827SRod.Evans@Sun.COM 		Word		lndx;
118411827SRod.Evans@Sun.COM 		uchar_t		gndx;
118511827SRod.Evans@Sun.COM 
118611827SRod.Evans@Sun.COM 		if ((gndx = (uchar_t)ELF_C_GROUP(*capinfo)) == 0)
118711827SRod.Evans@Sun.COM 			continue;
118811827SRod.Evans@Sun.COM 		lndx = (Word)ELF_C_SYM(*capinfo);
118911827SRod.Evans@Sun.COM 
119011827SRod.Evans@Sun.COM 		/*
119111827SRod.Evans@Sun.COM 		 * Catch any anomalies.  A capabilities symbol should be valid,
119211827SRod.Evans@Sun.COM 		 * and the capabilities lead symbol should also be global.
119311827SRod.Evans@Sun.COM 		 * Note, ld(1) -z symbolcap would create local capabilities
119411827SRod.Evans@Sun.COM 		 * symbols, but we don't enforce this so as to give the
119511827SRod.Evans@Sun.COM 		 * compilation environment a little more freedom.
119611827SRod.Evans@Sun.COM 		 */
119711827SRod.Evans@Sun.COM 		if ((sdp = ifl->ifl_oldndx[cndx]) == NULL) {
119811827SRod.Evans@Sun.COM 			eprintf(ofl->ofl_lml, ERR_WARNING,
119911827SRod.Evans@Sun.COM 			    MSG_INTL(MSG_CAPINFO_INVALSYM), ifl->ifl_name,
120011827SRod.Evans@Sun.COM 			    EC_WORD(isp->is_scnndx), isp->is_name, cndx,
120111827SRod.Evans@Sun.COM 			    MSG_INTL(MSG_STR_UNKNOWN));
120211827SRod.Evans@Sun.COM 			continue;
120311827SRod.Evans@Sun.COM 		}
120411827SRod.Evans@Sun.COM 		if ((lndx == 0) || (lndx >= ifl->ifl_symscnt) ||
120511827SRod.Evans@Sun.COM 		    ((lsdp = ifl->ifl_oldndx[lndx]) == NULL) ||
120611827SRod.Evans@Sun.COM 		    (ELF_ST_BIND(lsdp->sd_sym->st_info) != STB_GLOBAL)) {
120711827SRod.Evans@Sun.COM 			eprintf(ofl->ofl_lml, ERR_WARNING,
120811827SRod.Evans@Sun.COM 			    MSG_INTL(MSG_CAPINFO_INVALLEAD), ifl->ifl_name,
120911827SRod.Evans@Sun.COM 			    EC_WORD(isp->is_scnndx), isp->is_name, cndx, lsdp ?
121011827SRod.Evans@Sun.COM 			    demangle(lsdp->sd_name) : MSG_INTL(MSG_STR_UNKNOWN),
121111827SRod.Evans@Sun.COM 			    lndx);
121211827SRod.Evans@Sun.COM 			continue;
121311827SRod.Evans@Sun.COM 		}
121411827SRod.Evans@Sun.COM 
121511827SRod.Evans@Sun.COM 		/*
121611827SRod.Evans@Sun.COM 		 * Indicate that this is a capabilities symbol.
121711827SRod.Evans@Sun.COM 		 */
121811827SRod.Evans@Sun.COM 		sdp->sd_flags |= FLG_SY_CAP;
121911827SRod.Evans@Sun.COM 
122011827SRod.Evans@Sun.COM 		/*
122111827SRod.Evans@Sun.COM 		 * Save any global capability symbols.  Global capability
122211827SRod.Evans@Sun.COM 		 * symbols are identified with a CAPINFO_SUNW_GLOB group id.
122311827SRod.Evans@Sun.COM 		 * The lead symbol for this global capability symbol is either
122411827SRod.Evans@Sun.COM 		 * the symbol itself, or an alias.
122511827SRod.Evans@Sun.COM 		 */
122611827SRod.Evans@Sun.COM 		if (gndx == CAPINFO_SUNW_GLOB) {
122711827SRod.Evans@Sun.COM 			if (ld_cap_add_family(ofl, lsdp, sdp,
122811827SRod.Evans@Sun.COM 			    NULL, NULL) == S_ERROR)
122911827SRod.Evans@Sun.COM 				return (S_ERROR);
123011827SRod.Evans@Sun.COM 			continue;
123111827SRod.Evans@Sun.COM 		}
123211827SRod.Evans@Sun.COM 
123311827SRod.Evans@Sun.COM 		/*
123411827SRod.Evans@Sun.COM 		 * Track the number of non-global capabilities symbols, as these
123511827SRod.Evans@Sun.COM 		 * are used to size any symbol tables.  If we're generating a
123611827SRod.Evans@Sun.COM 		 * dynamic object, this symbol will be added to the dynamic
123711827SRod.Evans@Sun.COM 		 * symbol table, therefore ensure there is space in the dynamic
123811827SRod.Evans@Sun.COM 		 * string table.
123911827SRod.Evans@Sun.COM 		 */
124011827SRod.Evans@Sun.COM 		ofl->ofl_caploclcnt++;
124111827SRod.Evans@Sun.COM 		if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) &&
124211827SRod.Evans@Sun.COM 		    (st_insert(ofl->ofl_dynstrtab, sdp->sd_name) == -1))
124311827SRod.Evans@Sun.COM 			return (S_ERROR);
124411827SRod.Evans@Sun.COM 
124511827SRod.Evans@Sun.COM 		/*
124611827SRod.Evans@Sun.COM 		 * As we're tracking this local symbol as a capabilities symbol,
124711827SRod.Evans@Sun.COM 		 * reduce the local symbol count to compensate.
124811827SRod.Evans@Sun.COM 		 */
124911827SRod.Evans@Sun.COM 		ofl->ofl_locscnt--;
125011827SRod.Evans@Sun.COM 
125111827SRod.Evans@Sun.COM 		/*
125211827SRod.Evans@Sun.COM 		 * Determine whether the associated lead symbol indicates
125311827SRod.Evans@Sun.COM 		 * NODYNSORT.  If so, remove this local entry from the
125411827SRod.Evans@Sun.COM 		 * SUNW_dynsort section too.  NODYNSORT tagging can only be
125511827SRod.Evans@Sun.COM 		 * obtained from a mapfile symbol definition, and thus any
125611827SRod.Evans@Sun.COM 		 * global definition that has this tagging has already been
125711827SRod.Evans@Sun.COM 		 * instantiated and this instance resolved to it.
125811827SRod.Evans@Sun.COM 		 */
125911827SRod.Evans@Sun.COM 		if (lsdp->sd_flags & FLG_SY_NODYNSORT) {
126011827SRod.Evans@Sun.COM 			Sym	*lsym = lsdp->sd_sym;
126111827SRod.Evans@Sun.COM 			uchar_t ltype = ELF_ST_TYPE(lsym->st_info);
126211827SRod.Evans@Sun.COM 
126311827SRod.Evans@Sun.COM 			DYNSORT_COUNT(lsdp, lsym, ltype, --);
126411827SRod.Evans@Sun.COM 			lsdp->sd_flags |= FLG_SY_NODYNSORT;
126511827SRod.Evans@Sun.COM 		}
126611827SRod.Evans@Sun.COM 
126711827SRod.Evans@Sun.COM 		/*
126811827SRod.Evans@Sun.COM 		 * Track this family member, together with its associated group.
126911827SRod.Evans@Sun.COM 		 */
127011827SRod.Evans@Sun.COM 		if (ld_cap_add_family(ofl, lsdp, sdp,
127111827SRod.Evans@Sun.COM 		    cdp->ca_groups->apl_data[gndx], NULL) == S_ERROR)
127211827SRod.Evans@Sun.COM 			return (S_ERROR);
127311827SRod.Evans@Sun.COM 	}
127411827SRod.Evans@Sun.COM 
127511827SRod.Evans@Sun.COM 	return (0);
12760Sstevel@tonic-gate }
12770Sstevel@tonic-gate 
12780Sstevel@tonic-gate /*
12790Sstevel@tonic-gate  * Simply process the section so that we have pointers to the data for use
12800Sstevel@tonic-gate  * in later routines, however don't add the section to the output section
12810Sstevel@tonic-gate  * list as we will be creating our own replacement sections later (ie.
12820Sstevel@tonic-gate  * symtab and relocation).
12830Sstevel@tonic-gate  */
12841618Srie static uintptr_t
12850Sstevel@tonic-gate /* ARGSUSED5 */
12860Sstevel@tonic-gate process_input(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
12877463SRod.Evans@Sun.COM     Word ndx, int ident, Ofl_desc *ofl)
12880Sstevel@tonic-gate {
12896206Sab196087 	return (process_section(name, ifl, shdr, scn, ndx,
12906206Sab196087 	    ld_targ.t_id.id_null, ofl));
12910Sstevel@tonic-gate }
12920Sstevel@tonic-gate 
12930Sstevel@tonic-gate /*
12940Sstevel@tonic-gate  * Keep a running count of relocation entries from input relocatable objects for
12950Sstevel@tonic-gate  * sizing relocation buckets later.  If we're building an executable, save any
12960Sstevel@tonic-gate  * relocations from shared objects to determine if any copy relocation symbol
12970Sstevel@tonic-gate  * has a displacement relocation against it.
12980Sstevel@tonic-gate  */
12991618Srie static uintptr_t
13000Sstevel@tonic-gate /* ARGSUSED5 */
13010Sstevel@tonic-gate process_reloc(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
13027463SRod.Evans@Sun.COM     Word ndx, int ident, Ofl_desc *ofl)
13030Sstevel@tonic-gate {
13040Sstevel@tonic-gate 	if (process_section(name, ifl,
13056206Sab196087 	    shdr, scn, ndx, ld_targ.t_id.id_null, ofl) == S_ERROR)
13060Sstevel@tonic-gate 		return (S_ERROR);
13070Sstevel@tonic-gate 
13080Sstevel@tonic-gate 	if (ifl->ifl_ehdr->e_type == ET_REL) {
13090Sstevel@tonic-gate 		if (shdr->sh_entsize && (shdr->sh_entsize <= shdr->sh_size))
13100Sstevel@tonic-gate 			/* LINTED */
13110Sstevel@tonic-gate 			ofl->ofl_relocincnt +=
13120Sstevel@tonic-gate 			    (Word)(shdr->sh_size / shdr->sh_entsize);
13130Sstevel@tonic-gate 	} else if (ofl->ofl_flags & FLG_OF_EXEC) {
13149131SRod.Evans@Sun.COM 		if (aplist_append(&ifl->ifl_relsect, ifl->ifl_isdesc[ndx],
13159131SRod.Evans@Sun.COM 		    AL_CNT_IFL_RELSECS) == NULL)
13160Sstevel@tonic-gate 			return (S_ERROR);
13170Sstevel@tonic-gate 	}
13180Sstevel@tonic-gate 	return (1);
13190Sstevel@tonic-gate }
13200Sstevel@tonic-gate 
13210Sstevel@tonic-gate /*
13220Sstevel@tonic-gate  * Process a string table section.  A valid section contains an initial and
13230Sstevel@tonic-gate  * final null byte.
13240Sstevel@tonic-gate  */
13251618Srie static uintptr_t
13260Sstevel@tonic-gate process_strtab(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
13277463SRod.Evans@Sun.COM     Word ndx, int ident, Ofl_desc *ofl)
13280Sstevel@tonic-gate {
13290Sstevel@tonic-gate 	char		*data;
13300Sstevel@tonic-gate 	size_t		size;
13310Sstevel@tonic-gate 	Is_desc		*isp;
13320Sstevel@tonic-gate 	uintptr_t	error;
13330Sstevel@tonic-gate 
13340Sstevel@tonic-gate 	/*
13350Sstevel@tonic-gate 	 * Never include .stab.excl sections in any output file.
13360Sstevel@tonic-gate 	 * If the -s flag has been specified strip any .stab sections.
13370Sstevel@tonic-gate 	 */
13380Sstevel@tonic-gate 	if (((ofl->ofl_flags & FLG_OF_STRIP) && ident &&
13390Sstevel@tonic-gate 	    (strncmp(name, MSG_ORIG(MSG_SCN_STAB), MSG_SCN_STAB_SIZE) == 0)) ||
13400Sstevel@tonic-gate 	    (strcmp(name, MSG_ORIG(MSG_SCN_STABEXCL)) == 0) && ident)
13410Sstevel@tonic-gate 		return (1);
13420Sstevel@tonic-gate 
13430Sstevel@tonic-gate 	/*
13440Sstevel@tonic-gate 	 * If we got here to process a .shstrtab or .dynstr table, `ident' will
13450Sstevel@tonic-gate 	 * be null.  Otherwise make sure we don't have a .strtab section as this
13460Sstevel@tonic-gate 	 * should not be added to the output section list either.
13470Sstevel@tonic-gate 	 */
13486206Sab196087 	if ((ident != ld_targ.t_id.id_null) &&
13490Sstevel@tonic-gate 	    (strcmp(name, MSG_ORIG(MSG_SCN_STRTAB)) == 0))
13506206Sab196087 		ident = ld_targ.t_id.id_null;
13510Sstevel@tonic-gate 
13520Sstevel@tonic-gate 	error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
13530Sstevel@tonic-gate 	if ((error == 0) || (error == S_ERROR))
13540Sstevel@tonic-gate 		return (error);
13550Sstevel@tonic-gate 
13560Sstevel@tonic-gate 	/*
13570Sstevel@tonic-gate 	 * String tables should start and end with a NULL byte.  Note, it has
13580Sstevel@tonic-gate 	 * been known for the assembler to create empty string tables, so check
13590Sstevel@tonic-gate 	 * the size before attempting to verify the data itself.
13600Sstevel@tonic-gate 	 */
13610Sstevel@tonic-gate 	isp = ifl->ifl_isdesc[ndx];
13620Sstevel@tonic-gate 	size = isp->is_indata->d_size;
13630Sstevel@tonic-gate 	if (size) {
13640Sstevel@tonic-gate 		data = isp->is_indata->d_buf;
13650Sstevel@tonic-gate 		if (data[0] != '\0' || data[size - 1] != '\0')
13661618Srie 			eprintf(ofl->ofl_lml, ERR_WARNING,
13679878SAli.Bahrami@Sun.COM 			    MSG_INTL(MSG_FIL_MALSTR), ifl->ifl_name,
13689878SAli.Bahrami@Sun.COM 			    EC_WORD(isp->is_scnndx), name);
13690Sstevel@tonic-gate 	} else
13700Sstevel@tonic-gate 		isp->is_indata->d_buf = (void *)MSG_ORIG(MSG_STR_EMPTY);
13710Sstevel@tonic-gate 
13720Sstevel@tonic-gate 	ifl->ifl_flags |= FLG_IF_HSTRTAB;
13730Sstevel@tonic-gate 	return (1);
13740Sstevel@tonic-gate }
13750Sstevel@tonic-gate 
13760Sstevel@tonic-gate /*
13770Sstevel@tonic-gate  * Invalid sections produce a warning and are skipped.
13780Sstevel@tonic-gate  */
13791618Srie static uintptr_t
13800Sstevel@tonic-gate /* ARGSUSED3 */
13810Sstevel@tonic-gate invalid_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
13820Sstevel@tonic-gate     Word ndx, int ident, Ofl_desc *ofl)
13830Sstevel@tonic-gate {
13844734Sab196087 	Conv_inv_buf_t inv_buf;
13854734Sab196087 
13861618Srie 	eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_INVALSEC),
13879878SAli.Bahrami@Sun.COM 	    ifl->ifl_name, EC_WORD(ndx), name,
13889273SAli.Bahrami@Sun.COM 	    conv_sec_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
13899273SAli.Bahrami@Sun.COM 	    ifl->ifl_ehdr->e_machine, shdr->sh_type, 0, &inv_buf));
13900Sstevel@tonic-gate 	return (1);
13910Sstevel@tonic-gate }
13920Sstevel@tonic-gate 
13930Sstevel@tonic-gate /*
139410454SAli.Bahrami@Sun.COM  * Compare an input section name to a given string, taking the ELF '%'
139510454SAli.Bahrami@Sun.COM  * section naming convention into account. If an input section name
139610454SAli.Bahrami@Sun.COM  * contains a '%' character, the '%' and all following characters are
139710454SAli.Bahrami@Sun.COM  * ignored in the comparison.
139810454SAli.Bahrami@Sun.COM  *
139910454SAli.Bahrami@Sun.COM  * entry:
140010454SAli.Bahrami@Sun.COM  *	is_name - Name of input section
140110454SAli.Bahrami@Sun.COM  *	match_name - Name to compare to
140210454SAli.Bahrami@Sun.COM  *	match_len - strlen(match_name)
140310454SAli.Bahrami@Sun.COM  *
140410454SAli.Bahrami@Sun.COM  * exit:
140510454SAli.Bahrami@Sun.COM  *	Returns True (1) if the names match, and False (0) otherwise.
140610454SAli.Bahrami@Sun.COM  */
140710454SAli.Bahrami@Sun.COM inline static int
140810454SAli.Bahrami@Sun.COM is_name_cmp(const char *is_name, const char *match_name, size_t match_len)
140910454SAli.Bahrami@Sun.COM {
141010454SAli.Bahrami@Sun.COM 	/*
141110454SAli.Bahrami@Sun.COM 	 * If the start of is_name is not a match for name,
141210454SAli.Bahrami@Sun.COM 	 * the match fails.
141310454SAli.Bahrami@Sun.COM 	 */
141410454SAli.Bahrami@Sun.COM 	if (strncmp(is_name, match_name, match_len) != 0)
141510454SAli.Bahrami@Sun.COM 		return (0);
141610454SAli.Bahrami@Sun.COM 
141710454SAli.Bahrami@Sun.COM 	/*
141810454SAli.Bahrami@Sun.COM 	 * The prefix matched. The next character must be either '%', or
141910454SAli.Bahrami@Sun.COM 	 * NULL, in order for a match to be true.
142010454SAli.Bahrami@Sun.COM 	 */
142110454SAli.Bahrami@Sun.COM 	is_name += match_len;
142210454SAli.Bahrami@Sun.COM 	return ((*is_name == '\0') || (*is_name == '%'));
142310454SAli.Bahrami@Sun.COM }
142410454SAli.Bahrami@Sun.COM 
142510454SAli.Bahrami@Sun.COM /*
142611993SAli.Bahrami@Sun.COM  * Helper routine for process_progbits() to process allocable sections.
142711993SAli.Bahrami@Sun.COM  *
142811993SAli.Bahrami@Sun.COM  * entry:
142911993SAli.Bahrami@Sun.COM  *	name, ifl, shdr, ndx, ident, ofl - As passed to process_progbits().
143011993SAli.Bahrami@Sun.COM  *	is_stab_index - TRUE if section is .index.
143111993SAli.Bahrami@Sun.COM  *	is_flags - Additional flags to be added to the input section.
143211993SAli.Bahrami@Sun.COM  *
143311993SAli.Bahrami@Sun.COM  * exit:
143411993SAli.Bahrami@Sun.COM  *	The allocable section has been processed. *ident and *is_flags
143511993SAli.Bahrami@Sun.COM  *	are updated as necessary to reflect the changes. Returns TRUE
143611993SAli.Bahrami@Sun.COM  *	for success, FALSE for failure.
143711993SAli.Bahrami@Sun.COM  */
143811993SAli.Bahrami@Sun.COM inline static Boolean
143911993SAli.Bahrami@Sun.COM process_progbits_alloc(const char *name, Ifl_desc *ifl, Shdr *shdr,
144011993SAli.Bahrami@Sun.COM     Word ndx, int *ident, Ofl_desc *ofl, Boolean is_stab_index,
144111993SAli.Bahrami@Sun.COM     Word *is_flags)
144211993SAli.Bahrami@Sun.COM {
144311993SAli.Bahrami@Sun.COM 	Boolean done = FALSE;
144411993SAli.Bahrami@Sun.COM 
144511993SAli.Bahrami@Sun.COM 	if (name[0] == '.') {
144611993SAli.Bahrami@Sun.COM 		Conv_inv_buf_t inv_buf1, inv_buf2;
144711993SAli.Bahrami@Sun.COM 
144811993SAli.Bahrami@Sun.COM 		switch (name[1]) {
144911993SAli.Bahrami@Sun.COM 		case 'e':
145011993SAli.Bahrami@Sun.COM 			if (!is_name_cmp(name, MSG_ORIG(MSG_SCN_EHFRAME),
145111993SAli.Bahrami@Sun.COM 			    MSG_SCN_EHFRAME_SIZE))
145211993SAli.Bahrami@Sun.COM 				break;
145311993SAli.Bahrami@Sun.COM 
145411993SAli.Bahrami@Sun.COM 			*ident = ld_targ.t_id.id_unwind;
145511993SAli.Bahrami@Sun.COM 			*is_flags |= FLG_IS_EHFRAME;
145611993SAli.Bahrami@Sun.COM 			done = TRUE;
145711993SAli.Bahrami@Sun.COM 
145811993SAli.Bahrami@Sun.COM 			/*
145911993SAli.Bahrami@Sun.COM 			 * Only accept a progbits .eh_frame on a platform
146011993SAli.Bahrami@Sun.COM 			 * for which this is the expected type.
146111993SAli.Bahrami@Sun.COM 			 */
146211993SAli.Bahrami@Sun.COM 			if (ld_targ.t_m.m_sht_unwind == SHT_PROGBITS)
146311993SAli.Bahrami@Sun.COM 				break;
146411993SAli.Bahrami@Sun.COM 			eprintf(ofl->ofl_lml, ERR_FATAL,
146511993SAli.Bahrami@Sun.COM 			    MSG_INTL(MSG_FIL_EXEHFRMTYP), ifl->ifl_name,
146611993SAli.Bahrami@Sun.COM 			    EC_WORD(ndx), name,
146711993SAli.Bahrami@Sun.COM 			    conv_sec_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
146811993SAli.Bahrami@Sun.COM 			    ifl->ifl_ehdr->e_machine, shdr->sh_type,
146911993SAli.Bahrami@Sun.COM 			    CONV_FMT_ALT_CF, &inv_buf1),
147011993SAli.Bahrami@Sun.COM 			    conv_sec_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
147111993SAli.Bahrami@Sun.COM 			    ifl->ifl_ehdr->e_machine, ld_targ.t_m.m_sht_unwind,
147211993SAli.Bahrami@Sun.COM 			    CONV_FMT_ALT_CF, &inv_buf2));
147311993SAli.Bahrami@Sun.COM 			ofl->ofl_flags |= FLG_OF_FATAL;
147411993SAli.Bahrami@Sun.COM 			return (FALSE);
147511993SAli.Bahrami@Sun.COM 		case 'g':
147611993SAli.Bahrami@Sun.COM 			if (is_name_cmp(name, MSG_ORIG(MSG_SCN_GOT),
147711993SAli.Bahrami@Sun.COM 			    MSG_SCN_GOT_SIZE)) {
147811993SAli.Bahrami@Sun.COM 				*ident = ld_targ.t_id.id_null;
147911993SAli.Bahrami@Sun.COM 				done = TRUE;
148011993SAli.Bahrami@Sun.COM 				break;
148111993SAli.Bahrami@Sun.COM 			}
148211993SAli.Bahrami@Sun.COM 			if ((ld_targ.t_m.m_sht_unwind == SHT_PROGBITS) &&
148311993SAli.Bahrami@Sun.COM 			    is_name_cmp(name, MSG_ORIG(MSG_SCN_GCC_X_TBL),
148411993SAli.Bahrami@Sun.COM 			    MSG_SCN_GCC_X_TBL_SIZE)) {
148511993SAli.Bahrami@Sun.COM 				*ident = ld_targ.t_id.id_unwind;
148611993SAli.Bahrami@Sun.COM 				done = TRUE;
148711993SAli.Bahrami@Sun.COM 				break;
148811993SAli.Bahrami@Sun.COM 			}
148911993SAli.Bahrami@Sun.COM 			break;
149011993SAli.Bahrami@Sun.COM 		case 'p':
149111993SAli.Bahrami@Sun.COM 			if (is_name_cmp(name, MSG_ORIG(MSG_SCN_PLT),
149211993SAli.Bahrami@Sun.COM 			    MSG_SCN_PLT_SIZE)) {
149311993SAli.Bahrami@Sun.COM 				*ident = ld_targ.t_id.id_null;
149411993SAli.Bahrami@Sun.COM 				done = TRUE;
149511993SAli.Bahrami@Sun.COM 			}
149611993SAli.Bahrami@Sun.COM 			break;
149711993SAli.Bahrami@Sun.COM 		}
149811993SAli.Bahrami@Sun.COM 	}
149911993SAli.Bahrami@Sun.COM 	if (!done) {
150011993SAli.Bahrami@Sun.COM 		if (is_stab_index) {
150111993SAli.Bahrami@Sun.COM 			/*
150211993SAli.Bahrami@Sun.COM 			 * This is a work-around for x86 compilers that have
150311993SAli.Bahrami@Sun.COM 			 * set SHF_ALLOC for the .stab.index section.
150411993SAli.Bahrami@Sun.COM 			 *
150511993SAli.Bahrami@Sun.COM 			 * Because of this, make sure that the .stab.index
150611993SAli.Bahrami@Sun.COM 			 * does not end up as the last section in the text
150711993SAli.Bahrami@Sun.COM 			 * segment. Older linkers can produce segmentation
150811993SAli.Bahrami@Sun.COM 			 * violations when they strip (ld -s) against a
150911993SAli.Bahrami@Sun.COM 			 * shared object whose last section in the text
151011993SAli.Bahrami@Sun.COM 			 * segment is a .stab.
151111993SAli.Bahrami@Sun.COM 			 */
151211993SAli.Bahrami@Sun.COM 			*ident = ld_targ.t_id.id_interp;
151311993SAli.Bahrami@Sun.COM 		} else {
151411993SAli.Bahrami@Sun.COM 			*ident = ld_targ.t_id.id_data;
151511993SAli.Bahrami@Sun.COM 		}
151611993SAli.Bahrami@Sun.COM 	}
151711993SAli.Bahrami@Sun.COM 
151811993SAli.Bahrami@Sun.COM 	return (TRUE);
151911993SAli.Bahrami@Sun.COM }
152011993SAli.Bahrami@Sun.COM 
152111993SAli.Bahrami@Sun.COM /*
15220Sstevel@tonic-gate  * Process a progbits section.
15230Sstevel@tonic-gate  */
15241618Srie static uintptr_t
15250Sstevel@tonic-gate process_progbits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
15260Sstevel@tonic-gate     Word ndx, int ident, Ofl_desc *ofl)
15270Sstevel@tonic-gate {
152811993SAli.Bahrami@Sun.COM 	Boolean		is_stab_index = FALSE;
15299085SAli.Bahrami@Sun.COM 	Word		is_flags = 0;
15309085SAli.Bahrami@Sun.COM 	uintptr_t	r;
15310Sstevel@tonic-gate 
15320Sstevel@tonic-gate 	/*
15330Sstevel@tonic-gate 	 * Never include .stab.excl sections in any output file.
15340Sstevel@tonic-gate 	 * If the -s flag has been specified strip any .stab sections.
15350Sstevel@tonic-gate 	 */
15360Sstevel@tonic-gate 	if (ident && (strncmp(name, MSG_ORIG(MSG_SCN_STAB),
15370Sstevel@tonic-gate 	    MSG_SCN_STAB_SIZE) == 0)) {
15380Sstevel@tonic-gate 		if ((ofl->ofl_flags & FLG_OF_STRIP) ||
15390Sstevel@tonic-gate 		    (strcmp((name + MSG_SCN_STAB_SIZE),
15404716Sab196087 		    MSG_ORIG(MSG_SCN_EXCL)) == 0))
15410Sstevel@tonic-gate 			return (1);
15420Sstevel@tonic-gate 
15430Sstevel@tonic-gate 		if (strcmp((name + MSG_SCN_STAB_SIZE),
15440Sstevel@tonic-gate 		    MSG_ORIG(MSG_SCN_INDEX)) == 0)
154511993SAli.Bahrami@Sun.COM 			is_stab_index = TRUE;
15460Sstevel@tonic-gate 	}
15470Sstevel@tonic-gate 
15480Sstevel@tonic-gate 	if ((ofl->ofl_flags & FLG_OF_STRIP) && ident) {
15490Sstevel@tonic-gate 		if ((strncmp(name, MSG_ORIG(MSG_SCN_DEBUG),
15500Sstevel@tonic-gate 		    MSG_SCN_DEBUG_SIZE) == 0) ||
15510Sstevel@tonic-gate 		    (strcmp(name, MSG_ORIG(MSG_SCN_LINE)) == 0))
15520Sstevel@tonic-gate 			return (1);
15530Sstevel@tonic-gate 	}
15540Sstevel@tonic-gate 
15550Sstevel@tonic-gate 	/*
15560Sstevel@tonic-gate 	 * Update the ident to reflect the type of section we've got.
15570Sstevel@tonic-gate 	 *
15580Sstevel@tonic-gate 	 * If there is any .plt or .got section to generate we'll be creating
15590Sstevel@tonic-gate 	 * our own version, so don't allow any input sections of these types to
15600Sstevel@tonic-gate 	 * be added to the output section list (why a relocatable object would
15610Sstevel@tonic-gate 	 * have a .plt or .got is a mystery, but stranger things have occurred).
15629085SAli.Bahrami@Sun.COM 	 *
15639085SAli.Bahrami@Sun.COM 	 * If there are any unwind sections, and this is a platform that uses
15649085SAli.Bahrami@Sun.COM 	 * SHT_PROGBITS for unwind sections, then set their ident to reflect
15659085SAli.Bahrami@Sun.COM 	 * that.
15660Sstevel@tonic-gate 	 */
15670Sstevel@tonic-gate 	if (ident) {
15689085SAli.Bahrami@Sun.COM 		if (shdr->sh_flags & SHF_TLS) {
15696206Sab196087 			ident = ld_targ.t_id.id_tls;
15709085SAli.Bahrami@Sun.COM 		} else if ((shdr->sh_flags & ~ALL_SHF_IGNORE) ==
15719085SAli.Bahrami@Sun.COM 		    (SHF_ALLOC | SHF_EXECINSTR)) {
15726206Sab196087 			ident = ld_targ.t_id.id_text;
15739085SAli.Bahrami@Sun.COM 		} else if (shdr->sh_flags & SHF_ALLOC) {
157411993SAli.Bahrami@Sun.COM 			if (process_progbits_alloc(name, ifl, shdr, ndx,
157511993SAli.Bahrami@Sun.COM 			    &ident, ofl, is_stab_index, &is_flags) == FALSE)
157611993SAli.Bahrami@Sun.COM 				return (S_ERROR);
157711993SAli.Bahrami@Sun.COM 		} else {
15786206Sab196087 			ident = ld_targ.t_id.id_note;
157911993SAli.Bahrami@Sun.COM 		}
15800Sstevel@tonic-gate 	}
15819085SAli.Bahrami@Sun.COM 
15829085SAli.Bahrami@Sun.COM 	r = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
15839085SAli.Bahrami@Sun.COM 
15849085SAli.Bahrami@Sun.COM 	/*
15859085SAli.Bahrami@Sun.COM 	 * On success, process_section() creates an input section descriptor.
15869085SAli.Bahrami@Sun.COM 	 * Now that it exists, we can add any pending input section flags.
15879085SAli.Bahrami@Sun.COM 	 */
15889085SAli.Bahrami@Sun.COM 	if ((is_flags != 0) && (r == 1))
15899085SAli.Bahrami@Sun.COM 		ifl->ifl_isdesc[ndx]->is_flags |= is_flags;
15909085SAli.Bahrami@Sun.COM 
15919085SAli.Bahrami@Sun.COM 	return (r);
15920Sstevel@tonic-gate }
15930Sstevel@tonic-gate 
15940Sstevel@tonic-gate /*
15950Sstevel@tonic-gate  * Handles the SHT_SUNW_{DEBUG,DEBUGSTR) sections.
15960Sstevel@tonic-gate  */
15971618Srie static uintptr_t
15980Sstevel@tonic-gate process_debug(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
15990Sstevel@tonic-gate     Word ndx, int ident, Ofl_desc *ofl)
16000Sstevel@tonic-gate {
16010Sstevel@tonic-gate 	/*
16020Sstevel@tonic-gate 	 * Debug information is discarded when the 'ld -s' flag is invoked.
16030Sstevel@tonic-gate 	 */
16040Sstevel@tonic-gate 	if (ofl->ofl_flags & FLG_OF_STRIP) {
16050Sstevel@tonic-gate 		return (1);
16060Sstevel@tonic-gate 	}
16070Sstevel@tonic-gate 	return (process_progbits(name, ifl, shdr, scn, ndx, ident, ofl));
16080Sstevel@tonic-gate }
16090Sstevel@tonic-gate 
16100Sstevel@tonic-gate /*
16110Sstevel@tonic-gate  * Process a nobits section.
16120Sstevel@tonic-gate  */
16131618Srie static uintptr_t
16140Sstevel@tonic-gate process_nobits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
16150Sstevel@tonic-gate     Word ndx, int ident, Ofl_desc *ofl)
16160Sstevel@tonic-gate {
16170Sstevel@tonic-gate 	if (ident) {
16180Sstevel@tonic-gate 		if (shdr->sh_flags & SHF_TLS)
16196206Sab196087 			ident = ld_targ.t_id.id_tlsbss;
16206206Sab196087 #if	defined(_ELF64)
16216206Sab196087 		else if ((shdr->sh_flags & SHF_AMD64_LARGE) &&
16226206Sab196087 		    (ld_targ.t_m.m_mach == EM_AMD64))
16236206Sab196087 			ident = ld_targ.t_id.id_lbss;
1624574Sseizo #endif
16250Sstevel@tonic-gate 		else
16266206Sab196087 			ident = ld_targ.t_id.id_bss;
16270Sstevel@tonic-gate 	}
16280Sstevel@tonic-gate 	return (process_section(name, ifl, shdr, scn, ndx, ident, ofl));
16290Sstevel@tonic-gate }
16300Sstevel@tonic-gate 
16310Sstevel@tonic-gate /*
16320Sstevel@tonic-gate  * Process a SHT_*_ARRAY section.
16330Sstevel@tonic-gate  */
16341618Srie static uintptr_t
16350Sstevel@tonic-gate process_array(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
16360Sstevel@tonic-gate     Word ndx, int ident, Ofl_desc *ofl)
16370Sstevel@tonic-gate {
16387463SRod.Evans@Sun.COM 	uintptr_t	error;
16390Sstevel@tonic-gate 
16400Sstevel@tonic-gate 	if (ident)
16416206Sab196087 		ident = ld_targ.t_id.id_array;
16420Sstevel@tonic-gate 
16437463SRod.Evans@Sun.COM 	error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
16447463SRod.Evans@Sun.COM 	if ((error == 0) || (error == S_ERROR))
16457463SRod.Evans@Sun.COM 		return (error);
16467463SRod.Evans@Sun.COM 
16477463SRod.Evans@Sun.COM 	return (1);
16487463SRod.Evans@Sun.COM }
16490Sstevel@tonic-gate 
16507463SRod.Evans@Sun.COM static uintptr_t
16517463SRod.Evans@Sun.COM /* ARGSUSED1 */
16527463SRod.Evans@Sun.COM array_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
16537463SRod.Evans@Sun.COM {
16547463SRod.Evans@Sun.COM 	Os_desc	*osp;
16557463SRod.Evans@Sun.COM 	Shdr	*shdr;
16567463SRod.Evans@Sun.COM 
16577463SRod.Evans@Sun.COM 	if ((isc == NULL) || ((osp = isc->is_osdesc) == NULL))
16580Sstevel@tonic-gate 		return (0);
16590Sstevel@tonic-gate 
16607463SRod.Evans@Sun.COM 	shdr = isc->is_shdr;
16617463SRod.Evans@Sun.COM 
16620Sstevel@tonic-gate 	if ((shdr->sh_type == SHT_FINI_ARRAY) &&
16637463SRod.Evans@Sun.COM 	    (ofl->ofl_osfiniarray == NULL))
16640Sstevel@tonic-gate 		ofl->ofl_osfiniarray = osp;
16650Sstevel@tonic-gate 	else if ((shdr->sh_type == SHT_INIT_ARRAY) &&
16667463SRod.Evans@Sun.COM 	    (ofl->ofl_osinitarray == NULL))
16670Sstevel@tonic-gate 		ofl->ofl_osinitarray = osp;
16680Sstevel@tonic-gate 	else if ((shdr->sh_type == SHT_PREINIT_ARRAY) &&
16697463SRod.Evans@Sun.COM 	    (ofl->ofl_ospreinitarray == NULL))
16700Sstevel@tonic-gate 		ofl->ofl_ospreinitarray = osp;
16710Sstevel@tonic-gate 
16720Sstevel@tonic-gate 	return (1);
16730Sstevel@tonic-gate }
16740Sstevel@tonic-gate 
16750Sstevel@tonic-gate /*
16760Sstevel@tonic-gate  * Process a SHT_SYMTAB_SHNDX section.
16770Sstevel@tonic-gate  */
16781618Srie static uintptr_t
16790Sstevel@tonic-gate process_sym_shndx(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
16800Sstevel@tonic-gate     Word ndx, int ident, Ofl_desc *ofl)
16810Sstevel@tonic-gate {
16820Sstevel@tonic-gate 	if (process_input(name, ifl, shdr, scn, ndx, ident, ofl) == S_ERROR)
16830Sstevel@tonic-gate 		return (S_ERROR);
16840Sstevel@tonic-gate 
16850Sstevel@tonic-gate 	/*
16860Sstevel@tonic-gate 	 * Have we already seen the related SYMTAB - if so verify it now.
16870Sstevel@tonic-gate 	 */
16880Sstevel@tonic-gate 	if (shdr->sh_link < ndx) {
16890Sstevel@tonic-gate 		Is_desc	*isp = ifl->ifl_isdesc[shdr->sh_link];
16900Sstevel@tonic-gate 
169110792SRod.Evans@Sun.COM 		if ((isp == NULL) || ((isp->is_shdr->sh_type != SHT_SYMTAB) &&
16920Sstevel@tonic-gate 		    (isp->is_shdr->sh_type != SHT_DYNSYM))) {
16931618Srie 			eprintf(ofl->ofl_lml, ERR_FATAL,
16949878SAli.Bahrami@Sun.COM 			    MSG_INTL(MSG_FIL_INVSHLINK), ifl->ifl_name,
16959878SAli.Bahrami@Sun.COM 			    EC_WORD(ndx), name, EC_XWORD(shdr->sh_link));
16960Sstevel@tonic-gate 			return (S_ERROR);
16970Sstevel@tonic-gate 		}
16980Sstevel@tonic-gate 		isp->is_symshndx = ifl->ifl_isdesc[ndx];
16990Sstevel@tonic-gate 	}
17000Sstevel@tonic-gate 	return (1);
17010Sstevel@tonic-gate }
17020Sstevel@tonic-gate 
17030Sstevel@tonic-gate /*
17040Sstevel@tonic-gate  * Final processing for SHT_SYMTAB_SHNDX section.
17050Sstevel@tonic-gate  */
17061618Srie static uintptr_t
17070Sstevel@tonic-gate /* ARGSUSED2 */
17080Sstevel@tonic-gate sym_shndx_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
17090Sstevel@tonic-gate {
17100Sstevel@tonic-gate 	if (isc->is_shdr->sh_link > isc->is_scnndx) {
17110Sstevel@tonic-gate 		Is_desc	*isp = ifl->ifl_isdesc[isc->is_shdr->sh_link];
17120Sstevel@tonic-gate 
171310792SRod.Evans@Sun.COM 		if ((isp == NULL) || ((isp->is_shdr->sh_type != SHT_SYMTAB) &&
17140Sstevel@tonic-gate 		    (isp->is_shdr->sh_type != SHT_DYNSYM))) {
17151618Srie 			eprintf(ofl->ofl_lml, ERR_FATAL,
17161618Srie 			    MSG_INTL(MSG_FIL_INVSHLINK), isc->is_file->ifl_name,
17179878SAli.Bahrami@Sun.COM 			    EC_WORD(isc->is_scnndx), isc->is_name,
17189878SAli.Bahrami@Sun.COM 			    EC_XWORD(isc->is_shdr->sh_link));
17190Sstevel@tonic-gate 			return (S_ERROR);
17200Sstevel@tonic-gate 		}
17210Sstevel@tonic-gate 		isp->is_symshndx = isc;
17220Sstevel@tonic-gate 	}
17230Sstevel@tonic-gate 	return (1);
17240Sstevel@tonic-gate }
17250Sstevel@tonic-gate 
17260Sstevel@tonic-gate /*
17270Sstevel@tonic-gate  * Process .dynamic section from a relocatable object.
17280Sstevel@tonic-gate  *
17290Sstevel@tonic-gate  * Note: That the .dynamic section is only considered interesting when
17300Sstevel@tonic-gate  *	 dlopen()ing a relocatable object (thus FLG_OF1_RELDYN can only get
17310Sstevel@tonic-gate  *	 set when libld is called from ld.so.1).
17320Sstevel@tonic-gate  */
17330Sstevel@tonic-gate /*ARGSUSED*/
17341618Srie static uintptr_t
17350Sstevel@tonic-gate process_rel_dynamic(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
17360Sstevel@tonic-gate     Word ndx, int ident, Ofl_desc *ofl)
17370Sstevel@tonic-gate {
17380Sstevel@tonic-gate 	Dyn		*dyn;
17390Sstevel@tonic-gate 	Elf_Scn		*strscn;
17400Sstevel@tonic-gate 	Elf_Data	*dp;
17410Sstevel@tonic-gate 	char		*str;
17420Sstevel@tonic-gate 
17430Sstevel@tonic-gate 	/*
17440Sstevel@tonic-gate 	 * Process .dynamic sections from relocatable objects ?
17450Sstevel@tonic-gate 	 */
17460Sstevel@tonic-gate 	if ((ofl->ofl_flags1 & FLG_OF1_RELDYN) == 0)
17470Sstevel@tonic-gate 		return (1);
17480Sstevel@tonic-gate 
17490Sstevel@tonic-gate 	/*
17500Sstevel@tonic-gate 	 * Find the string section associated with the .dynamic section.
17510Sstevel@tonic-gate 	 */
17520Sstevel@tonic-gate 	if ((strscn = elf_getscn(ifl->ifl_elf, shdr->sh_link)) == NULL) {
17531618Srie 		eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN),
17541618Srie 		    ifl->ifl_name);
17550Sstevel@tonic-gate 		ofl->ofl_flags |= FLG_OF_FATAL;
17560Sstevel@tonic-gate 		return (0);
17570Sstevel@tonic-gate 	}
17580Sstevel@tonic-gate 	dp = elf_getdata(strscn, NULL);
17590Sstevel@tonic-gate 	str = (char *)dp->d_buf;
17600Sstevel@tonic-gate 
17610Sstevel@tonic-gate 	/*
17620Sstevel@tonic-gate 	 * And get the .dynamic data
17630Sstevel@tonic-gate 	 */
17640Sstevel@tonic-gate 	dp = elf_getdata(scn, NULL);
17650Sstevel@tonic-gate 
17660Sstevel@tonic-gate 	for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) {
17671109Srie 		Ifl_desc	*difl;
17680Sstevel@tonic-gate 
17690Sstevel@tonic-gate 		switch (dyn->d_tag) {
17700Sstevel@tonic-gate 		case DT_NEEDED:
17710Sstevel@tonic-gate 		case DT_USED:
17729131SRod.Evans@Sun.COM 			if (((difl = libld_calloc(1,
17739131SRod.Evans@Sun.COM 			    sizeof (Ifl_desc))) == NULL) ||
17749131SRod.Evans@Sun.COM 			    (aplist_append(&ofl->ofl_sos, difl,
17759131SRod.Evans@Sun.COM 			    AL_CNT_OFL_LIBS) == NULL))
17760Sstevel@tonic-gate 				return (S_ERROR);
17771109Srie 
17781109Srie 			difl->ifl_name = MSG_ORIG(MSG_STR_DYNAMIC);
17791109Srie 			difl->ifl_soname = str + (size_t)dyn->d_un.d_val;
17801109Srie 			difl->ifl_flags = FLG_IF_NEEDSTR;
17810Sstevel@tonic-gate 			break;
17820Sstevel@tonic-gate 		case DT_RPATH:
17830Sstevel@tonic-gate 		case DT_RUNPATH:
17840Sstevel@tonic-gate 			if ((ofl->ofl_rpath = add_string(ofl->ofl_rpath,
17850Sstevel@tonic-gate 			    (str + (size_t)dyn->d_un.d_val))) ==
17860Sstevel@tonic-gate 			    (const char *)S_ERROR)
17870Sstevel@tonic-gate 				return (S_ERROR);
17880Sstevel@tonic-gate 			break;
17894716Sab196087 		case DT_VERSYM:
17904716Sab196087 			/*
17914716Sab196087 			 * The Solaris ld does not put DT_VERSYM in the
17924716Sab196087 			 * dynamic section. If the object has DT_VERSYM,
17934716Sab196087 			 * then it must have been produced by the GNU ld,
17944716Sab196087 			 * and is using the GNU style of versioning.
17954716Sab196087 			 */
17964716Sab196087 			ifl->ifl_flags |= FLG_IF_GNUVER;
17974716Sab196087 			break;
17980Sstevel@tonic-gate 		}
17990Sstevel@tonic-gate 	}
18000Sstevel@tonic-gate 	return (1);
18010Sstevel@tonic-gate }
18020Sstevel@tonic-gate 
18030Sstevel@tonic-gate /*
18040Sstevel@tonic-gate  * Expand implicit references.  Dependencies can be specified in terms of the
180511827SRod.Evans@Sun.COM  * $ORIGIN, $MACHINE, $PLATFORM, $OSREL and $OSNAME tokens, either from their
180611827SRod.Evans@Sun.COM  * needed name, or via a runpath.  In addition runpaths may also specify the
180711827SRod.Evans@Sun.COM  * $ISALIST token.
18080Sstevel@tonic-gate  *
18091109Srie  * Probably the most common reference to explicit dependencies (via -L) will be
18100Sstevel@tonic-gate  * sufficient to find any associated implicit dependencies, but just in case we
18110Sstevel@tonic-gate  * expand any occurrence of these known tokens here.
18120Sstevel@tonic-gate  *
18130Sstevel@tonic-gate  * Note, if any errors occur we simply return the original name.
18140Sstevel@tonic-gate  *
18150Sstevel@tonic-gate  * This code is remarkably similar to expand() in rtld/common/paths.c.
18160Sstevel@tonic-gate  */
181711827SRod.Evans@Sun.COM static char		*machine = NULL;
181811827SRod.Evans@Sun.COM static size_t		machine_sz = 0;
181910792SRod.Evans@Sun.COM static char		*platform = NULL;
18200Sstevel@tonic-gate static size_t		platform_sz = 0;
182110792SRod.Evans@Sun.COM static Isa_desc		*isa = NULL;
182210792SRod.Evans@Sun.COM static Uts_desc		*uts = NULL;
18230Sstevel@tonic-gate 
18240Sstevel@tonic-gate static char *
18250Sstevel@tonic-gate expand(const char *parent, const char *name, char **next)
18260Sstevel@tonic-gate {
18270Sstevel@tonic-gate 	char		_name[PATH_MAX], *nptr, *_next;
18280Sstevel@tonic-gate 	const char	*optr;
18290Sstevel@tonic-gate 	size_t		nrem = PATH_MAX - 1;
18300Sstevel@tonic-gate 	int		expanded = 0, _expanded, isaflag = 0;
18310Sstevel@tonic-gate 
18320Sstevel@tonic-gate 	optr = name;
18330Sstevel@tonic-gate 	nptr = _name;
18340Sstevel@tonic-gate 
18350Sstevel@tonic-gate 	while (*optr) {
18360Sstevel@tonic-gate 		if (nrem == 0)
18370Sstevel@tonic-gate 			return ((char *)name);
18380Sstevel@tonic-gate 
18390Sstevel@tonic-gate 		if (*optr != '$') {
18400Sstevel@tonic-gate 			*nptr++ = *optr++, nrem--;
18410Sstevel@tonic-gate 			continue;
18420Sstevel@tonic-gate 		}
18430Sstevel@tonic-gate 
18440Sstevel@tonic-gate 		_expanded = 0;
18450Sstevel@tonic-gate 
18460Sstevel@tonic-gate 		if (strncmp(optr, MSG_ORIG(MSG_STR_ORIGIN),
18470Sstevel@tonic-gate 		    MSG_STR_ORIGIN_SIZE) == 0) {
18480Sstevel@tonic-gate 			char *eptr;
18490Sstevel@tonic-gate 
18500Sstevel@tonic-gate 			/*
18510Sstevel@tonic-gate 			 * For $ORIGIN, expansion is really just a concatenation
18520Sstevel@tonic-gate 			 * of the parents directory name.  For example, an
18531109Srie 			 * explicit dependency foo/bar/lib1.so with a dependency
18540Sstevel@tonic-gate 			 * on $ORIGIN/lib2.so would be expanded to
18550Sstevel@tonic-gate 			 * foo/bar/lib2.so.
18560Sstevel@tonic-gate 			 */
185710792SRod.Evans@Sun.COM 			if ((eptr = strrchr(parent, '/')) == NULL) {
18580Sstevel@tonic-gate 				*nptr++ = '.';
18590Sstevel@tonic-gate 				nrem--;
18600Sstevel@tonic-gate 			} else {
18610Sstevel@tonic-gate 				size_t	len = eptr - parent;
18620Sstevel@tonic-gate 
18630Sstevel@tonic-gate 				if (len >= nrem)
18640Sstevel@tonic-gate 					return ((char *)name);
18650Sstevel@tonic-gate 
18660Sstevel@tonic-gate 				(void) strncpy(nptr, parent, len);
18670Sstevel@tonic-gate 				nptr = nptr + len;
18680Sstevel@tonic-gate 				nrem -= len;
18690Sstevel@tonic-gate 			}
18700Sstevel@tonic-gate 			optr += MSG_STR_ORIGIN_SIZE;
18710Sstevel@tonic-gate 			expanded = _expanded = 1;
18720Sstevel@tonic-gate 
187311827SRod.Evans@Sun.COM 		} else if (strncmp(optr, MSG_ORIG(MSG_STR_MACHINE),
187411827SRod.Evans@Sun.COM 		    MSG_STR_MACHINE_SIZE) == 0) {
187511827SRod.Evans@Sun.COM 			/*
187611827SRod.Evans@Sun.COM 			 * Establish the machine from sysconf - like uname -i.
187711827SRod.Evans@Sun.COM 			 */
187811827SRod.Evans@Sun.COM 			if ((machine == NULL) && (machine_sz == 0)) {
187911827SRod.Evans@Sun.COM 				char	info[SYS_NMLN];
188011827SRod.Evans@Sun.COM 				long	size;
188111827SRod.Evans@Sun.COM 
188211827SRod.Evans@Sun.COM 				size = sysinfo(SI_MACHINE, info, SYS_NMLN);
188311827SRod.Evans@Sun.COM 				if ((size != -1) &&
188411827SRod.Evans@Sun.COM 				    (machine = libld_malloc((size_t)size))) {
188511827SRod.Evans@Sun.COM 					(void) strcpy(machine, info);
188611827SRod.Evans@Sun.COM 					machine_sz = (size_t)size - 1;
188711827SRod.Evans@Sun.COM 				} else
188811827SRod.Evans@Sun.COM 					machine_sz = 1;
188911827SRod.Evans@Sun.COM 			}
189011827SRod.Evans@Sun.COM 			if (machine) {
189111827SRod.Evans@Sun.COM 				if (machine_sz >= nrem)
189211827SRod.Evans@Sun.COM 					return ((char *)name);
189311827SRod.Evans@Sun.COM 
189411827SRod.Evans@Sun.COM 				(void) strncpy(nptr, machine, machine_sz);
189511827SRod.Evans@Sun.COM 				nptr = nptr + machine_sz;
189611827SRod.Evans@Sun.COM 				nrem -= machine_sz;
189711827SRod.Evans@Sun.COM 
189811827SRod.Evans@Sun.COM 				optr += MSG_STR_MACHINE_SIZE;
189911827SRod.Evans@Sun.COM 				expanded = _expanded = 1;
190011827SRod.Evans@Sun.COM 			}
190111827SRod.Evans@Sun.COM 
19020Sstevel@tonic-gate 		} else if (strncmp(optr, MSG_ORIG(MSG_STR_PLATFORM),
19030Sstevel@tonic-gate 		    MSG_STR_PLATFORM_SIZE) == 0) {
19040Sstevel@tonic-gate 			/*
19050Sstevel@tonic-gate 			 * Establish the platform from sysconf - like uname -i.
19060Sstevel@tonic-gate 			 */
190710792SRod.Evans@Sun.COM 			if ((platform == NULL) && (platform_sz == 0)) {
19080Sstevel@tonic-gate 				char	info[SYS_NMLN];
19090Sstevel@tonic-gate 				long	size;
19100Sstevel@tonic-gate 
19110Sstevel@tonic-gate 				size = sysinfo(SI_PLATFORM, info, SYS_NMLN);
19120Sstevel@tonic-gate 				if ((size != -1) &&
19130Sstevel@tonic-gate 				    (platform = libld_malloc((size_t)size))) {
19140Sstevel@tonic-gate 					(void) strcpy(platform, info);
19150Sstevel@tonic-gate 					platform_sz = (size_t)size - 1;
19160Sstevel@tonic-gate 				} else
19170Sstevel@tonic-gate 					platform_sz = 1;
19180Sstevel@tonic-gate 			}
191910792SRod.Evans@Sun.COM 			if (platform) {
19200Sstevel@tonic-gate 				if (platform_sz >= nrem)
19210Sstevel@tonic-gate 					return ((char *)name);
19220Sstevel@tonic-gate 
19230Sstevel@tonic-gate 				(void) strncpy(nptr, platform, platform_sz);
19240Sstevel@tonic-gate 				nptr = nptr + platform_sz;
19250Sstevel@tonic-gate 				nrem -= platform_sz;
19260Sstevel@tonic-gate 
19270Sstevel@tonic-gate 				optr += MSG_STR_PLATFORM_SIZE;
19280Sstevel@tonic-gate 				expanded = _expanded = 1;
19290Sstevel@tonic-gate 			}
19300Sstevel@tonic-gate 
19310Sstevel@tonic-gate 		} else if (strncmp(optr, MSG_ORIG(MSG_STR_OSNAME),
19320Sstevel@tonic-gate 		    MSG_STR_OSNAME_SIZE) == 0) {
19330Sstevel@tonic-gate 			/*
19340Sstevel@tonic-gate 			 * Establish the os name - like uname -s.
19350Sstevel@tonic-gate 			 */
193610792SRod.Evans@Sun.COM 			if (uts == NULL)
19370Sstevel@tonic-gate 				uts = conv_uts();
19380Sstevel@tonic-gate 
19390Sstevel@tonic-gate 			if (uts && uts->uts_osnamesz) {
19400Sstevel@tonic-gate 				if (uts->uts_osnamesz >= nrem)
19410Sstevel@tonic-gate 					return ((char *)name);
19420Sstevel@tonic-gate 
19430Sstevel@tonic-gate 				(void) strncpy(nptr, uts->uts_osname,
19440Sstevel@tonic-gate 				    uts->uts_osnamesz);
19450Sstevel@tonic-gate 				nptr = nptr + uts->uts_osnamesz;
19460Sstevel@tonic-gate 				nrem -= uts->uts_osnamesz;
19470Sstevel@tonic-gate 
19480Sstevel@tonic-gate 				optr += MSG_STR_OSNAME_SIZE;
19490Sstevel@tonic-gate 				expanded = _expanded = 1;
19500Sstevel@tonic-gate 			}
19510Sstevel@tonic-gate 
19520Sstevel@tonic-gate 		} else if (strncmp(optr, MSG_ORIG(MSG_STR_OSREL),
19530Sstevel@tonic-gate 		    MSG_STR_OSREL_SIZE) == 0) {
19540Sstevel@tonic-gate 			/*
19550Sstevel@tonic-gate 			 * Establish the os release - like uname -r.
19560Sstevel@tonic-gate 			 */
195710792SRod.Evans@Sun.COM 			if (uts == NULL)
19580Sstevel@tonic-gate 				uts = conv_uts();
19590Sstevel@tonic-gate 
19600Sstevel@tonic-gate 			if (uts && uts->uts_osrelsz) {
19610Sstevel@tonic-gate 				if (uts->uts_osrelsz >= nrem)
19620Sstevel@tonic-gate 					return ((char *)name);
19630Sstevel@tonic-gate 
19640Sstevel@tonic-gate 				(void) strncpy(nptr, uts->uts_osrel,
19650Sstevel@tonic-gate 				    uts->uts_osrelsz);
19660Sstevel@tonic-gate 				nptr = nptr + uts->uts_osrelsz;
19670Sstevel@tonic-gate 				nrem -= uts->uts_osrelsz;
19680Sstevel@tonic-gate 
19690Sstevel@tonic-gate 				optr += MSG_STR_OSREL_SIZE;
19700Sstevel@tonic-gate 				expanded = _expanded = 1;
19710Sstevel@tonic-gate 			}
19720Sstevel@tonic-gate 
19730Sstevel@tonic-gate 		} else if ((strncmp(optr, MSG_ORIG(MSG_STR_ISALIST),
19740Sstevel@tonic-gate 		    MSG_STR_ISALIST_SIZE) == 0) && next && (isaflag++ == 0)) {
19750Sstevel@tonic-gate 			/*
19760Sstevel@tonic-gate 			 * Establish instruction sets from sysconf.  Note that
19770Sstevel@tonic-gate 			 * this is only meaningful from runpaths.
19780Sstevel@tonic-gate 			 */
197910792SRod.Evans@Sun.COM 			if (isa == NULL)
19800Sstevel@tonic-gate 				isa = conv_isalist();
19810Sstevel@tonic-gate 
19820Sstevel@tonic-gate 			if (isa && isa->isa_listsz &&
19830Sstevel@tonic-gate 			    (nrem > isa->isa_opt->isa_namesz)) {
19840Sstevel@tonic-gate 				size_t		mlen, tlen, hlen = optr - name;
19850Sstevel@tonic-gate 				size_t		no;
19860Sstevel@tonic-gate 				char		*lptr;
19870Sstevel@tonic-gate 				Isa_opt		*opt = isa->isa_opt;
19880Sstevel@tonic-gate 
19890Sstevel@tonic-gate 				(void) strncpy(nptr, opt->isa_name,
19900Sstevel@tonic-gate 				    opt->isa_namesz);
19910Sstevel@tonic-gate 				nptr = nptr + opt->isa_namesz;
19920Sstevel@tonic-gate 				nrem -= opt->isa_namesz;
19930Sstevel@tonic-gate 
19940Sstevel@tonic-gate 				optr += MSG_STR_ISALIST_SIZE;
19950Sstevel@tonic-gate 				expanded = _expanded = 1;
19960Sstevel@tonic-gate 
19970Sstevel@tonic-gate 				tlen = strlen(optr);
19980Sstevel@tonic-gate 
19990Sstevel@tonic-gate 				/*
20000Sstevel@tonic-gate 				 * As ISALIST expands to a number of elements,
20010Sstevel@tonic-gate 				 * establish a new list to return to the caller.
20020Sstevel@tonic-gate 				 * This will contain the present path being
20030Sstevel@tonic-gate 				 * processed redefined for each isalist option,
20040Sstevel@tonic-gate 				 * plus the original remaining list entries.
20050Sstevel@tonic-gate 				 */
20060Sstevel@tonic-gate 				mlen = ((hlen + tlen) * (isa->isa_optno - 1)) +
20070Sstevel@tonic-gate 				    isa->isa_listsz - opt->isa_namesz;
20080Sstevel@tonic-gate 				if (*next)
20094716Sab196087 					mlen += strlen(*next);
201010792SRod.Evans@Sun.COM 				if ((_next = lptr = libld_malloc(mlen)) == NULL)
20110Sstevel@tonic-gate 					return (0);
20120Sstevel@tonic-gate 
20130Sstevel@tonic-gate 				for (no = 1, opt++; no < isa->isa_optno;
20140Sstevel@tonic-gate 				    no++, opt++) {
20150Sstevel@tonic-gate 					(void) strncpy(lptr, name, hlen);
20160Sstevel@tonic-gate 					lptr = lptr + hlen;
20170Sstevel@tonic-gate 					(void) strncpy(lptr, opt->isa_name,
20180Sstevel@tonic-gate 					    opt->isa_namesz);
20190Sstevel@tonic-gate 					lptr = lptr + opt->isa_namesz;
20200Sstevel@tonic-gate 					(void) strncpy(lptr, optr, tlen);
20210Sstevel@tonic-gate 					lptr = lptr + tlen;
20220Sstevel@tonic-gate 					*lptr++ = ':';
20230Sstevel@tonic-gate 				}
20240Sstevel@tonic-gate 				if (*next)
20250Sstevel@tonic-gate 					(void) strcpy(lptr, *next);
20260Sstevel@tonic-gate 				else
20270Sstevel@tonic-gate 					*--lptr = '\0';
20280Sstevel@tonic-gate 			}
20290Sstevel@tonic-gate 		}
20300Sstevel@tonic-gate 
20310Sstevel@tonic-gate 		/*
20320Sstevel@tonic-gate 		 * If no expansion occurred skip the $ and continue.
20330Sstevel@tonic-gate 		 */
20340Sstevel@tonic-gate 		if (_expanded == 0)
20350Sstevel@tonic-gate 			*nptr++ = *optr++, nrem--;
20360Sstevel@tonic-gate 	}
20370Sstevel@tonic-gate 
20380Sstevel@tonic-gate 	/*
20390Sstevel@tonic-gate 	 * If any ISALIST processing has occurred not only do we return the
20400Sstevel@tonic-gate 	 * expanded node we're presently working on, but we must also update the
20410Sstevel@tonic-gate 	 * remaining list so that it is effectively prepended with this node
20420Sstevel@tonic-gate 	 * expanded to all remaining isalist options.  Note that we can only
20430Sstevel@tonic-gate 	 * handle one ISALIST per node.  For more than one ISALIST to be
20440Sstevel@tonic-gate 	 * processed we'd need a better algorithm than above to replace the
20450Sstevel@tonic-gate 	 * newly generated list.  Whether we want to encourage the number of
20460Sstevel@tonic-gate 	 * pathname permutations this would provide is another question. So, for
20470Sstevel@tonic-gate 	 * now if more than one ISALIST is encountered we return the original
20480Sstevel@tonic-gate 	 * node untouched.
20490Sstevel@tonic-gate 	 */
20500Sstevel@tonic-gate 	if (isaflag) {
20510Sstevel@tonic-gate 		if (isaflag == 1)
20520Sstevel@tonic-gate 			*next = _next;
20530Sstevel@tonic-gate 		else
20540Sstevel@tonic-gate 			return ((char *)name);
20550Sstevel@tonic-gate 	}
20560Sstevel@tonic-gate 
20570Sstevel@tonic-gate 	*nptr = '\0';
20580Sstevel@tonic-gate 
20590Sstevel@tonic-gate 	if (expanded) {
206010792SRod.Evans@Sun.COM 		if ((nptr = libld_malloc(strlen(_name) + 1)) == NULL)
20610Sstevel@tonic-gate 			return ((char *)name);
20620Sstevel@tonic-gate 		(void) strcpy(nptr, _name);
20630Sstevel@tonic-gate 		return (nptr);
20640Sstevel@tonic-gate 	}
20650Sstevel@tonic-gate 	return ((char *)name);
20660Sstevel@tonic-gate }
20670Sstevel@tonic-gate 
20680Sstevel@tonic-gate /*
20694716Sab196087  * The Solaris ld does not put DT_VERSYM in the dynamic section, but the
20704716Sab196087  * GNU ld does, and it is used by the runtime linker to implement their
20714716Sab196087  * versioning scheme. Use this fact to determine if the sharable object
20724716Sab196087  * was produced by the GNU ld rather than the Solaris one, and to set
20734716Sab196087  * FLG_IF_GNUVER if so. This needs to be done before the symbols are
20744716Sab196087  * processed, since the answer determines whether we interpret the
20754716Sab196087  * symbols versions according to Solaris or GNU rules.
20764716Sab196087  */
20774716Sab196087 /*ARGSUSED*/
20784716Sab196087 static uintptr_t
20794716Sab196087 process_dynamic_isgnu(const char *name, Ifl_desc *ifl, Shdr *shdr,
20804716Sab196087     Elf_Scn *scn, Word ndx, int ident, Ofl_desc *ofl)
20814716Sab196087 {
20824716Sab196087 	Dyn		*dyn;
20834716Sab196087 	Elf_Data	*dp;
20847463SRod.Evans@Sun.COM 	uintptr_t	error;
20854716Sab196087 
20867463SRod.Evans@Sun.COM 	error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
20877463SRod.Evans@Sun.COM 	if ((error == 0) || (error == S_ERROR))
20887463SRod.Evans@Sun.COM 		return (error);
20894716Sab196087 
20904716Sab196087 	/* Get the .dynamic data */
20914716Sab196087 	dp = elf_getdata(scn, NULL);
20924716Sab196087 
20934716Sab196087 	for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) {
20944716Sab196087 		if (dyn->d_tag == DT_VERSYM) {
20954716Sab196087 			ifl->ifl_flags |= FLG_IF_GNUVER;
20964716Sab196087 			break;
20974716Sab196087 		}
20984716Sab196087 	}
20994716Sab196087 	return (1);
21004716Sab196087 }
21014716Sab196087 
21024716Sab196087 /*
21030Sstevel@tonic-gate  * Process a dynamic section.  If we are processing an explicit shared object
21040Sstevel@tonic-gate  * then we need to determine if it has a recorded SONAME, if so, this name will
21050Sstevel@tonic-gate  * be recorded in the output file being generated as the NEEDED entry rather
21060Sstevel@tonic-gate  * than the shared objects filename itself.
21070Sstevel@tonic-gate  * If the mode of the link-edit indicates that no undefined symbols should
21080Sstevel@tonic-gate  * remain, then we also need to build up a list of any additional shared object
21090Sstevel@tonic-gate  * dependencies this object may have.  In this case save any NEEDED entries
21100Sstevel@tonic-gate  * together with any associated run-path specifications.  This information is
21110Sstevel@tonic-gate  * recorded on the `ofl_soneed' list and will be analyzed after all explicit
21120Sstevel@tonic-gate  * file processing has been completed (refer finish_libs()).
21130Sstevel@tonic-gate  */
21141618Srie static uintptr_t
21150Sstevel@tonic-gate process_dynamic(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
21160Sstevel@tonic-gate {
21170Sstevel@tonic-gate 	Dyn		*data, *dyn;
21180Sstevel@tonic-gate 	char		*str, *rpath = NULL;
21190Sstevel@tonic-gate 	const char	*soname, *needed;
21200Sstevel@tonic-gate 
21210Sstevel@tonic-gate 	data = (Dyn *)isc->is_indata->d_buf;
21220Sstevel@tonic-gate 	str = (char *)ifl->ifl_isdesc[isc->is_shdr->sh_link]->is_indata->d_buf;
21230Sstevel@tonic-gate 
21240Sstevel@tonic-gate 	/*
21250Sstevel@tonic-gate 	 * First loop through the dynamic section looking for a run path.
21260Sstevel@tonic-gate 	 */
21270Sstevel@tonic-gate 	if (ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)) {
21280Sstevel@tonic-gate 		for (dyn = data; dyn->d_tag != DT_NULL; dyn++) {
21290Sstevel@tonic-gate 			if ((dyn->d_tag != DT_RPATH) &&
21300Sstevel@tonic-gate 			    (dyn->d_tag != DT_RUNPATH))
21310Sstevel@tonic-gate 				continue;
21320Sstevel@tonic-gate 			if ((rpath = str + (size_t)dyn->d_un.d_val) == NULL)
21330Sstevel@tonic-gate 				continue;
21340Sstevel@tonic-gate 			break;
21350Sstevel@tonic-gate 		}
21360Sstevel@tonic-gate 	}
21370Sstevel@tonic-gate 
21380Sstevel@tonic-gate 	/*
21390Sstevel@tonic-gate 	 * Now look for any needed dependencies (which may use the rpath)
21400Sstevel@tonic-gate 	 * or a new SONAME.
21410Sstevel@tonic-gate 	 */
21420Sstevel@tonic-gate 	for (dyn = data; dyn->d_tag != DT_NULL; dyn++) {
21430Sstevel@tonic-gate 		if (dyn->d_tag == DT_SONAME) {
21440Sstevel@tonic-gate 			if ((soname = str + (size_t)dyn->d_un.d_val) == NULL)
21450Sstevel@tonic-gate 				continue;
21460Sstevel@tonic-gate 
21470Sstevel@tonic-gate 			/*
21480Sstevel@tonic-gate 			 * Update the input file structure with this new name.
21490Sstevel@tonic-gate 			 */
21500Sstevel@tonic-gate 			ifl->ifl_soname = soname;
21510Sstevel@tonic-gate 
21520Sstevel@tonic-gate 		} else if ((dyn->d_tag == DT_NEEDED) ||
21530Sstevel@tonic-gate 		    (dyn->d_tag == DT_USED)) {
21549131SRod.Evans@Sun.COM 			Sdf_desc	*sdf;
21559131SRod.Evans@Sun.COM 
21560Sstevel@tonic-gate 			if (!(ofl->ofl_flags &
21570Sstevel@tonic-gate 			    (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)))
21580Sstevel@tonic-gate 				continue;
21590Sstevel@tonic-gate 			if ((needed = str + (size_t)dyn->d_un.d_val) == NULL)
21600Sstevel@tonic-gate 				continue;
21610Sstevel@tonic-gate 
21620Sstevel@tonic-gate 			/*
21630Sstevel@tonic-gate 			 * Determine if this needed entry is already recorded on
21640Sstevel@tonic-gate 			 * the shared object needed list, if not create a new
21650Sstevel@tonic-gate 			 * definition for later processing (see finish_libs()).
21660Sstevel@tonic-gate 			 */
21679131SRod.Evans@Sun.COM 			needed = expand(ifl->ifl_name, needed, NULL);
21680Sstevel@tonic-gate 
21699131SRod.Evans@Sun.COM 			if ((sdf = sdf_find(needed, ofl->ofl_soneed)) == NULL) {
21700Sstevel@tonic-gate 				if ((sdf = sdf_add(needed,
21710Sstevel@tonic-gate 				    &ofl->ofl_soneed)) == (Sdf_desc *)S_ERROR)
21720Sstevel@tonic-gate 					return (S_ERROR);
21730Sstevel@tonic-gate 				sdf->sdf_rfile = ifl->ifl_name;
21740Sstevel@tonic-gate 			}
21750Sstevel@tonic-gate 
21760Sstevel@tonic-gate 			/*
21770Sstevel@tonic-gate 			 * Record the runpath (Note that we take the first
21780Sstevel@tonic-gate 			 * runpath which is exactly what ld.so.1 would do during
21790Sstevel@tonic-gate 			 * its dependency processing).
21800Sstevel@tonic-gate 			 */
218110792SRod.Evans@Sun.COM 			if (rpath && (sdf->sdf_rpath == NULL))
21820Sstevel@tonic-gate 				sdf->sdf_rpath = rpath;
21830Sstevel@tonic-gate 
21840Sstevel@tonic-gate 		} else if (dyn->d_tag == DT_FLAGS_1) {
21850Sstevel@tonic-gate 			if (dyn->d_un.d_val & (DF_1_INITFIRST | DF_1_INTERPOSE))
21860Sstevel@tonic-gate 				ifl->ifl_flags &= ~FLG_IF_LAZYLD;
21870Sstevel@tonic-gate 			if (dyn->d_un.d_val & DF_1_DISPRELPND)
21880Sstevel@tonic-gate 				ifl->ifl_flags |= FLG_IF_DISPPEND;
21890Sstevel@tonic-gate 			if (dyn->d_un.d_val & DF_1_DISPRELDNE)
21900Sstevel@tonic-gate 				ifl->ifl_flags |= FLG_IF_DISPDONE;
21910Sstevel@tonic-gate 			if (dyn->d_un.d_val & DF_1_NODIRECT)
21920Sstevel@tonic-gate 				ifl->ifl_flags |= FLG_IF_NODIRECT;
21930Sstevel@tonic-gate 
21940Sstevel@tonic-gate 		} else if ((dyn->d_tag == DT_AUDIT) &&
21950Sstevel@tonic-gate 		    (ifl->ifl_flags & FLG_IF_NEEDED)) {
21960Sstevel@tonic-gate 			/*
21970Sstevel@tonic-gate 			 * Record audit string as DT_DEPAUDIT.
21980Sstevel@tonic-gate 			 */
21990Sstevel@tonic-gate 			if ((ofl->ofl_depaudit = add_string(ofl->ofl_depaudit,
22000Sstevel@tonic-gate 			    (str + (size_t)dyn->d_un.d_val))) ==
22010Sstevel@tonic-gate 			    (const char *)S_ERROR)
22020Sstevel@tonic-gate 				return (S_ERROR);
22030Sstevel@tonic-gate 
22040Sstevel@tonic-gate 		} else if (dyn->d_tag == DT_SUNW_RTLDINF) {
22050Sstevel@tonic-gate 			/*
22060Sstevel@tonic-gate 			 * If a library has the SUNW_RTLDINF .dynamic entry
22070Sstevel@tonic-gate 			 * then we must not permit lazyloading of this library.
22080Sstevel@tonic-gate 			 * This is because critical startup information (TLS
22090Sstevel@tonic-gate 			 * routines) are provided as part of these interfaces
22100Sstevel@tonic-gate 			 * and we must have them as part of process startup.
22110Sstevel@tonic-gate 			 */
22120Sstevel@tonic-gate 			ifl->ifl_flags &= ~FLG_IF_LAZYLD;
22130Sstevel@tonic-gate 		}
22140Sstevel@tonic-gate 	}
22150Sstevel@tonic-gate 
22160Sstevel@tonic-gate 	/*
22170Sstevel@tonic-gate 	 * Perform some SONAME sanity checks.
22180Sstevel@tonic-gate 	 */
22190Sstevel@tonic-gate 	if (ifl->ifl_flags & FLG_IF_NEEDED) {
22207463SRod.Evans@Sun.COM 		Ifl_desc	*sifl;
22219131SRod.Evans@Sun.COM 		Aliste		idx;
22220Sstevel@tonic-gate 
22230Sstevel@tonic-gate 		/*
22240Sstevel@tonic-gate 		 * Determine if anyone else will cause the same SONAME to be
22250Sstevel@tonic-gate 		 * used (this is either caused by two different files having the
22260Sstevel@tonic-gate 		 * same SONAME, or by one file SONAME actually matching another
22270Sstevel@tonic-gate 		 * file basename (if no SONAME is specified within a shared
22280Sstevel@tonic-gate 		 * library its basename will be used)). Probably rare, but some
22290Sstevel@tonic-gate 		 * idiot will do it.
22300Sstevel@tonic-gate 		 */
22319131SRod.Evans@Sun.COM 		for (APLIST_TRAVERSE(ofl->ofl_sos, idx, sifl)) {
22320Sstevel@tonic-gate 			if ((strcmp(ifl->ifl_soname, sifl->ifl_soname) == 0) &&
22330Sstevel@tonic-gate 			    (ifl != sifl)) {
22340Sstevel@tonic-gate 				const char	*hint, *iflb, *siflb;
22350Sstevel@tonic-gate 
22360Sstevel@tonic-gate 				/*
22370Sstevel@tonic-gate 				 * Determine the basename of each file. Perhaps
22380Sstevel@tonic-gate 				 * there are multiple copies of the same file
22390Sstevel@tonic-gate 				 * being brought in using different -L search
22400Sstevel@tonic-gate 				 * paths, and if so give an extra hint in the
22410Sstevel@tonic-gate 				 * error message.
22420Sstevel@tonic-gate 				 */
22430Sstevel@tonic-gate 				iflb = strrchr(ifl->ifl_name, '/');
22440Sstevel@tonic-gate 				if (iflb == NULL)
22450Sstevel@tonic-gate 					iflb = ifl->ifl_name;
22460Sstevel@tonic-gate 				else
22470Sstevel@tonic-gate 					iflb++;
22480Sstevel@tonic-gate 
22490Sstevel@tonic-gate 				siflb = strrchr(sifl->ifl_name, '/');
22500Sstevel@tonic-gate 				if (siflb == NULL)
22510Sstevel@tonic-gate 					siflb = sifl->ifl_name;
22520Sstevel@tonic-gate 				else
22530Sstevel@tonic-gate 					siflb++;
22540Sstevel@tonic-gate 
22550Sstevel@tonic-gate 				if (strcmp(iflb, siflb) == 0)
22560Sstevel@tonic-gate 					hint = MSG_INTL(MSG_REC_CNFLTHINT);
22570Sstevel@tonic-gate 				else
22580Sstevel@tonic-gate 					hint = MSG_ORIG(MSG_STR_EMPTY);
22590Sstevel@tonic-gate 
22601618Srie 				eprintf(ofl->ofl_lml, ERR_FATAL,
22611618Srie 				    MSG_INTL(MSG_REC_OBJCNFLT), sifl->ifl_name,
22621618Srie 				    ifl->ifl_name, sifl->ifl_soname, hint);
22630Sstevel@tonic-gate 				ofl->ofl_flags |= FLG_OF_FATAL;
22640Sstevel@tonic-gate 				return (0);
22650Sstevel@tonic-gate 			}
22660Sstevel@tonic-gate 		}
22670Sstevel@tonic-gate 
22680Sstevel@tonic-gate 		/*
22690Sstevel@tonic-gate 		 * If the SONAME is the same as the name the user wishes to
22700Sstevel@tonic-gate 		 * record when building a dynamic library (refer -h option),
22710Sstevel@tonic-gate 		 * we also have a name clash.
22720Sstevel@tonic-gate 		 */
22730Sstevel@tonic-gate 		if (ofl->ofl_soname &&
22740Sstevel@tonic-gate 		    (strcmp(ofl->ofl_soname, ifl->ifl_soname) == 0)) {
22751618Srie 			eprintf(ofl->ofl_lml, ERR_FATAL,
22761618Srie 			    MSG_INTL(MSG_REC_OPTCNFLT), ifl->ifl_name,
22777983SAli.Bahrami@Sun.COM 			    MSG_INTL(MSG_MARG_SONAME), ifl->ifl_soname);
22780Sstevel@tonic-gate 			ofl->ofl_flags |= FLG_OF_FATAL;
22790Sstevel@tonic-gate 			return (0);
22800Sstevel@tonic-gate 		}
22810Sstevel@tonic-gate 	}
22820Sstevel@tonic-gate 	return (1);
22830Sstevel@tonic-gate }
22840Sstevel@tonic-gate 
22850Sstevel@tonic-gate /*
22869085SAli.Bahrami@Sun.COM  * Process a progbits section from a relocatable object (ET_REL).
22879085SAli.Bahrami@Sun.COM  * This is used on non-amd64 objects to recognize .eh_frame sections.
22889085SAli.Bahrami@Sun.COM  */
22899085SAli.Bahrami@Sun.COM /*ARGSUSED1*/
22909085SAli.Bahrami@Sun.COM static uintptr_t
22919085SAli.Bahrami@Sun.COM process_progbits_final(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
22929085SAli.Bahrami@Sun.COM {
22939085SAli.Bahrami@Sun.COM 	if (isc->is_osdesc && (isc->is_flags & FLG_IS_EHFRAME) &&
22949085SAli.Bahrami@Sun.COM 	    (ld_unwind_register(isc->is_osdesc, ofl) == S_ERROR))
22959085SAli.Bahrami@Sun.COM 		return (S_ERROR);
22969085SAli.Bahrami@Sun.COM 
22979085SAli.Bahrami@Sun.COM 	return (1);
22989085SAli.Bahrami@Sun.COM }
22999085SAli.Bahrami@Sun.COM 
23009085SAli.Bahrami@Sun.COM /*
23017463SRod.Evans@Sun.COM  * Process a group section.
23027463SRod.Evans@Sun.COM  */
23037463SRod.Evans@Sun.COM static uintptr_t
23047463SRod.Evans@Sun.COM process_group(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
23057463SRod.Evans@Sun.COM     Word ndx, int ident, Ofl_desc *ofl)
23067463SRod.Evans@Sun.COM {
23077463SRod.Evans@Sun.COM 	uintptr_t	error;
23087463SRod.Evans@Sun.COM 
23097463SRod.Evans@Sun.COM 	error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
23107463SRod.Evans@Sun.COM 	if ((error == 0) || (error == S_ERROR))
23117463SRod.Evans@Sun.COM 		return (error);
23127463SRod.Evans@Sun.COM 
23137463SRod.Evans@Sun.COM 	/*
23147463SRod.Evans@Sun.COM 	 * Indicate that this input file has groups to process.  Groups are
23157463SRod.Evans@Sun.COM 	 * processed after all input sections have been processed.
23167463SRod.Evans@Sun.COM 	 */
23177463SRod.Evans@Sun.COM 	ifl->ifl_flags |= FLG_IS_GROUPS;
23187463SRod.Evans@Sun.COM 
23197463SRod.Evans@Sun.COM 	return (1);
23207463SRod.Evans@Sun.COM }
23217463SRod.Evans@Sun.COM 
23227463SRod.Evans@Sun.COM /*
23230Sstevel@tonic-gate  * Process a relocation entry. At this point all input sections from this
23240Sstevel@tonic-gate  * input file have been assigned an input section descriptor which is saved
23250Sstevel@tonic-gate  * in the `ifl_isdesc' array.
23260Sstevel@tonic-gate  */
23271618Srie static uintptr_t
23280Sstevel@tonic-gate rel_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
23290Sstevel@tonic-gate {
23300Sstevel@tonic-gate 	Word 	rndx;
23310Sstevel@tonic-gate 	Is_desc	*risc;
23320Sstevel@tonic-gate 	Os_desc	*osp;
23330Sstevel@tonic-gate 	Shdr	*shdr = isc->is_shdr;
23344734Sab196087 	Conv_inv_buf_t inv_buf;
23350Sstevel@tonic-gate 
23360Sstevel@tonic-gate 	/*
23370Sstevel@tonic-gate 	 * Make sure this is a valid relocation we can handle.
23380Sstevel@tonic-gate 	 */
23396206Sab196087 	if (shdr->sh_type != ld_targ.t_m.m_rel_sht_type) {
23401618Srie 		eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_FIL_INVALSEC),
23419878SAli.Bahrami@Sun.COM 		    ifl->ifl_name, EC_WORD(isc->is_scnndx), isc->is_name,
23429273SAli.Bahrami@Sun.COM 		    conv_sec_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
23439273SAli.Bahrami@Sun.COM 		    ifl->ifl_ehdr->e_machine, shdr->sh_type, 0, &inv_buf));
23440Sstevel@tonic-gate 		ofl->ofl_flags |= FLG_OF_FATAL;
23450Sstevel@tonic-gate 		return (0);
23460Sstevel@tonic-gate 	}
23470Sstevel@tonic-gate 
23480Sstevel@tonic-gate 	/*
23490Sstevel@tonic-gate 	 * From the relocation section header information determine which
23500Sstevel@tonic-gate 	 * section needs the actual relocation.  Determine which output section
23510Sstevel@tonic-gate 	 * this input section has been assigned to and add to its relocation
23520Sstevel@tonic-gate 	 * list.  Note that the relocation section may be null if it is not
23530Sstevel@tonic-gate 	 * required (ie. .debug, .stabs, etc).
23540Sstevel@tonic-gate 	 */
23550Sstevel@tonic-gate 	rndx = shdr->sh_info;
23560Sstevel@tonic-gate 	if (rndx >= ifl->ifl_shnum) {
23570Sstevel@tonic-gate 		/*
23580Sstevel@tonic-gate 		 * Broken input file.
23590Sstevel@tonic-gate 		 */
23601618Srie 		eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHINFO),
23619878SAli.Bahrami@Sun.COM 		    ifl->ifl_name, EC_WORD(isc->is_scnndx), isc->is_name,
23629878SAli.Bahrami@Sun.COM 		    EC_XWORD(rndx));
23630Sstevel@tonic-gate 		ofl->ofl_flags |= FLG_OF_FATAL;
23640Sstevel@tonic-gate 		return (0);
23650Sstevel@tonic-gate 	}
23660Sstevel@tonic-gate 	if (rndx == 0) {
23679131SRod.Evans@Sun.COM 		if (aplist_append(&ofl->ofl_extrarels, isc,
23689131SRod.Evans@Sun.COM 		    AL_CNT_OFL_RELS) == NULL)
23690Sstevel@tonic-gate 			return (S_ERROR);
23709131SRod.Evans@Sun.COM 
23719131SRod.Evans@Sun.COM 	} else if ((risc = ifl->ifl_isdesc[rndx]) != NULL) {
23720Sstevel@tonic-gate 		/*
23730Sstevel@tonic-gate 		 * Discard relocations if they are against a section
23740Sstevel@tonic-gate 		 * which has been discarded.
23750Sstevel@tonic-gate 		 */
23760Sstevel@tonic-gate 		if (risc->is_flags & FLG_IS_DISCARD)
23770Sstevel@tonic-gate 			return (1);
23789131SRod.Evans@Sun.COM 
23799131SRod.Evans@Sun.COM 		if ((osp = risc->is_osdesc) == NULL) {
23800Sstevel@tonic-gate 			if (risc->is_shdr->sh_type == SHT_SUNW_move) {
23810Sstevel@tonic-gate 				/*
23829131SRod.Evans@Sun.COM 				 * This section is processed later in
23839131SRod.Evans@Sun.COM 				 * process_movereloc().
23840Sstevel@tonic-gate 				 */
23859131SRod.Evans@Sun.COM 				if (aplist_append(&ofl->ofl_ismoverel,
23869131SRod.Evans@Sun.COM 				    isc, AL_CNT_OFL_MOVE) == NULL)
23870Sstevel@tonic-gate 					return (S_ERROR);
23880Sstevel@tonic-gate 				return (1);
23890Sstevel@tonic-gate 			}
23901618Srie 			eprintf(ofl->ofl_lml, ERR_FATAL,
23911618Srie 			    MSG_INTL(MSG_FIL_INVRELOC1), ifl->ifl_name,
23929878SAli.Bahrami@Sun.COM 			    EC_WORD(isc->is_scnndx), isc->is_name,
23939878SAli.Bahrami@Sun.COM 			    EC_WORD(risc->is_scnndx), risc->is_name);
23940Sstevel@tonic-gate 			return (0);
23950Sstevel@tonic-gate 		}
23968608SAli.Bahrami@Sun.COM 		if (aplist_append(&osp->os_relisdescs, isc,
23978608SAli.Bahrami@Sun.COM 		    AL_CNT_OS_RELISDESCS) == NULL)
23980Sstevel@tonic-gate 			return (S_ERROR);
23990Sstevel@tonic-gate 	}
24000Sstevel@tonic-gate 	return (1);
24010Sstevel@tonic-gate }
24020Sstevel@tonic-gate 
24030Sstevel@tonic-gate /*
24040Sstevel@tonic-gate  * SHF_EXCLUDE flags is set for this section.
24050Sstevel@tonic-gate  */
24060Sstevel@tonic-gate static uintptr_t
24070Sstevel@tonic-gate process_exclude(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
24080Sstevel@tonic-gate     Word ndx, Ofl_desc *ofl)
24090Sstevel@tonic-gate {
24100Sstevel@tonic-gate 	/*
24110Sstevel@tonic-gate 	 * Sections SHT_SYMTAB and SHT_DYNDYM, even if SHF_EXCLUDE is on, might
24120Sstevel@tonic-gate 	 * be needed for ld processing.  These sections need to be in the
24130Sstevel@tonic-gate 	 * internal table.  Later it will be determined whether they can be
24140Sstevel@tonic-gate 	 * eliminated or not.
24150Sstevel@tonic-gate 	 */
24160Sstevel@tonic-gate 	if (shdr->sh_type == SHT_SYMTAB || shdr->sh_type == SHT_DYNSYM)
24170Sstevel@tonic-gate 		return (0);
24180Sstevel@tonic-gate 
24190Sstevel@tonic-gate 	/*
24200Sstevel@tonic-gate 	 * Other checks
24210Sstevel@tonic-gate 	 */
24220Sstevel@tonic-gate 	if (shdr->sh_flags & SHF_ALLOC) {
24230Sstevel@tonic-gate 		/*
24240Sstevel@tonic-gate 		 * A conflict, issue an warning message, and ignore the section.
24250Sstevel@tonic-gate 		 */
24261618Srie 		eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_FIL_EXCLUDE),
24279878SAli.Bahrami@Sun.COM 		    ifl->ifl_name, EC_WORD(ndx), name);
24280Sstevel@tonic-gate 		return (0);
24290Sstevel@tonic-gate 	}
24300Sstevel@tonic-gate 
24310Sstevel@tonic-gate 	/*
24320Sstevel@tonic-gate 	 * This sections is not going to the output file.
24330Sstevel@tonic-gate 	 */
24340Sstevel@tonic-gate 	return (process_section(name, ifl, shdr, scn, ndx, 0, ofl));
24350Sstevel@tonic-gate }
24360Sstevel@tonic-gate 
24370Sstevel@tonic-gate /*
24380Sstevel@tonic-gate  * Section processing state table.  `Initial' describes the required initial
24390Sstevel@tonic-gate  * procedure to be called (if any), `Final' describes the final processing
24400Sstevel@tonic-gate  * procedure (ie. things that can only be done when all required sections
24410Sstevel@tonic-gate  * have been collected).
24420Sstevel@tonic-gate  */
24439085SAli.Bahrami@Sun.COM typedef uintptr_t	(* initial_func_t)(const char *, Ifl_desc *, Shdr *,
24449085SAli.Bahrami@Sun.COM 			    Elf_Scn *, Word, int, Ofl_desc *);
24450Sstevel@tonic-gate 
24469085SAli.Bahrami@Sun.COM static initial_func_t Initial[SHT_NUM][2] = {
24470Sstevel@tonic-gate /*			ET_REL			ET_DYN			*/
24480Sstevel@tonic-gate 
24490Sstevel@tonic-gate /* SHT_NULL	*/	invalid_section,	invalid_section,
24500Sstevel@tonic-gate /* SHT_PROGBITS	*/	process_progbits,	process_progbits,
24510Sstevel@tonic-gate /* SHT_SYMTAB	*/	process_input,		process_input,
24520Sstevel@tonic-gate /* SHT_STRTAB	*/	process_strtab,		process_strtab,
24530Sstevel@tonic-gate /* SHT_RELA	*/	process_reloc,		process_reloc,
24540Sstevel@tonic-gate /* SHT_HASH	*/	invalid_section,	NULL,
24554716Sab196087 /* SHT_DYNAMIC	*/	process_rel_dynamic,	process_dynamic_isgnu,
24560Sstevel@tonic-gate /* SHT_NOTE	*/	process_section,	NULL,
24570Sstevel@tonic-gate /* SHT_NOBITS	*/	process_nobits,		process_nobits,
24580Sstevel@tonic-gate /* SHT_REL	*/	process_reloc,		process_reloc,
24590Sstevel@tonic-gate /* SHT_SHLIB	*/	process_section,	invalid_section,
24600Sstevel@tonic-gate /* SHT_DYNSYM	*/	invalid_section,	process_input,
24610Sstevel@tonic-gate /* SHT_UNKNOWN12 */	process_progbits,	process_progbits,
24620Sstevel@tonic-gate /* SHT_UNKNOWN13 */	process_progbits,	process_progbits,
24630Sstevel@tonic-gate /* SHT_INIT_ARRAY */	process_array,		NULL,
24640Sstevel@tonic-gate /* SHT_FINI_ARRAY */	process_array,		NULL,
24650Sstevel@tonic-gate /* SHT_PREINIT_ARRAY */	process_array,		NULL,
24667463SRod.Evans@Sun.COM /* SHT_GROUP */		process_group,		invalid_section,
24670Sstevel@tonic-gate /* SHT_SYMTAB_SHNDX */	process_sym_shndx,	NULL
24680Sstevel@tonic-gate };
24690Sstevel@tonic-gate 
24709085SAli.Bahrami@Sun.COM typedef uintptr_t	(* final_func_t)(Is_desc *, Ifl_desc *, Ofl_desc *);
24719085SAli.Bahrami@Sun.COM 
24729085SAli.Bahrami@Sun.COM static final_func_t Final[SHT_NUM][2] = {
24739085SAli.Bahrami@Sun.COM /*			ET_REL			ET_DYN			*/
24740Sstevel@tonic-gate 
24750Sstevel@tonic-gate /* SHT_NULL	*/	NULL,			NULL,
24769085SAli.Bahrami@Sun.COM /* SHT_PROGBITS	*/	process_progbits_final,	NULL,
24771618Srie /* SHT_SYMTAB	*/	ld_sym_process,		ld_sym_process,
24780Sstevel@tonic-gate /* SHT_STRTAB	*/	NULL,			NULL,
24790Sstevel@tonic-gate /* SHT_RELA	*/	rel_process,		NULL,
24800Sstevel@tonic-gate /* SHT_HASH	*/	NULL,			NULL,
24810Sstevel@tonic-gate /* SHT_DYNAMIC	*/	NULL,			process_dynamic,
24820Sstevel@tonic-gate /* SHT_NOTE	*/	NULL,			NULL,
24830Sstevel@tonic-gate /* SHT_NOBITS	*/	NULL,			NULL,
24840Sstevel@tonic-gate /* SHT_REL	*/	rel_process,		NULL,
24850Sstevel@tonic-gate /* SHT_SHLIB	*/	NULL,			NULL,
24861618Srie /* SHT_DYNSYM	*/	NULL,			ld_sym_process,
24870Sstevel@tonic-gate /* SHT_UNKNOWN12 */	NULL,			NULL,
24880Sstevel@tonic-gate /* SHT_UNKNOWN13 */	NULL,			NULL,
24897463SRod.Evans@Sun.COM /* SHT_INIT_ARRAY */	array_process,		NULL,
24907463SRod.Evans@Sun.COM /* SHT_FINI_ARRAY */	array_process,		NULL,
24917463SRod.Evans@Sun.COM /* SHT_PREINIT_ARRAY */	array_process,		NULL,
24920Sstevel@tonic-gate /* SHT_GROUP */		NULL,			NULL,
24930Sstevel@tonic-gate /* SHT_SYMTAB_SHNDX */	sym_shndx_process,	NULL
24940Sstevel@tonic-gate };
24950Sstevel@tonic-gate 
24960Sstevel@tonic-gate #define	MAXNDXSIZE	10
24970Sstevel@tonic-gate 
24980Sstevel@tonic-gate /*
24990Sstevel@tonic-gate  * Process an elf file.  Each section is compared against the section state
25000Sstevel@tonic-gate  * table to determine whether it should be processed (saved), ignored, or
25010Sstevel@tonic-gate  * is invalid for the type of input file being processed.
25020Sstevel@tonic-gate  */
25031618Srie static uintptr_t
25040Sstevel@tonic-gate process_elf(Ifl_desc *ifl, Elf *elf, Ofl_desc *ofl)
25050Sstevel@tonic-gate {
25060Sstevel@tonic-gate 	Elf_Scn		*scn;
25070Sstevel@tonic-gate 	Shdr		*shdr;
25087463SRod.Evans@Sun.COM 	Word		ndx, sndx, ordndx = 0, ordcnt = 0;
25099878SAli.Bahrami@Sun.COM 	char		*str, *name;
25100Sstevel@tonic-gate 	Word		row, column;
25110Sstevel@tonic-gate 	int		ident;
25120Sstevel@tonic-gate 	uintptr_t	error;
251311827SRod.Evans@Sun.COM 	Is_desc		*vdfisp, *vndisp, *vsyisp, *sifisp;
251411827SRod.Evans@Sun.COM 	Is_desc		*capinfoisp, *capisp;
25150Sstevel@tonic-gate 	Sdf_desc	*sdf;
251611734SAli.Bahrami@Sun.COM 	Place_path_info	path_info_buf, *path_info;
251711734SAli.Bahrami@Sun.COM 
251811734SAli.Bahrami@Sun.COM 	/*
251911734SAli.Bahrami@Sun.COM 	 * Path information buffer used by ld_place_section() and related
252011734SAli.Bahrami@Sun.COM 	 * routines. This information is used to evaluate entrance criteria
252111734SAli.Bahrami@Sun.COM 	 * with non-empty file matching lists (ec_files).
252211734SAli.Bahrami@Sun.COM 	 */
252311734SAli.Bahrami@Sun.COM 	path_info = ld_place_path_info_init(ofl, ifl, &path_info_buf);
25240Sstevel@tonic-gate 
25250Sstevel@tonic-gate 	/*
25260Sstevel@tonic-gate 	 * First process the .shstrtab section so that later sections can
25270Sstevel@tonic-gate 	 * reference their name.
25280Sstevel@tonic-gate 	 */
25291618Srie 	ld_sup_file(ofl, ifl->ifl_name, elf_kind(elf), ifl->ifl_flags, elf);
25300Sstevel@tonic-gate 
25310Sstevel@tonic-gate 	sndx = ifl->ifl_shstrndx;
25320Sstevel@tonic-gate 	if ((scn = elf_getscn(elf, (size_t)sndx)) == NULL) {
25331618Srie 		eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN),
25341618Srie 		    ifl->ifl_name);
25350Sstevel@tonic-gate 		ofl->ofl_flags |= FLG_OF_FATAL;
25360Sstevel@tonic-gate 		return (0);
25370Sstevel@tonic-gate 	}
25380Sstevel@tonic-gate 	if ((shdr = elf_getshdr(scn)) == NULL) {
25391618Srie 		eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR),
25401618Srie 		    ifl->ifl_name);
25410Sstevel@tonic-gate 		ofl->ofl_flags |= FLG_OF_FATAL;
25420Sstevel@tonic-gate 		return (0);
25430Sstevel@tonic-gate 	}
25440Sstevel@tonic-gate 	if ((name = elf_strptr(elf, (size_t)sndx, (size_t)shdr->sh_name)) ==
25450Sstevel@tonic-gate 	    NULL) {
25461618Srie 		eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR),
25471618Srie 		    ifl->ifl_name);
25480Sstevel@tonic-gate 		ofl->ofl_flags |= FLG_OF_FATAL;
25490Sstevel@tonic-gate 		return (0);
25500Sstevel@tonic-gate 	}
25510Sstevel@tonic-gate 
25522647Srie 	if (ld_sup_input_section(ofl, ifl, name, &shdr, sndx, scn,
25532647Srie 	    elf) == S_ERROR)
25540Sstevel@tonic-gate 		return (S_ERROR);
25550Sstevel@tonic-gate 
25560Sstevel@tonic-gate 	/*
25570Sstevel@tonic-gate 	 * Reset the name since the shdr->sh_name could have been changed as
25589878SAli.Bahrami@Sun.COM 	 * part of ld_sup_input_section().
25590Sstevel@tonic-gate 	 */
25609878SAli.Bahrami@Sun.COM 	if ((name = elf_strptr(elf, (size_t)sndx, (size_t)shdr->sh_name)) ==
25619878SAli.Bahrami@Sun.COM 	    NULL) {
25621618Srie 		eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR),
25631618Srie 		    ifl->ifl_name);
25640Sstevel@tonic-gate 		ofl->ofl_flags |= FLG_OF_FATAL;
25650Sstevel@tonic-gate 		return (0);
25660Sstevel@tonic-gate 	}
25670Sstevel@tonic-gate 
25680Sstevel@tonic-gate 	error = process_strtab(name, ifl, shdr, scn, sndx, FALSE, ofl);
25690Sstevel@tonic-gate 	if ((error == 0) || (error == S_ERROR))
25700Sstevel@tonic-gate 		return (error);
25710Sstevel@tonic-gate 	str = ifl->ifl_isdesc[sndx]->is_indata->d_buf;
25720Sstevel@tonic-gate 
25730Sstevel@tonic-gate 	/*
25740Sstevel@tonic-gate 	 * Determine the state table column from the input file type.  Note,
25750Sstevel@tonic-gate 	 * shared library sections are not added to the output section list.
25760Sstevel@tonic-gate 	 */
25770Sstevel@tonic-gate 	if (ifl->ifl_ehdr->e_type == ET_DYN) {
25780Sstevel@tonic-gate 		column = 1;
25790Sstevel@tonic-gate 		ofl->ofl_soscnt++;
25806206Sab196087 		ident = ld_targ.t_id.id_null;
25810Sstevel@tonic-gate 	} else {
25820Sstevel@tonic-gate 		column = 0;
25830Sstevel@tonic-gate 		ofl->ofl_objscnt++;
25846206Sab196087 		ident = ld_targ.t_id.id_unknown;
25850Sstevel@tonic-gate 	}
25860Sstevel@tonic-gate 
25871618Srie 	DBG_CALL(Dbg_file_generic(ofl->ofl_lml, ifl));
25880Sstevel@tonic-gate 	ndx = 0;
258911827SRod.Evans@Sun.COM 	vdfisp = vndisp = vsyisp = sifisp = capinfoisp = capisp = NULL;
25900Sstevel@tonic-gate 	scn = NULL;
25910Sstevel@tonic-gate 	while (scn = elf_nextscn(elf, scn)) {
25920Sstevel@tonic-gate 		ndx++;
25937463SRod.Evans@Sun.COM 
25940Sstevel@tonic-gate 		/*
25950Sstevel@tonic-gate 		 * As we've already processed the .shstrtab don't do it again.
25960Sstevel@tonic-gate 		 */
25970Sstevel@tonic-gate 		if (ndx == sndx)
25980Sstevel@tonic-gate 			continue;
25990Sstevel@tonic-gate 
26000Sstevel@tonic-gate 		if ((shdr = elf_getshdr(scn)) == NULL) {
26011618Srie 			eprintf(ofl->ofl_lml, ERR_ELF,
26021618Srie 			    MSG_INTL(MSG_ELF_GETSHDR), ifl->ifl_name);
26030Sstevel@tonic-gate 			ofl->ofl_flags |= FLG_OF_FATAL;
26040Sstevel@tonic-gate 			return (0);
26050Sstevel@tonic-gate 		}
26060Sstevel@tonic-gate 		name = str + (size_t)(shdr->sh_name);
26070Sstevel@tonic-gate 
26082647Srie 		if (ld_sup_input_section(ofl, ifl, name, &shdr, ndx, scn,
26092647Srie 		    elf) == S_ERROR)
26100Sstevel@tonic-gate 			return (S_ERROR);
26110Sstevel@tonic-gate 
26120Sstevel@tonic-gate 		/*
26130Sstevel@tonic-gate 		 * Reset the name since the shdr->sh_name could have been
26149878SAli.Bahrami@Sun.COM 		 * changed as part of ld_sup_input_section().
26150Sstevel@tonic-gate 		 */
26169878SAli.Bahrami@Sun.COM 		name = str + (size_t)(shdr->sh_name);
26170Sstevel@tonic-gate 
26180Sstevel@tonic-gate 		row = shdr->sh_type;
26190Sstevel@tonic-gate 
26200Sstevel@tonic-gate 		/*
26210Sstevel@tonic-gate 		 * If the section has the SHF_EXCLUDE flag on, and we're not
26220Sstevel@tonic-gate 		 * generating a relocatable object, exclude the section.
26230Sstevel@tonic-gate 		 */
26240Sstevel@tonic-gate 		if (((shdr->sh_flags & SHF_EXCLUDE) != 0) &&
26250Sstevel@tonic-gate 		    ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0)) {
26260Sstevel@tonic-gate 			if ((error = process_exclude(name, ifl, shdr, scn,
26270Sstevel@tonic-gate 			    ndx, ofl)) == S_ERROR)
26280Sstevel@tonic-gate 				return (S_ERROR);
26290Sstevel@tonic-gate 			if (error == 1)
26300Sstevel@tonic-gate 				continue;
26310Sstevel@tonic-gate 		}
26320Sstevel@tonic-gate 
26330Sstevel@tonic-gate 		/*
26340Sstevel@tonic-gate 		 * If this is a standard section type process it via the
26350Sstevel@tonic-gate 		 * appropriate action routine.
26360Sstevel@tonic-gate 		 */
26370Sstevel@tonic-gate 		if (row < SHT_NUM) {
26380Sstevel@tonic-gate 			if (Initial[row][column] != NULL) {
26390Sstevel@tonic-gate 				if (Initial[row][column](name, ifl, shdr, scn,
26400Sstevel@tonic-gate 				    ndx, ident, ofl) == S_ERROR)
26410Sstevel@tonic-gate 					return (S_ERROR);
26420Sstevel@tonic-gate 			}
26430Sstevel@tonic-gate 		} else {
26440Sstevel@tonic-gate 			/*
26450Sstevel@tonic-gate 			 * If this section is below SHT_LOSUNW then we don't
26460Sstevel@tonic-gate 			 * really know what to do with it, issue a warning
26470Sstevel@tonic-gate 			 * message but do the basic section processing anyway.
26480Sstevel@tonic-gate 			 */
26494734Sab196087 			if (row < (Word)SHT_LOSUNW) {
26504734Sab196087 				Conv_inv_buf_t inv_buf;
26514734Sab196087 
26521618Srie 				eprintf(ofl->ofl_lml, ERR_WARNING,
26531618Srie 				    MSG_INTL(MSG_FIL_INVALSEC), ifl->ifl_name,
26549878SAli.Bahrami@Sun.COM 				    EC_WORD(ndx), name, conv_sec_type(
26559273SAli.Bahrami@Sun.COM 				    ifl->ifl_ehdr->e_ident[EI_OSABI],
26569273SAli.Bahrami@Sun.COM 				    ifl->ifl_ehdr->e_machine,
26574734Sab196087 				    shdr->sh_type, 0, &inv_buf));
26584734Sab196087 			}
26590Sstevel@tonic-gate 
26600Sstevel@tonic-gate 			/*
26610Sstevel@tonic-gate 			 * Handle sections greater than SHT_LOSUNW.
26620Sstevel@tonic-gate 			 */
26630Sstevel@tonic-gate 			switch (row) {
26640Sstevel@tonic-gate 			case SHT_SUNW_dof:
26650Sstevel@tonic-gate 				if (process_section(name, ifl, shdr, scn,
26660Sstevel@tonic-gate 				    ndx, ident, ofl) == S_ERROR)
26670Sstevel@tonic-gate 					return (S_ERROR);
26680Sstevel@tonic-gate 				break;
26690Sstevel@tonic-gate 			case SHT_SUNW_cap:
26709085SAli.Bahrami@Sun.COM 				if (process_section(name, ifl, shdr, scn, ndx,
26719085SAli.Bahrami@Sun.COM 				    ld_targ.t_id.id_null, ofl) == S_ERROR)
26720Sstevel@tonic-gate 					return (S_ERROR);
26730Sstevel@tonic-gate 				capisp = ifl->ifl_isdesc[ndx];
26740Sstevel@tonic-gate 				break;
267511827SRod.Evans@Sun.COM 			case SHT_SUNW_capinfo:
267611827SRod.Evans@Sun.COM 				if (process_section(name, ifl, shdr, scn, ndx,
267711827SRod.Evans@Sun.COM 				    ld_targ.t_id.id_null, ofl) == S_ERROR)
267811827SRod.Evans@Sun.COM 					return (S_ERROR);
267911827SRod.Evans@Sun.COM 				capinfoisp = ifl->ifl_isdesc[ndx];
268011827SRod.Evans@Sun.COM 				break;
26810Sstevel@tonic-gate 			case SHT_SUNW_DEBUGSTR:
26820Sstevel@tonic-gate 			case SHT_SUNW_DEBUG:
26830Sstevel@tonic-gate 				if (process_debug(name, ifl, shdr, scn,
26840Sstevel@tonic-gate 				    ndx, ident, ofl) == S_ERROR)
26850Sstevel@tonic-gate 					return (S_ERROR);
26860Sstevel@tonic-gate 				break;
26870Sstevel@tonic-gate 			case SHT_SUNW_move:
26889085SAli.Bahrami@Sun.COM 				if (process_section(name, ifl, shdr, scn, ndx,
26899085SAli.Bahrami@Sun.COM 				    ld_targ.t_id.id_null, ofl) == S_ERROR)
26900Sstevel@tonic-gate 					return (S_ERROR);
26910Sstevel@tonic-gate 				break;
26920Sstevel@tonic-gate 			case SHT_SUNW_syminfo:
26939085SAli.Bahrami@Sun.COM 				if (process_section(name, ifl, shdr, scn, ndx,
26949085SAli.Bahrami@Sun.COM 				    ld_targ.t_id.id_null, ofl) == S_ERROR)
26950Sstevel@tonic-gate 					return (S_ERROR);
26960Sstevel@tonic-gate 				sifisp = ifl->ifl_isdesc[ndx];
26970Sstevel@tonic-gate 				break;
26980Sstevel@tonic-gate 			case SHT_SUNW_ANNOTATE:
26997463SRod.Evans@Sun.COM 				if (process_progbits(name, ifl, shdr, scn,
27007463SRod.Evans@Sun.COM 				    ndx, ident, ofl) == S_ERROR)
27017463SRod.Evans@Sun.COM 					return (S_ERROR);
27027463SRod.Evans@Sun.COM 				break;
27030Sstevel@tonic-gate 			case SHT_SUNW_COMDAT:
27040Sstevel@tonic-gate 				if (process_progbits(name, ifl, shdr, scn,
27050Sstevel@tonic-gate 				    ndx, ident, ofl) == S_ERROR)
27060Sstevel@tonic-gate 					return (S_ERROR);
27077463SRod.Evans@Sun.COM 				ifl->ifl_isdesc[ndx]->is_flags |= FLG_IS_COMDAT;
27080Sstevel@tonic-gate 				break;
27090Sstevel@tonic-gate 			case SHT_SUNW_verdef:
27109085SAli.Bahrami@Sun.COM 				if (process_section(name, ifl, shdr, scn, ndx,
27119085SAli.Bahrami@Sun.COM 				    ld_targ.t_id.id_null, ofl) == S_ERROR)
27120Sstevel@tonic-gate 					return (S_ERROR);
27130Sstevel@tonic-gate 				vdfisp = ifl->ifl_isdesc[ndx];
27140Sstevel@tonic-gate 				break;
27150Sstevel@tonic-gate 			case SHT_SUNW_verneed:
27169085SAli.Bahrami@Sun.COM 				if (process_section(name, ifl, shdr, scn, ndx,
27179085SAli.Bahrami@Sun.COM 				    ld_targ.t_id.id_null, ofl) == S_ERROR)
27180Sstevel@tonic-gate 					return (S_ERROR);
27190Sstevel@tonic-gate 				vndisp = ifl->ifl_isdesc[ndx];
27200Sstevel@tonic-gate 				break;
27210Sstevel@tonic-gate 			case SHT_SUNW_versym:
27229085SAli.Bahrami@Sun.COM 				if (process_section(name, ifl, shdr, scn, ndx,
27239085SAli.Bahrami@Sun.COM 				    ld_targ.t_id.id_null, ofl) == S_ERROR)
27240Sstevel@tonic-gate 					return (S_ERROR);
27250Sstevel@tonic-gate 				vsyisp = ifl->ifl_isdesc[ndx];
27260Sstevel@tonic-gate 				break;
27270Sstevel@tonic-gate 			case SHT_SPARC_GOTDATA:
27286206Sab196087 				/*
27296206Sab196087 				 * SHT_SPARC_GOTDATA (0x70000000) is in the
27306206Sab196087 				 * SHT_LOPROC - SHT_HIPROC range reserved
27316206Sab196087 				 * for processor-specific semantics. It is
27326206Sab196087 				 * only meaningful for sparc targets.
27336206Sab196087 				 */
27346206Sab196087 				if (ld_targ.t_m.m_mach !=
27356206Sab196087 				    LD_TARG_BYCLASS(EM_SPARC, EM_SPARCV9))
27366206Sab196087 					goto do_default;
27379085SAli.Bahrami@Sun.COM 				if (process_section(name, ifl, shdr, scn, ndx,
27389085SAli.Bahrami@Sun.COM 				    ld_targ.t_id.id_gotdata, ofl) == S_ERROR)
27390Sstevel@tonic-gate 					return (S_ERROR);
27400Sstevel@tonic-gate 				break;
27416206Sab196087 #if	defined(_ELF64)
27420Sstevel@tonic-gate 			case SHT_AMD64_UNWIND:
27436206Sab196087 				/*
27446206Sab196087 				 * SHT_AMD64_UNWIND (0x70000001) is in the
27456206Sab196087 				 * SHT_LOPROC - SHT_HIPROC range reserved
27466206Sab196087 				 * for processor-specific semantics. It is
27476206Sab196087 				 * only meaningful for amd64 targets.
27486206Sab196087 				 */
27496206Sab196087 				if (ld_targ.t_m.m_mach != EM_AMD64)
27506206Sab196087 					goto do_default;
27517463SRod.Evans@Sun.COM 
27526206Sab196087 				/*
27536206Sab196087 				 * Target is x86, so this really is
27546206Sab196087 				 * SHT_AMD64_UNWIND
27556206Sab196087 				 */
27560Sstevel@tonic-gate 				if (column == 0) {
27570Sstevel@tonic-gate 					/*
27580Sstevel@tonic-gate 					 * column == ET_REL
27590Sstevel@tonic-gate 					 */
27607463SRod.Evans@Sun.COM 					if (process_section(name, ifl, shdr,
27617463SRod.Evans@Sun.COM 					    scn, ndx, ld_targ.t_id.id_unwind,
27627463SRod.Evans@Sun.COM 					    ofl) == S_ERROR)
27630Sstevel@tonic-gate 						return (S_ERROR);
27649085SAli.Bahrami@Sun.COM 					ifl->ifl_isdesc[ndx]->is_flags |=
27659085SAli.Bahrami@Sun.COM 					    FLG_IS_EHFRAME;
27660Sstevel@tonic-gate 				}
27670Sstevel@tonic-gate 				break;
27680Sstevel@tonic-gate #endif
27690Sstevel@tonic-gate 			default:
27706206Sab196087 			do_default:
27719085SAli.Bahrami@Sun.COM 				if (process_section(name, ifl, shdr, scn, ndx,
27729085SAli.Bahrami@Sun.COM 				    ((ident == ld_targ.t_id.id_null) ?
27739085SAli.Bahrami@Sun.COM 				    ident : ld_targ.t_id.id_user), ofl) ==
27749085SAli.Bahrami@Sun.COM 				    S_ERROR)
27750Sstevel@tonic-gate 					return (S_ERROR);
27760Sstevel@tonic-gate 				break;
27770Sstevel@tonic-gate 			}
27780Sstevel@tonic-gate 		}
27797463SRod.Evans@Sun.COM 	}
27800Sstevel@tonic-gate 
27817463SRod.Evans@Sun.COM 	/*
27827463SRod.Evans@Sun.COM 	 * Now that all input sections have been analyzed, and prior to placing
27837463SRod.Evans@Sun.COM 	 * any input sections to their output sections, process any groups.
27847463SRod.Evans@Sun.COM 	 * Groups can contribute COMDAT items, which may get discarded as part
27857463SRod.Evans@Sun.COM 	 * of placement.  In addition, COMDAT names may require transformation
27867463SRod.Evans@Sun.COM 	 * to indicate different output section placement.
27877463SRod.Evans@Sun.COM 	 */
27887463SRod.Evans@Sun.COM 	if (ifl->ifl_flags & FLG_IS_GROUPS) {
27897463SRod.Evans@Sun.COM 		for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) {
27907463SRod.Evans@Sun.COM 			Is_desc	*isp;
27917463SRod.Evans@Sun.COM 
27927463SRod.Evans@Sun.COM 			if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
27937463SRod.Evans@Sun.COM 			    (isp->is_shdr->sh_type != SHT_GROUP))
27947463SRod.Evans@Sun.COM 				continue;
27957463SRod.Evans@Sun.COM 
27967463SRod.Evans@Sun.COM 			if (ld_group_process(isp, ofl) == S_ERROR)
27977463SRod.Evans@Sun.COM 				return (S_ERROR);
27980Sstevel@tonic-gate 		}
27990Sstevel@tonic-gate 	}
28000Sstevel@tonic-gate 
28010Sstevel@tonic-gate 	/*
28029615SAli.Bahrami@Sun.COM 	 * Now that all of the input sections have been processed, place
28039615SAli.Bahrami@Sun.COM 	 * them in the appropriate output sections.
28040Sstevel@tonic-gate 	 */
28057463SRod.Evans@Sun.COM 	for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) {
28067463SRod.Evans@Sun.COM 		Is_desc	*isp;
28077463SRod.Evans@Sun.COM 
28087463SRod.Evans@Sun.COM 		if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
28097463SRod.Evans@Sun.COM 		    ((isp->is_flags & FLG_IS_PLACE) == 0))
28107463SRod.Evans@Sun.COM 			continue;
28117463SRod.Evans@Sun.COM 
28127463SRod.Evans@Sun.COM 		/*
28137463SRod.Evans@Sun.COM 		 * Place all non-ordered sections within their appropriate
28147463SRod.Evans@Sun.COM 		 * output section.
28157463SRod.Evans@Sun.COM 		 */
28169615SAli.Bahrami@Sun.COM 		if ((isp->is_flags & FLG_IS_ORDERED) == 0) {
281711734SAli.Bahrami@Sun.COM 			if (ld_place_section(ofl, isp, path_info,
28189615SAli.Bahrami@Sun.COM 			    isp->is_keyident, NULL) == (Os_desc *)S_ERROR)
28197463SRod.Evans@Sun.COM 				return (S_ERROR);
28209615SAli.Bahrami@Sun.COM 			continue;
28217463SRod.Evans@Sun.COM 		}
28227463SRod.Evans@Sun.COM 
28237463SRod.Evans@Sun.COM 		/*
28249615SAli.Bahrami@Sun.COM 		 * Count the number of ordered sections and retain the first
28259615SAli.Bahrami@Sun.COM 		 * ordered section index. This will be used to optimize the
28269615SAli.Bahrami@Sun.COM 		 * ordered section loop that immediately follows this one.
28277463SRod.Evans@Sun.COM 		 */
28289615SAli.Bahrami@Sun.COM 		ordcnt++;
28299615SAli.Bahrami@Sun.COM 		if (ordndx == 0)
28309615SAli.Bahrami@Sun.COM 			ordndx = ndx;
28319615SAli.Bahrami@Sun.COM 	}
28329615SAli.Bahrami@Sun.COM 
28339615SAli.Bahrami@Sun.COM 	/*
28349615SAli.Bahrami@Sun.COM 	 * Having placed all the non-ordered sections, it is now
28359615SAli.Bahrami@Sun.COM 	 * safe to place SHF_ORDERED/SHF_LINK_ORDER sections.
28369615SAli.Bahrami@Sun.COM 	 */
28379615SAli.Bahrami@Sun.COM 	if (ifl->ifl_flags & FLG_IF_ORDERED) {
28389615SAli.Bahrami@Sun.COM 		for (ndx = ordndx; ndx < ifl->ifl_shnum; ndx++) {
28399615SAli.Bahrami@Sun.COM 			Is_desc	*isp;
28409615SAli.Bahrami@Sun.COM 
28419615SAli.Bahrami@Sun.COM 			if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
28429615SAli.Bahrami@Sun.COM 			    ((isp->is_flags &
28439615SAli.Bahrami@Sun.COM 			    (FLG_IS_PLACE | FLG_IS_ORDERED)) !=
28449615SAli.Bahrami@Sun.COM 			    (FLG_IS_PLACE | FLG_IS_ORDERED)))
28459615SAli.Bahrami@Sun.COM 				continue;
28469615SAli.Bahrami@Sun.COM 
28479615SAli.Bahrami@Sun.COM 			/* ld_process_ordered() calls ld_place_section() */
284811734SAli.Bahrami@Sun.COM 			if (ld_process_ordered(ofl, ifl, path_info, ndx) ==
284911734SAli.Bahrami@Sun.COM 			    S_ERROR)
28509615SAli.Bahrami@Sun.COM 				return (S_ERROR);
28519615SAli.Bahrami@Sun.COM 
28529615SAli.Bahrami@Sun.COM 			/* If we've done them all, stop searching */
28539615SAli.Bahrami@Sun.COM 			if (--ordcnt == 0)
28549615SAli.Bahrami@Sun.COM 				break;
28557463SRod.Evans@Sun.COM 		}
28567463SRod.Evans@Sun.COM 	}
28577463SRod.Evans@Sun.COM 
28587463SRod.Evans@Sun.COM 	/*
28599615SAli.Bahrami@Sun.COM 	 * If this is a shared object explicitly specified on the command
28609615SAli.Bahrami@Sun.COM 	 * line (as opposed to being a dependency of such an object),
28619615SAli.Bahrami@Sun.COM 	 * determine if the user has specified a control definition. This
28629615SAli.Bahrami@Sun.COM 	 * descriptor may specify which version definitions can be used
28639615SAli.Bahrami@Sun.COM 	 * from this object. It may also update the dependency to USED and
28649615SAli.Bahrami@Sun.COM 	 * supply an alternative SONAME.
28650Sstevel@tonic-gate 	 */
286610792SRod.Evans@Sun.COM 	sdf = NULL;
28670Sstevel@tonic-gate 	if (column && (ifl->ifl_flags & FLG_IF_NEEDED)) {
28680Sstevel@tonic-gate 		const char	*base;
28690Sstevel@tonic-gate 
28700Sstevel@tonic-gate 		/*
28710Sstevel@tonic-gate 		 * Use the basename of the input file (typically this is the
28720Sstevel@tonic-gate 		 * compilation environment name, ie. libfoo.so).
28730Sstevel@tonic-gate 		 */
28740Sstevel@tonic-gate 		if ((base = strrchr(ifl->ifl_name, '/')) == NULL)
28750Sstevel@tonic-gate 			base = ifl->ifl_name;
28760Sstevel@tonic-gate 		else
28770Sstevel@tonic-gate 			base++;
28780Sstevel@tonic-gate 
28799131SRod.Evans@Sun.COM 		if ((sdf = sdf_find(base, ofl->ofl_socntl)) != NULL) {
28800Sstevel@tonic-gate 			sdf->sdf_file = ifl;
28810Sstevel@tonic-gate 			ifl->ifl_sdfdesc = sdf;
28820Sstevel@tonic-gate 		}
28830Sstevel@tonic-gate 	}
28840Sstevel@tonic-gate 
28850Sstevel@tonic-gate 	/*
288611827SRod.Evans@Sun.COM 	 * Before symbol processing, process any capabilities.  Capabilities
288711827SRod.Evans@Sun.COM 	 * can reference a string table, which is why this processing is
288811827SRod.Evans@Sun.COM 	 * carried out after the initial section processing.  Capabilities,
288911827SRod.Evans@Sun.COM 	 * together with -z symbolcap, can require the conversion of global
289011827SRod.Evans@Sun.COM 	 * symbols to local symbols.
28910Sstevel@tonic-gate 	 */
289211827SRod.Evans@Sun.COM 	if (capisp && (process_cap(ofl, ifl, capisp) == S_ERROR))
289311827SRod.Evans@Sun.COM 		return (S_ERROR);
28940Sstevel@tonic-gate 
28950Sstevel@tonic-gate 	/*
28960Sstevel@tonic-gate 	 * Process any version dependencies.  These will establish shared object
28970Sstevel@tonic-gate 	 * `needed' entries in the same manner as will be generated from the
28980Sstevel@tonic-gate 	 * .dynamic's NEEDED entries.
28990Sstevel@tonic-gate 	 */
29000Sstevel@tonic-gate 	if (vndisp && (ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)))
29011618Srie 		if (ld_vers_need_process(vndisp, ifl, ofl) == S_ERROR)
29020Sstevel@tonic-gate 			return (S_ERROR);
29030Sstevel@tonic-gate 
29040Sstevel@tonic-gate 	/*
29050Sstevel@tonic-gate 	 * Before processing any symbol resolution or relocations process any
29060Sstevel@tonic-gate 	 * version sections.
29070Sstevel@tonic-gate 	 */
29080Sstevel@tonic-gate 	if (vsyisp)
29091618Srie 		(void) ld_vers_sym_process(ofl->ofl_lml, vsyisp, ifl);
29100Sstevel@tonic-gate 
29110Sstevel@tonic-gate 	if (ifl->ifl_versym &&
29120Sstevel@tonic-gate 	    (vdfisp || (sdf && (sdf->sdf_flags & FLG_SDF_SELECT))))
29131618Srie 		if (ld_vers_def_process(vdfisp, ifl, ofl) == S_ERROR)
29140Sstevel@tonic-gate 			return (S_ERROR);
29150Sstevel@tonic-gate 
29160Sstevel@tonic-gate 	/*
29170Sstevel@tonic-gate 	 * Having collected the appropriate sections carry out any additional
29180Sstevel@tonic-gate 	 * processing if necessary.
29190Sstevel@tonic-gate 	 */
29200Sstevel@tonic-gate 	for (ndx = 0; ndx < ifl->ifl_shnum; ndx++) {
29217463SRod.Evans@Sun.COM 		Is_desc	*isp;
29220Sstevel@tonic-gate 
292310792SRod.Evans@Sun.COM 		if ((isp = ifl->ifl_isdesc[ndx]) == NULL)
29240Sstevel@tonic-gate 			continue;
29250Sstevel@tonic-gate 		row = isp->is_shdr->sh_type;
29260Sstevel@tonic-gate 
29270Sstevel@tonic-gate 		if ((isp->is_flags & FLG_IS_DISCARD) == 0)
29281618Srie 			ld_sup_section(ofl, isp->is_name, isp->is_shdr, ndx,
29291618Srie 			    isp->is_indata, elf);
29300Sstevel@tonic-gate 
29310Sstevel@tonic-gate 		/*
29329131SRod.Evans@Sun.COM 		 * If this is a SHT_SUNW_move section from a relocatable file,
29339131SRod.Evans@Sun.COM 		 * keep track of the section for later processing.
29340Sstevel@tonic-gate 		 */
29350Sstevel@tonic-gate 		if ((row == SHT_SUNW_move) && (column == 0)) {
29369131SRod.Evans@Sun.COM 			if (aplist_append(&(ofl->ofl_ismove), isp,
29379131SRod.Evans@Sun.COM 			    AL_CNT_OFL_MOVE) == NULL)
29380Sstevel@tonic-gate 				return (S_ERROR);
29390Sstevel@tonic-gate 		}
29400Sstevel@tonic-gate 
29410Sstevel@tonic-gate 		/*
29420Sstevel@tonic-gate 		 * If this is a standard section type process it via the
29430Sstevel@tonic-gate 		 * appropriate action routine.
29440Sstevel@tonic-gate 		 */
29450Sstevel@tonic-gate 		if (row < SHT_NUM) {
29467463SRod.Evans@Sun.COM 			if (Final[row][column] != NULL) {
29477463SRod.Evans@Sun.COM 				if (Final[row][column](isp, ifl,
29487463SRod.Evans@Sun.COM 				    ofl) == S_ERROR)
29490Sstevel@tonic-gate 					return (S_ERROR);
29507463SRod.Evans@Sun.COM 			}
29517463SRod.Evans@Sun.COM #if	defined(_ELF64)
29527463SRod.Evans@Sun.COM 		} else if ((row == SHT_AMD64_UNWIND) && (column == 0)) {
29537463SRod.Evans@Sun.COM 			Os_desc	*osp = isp->is_osdesc;
29547463SRod.Evans@Sun.COM 
29557463SRod.Evans@Sun.COM 			/*
29567463SRod.Evans@Sun.COM 			 * SHT_AMD64_UNWIND (0x70000001) is in the SHT_LOPROC -
29577463SRod.Evans@Sun.COM 			 * SHT_HIPROC range reserved for processor-specific
29587463SRod.Evans@Sun.COM 			 * semantics, and is only meaningful for amd64 targets.
29597463SRod.Evans@Sun.COM 			 *
29607463SRod.Evans@Sun.COM 			 * Only process unwind contents from relocatable
29617463SRod.Evans@Sun.COM 			 * objects.
29627463SRod.Evans@Sun.COM 			 */
29637463SRod.Evans@Sun.COM 			if (osp && (ld_targ.t_m.m_mach == EM_AMD64) &&
29649085SAli.Bahrami@Sun.COM 			    (ld_unwind_register(osp, ofl) == S_ERROR))
29657463SRod.Evans@Sun.COM 				return (S_ERROR);
29667463SRod.Evans@Sun.COM #endif
29670Sstevel@tonic-gate 		}
29680Sstevel@tonic-gate 	}
29690Sstevel@tonic-gate 
29700Sstevel@tonic-gate 	/*
297111827SRod.Evans@Sun.COM 	 * Following symbol processing, if this relocatable object input file
297211827SRod.Evans@Sun.COM 	 * provides symbol capabilities, tag the associated symbols so that
297311827SRod.Evans@Sun.COM 	 * the symbols can be re-assigned to the new capabilities symbol
297411827SRod.Evans@Sun.COM 	 * section that will be created for the output file.
297511827SRod.Evans@Sun.COM 	 */
297611827SRod.Evans@Sun.COM 	if (capinfoisp && (ifl->ifl_ehdr->e_type == ET_REL) &&
297711827SRod.Evans@Sun.COM 	    (process_capinfo(ofl, ifl, capinfoisp) == S_ERROR))
297811827SRod.Evans@Sun.COM 		return (S_ERROR);
297911827SRod.Evans@Sun.COM 
298011827SRod.Evans@Sun.COM 	/*
29810Sstevel@tonic-gate 	 * After processing any symbol resolution, and if this dependency
29820Sstevel@tonic-gate 	 * indicates it contains symbols that can't be directly bound to,
29830Sstevel@tonic-gate 	 * set the symbols appropriately.
29840Sstevel@tonic-gate 	 */
29850Sstevel@tonic-gate 	if (sifisp && ((ifl->ifl_flags & (FLG_IF_NEEDED | FLG_IF_NODIRECT)) ==
29860Sstevel@tonic-gate 	    (FLG_IF_NEEDED | FLG_IF_NODIRECT)))
29871618Srie 		(void) ld_sym_nodirect(sifisp, ifl, ofl);
29880Sstevel@tonic-gate 
29890Sstevel@tonic-gate 	return (1);
29900Sstevel@tonic-gate }
29910Sstevel@tonic-gate 
29920Sstevel@tonic-gate /*
29930Sstevel@tonic-gate  * Process the current input file.  There are basically three types of files
29940Sstevel@tonic-gate  * that come through here:
29950Sstevel@tonic-gate  *
299610792SRod.Evans@Sun.COM  *  -	files explicitly defined on the command line (ie. foo.o or bar.so),
29970Sstevel@tonic-gate  *	in this case only the `name' field is valid.
29980Sstevel@tonic-gate  *
299910792SRod.Evans@Sun.COM  *  -	libraries determined from the -l command line option (ie. -lbar),
30000Sstevel@tonic-gate  *	in this case the `soname' field contains the basename of the located
30010Sstevel@tonic-gate  *	file.
30020Sstevel@tonic-gate  *
30030Sstevel@tonic-gate  * Any shared object specified via the above two conventions must be recorded
30040Sstevel@tonic-gate  * as a needed dependency.
30050Sstevel@tonic-gate  *
300610792SRod.Evans@Sun.COM  *  -	libraries specified as dependencies of those libraries already obtained
30070Sstevel@tonic-gate  *	via the command line (ie. bar.so has a DT_NEEDED entry of fred.so.1),
30080Sstevel@tonic-gate  *	in this case the `soname' field contains either a full pathname (if the
30090Sstevel@tonic-gate  *	needed entry contained a `/'), or the basename of the located file.
30100Sstevel@tonic-gate  *	These libraries are processed to verify symbol binding but are not
30110Sstevel@tonic-gate  *	recorded as dependencies of the output file being generated.
3012*12254SAli.Bahrami@Oracle.COM  *
3013*12254SAli.Bahrami@Oracle.COM  * entry:
3014*12254SAli.Bahrami@Oracle.COM  *	name - File name
3015*12254SAli.Bahrami@Oracle.COM  *	soname - SONAME for needed sharable library, as described above
3016*12254SAli.Bahrami@Oracle.COM  *	fd - Open file descriptor
3017*12254SAli.Bahrami@Oracle.COM  *	elf - Open ELF handle
3018*12254SAli.Bahrami@Oracle.COM  *	flags - FLG_IF_ flags applicable to file
3019*12254SAli.Bahrami@Oracle.COM  *	ofl - Output file descriptor
3020*12254SAli.Bahrami@Oracle.COM  *	rej - Rejection descriptor used to record rejection reason
3021*12254SAli.Bahrami@Oracle.COM  *	ifl_ret - NULL, or address of pointer to receive reference to
3022*12254SAli.Bahrami@Oracle.COM  *		resulting input descriptor for file. If ifl_ret is non-NULL,
3023*12254SAli.Bahrami@Oracle.COM  *		the file cannot be an archive or it will be rejected.
3024*12254SAli.Bahrami@Oracle.COM  *
3025*12254SAli.Bahrami@Oracle.COM  * exit:
3026*12254SAli.Bahrami@Oracle.COM  *	If a error occurs in examining the file, S_ERROR is returned.
3027*12254SAli.Bahrami@Oracle.COM  *	If the file can be examined, but is not suitable, *rej is updated,
3028*12254SAli.Bahrami@Oracle.COM  *	and 0 is returned. If the file is acceptable, 1 is returned, and if
3029*12254SAli.Bahrami@Oracle.COM  *	ifl_ret is non-NULL, *ifl_ret is set to contain the pointer to the
3030*12254SAli.Bahrami@Oracle.COM  *	resulting input descriptor.
30310Sstevel@tonic-gate  */
3032*12254SAli.Bahrami@Oracle.COM uintptr_t
30331618Srie ld_process_ifl(const char *name, const char *soname, int fd, Elf *elf,
3034*12254SAli.Bahrami@Oracle.COM     Word flags, Ofl_desc *ofl, Rej_desc *rej, Ifl_desc **ifl_ret)
30350Sstevel@tonic-gate {
30360Sstevel@tonic-gate 	Ifl_desc	*ifl;
30370Sstevel@tonic-gate 	Ehdr		*ehdr;
30380Sstevel@tonic-gate 	uintptr_t	error = 0;
30390Sstevel@tonic-gate 	struct stat	status;
30400Sstevel@tonic-gate 	Ar_desc		*adp;
30410Sstevel@tonic-gate 	Rej_desc	_rej;
30420Sstevel@tonic-gate 
30430Sstevel@tonic-gate 	/*
30440Sstevel@tonic-gate 	 * If this file was not extracted from an archive obtain its device
30450Sstevel@tonic-gate 	 * information.  This will be used to determine if the file has already
30460Sstevel@tonic-gate 	 * been processed (rather than simply comparing filenames, the device
30470Sstevel@tonic-gate 	 * information provides a quicker comparison and detects linked files).
30480Sstevel@tonic-gate 	 */
30498598SRod.Evans@Sun.COM 	if (fd && ((flags & FLG_IF_EXTRACT) == 0))
30500Sstevel@tonic-gate 		(void) fstat(fd, &status);
30510Sstevel@tonic-gate 	else {
30520Sstevel@tonic-gate 		status.st_dev = 0;
30530Sstevel@tonic-gate 		status.st_ino = 0;
30540Sstevel@tonic-gate 	}
30550Sstevel@tonic-gate 
30560Sstevel@tonic-gate 	switch (elf_kind(elf)) {
30570Sstevel@tonic-gate 	case ELF_K_AR:
30580Sstevel@tonic-gate 		/*
3059*12254SAli.Bahrami@Oracle.COM 		 * If the caller has supplied a non-NULL ifl_ret, then
3060*12254SAli.Bahrami@Oracle.COM 		 * we cannot process archives, for there will be no
3061*12254SAli.Bahrami@Oracle.COM 		 * input file descriptor for us to return. In this case,
3062*12254SAli.Bahrami@Oracle.COM 		 * reject the attempt.
3063*12254SAli.Bahrami@Oracle.COM 		 */
3064*12254SAli.Bahrami@Oracle.COM 		if (ifl_ret != NULL) {
3065*12254SAli.Bahrami@Oracle.COM 			_rej.rej_type = SGS_REJ_ARCHIVE;
3066*12254SAli.Bahrami@Oracle.COM 			_rej.rej_name = name;
3067*12254SAli.Bahrami@Oracle.COM 			DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3068*12254SAli.Bahrami@Oracle.COM 			    ld_targ.t_m.m_mach));
3069*12254SAli.Bahrami@Oracle.COM 			if (rej->rej_type == 0) {
3070*12254SAli.Bahrami@Oracle.COM 				*rej = _rej;
3071*12254SAli.Bahrami@Oracle.COM 				rej->rej_name = strdup(_rej.rej_name);
3072*12254SAli.Bahrami@Oracle.COM 			}
3073*12254SAli.Bahrami@Oracle.COM 			return (0);
3074*12254SAli.Bahrami@Oracle.COM 		}
3075*12254SAli.Bahrami@Oracle.COM 
3076*12254SAli.Bahrami@Oracle.COM 		/*
30770Sstevel@tonic-gate 		 * Determine if we've already come across this archive file.
30780Sstevel@tonic-gate 		 */
30790Sstevel@tonic-gate 		if (!(flags & FLG_IF_EXTRACT)) {
30809131SRod.Evans@Sun.COM 			Aliste	idx;
30819131SRod.Evans@Sun.COM 
30829131SRod.Evans@Sun.COM 			for (APLIST_TRAVERSE(ofl->ofl_ars, idx, adp)) {
30830Sstevel@tonic-gate 				if ((adp->ad_stdev != status.st_dev) ||
30840Sstevel@tonic-gate 				    (adp->ad_stino != status.st_ino))
30850Sstevel@tonic-gate 					continue;
30860Sstevel@tonic-gate 
30870Sstevel@tonic-gate 				/*
30880Sstevel@tonic-gate 				 * We've seen this file before so reuse the
30890Sstevel@tonic-gate 				 * original archive descriptor and discard the
30907359SRod.Evans@Sun.COM 				 * new elf descriptor.  Note that a file
30917359SRod.Evans@Sun.COM 				 * descriptor is unnecessary, as the file is
30927359SRod.Evans@Sun.COM 				 * already available in memory.
30930Sstevel@tonic-gate 				 */
30941618Srie 				DBG_CALL(Dbg_file_reuse(ofl->ofl_lml, name,
30951618Srie 				    adp->ad_name));
30960Sstevel@tonic-gate 				(void) elf_end(elf);
3097*12254SAli.Bahrami@Oracle.COM 				if (!ld_process_archive(name, -1, adp, ofl))
3098*12254SAli.Bahrami@Oracle.COM 					return (S_ERROR);
3099*12254SAli.Bahrami@Oracle.COM 				return (1);
31000Sstevel@tonic-gate 			}
31010Sstevel@tonic-gate 		}
31020Sstevel@tonic-gate 
31030Sstevel@tonic-gate 		/*
31040Sstevel@tonic-gate 		 * As we haven't processed this file before establish a new
31050Sstevel@tonic-gate 		 * archive descriptor.
31060Sstevel@tonic-gate 		 */
31071618Srie 		adp = ld_ar_setup(name, elf, ofl);
310810792SRod.Evans@Sun.COM 		if ((adp == NULL) || (adp == (Ar_desc *)S_ERROR))
3109*12254SAli.Bahrami@Oracle.COM 			return ((uintptr_t)adp);
31100Sstevel@tonic-gate 		adp->ad_stdev = status.st_dev;
31110Sstevel@tonic-gate 		adp->ad_stino = status.st_ino;
31120Sstevel@tonic-gate 
31131618Srie 		ld_sup_file(ofl, name, ELF_K_AR, flags, elf);
31140Sstevel@tonic-gate 
31157359SRod.Evans@Sun.COM 		/*
31167359SRod.Evans@Sun.COM 		 * Indicate that the ELF descriptor no longer requires a file
31177359SRod.Evans@Sun.COM 		 * descriptor by reading the entire file.  The file is already
31187359SRod.Evans@Sun.COM 		 * read via the initial mmap(2) behind elf_begin(3elf), thus
31197359SRod.Evans@Sun.COM 		 * this operation is effectively a no-op.  However, a side-
31207359SRod.Evans@Sun.COM 		 * effect is that the internal file descriptor, maintained in
31217359SRod.Evans@Sun.COM 		 * the ELF descriptor, is set to -1.  This setting will not
31227359SRod.Evans@Sun.COM 		 * be compared with any file descriptor that is passed to
31237359SRod.Evans@Sun.COM 		 * elf_begin(), should this archive, or one of the archive
31247359SRod.Evans@Sun.COM 		 * members, be processed again from the command line or
31257359SRod.Evans@Sun.COM 		 * because of a -z rescan.
31267359SRod.Evans@Sun.COM 		 */
31277359SRod.Evans@Sun.COM 		if (elf_cntl(elf, ELF_C_FDREAD) == -1) {
31287359SRod.Evans@Sun.COM 			eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_CNTL),
31297359SRod.Evans@Sun.COM 			    name);
31307359SRod.Evans@Sun.COM 			ofl->ofl_flags |= FLG_OF_FATAL;
3131*12254SAli.Bahrami@Oracle.COM 			return (0);
31327359SRod.Evans@Sun.COM 		}
31337359SRod.Evans@Sun.COM 
3134*12254SAli.Bahrami@Oracle.COM 		if (!ld_process_archive(name, -1, adp, ofl))
3135*12254SAli.Bahrami@Oracle.COM 			return (S_ERROR);
3136*12254SAli.Bahrami@Oracle.COM 		return (1);
31370Sstevel@tonic-gate 
31380Sstevel@tonic-gate 	case ELF_K_ELF:
31390Sstevel@tonic-gate 		/*
31400Sstevel@tonic-gate 		 * Obtain the elf header so that we can determine what type of
31410Sstevel@tonic-gate 		 * elf ELF_K_ELF file this is.
31420Sstevel@tonic-gate 		 */
31430Sstevel@tonic-gate 		if ((ehdr = elf_getehdr(elf)) == NULL) {
31440Sstevel@tonic-gate 			int	_class = gelf_getclass(elf);
31450Sstevel@tonic-gate 
31460Sstevel@tonic-gate 			/*
3147*12254SAli.Bahrami@Oracle.COM 			 * This can fail for a number of reasons. Typically
3148*12254SAli.Bahrami@Oracle.COM 			 * the object class is incorrect (ie. user is building
3149*12254SAli.Bahrami@Oracle.COM 			 * 64-bit but managed to point at 32-bit libraries).
3150*12254SAli.Bahrami@Oracle.COM 			 * Other ELF errors can include a truncated or corrupt
3151*12254SAli.Bahrami@Oracle.COM 			 * file. Try to get the best error message possible.
31520Sstevel@tonic-gate 			 */
31536206Sab196087 			if (ld_targ.t_m.m_class != _class) {
31540Sstevel@tonic-gate 				_rej.rej_type = SGS_REJ_CLASS;
31550Sstevel@tonic-gate 				_rej.rej_info = (uint_t)_class;
31560Sstevel@tonic-gate 			} else {
31570Sstevel@tonic-gate 				_rej.rej_type = SGS_REJ_STR;
31580Sstevel@tonic-gate 				_rej.rej_str = elf_errmsg(-1);
31590Sstevel@tonic-gate 			}
31600Sstevel@tonic-gate 			_rej.rej_name = name;
31616206Sab196087 			DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
31626206Sab196087 			    ld_targ.t_m.m_mach));
31630Sstevel@tonic-gate 			if (rej->rej_type == 0) {
31640Sstevel@tonic-gate 				*rej = _rej;
31650Sstevel@tonic-gate 				rej->rej_name = strdup(_rej.rej_name);
31660Sstevel@tonic-gate 			}
3167*12254SAli.Bahrami@Oracle.COM 			return (0);
31680Sstevel@tonic-gate 		}
31690Sstevel@tonic-gate 
31700Sstevel@tonic-gate 		/*
31710Sstevel@tonic-gate 		 * Determine if we've already come across this file.
31720Sstevel@tonic-gate 		 */
31730Sstevel@tonic-gate 		if (!(flags & FLG_IF_EXTRACT)) {
31749131SRod.Evans@Sun.COM 			APlist	*apl;
31759131SRod.Evans@Sun.COM 			Aliste	idx;
31760Sstevel@tonic-gate 
31770Sstevel@tonic-gate 			if (ehdr->e_type == ET_REL)
31789131SRod.Evans@Sun.COM 				apl = ofl->ofl_objs;
31790Sstevel@tonic-gate 			else
31809131SRod.Evans@Sun.COM 				apl = ofl->ofl_sos;
31810Sstevel@tonic-gate 
31820Sstevel@tonic-gate 			/*
31830Sstevel@tonic-gate 			 * Traverse the appropriate file list and determine if
31840Sstevel@tonic-gate 			 * a dev/inode match is found.
31850Sstevel@tonic-gate 			 */
31869131SRod.Evans@Sun.COM 			for (APLIST_TRAVERSE(apl, idx, ifl)) {
31870Sstevel@tonic-gate 				/*
31880Sstevel@tonic-gate 				 * Ifl_desc generated via -Nneed, therefore no
31890Sstevel@tonic-gate 				 * actual file behind it.
31900Sstevel@tonic-gate 				 */
31910Sstevel@tonic-gate 				if (ifl->ifl_flags & FLG_IF_NEEDSTR)
31920Sstevel@tonic-gate 					continue;
31930Sstevel@tonic-gate 
31940Sstevel@tonic-gate 				if ((ifl->ifl_stino != status.st_ino) ||
31950Sstevel@tonic-gate 				    (ifl->ifl_stdev != status.st_dev))
31960Sstevel@tonic-gate 					continue;
31970Sstevel@tonic-gate 
31980Sstevel@tonic-gate 				/*
31990Sstevel@tonic-gate 				 * Disregard (skip) this image.
32000Sstevel@tonic-gate 				 */
32011618Srie 				DBG_CALL(Dbg_file_skip(ofl->ofl_lml,
32021618Srie 				    ifl->ifl_name, name));
32030Sstevel@tonic-gate 				(void) elf_end(elf);
32040Sstevel@tonic-gate 
32050Sstevel@tonic-gate 				/*
32060Sstevel@tonic-gate 				 * If the file was explicitly defined on the
32070Sstevel@tonic-gate 				 * command line (this is always the case for
32080Sstevel@tonic-gate 				 * relocatable objects, and is true for shared
32090Sstevel@tonic-gate 				 * objects when they weren't specified via -l or
32100Sstevel@tonic-gate 				 * were dragged in as an implicit dependency),
32110Sstevel@tonic-gate 				 * then warn the user.
32120Sstevel@tonic-gate 				 */
32130Sstevel@tonic-gate 				if ((flags & FLG_IF_CMDLINE) ||
32140Sstevel@tonic-gate 				    (ifl->ifl_flags & FLG_IF_CMDLINE)) {
32150Sstevel@tonic-gate 					const char	*errmsg;
32160Sstevel@tonic-gate 
32170Sstevel@tonic-gate 					/*
32180Sstevel@tonic-gate 					 * Determine whether this is the same
32190Sstevel@tonic-gate 					 * file name as originally encountered
32200Sstevel@tonic-gate 					 * so as to provide the most
32210Sstevel@tonic-gate 					 * descriptive diagnostic.
32220Sstevel@tonic-gate 					 */
32234734Sab196087 					errmsg =
32244734Sab196087 					    (strcmp(name, ifl->ifl_name) == 0) ?
32254734Sab196087 					    MSG_INTL(MSG_FIL_MULINC_1) :
32264734Sab196087 					    MSG_INTL(MSG_FIL_MULINC_2);
32271618Srie 					eprintf(ofl->ofl_lml, ERR_WARNING,
32281618Srie 					    errmsg, name, ifl->ifl_name);
32290Sstevel@tonic-gate 				}
3230*12254SAli.Bahrami@Oracle.COM 				if (ifl_ret)
3231*12254SAli.Bahrami@Oracle.COM 					*ifl_ret = ifl;
3232*12254SAli.Bahrami@Oracle.COM 				return (1);
32330Sstevel@tonic-gate 			}
32340Sstevel@tonic-gate 		}
32350Sstevel@tonic-gate 
32360Sstevel@tonic-gate 		/*
32370Sstevel@tonic-gate 		 * At this point, we know we need the file.  Establish an input
32380Sstevel@tonic-gate 		 * file descriptor and continue processing.
32390Sstevel@tonic-gate 		 */
32400Sstevel@tonic-gate 		ifl = ifl_setup(name, ehdr, elf, flags, ofl, rej);
324110792SRod.Evans@Sun.COM 		if ((ifl == NULL) || (ifl == (Ifl_desc *)S_ERROR))
3242*12254SAli.Bahrami@Oracle.COM 			return ((uintptr_t)ifl);
32430Sstevel@tonic-gate 		ifl->ifl_stdev = status.st_dev;
32440Sstevel@tonic-gate 		ifl->ifl_stino = status.st_ino;
32450Sstevel@tonic-gate 
32460Sstevel@tonic-gate 		/*
32470Sstevel@tonic-gate 		 * If -zignore is in effect, mark this file as a potential
32480Sstevel@tonic-gate 		 * candidate (the files use isn't actually determined until
32490Sstevel@tonic-gate 		 * symbol resolution and relocation processing are completed).
32500Sstevel@tonic-gate 		 */
32510Sstevel@tonic-gate 		if (ofl->ofl_flags1 & FLG_OF1_IGNORE)
32520Sstevel@tonic-gate 			ifl->ifl_flags |= FLG_IF_IGNORE;
32530Sstevel@tonic-gate 
32540Sstevel@tonic-gate 		switch (ehdr->e_type) {
32550Sstevel@tonic-gate 		case ET_REL:
32566206Sab196087 			(*ld_targ.t_mr.mr_mach_eflags)(ehdr, ofl);
32570Sstevel@tonic-gate 			error = process_elf(ifl, elf, ofl);
32580Sstevel@tonic-gate 			break;
32590Sstevel@tonic-gate 		case ET_DYN:
32600Sstevel@tonic-gate 			if ((ofl->ofl_flags & FLG_OF_STATIC) ||
32610Sstevel@tonic-gate 			    !(ofl->ofl_flags & FLG_OF_DYNLIBS)) {
32621618Srie 				eprintf(ofl->ofl_lml, ERR_FATAL,
32631618Srie 				    MSG_INTL(MSG_FIL_SOINSTAT), name);
32640Sstevel@tonic-gate 				ofl->ofl_flags |= FLG_OF_FATAL;
3265*12254SAli.Bahrami@Oracle.COM 				return (0);
32660Sstevel@tonic-gate 			}
32670Sstevel@tonic-gate 
32680Sstevel@tonic-gate 			/*
32690Sstevel@tonic-gate 			 * Record any additional shared object information.
32700Sstevel@tonic-gate 			 * If no soname is specified (eg. this file was
32710Sstevel@tonic-gate 			 * derived from a explicit filename declaration on the
32720Sstevel@tonic-gate 			 * command line, ie. bar.so) use the pathname.
32730Sstevel@tonic-gate 			 * This entry may be overridden if the files dynamic
32740Sstevel@tonic-gate 			 * section specifies an DT_SONAME value.
32750Sstevel@tonic-gate 			 */
32760Sstevel@tonic-gate 			if (soname == NULL)
32770Sstevel@tonic-gate 				ifl->ifl_soname = ifl->ifl_name;
32780Sstevel@tonic-gate 			else
32790Sstevel@tonic-gate 				ifl->ifl_soname = soname;
32800Sstevel@tonic-gate 
32810Sstevel@tonic-gate 			/*
32820Sstevel@tonic-gate 			 * If direct bindings, lazy loading, or group
32830Sstevel@tonic-gate 			 * permissions need to be established, mark this object.
32840Sstevel@tonic-gate 			 */
32850Sstevel@tonic-gate 			if (ofl->ofl_flags1 & FLG_OF1_ZDIRECT)
32860Sstevel@tonic-gate 				ifl->ifl_flags |= FLG_IF_DIRECT;
32870Sstevel@tonic-gate 			if (ofl->ofl_flags1 & FLG_OF1_LAZYLD)
32880Sstevel@tonic-gate 				ifl->ifl_flags |= FLG_IF_LAZYLD;
32890Sstevel@tonic-gate 			if (ofl->ofl_flags1 & FLG_OF1_GRPPRM)
32900Sstevel@tonic-gate 				ifl->ifl_flags |= FLG_IF_GRPPRM;
32910Sstevel@tonic-gate 			error = process_elf(ifl, elf, ofl);
32920Sstevel@tonic-gate 
32930Sstevel@tonic-gate 			/*
32940Sstevel@tonic-gate 			 * At this point we know if this file will be
32950Sstevel@tonic-gate 			 * lazyloaded, or whether bindings to it must be direct.
32960Sstevel@tonic-gate 			 * In either case, a syminfo section is required.
32970Sstevel@tonic-gate 			 */
32980Sstevel@tonic-gate 			if (ifl->ifl_flags & (FLG_IF_LAZYLD | FLG_IF_DIRECT))
32990Sstevel@tonic-gate 				ofl->ofl_flags |= FLG_OF_SYMINFO;
33000Sstevel@tonic-gate 
33010Sstevel@tonic-gate 			break;
33020Sstevel@tonic-gate 		default:
33030Sstevel@tonic-gate 			(void) elf_errno();
33040Sstevel@tonic-gate 			_rej.rej_type = SGS_REJ_UNKFILE;
33050Sstevel@tonic-gate 			_rej.rej_name = name;
33066206Sab196087 			DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
33076206Sab196087 			    ld_targ.t_m.m_mach));
33080Sstevel@tonic-gate 			if (rej->rej_type == 0) {
33090Sstevel@tonic-gate 				*rej = _rej;
33100Sstevel@tonic-gate 				rej->rej_name = strdup(_rej.rej_name);
33110Sstevel@tonic-gate 			}
3312*12254SAli.Bahrami@Oracle.COM 			return (0);
33130Sstevel@tonic-gate 		}
33140Sstevel@tonic-gate 		break;
33150Sstevel@tonic-gate 	default:
33160Sstevel@tonic-gate 		(void) elf_errno();
33170Sstevel@tonic-gate 		_rej.rej_type = SGS_REJ_UNKFILE;
33180Sstevel@tonic-gate 		_rej.rej_name = name;
33196206Sab196087 		DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
33206206Sab196087 		    ld_targ.t_m.m_mach));
33210Sstevel@tonic-gate 		if (rej->rej_type == 0) {
33220Sstevel@tonic-gate 			*rej = _rej;
33230Sstevel@tonic-gate 			rej->rej_name = strdup(_rej.rej_name);
33240Sstevel@tonic-gate 		}
3325*12254SAli.Bahrami@Oracle.COM 		return (0);
33260Sstevel@tonic-gate 	}
33270Sstevel@tonic-gate 	if ((error == 0) || (error == S_ERROR))
3328*12254SAli.Bahrami@Oracle.COM 		return (error);
3329*12254SAli.Bahrami@Oracle.COM 
3330*12254SAli.Bahrami@Oracle.COM 	if (ifl_ret)
3331*12254SAli.Bahrami@Oracle.COM 		*ifl_ret = ifl;
3332*12254SAli.Bahrami@Oracle.COM 	return (1);
33330Sstevel@tonic-gate }
33340Sstevel@tonic-gate 
33350Sstevel@tonic-gate /*
33360Sstevel@tonic-gate  * Having successfully opened a file, set up the necessary elf structures to
33370Sstevel@tonic-gate  * process it further.  This small section of processing is slightly different
33380Sstevel@tonic-gate  * from the elf initialization required to process a relocatable object from an
33392850Srie  * archive (see libs.c: ld_process_archive()).
33400Sstevel@tonic-gate  */
3341*12254SAli.Bahrami@Oracle.COM uintptr_t
33422978Srie ld_process_open(const char *opath, const char *ofile, int *fd, Ofl_desc *ofl,
3343*12254SAli.Bahrami@Oracle.COM     Word flags, Rej_desc *rej, Ifl_desc **ifl_ret)
33440Sstevel@tonic-gate {
33452978Srie 	Elf		*elf;
33462978Srie 	const char	*npath = opath;
33472978Srie 	const char	*nfile = ofile;
33480Sstevel@tonic-gate 
33492978Srie 	if ((elf = elf_begin(*fd, ELF_C_READ, NULL)) == NULL) {
33502978Srie 		eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_BEGIN), npath);
33510Sstevel@tonic-gate 		ofl->ofl_flags |= FLG_OF_FATAL;
3352*12254SAli.Bahrami@Oracle.COM 		return (0);
33530Sstevel@tonic-gate 	}
33540Sstevel@tonic-gate 
33552978Srie 	/*
33562978Srie 	 * Determine whether the support library wishes to process this open.
33572978Srie 	 * The support library may return:
33582978Srie 	 *   .	a different ELF descriptor (in which case they should have
33592978Srie 	 *	closed the original)
33602978Srie 	 *   .	a different file descriptor (in which case they should have
33612978Srie 	 *	closed the original)
33622978Srie 	 *   .	a different path and file name (presumably associated with
33632978Srie 	 *	a different file descriptor)
33642978Srie 	 *
33652978Srie 	 * A file descriptor of -1, or and ELF descriptor of zero indicates
33662978Srie 	 * the file should be ignored.
33672978Srie 	 */
33682978Srie 	ld_sup_open(ofl, &npath, &nfile, fd, flags, &elf, NULL, 0,
33692978Srie 	    elf_kind(elf));
33702978Srie 
33712978Srie 	if ((*fd == -1) || (elf == NULL))
3372*12254SAli.Bahrami@Oracle.COM 		return (0);
3373*12254SAli.Bahrami@Oracle.COM 
3374*12254SAli.Bahrami@Oracle.COM 	return (ld_process_ifl(npath, nfile, *fd, elf, flags, ofl, rej,
3375*12254SAli.Bahrami@Oracle.COM 	    ifl_ret));
33760Sstevel@tonic-gate }
33770Sstevel@tonic-gate 
33780Sstevel@tonic-gate /*
33798598SRod.Evans@Sun.COM  * Having successfully mapped a file, set up the necessary elf structures to
33808598SRod.Evans@Sun.COM  * process it further.  This routine is patterned after ld_process_open() and
33818598SRod.Evans@Sun.COM  * is only called by ld.so.1(1) to process a relocatable object.
33828598SRod.Evans@Sun.COM  */
33838598SRod.Evans@Sun.COM Ifl_desc *
33848598SRod.Evans@Sun.COM ld_process_mem(const char *path, const char *file, char *addr, size_t size,
33858598SRod.Evans@Sun.COM     Ofl_desc *ofl, Rej_desc *rej)
33868598SRod.Evans@Sun.COM {
3387*12254SAli.Bahrami@Oracle.COM 	Elf		*elf;
3388*12254SAli.Bahrami@Oracle.COM 	uintptr_t	open_ret;
3389*12254SAli.Bahrami@Oracle.COM 	Ifl_desc	*ifl;
33908598SRod.Evans@Sun.COM 
33918598SRod.Evans@Sun.COM 	if ((elf = elf_memory(addr, size)) == NULL) {
33928598SRod.Evans@Sun.COM 		eprintf(ofl->ofl_lml, ERR_ELF, MSG_INTL(MSG_ELF_MEMORY), path);
33938598SRod.Evans@Sun.COM 		ofl->ofl_flags |= FLG_OF_FATAL;
33948598SRod.Evans@Sun.COM 		return (0);
33958598SRod.Evans@Sun.COM 	}
33968598SRod.Evans@Sun.COM 
3397*12254SAli.Bahrami@Oracle.COM 	open_ret = ld_process_ifl(path, file, 0, elf, 0, ofl, rej, &ifl);
3398*12254SAli.Bahrami@Oracle.COM 	if (open_ret != 1)
3399*12254SAli.Bahrami@Oracle.COM 		return ((Ifl_desc *) open_ret);
3400*12254SAli.Bahrami@Oracle.COM 	return (ifl);
34018598SRod.Evans@Sun.COM }
34028598SRod.Evans@Sun.COM 
34038598SRod.Evans@Sun.COM /*
34040Sstevel@tonic-gate  * Process a required library (i.e. the dependency of a shared object).
34050Sstevel@tonic-gate  * Combine the directory and filename, check the resultant path size, and try
34060Sstevel@tonic-gate  * opening the pathname.
34070Sstevel@tonic-gate  */
34081618Srie static Ifl_desc *
34090Sstevel@tonic-gate process_req_lib(Sdf_desc *sdf, const char *dir, const char *file,
34107463SRod.Evans@Sun.COM     Ofl_desc *ofl, Rej_desc *rej)
34110Sstevel@tonic-gate {
34120Sstevel@tonic-gate 	size_t		dlen, plen;
34130Sstevel@tonic-gate 	int		fd;
34140Sstevel@tonic-gate 	char		path[PATH_MAX];
34150Sstevel@tonic-gate 	const char	*_dir = dir;
34160Sstevel@tonic-gate 
34170Sstevel@tonic-gate 	/*
34180Sstevel@tonic-gate 	 * Determine the sizes of the directory and filename to insure we don't
34190Sstevel@tonic-gate 	 * exceed our buffer.
34200Sstevel@tonic-gate 	 */
34210Sstevel@tonic-gate 	if ((dlen = strlen(dir)) == 0) {
34220Sstevel@tonic-gate 		_dir = MSG_ORIG(MSG_STR_DOT);
34230Sstevel@tonic-gate 		dlen = 1;
34240Sstevel@tonic-gate 	}
34250Sstevel@tonic-gate 	dlen++;
34260Sstevel@tonic-gate 	plen = dlen + strlen(file) + 1;
34270Sstevel@tonic-gate 	if (plen > PATH_MAX) {
34281618Srie 		eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_FIL_PTHTOLONG),
34291618Srie 		    _dir, file);
34300Sstevel@tonic-gate 		ofl->ofl_flags |= FLG_OF_FATAL;
34310Sstevel@tonic-gate 		return (0);
34320Sstevel@tonic-gate 	}
34330Sstevel@tonic-gate 
34340Sstevel@tonic-gate 	/*
34350Sstevel@tonic-gate 	 * Build the entire pathname and try and open the file.
34360Sstevel@tonic-gate 	 */
34370Sstevel@tonic-gate 	(void) strcpy(path, _dir);
34380Sstevel@tonic-gate 	(void) strcat(path, MSG_ORIG(MSG_STR_SLASH));
34390Sstevel@tonic-gate 	(void) strcat(path, file);
34401618Srie 	DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name,
34411618Srie 	    sdf->sdf_rfile, path));
34420Sstevel@tonic-gate 
34430Sstevel@tonic-gate 	if ((fd = open(path, O_RDONLY)) == -1)
34440Sstevel@tonic-gate 		return (0);
34450Sstevel@tonic-gate 	else {
3446*12254SAli.Bahrami@Oracle.COM 		uintptr_t	open_ret;
34470Sstevel@tonic-gate 		Ifl_desc	*ifl;
34480Sstevel@tonic-gate 		char		*_path;
34490Sstevel@tonic-gate 
345010792SRod.Evans@Sun.COM 		if ((_path = libld_malloc(strlen(path) + 1)) == NULL)
34510Sstevel@tonic-gate 			return ((Ifl_desc *)S_ERROR);
34520Sstevel@tonic-gate 		(void) strcpy(_path, path);
3453*12254SAli.Bahrami@Oracle.COM 		open_ret = ld_process_open(_path, &_path[dlen], &fd, ofl,
3454*12254SAli.Bahrami@Oracle.COM 		    0, rej, &ifl);
34552978Srie 		if (fd != -1)
34562978Srie 			(void) close(fd);
3457*12254SAli.Bahrami@Oracle.COM 		if (open_ret != 1)
3458*12254SAli.Bahrami@Oracle.COM 			return ((Ifl_desc *)open_ret);
34590Sstevel@tonic-gate 		return (ifl);
34600Sstevel@tonic-gate 	}
34610Sstevel@tonic-gate }
34620Sstevel@tonic-gate 
34630Sstevel@tonic-gate /*
34640Sstevel@tonic-gate  * Finish any library processing.  Walk the list of so's that have been listed
34650Sstevel@tonic-gate  * as "included" by shared objects we have previously processed.  Examine them,
34660Sstevel@tonic-gate  * without adding them as explicit dependents of this program, in order to
34670Sstevel@tonic-gate  * complete our symbol definition process.  The search path rules are:
34680Sstevel@tonic-gate  *
346910792SRod.Evans@Sun.COM  *  -	use any user supplied paths, i.e. LD_LIBRARY_PATH and -L, then
34700Sstevel@tonic-gate  *
347110792SRod.Evans@Sun.COM  *  -	use any RPATH defined within the parent shared object, then
34720Sstevel@tonic-gate  *
347310792SRod.Evans@Sun.COM  *  -	use the default directories, i.e. LIBPATH or -YP.
34740Sstevel@tonic-gate  */
34750Sstevel@tonic-gate uintptr_t
34761618Srie ld_finish_libs(Ofl_desc *ofl)
34770Sstevel@tonic-gate {
34789131SRod.Evans@Sun.COM 	Aliste		idx1;
34790Sstevel@tonic-gate 	Sdf_desc	*sdf;
34800Sstevel@tonic-gate 	Rej_desc	rej = { 0 };
34810Sstevel@tonic-gate 
34820Sstevel@tonic-gate 	/*
34830Sstevel@tonic-gate 	 * Make sure we are back in dynamic mode.
34840Sstevel@tonic-gate 	 */
34850Sstevel@tonic-gate 	ofl->ofl_flags |= FLG_OF_DYNLIBS;
34860Sstevel@tonic-gate 
34879131SRod.Evans@Sun.COM 	for (APLIST_TRAVERSE(ofl->ofl_soneed, idx1, sdf)) {
34889131SRod.Evans@Sun.COM 		Aliste		idx2;
34892850Srie 		char		*path, *slash = NULL;
34900Sstevel@tonic-gate 		int		fd;
34910Sstevel@tonic-gate 		Ifl_desc	*ifl;
34922850Srie 		char		*file = (char *)sdf->sdf_name;
34930Sstevel@tonic-gate 
34940Sstevel@tonic-gate 		/*
34950Sstevel@tonic-gate 		 * See if this file has already been processed.  At the time
34960Sstevel@tonic-gate 		 * this implicit dependency was determined there may still have
34971109Srie 		 * been more explicit dependencies to process.  Note, if we ever
34980Sstevel@tonic-gate 		 * do parse the command line three times we would be able to
34991109Srie 		 * do all this checking when processing the dynamic section.
35000Sstevel@tonic-gate 		 */
35010Sstevel@tonic-gate 		if (sdf->sdf_file)
35020Sstevel@tonic-gate 			continue;
35030Sstevel@tonic-gate 
35049131SRod.Evans@Sun.COM 		for (APLIST_TRAVERSE(ofl->ofl_sos, idx2, ifl)) {
35050Sstevel@tonic-gate 			if (!(ifl->ifl_flags & FLG_IF_NEEDSTR) &&
35060Sstevel@tonic-gate 			    (strcmp(file, ifl->ifl_soname) == 0)) {
35070Sstevel@tonic-gate 				sdf->sdf_file = ifl;
35080Sstevel@tonic-gate 				break;
35090Sstevel@tonic-gate 			}
35100Sstevel@tonic-gate 		}
35110Sstevel@tonic-gate 		if (sdf->sdf_file)
35120Sstevel@tonic-gate 			continue;
35130Sstevel@tonic-gate 
35140Sstevel@tonic-gate 		/*
35152850Srie 		 * If the current path name element embeds a "/", then it's to
35162850Srie 		 * be taken "as is", with no searching involved.  Process all
35172850Srie 		 * "/" occurrences, so that we can deduce the base file name.
35180Sstevel@tonic-gate 		 */
35192850Srie 		for (path = file; *path; path++) {
35200Sstevel@tonic-gate 			if (*path == '/')
35212850Srie 				slash = path;
35222850Srie 		}
35232850Srie 		if (slash) {
35241618Srie 			DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name,
35251618Srie 			    sdf->sdf_rfile, file));
35260Sstevel@tonic-gate 			if ((fd = open(file, O_RDONLY)) == -1) {
35271618Srie 				eprintf(ofl->ofl_lml, ERR_WARNING,
35281618Srie 				    MSG_INTL(MSG_FIL_NOTFOUND), file,
35291618Srie 				    sdf->sdf_rfile);
35300Sstevel@tonic-gate 			} else {
3531*12254SAli.Bahrami@Oracle.COM 				uintptr_t	open_ret;
35320Sstevel@tonic-gate 				Rej_desc	_rej = { 0 };
35330Sstevel@tonic-gate 
3534*12254SAli.Bahrami@Oracle.COM 				open_ret = ld_process_open(file, ++slash, &fd,
3535*12254SAli.Bahrami@Oracle.COM 				    ofl, 0, &_rej, &ifl);
35362978Srie 				if (fd != -1)
35372978Srie 					(void) close(fd);
3538*12254SAli.Bahrami@Oracle.COM 				if (open_ret == S_ERROR)
35397359SRod.Evans@Sun.COM 					return (S_ERROR);
35400Sstevel@tonic-gate 
35410Sstevel@tonic-gate 				if (_rej.rej_type) {
35424734Sab196087 					Conv_reject_desc_buf_t rej_buf;
35434734Sab196087 
35441618Srie 					eprintf(ofl->ofl_lml, ERR_WARNING,
35450Sstevel@tonic-gate 					    MSG_INTL(reject[_rej.rej_type]),
35460Sstevel@tonic-gate 					    _rej.rej_name ? rej.rej_name :
35470Sstevel@tonic-gate 					    MSG_INTL(MSG_STR_UNKNOWN),
35486206Sab196087 					    conv_reject_desc(&_rej, &rej_buf,
35496206Sab196087 					    ld_targ.t_m.m_mach));
35500Sstevel@tonic-gate 				} else
35510Sstevel@tonic-gate 					sdf->sdf_file = ifl;
35520Sstevel@tonic-gate 			}
35530Sstevel@tonic-gate 			continue;
35540Sstevel@tonic-gate 		}
35550Sstevel@tonic-gate 
35560Sstevel@tonic-gate 		/*
35570Sstevel@tonic-gate 		 * Now search for this file in any user defined directories.
35580Sstevel@tonic-gate 		 */
35599131SRod.Evans@Sun.COM 		for (APLIST_TRAVERSE(ofl->ofl_ulibdirs, idx2, path)) {
35600Sstevel@tonic-gate 			Rej_desc	_rej = { 0 };
35610Sstevel@tonic-gate 
35620Sstevel@tonic-gate 			ifl = process_req_lib(sdf, path, file, ofl, &_rej);
35630Sstevel@tonic-gate 			if (ifl == (Ifl_desc *)S_ERROR) {
35640Sstevel@tonic-gate 				return (S_ERROR);
35650Sstevel@tonic-gate 			}
35660Sstevel@tonic-gate 			if (_rej.rej_type) {
35670Sstevel@tonic-gate 				if (rej.rej_type == 0) {
35680Sstevel@tonic-gate 					rej = _rej;
35690Sstevel@tonic-gate 					rej.rej_name = strdup(_rej.rej_name);
35700Sstevel@tonic-gate 				}
35710Sstevel@tonic-gate 			}
35720Sstevel@tonic-gate 			if (ifl) {
35730Sstevel@tonic-gate 				sdf->sdf_file = ifl;
35740Sstevel@tonic-gate 				break;
35750Sstevel@tonic-gate 			}
35760Sstevel@tonic-gate 		}
35770Sstevel@tonic-gate 		if (sdf->sdf_file)
35780Sstevel@tonic-gate 			continue;
35790Sstevel@tonic-gate 
35800Sstevel@tonic-gate 		/*
35810Sstevel@tonic-gate 		 * Next use the local rules defined within the parent shared
35820Sstevel@tonic-gate 		 * object.
35830Sstevel@tonic-gate 		 */
35840Sstevel@tonic-gate 		if (sdf->sdf_rpath != NULL) {
35850Sstevel@tonic-gate 			char	*rpath, *next;
35860Sstevel@tonic-gate 
35870Sstevel@tonic-gate 			rpath = libld_malloc(strlen(sdf->sdf_rpath) + 1);
358810792SRod.Evans@Sun.COM 			if (rpath == NULL)
35890Sstevel@tonic-gate 				return (S_ERROR);
35900Sstevel@tonic-gate 			(void) strcpy(rpath, sdf->sdf_rpath);
35911618Srie 			DBG_CALL(Dbg_libs_path(ofl->ofl_lml, rpath,
35921618Srie 			    LA_SER_RUNPATH, sdf->sdf_rfile));
35930Sstevel@tonic-gate 			if ((path = strtok_r(rpath,
35940Sstevel@tonic-gate 			    MSG_ORIG(MSG_STR_COLON), &next)) != NULL) {
35950Sstevel@tonic-gate 				do {
35960Sstevel@tonic-gate 					Rej_desc	_rej = { 0 };
35970Sstevel@tonic-gate 
35980Sstevel@tonic-gate 					path = expand(sdf->sdf_rfile, path,
35990Sstevel@tonic-gate 					    &next);
36000Sstevel@tonic-gate 
36010Sstevel@tonic-gate 					ifl = process_req_lib(sdf, path,
36024716Sab196087 					    file, ofl, &_rej);
36030Sstevel@tonic-gate 					if (ifl == (Ifl_desc *)S_ERROR) {
36040Sstevel@tonic-gate 						return (S_ERROR);
36050Sstevel@tonic-gate 					}
36064716Sab196087 					if ((_rej.rej_type) &&
36074716Sab196087 					    (rej.rej_type == 0)) {
36084716Sab196087 						rej = _rej;
36094716Sab196087 						rej.rej_name =
36104716Sab196087 						    strdup(_rej.rej_name);
36110Sstevel@tonic-gate 					}
36120Sstevel@tonic-gate 					if (ifl) {
36130Sstevel@tonic-gate 						sdf->sdf_file = ifl;
36140Sstevel@tonic-gate 						break;
36150Sstevel@tonic-gate 					}
36160Sstevel@tonic-gate 				} while ((path = strtok_r(NULL,
36170Sstevel@tonic-gate 				    MSG_ORIG(MSG_STR_COLON), &next)) != NULL);
36180Sstevel@tonic-gate 			}
36190Sstevel@tonic-gate 		}
36200Sstevel@tonic-gate 		if (sdf->sdf_file)
36210Sstevel@tonic-gate 			continue;
36220Sstevel@tonic-gate 
36230Sstevel@tonic-gate 		/*
36240Sstevel@tonic-gate 		 * Finally try the default library search directories.
36250Sstevel@tonic-gate 		 */
36269131SRod.Evans@Sun.COM 		for (APLIST_TRAVERSE(ofl->ofl_dlibdirs, idx2, path)) {
36270Sstevel@tonic-gate 			Rej_desc	_rej = { 0 };
36280Sstevel@tonic-gate 
36290Sstevel@tonic-gate 			ifl = process_req_lib(sdf, path, file, ofl, &rej);
36300Sstevel@tonic-gate 			if (ifl == (Ifl_desc *)S_ERROR) {
36310Sstevel@tonic-gate 				return (S_ERROR);
36320Sstevel@tonic-gate 			}
36330Sstevel@tonic-gate 			if (_rej.rej_type) {
36340Sstevel@tonic-gate 				if (rej.rej_type == 0) {
36350Sstevel@tonic-gate 					rej = _rej;
36360Sstevel@tonic-gate 					rej.rej_name = strdup(_rej.rej_name);
36370Sstevel@tonic-gate 				}
36380Sstevel@tonic-gate 			}
36390Sstevel@tonic-gate 			if (ifl) {
36400Sstevel@tonic-gate 				sdf->sdf_file = ifl;
36410Sstevel@tonic-gate 				break;
36420Sstevel@tonic-gate 			}
36430Sstevel@tonic-gate 		}
36440Sstevel@tonic-gate 		if (sdf->sdf_file)
36450Sstevel@tonic-gate 			continue;
36460Sstevel@tonic-gate 
36470Sstevel@tonic-gate 		/*
36480Sstevel@tonic-gate 		 * If we've got this far we haven't found the shared object.
36490Sstevel@tonic-gate 		 * If an object was found, but was rejected for some reason,
36500Sstevel@tonic-gate 		 * print a diagnostic to that effect, otherwise generate a
36510Sstevel@tonic-gate 		 * generic "not found" diagnostic.
36520Sstevel@tonic-gate 		 */
36530Sstevel@tonic-gate 		if (rej.rej_type) {
36544734Sab196087 			Conv_reject_desc_buf_t rej_buf;
36554734Sab196087 
36561618Srie 			eprintf(ofl->ofl_lml, ERR_WARNING,
36571618Srie 			    MSG_INTL(reject[rej.rej_type]),
36580Sstevel@tonic-gate 			    rej.rej_name ? rej.rej_name :
36594734Sab196087 			    MSG_INTL(MSG_STR_UNKNOWN),
36606206Sab196087 			    conv_reject_desc(&rej, &rej_buf,
36616206Sab196087 			    ld_targ.t_m.m_mach));
36620Sstevel@tonic-gate 		} else {
36631618Srie 			eprintf(ofl->ofl_lml, ERR_WARNING,
36641618Srie 			    MSG_INTL(MSG_FIL_NOTFOUND), file, sdf->sdf_rfile);
36650Sstevel@tonic-gate 		}
36660Sstevel@tonic-gate 	}
36670Sstevel@tonic-gate 
36680Sstevel@tonic-gate 	/*
36690Sstevel@tonic-gate 	 * Finally, now that all objects have been input, make sure any version
36700Sstevel@tonic-gate 	 * requirements have been met.
36710Sstevel@tonic-gate 	 */
36721618Srie 	return (ld_vers_verify(ofl));
36730Sstevel@tonic-gate }
3674