17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
55aefb655Srie * Common Development and Distribution License (the "License").
65aefb655Srie * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21fb1354edSrie
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright (c) 1988 AT&T
247c478bd9Sstevel@tonic-gate * All Rights Reserved
257c478bd9Sstevel@tonic-gate *
26dc0f59e5SAli Bahrami * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
273fc1e289SBryan Cantrill * Copyright (c) 2012, Joyent, Inc. All rights reserved.
28*56726c7eSRobert Mustacchi * Copyright 2022 Oxide Computer Company
297c478bd9Sstevel@tonic-gate */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate * Processing of relocatable objects and shared objects.
337c478bd9Sstevel@tonic-gate */
34ba2be530Sab
35ba2be530Sab #define ELF_TARGET_AMD64
36ba2be530Sab #define ELF_TARGET_SPARC
37ba2be530Sab
387c478bd9Sstevel@tonic-gate #include <stdio.h>
397c478bd9Sstevel@tonic-gate #include <string.h>
407c478bd9Sstevel@tonic-gate #include <fcntl.h>
417c478bd9Sstevel@tonic-gate #include <unistd.h>
427c478bd9Sstevel@tonic-gate #include <link.h>
437c478bd9Sstevel@tonic-gate #include <limits.h>
447c478bd9Sstevel@tonic-gate #include <sys/stat.h>
457c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
467c478bd9Sstevel@tonic-gate #include <debug.h>
477c478bd9Sstevel@tonic-gate #include <msg.h>
487c478bd9Sstevel@tonic-gate #include <_libld.h>
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate * Decide if we can link against this input file.
527c478bd9Sstevel@tonic-gate */
537c478bd9Sstevel@tonic-gate static int
ifl_verify(Ehdr * ehdr,Ofl_desc * ofl,Rej_desc * rej)540e233487SRod Evans ifl_verify(Ehdr *ehdr, Ofl_desc *ofl, Rej_desc *rej)
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate * Check the validity of the elf header information for compatibility
587c478bd9Sstevel@tonic-gate * with this machine and our own internal elf library.
597c478bd9Sstevel@tonic-gate */
60ba2be530Sab if ((ehdr->e_machine != ld_targ.t_m.m_mach) &&
61ba2be530Sab ((ehdr->e_machine != ld_targ.t_m.m_machplus) &&
62ba2be530Sab ((ehdr->e_flags & ld_targ.t_m.m_flagsplus) == 0))) {
637c478bd9Sstevel@tonic-gate rej->rej_type = SGS_REJ_MACH;
647c478bd9Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_machine;
657c478bd9Sstevel@tonic-gate return (0);
667c478bd9Sstevel@tonic-gate }
67ba2be530Sab if (ehdr->e_ident[EI_DATA] != ld_targ.t_m.m_data) {
687c478bd9Sstevel@tonic-gate rej->rej_type = SGS_REJ_DATA;
697c478bd9Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_ident[EI_DATA];
707c478bd9Sstevel@tonic-gate return (0);
717c478bd9Sstevel@tonic-gate }
725aefb655Srie if (ehdr->e_version > ofl->ofl_dehdr->e_version) {
737c478bd9Sstevel@tonic-gate rej->rej_type = SGS_REJ_VERSION;
747c478bd9Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_version;
757c478bd9Sstevel@tonic-gate return (0);
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate return (1);
787c478bd9Sstevel@tonic-gate }
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate * Check sanity of file header and allocate an infile descriptor
827c478bd9Sstevel@tonic-gate * for the file being processed.
837c478bd9Sstevel@tonic-gate */
845aefb655Srie static Ifl_desc *
ifl_setup(const char * name,Ehdr * ehdr,Elf * elf,Word flags,Ofl_desc * ofl,Rej_desc * rej)85d840867fSab ifl_setup(const char *name, Ehdr *ehdr, Elf *elf, Word flags, Ofl_desc *ofl,
867c478bd9Sstevel@tonic-gate Rej_desc *rej)
877c478bd9Sstevel@tonic-gate {
887c478bd9Sstevel@tonic-gate Ifl_desc *ifl;
897c478bd9Sstevel@tonic-gate Rej_desc _rej = { 0 };
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate if (ifl_verify(ehdr, ofl, &_rej) == 0) {
927c478bd9Sstevel@tonic-gate _rej.rej_name = name;
93ba2be530Sab DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
94ba2be530Sab ld_targ.t_m.m_mach));
957c478bd9Sstevel@tonic-gate if (rej->rej_type == 0) {
967c478bd9Sstevel@tonic-gate *rej = _rej;
977c478bd9Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name);
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate return (0);
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate
102635216b6SRod Evans if ((ifl = libld_calloc(1, sizeof (Ifl_desc))) == NULL)
1037c478bd9Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR);
1047c478bd9Sstevel@tonic-gate ifl->ifl_name = name;
1057c478bd9Sstevel@tonic-gate ifl->ifl_ehdr = ehdr;
1067c478bd9Sstevel@tonic-gate ifl->ifl_elf = elf;
1077c478bd9Sstevel@tonic-gate ifl->ifl_flags = flags;
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate * Is this file using 'extended Section Indexes'. If so, use the
1117c478bd9Sstevel@tonic-gate * e_shnum & e_shstrndx which can be found at:
1127c478bd9Sstevel@tonic-gate *
1137c478bd9Sstevel@tonic-gate * e_shnum == Shdr[0].sh_size
1147c478bd9Sstevel@tonic-gate * e_shstrndx == Shdr[0].sh_link
1157c478bd9Sstevel@tonic-gate */
1167c478bd9Sstevel@tonic-gate if ((ehdr->e_shnum == 0) && (ehdr->e_shoff != 0)) {
1177c478bd9Sstevel@tonic-gate Elf_Scn *scn;
1187c478bd9Sstevel@tonic-gate Shdr *shdr0;
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate if ((scn = elf_getscn(elf, 0)) == NULL) {
1211007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN),
1221007fd6fSAli Bahrami name);
1237c478bd9Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR);
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate if ((shdr0 = elf_getshdr(scn)) == NULL) {
1261007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR),
1271007fd6fSAli Bahrami name);
1287c478bd9Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR);
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate ifl->ifl_shnum = (Word)shdr0->sh_size;
1317c478bd9Sstevel@tonic-gate if (ehdr->e_shstrndx == SHN_XINDEX)
1327c478bd9Sstevel@tonic-gate ifl->ifl_shstrndx = shdr0->sh_link;
1337c478bd9Sstevel@tonic-gate else
1347c478bd9Sstevel@tonic-gate ifl->ifl_shstrndx = ehdr->e_shstrndx;
1357c478bd9Sstevel@tonic-gate } else {
1367c478bd9Sstevel@tonic-gate ifl->ifl_shnum = ehdr->e_shnum;
1377c478bd9Sstevel@tonic-gate ifl->ifl_shstrndx = ehdr->e_shstrndx;
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate if ((ifl->ifl_isdesc = libld_calloc(ifl->ifl_shnum,
141635216b6SRod Evans sizeof (Is_desc *))) == NULL)
1427c478bd9Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR);
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate * Record this new input file on the shared object or relocatable
1467c478bd9Sstevel@tonic-gate * object input file list.
1477c478bd9Sstevel@tonic-gate */
1487c478bd9Sstevel@tonic-gate if (ifl->ifl_ehdr->e_type == ET_DYN) {
14957ef7aa9SRod Evans if (aplist_append(&ofl->ofl_sos, ifl, AL_CNT_OFL_LIBS) == NULL)
15057ef7aa9SRod Evans return ((Ifl_desc *)S_ERROR);
1517c478bd9Sstevel@tonic-gate } else {
15257ef7aa9SRod Evans if (aplist_append(&ofl->ofl_objs, ifl, AL_CNT_OFL_OBJS) == NULL)
15357ef7aa9SRod Evans return ((Ifl_desc *)S_ERROR);
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate return (ifl);
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
159c9d20e65SRichard Lowe /*
160c9d20e65SRichard Lowe * Return TRUE if shdr is to be excluded via SHF_EXCLUDE.
161c9d20e65SRichard Lowe *
162c9d20e65SRichard Lowe * If SHF_EXCLUDE is set, a section should be excluded from dynamic output.
163c9d20e65SRichard Lowe * Additionally, it will be excluded from kernel modules (-ztype=kmod).
164c9d20e65SRichard Lowe */
165c9d20e65SRichard Lowe static inline Boolean
section_is_exclude(Ofl_desc * ofl,Shdr * shdr)166c9d20e65SRichard Lowe section_is_exclude(Ofl_desc *ofl, Shdr *shdr)
167c9d20e65SRichard Lowe {
168c9d20e65SRichard Lowe if (shdr->sh_flags & SHF_EXCLUDE) {
169c9d20e65SRichard Lowe if ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0)
170c9d20e65SRichard Lowe return (TRUE);
171c9d20e65SRichard Lowe if (ofl->ofl_flags & FLG_OF_KMOD)
172c9d20e65SRichard Lowe return (TRUE);
173c9d20e65SRichard Lowe }
174c9d20e65SRichard Lowe return (FALSE);
175c9d20e65SRichard Lowe }
176c9d20e65SRichard Lowe
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate * Process a generic section. The appropriate section information is added
1797c478bd9Sstevel@tonic-gate * to the files input descriptor list.
1807c478bd9Sstevel@tonic-gate */
1815aefb655Srie static uintptr_t
process_section(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)1827c478bd9Sstevel@tonic-gate process_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1837c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
1847c478bd9Sstevel@tonic-gate {
1857c478bd9Sstevel@tonic-gate Is_desc *isp;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate * Create a new input section descriptor. If this is a NOBITS
1897c478bd9Sstevel@tonic-gate * section elf_getdata() will still create a data buffer (the buffer
1907c478bd9Sstevel@tonic-gate * will be null and the size will reflect the actual memory size).
1917c478bd9Sstevel@tonic-gate */
192fb12490aSRichard Lowe if ((isp = libld_calloc(1, sizeof (Is_desc))) == NULL)
1937c478bd9Sstevel@tonic-gate return (S_ERROR);
1947c478bd9Sstevel@tonic-gate isp->is_shdr = shdr;
1957c478bd9Sstevel@tonic-gate isp->is_file = ifl;
1967c478bd9Sstevel@tonic-gate isp->is_name = name;
1977c478bd9Sstevel@tonic-gate isp->is_scnndx = ndx;
19854d82594Sseizo isp->is_flags = FLG_IS_EXTERNAL;
1990e233487SRod Evans isp->is_keyident = ident;
2000e233487SRod Evans
2017c478bd9Sstevel@tonic-gate if ((isp->is_indata = elf_getdata(scn, NULL)) == NULL) {
2021007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETDATA),
2035aefb655Srie ifl->ifl_name);
2047c478bd9Sstevel@tonic-gate return (0);
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate
207c9d20e65SRichard Lowe if (section_is_exclude(ofl, shdr))
2087c478bd9Sstevel@tonic-gate isp->is_flags |= FLG_IS_DISCARD;
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate * Add the new input section to the files input section list and
2120e233487SRod Evans * flag whether the section needs placing in an output section. This
2130e233487SRod Evans * placement is deferred until all input section processing has been
2140e233487SRod Evans * completed, as SHT_GROUP sections can provide information that will
2150e233487SRod Evans * affect how other sections within the file should be placed.
2167c478bd9Sstevel@tonic-gate */
2177c478bd9Sstevel@tonic-gate ifl->ifl_isdesc[ndx] = isp;
2187c478bd9Sstevel@tonic-gate
2190e233487SRod Evans if (ident) {
2200e233487SRod Evans if (shdr->sh_flags & ALL_SHF_ORDER) {
2210e233487SRod Evans isp->is_flags |= FLG_IS_ORDERED;
2220e233487SRod Evans ifl->ifl_flags |= FLG_IF_ORDERED;
2237010c12aSrie }
2240e233487SRod Evans isp->is_flags |= FLG_IS_PLACE;
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate return (1);
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate /*
2307c478bd9Sstevel@tonic-gate * Determine the software capabilities of the object being built from the
2317c478bd9Sstevel@tonic-gate * capabilities of the input relocatable objects. One software capability
2327c478bd9Sstevel@tonic-gate * is presently recognized, and represented with the following (sys/elf.h):
2337c478bd9Sstevel@tonic-gate *
2347c478bd9Sstevel@tonic-gate * SF1_SUNW_FPKNWN use/non-use of frame pointer is known, and
2357c478bd9Sstevel@tonic-gate * SF1_SUNW_FPUSED the frame pointer is in use.
2367c478bd9Sstevel@tonic-gate *
2377c478bd9Sstevel@tonic-gate * The resolution of the present fame pointer state, and the capabilities
2387c478bd9Sstevel@tonic-gate * provided by a new input relocatable object are:
2397c478bd9Sstevel@tonic-gate *
2407c478bd9Sstevel@tonic-gate * new input relocatable object
2417c478bd9Sstevel@tonic-gate *
2427c478bd9Sstevel@tonic-gate * present | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown>
2437c478bd9Sstevel@tonic-gate * state | SF1_SUNW_FPUSED | |
2447c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------------------
2457c478bd9Sstevel@tonic-gate * SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN
2467c478bd9Sstevel@tonic-gate * SF1_SUNW_FPUSED | SF1_SUNW_FPUSED | | SF1_SUNW_FPUSED
2477c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------------------
2487c478bd9Sstevel@tonic-gate * SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN
2497c478bd9Sstevel@tonic-gate * | | |
2507c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------------------
2517c478bd9Sstevel@tonic-gate * <unknown> | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown>
2527c478bd9Sstevel@tonic-gate * | SF1_SUNW_FPUSED | |
2537c478bd9Sstevel@tonic-gate */
2547c478bd9Sstevel@tonic-gate static void
sf1_cap(Ofl_desc * ofl,Xword val,Ifl_desc * ifl,Is_desc * cisp)2554a8d0ea7SAli Bahrami sf1_cap(Ofl_desc *ofl, Xword val, Ifl_desc *ifl, Is_desc *cisp)
2567c478bd9Sstevel@tonic-gate {
25769112eddSAli Bahrami #define FP_FLAGS (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)
25869112eddSAli Bahrami
2597c478bd9Sstevel@tonic-gate Xword badval;
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate /*
26208278a5eSRod Evans * If a mapfile has established definitions to override any object
26308278a5eSRod Evans * capabilities, ignore any new object capabilities.
2647c478bd9Sstevel@tonic-gate */
26569112eddSAli Bahrami if (ofl->ofl_flags1 & FLG_OF1_OVSFCAP1) {
26608278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
26769112eddSAli Bahrami CA_SUNW_SF_1, val, ld_targ.t_m.m_mach));
2687c478bd9Sstevel@tonic-gate return;
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate
271bebb829dSRod Evans #if !defined(_ELF64)
27208278a5eSRod Evans if (ifl && (ifl->ifl_ehdr->e_type == ET_REL)) {
273bebb829dSRod Evans /*
274bebb829dSRod Evans * The SF1_SUNW_ADDR32 is only meaningful when building a 64-bit
275bebb829dSRod Evans * object. Warn the user, and remove the setting, if we're
276bebb829dSRod Evans * building a 32-bit object.
277bebb829dSRod Evans */
278bebb829dSRod Evans if (val & SF1_SUNW_ADDR32) {
2791007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
2804a8d0ea7SAli Bahrami MSG_INTL(MSG_FIL_INADDR32SF1), ifl->ifl_name,
2814a8d0ea7SAli Bahrami EC_WORD(cisp->is_scnndx), cisp->is_name);
282bebb829dSRod Evans val &= ~SF1_SUNW_ADDR32;
283bebb829dSRod Evans }
284bebb829dSRod Evans }
285bebb829dSRod Evans #endif
2867c478bd9Sstevel@tonic-gate /*
2877c478bd9Sstevel@tonic-gate * If this object doesn't specify any capabilities, ignore it, and
2887c478bd9Sstevel@tonic-gate * leave the state as is.
2897c478bd9Sstevel@tonic-gate */
2907c478bd9Sstevel@tonic-gate if (val == 0)
2917c478bd9Sstevel@tonic-gate return;
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate /*
2947c478bd9Sstevel@tonic-gate * Make sure we only accept known software capabilities. Note, that
2957c478bd9Sstevel@tonic-gate * an F1_SUNW_FPUSED by itself is viewed as bad practice.
2967c478bd9Sstevel@tonic-gate */
2977c478bd9Sstevel@tonic-gate if ((badval = (val & ~SF1_SUNW_MASK)) != 0) {
2981007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1),
2994a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(cisp->is_scnndx), cisp->is_name,
3004a8d0ea7SAli Bahrami EC_XWORD(badval));
3017c478bd9Sstevel@tonic-gate val &= SF1_SUNW_MASK;
3027c478bd9Sstevel@tonic-gate }
30369112eddSAli Bahrami if ((val & FP_FLAGS) == SF1_SUNW_FPUSED) {
3041007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1),
3054a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(cisp->is_scnndx), cisp->is_name,
3064a8d0ea7SAli Bahrami EC_XWORD(val));
3077c478bd9Sstevel@tonic-gate return;
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate
310bebb829dSRod Evans /*
311bebb829dSRod Evans * If the input file is not a relocatable object, then we're only here
312bebb829dSRod Evans * to warn the user of any questionable capabilities.
313bebb829dSRod Evans */
314bebb829dSRod Evans if (ifl->ifl_ehdr->e_type != ET_REL) {
315bebb829dSRod Evans #if defined(_ELF64)
316bebb829dSRod Evans /*
317bebb829dSRod Evans * If we're building a 64-bit executable, and we come across a
318bebb829dSRod Evans * dependency that requires a restricted address space, then
319bebb829dSRod Evans * that dependencies requirement can only be satisfied if the
320bebb829dSRod Evans * executable triggers the restricted address space. This is a
321bebb829dSRod Evans * warning rather than a fatal error, as the possibility exists
322bebb829dSRod Evans * that an appropriate dependency will be provided at runtime.
323bebb829dSRod Evans * The runtime linker will refuse to use this dependency.
324bebb829dSRod Evans */
325bebb829dSRod Evans if ((val & SF1_SUNW_ADDR32) && (ofl->ofl_flags & FLG_OF_EXEC) &&
32608278a5eSRod Evans ((ofl->ofl_ocapset.oc_sf_1.cm_val &
32769112eddSAli Bahrami SF1_SUNW_ADDR32) == 0)) {
3281007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
3294a8d0ea7SAli Bahrami MSG_INTL(MSG_FIL_EXADDR32SF1), ifl->ifl_name,
3304a8d0ea7SAli Bahrami EC_WORD(cisp->is_scnndx), cisp->is_name);
331bebb829dSRod Evans }
332bebb829dSRod Evans #endif
333bebb829dSRod Evans return;
334bebb829dSRod Evans }
335bebb829dSRod Evans
33669112eddSAli Bahrami if (DBG_ENABLED) {
33708278a5eSRod Evans Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_CURRENT, CA_SUNW_SF_1,
33808278a5eSRod Evans ofl->ofl_ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach);
33908278a5eSRod Evans Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_NEW, CA_SUNW_SF_1,
34069112eddSAli Bahrami val, ld_targ.t_m.m_mach);
34169112eddSAli Bahrami }
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate /*
3447c478bd9Sstevel@tonic-gate * Determine the resolution of the present frame pointer and the
3457c478bd9Sstevel@tonic-gate * new input relocatable objects frame pointer.
3467c478bd9Sstevel@tonic-gate */
34708278a5eSRod Evans if ((ofl->ofl_ocapset.oc_sf_1.cm_val & FP_FLAGS) == FP_FLAGS) {
3487c478bd9Sstevel@tonic-gate /*
3497c478bd9Sstevel@tonic-gate * If the new relocatable object isn't using a frame pointer,
3507c478bd9Sstevel@tonic-gate * reduce the present state to unused.
3517c478bd9Sstevel@tonic-gate */
35269112eddSAli Bahrami if ((val & FP_FLAGS) != FP_FLAGS)
35308278a5eSRod Evans ofl->ofl_ocapset.oc_sf_1.cm_val &= ~SF1_SUNW_FPUSED;
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate /*
35669112eddSAli Bahrami * Having processed the frame pointer bits, remove them from
35769112eddSAli Bahrami * the value so they don't get OR'd in below.
3587c478bd9Sstevel@tonic-gate */
35969112eddSAli Bahrami val &= ~FP_FLAGS;
36069112eddSAli Bahrami
36108278a5eSRod Evans } else if ((ofl->ofl_ocapset.oc_sf_1.cm_val & SF1_SUNW_FPKNWN) == 0) {
36269112eddSAli Bahrami /*
36369112eddSAli Bahrami * If the present frame pointer state is unknown, mask it out
36469112eddSAli Bahrami * and allow the values from the new relocatable object
36569112eddSAli Bahrami * to overwrite them.
36669112eddSAli Bahrami */
36708278a5eSRod Evans ofl->ofl_ocapset.oc_sf_1.cm_val &= ~FP_FLAGS;
36869112eddSAli Bahrami } else {
36969112eddSAli Bahrami /* Do not take the frame pointer flags from the object */
37069112eddSAli Bahrami val &= ~FP_FLAGS;
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate
37308278a5eSRod Evans ofl->ofl_ocapset.oc_sf_1.cm_val |= val;
37469112eddSAli Bahrami
37508278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_RESOLVED,
37608278a5eSRod Evans CA_SUNW_SF_1, ofl->ofl_ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach));
37769112eddSAli Bahrami
37869112eddSAli Bahrami #undef FP_FLAGS
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gate /*
3827c478bd9Sstevel@tonic-gate * Determine the hardware capabilities of the object being built from the
3837c478bd9Sstevel@tonic-gate * capabilities of the input relocatable objects. There's really little to
3847c478bd9Sstevel@tonic-gate * do here, other than to offer diagnostics, hardware capabilities are simply
3857c478bd9Sstevel@tonic-gate * additive.
3867c478bd9Sstevel@tonic-gate */
3877c478bd9Sstevel@tonic-gate static void
hw_cap(Ofl_desc * ofl,Xword tag,Xword val)38808278a5eSRod Evans hw_cap(Ofl_desc *ofl, Xword tag, Xword val)
3897c478bd9Sstevel@tonic-gate {
39008278a5eSRod Evans elfcap_mask_t *hwcap;
39108278a5eSRod Evans ofl_flag_t flags1;
39208278a5eSRod Evans
393*56726c7eSRobert Mustacchi switch (tag) {
394*56726c7eSRobert Mustacchi case CA_SUNW_HW_1:
39508278a5eSRod Evans hwcap = &ofl->ofl_ocapset.oc_hw_1.cm_val;
39608278a5eSRod Evans flags1 = FLG_OF1_OVHWCAP1;
397*56726c7eSRobert Mustacchi break;
398*56726c7eSRobert Mustacchi case CA_SUNW_HW_2:
39908278a5eSRod Evans hwcap = &ofl->ofl_ocapset.oc_hw_2.cm_val;
40008278a5eSRod Evans flags1 = FLG_OF1_OVHWCAP2;
401*56726c7eSRobert Mustacchi break;
402*56726c7eSRobert Mustacchi case CA_SUNW_HW_3:
403*56726c7eSRobert Mustacchi hwcap = &ofl->ofl_ocapset.oc_hw_3.cm_val;
404*56726c7eSRobert Mustacchi flags1 = FLG_OF1_OVHWCAP3;
405*56726c7eSRobert Mustacchi break;
406*56726c7eSRobert Mustacchi default:
407*56726c7eSRobert Mustacchi assert(0);
40808278a5eSRod Evans }
40908278a5eSRod Evans
4107c478bd9Sstevel@tonic-gate /*
41108278a5eSRod Evans * If a mapfile has established definitions to override any object
41208278a5eSRod Evans * capabilities, ignore any new object capabilities.
4137c478bd9Sstevel@tonic-gate */
41408278a5eSRod Evans if (ofl->ofl_flags1 & flags1) {
41508278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
41608278a5eSRod Evans tag, val, ld_targ.t_m.m_mach));
4177c478bd9Sstevel@tonic-gate return;
4187c478bd9Sstevel@tonic-gate }
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate /*
4217c478bd9Sstevel@tonic-gate * If this object doesn't specify any capabilities, ignore it, and
4227c478bd9Sstevel@tonic-gate * leave the state as is.
4237c478bd9Sstevel@tonic-gate */
4247c478bd9Sstevel@tonic-gate if (val == 0)
4257c478bd9Sstevel@tonic-gate return;
4267c478bd9Sstevel@tonic-gate
42769112eddSAli Bahrami if (DBG_ENABLED) {
42808278a5eSRod Evans Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_CURRENT, CA_SUNW_HW_1,
42908278a5eSRod Evans ofl->ofl_ocapset.oc_hw_1.cm_val, ld_targ.t_m.m_mach);
43008278a5eSRod Evans Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_NEW, CA_SUNW_HW_1,
43108278a5eSRod Evans val, ld_targ.t_m.m_mach);
43269112eddSAli Bahrami }
4337c478bd9Sstevel@tonic-gate
43408278a5eSRod Evans *hwcap |= val;
4357c478bd9Sstevel@tonic-gate
43608278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_RESOLVED, tag,
43708278a5eSRod Evans *hwcap, ld_targ.t_m.m_mach));
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate
4407c478bd9Sstevel@tonic-gate /*
44108278a5eSRod Evans * Promote a machine capability or platform capability to the output file.
44208278a5eSRod Evans * Multiple instances of these names can be defined.
4437c478bd9Sstevel@tonic-gate */
4447c478bd9Sstevel@tonic-gate static void
str_cap(Ofl_desc * ofl,char * pstr,ofl_flag_t flags,Xword tag,Caplist * list)44508278a5eSRod Evans str_cap(Ofl_desc *ofl, char *pstr, ofl_flag_t flags, Xword tag, Caplist *list)
4467c478bd9Sstevel@tonic-gate {
44708278a5eSRod Evans Capstr *capstr;
44808278a5eSRod Evans Aliste idx;
44908278a5eSRod Evans Boolean found = FALSE;
4507c478bd9Sstevel@tonic-gate
45108278a5eSRod Evans /*
45208278a5eSRod Evans * If a mapfile has established definitions to override this capability,
45308278a5eSRod Evans * ignore any new capability.
45408278a5eSRod Evans */
45508278a5eSRod Evans if (ofl->ofl_flags1 & flags) {
45608278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
45708278a5eSRod Evans tag, pstr));
45808278a5eSRod Evans return;
45908278a5eSRod Evans }
46008278a5eSRod Evans
46108278a5eSRod Evans for (ALIST_TRAVERSE(list->cl_val, idx, capstr)) {
46208278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
46308278a5eSRod Evans DBG_STATE_CURRENT, tag, capstr->cs_str));
46408278a5eSRod Evans if (strcmp(capstr->cs_str, pstr) == 0)
46508278a5eSRod Evans found = TRUE;
46608278a5eSRod Evans }
46708278a5eSRod Evans
46808278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_NEW, tag, pstr));
46908278a5eSRod Evans
47008278a5eSRod Evans if (found == FALSE) {
47108278a5eSRod Evans if ((capstr = alist_append(&list->cl_val, NULL,
47208278a5eSRod Evans sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL) {
47308278a5eSRod Evans ofl->ofl_flags |= FLG_OF_FATAL;
47408278a5eSRod Evans return;
47508278a5eSRod Evans }
47608278a5eSRod Evans capstr->cs_str = pstr;
47708278a5eSRod Evans }
47808278a5eSRod Evans
47908278a5eSRod Evans if (DBG_ENABLED) {
48008278a5eSRod Evans for (ALIST_TRAVERSE(list->cl_val, idx, capstr)) {
48108278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
48208278a5eSRod Evans DBG_STATE_RESOLVED, tag, capstr->cs_str));
48308278a5eSRod Evans }
48408278a5eSRod Evans }
48508278a5eSRod Evans }
48608278a5eSRod Evans
48708278a5eSRod Evans /*
48808278a5eSRod Evans * Promote a capability identifier to the output file. A capability group can
48908278a5eSRod Evans * only have one identifier, and thus only the first identifier seen from any
49008278a5eSRod Evans * input relocatable objects is retained. An explicit user defined identifier,
49108278a5eSRod Evans * rather than an an identifier fabricated by ld(1) with -z symbcap processing,
49208278a5eSRod Evans * takes precedence. Note, a user may have defined an identifier via a mapfile,
49308278a5eSRod Evans * in which case the mapfile identifier is retained.
49408278a5eSRod Evans */
49508278a5eSRod Evans static void
id_cap(Ofl_desc * ofl,char * pstr,oc_flag_t flags)49608278a5eSRod Evans id_cap(Ofl_desc *ofl, char *pstr, oc_flag_t flags)
49708278a5eSRod Evans {
49808278a5eSRod Evans Objcapset *ocapset = &ofl->ofl_ocapset;
49908278a5eSRod Evans
50008278a5eSRod Evans if (ocapset->oc_id.cs_str) {
50108278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_CURRENT,
50208278a5eSRod Evans CA_SUNW_ID, ocapset->oc_id.cs_str));
50308278a5eSRod Evans
50408278a5eSRod Evans if ((ocapset->oc_flags & FLG_OCS_USRDEFID) ||
50508278a5eSRod Evans ((flags & FLG_OCS_USRDEFID) == 0)) {
50608278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
50708278a5eSRod Evans DBG_STATE_IGNORED, CA_SUNW_ID, pstr));
50808278a5eSRod Evans return;
50908278a5eSRod Evans }
51008278a5eSRod Evans }
51108278a5eSRod Evans
51208278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_NEW,
51308278a5eSRod Evans CA_SUNW_ID, pstr));
51408278a5eSRod Evans
51508278a5eSRod Evans ocapset->oc_id.cs_str = pstr;
51608278a5eSRod Evans ocapset->oc_flags |= flags;
51708278a5eSRod Evans
51808278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_RESOLVED,
51908278a5eSRod Evans CA_SUNW_ID, pstr));
52008278a5eSRod Evans }
52108278a5eSRod Evans
52208278a5eSRod Evans /*
52308278a5eSRod Evans * Promote a capabilities group to the object capabilities. This catches a
52408278a5eSRod Evans * corner case. An object capabilities file can be converted to symbol
52508278a5eSRod Evans * capabilities with -z symbolcap. However, if the user has indicated that all
52608278a5eSRod Evans * the symbols should be demoted, we'd be left with a symbol capabilities file,
52708278a5eSRod Evans * with no associated symbols. Catch this case by promoting the symbol
52808278a5eSRod Evans * capabilities back to object capabilities.
52908278a5eSRod Evans */
53008278a5eSRod Evans void
ld_cap_move_symtoobj(Ofl_desc * ofl)53108278a5eSRod Evans ld_cap_move_symtoobj(Ofl_desc *ofl)
53208278a5eSRod Evans {
53308278a5eSRod Evans Cap_group *cgp;
53408278a5eSRod Evans Aliste idx1;
53508278a5eSRod Evans
53608278a5eSRod Evans for (APLIST_TRAVERSE(ofl->ofl_capgroups, idx1, cgp)) {
53708278a5eSRod Evans Objcapset *scapset = &cgp->cg_set;
53808278a5eSRod Evans Capstr *capstr;
53908278a5eSRod Evans Aliste idx2;
54008278a5eSRod Evans
54108278a5eSRod Evans if (scapset->oc_id.cs_str) {
54208278a5eSRod Evans if (scapset->oc_flags & FLG_OCS_USRDEFID)
54308278a5eSRod Evans id_cap(ofl, scapset->oc_id.cs_str,
54408278a5eSRod Evans scapset->oc_flags);
54508278a5eSRod Evans }
54608278a5eSRod Evans if (scapset->oc_plat.cl_val) {
54708278a5eSRod Evans for (ALIST_TRAVERSE(scapset->oc_plat.cl_val, idx2,
54808278a5eSRod Evans capstr)) {
54908278a5eSRod Evans str_cap(ofl, capstr->cs_str, FLG_OF1_OVPLATCAP,
55008278a5eSRod Evans CA_SUNW_PLAT, &ofl->ofl_ocapset.oc_plat);
55108278a5eSRod Evans }
55208278a5eSRod Evans }
55308278a5eSRod Evans if (scapset->oc_mach.cl_val) {
55408278a5eSRod Evans for (ALIST_TRAVERSE(scapset->oc_mach.cl_val, idx2,
55508278a5eSRod Evans capstr)) {
55608278a5eSRod Evans str_cap(ofl, capstr->cs_str, FLG_OF1_OVMACHCAP,
55708278a5eSRod Evans CA_SUNW_MACH, &ofl->ofl_ocapset.oc_mach);
55808278a5eSRod Evans }
55908278a5eSRod Evans }
560*56726c7eSRobert Mustacchi if (scapset->oc_hw_3.cm_val)
561*56726c7eSRobert Mustacchi hw_cap(ofl, CA_SUNW_HW_3, scapset->oc_hw_3.cm_val);
562*56726c7eSRobert Mustacchi
56308278a5eSRod Evans if (scapset->oc_hw_2.cm_val)
56408278a5eSRod Evans hw_cap(ofl, CA_SUNW_HW_2, scapset->oc_hw_2.cm_val);
56508278a5eSRod Evans
56608278a5eSRod Evans if (scapset->oc_hw_1.cm_val)
56708278a5eSRod Evans hw_cap(ofl, CA_SUNW_HW_1, scapset->oc_hw_1.cm_val);
56808278a5eSRod Evans
56908278a5eSRod Evans if (scapset->oc_sf_1.cm_val)
57008278a5eSRod Evans sf1_cap(ofl, scapset->oc_sf_1.cm_val, NULL, NULL);
57108278a5eSRod Evans }
57208278a5eSRod Evans }
57308278a5eSRod Evans
57408278a5eSRod Evans /*
57508278a5eSRod Evans * Determine whether a capabilities group already exists that describes this
57608278a5eSRod Evans * new capabilities group.
57708278a5eSRod Evans *
57808278a5eSRod Evans * Note, a capability group identifier, CA_SUNW_ID, isn't used as part of the
57908278a5eSRod Evans * comparison. This attribute simply assigns a diagnostic name to the group,
58008278a5eSRod Evans * and in the case of multiple identifiers, the first will be taken.
58108278a5eSRod Evans */
58208278a5eSRod Evans static Cap_group *
get_cap_group(Objcapset * ocapset,Word cnum,Ofl_desc * ofl,Is_desc * isp)58308278a5eSRod Evans get_cap_group(Objcapset *ocapset, Word cnum, Ofl_desc *ofl, Is_desc *isp)
58408278a5eSRod Evans {
58508278a5eSRod Evans Aliste idx;
58608278a5eSRod Evans Cap_group *cgp;
58708278a5eSRod Evans Word ccnum = cnum;
58808278a5eSRod Evans
58908278a5eSRod Evans /*
59008278a5eSRod Evans * If the new capabilities contains a CA_SUNW_ID, drop the count of the
59108278a5eSRod Evans * number of comparable items.
59208278a5eSRod Evans */
59308278a5eSRod Evans if (ocapset->oc_id.cs_str)
59408278a5eSRod Evans ccnum--;
59508278a5eSRod Evans
59608278a5eSRod Evans /*
59708278a5eSRod Evans * Traverse the existing symbols capabilities groups.
59808278a5eSRod Evans */
59908278a5eSRod Evans for (APLIST_TRAVERSE(ofl->ofl_capgroups, idx, cgp)) {
60008278a5eSRod Evans Word onum = cgp->cg_num;
60108278a5eSRod Evans Alist *calp, *oalp;
60208278a5eSRod Evans
60308278a5eSRod Evans if (cgp->cg_set.oc_id.cs_str)
60408278a5eSRod Evans onum--;
60508278a5eSRod Evans
60608278a5eSRod Evans if (onum != ccnum)
60708278a5eSRod Evans continue;
60808278a5eSRod Evans
60908278a5eSRod Evans if (cgp->cg_set.oc_hw_1.cm_val != ocapset->oc_hw_1.cm_val)
61008278a5eSRod Evans continue;
61108278a5eSRod Evans if (cgp->cg_set.oc_sf_1.cm_val != ocapset->oc_sf_1.cm_val)
61208278a5eSRod Evans continue;
61308278a5eSRod Evans if (cgp->cg_set.oc_hw_2.cm_val != ocapset->oc_hw_2.cm_val)
61408278a5eSRod Evans continue;
615*56726c7eSRobert Mustacchi if (cgp->cg_set.oc_hw_3.cm_val != ocapset->oc_hw_3.cm_val)
616*56726c7eSRobert Mustacchi continue;
61708278a5eSRod Evans
61808278a5eSRod Evans calp = cgp->cg_set.oc_plat.cl_val;
61908278a5eSRod Evans oalp = ocapset->oc_plat.cl_val;
62008278a5eSRod Evans if ((calp == NULL) && oalp)
62108278a5eSRod Evans continue;
62208278a5eSRod Evans if (calp && ((oalp == NULL) || cap_names_match(calp, oalp)))
62308278a5eSRod Evans continue;
62408278a5eSRod Evans
62508278a5eSRod Evans calp = cgp->cg_set.oc_mach.cl_val;
62608278a5eSRod Evans oalp = ocapset->oc_mach.cl_val;
62708278a5eSRod Evans if ((calp == NULL) && oalp)
62808278a5eSRod Evans continue;
62908278a5eSRod Evans if (calp && ((oalp == NULL) || cap_names_match(calp, oalp)))
63008278a5eSRod Evans continue;
63108278a5eSRod Evans
63208278a5eSRod Evans /*
63308278a5eSRod Evans * If a matching group is found, then this new group has
63408278a5eSRod Evans * already been supplied by a previous file, and hence the
63508278a5eSRod Evans * existing group can be used. Record this new input section,
63608278a5eSRod Evans * from which we can also derive the input file name, on the
63708278a5eSRod Evans * existing groups input sections.
63808278a5eSRod Evans */
63908278a5eSRod Evans if (aplist_append(&(cgp->cg_secs), isp,
64008278a5eSRod Evans AL_CNT_CAP_SECS) == NULL)
64108278a5eSRod Evans return (NULL);
64208278a5eSRod Evans return (cgp);
64308278a5eSRod Evans }
64408278a5eSRod Evans
64508278a5eSRod Evans /*
64608278a5eSRod Evans * If a capabilities group is not found, create a new one.
64708278a5eSRod Evans */
648fb12490aSRichard Lowe if (((cgp = libld_calloc(1, sizeof (Cap_group))) == NULL) ||
64908278a5eSRod Evans (aplist_append(&(ofl->ofl_capgroups), cgp,
65008278a5eSRod Evans AL_CNT_CAP_DESCS) == NULL))
65108278a5eSRod Evans return (NULL);
65208278a5eSRod Evans
65308278a5eSRod Evans /*
65408278a5eSRod Evans * If we're converting object capabilities to symbol capabilities and
65508278a5eSRod Evans * no CA_SUNW_ID is defined, fabricate one. This identifier is appended
65608278a5eSRod Evans * to all symbol names that are converted into capabilities symbols,
65708278a5eSRod Evans * see ld_sym_process().
65808278a5eSRod Evans */
65908278a5eSRod Evans if ((isp->is_file->ifl_flags & FLG_IF_OTOSCAP) &&
66008278a5eSRod Evans (ocapset->oc_id.cs_str == NULL)) {
66108278a5eSRod Evans size_t len;
66208278a5eSRod Evans
66308278a5eSRod Evans /*
66408278a5eSRod Evans * Create an identifier using the group number together with a
66508278a5eSRod Evans * default template. We allocate a buffer large enough for any
66608278a5eSRod Evans * possible number of items (way more than we need).
66708278a5eSRod Evans */
66808278a5eSRod Evans len = MSG_STR_CAPGROUPID_SIZE + CONV_INV_BUFSIZE;
66908278a5eSRod Evans if ((ocapset->oc_id.cs_str = libld_malloc(len)) == NULL)
67008278a5eSRod Evans return (NULL);
67108278a5eSRod Evans
67208278a5eSRod Evans (void) snprintf(ocapset->oc_id.cs_str, len,
67308278a5eSRod Evans MSG_ORIG(MSG_STR_CAPGROUPID),
67408278a5eSRod Evans aplist_nitems(ofl->ofl_capgroups));
67508278a5eSRod Evans cnum++;
67608278a5eSRod Evans }
67708278a5eSRod Evans
67808278a5eSRod Evans cgp->cg_set = *ocapset;
67908278a5eSRod Evans cgp->cg_num = cnum;
6807c478bd9Sstevel@tonic-gate
681c75e1b9dSrie /*
68208278a5eSRod Evans * Null the callers alist's as they've effectively been transferred
68308278a5eSRod Evans * to this new Cap_group.
68408278a5eSRod Evans */
68508278a5eSRod Evans ocapset->oc_plat.cl_val = ocapset->oc_mach.cl_val = NULL;
68608278a5eSRod Evans
68708278a5eSRod Evans /*
68808278a5eSRod Evans * Keep track of which input section, and hence input file, established
68908278a5eSRod Evans * this group.
69008278a5eSRod Evans */
69108278a5eSRod Evans if (aplist_append(&(cgp->cg_secs), isp, AL_CNT_CAP_SECS) == NULL)
69208278a5eSRod Evans return (NULL);
69308278a5eSRod Evans
69408278a5eSRod Evans /*
69508278a5eSRod Evans * Keep track of the number of symbol capabilities entries that will be
69608278a5eSRod Evans * required in the output file. Each group requires a terminating
69708278a5eSRod Evans * CA_SUNW_NULL.
69808278a5eSRod Evans */
69908278a5eSRod Evans ofl->ofl_capsymcnt += (cnum + 1);
70008278a5eSRod Evans return (cgp);
70108278a5eSRod Evans }
70208278a5eSRod Evans
70308278a5eSRod Evans /*
70408278a5eSRod Evans * Capture symbol capability family information. This data structure is focal
70508278a5eSRod Evans * in maintaining all symbol capability relationships, and provides for the
70608278a5eSRod Evans * eventual creation of a capabilities information section, and possibly a
70708278a5eSRod Evans * capabilities chain section.
70808278a5eSRod Evans *
70908278a5eSRod Evans * Capabilities families are lead by a CAPINFO_SUNW_GLOB symbol. This symbol
71008278a5eSRod Evans * provides the visible global symbol that is referenced by all external
71108278a5eSRod Evans * callers. This symbol may have aliases. For example, a weak/global symbol
71208278a5eSRod Evans * pair, such as memcpy()/_memcpy() may lead the same capabilities family.
71308278a5eSRod Evans * Each family contains one or more local symbol members. These members provide
71408278a5eSRod Evans * the capabilities specific functions, and are associated to a capabilities
71508278a5eSRod Evans * group. For example, the capability members memcpy%sun4u and memcpy%sun4v
71608278a5eSRod Evans * might be associated with the memcpy() capability family.
71708278a5eSRod Evans *
71808278a5eSRod Evans * This routine is called when a relocatable object that provides object
71908278a5eSRod Evans * capabilities is transformed into a symbol capabilities object, using the
72008278a5eSRod Evans * -z symbolcap option.
72108278a5eSRod Evans *
72208278a5eSRod Evans * This routine is also called to collect the SUNW_capinfo section information
72308278a5eSRod Evans * of a relocatable object that contains symbol capability definitions.
72408278a5eSRod Evans */
72508278a5eSRod Evans uintptr_t
ld_cap_add_family(Ofl_desc * ofl,Sym_desc * lsdp,Sym_desc * csdp,Cap_group * cgp,APlist ** csyms)72608278a5eSRod Evans ld_cap_add_family(Ofl_desc *ofl, Sym_desc *lsdp, Sym_desc *csdp, Cap_group *cgp,
72708278a5eSRod Evans APlist **csyms)
72808278a5eSRod Evans {
72908278a5eSRod Evans Cap_avlnode qcav, *cav;
73008278a5eSRod Evans avl_tree_t *avlt;
73108278a5eSRod Evans avl_index_t where = 0;
73208278a5eSRod Evans Cap_sym *mcsp;
73308278a5eSRod Evans Aliste idx;
73408278a5eSRod Evans
73508278a5eSRod Evans /*
73608278a5eSRod Evans * Make sure the capability families have an initialized AVL tree.
73708278a5eSRod Evans */
73808278a5eSRod Evans if ((avlt = ofl->ofl_capfamilies) == NULL) {
739fb12490aSRichard Lowe if ((avlt = libld_calloc(1, sizeof (avl_tree_t))) == NULL)
74008278a5eSRod Evans return (S_ERROR);
74108278a5eSRod Evans avl_create(avlt, &ld_sym_avl_comp, sizeof (Cap_avlnode),
74208278a5eSRod Evans SGSOFFSETOF(Cap_avlnode, cn_symavlnode.sav_node));
74308278a5eSRod Evans ofl->ofl_capfamilies = avlt;
74408278a5eSRod Evans
74508278a5eSRod Evans /*
74608278a5eSRod Evans * When creating a dynamic object, capability family members
74708278a5eSRod Evans * are maintained in a .SUNW_capchain, the first entry of
74808278a5eSRod Evans * which is the version number of the chain.
74908278a5eSRod Evans */
75008278a5eSRod Evans ofl->ofl_capchaincnt = 1;
75108278a5eSRod Evans }
75208278a5eSRod Evans
75308278a5eSRod Evans /*
75408278a5eSRod Evans * Determine whether a family already exists, and if not, create one
75508278a5eSRod Evans * using the lead family symbol.
75608278a5eSRod Evans */
75708278a5eSRod Evans qcav.cn_symavlnode.sav_hash = (Word)elf_hash(lsdp->sd_name);
75808278a5eSRod Evans qcav.cn_symavlnode.sav_name = lsdp->sd_name;
75908278a5eSRod Evans
76008278a5eSRod Evans if ((cav = avl_find(avlt, &qcav, &where)) == NULL) {
761fb12490aSRichard Lowe if ((cav = libld_calloc(1, sizeof (Cap_avlnode))) == NULL)
76208278a5eSRod Evans return (S_ERROR);
76308278a5eSRod Evans cav->cn_symavlnode.sav_hash = qcav.cn_symavlnode.sav_hash;
76408278a5eSRod Evans cav->cn_symavlnode.sav_name = qcav.cn_symavlnode.sav_name;
76508278a5eSRod Evans cav->cn_symavlnode.sav_sdp = lsdp;
76608278a5eSRod Evans
76708278a5eSRod Evans avl_insert(avlt, cav, where);
76808278a5eSRod Evans
76908278a5eSRod Evans /*
77008278a5eSRod Evans * When creating a dynamic object, capability family members
77108278a5eSRod Evans * are maintained in a .SUNW_capchain, each family starts with
77208278a5eSRod Evans * this lead symbol, and is terminated with a 0 element.
77308278a5eSRod Evans */
77408278a5eSRod Evans ofl->ofl_capchaincnt += 2;
77508278a5eSRod Evans }
77608278a5eSRod Evans
77708278a5eSRod Evans /*
77808278a5eSRod Evans * If no group information is provided then this request is to add a
77908278a5eSRod Evans * lead capability symbol, or lead symbol alias. If this is the lead
78008278a5eSRod Evans * symbol there's nothing more to do. Otherwise save the alias.
78108278a5eSRod Evans */
78208278a5eSRod Evans if (cgp == NULL) {
78308278a5eSRod Evans if ((lsdp != csdp) && (aplist_append(&cav->cn_aliases, csdp,
78408278a5eSRod Evans AL_CNT_CAP_ALIASES) == NULL))
78508278a5eSRod Evans return (S_ERROR);
78608278a5eSRod Evans
78708278a5eSRod Evans return (0);
78808278a5eSRod Evans }
78908278a5eSRod Evans
79008278a5eSRod Evans /*
79108278a5eSRod Evans * Determine whether a member of the same group as this new member is
79208278a5eSRod Evans * already defined within this family. If so, we have a multiply
79308278a5eSRod Evans * defined symbol.
79408278a5eSRod Evans */
79508278a5eSRod Evans for (APLIST_TRAVERSE(cav->cn_members, idx, mcsp)) {
79608278a5eSRod Evans Sym_desc *msdp;
79708278a5eSRod Evans
79808278a5eSRod Evans if (cgp != mcsp->cs_group)
79908278a5eSRod Evans continue;
80008278a5eSRod Evans
80108278a5eSRod Evans /*
80208278a5eSRod Evans * Diagnose that a multiple symbol definition exists.
80308278a5eSRod Evans */
80408278a5eSRod Evans msdp = mcsp->cs_sdp;
80508278a5eSRod Evans
8061007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_CAP_MULDEF),
80708278a5eSRod Evans demangle(lsdp->sd_name));
8081007fd6fSAli Bahrami ld_eprintf(ofl, ERR_NONE, MSG_INTL(MSG_CAP_MULDEFSYMS),
80908278a5eSRod Evans msdp->sd_file->ifl_name, msdp->sd_name,
81008278a5eSRod Evans csdp->sd_file->ifl_name, csdp->sd_name);
81108278a5eSRod Evans }
81208278a5eSRod Evans
81308278a5eSRod Evans /*
81408278a5eSRod Evans * Add this capabilities symbol member to the family.
81508278a5eSRod Evans */
81608278a5eSRod Evans if (((mcsp = libld_malloc(sizeof (Cap_sym))) == NULL) ||
81708278a5eSRod Evans (aplist_append(&cav->cn_members, mcsp, AL_CNT_CAP_MEMS) == NULL))
81808278a5eSRod Evans return (S_ERROR);
81908278a5eSRod Evans
82008278a5eSRod Evans mcsp->cs_sdp = csdp;
82108278a5eSRod Evans mcsp->cs_group = cgp;
82208278a5eSRod Evans
82308278a5eSRod Evans /*
82408278a5eSRod Evans * When creating a dynamic object, capability family members are
82508278a5eSRod Evans * maintained in a .SUNW_capchain. Account for this family member.
82608278a5eSRod Evans */
82708278a5eSRod Evans ofl->ofl_capchaincnt++;
82808278a5eSRod Evans
82908278a5eSRod Evans /*
83008278a5eSRod Evans * If this input file is undergoing object capabilities to symbol
83108278a5eSRod Evans * capabilities conversion, then this member is a new local symbol
83208278a5eSRod Evans * that has been generated from an original global symbol. Keep track
83308278a5eSRod Evans * of this symbol so that the output file symbol table can be populated
83408278a5eSRod Evans * with these new symbol entries.
83508278a5eSRod Evans */
83608278a5eSRod Evans if (csyms && (aplist_append(csyms, mcsp, AL_CNT_CAP_SYMS) == NULL))
83708278a5eSRod Evans return (S_ERROR);
83808278a5eSRod Evans
83908278a5eSRod Evans return (0);
84008278a5eSRod Evans }
84108278a5eSRod Evans
84208278a5eSRod Evans /*
84308278a5eSRod Evans * Process a SHT_SUNW_cap capabilities section.
84408278a5eSRod Evans */
84508278a5eSRod Evans static uintptr_t
process_cap(Ofl_desc * ofl,Ifl_desc * ifl,Is_desc * cisp)84608278a5eSRod Evans process_cap(Ofl_desc *ofl, Ifl_desc *ifl, Is_desc *cisp)
84708278a5eSRod Evans {
84808278a5eSRod Evans Objcapset ocapset = { 0 };
84908278a5eSRod Evans Cap_desc *cdp;
85008278a5eSRod Evans Cap *data, *cdata;
85108278a5eSRod Evans char *strs;
85208278a5eSRod Evans Word ndx, cnum;
85308278a5eSRod Evans int objcapndx, descapndx, symcapndx;
85408278a5eSRod Evans int nulls, capstrs = 0;
85508278a5eSRod Evans
85608278a5eSRod Evans /*
85708278a5eSRod Evans * Determine the capabilities data and size.
858c75e1b9dSrie */
859c75e1b9dSrie cdata = (Cap *)cisp->is_indata->d_buf;
860c75e1b9dSrie cnum = (Word)(cisp->is_shdr->sh_size / cisp->is_shdr->sh_entsize);
861c75e1b9dSrie
86208278a5eSRod Evans if ((cdata == NULL) || (cnum == 0))
86308278a5eSRod Evans return (0);
86408278a5eSRod Evans
86508278a5eSRod Evans DBG_CALL(Dbg_cap_sec_title(ofl->ofl_lml, ifl->ifl_name));
86608278a5eSRod Evans
86708278a5eSRod Evans /*
86808278a5eSRod Evans * Traverse the section to determine what capabilities groups are
86908278a5eSRod Evans * available.
87008278a5eSRod Evans *
87108278a5eSRod Evans * A capabilities section can contain one or more, CA_SUNW_NULL
87208278a5eSRod Evans * terminated groups.
87308278a5eSRod Evans *
87408278a5eSRod Evans * - The first group defines the object capabilities.
87508278a5eSRod Evans * - Additional groups define symbol capabilities.
87608278a5eSRod Evans * - Since the initial group is always reserved for object
87708278a5eSRod Evans * capabilities, any object with symbol capabilities must also
87808278a5eSRod Evans * have an object capabilities group. If the object has no object
87908278a5eSRod Evans * capabilities, an empty object group is defined, consisting of a
88008278a5eSRod Evans * CA_SUNW_NULL element in index [0].
88108278a5eSRod Evans * - If any capabilities require references to a named string, then
88208278a5eSRod Evans * the section header sh_info points to the associated string
88308278a5eSRod Evans * table.
88408278a5eSRod Evans * - If an object contains symbol capability groups, then the
88508278a5eSRod Evans * section header sh_link points to the associated capinfo table.
88608278a5eSRod Evans */
88708278a5eSRod Evans objcapndx = 0;
88808278a5eSRod Evans descapndx = symcapndx = -1;
88908278a5eSRod Evans nulls = 0;
89008278a5eSRod Evans
89108278a5eSRod Evans for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
89208278a5eSRod Evans switch (data->c_tag) {
89308278a5eSRod Evans case CA_SUNW_NULL:
89408278a5eSRod Evans /*
89508278a5eSRod Evans * If this is the first CA_SUNW_NULL entry, and no
89608278a5eSRod Evans * capabilities group has been found, then this object
89708278a5eSRod Evans * does not define any object capabilities.
89808278a5eSRod Evans */
89908278a5eSRod Evans if (nulls++ == 0) {
90008278a5eSRod Evans if (ndx == 0)
90108278a5eSRod Evans objcapndx = -1;
90208278a5eSRod Evans } else if ((symcapndx == -1) && (descapndx != -1))
90308278a5eSRod Evans symcapndx = descapndx;
90408278a5eSRod Evans
90508278a5eSRod Evans break;
90608278a5eSRod Evans
90708278a5eSRod Evans case CA_SUNW_PLAT:
90808278a5eSRod Evans case CA_SUNW_MACH:
90908278a5eSRod Evans case CA_SUNW_ID:
91008278a5eSRod Evans capstrs++;
91108278a5eSRod Evans /* FALLTHROUGH */
91208278a5eSRod Evans
91308278a5eSRod Evans case CA_SUNW_HW_1:
91408278a5eSRod Evans case CA_SUNW_SF_1:
91508278a5eSRod Evans case CA_SUNW_HW_2:
916*56726c7eSRobert Mustacchi case CA_SUNW_HW_3:
91708278a5eSRod Evans /*
91808278a5eSRod Evans * If this is the start of a new group, save it.
91908278a5eSRod Evans */
92008278a5eSRod Evans if (descapndx == -1)
92108278a5eSRod Evans descapndx = ndx;
92208278a5eSRod Evans break;
92308278a5eSRod Evans
92408278a5eSRod Evans default:
9251007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_UNKCAP),
9261007fd6fSAli Bahrami ifl->ifl_name, EC_WORD(cisp->is_scnndx),
9271007fd6fSAli Bahrami cisp->is_name, data->c_tag);
92808278a5eSRod Evans }
92908278a5eSRod Evans }
93008278a5eSRod Evans
93108278a5eSRod Evans /*
93208278a5eSRod Evans * If a string capabilities entry has been found, the capabilities
93308278a5eSRod Evans * section must reference the associated string table.
93408278a5eSRod Evans */
93508278a5eSRod Evans if (capstrs) {
93608278a5eSRod Evans Word info = cisp->is_shdr->sh_info;
93708278a5eSRod Evans
93808278a5eSRod Evans if ((info == 0) || (info > ifl->ifl_shnum)) {
9391007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHINFO),
9401007fd6fSAli Bahrami ifl->ifl_name, EC_WORD(cisp->is_scnndx),
9411007fd6fSAli Bahrami cisp->is_name, EC_XWORD(info));
94208278a5eSRod Evans return (S_ERROR);
94308278a5eSRod Evans }
94408278a5eSRod Evans strs = (char *)ifl->ifl_isdesc[info]->is_indata->d_buf;
94508278a5eSRod Evans }
94608278a5eSRod Evans
94708278a5eSRod Evans /*
94808278a5eSRod Evans * The processing of capabilities groups is as follows:
94908278a5eSRod Evans *
95008278a5eSRod Evans * - if a relocatable object provides only object capabilities, and
95108278a5eSRod Evans * the -z symbolcap option is in effect, then the object
95208278a5eSRod Evans * capabilities are transformed into symbol capabilities and the
95308278a5eSRod Evans * symbol capabilities are carried over to the output file.
95408278a5eSRod Evans * - in all other cases, any capabilities present in an input
95508278a5eSRod Evans * relocatable object are carried from the input object to the
95608278a5eSRod Evans * output without any transformation or conversion.
95708278a5eSRod Evans *
95808278a5eSRod Evans * Capture any object capabilities that are to be carried over to the
95908278a5eSRod Evans * output file.
96008278a5eSRod Evans */
96108278a5eSRod Evans if ((objcapndx == 0) &&
96208278a5eSRod Evans ((symcapndx != -1) || ((ofl->ofl_flags & FLG_OF_OTOSCAP) == 0))) {
96308278a5eSRod Evans for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
96408278a5eSRod Evans /*
96508278a5eSRod Evans * Object capabilities end at the first null.
96608278a5eSRod Evans */
96708278a5eSRod Evans if (data->c_tag == CA_SUNW_NULL)
96808278a5eSRod Evans break;
96908278a5eSRod Evans
97008278a5eSRod Evans /*
97108278a5eSRod Evans * Only the object software capabilities that are
97208278a5eSRod Evans * defined in a relocatable object become part of the
97308278a5eSRod Evans * object software capabilities in the output file.
97408278a5eSRod Evans * However, check the validity of any object software
97508278a5eSRod Evans * capabilities of any dependencies.
97608278a5eSRod Evans */
97708278a5eSRod Evans if (data->c_tag == CA_SUNW_SF_1) {
97808278a5eSRod Evans sf1_cap(ofl, data->c_un.c_val, ifl, cisp);
97908278a5eSRod Evans continue;
98008278a5eSRod Evans }
98108278a5eSRod Evans
98208278a5eSRod Evans /*
98308278a5eSRod Evans * The remaining capability types must come from a
98408278a5eSRod Evans * relocatable object in order to contribute to the
98508278a5eSRod Evans * output.
98608278a5eSRod Evans */
98708278a5eSRod Evans if (ifl->ifl_ehdr->e_type != ET_REL)
98808278a5eSRod Evans continue;
98908278a5eSRod Evans
99008278a5eSRod Evans switch (data->c_tag) {
9917c478bd9Sstevel@tonic-gate case CA_SUNW_HW_1:
99208278a5eSRod Evans case CA_SUNW_HW_2:
99308278a5eSRod Evans hw_cap(ofl, data->c_tag, data->c_un.c_val);
9947c478bd9Sstevel@tonic-gate break;
99508278a5eSRod Evans
99608278a5eSRod Evans case CA_SUNW_PLAT:
99708278a5eSRod Evans str_cap(ofl, strs + data->c_un.c_ptr,
99808278a5eSRod Evans FLG_OF1_OVPLATCAP, CA_SUNW_PLAT,
99908278a5eSRod Evans &ofl->ofl_ocapset.oc_plat);
1000c75e1b9dSrie break;
100108278a5eSRod Evans
100208278a5eSRod Evans case CA_SUNW_MACH:
100308278a5eSRod Evans str_cap(ofl, strs + data->c_un.c_ptr,
100408278a5eSRod Evans FLG_OF1_OVMACHCAP, CA_SUNW_MACH,
100508278a5eSRod Evans &ofl->ofl_ocapset.oc_mach);
100608278a5eSRod Evans break;
100708278a5eSRod Evans
100808278a5eSRod Evans case CA_SUNW_ID:
100908278a5eSRod Evans id_cap(ofl, strs + data->c_un.c_ptr,
101008278a5eSRod Evans FLG_OCS_USRDEFID);
10117c478bd9Sstevel@tonic-gate break;
101208278a5eSRod Evans
10137c478bd9Sstevel@tonic-gate default:
101408278a5eSRod Evans assert(0); /* Unknown capability type */
101508278a5eSRod Evans }
101608278a5eSRod Evans }
101708278a5eSRod Evans
101808278a5eSRod Evans /*
101908278a5eSRod Evans * If there are no symbol capabilities, or this objects
102008278a5eSRod Evans * capabilities aren't being transformed into a symbol
102108278a5eSRod Evans * capabilities, then we're done.
102208278a5eSRod Evans */
102308278a5eSRod Evans if ((symcapndx == -1) &&
102408278a5eSRod Evans ((ofl->ofl_flags & FLG_OF_OTOSCAP) == 0))
102508278a5eSRod Evans return (1);
102608278a5eSRod Evans }
102708278a5eSRod Evans
102808278a5eSRod Evans /*
102908278a5eSRod Evans * If these capabilities don't originate from a relocatable object
103008278a5eSRod Evans * there's no further processing required.
103108278a5eSRod Evans */
103208278a5eSRod Evans if (ifl->ifl_ehdr->e_type != ET_REL)
103308278a5eSRod Evans return (1);
103408278a5eSRod Evans
103508278a5eSRod Evans /*
103608278a5eSRod Evans * If this object only defines an object capabilities group, and the
103708278a5eSRod Evans * -z symbolcap option is in effect, then all global function symbols
103808278a5eSRod Evans * and initialized global data symbols are renamed and assigned to the
103908278a5eSRod Evans * transformed symbol capabilities group.
104008278a5eSRod Evans */
104108278a5eSRod Evans if ((objcapndx == 0) &&
104208278a5eSRod Evans (symcapndx == -1) && (ofl->ofl_flags & FLG_OF_OTOSCAP))
104308278a5eSRod Evans ifl->ifl_flags |= FLG_IF_OTOSCAP;
104408278a5eSRod Evans
104508278a5eSRod Evans /*
104608278a5eSRod Evans * Allocate a capabilities descriptor to collect the capabilities data
104708278a5eSRod Evans * for this input file. Allocate a mirror of the raw capabilities data
104808278a5eSRod Evans * that points to the individual symbol capabilities groups. An APlist
104908278a5eSRod Evans * is used, although it will be sparsely populated, as the list provides
105008278a5eSRod Evans * a convenient mechanism for traversal later.
105108278a5eSRod Evans */
1052fb12490aSRichard Lowe if (((cdp = libld_calloc(1, sizeof (Cap_desc))) == NULL) ||
105308278a5eSRod Evans (aplist_append(&(cdp->ca_groups), NULL, cnum) == NULL))
105408278a5eSRod Evans return (S_ERROR);
105508278a5eSRod Evans
105608278a5eSRod Evans /*
105708278a5eSRod Evans * Clear the allocated APlist data array, and assign the number of
105808278a5eSRod Evans * items as the total number of array items.
105908278a5eSRod Evans */
106008278a5eSRod Evans (void) memset(&cdp->ca_groups->apl_data[0], 0,
106108278a5eSRod Evans (cnum * sizeof (void *)));
106208278a5eSRod Evans cdp->ca_groups->apl_nitems = cnum;
106308278a5eSRod Evans
106408278a5eSRod Evans ifl->ifl_caps = cdp;
106508278a5eSRod Evans
106608278a5eSRod Evans /*
106708278a5eSRod Evans * Traverse the capabilities data, unpacking the data into a
106808278a5eSRod Evans * capabilities set. Process each capabilities set as a unique group.
106908278a5eSRod Evans */
107008278a5eSRod Evans descapndx = -1;
107108278a5eSRod Evans nulls = 0;
107208278a5eSRod Evans
107308278a5eSRod Evans for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
107408278a5eSRod Evans Capstr *capstr;
107508278a5eSRod Evans
107608278a5eSRod Evans switch (data->c_tag) {
107708278a5eSRod Evans case CA_SUNW_NULL:
107808278a5eSRod Evans nulls++;
107908278a5eSRod Evans
108008278a5eSRod Evans /*
108108278a5eSRod Evans * Process the capabilities group that this null entry
108208278a5eSRod Evans * terminates. The capabilities group that is returned
108308278a5eSRod Evans * will either point to this file's data, or to a
108408278a5eSRod Evans * matching capabilities group that has already been
108508278a5eSRod Evans * processed.
108608278a5eSRod Evans *
108708278a5eSRod Evans * Note, if this object defines object capabilities,
108808278a5eSRod Evans * the first group descriptor points to these object
108908278a5eSRod Evans * capabilities. It is only necessary to save this
109008278a5eSRod Evans * descriptor when object capabilities are being
109108278a5eSRod Evans * transformed into symbol capabilities (-z symbolcap).
109208278a5eSRod Evans */
109308278a5eSRod Evans if (descapndx != -1) {
109408278a5eSRod Evans if ((nulls > 1) ||
109508278a5eSRod Evans (ifl->ifl_flags & FLG_IF_OTOSCAP)) {
109608278a5eSRod Evans APlist *alp = cdp->ca_groups;
109708278a5eSRod Evans
109808278a5eSRod Evans if ((alp->apl_data[descapndx] =
109908278a5eSRod Evans get_cap_group(&ocapset,
110008278a5eSRod Evans (ndx - descapndx), ofl,
110108278a5eSRod Evans cisp)) == NULL)
110208278a5eSRod Evans return (S_ERROR);
110308278a5eSRod Evans }
110408278a5eSRod Evans
110508278a5eSRod Evans /*
110608278a5eSRod Evans * Clean up the capabilities data in preparation
110708278a5eSRod Evans * for processing additional groups. If the
110808278a5eSRod Evans * collected capabilities strings were used to
110908278a5eSRod Evans * establish a new output group, they will have
111008278a5eSRod Evans * been saved in get_cap_group(). If these
111108278a5eSRod Evans * descriptors still exist, then an existing
111208278a5eSRod Evans * descriptor has been used to associate with
111308278a5eSRod Evans * this file, and these string descriptors can
111408278a5eSRod Evans * be freed.
111508278a5eSRod Evans */
111608278a5eSRod Evans ocapset.oc_hw_1.cm_val =
111708278a5eSRod Evans ocapset.oc_sf_1.cm_val =
1118*56726c7eSRobert Mustacchi ocapset.oc_hw_2.cm_val =
1119*56726c7eSRobert Mustacchi ocapset.oc_hw_3.cm_val = 0;
112008278a5eSRod Evans if (ocapset.oc_plat.cl_val) {
112108278a5eSRod Evans free((void *)ocapset.oc_plat.cl_val);
112208278a5eSRod Evans ocapset.oc_plat.cl_val = NULL;
112308278a5eSRod Evans }
112408278a5eSRod Evans if (ocapset.oc_mach.cl_val) {
112508278a5eSRod Evans free((void *)ocapset.oc_mach.cl_val);
112608278a5eSRod Evans ocapset.oc_mach.cl_val = NULL;
112708278a5eSRod Evans }
112808278a5eSRod Evans descapndx = -1;
112908278a5eSRod Evans }
113008278a5eSRod Evans continue;
113108278a5eSRod Evans
113208278a5eSRod Evans case CA_SUNW_HW_1:
113308278a5eSRod Evans ocapset.oc_hw_1.cm_val = data->c_un.c_val;
113408278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
113508278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_HW_1,
113608278a5eSRod Evans ocapset.oc_hw_1.cm_val, ld_targ.t_m.m_mach));
113708278a5eSRod Evans break;
113808278a5eSRod Evans
113908278a5eSRod Evans case CA_SUNW_SF_1:
114008278a5eSRod Evans ocapset.oc_sf_1.cm_val = data->c_un.c_val;
114108278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
114208278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_SF_1,
114308278a5eSRod Evans ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach));
114408278a5eSRod Evans break;
114508278a5eSRod Evans
114608278a5eSRod Evans case CA_SUNW_HW_2:
114708278a5eSRod Evans ocapset.oc_hw_2.cm_val = data->c_un.c_val;
114808278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
114908278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_HW_2,
115008278a5eSRod Evans ocapset.oc_hw_2.cm_val, ld_targ.t_m.m_mach));
115108278a5eSRod Evans break;
115208278a5eSRod Evans
115308278a5eSRod Evans case CA_SUNW_PLAT:
115408278a5eSRod Evans if ((capstr = alist_append(&ocapset.oc_plat.cl_val,
115508278a5eSRod Evans NULL, sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL)
115608278a5eSRod Evans return (S_ERROR);
115708278a5eSRod Evans capstr->cs_str = strs + data->c_un.c_ptr;
115808278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
115908278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_PLAT, capstr->cs_str));
116008278a5eSRod Evans break;
116108278a5eSRod Evans
116208278a5eSRod Evans case CA_SUNW_MACH:
116308278a5eSRod Evans if ((capstr = alist_append(&ocapset.oc_mach.cl_val,
116408278a5eSRod Evans NULL, sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL)
116508278a5eSRod Evans return (S_ERROR);
116608278a5eSRod Evans capstr->cs_str = strs + data->c_un.c_ptr;
116708278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
116808278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_MACH, capstr->cs_str));
116908278a5eSRod Evans break;
117008278a5eSRod Evans
117108278a5eSRod Evans case CA_SUNW_ID:
117208278a5eSRod Evans ocapset.oc_id.cs_str = strs + data->c_un.c_ptr;
117308278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
117408278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_ID,
117508278a5eSRod Evans ocapset.oc_id.cs_str));
117608278a5eSRod Evans break;
1177*56726c7eSRobert Mustacchi
1178*56726c7eSRobert Mustacchi case CA_SUNW_HW_3:
1179*56726c7eSRobert Mustacchi ocapset.oc_hw_3.cm_val = data->c_un.c_val;
1180*56726c7eSRobert Mustacchi DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
1181*56726c7eSRobert Mustacchi DBG_STATE_ORIGINAL, CA_SUNW_HW_3,
1182*56726c7eSRobert Mustacchi ocapset.oc_hw_3.cm_val, ld_targ.t_m.m_mach));
1183*56726c7eSRobert Mustacchi break;
11847c478bd9Sstevel@tonic-gate }
118508278a5eSRod Evans
118608278a5eSRod Evans /*
118708278a5eSRod Evans * Save the start of this new group.
118808278a5eSRod Evans */
118908278a5eSRod Evans if (descapndx == -1)
119008278a5eSRod Evans descapndx = ndx;
11917c478bd9Sstevel@tonic-gate }
119208278a5eSRod Evans return (1);
119308278a5eSRod Evans }
119408278a5eSRod Evans
119508278a5eSRod Evans /*
119608278a5eSRod Evans * Capture any symbol capabilities symbols. An object file that contains symbol
119708278a5eSRod Evans * capabilities has an associated .SUNW_capinfo section. This section
119808278a5eSRod Evans * identifies which symbols are associated to which capabilities, together with
119908278a5eSRod Evans * their associated lead symbol. Each of these symbol pairs are recorded for
120008278a5eSRod Evans * processing later.
120108278a5eSRod Evans */
120208278a5eSRod Evans static uintptr_t
process_capinfo(Ofl_desc * ofl,Ifl_desc * ifl,Is_desc * isp)120308278a5eSRod Evans process_capinfo(Ofl_desc *ofl, Ifl_desc *ifl, Is_desc *isp)
120408278a5eSRod Evans {
120508278a5eSRod Evans Cap_desc *cdp = ifl->ifl_caps;
120608278a5eSRod Evans Capinfo *capinfo = isp->is_indata->d_buf;
120708278a5eSRod Evans Shdr *shdr = isp->is_shdr;
120808278a5eSRod Evans Word cndx, capinfonum;
120908278a5eSRod Evans
121008278a5eSRod Evans capinfonum = (Word)(shdr->sh_size / shdr->sh_entsize);
121108278a5eSRod Evans
121208278a5eSRod Evans if ((cdp == NULL) || (capinfo == NULL) || (capinfonum == 0))
121308278a5eSRod Evans return (0);
121408278a5eSRod Evans
121508278a5eSRod Evans for (cndx = 1, capinfo++; cndx < capinfonum; cndx++, capinfo++) {
121608278a5eSRod Evans Sym_desc *sdp, *lsdp;
121708278a5eSRod Evans Word lndx;
121808278a5eSRod Evans uchar_t gndx;
121908278a5eSRod Evans
122008278a5eSRod Evans if ((gndx = (uchar_t)ELF_C_GROUP(*capinfo)) == 0)
122108278a5eSRod Evans continue;
122208278a5eSRod Evans lndx = (Word)ELF_C_SYM(*capinfo);
122308278a5eSRod Evans
122408278a5eSRod Evans /*
122508278a5eSRod Evans * Catch any anomalies. A capabilities symbol should be valid,
122608278a5eSRod Evans * and the capabilities lead symbol should also be global.
122708278a5eSRod Evans * Note, ld(1) -z symbolcap would create local capabilities
122808278a5eSRod Evans * symbols, but we don't enforce this so as to give the
122908278a5eSRod Evans * compilation environment a little more freedom.
123008278a5eSRod Evans */
123108278a5eSRod Evans if ((sdp = ifl->ifl_oldndx[cndx]) == NULL) {
12321007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
123308278a5eSRod Evans MSG_INTL(MSG_CAPINFO_INVALSYM), ifl->ifl_name,
123408278a5eSRod Evans EC_WORD(isp->is_scnndx), isp->is_name, cndx,
123508278a5eSRod Evans MSG_INTL(MSG_STR_UNKNOWN));
123608278a5eSRod Evans continue;
123708278a5eSRod Evans }
123808278a5eSRod Evans if ((lndx == 0) || (lndx >= ifl->ifl_symscnt) ||
123908278a5eSRod Evans ((lsdp = ifl->ifl_oldndx[lndx]) == NULL) ||
124008278a5eSRod Evans (ELF_ST_BIND(lsdp->sd_sym->st_info) != STB_GLOBAL)) {
12411007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
124208278a5eSRod Evans MSG_INTL(MSG_CAPINFO_INVALLEAD), ifl->ifl_name,
124308278a5eSRod Evans EC_WORD(isp->is_scnndx), isp->is_name, cndx, lsdp ?
124408278a5eSRod Evans demangle(lsdp->sd_name) : MSG_INTL(MSG_STR_UNKNOWN),
124508278a5eSRod Evans lndx);
124608278a5eSRod Evans continue;
124708278a5eSRod Evans }
124808278a5eSRod Evans
124908278a5eSRod Evans /*
125008278a5eSRod Evans * Indicate that this is a capabilities symbol.
125108278a5eSRod Evans */
125208278a5eSRod Evans sdp->sd_flags |= FLG_SY_CAP;
125308278a5eSRod Evans
125408278a5eSRod Evans /*
125508278a5eSRod Evans * Save any global capability symbols. Global capability
125608278a5eSRod Evans * symbols are identified with a CAPINFO_SUNW_GLOB group id.
125708278a5eSRod Evans * The lead symbol for this global capability symbol is either
125808278a5eSRod Evans * the symbol itself, or an alias.
125908278a5eSRod Evans */
126008278a5eSRod Evans if (gndx == CAPINFO_SUNW_GLOB) {
126108278a5eSRod Evans if (ld_cap_add_family(ofl, lsdp, sdp,
126208278a5eSRod Evans NULL, NULL) == S_ERROR)
126308278a5eSRod Evans return (S_ERROR);
126408278a5eSRod Evans continue;
126508278a5eSRod Evans }
126608278a5eSRod Evans
126708278a5eSRod Evans /*
126808278a5eSRod Evans * Track the number of non-global capabilities symbols, as these
126908278a5eSRod Evans * are used to size any symbol tables. If we're generating a
127008278a5eSRod Evans * dynamic object, this symbol will be added to the dynamic
127108278a5eSRod Evans * symbol table, therefore ensure there is space in the dynamic
127208278a5eSRod Evans * string table.
127308278a5eSRod Evans */
127408278a5eSRod Evans ofl->ofl_caploclcnt++;
127508278a5eSRod Evans if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) &&
127608278a5eSRod Evans (st_insert(ofl->ofl_dynstrtab, sdp->sd_name) == -1))
127708278a5eSRod Evans return (S_ERROR);
127808278a5eSRod Evans
127908278a5eSRod Evans /*
128008278a5eSRod Evans * As we're tracking this local symbol as a capabilities symbol,
128108278a5eSRod Evans * reduce the local symbol count to compensate.
128208278a5eSRod Evans */
128308278a5eSRod Evans ofl->ofl_locscnt--;
128408278a5eSRod Evans
128508278a5eSRod Evans /*
128608278a5eSRod Evans * Determine whether the associated lead symbol indicates
128708278a5eSRod Evans * NODYNSORT. If so, remove this local entry from the
128808278a5eSRod Evans * SUNW_dynsort section too. NODYNSORT tagging can only be
128908278a5eSRod Evans * obtained from a mapfile symbol definition, and thus any
129008278a5eSRod Evans * global definition that has this tagging has already been
129108278a5eSRod Evans * instantiated and this instance resolved to it.
129208278a5eSRod Evans */
129308278a5eSRod Evans if (lsdp->sd_flags & FLG_SY_NODYNSORT) {
129408278a5eSRod Evans Sym *lsym = lsdp->sd_sym;
129508278a5eSRod Evans uchar_t ltype = ELF_ST_TYPE(lsym->st_info);
129608278a5eSRod Evans
129708278a5eSRod Evans DYNSORT_COUNT(lsdp, lsym, ltype, --);
129808278a5eSRod Evans lsdp->sd_flags |= FLG_SY_NODYNSORT;
129908278a5eSRod Evans }
130008278a5eSRod Evans
130108278a5eSRod Evans /*
130208278a5eSRod Evans * Track this family member, together with its associated group.
130308278a5eSRod Evans */
130408278a5eSRod Evans if (ld_cap_add_family(ofl, lsdp, sdp,
130508278a5eSRod Evans cdp->ca_groups->apl_data[gndx], NULL) == S_ERROR)
130608278a5eSRod Evans return (S_ERROR);
130708278a5eSRod Evans }
130808278a5eSRod Evans
130908278a5eSRod Evans return (0);
13107c478bd9Sstevel@tonic-gate }
13117c478bd9Sstevel@tonic-gate
13127c478bd9Sstevel@tonic-gate /*
13137c478bd9Sstevel@tonic-gate * Simply process the section so that we have pointers to the data for use
13147c478bd9Sstevel@tonic-gate * in later routines, however don't add the section to the output section
13157c478bd9Sstevel@tonic-gate * list as we will be creating our own replacement sections later (ie.
13167c478bd9Sstevel@tonic-gate * symtab and relocation).
13177c478bd9Sstevel@tonic-gate */
13185aefb655Srie static uintptr_t
13197c478bd9Sstevel@tonic-gate /* ARGSUSED5 */
process_input(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)13207c478bd9Sstevel@tonic-gate process_input(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
13210e233487SRod Evans Word ndx, int ident, Ofl_desc *ofl)
13227c478bd9Sstevel@tonic-gate {
1323ba2be530Sab return (process_section(name, ifl, shdr, scn, ndx,
1324ba2be530Sab ld_targ.t_id.id_null, ofl));
13257c478bd9Sstevel@tonic-gate }
13267c478bd9Sstevel@tonic-gate
13277c478bd9Sstevel@tonic-gate /*
13287c478bd9Sstevel@tonic-gate * Keep a running count of relocation entries from input relocatable objects for
13297c478bd9Sstevel@tonic-gate * sizing relocation buckets later. If we're building an executable, save any
13307c478bd9Sstevel@tonic-gate * relocations from shared objects to determine if any copy relocation symbol
13317c478bd9Sstevel@tonic-gate * has a displacement relocation against it.
13327c478bd9Sstevel@tonic-gate */
13335aefb655Srie static uintptr_t
13347c478bd9Sstevel@tonic-gate /* ARGSUSED5 */
process_reloc(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)13357c478bd9Sstevel@tonic-gate process_reloc(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
13360e233487SRod Evans Word ndx, int ident, Ofl_desc *ofl)
13377c478bd9Sstevel@tonic-gate {
13387c478bd9Sstevel@tonic-gate if (process_section(name, ifl,
1339ba2be530Sab shdr, scn, ndx, ld_targ.t_id.id_null, ofl) == S_ERROR)
13407c478bd9Sstevel@tonic-gate return (S_ERROR);
13417c478bd9Sstevel@tonic-gate
13427c478bd9Sstevel@tonic-gate if (ifl->ifl_ehdr->e_type == ET_REL) {
13437c478bd9Sstevel@tonic-gate if (shdr->sh_entsize && (shdr->sh_entsize <= shdr->sh_size))
13447c478bd9Sstevel@tonic-gate /* LINTED */
13457c478bd9Sstevel@tonic-gate ofl->ofl_relocincnt +=
13467c478bd9Sstevel@tonic-gate (Word)(shdr->sh_size / shdr->sh_entsize);
13477c478bd9Sstevel@tonic-gate } else if (ofl->ofl_flags & FLG_OF_EXEC) {
134857ef7aa9SRod Evans if (aplist_append(&ifl->ifl_relsect, ifl->ifl_isdesc[ndx],
134957ef7aa9SRod Evans AL_CNT_IFL_RELSECS) == NULL)
13507c478bd9Sstevel@tonic-gate return (S_ERROR);
13517c478bd9Sstevel@tonic-gate }
13527c478bd9Sstevel@tonic-gate return (1);
13537c478bd9Sstevel@tonic-gate }
13547c478bd9Sstevel@tonic-gate
13557c478bd9Sstevel@tonic-gate /*
13567c478bd9Sstevel@tonic-gate * Process a string table section. A valid section contains an initial and
13577c478bd9Sstevel@tonic-gate * final null byte.
13587c478bd9Sstevel@tonic-gate */
13595aefb655Srie static uintptr_t
process_strtab(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)13607c478bd9Sstevel@tonic-gate process_strtab(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
13610e233487SRod Evans Word ndx, int ident, Ofl_desc *ofl)
13627c478bd9Sstevel@tonic-gate {
13637c478bd9Sstevel@tonic-gate char *data;
13647c478bd9Sstevel@tonic-gate size_t size;
13657c478bd9Sstevel@tonic-gate Is_desc *isp;
13667c478bd9Sstevel@tonic-gate uintptr_t error;
13677c478bd9Sstevel@tonic-gate
13687c478bd9Sstevel@tonic-gate /*
13697c478bd9Sstevel@tonic-gate * Never include .stab.excl sections in any output file.
13707c478bd9Sstevel@tonic-gate * If the -s flag has been specified strip any .stab sections.
13717c478bd9Sstevel@tonic-gate */
13727c478bd9Sstevel@tonic-gate if (((ofl->ofl_flags & FLG_OF_STRIP) && ident &&
13737c478bd9Sstevel@tonic-gate (strncmp(name, MSG_ORIG(MSG_SCN_STAB), MSG_SCN_STAB_SIZE) == 0)) ||
13747c478bd9Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_STABEXCL)) == 0) && ident)
13757c478bd9Sstevel@tonic-gate return (1);
13767c478bd9Sstevel@tonic-gate
13777c478bd9Sstevel@tonic-gate /*
13787c478bd9Sstevel@tonic-gate * If we got here to process a .shstrtab or .dynstr table, `ident' will
13797c478bd9Sstevel@tonic-gate * be null. Otherwise make sure we don't have a .strtab section as this
13807c478bd9Sstevel@tonic-gate * should not be added to the output section list either.
13817c478bd9Sstevel@tonic-gate */
1382ba2be530Sab if ((ident != ld_targ.t_id.id_null) &&
13837c478bd9Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_STRTAB)) == 0))
1384ba2be530Sab ident = ld_targ.t_id.id_null;
13857c478bd9Sstevel@tonic-gate
13867c478bd9Sstevel@tonic-gate error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
13877c478bd9Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR))
13887c478bd9Sstevel@tonic-gate return (error);
13897c478bd9Sstevel@tonic-gate
13907c478bd9Sstevel@tonic-gate /*
13917c478bd9Sstevel@tonic-gate * String tables should start and end with a NULL byte. Note, it has
13927c478bd9Sstevel@tonic-gate * been known for the assembler to create empty string tables, so check
13937c478bd9Sstevel@tonic-gate * the size before attempting to verify the data itself.
13947c478bd9Sstevel@tonic-gate */
13957c478bd9Sstevel@tonic-gate isp = ifl->ifl_isdesc[ndx];
13967c478bd9Sstevel@tonic-gate size = isp->is_indata->d_size;
13977c478bd9Sstevel@tonic-gate if (size) {
13987c478bd9Sstevel@tonic-gate data = isp->is_indata->d_buf;
13997c478bd9Sstevel@tonic-gate if (data[0] != '\0' || data[size - 1] != '\0')
14001007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
14014a8d0ea7SAli Bahrami MSG_INTL(MSG_FIL_MALSTR), ifl->ifl_name,
14024a8d0ea7SAli Bahrami EC_WORD(isp->is_scnndx), name);
14037c478bd9Sstevel@tonic-gate } else
14047c478bd9Sstevel@tonic-gate isp->is_indata->d_buf = (void *)MSG_ORIG(MSG_STR_EMPTY);
14057c478bd9Sstevel@tonic-gate
14067c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_HSTRTAB;
14077c478bd9Sstevel@tonic-gate return (1);
14087c478bd9Sstevel@tonic-gate }
14097c478bd9Sstevel@tonic-gate
14107c478bd9Sstevel@tonic-gate /*
14117c478bd9Sstevel@tonic-gate * Invalid sections produce a warning and are skipped.
14127c478bd9Sstevel@tonic-gate */
14135aefb655Srie static uintptr_t
14147c478bd9Sstevel@tonic-gate /* ARGSUSED3 */
invalid_section(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)14157c478bd9Sstevel@tonic-gate invalid_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
14167c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
14177c478bd9Sstevel@tonic-gate {
1418de777a60Sab Conv_inv_buf_t inv_buf;
1419de777a60Sab
14201007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_INVALSEC),
14214a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(ndx), name,
14224f680cc6SAli Bahrami conv_sec_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
1423ff4c9ae3SRichard Lowe ifl->ifl_ehdr->e_machine, shdr->sh_type, CONV_FMT_ALT_CF,
1424ff4c9ae3SRichard Lowe &inv_buf));
14257c478bd9Sstevel@tonic-gate return (1);
14267c478bd9Sstevel@tonic-gate }
14277c478bd9Sstevel@tonic-gate
14283f768744SAli Bahrami /*
14293f768744SAli Bahrami * Compare an input section name to a given string, taking the ELF '%'
14303f768744SAli Bahrami * section naming convention into account. If an input section name
14313f768744SAli Bahrami * contains a '%' character, the '%' and all following characters are
14323f768744SAli Bahrami * ignored in the comparison.
14333f768744SAli Bahrami *
14343f768744SAli Bahrami * entry:
14353f768744SAli Bahrami * is_name - Name of input section
14363f768744SAli Bahrami * match_name - Name to compare to
14373f768744SAli Bahrami * match_len - strlen(match_name)
14383f768744SAli Bahrami *
14393f768744SAli Bahrami * exit:
14403f768744SAli Bahrami * Returns True (1) if the names match, and False (0) otherwise.
14413f768744SAli Bahrami */
1442fd5e5f43SAndy Fiddaman static int
is_name_cmp(const char * is_name,const char * match_name,size_t match_len)14433f768744SAli Bahrami is_name_cmp(const char *is_name, const char *match_name, size_t match_len)
14443f768744SAli Bahrami {
14453f768744SAli Bahrami /*
14463f768744SAli Bahrami * If the start of is_name is not a match for name,
14473f768744SAli Bahrami * the match fails.
14483f768744SAli Bahrami */
14493f768744SAli Bahrami if (strncmp(is_name, match_name, match_len) != 0)
14503f768744SAli Bahrami return (0);
14513f768744SAli Bahrami
14523f768744SAli Bahrami /*
14533f768744SAli Bahrami * The prefix matched. The next character must be either '%', or
14543f768744SAli Bahrami * NULL, in order for a match to be true.
14553f768744SAli Bahrami */
14563f768744SAli Bahrami is_name += match_len;
14573f768744SAli Bahrami return ((*is_name == '\0') || (*is_name == '%'));
14583f768744SAli Bahrami }
14593f768744SAli Bahrami
1460d444b03eSAli Bahrami /*
1461d444b03eSAli Bahrami * Helper routine for process_progbits() to process allocable sections.
1462d444b03eSAli Bahrami *
1463d444b03eSAli Bahrami * entry:
1464d444b03eSAli Bahrami * name, ifl, shdr, ndx, ident, ofl - As passed to process_progbits().
1465d444b03eSAli Bahrami * is_stab_index - TRUE if section is .index.
1466d444b03eSAli Bahrami * is_flags - Additional flags to be added to the input section.
1467d444b03eSAli Bahrami *
1468d444b03eSAli Bahrami * exit:
1469d444b03eSAli Bahrami * The allocable section has been processed. *ident and *is_flags
1470d444b03eSAli Bahrami * are updated as necessary to reflect the changes. Returns TRUE
1471d444b03eSAli Bahrami * for success, FALSE for failure.
1472d444b03eSAli Bahrami */
14733fc1e289SBryan Cantrill /*ARGSUSED*/
1474d444b03eSAli Bahrami inline static Boolean
process_progbits_alloc(const char * name,Ifl_desc * ifl,Shdr * shdr,Word ndx,int * ident,Ofl_desc * ofl,Boolean is_stab_index,Word * is_flags)1475d444b03eSAli Bahrami process_progbits_alloc(const char *name, Ifl_desc *ifl, Shdr *shdr,
1476d444b03eSAli Bahrami Word ndx, int *ident, Ofl_desc *ofl, Boolean is_stab_index,
1477d444b03eSAli Bahrami Word *is_flags)
1478d444b03eSAli Bahrami {
1479d444b03eSAli Bahrami Boolean done = FALSE;
1480d444b03eSAli Bahrami
1481d444b03eSAli Bahrami if (name[0] == '.') {
1482d444b03eSAli Bahrami switch (name[1]) {
1483d444b03eSAli Bahrami case 'e':
1484d444b03eSAli Bahrami if (!is_name_cmp(name, MSG_ORIG(MSG_SCN_EHFRAME),
1485d444b03eSAli Bahrami MSG_SCN_EHFRAME_SIZE))
1486d444b03eSAli Bahrami break;
1487d444b03eSAli Bahrami
1488d444b03eSAli Bahrami *ident = ld_targ.t_id.id_unwind;
1489d444b03eSAli Bahrami *is_flags |= FLG_IS_EHFRAME;
1490d444b03eSAli Bahrami done = TRUE;
1491d444b03eSAli Bahrami
1492d444b03eSAli Bahrami /*
14933fc1e289SBryan Cantrill * Historically, the section containing the logic to
14943fc1e289SBryan Cantrill * unwind stack frames -- the .eh_frame section -- was
14953fc1e289SBryan Cantrill * of type SHT_PROGBITS. Apparently the most
14963fc1e289SBryan Cantrill * aesthetically galling aspect of this was not the
14973fc1e289SBryan Cantrill * .eh_frame section's dubious purpose or its filthy
14983fc1e289SBryan Cantrill * implementation, but rather its section type; with the
14993fc1e289SBryan Cantrill * introduction of the AMD64 ABI, a new section header
15003fc1e289SBryan Cantrill * type (SHT_AMD64_UNWIND) was introduced for (and
15013fc1e289SBryan Cantrill * dedicated to) this section. When both the Sun
15023fc1e289SBryan Cantrill * compilers and the GNU compilers had been modified to
15033fc1e289SBryan Cantrill * generate this new section type, the linker became
15043fc1e289SBryan Cantrill * much more pedantic about .eh_frame: it refused to
15053fc1e289SBryan Cantrill * link an AMD64 object that contained a .eh_frame with
15063fc1e289SBryan Cantrill * the legacy SHT_PROGBITS. That this was too fussy is
15073fc1e289SBryan Cantrill * evidenced by searching the net for the error message
15083fc1e289SBryan Cantrill * that it generated ("section type is SHT_PROGBITS:
15093fc1e289SBryan Cantrill * expected SHT_AMD64_UNWIND"), which reveals a myriad
15103fc1e289SBryan Cantrill * of problems, including legacy objects, hand-coded
15113fc1e289SBryan Cantrill * assembly and otherwise cross-platform objects
15123fc1e289SBryan Cantrill * created on other platforms (the GNU toolchain was
15133fc1e289SBryan Cantrill * only modified to create the new section type on
15143fc1e289SBryan Cantrill * Solaris and derivatives). We therefore always accept
15153fc1e289SBryan Cantrill * a .eh_frame of SHT_PROGBITS -- regardless of
15163fc1e289SBryan Cantrill * m_sht_unwind.
1517d444b03eSAli Bahrami */
15183fc1e289SBryan Cantrill break;
1519d444b03eSAli Bahrami case 'g':
1520d444b03eSAli Bahrami if (is_name_cmp(name, MSG_ORIG(MSG_SCN_GOT),
1521d444b03eSAli Bahrami MSG_SCN_GOT_SIZE)) {
1522d444b03eSAli Bahrami *ident = ld_targ.t_id.id_null;
1523d444b03eSAli Bahrami done = TRUE;
1524d444b03eSAli Bahrami break;
1525d444b03eSAli Bahrami }
1526d444b03eSAli Bahrami if ((ld_targ.t_m.m_sht_unwind == SHT_PROGBITS) &&
1527d444b03eSAli Bahrami is_name_cmp(name, MSG_ORIG(MSG_SCN_GCC_X_TBL),
1528d444b03eSAli Bahrami MSG_SCN_GCC_X_TBL_SIZE)) {
1529d444b03eSAli Bahrami *ident = ld_targ.t_id.id_unwind;
1530d444b03eSAli Bahrami done = TRUE;
1531d444b03eSAli Bahrami break;
1532d444b03eSAli Bahrami }
1533d444b03eSAli Bahrami break;
1534d444b03eSAli Bahrami case 'p':
1535d444b03eSAli Bahrami if (is_name_cmp(name, MSG_ORIG(MSG_SCN_PLT),
1536d444b03eSAli Bahrami MSG_SCN_PLT_SIZE)) {
1537d444b03eSAli Bahrami *ident = ld_targ.t_id.id_null;
1538d444b03eSAli Bahrami done = TRUE;
1539d444b03eSAli Bahrami }
1540d444b03eSAli Bahrami break;
1541d444b03eSAli Bahrami }
1542d444b03eSAli Bahrami }
1543d444b03eSAli Bahrami if (!done) {
1544d444b03eSAli Bahrami if (is_stab_index) {
1545d444b03eSAli Bahrami /*
1546d444b03eSAli Bahrami * This is a work-around for x86 compilers that have
1547d444b03eSAli Bahrami * set SHF_ALLOC for the .stab.index section.
1548d444b03eSAli Bahrami *
1549d444b03eSAli Bahrami * Because of this, make sure that the .stab.index
1550d444b03eSAli Bahrami * does not end up as the last section in the text
1551d444b03eSAli Bahrami * segment. Older linkers can produce segmentation
1552d444b03eSAli Bahrami * violations when they strip (ld -s) against a
1553d444b03eSAli Bahrami * shared object whose last section in the text
1554d444b03eSAli Bahrami * segment is a .stab.
1555d444b03eSAli Bahrami */
1556d444b03eSAli Bahrami *ident = ld_targ.t_id.id_interp;
1557d444b03eSAli Bahrami } else {
1558d444b03eSAli Bahrami *ident = ld_targ.t_id.id_data;
1559d444b03eSAli Bahrami }
1560d444b03eSAli Bahrami }
1561d444b03eSAli Bahrami
1562d444b03eSAli Bahrami return (TRUE);
1563d444b03eSAli Bahrami }
1564d444b03eSAli Bahrami
15657c478bd9Sstevel@tonic-gate /*
15667c478bd9Sstevel@tonic-gate * Process a progbits section.
15677c478bd9Sstevel@tonic-gate */
15685aefb655Srie static uintptr_t
process_progbits(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)15697c478bd9Sstevel@tonic-gate process_progbits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
15707c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
15717c478bd9Sstevel@tonic-gate {
1572d444b03eSAli Bahrami Boolean is_stab_index = FALSE;
15737e16fca0SAli Bahrami Word is_flags = 0;
15747e16fca0SAli Bahrami uintptr_t r;
15757c478bd9Sstevel@tonic-gate
15767c478bd9Sstevel@tonic-gate /*
15777c478bd9Sstevel@tonic-gate * Never include .stab.excl sections in any output file.
15787c478bd9Sstevel@tonic-gate * If the -s flag has been specified strip any .stab sections.
15797c478bd9Sstevel@tonic-gate */
15807c478bd9Sstevel@tonic-gate if (ident && (strncmp(name, MSG_ORIG(MSG_SCN_STAB),
15817c478bd9Sstevel@tonic-gate MSG_SCN_STAB_SIZE) == 0)) {
15827c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STRIP) ||
15837c478bd9Sstevel@tonic-gate (strcmp((name + MSG_SCN_STAB_SIZE),
1584d840867fSab MSG_ORIG(MSG_SCN_EXCL)) == 0))
15857c478bd9Sstevel@tonic-gate return (1);
15867c478bd9Sstevel@tonic-gate
15877c478bd9Sstevel@tonic-gate if (strcmp((name + MSG_SCN_STAB_SIZE),
15887c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_SCN_INDEX)) == 0)
1589d444b03eSAli Bahrami is_stab_index = TRUE;
15907c478bd9Sstevel@tonic-gate }
15917c478bd9Sstevel@tonic-gate
15927c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STRIP) && ident) {
15937c478bd9Sstevel@tonic-gate if ((strncmp(name, MSG_ORIG(MSG_SCN_DEBUG),
15947c478bd9Sstevel@tonic-gate MSG_SCN_DEBUG_SIZE) == 0) ||
15957c478bd9Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_LINE)) == 0))
15967c478bd9Sstevel@tonic-gate return (1);
15977c478bd9Sstevel@tonic-gate }
15987c478bd9Sstevel@tonic-gate
15997c478bd9Sstevel@tonic-gate /*
16007c478bd9Sstevel@tonic-gate * Update the ident to reflect the type of section we've got.
16017c478bd9Sstevel@tonic-gate *
16027c478bd9Sstevel@tonic-gate * If there is any .plt or .got section to generate we'll be creating
16037c478bd9Sstevel@tonic-gate * our own version, so don't allow any input sections of these types to
16047c478bd9Sstevel@tonic-gate * be added to the output section list (why a relocatable object would
16057c478bd9Sstevel@tonic-gate * have a .plt or .got is a mystery, but stranger things have occurred).
16067e16fca0SAli Bahrami *
16077e16fca0SAli Bahrami * If there are any unwind sections, and this is a platform that uses
16087e16fca0SAli Bahrami * SHT_PROGBITS for unwind sections, then set their ident to reflect
16097e16fca0SAli Bahrami * that.
16107c478bd9Sstevel@tonic-gate */
16117c478bd9Sstevel@tonic-gate if (ident) {
16127e16fca0SAli Bahrami if (shdr->sh_flags & SHF_TLS) {
1613ba2be530Sab ident = ld_targ.t_id.id_tls;
16147e16fca0SAli Bahrami } else if ((shdr->sh_flags & ~ALL_SHF_IGNORE) ==
16157e16fca0SAli Bahrami (SHF_ALLOC | SHF_EXECINSTR)) {
1616ba2be530Sab ident = ld_targ.t_id.id_text;
16177e16fca0SAli Bahrami } else if (shdr->sh_flags & SHF_ALLOC) {
1618d444b03eSAli Bahrami if (process_progbits_alloc(name, ifl, shdr, ndx,
1619d444b03eSAli Bahrami &ident, ofl, is_stab_index, &is_flags) == FALSE)
1620d444b03eSAli Bahrami return (S_ERROR);
1621d444b03eSAli Bahrami } else {
1622ba2be530Sab ident = ld_targ.t_id.id_note;
1623d444b03eSAli Bahrami }
16247c478bd9Sstevel@tonic-gate }
16257e16fca0SAli Bahrami
16267e16fca0SAli Bahrami r = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
16277e16fca0SAli Bahrami
16287e16fca0SAli Bahrami /*
16297e16fca0SAli Bahrami * On success, process_section() creates an input section descriptor.
16307e16fca0SAli Bahrami * Now that it exists, we can add any pending input section flags.
16317e16fca0SAli Bahrami */
16327e16fca0SAli Bahrami if ((is_flags != 0) && (r == 1))
16337e16fca0SAli Bahrami ifl->ifl_isdesc[ndx]->is_flags |= is_flags;
16347e16fca0SAli Bahrami
16357e16fca0SAli Bahrami return (r);
16367c478bd9Sstevel@tonic-gate }
16377c478bd9Sstevel@tonic-gate
16387c478bd9Sstevel@tonic-gate /*
16397c478bd9Sstevel@tonic-gate * Handles the SHT_SUNW_{DEBUG,DEBUGSTR) sections.
16407c478bd9Sstevel@tonic-gate */
16415aefb655Srie static uintptr_t
process_debug(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)16427c478bd9Sstevel@tonic-gate process_debug(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
16437c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
16447c478bd9Sstevel@tonic-gate {
16457c478bd9Sstevel@tonic-gate /*
16467c478bd9Sstevel@tonic-gate * Debug information is discarded when the 'ld -s' flag is invoked.
16477c478bd9Sstevel@tonic-gate */
16487c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_STRIP) {
16497c478bd9Sstevel@tonic-gate return (1);
16507c478bd9Sstevel@tonic-gate }
16517c478bd9Sstevel@tonic-gate return (process_progbits(name, ifl, shdr, scn, ndx, ident, ofl));
16527c478bd9Sstevel@tonic-gate }
16537c478bd9Sstevel@tonic-gate
16547c478bd9Sstevel@tonic-gate /*
16557c478bd9Sstevel@tonic-gate * Process a nobits section.
16567c478bd9Sstevel@tonic-gate */
16575aefb655Srie static uintptr_t
process_nobits(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)16587c478bd9Sstevel@tonic-gate process_nobits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
16597c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
16607c478bd9Sstevel@tonic-gate {
16617c478bd9Sstevel@tonic-gate if (ident) {
16627c478bd9Sstevel@tonic-gate if (shdr->sh_flags & SHF_TLS)
1663ba2be530Sab ident = ld_targ.t_id.id_tlsbss;
1664ba2be530Sab #if defined(_ELF64)
1665ba2be530Sab else if ((shdr->sh_flags & SHF_AMD64_LARGE) &&
1666ba2be530Sab (ld_targ.t_m.m_mach == EM_AMD64))
1667ba2be530Sab ident = ld_targ.t_id.id_lbss;
166854d82594Sseizo #endif
16697c478bd9Sstevel@tonic-gate else
1670ba2be530Sab ident = ld_targ.t_id.id_bss;
16717c478bd9Sstevel@tonic-gate }
16727c478bd9Sstevel@tonic-gate return (process_section(name, ifl, shdr, scn, ndx, ident, ofl));
16737c478bd9Sstevel@tonic-gate }
16747c478bd9Sstevel@tonic-gate
16757c478bd9Sstevel@tonic-gate /*
16767c478bd9Sstevel@tonic-gate * Process a SHT_*_ARRAY section.
16777c478bd9Sstevel@tonic-gate */
16785aefb655Srie static uintptr_t
process_array(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)16797c478bd9Sstevel@tonic-gate process_array(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
16807c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
16817c478bd9Sstevel@tonic-gate {
16820e233487SRod Evans uintptr_t error;
16837c478bd9Sstevel@tonic-gate
16847c478bd9Sstevel@tonic-gate if (ident)
1685ba2be530Sab ident = ld_targ.t_id.id_array;
16867c478bd9Sstevel@tonic-gate
16870e233487SRod Evans error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
16880e233487SRod Evans if ((error == 0) || (error == S_ERROR))
16890e233487SRod Evans return (error);
16900e233487SRod Evans
16910e233487SRod Evans return (1);
16920e233487SRod Evans }
16930e233487SRod Evans
16940e233487SRod Evans static uintptr_t
16950e233487SRod Evans /* ARGSUSED1 */
array_process(Is_desc * isc,Ifl_desc * ifl,Ofl_desc * ofl)16960e233487SRod Evans array_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
16970e233487SRod Evans {
16980e233487SRod Evans Os_desc *osp;
16990e233487SRod Evans Shdr *shdr;
17007c478bd9Sstevel@tonic-gate
17010e233487SRod Evans if ((isc == NULL) || ((osp = isc->is_osdesc) == NULL))
17027c478bd9Sstevel@tonic-gate return (0);
17037c478bd9Sstevel@tonic-gate
17040e233487SRod Evans shdr = isc->is_shdr;
17050e233487SRod Evans
17067c478bd9Sstevel@tonic-gate if ((shdr->sh_type == SHT_FINI_ARRAY) &&
17070e233487SRod Evans (ofl->ofl_osfiniarray == NULL))
17087c478bd9Sstevel@tonic-gate ofl->ofl_osfiniarray = osp;
17097c478bd9Sstevel@tonic-gate else if ((shdr->sh_type == SHT_INIT_ARRAY) &&
17100e233487SRod Evans (ofl->ofl_osinitarray == NULL))
17117c478bd9Sstevel@tonic-gate ofl->ofl_osinitarray = osp;
17127c478bd9Sstevel@tonic-gate else if ((shdr->sh_type == SHT_PREINIT_ARRAY) &&
17130e233487SRod Evans (ofl->ofl_ospreinitarray == NULL))
17147c478bd9Sstevel@tonic-gate ofl->ofl_ospreinitarray = osp;
17157c478bd9Sstevel@tonic-gate
17167c478bd9Sstevel@tonic-gate return (1);
17177c478bd9Sstevel@tonic-gate }
17187c478bd9Sstevel@tonic-gate
17197c478bd9Sstevel@tonic-gate /*
17207c478bd9Sstevel@tonic-gate * Process a SHT_SYMTAB_SHNDX section.
17217c478bd9Sstevel@tonic-gate */
17225aefb655Srie static uintptr_t
process_sym_shndx(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)17237c478bd9Sstevel@tonic-gate process_sym_shndx(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
17247c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
17257c478bd9Sstevel@tonic-gate {
17267c478bd9Sstevel@tonic-gate if (process_input(name, ifl, shdr, scn, ndx, ident, ofl) == S_ERROR)
17277c478bd9Sstevel@tonic-gate return (S_ERROR);
17287c478bd9Sstevel@tonic-gate
17297c478bd9Sstevel@tonic-gate /*
17307c478bd9Sstevel@tonic-gate * Have we already seen the related SYMTAB - if so verify it now.
17317c478bd9Sstevel@tonic-gate */
17327c478bd9Sstevel@tonic-gate if (shdr->sh_link < ndx) {
17337c478bd9Sstevel@tonic-gate Is_desc *isp = ifl->ifl_isdesc[shdr->sh_link];
17347c478bd9Sstevel@tonic-gate
1735635216b6SRod Evans if ((isp == NULL) || ((isp->is_shdr->sh_type != SHT_SYMTAB) &&
17367c478bd9Sstevel@tonic-gate (isp->is_shdr->sh_type != SHT_DYNSYM))) {
17371007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
17384a8d0ea7SAli Bahrami MSG_INTL(MSG_FIL_INVSHLINK), ifl->ifl_name,
17394a8d0ea7SAli Bahrami EC_WORD(ndx), name, EC_XWORD(shdr->sh_link));
17407c478bd9Sstevel@tonic-gate return (S_ERROR);
17417c478bd9Sstevel@tonic-gate }
17427c478bd9Sstevel@tonic-gate isp->is_symshndx = ifl->ifl_isdesc[ndx];
17437c478bd9Sstevel@tonic-gate }
17447c478bd9Sstevel@tonic-gate return (1);
17457c478bd9Sstevel@tonic-gate }
17467c478bd9Sstevel@tonic-gate
17477c478bd9Sstevel@tonic-gate /*
17487c478bd9Sstevel@tonic-gate * Final processing for SHT_SYMTAB_SHNDX section.
17497c478bd9Sstevel@tonic-gate */
17505aefb655Srie static uintptr_t
17517c478bd9Sstevel@tonic-gate /* ARGSUSED2 */
sym_shndx_process(Is_desc * isc,Ifl_desc * ifl,Ofl_desc * ofl)17527c478bd9Sstevel@tonic-gate sym_shndx_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
17537c478bd9Sstevel@tonic-gate {
17547c478bd9Sstevel@tonic-gate if (isc->is_shdr->sh_link > isc->is_scnndx) {
17557c478bd9Sstevel@tonic-gate Is_desc *isp = ifl->ifl_isdesc[isc->is_shdr->sh_link];
17567c478bd9Sstevel@tonic-gate
1757635216b6SRod Evans if ((isp == NULL) || ((isp->is_shdr->sh_type != SHT_SYMTAB) &&
17587c478bd9Sstevel@tonic-gate (isp->is_shdr->sh_type != SHT_DYNSYM))) {
17591007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
17605aefb655Srie MSG_INTL(MSG_FIL_INVSHLINK), isc->is_file->ifl_name,
17614a8d0ea7SAli Bahrami EC_WORD(isc->is_scnndx), isc->is_name,
17624a8d0ea7SAli Bahrami EC_XWORD(isc->is_shdr->sh_link));
17637c478bd9Sstevel@tonic-gate return (S_ERROR);
17647c478bd9Sstevel@tonic-gate }
17657c478bd9Sstevel@tonic-gate isp->is_symshndx = isc;
17667c478bd9Sstevel@tonic-gate }
17677c478bd9Sstevel@tonic-gate return (1);
17687c478bd9Sstevel@tonic-gate }
17697c478bd9Sstevel@tonic-gate
17707c478bd9Sstevel@tonic-gate /*
17717c478bd9Sstevel@tonic-gate * Process .dynamic section from a relocatable object.
17727c478bd9Sstevel@tonic-gate *
17737c478bd9Sstevel@tonic-gate * Note: That the .dynamic section is only considered interesting when
17747c478bd9Sstevel@tonic-gate * dlopen()ing a relocatable object (thus FLG_OF1_RELDYN can only get
17757c478bd9Sstevel@tonic-gate * set when libld is called from ld.so.1).
17767c478bd9Sstevel@tonic-gate */
17777c478bd9Sstevel@tonic-gate /*ARGSUSED*/
17785aefb655Srie static uintptr_t
process_rel_dynamic(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)17797c478bd9Sstevel@tonic-gate process_rel_dynamic(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
17807c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
17817c478bd9Sstevel@tonic-gate {
17827c478bd9Sstevel@tonic-gate Dyn *dyn;
17837c478bd9Sstevel@tonic-gate Elf_Scn *strscn;
17847c478bd9Sstevel@tonic-gate Elf_Data *dp;
17857c478bd9Sstevel@tonic-gate char *str;
17867c478bd9Sstevel@tonic-gate
17877c478bd9Sstevel@tonic-gate /*
17887c478bd9Sstevel@tonic-gate * Process .dynamic sections from relocatable objects ?
17897c478bd9Sstevel@tonic-gate */
17907c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags1 & FLG_OF1_RELDYN) == 0)
17917c478bd9Sstevel@tonic-gate return (1);
17927c478bd9Sstevel@tonic-gate
17937c478bd9Sstevel@tonic-gate /*
17947c478bd9Sstevel@tonic-gate * Find the string section associated with the .dynamic section.
17957c478bd9Sstevel@tonic-gate */
17967c478bd9Sstevel@tonic-gate if ((strscn = elf_getscn(ifl->ifl_elf, shdr->sh_link)) == NULL) {
17971007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN),
17985aefb655Srie ifl->ifl_name);
17997c478bd9Sstevel@tonic-gate return (0);
18007c478bd9Sstevel@tonic-gate }
18017c478bd9Sstevel@tonic-gate dp = elf_getdata(strscn, NULL);
18027c478bd9Sstevel@tonic-gate str = (char *)dp->d_buf;
18037c478bd9Sstevel@tonic-gate
18047c478bd9Sstevel@tonic-gate /*
18057c478bd9Sstevel@tonic-gate * And get the .dynamic data
18067c478bd9Sstevel@tonic-gate */
18077c478bd9Sstevel@tonic-gate dp = elf_getdata(scn, NULL);
18087c478bd9Sstevel@tonic-gate
18097c478bd9Sstevel@tonic-gate for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) {
1810fb1354edSrie Ifl_desc *difl;
18117c478bd9Sstevel@tonic-gate
18127c478bd9Sstevel@tonic-gate switch (dyn->d_tag) {
18137c478bd9Sstevel@tonic-gate case DT_NEEDED:
18147c478bd9Sstevel@tonic-gate case DT_USED:
181557ef7aa9SRod Evans if (((difl = libld_calloc(1,
181657ef7aa9SRod Evans sizeof (Ifl_desc))) == NULL) ||
181757ef7aa9SRod Evans (aplist_append(&ofl->ofl_sos, difl,
181857ef7aa9SRod Evans AL_CNT_OFL_LIBS) == NULL))
18197c478bd9Sstevel@tonic-gate return (S_ERROR);
1820fb1354edSrie
1821fb1354edSrie difl->ifl_name = MSG_ORIG(MSG_STR_DYNAMIC);
1822fb1354edSrie difl->ifl_soname = str + (size_t)dyn->d_un.d_val;
1823fb1354edSrie difl->ifl_flags = FLG_IF_NEEDSTR;
18247c478bd9Sstevel@tonic-gate break;
18257c478bd9Sstevel@tonic-gate case DT_RPATH:
18267c478bd9Sstevel@tonic-gate case DT_RUNPATH:
18277c478bd9Sstevel@tonic-gate if ((ofl->ofl_rpath = add_string(ofl->ofl_rpath,
18287c478bd9Sstevel@tonic-gate (str + (size_t)dyn->d_un.d_val))) ==
18297c478bd9Sstevel@tonic-gate (const char *)S_ERROR)
18307c478bd9Sstevel@tonic-gate return (S_ERROR);
18317c478bd9Sstevel@tonic-gate break;
1832d840867fSab case DT_VERSYM:
1833d840867fSab /*
1834d840867fSab * The Solaris ld does not put DT_VERSYM in the
1835d840867fSab * dynamic section. If the object has DT_VERSYM,
1836d840867fSab * then it must have been produced by the GNU ld,
1837d840867fSab * and is using the GNU style of versioning.
1838d840867fSab */
1839d840867fSab ifl->ifl_flags |= FLG_IF_GNUVER;
1840d840867fSab break;
18417c478bd9Sstevel@tonic-gate }
18427c478bd9Sstevel@tonic-gate }
18437c478bd9Sstevel@tonic-gate return (1);
18447c478bd9Sstevel@tonic-gate }
18457c478bd9Sstevel@tonic-gate
18467c478bd9Sstevel@tonic-gate /*
18477c478bd9Sstevel@tonic-gate * Expand implicit references. Dependencies can be specified in terms of the
184808278a5eSRod Evans * $ORIGIN, $MACHINE, $PLATFORM, $OSREL and $OSNAME tokens, either from their
184908278a5eSRod Evans * needed name, or via a runpath. In addition runpaths may also specify the
185008278a5eSRod Evans * $ISALIST token.
18517c478bd9Sstevel@tonic-gate *
1852fb1354edSrie * Probably the most common reference to explicit dependencies (via -L) will be
18537c478bd9Sstevel@tonic-gate * sufficient to find any associated implicit dependencies, but just in case we
18547c478bd9Sstevel@tonic-gate * expand any occurrence of these known tokens here.
18557c478bd9Sstevel@tonic-gate *
18567c478bd9Sstevel@tonic-gate * Note, if any errors occur we simply return the original name.
18577c478bd9Sstevel@tonic-gate *
18587c478bd9Sstevel@tonic-gate * This code is remarkably similar to expand() in rtld/common/paths.c.
18597c478bd9Sstevel@tonic-gate */
186008278a5eSRod Evans static char *machine = NULL;
186108278a5eSRod Evans static size_t machine_sz = 0;
1862635216b6SRod Evans static char *platform = NULL;
18637c478bd9Sstevel@tonic-gate static size_t platform_sz = 0;
1864635216b6SRod Evans static Isa_desc *isa = NULL;
1865635216b6SRod Evans static Uts_desc *uts = NULL;
18667c478bd9Sstevel@tonic-gate
18677c478bd9Sstevel@tonic-gate static char *
expand(const char * parent,const char * name,char ** next)18687c478bd9Sstevel@tonic-gate expand(const char *parent, const char *name, char **next)
18697c478bd9Sstevel@tonic-gate {
18707c478bd9Sstevel@tonic-gate char _name[PATH_MAX], *nptr, *_next;
18717c478bd9Sstevel@tonic-gate const char *optr;
18727c478bd9Sstevel@tonic-gate size_t nrem = PATH_MAX - 1;
18737c478bd9Sstevel@tonic-gate int expanded = 0, _expanded, isaflag = 0;
18747c478bd9Sstevel@tonic-gate
18757c478bd9Sstevel@tonic-gate optr = name;
18767c478bd9Sstevel@tonic-gate nptr = _name;
18777c478bd9Sstevel@tonic-gate
18787c478bd9Sstevel@tonic-gate while (*optr) {
18797c478bd9Sstevel@tonic-gate if (nrem == 0)
18807c478bd9Sstevel@tonic-gate return ((char *)name);
18817c478bd9Sstevel@tonic-gate
18827c478bd9Sstevel@tonic-gate if (*optr != '$') {
18837c478bd9Sstevel@tonic-gate *nptr++ = *optr++, nrem--;
18847c478bd9Sstevel@tonic-gate continue;
18857c478bd9Sstevel@tonic-gate }
18867c478bd9Sstevel@tonic-gate
18877c478bd9Sstevel@tonic-gate _expanded = 0;
18887c478bd9Sstevel@tonic-gate
18897c478bd9Sstevel@tonic-gate if (strncmp(optr, MSG_ORIG(MSG_STR_ORIGIN),
18907c478bd9Sstevel@tonic-gate MSG_STR_ORIGIN_SIZE) == 0) {
18917c478bd9Sstevel@tonic-gate char *eptr;
18927c478bd9Sstevel@tonic-gate
18937c478bd9Sstevel@tonic-gate /*
18947c478bd9Sstevel@tonic-gate * For $ORIGIN, expansion is really just a concatenation
18957c478bd9Sstevel@tonic-gate * of the parents directory name. For example, an
1896fb1354edSrie * explicit dependency foo/bar/lib1.so with a dependency
18977c478bd9Sstevel@tonic-gate * on $ORIGIN/lib2.so would be expanded to
18987c478bd9Sstevel@tonic-gate * foo/bar/lib2.so.
18997c478bd9Sstevel@tonic-gate */
1900635216b6SRod Evans if ((eptr = strrchr(parent, '/')) == NULL) {
19017c478bd9Sstevel@tonic-gate *nptr++ = '.';
19027c478bd9Sstevel@tonic-gate nrem--;
19037c478bd9Sstevel@tonic-gate } else {
19047c478bd9Sstevel@tonic-gate size_t len = eptr - parent;
19057c478bd9Sstevel@tonic-gate
19067c478bd9Sstevel@tonic-gate if (len >= nrem)
19077c478bd9Sstevel@tonic-gate return ((char *)name);
19087c478bd9Sstevel@tonic-gate
19097c478bd9Sstevel@tonic-gate (void) strncpy(nptr, parent, len);
19107c478bd9Sstevel@tonic-gate nptr = nptr + len;
19117c478bd9Sstevel@tonic-gate nrem -= len;
19127c478bd9Sstevel@tonic-gate }
19137c478bd9Sstevel@tonic-gate optr += MSG_STR_ORIGIN_SIZE;
19147c478bd9Sstevel@tonic-gate expanded = _expanded = 1;
19157c478bd9Sstevel@tonic-gate
191608278a5eSRod Evans } else if (strncmp(optr, MSG_ORIG(MSG_STR_MACHINE),
191708278a5eSRod Evans MSG_STR_MACHINE_SIZE) == 0) {
191808278a5eSRod Evans /*
191908278a5eSRod Evans * Establish the machine from sysconf - like uname -i.
192008278a5eSRod Evans */
192108278a5eSRod Evans if ((machine == NULL) && (machine_sz == 0)) {
192208278a5eSRod Evans char info[SYS_NMLN];
192308278a5eSRod Evans long size;
192408278a5eSRod Evans
192508278a5eSRod Evans size = sysinfo(SI_MACHINE, info, SYS_NMLN);
192608278a5eSRod Evans if ((size != -1) &&
192708278a5eSRod Evans (machine = libld_malloc((size_t)size))) {
192808278a5eSRod Evans (void) strcpy(machine, info);
192908278a5eSRod Evans machine_sz = (size_t)size - 1;
193008278a5eSRod Evans } else
193108278a5eSRod Evans machine_sz = 1;
193208278a5eSRod Evans }
193308278a5eSRod Evans if (machine) {
193408278a5eSRod Evans if (machine_sz >= nrem)
193508278a5eSRod Evans return ((char *)name);
193608278a5eSRod Evans
193708278a5eSRod Evans (void) strncpy(nptr, machine, machine_sz);
193808278a5eSRod Evans nptr = nptr + machine_sz;
193908278a5eSRod Evans nrem -= machine_sz;
194008278a5eSRod Evans
194108278a5eSRod Evans optr += MSG_STR_MACHINE_SIZE;
194208278a5eSRod Evans expanded = _expanded = 1;
194308278a5eSRod Evans }
194408278a5eSRod Evans
19457c478bd9Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_PLATFORM),
19467c478bd9Sstevel@tonic-gate MSG_STR_PLATFORM_SIZE) == 0) {
19477c478bd9Sstevel@tonic-gate /*
19487c478bd9Sstevel@tonic-gate * Establish the platform from sysconf - like uname -i.
19497c478bd9Sstevel@tonic-gate */
1950635216b6SRod Evans if ((platform == NULL) && (platform_sz == 0)) {
19517c478bd9Sstevel@tonic-gate char info[SYS_NMLN];
19527c478bd9Sstevel@tonic-gate long size;
19537c478bd9Sstevel@tonic-gate
19547c478bd9Sstevel@tonic-gate size = sysinfo(SI_PLATFORM, info, SYS_NMLN);
19557c478bd9Sstevel@tonic-gate if ((size != -1) &&
19567c478bd9Sstevel@tonic-gate (platform = libld_malloc((size_t)size))) {
19577c478bd9Sstevel@tonic-gate (void) strcpy(platform, info);
19587c478bd9Sstevel@tonic-gate platform_sz = (size_t)size - 1;
19597c478bd9Sstevel@tonic-gate } else
19607c478bd9Sstevel@tonic-gate platform_sz = 1;
19617c478bd9Sstevel@tonic-gate }
1962635216b6SRod Evans if (platform) {
19637c478bd9Sstevel@tonic-gate if (platform_sz >= nrem)
19647c478bd9Sstevel@tonic-gate return ((char *)name);
19657c478bd9Sstevel@tonic-gate
19667c478bd9Sstevel@tonic-gate (void) strncpy(nptr, platform, platform_sz);
19677c478bd9Sstevel@tonic-gate nptr = nptr + platform_sz;
19687c478bd9Sstevel@tonic-gate nrem -= platform_sz;
19697c478bd9Sstevel@tonic-gate
19707c478bd9Sstevel@tonic-gate optr += MSG_STR_PLATFORM_SIZE;
19717c478bd9Sstevel@tonic-gate expanded = _expanded = 1;
19727c478bd9Sstevel@tonic-gate }
19737c478bd9Sstevel@tonic-gate
19747c478bd9Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_OSNAME),
19757c478bd9Sstevel@tonic-gate MSG_STR_OSNAME_SIZE) == 0) {
19767c478bd9Sstevel@tonic-gate /*
19777c478bd9Sstevel@tonic-gate * Establish the os name - like uname -s.
19787c478bd9Sstevel@tonic-gate */
1979635216b6SRod Evans if (uts == NULL)
19807c478bd9Sstevel@tonic-gate uts = conv_uts();
19817c478bd9Sstevel@tonic-gate
19827c478bd9Sstevel@tonic-gate if (uts && uts->uts_osnamesz) {
19837c478bd9Sstevel@tonic-gate if (uts->uts_osnamesz >= nrem)
19847c478bd9Sstevel@tonic-gate return ((char *)name);
19857c478bd9Sstevel@tonic-gate
19867c478bd9Sstevel@tonic-gate (void) strncpy(nptr, uts->uts_osname,
19877c478bd9Sstevel@tonic-gate uts->uts_osnamesz);
19887c478bd9Sstevel@tonic-gate nptr = nptr + uts->uts_osnamesz;
19897c478bd9Sstevel@tonic-gate nrem -= uts->uts_osnamesz;
19907c478bd9Sstevel@tonic-gate
19917c478bd9Sstevel@tonic-gate optr += MSG_STR_OSNAME_SIZE;
19927c478bd9Sstevel@tonic-gate expanded = _expanded = 1;
19937c478bd9Sstevel@tonic-gate }
19947c478bd9Sstevel@tonic-gate
19957c478bd9Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_OSREL),
19967c478bd9Sstevel@tonic-gate MSG_STR_OSREL_SIZE) == 0) {
19977c478bd9Sstevel@tonic-gate /*
19987c478bd9Sstevel@tonic-gate * Establish the os release - like uname -r.
19997c478bd9Sstevel@tonic-gate */
2000635216b6SRod Evans if (uts == NULL)
20017c478bd9Sstevel@tonic-gate uts = conv_uts();
20027c478bd9Sstevel@tonic-gate
20037c478bd9Sstevel@tonic-gate if (uts && uts->uts_osrelsz) {
20047c478bd9Sstevel@tonic-gate if (uts->uts_osrelsz >= nrem)
20057c478bd9Sstevel@tonic-gate return ((char *)name);
20067c478bd9Sstevel@tonic-gate
20077c478bd9Sstevel@tonic-gate (void) strncpy(nptr, uts->uts_osrel,
20087c478bd9Sstevel@tonic-gate uts->uts_osrelsz);
20097c478bd9Sstevel@tonic-gate nptr = nptr + uts->uts_osrelsz;
20107c478bd9Sstevel@tonic-gate nrem -= uts->uts_osrelsz;
20117c478bd9Sstevel@tonic-gate
20127c478bd9Sstevel@tonic-gate optr += MSG_STR_OSREL_SIZE;
20137c478bd9Sstevel@tonic-gate expanded = _expanded = 1;
20147c478bd9Sstevel@tonic-gate }
20157c478bd9Sstevel@tonic-gate
20167c478bd9Sstevel@tonic-gate } else if ((strncmp(optr, MSG_ORIG(MSG_STR_ISALIST),
20177c478bd9Sstevel@tonic-gate MSG_STR_ISALIST_SIZE) == 0) && next && (isaflag++ == 0)) {
20187c478bd9Sstevel@tonic-gate /*
20197c478bd9Sstevel@tonic-gate * Establish instruction sets from sysconf. Note that
20207c478bd9Sstevel@tonic-gate * this is only meaningful from runpaths.
20217c478bd9Sstevel@tonic-gate */
2022635216b6SRod Evans if (isa == NULL)
20237c478bd9Sstevel@tonic-gate isa = conv_isalist();
20247c478bd9Sstevel@tonic-gate
20257c478bd9Sstevel@tonic-gate if (isa && isa->isa_listsz &&
20267c478bd9Sstevel@tonic-gate (nrem > isa->isa_opt->isa_namesz)) {
20277c478bd9Sstevel@tonic-gate size_t mlen, tlen, hlen = optr - name;
20287c478bd9Sstevel@tonic-gate size_t no;
20297c478bd9Sstevel@tonic-gate char *lptr;
20307c478bd9Sstevel@tonic-gate Isa_opt *opt = isa->isa_opt;
20317c478bd9Sstevel@tonic-gate
20327c478bd9Sstevel@tonic-gate (void) strncpy(nptr, opt->isa_name,
20337c478bd9Sstevel@tonic-gate opt->isa_namesz);
20347c478bd9Sstevel@tonic-gate nptr = nptr + opt->isa_namesz;
20357c478bd9Sstevel@tonic-gate nrem -= opt->isa_namesz;
20367c478bd9Sstevel@tonic-gate
20377c478bd9Sstevel@tonic-gate optr += MSG_STR_ISALIST_SIZE;
20387c478bd9Sstevel@tonic-gate expanded = _expanded = 1;
20397c478bd9Sstevel@tonic-gate
20407c478bd9Sstevel@tonic-gate tlen = strlen(optr);
20417c478bd9Sstevel@tonic-gate
20427c478bd9Sstevel@tonic-gate /*
20437c478bd9Sstevel@tonic-gate * As ISALIST expands to a number of elements,
20447c478bd9Sstevel@tonic-gate * establish a new list to return to the caller.
20457c478bd9Sstevel@tonic-gate * This will contain the present path being
20467c478bd9Sstevel@tonic-gate * processed redefined for each isalist option,
20477c478bd9Sstevel@tonic-gate * plus the original remaining list entries.
20487c478bd9Sstevel@tonic-gate */
20497c478bd9Sstevel@tonic-gate mlen = ((hlen + tlen) * (isa->isa_optno - 1)) +
20507c478bd9Sstevel@tonic-gate isa->isa_listsz - opt->isa_namesz;
20517c478bd9Sstevel@tonic-gate if (*next)
2052d840867fSab mlen += strlen(*next);
2053635216b6SRod Evans if ((_next = lptr = libld_malloc(mlen)) == NULL)
20547c478bd9Sstevel@tonic-gate return (0);
20557c478bd9Sstevel@tonic-gate
20567c478bd9Sstevel@tonic-gate for (no = 1, opt++; no < isa->isa_optno;
20577c478bd9Sstevel@tonic-gate no++, opt++) {
20587c478bd9Sstevel@tonic-gate (void) strncpy(lptr, name, hlen);
20597c478bd9Sstevel@tonic-gate lptr = lptr + hlen;
20607c478bd9Sstevel@tonic-gate (void) strncpy(lptr, opt->isa_name,
20617c478bd9Sstevel@tonic-gate opt->isa_namesz);
20627c478bd9Sstevel@tonic-gate lptr = lptr + opt->isa_namesz;
20637c478bd9Sstevel@tonic-gate (void) strncpy(lptr, optr, tlen);
20647c478bd9Sstevel@tonic-gate lptr = lptr + tlen;
20657c478bd9Sstevel@tonic-gate *lptr++ = ':';
20667c478bd9Sstevel@tonic-gate }
20677c478bd9Sstevel@tonic-gate if (*next)
20687c478bd9Sstevel@tonic-gate (void) strcpy(lptr, *next);
20697c478bd9Sstevel@tonic-gate else
20707c478bd9Sstevel@tonic-gate *--lptr = '\0';
20717c478bd9Sstevel@tonic-gate }
20727c478bd9Sstevel@tonic-gate }
20737c478bd9Sstevel@tonic-gate
20747c478bd9Sstevel@tonic-gate /*
20757c478bd9Sstevel@tonic-gate * If no expansion occurred skip the $ and continue.
20767c478bd9Sstevel@tonic-gate */
20777c478bd9Sstevel@tonic-gate if (_expanded == 0)
20787c478bd9Sstevel@tonic-gate *nptr++ = *optr++, nrem--;
20797c478bd9Sstevel@tonic-gate }
20807c478bd9Sstevel@tonic-gate
20817c478bd9Sstevel@tonic-gate /*
20827c478bd9Sstevel@tonic-gate * If any ISALIST processing has occurred not only do we return the
20837c478bd9Sstevel@tonic-gate * expanded node we're presently working on, but we must also update the
20847c478bd9Sstevel@tonic-gate * remaining list so that it is effectively prepended with this node
20857c478bd9Sstevel@tonic-gate * expanded to all remaining isalist options. Note that we can only
20867c478bd9Sstevel@tonic-gate * handle one ISALIST per node. For more than one ISALIST to be
20877c478bd9Sstevel@tonic-gate * processed we'd need a better algorithm than above to replace the
20887c478bd9Sstevel@tonic-gate * newly generated list. Whether we want to encourage the number of
20897c478bd9Sstevel@tonic-gate * pathname permutations this would provide is another question. So, for
20907c478bd9Sstevel@tonic-gate * now if more than one ISALIST is encountered we return the original
20917c478bd9Sstevel@tonic-gate * node untouched.
20927c478bd9Sstevel@tonic-gate */
20937c478bd9Sstevel@tonic-gate if (isaflag) {
20947c478bd9Sstevel@tonic-gate if (isaflag == 1)
20957c478bd9Sstevel@tonic-gate *next = _next;
20967c478bd9Sstevel@tonic-gate else
20977c478bd9Sstevel@tonic-gate return ((char *)name);
20987c478bd9Sstevel@tonic-gate }
20997c478bd9Sstevel@tonic-gate
21007c478bd9Sstevel@tonic-gate *nptr = '\0';
21017c478bd9Sstevel@tonic-gate
21027c478bd9Sstevel@tonic-gate if (expanded) {
2103635216b6SRod Evans if ((nptr = libld_malloc(strlen(_name) + 1)) == NULL)
21047c478bd9Sstevel@tonic-gate return ((char *)name);
21057c478bd9Sstevel@tonic-gate (void) strcpy(nptr, _name);
21067c478bd9Sstevel@tonic-gate return (nptr);
21077c478bd9Sstevel@tonic-gate }
21087c478bd9Sstevel@tonic-gate return ((char *)name);
21097c478bd9Sstevel@tonic-gate }
21107c478bd9Sstevel@tonic-gate
2111d840867fSab /*
2112d840867fSab * The Solaris ld does not put DT_VERSYM in the dynamic section, but the
2113d840867fSab * GNU ld does, and it is used by the runtime linker to implement their
2114d840867fSab * versioning scheme. Use this fact to determine if the sharable object
2115d840867fSab * was produced by the GNU ld rather than the Solaris one, and to set
2116d840867fSab * FLG_IF_GNUVER if so. This needs to be done before the symbols are
2117d840867fSab * processed, since the answer determines whether we interpret the
2118d840867fSab * symbols versions according to Solaris or GNU rules.
2119d840867fSab */
2120d840867fSab /*ARGSUSED*/
2121d840867fSab static uintptr_t
process_dynamic_isgnu(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)2122d840867fSab process_dynamic_isgnu(const char *name, Ifl_desc *ifl, Shdr *shdr,
2123d840867fSab Elf_Scn *scn, Word ndx, int ident, Ofl_desc *ofl)
2124d840867fSab {
2125d840867fSab Dyn *dyn;
2126d840867fSab Elf_Data *dp;
21270e233487SRod Evans uintptr_t error;
2128d840867fSab
21290e233487SRod Evans error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
21300e233487SRod Evans if ((error == 0) || (error == S_ERROR))
21310e233487SRod Evans return (error);
2132d840867fSab
2133d840867fSab /* Get the .dynamic data */
2134d840867fSab dp = elf_getdata(scn, NULL);
2135d840867fSab
2136d840867fSab for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) {
2137d840867fSab if (dyn->d_tag == DT_VERSYM) {
2138d840867fSab ifl->ifl_flags |= FLG_IF_GNUVER;
2139d840867fSab break;
2140d840867fSab }
2141d840867fSab }
2142d840867fSab return (1);
2143d840867fSab }
2144d840867fSab
21457c478bd9Sstevel@tonic-gate /*
21467c478bd9Sstevel@tonic-gate * Process a dynamic section. If we are processing an explicit shared object
21477c478bd9Sstevel@tonic-gate * then we need to determine if it has a recorded SONAME, if so, this name will
21487c478bd9Sstevel@tonic-gate * be recorded in the output file being generated as the NEEDED entry rather
21497c478bd9Sstevel@tonic-gate * than the shared objects filename itself.
21507c478bd9Sstevel@tonic-gate * If the mode of the link-edit indicates that no undefined symbols should
21517c478bd9Sstevel@tonic-gate * remain, then we also need to build up a list of any additional shared object
21527c478bd9Sstevel@tonic-gate * dependencies this object may have. In this case save any NEEDED entries
21537c478bd9Sstevel@tonic-gate * together with any associated run-path specifications. This information is
21547c478bd9Sstevel@tonic-gate * recorded on the `ofl_soneed' list and will be analyzed after all explicit
21557c478bd9Sstevel@tonic-gate * file processing has been completed (refer finish_libs()).
21567c478bd9Sstevel@tonic-gate */
21575aefb655Srie static uintptr_t
process_dynamic(Is_desc * isc,Ifl_desc * ifl,Ofl_desc * ofl)21587c478bd9Sstevel@tonic-gate process_dynamic(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
21597c478bd9Sstevel@tonic-gate {
21607c478bd9Sstevel@tonic-gate Dyn *data, *dyn;
21617c478bd9Sstevel@tonic-gate char *str, *rpath = NULL;
21627c478bd9Sstevel@tonic-gate const char *soname, *needed;
21631007fd6fSAli Bahrami Boolean no_undef;
21647c478bd9Sstevel@tonic-gate
21657c478bd9Sstevel@tonic-gate data = (Dyn *)isc->is_indata->d_buf;
21667c478bd9Sstevel@tonic-gate str = (char *)ifl->ifl_isdesc[isc->is_shdr->sh_link]->is_indata->d_buf;
21677c478bd9Sstevel@tonic-gate
21681007fd6fSAli Bahrami /* Determine if we need to examine the runpaths and NEEDED entries */
21691007fd6fSAli Bahrami no_undef = (ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)) ||
21701007fd6fSAli Bahrami OFL_GUIDANCE(ofl, FLG_OFG_NO_DEFS);
21711007fd6fSAli Bahrami
21727c478bd9Sstevel@tonic-gate /*
21737c478bd9Sstevel@tonic-gate * First loop through the dynamic section looking for a run path.
21747c478bd9Sstevel@tonic-gate */
21751007fd6fSAli Bahrami if (no_undef) {
21767c478bd9Sstevel@tonic-gate for (dyn = data; dyn->d_tag != DT_NULL; dyn++) {
21777c478bd9Sstevel@tonic-gate if ((dyn->d_tag != DT_RPATH) &&
21787c478bd9Sstevel@tonic-gate (dyn->d_tag != DT_RUNPATH))
21797c478bd9Sstevel@tonic-gate continue;
21807c478bd9Sstevel@tonic-gate if ((rpath = str + (size_t)dyn->d_un.d_val) == NULL)
21817c478bd9Sstevel@tonic-gate continue;
21827c478bd9Sstevel@tonic-gate break;
21837c478bd9Sstevel@tonic-gate }
21847c478bd9Sstevel@tonic-gate }
21857c478bd9Sstevel@tonic-gate
21867c478bd9Sstevel@tonic-gate /*
21877c478bd9Sstevel@tonic-gate * Now look for any needed dependencies (which may use the rpath)
21887c478bd9Sstevel@tonic-gate * or a new SONAME.
21897c478bd9Sstevel@tonic-gate */
21907c478bd9Sstevel@tonic-gate for (dyn = data; dyn->d_tag != DT_NULL; dyn++) {
21917c478bd9Sstevel@tonic-gate if (dyn->d_tag == DT_SONAME) {
21927c478bd9Sstevel@tonic-gate if ((soname = str + (size_t)dyn->d_un.d_val) == NULL)
21937c478bd9Sstevel@tonic-gate continue;
21947c478bd9Sstevel@tonic-gate
21957c478bd9Sstevel@tonic-gate /*
21967c478bd9Sstevel@tonic-gate * Update the input file structure with this new name.
21977c478bd9Sstevel@tonic-gate */
21987c478bd9Sstevel@tonic-gate ifl->ifl_soname = soname;
21997c478bd9Sstevel@tonic-gate
22007c478bd9Sstevel@tonic-gate } else if ((dyn->d_tag == DT_NEEDED) ||
22017c478bd9Sstevel@tonic-gate (dyn->d_tag == DT_USED)) {
220257ef7aa9SRod Evans Sdf_desc *sdf;
220357ef7aa9SRod Evans
22041007fd6fSAli Bahrami if (!no_undef)
22057c478bd9Sstevel@tonic-gate continue;
22067c478bd9Sstevel@tonic-gate if ((needed = str + (size_t)dyn->d_un.d_val) == NULL)
22077c478bd9Sstevel@tonic-gate continue;
22087c478bd9Sstevel@tonic-gate
22097c478bd9Sstevel@tonic-gate /*
22107c478bd9Sstevel@tonic-gate * Determine if this needed entry is already recorded on
22117c478bd9Sstevel@tonic-gate * the shared object needed list, if not create a new
22127c478bd9Sstevel@tonic-gate * definition for later processing (see finish_libs()).
22137c478bd9Sstevel@tonic-gate */
221457ef7aa9SRod Evans needed = expand(ifl->ifl_name, needed, NULL);
22157c478bd9Sstevel@tonic-gate
221657ef7aa9SRod Evans if ((sdf = sdf_find(needed, ofl->ofl_soneed)) == NULL) {
22177c478bd9Sstevel@tonic-gate if ((sdf = sdf_add(needed,
22187c478bd9Sstevel@tonic-gate &ofl->ofl_soneed)) == (Sdf_desc *)S_ERROR)
22197c478bd9Sstevel@tonic-gate return (S_ERROR);
22207c478bd9Sstevel@tonic-gate sdf->sdf_rfile = ifl->ifl_name;
22217c478bd9Sstevel@tonic-gate }
22227c478bd9Sstevel@tonic-gate
22237c478bd9Sstevel@tonic-gate /*
22247c478bd9Sstevel@tonic-gate * Record the runpath (Note that we take the first
22257c478bd9Sstevel@tonic-gate * runpath which is exactly what ld.so.1 would do during
22267c478bd9Sstevel@tonic-gate * its dependency processing).
22277c478bd9Sstevel@tonic-gate */
2228635216b6SRod Evans if (rpath && (sdf->sdf_rpath == NULL))
22297c478bd9Sstevel@tonic-gate sdf->sdf_rpath = rpath;
22307c478bd9Sstevel@tonic-gate
22317c478bd9Sstevel@tonic-gate } else if (dyn->d_tag == DT_FLAGS_1) {
22327c478bd9Sstevel@tonic-gate if (dyn->d_un.d_val & (DF_1_INITFIRST | DF_1_INTERPOSE))
22337c478bd9Sstevel@tonic-gate ifl->ifl_flags &= ~FLG_IF_LAZYLD;
22347c478bd9Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_DISPRELPND)
22357c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DISPPEND;
22367c478bd9Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_DISPRELDNE)
22377c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DISPDONE;
22387c478bd9Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_NODIRECT)
22397c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_NODIRECT;
22407c478bd9Sstevel@tonic-gate
22411007fd6fSAli Bahrami /*
22421007fd6fSAli Bahrami * If we are building an executable, and this
22431007fd6fSAli Bahrami * dependency is tagged as an interposer, then
22441007fd6fSAli Bahrami * assume that it is required even if symbol
22451007fd6fSAli Bahrami * resolution uncovers no evident use.
22461007fd6fSAli Bahrami *
22471007fd6fSAli Bahrami * If we are building a shared object, then an
22481007fd6fSAli Bahrami * interposer dependency has no special meaning, and we
22491007fd6fSAli Bahrami * treat it as a regular dependency. By definition, all
22501007fd6fSAli Bahrami * interposers must be visible to the runtime linker
22511007fd6fSAli Bahrami * at initialization time, and cannot be added later.
22521007fd6fSAli Bahrami */
22531007fd6fSAli Bahrami if ((dyn->d_un.d_val & DF_1_INTERPOSE) &&
22541007fd6fSAli Bahrami (ofl->ofl_flags & FLG_OF_EXEC))
22551007fd6fSAli Bahrami ifl->ifl_flags |= FLG_IF_DEPREQD;
22561007fd6fSAli Bahrami
22577c478bd9Sstevel@tonic-gate } else if ((dyn->d_tag == DT_AUDIT) &&
22587c478bd9Sstevel@tonic-gate (ifl->ifl_flags & FLG_IF_NEEDED)) {
22597c478bd9Sstevel@tonic-gate /*
22607c478bd9Sstevel@tonic-gate * Record audit string as DT_DEPAUDIT.
22617c478bd9Sstevel@tonic-gate */
22627c478bd9Sstevel@tonic-gate if ((ofl->ofl_depaudit = add_string(ofl->ofl_depaudit,
22637c478bd9Sstevel@tonic-gate (str + (size_t)dyn->d_un.d_val))) ==
22647c478bd9Sstevel@tonic-gate (const char *)S_ERROR)
22657c478bd9Sstevel@tonic-gate return (S_ERROR);
22667c478bd9Sstevel@tonic-gate
22677c478bd9Sstevel@tonic-gate } else if (dyn->d_tag == DT_SUNW_RTLDINF) {
22687c478bd9Sstevel@tonic-gate /*
2269f441771bSRod Evans * If this dependency has the DT_SUNW_RTLDINF .dynamic
2270f441771bSRod Evans * entry, then ensure no specialized dependency
2271f441771bSRod Evans * processing is in effect. This tag identifies libc,
2272f441771bSRod Evans * which provides critical startup information (TLS
2273f441771bSRod Evans * routines, threads initialization, etc.) that must
2274f441771bSRod Evans * be exercised as part of process initialization.
22757c478bd9Sstevel@tonic-gate */
2276f441771bSRod Evans ifl->ifl_flags &= ~MSK_IF_POSFLAG1;
22771007fd6fSAli Bahrami
22781007fd6fSAli Bahrami /*
22791007fd6fSAli Bahrami * libc is not subject to the usual guidance checks
22801007fd6fSAli Bahrami * for lazy loading. It cannot be lazy loaded, libld
22811007fd6fSAli Bahrami * ignores the request, and rtld would ignore the
22821007fd6fSAli Bahrami * setting if it were present.
22831007fd6fSAli Bahrami */
22841007fd6fSAli Bahrami ifl->ifl_flags |= FLG_IF_RTLDINF;
22857c478bd9Sstevel@tonic-gate }
22867c478bd9Sstevel@tonic-gate }
22877c478bd9Sstevel@tonic-gate
22887c478bd9Sstevel@tonic-gate /*
22897c478bd9Sstevel@tonic-gate * Perform some SONAME sanity checks.
22907c478bd9Sstevel@tonic-gate */
22917c478bd9Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_NEEDED) {
22920e233487SRod Evans Ifl_desc *sifl;
229357ef7aa9SRod Evans Aliste idx;
22947c478bd9Sstevel@tonic-gate
22957c478bd9Sstevel@tonic-gate /*
22967c478bd9Sstevel@tonic-gate * Determine if anyone else will cause the same SONAME to be
22977c478bd9Sstevel@tonic-gate * used (this is either caused by two different files having the
22987c478bd9Sstevel@tonic-gate * same SONAME, or by one file SONAME actually matching another
22997c478bd9Sstevel@tonic-gate * file basename (if no SONAME is specified within a shared
23007c478bd9Sstevel@tonic-gate * library its basename will be used)). Probably rare, but some
23017c478bd9Sstevel@tonic-gate * idiot will do it.
23027c478bd9Sstevel@tonic-gate */
230357ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_sos, idx, sifl)) {
23047c478bd9Sstevel@tonic-gate if ((strcmp(ifl->ifl_soname, sifl->ifl_soname) == 0) &&
23057c478bd9Sstevel@tonic-gate (ifl != sifl)) {
23067c478bd9Sstevel@tonic-gate const char *hint, *iflb, *siflb;
23077c478bd9Sstevel@tonic-gate
23087c478bd9Sstevel@tonic-gate /*
23097c478bd9Sstevel@tonic-gate * Determine the basename of each file. Perhaps
23107c478bd9Sstevel@tonic-gate * there are multiple copies of the same file
23117c478bd9Sstevel@tonic-gate * being brought in using different -L search
23127c478bd9Sstevel@tonic-gate * paths, and if so give an extra hint in the
23137c478bd9Sstevel@tonic-gate * error message.
23147c478bd9Sstevel@tonic-gate */
23157c478bd9Sstevel@tonic-gate iflb = strrchr(ifl->ifl_name, '/');
23167c478bd9Sstevel@tonic-gate if (iflb == NULL)
23177c478bd9Sstevel@tonic-gate iflb = ifl->ifl_name;
23187c478bd9Sstevel@tonic-gate else
23197c478bd9Sstevel@tonic-gate iflb++;
23207c478bd9Sstevel@tonic-gate
23217c478bd9Sstevel@tonic-gate siflb = strrchr(sifl->ifl_name, '/');
23227c478bd9Sstevel@tonic-gate if (siflb == NULL)
23237c478bd9Sstevel@tonic-gate siflb = sifl->ifl_name;
23247c478bd9Sstevel@tonic-gate else
23257c478bd9Sstevel@tonic-gate siflb++;
23267c478bd9Sstevel@tonic-gate
23277c478bd9Sstevel@tonic-gate if (strcmp(iflb, siflb) == 0)
23287c478bd9Sstevel@tonic-gate hint = MSG_INTL(MSG_REC_CNFLTHINT);
23297c478bd9Sstevel@tonic-gate else
23307c478bd9Sstevel@tonic-gate hint = MSG_ORIG(MSG_STR_EMPTY);
23317c478bd9Sstevel@tonic-gate
23321007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
23335aefb655Srie MSG_INTL(MSG_REC_OBJCNFLT), sifl->ifl_name,
23345aefb655Srie ifl->ifl_name, sifl->ifl_soname, hint);
23357c478bd9Sstevel@tonic-gate return (0);
23367c478bd9Sstevel@tonic-gate }
23377c478bd9Sstevel@tonic-gate }
23387c478bd9Sstevel@tonic-gate
23397c478bd9Sstevel@tonic-gate /*
23407c478bd9Sstevel@tonic-gate * If the SONAME is the same as the name the user wishes to
23417c478bd9Sstevel@tonic-gate * record when building a dynamic library (refer -h option),
23427c478bd9Sstevel@tonic-gate * we also have a name clash.
23437c478bd9Sstevel@tonic-gate */
23447c478bd9Sstevel@tonic-gate if (ofl->ofl_soname &&
23457c478bd9Sstevel@tonic-gate (strcmp(ofl->ofl_soname, ifl->ifl_soname) == 0)) {
23461007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
23475aefb655Srie MSG_INTL(MSG_REC_OPTCNFLT), ifl->ifl_name,
2348551cffe3SAli Bahrami MSG_INTL(MSG_MARG_SONAME), ifl->ifl_soname);
23497c478bd9Sstevel@tonic-gate return (0);
23507c478bd9Sstevel@tonic-gate }
23517c478bd9Sstevel@tonic-gate }
23527c478bd9Sstevel@tonic-gate return (1);
23537c478bd9Sstevel@tonic-gate }
23547c478bd9Sstevel@tonic-gate
23557e16fca0SAli Bahrami /*
23567e16fca0SAli Bahrami * Process a progbits section from a relocatable object (ET_REL).
23577e16fca0SAli Bahrami * This is used on non-amd64 objects to recognize .eh_frame sections.
23587e16fca0SAli Bahrami */
23597e16fca0SAli Bahrami /*ARGSUSED1*/
23607e16fca0SAli Bahrami static uintptr_t
process_progbits_final(Is_desc * isc,Ifl_desc * ifl,Ofl_desc * ofl)23617e16fca0SAli Bahrami process_progbits_final(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
23627e16fca0SAli Bahrami {
23637e16fca0SAli Bahrami if (isc->is_osdesc && (isc->is_flags & FLG_IS_EHFRAME) &&
23647e16fca0SAli Bahrami (ld_unwind_register(isc->is_osdesc, ofl) == S_ERROR))
23657e16fca0SAli Bahrami return (S_ERROR);
23667e16fca0SAli Bahrami
23677e16fca0SAli Bahrami return (1);
23687e16fca0SAli Bahrami }
23697e16fca0SAli Bahrami
23700e233487SRod Evans /*
23710e233487SRod Evans * Process a group section.
23720e233487SRod Evans */
23730e233487SRod Evans static uintptr_t
process_group(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)23740e233487SRod Evans process_group(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
23750e233487SRod Evans Word ndx, int ident, Ofl_desc *ofl)
23760e233487SRod Evans {
23770e233487SRod Evans uintptr_t error;
23780e233487SRod Evans
23790e233487SRod Evans error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
23800e233487SRod Evans if ((error == 0) || (error == S_ERROR))
23810e233487SRod Evans return (error);
23820e233487SRod Evans
23830e233487SRod Evans /*
23840e233487SRod Evans * Indicate that this input file has groups to process. Groups are
23850e233487SRod Evans * processed after all input sections have been processed.
23860e233487SRod Evans */
2387a8c23f9dSRichard Lowe ifl->ifl_flags |= FLG_IF_GROUPS;
23880e233487SRod Evans
23890e233487SRod Evans return (1);
23900e233487SRod Evans }
23910e233487SRod Evans
23927c478bd9Sstevel@tonic-gate /*
23937c478bd9Sstevel@tonic-gate * Process a relocation entry. At this point all input sections from this
23947c478bd9Sstevel@tonic-gate * input file have been assigned an input section descriptor which is saved
23957c478bd9Sstevel@tonic-gate * in the `ifl_isdesc' array.
23967c478bd9Sstevel@tonic-gate */
23975aefb655Srie static uintptr_t
rel_process(Is_desc * isc,Ifl_desc * ifl,Ofl_desc * ofl)23987c478bd9Sstevel@tonic-gate rel_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
23997c478bd9Sstevel@tonic-gate {
2400b6a0e2cdSRichard Lowe Word rndx;
24017c478bd9Sstevel@tonic-gate Is_desc *risc;
24027c478bd9Sstevel@tonic-gate Os_desc *osp;
24037c478bd9Sstevel@tonic-gate Shdr *shdr = isc->is_shdr;
2404de777a60Sab Conv_inv_buf_t inv_buf;
24057c478bd9Sstevel@tonic-gate
24067c478bd9Sstevel@tonic-gate /*
24077c478bd9Sstevel@tonic-gate * Make sure this is a valid relocation we can handle.
24087c478bd9Sstevel@tonic-gate */
2409ba2be530Sab if (shdr->sh_type != ld_targ.t_m.m_rel_sht_type) {
24101007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVALSEC),
24114a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(isc->is_scnndx), isc->is_name,
24124f680cc6SAli Bahrami conv_sec_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
2413ff4c9ae3SRichard Lowe ifl->ifl_ehdr->e_machine, shdr->sh_type, CONV_FMT_ALT_CF,
2414ff4c9ae3SRichard Lowe &inv_buf));
24157c478bd9Sstevel@tonic-gate return (0);
24167c478bd9Sstevel@tonic-gate }
24177c478bd9Sstevel@tonic-gate
24187c478bd9Sstevel@tonic-gate /*
24197c478bd9Sstevel@tonic-gate * From the relocation section header information determine which
24207c478bd9Sstevel@tonic-gate * section needs the actual relocation. Determine which output section
24217c478bd9Sstevel@tonic-gate * this input section has been assigned to and add to its relocation
24227c478bd9Sstevel@tonic-gate * list. Note that the relocation section may be null if it is not
24237c478bd9Sstevel@tonic-gate * required (ie. .debug, .stabs, etc).
24247c478bd9Sstevel@tonic-gate */
24257c478bd9Sstevel@tonic-gate rndx = shdr->sh_info;
24267c478bd9Sstevel@tonic-gate if (rndx >= ifl->ifl_shnum) {
24277c478bd9Sstevel@tonic-gate /*
24287c478bd9Sstevel@tonic-gate * Broken input file.
24297c478bd9Sstevel@tonic-gate */
24301007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHINFO),
24314a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(isc->is_scnndx), isc->is_name,
24324a8d0ea7SAli Bahrami EC_XWORD(rndx));
24337c478bd9Sstevel@tonic-gate return (0);
24347c478bd9Sstevel@tonic-gate }
24357c478bd9Sstevel@tonic-gate if (rndx == 0) {
243657ef7aa9SRod Evans if (aplist_append(&ofl->ofl_extrarels, isc,
243757ef7aa9SRod Evans AL_CNT_OFL_RELS) == NULL)
24387c478bd9Sstevel@tonic-gate return (S_ERROR);
243957ef7aa9SRod Evans
244057ef7aa9SRod Evans } else if ((risc = ifl->ifl_isdesc[rndx]) != NULL) {
24417c478bd9Sstevel@tonic-gate /*
24427c478bd9Sstevel@tonic-gate * Discard relocations if they are against a section
24437c478bd9Sstevel@tonic-gate * which has been discarded.
24447c478bd9Sstevel@tonic-gate */
24457c478bd9Sstevel@tonic-gate if (risc->is_flags & FLG_IS_DISCARD)
24467c478bd9Sstevel@tonic-gate return (1);
244757ef7aa9SRod Evans
244857ef7aa9SRod Evans if ((osp = risc->is_osdesc) == NULL) {
24497c478bd9Sstevel@tonic-gate if (risc->is_shdr->sh_type == SHT_SUNW_move) {
24507c478bd9Sstevel@tonic-gate /*
245157ef7aa9SRod Evans * This section is processed later in
245257ef7aa9SRod Evans * process_movereloc().
24537c478bd9Sstevel@tonic-gate */
245457ef7aa9SRod Evans if (aplist_append(&ofl->ofl_ismoverel,
245557ef7aa9SRod Evans isc, AL_CNT_OFL_MOVE) == NULL)
24567c478bd9Sstevel@tonic-gate return (S_ERROR);
24577c478bd9Sstevel@tonic-gate return (1);
24587c478bd9Sstevel@tonic-gate }
24591007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
24605aefb655Srie MSG_INTL(MSG_FIL_INVRELOC1), ifl->ifl_name,
24614a8d0ea7SAli Bahrami EC_WORD(isc->is_scnndx), isc->is_name,
24624a8d0ea7SAli Bahrami EC_WORD(risc->is_scnndx), risc->is_name);
24637c478bd9Sstevel@tonic-gate return (0);
24647c478bd9Sstevel@tonic-gate }
24656b3ba5bdSAli Bahrami if (aplist_append(&osp->os_relisdescs, isc,
24666b3ba5bdSAli Bahrami AL_CNT_OS_RELISDESCS) == NULL)
24677c478bd9Sstevel@tonic-gate return (S_ERROR);
24687c478bd9Sstevel@tonic-gate }
24697c478bd9Sstevel@tonic-gate return (1);
24707c478bd9Sstevel@tonic-gate }
24717c478bd9Sstevel@tonic-gate
24727c478bd9Sstevel@tonic-gate /*
24737c478bd9Sstevel@tonic-gate * SHF_EXCLUDE flags is set for this section.
24747c478bd9Sstevel@tonic-gate */
24757c478bd9Sstevel@tonic-gate static uintptr_t
process_exclude(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,Ofl_desc * ofl)24767c478bd9Sstevel@tonic-gate process_exclude(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
24777c478bd9Sstevel@tonic-gate Word ndx, Ofl_desc *ofl)
24787c478bd9Sstevel@tonic-gate {
24797c478bd9Sstevel@tonic-gate /*
24807c478bd9Sstevel@tonic-gate * Sections SHT_SYMTAB and SHT_DYNDYM, even if SHF_EXCLUDE is on, might
24817c478bd9Sstevel@tonic-gate * be needed for ld processing. These sections need to be in the
24827c478bd9Sstevel@tonic-gate * internal table. Later it will be determined whether they can be
24837c478bd9Sstevel@tonic-gate * eliminated or not.
24847c478bd9Sstevel@tonic-gate */
24857c478bd9Sstevel@tonic-gate if (shdr->sh_type == SHT_SYMTAB || shdr->sh_type == SHT_DYNSYM)
24867c478bd9Sstevel@tonic-gate return (0);
24877c478bd9Sstevel@tonic-gate
24887c478bd9Sstevel@tonic-gate /*
24897c478bd9Sstevel@tonic-gate * Other checks
24907c478bd9Sstevel@tonic-gate */
24917c478bd9Sstevel@tonic-gate if (shdr->sh_flags & SHF_ALLOC) {
24927c478bd9Sstevel@tonic-gate /*
24937c478bd9Sstevel@tonic-gate * A conflict, issue an warning message, and ignore the section.
24947c478bd9Sstevel@tonic-gate */
24951007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_EXCLUDE),
24964a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(ndx), name);
24977c478bd9Sstevel@tonic-gate return (0);
24987c478bd9Sstevel@tonic-gate }
24997c478bd9Sstevel@tonic-gate
25007c478bd9Sstevel@tonic-gate /*
25017c478bd9Sstevel@tonic-gate * This sections is not going to the output file.
25027c478bd9Sstevel@tonic-gate */
25037c478bd9Sstevel@tonic-gate return (process_section(name, ifl, shdr, scn, ndx, 0, ofl));
25047c478bd9Sstevel@tonic-gate }
25057c478bd9Sstevel@tonic-gate
25067c478bd9Sstevel@tonic-gate /*
25077c478bd9Sstevel@tonic-gate * Section processing state table. `Initial' describes the required initial
25087c478bd9Sstevel@tonic-gate * procedure to be called (if any), `Final' describes the final processing
25097c478bd9Sstevel@tonic-gate * procedure (ie. things that can only be done when all required sections
25107c478bd9Sstevel@tonic-gate * have been collected).
25117c478bd9Sstevel@tonic-gate */
25127e16fca0SAli Bahrami typedef uintptr_t (* initial_func_t)(const char *, Ifl_desc *, Shdr *,
25137e16fca0SAli Bahrami Elf_Scn *, Word, int, Ofl_desc *);
25147c478bd9Sstevel@tonic-gate
25157e16fca0SAli Bahrami static initial_func_t Initial[SHT_NUM][2] = {
25167c478bd9Sstevel@tonic-gate /* ET_REL ET_DYN */
25177c478bd9Sstevel@tonic-gate
25187c478bd9Sstevel@tonic-gate /* SHT_NULL */ invalid_section, invalid_section,
25197c478bd9Sstevel@tonic-gate /* SHT_PROGBITS */ process_progbits, process_progbits,
25207c478bd9Sstevel@tonic-gate /* SHT_SYMTAB */ process_input, process_input,
25217c478bd9Sstevel@tonic-gate /* SHT_STRTAB */ process_strtab, process_strtab,
25227c478bd9Sstevel@tonic-gate /* SHT_RELA */ process_reloc, process_reloc,
25237c478bd9Sstevel@tonic-gate /* SHT_HASH */ invalid_section, NULL,
2524d840867fSab /* SHT_DYNAMIC */ process_rel_dynamic, process_dynamic_isgnu,
25257c478bd9Sstevel@tonic-gate /* SHT_NOTE */ process_section, NULL,
25267c478bd9Sstevel@tonic-gate /* SHT_NOBITS */ process_nobits, process_nobits,
25277c478bd9Sstevel@tonic-gate /* SHT_REL */ process_reloc, process_reloc,
25287c478bd9Sstevel@tonic-gate /* SHT_SHLIB */ process_section, invalid_section,
25297c478bd9Sstevel@tonic-gate /* SHT_DYNSYM */ invalid_section, process_input,
25307c478bd9Sstevel@tonic-gate /* SHT_UNKNOWN12 */ process_progbits, process_progbits,
25317c478bd9Sstevel@tonic-gate /* SHT_UNKNOWN13 */ process_progbits, process_progbits,
25327c478bd9Sstevel@tonic-gate /* SHT_INIT_ARRAY */ process_array, NULL,
25337c478bd9Sstevel@tonic-gate /* SHT_FINI_ARRAY */ process_array, NULL,
25347c478bd9Sstevel@tonic-gate /* SHT_PREINIT_ARRAY */ process_array, NULL,
25350e233487SRod Evans /* SHT_GROUP */ process_group, invalid_section,
25367c478bd9Sstevel@tonic-gate /* SHT_SYMTAB_SHNDX */ process_sym_shndx, NULL
25377c478bd9Sstevel@tonic-gate };
25387c478bd9Sstevel@tonic-gate
25397e16fca0SAli Bahrami typedef uintptr_t (* final_func_t)(Is_desc *, Ifl_desc *, Ofl_desc *);
25407e16fca0SAli Bahrami
25417e16fca0SAli Bahrami static final_func_t Final[SHT_NUM][2] = {
25427e16fca0SAli Bahrami /* ET_REL ET_DYN */
25437c478bd9Sstevel@tonic-gate
25447c478bd9Sstevel@tonic-gate /* SHT_NULL */ NULL, NULL,
25457e16fca0SAli Bahrami /* SHT_PROGBITS */ process_progbits_final, NULL,
25465aefb655Srie /* SHT_SYMTAB */ ld_sym_process, ld_sym_process,
25477c478bd9Sstevel@tonic-gate /* SHT_STRTAB */ NULL, NULL,
25487c478bd9Sstevel@tonic-gate /* SHT_RELA */ rel_process, NULL,
25497c478bd9Sstevel@tonic-gate /* SHT_HASH */ NULL, NULL,
25507c478bd9Sstevel@tonic-gate /* SHT_DYNAMIC */ NULL, process_dynamic,
25517c478bd9Sstevel@tonic-gate /* SHT_NOTE */ NULL, NULL,
25527c478bd9Sstevel@tonic-gate /* SHT_NOBITS */ NULL, NULL,
25537c478bd9Sstevel@tonic-gate /* SHT_REL */ rel_process, NULL,
25547c478bd9Sstevel@tonic-gate /* SHT_SHLIB */ NULL, NULL,
25555aefb655Srie /* SHT_DYNSYM */ NULL, ld_sym_process,
25567c478bd9Sstevel@tonic-gate /* SHT_UNKNOWN12 */ NULL, NULL,
25577c478bd9Sstevel@tonic-gate /* SHT_UNKNOWN13 */ NULL, NULL,
25580e233487SRod Evans /* SHT_INIT_ARRAY */ array_process, NULL,
25590e233487SRod Evans /* SHT_FINI_ARRAY */ array_process, NULL,
25600e233487SRod Evans /* SHT_PREINIT_ARRAY */ array_process, NULL,
25617c478bd9Sstevel@tonic-gate /* SHT_GROUP */ NULL, NULL,
25627c478bd9Sstevel@tonic-gate /* SHT_SYMTAB_SHNDX */ sym_shndx_process, NULL
25637c478bd9Sstevel@tonic-gate };
25647c478bd9Sstevel@tonic-gate
25657c478bd9Sstevel@tonic-gate #define MAXNDXSIZE 10
25667c478bd9Sstevel@tonic-gate
25677c478bd9Sstevel@tonic-gate /*
25687c478bd9Sstevel@tonic-gate * Process an elf file. Each section is compared against the section state
25697c478bd9Sstevel@tonic-gate * table to determine whether it should be processed (saved), ignored, or
25707c478bd9Sstevel@tonic-gate * is invalid for the type of input file being processed.
25717c478bd9Sstevel@tonic-gate */
25725aefb655Srie static uintptr_t
process_elf(Ifl_desc * ifl,Elf * elf,Ofl_desc * ofl)25737c478bd9Sstevel@tonic-gate process_elf(Ifl_desc *ifl, Elf *elf, Ofl_desc *ofl)
25747c478bd9Sstevel@tonic-gate {
25757c478bd9Sstevel@tonic-gate Elf_Scn *scn;
25767c478bd9Sstevel@tonic-gate Shdr *shdr;
25770e233487SRod Evans Word ndx, sndx, ordndx = 0, ordcnt = 0;
25784a8d0ea7SAli Bahrami char *str, *name;
25797c478bd9Sstevel@tonic-gate Word row, column;
25807c478bd9Sstevel@tonic-gate int ident;
25817c478bd9Sstevel@tonic-gate uintptr_t error;
258208278a5eSRod Evans Is_desc *vdfisp, *vndisp, *vsyisp, *sifisp;
258308278a5eSRod Evans Is_desc *capinfoisp, *capisp;
25847c478bd9Sstevel@tonic-gate Sdf_desc *sdf;
258569112eddSAli Bahrami Place_path_info path_info_buf, *path_info;
258669112eddSAli Bahrami
258769112eddSAli Bahrami /*
258869112eddSAli Bahrami * Path information buffer used by ld_place_section() and related
258969112eddSAli Bahrami * routines. This information is used to evaluate entrance criteria
259069112eddSAli Bahrami * with non-empty file matching lists (ec_files).
259169112eddSAli Bahrami */
259269112eddSAli Bahrami path_info = ld_place_path_info_init(ofl, ifl, &path_info_buf);
25937c478bd9Sstevel@tonic-gate
25947c478bd9Sstevel@tonic-gate /*
25957c478bd9Sstevel@tonic-gate * First process the .shstrtab section so that later sections can
25967c478bd9Sstevel@tonic-gate * reference their name.
25977c478bd9Sstevel@tonic-gate */
25985aefb655Srie ld_sup_file(ofl, ifl->ifl_name, elf_kind(elf), ifl->ifl_flags, elf);
25997c478bd9Sstevel@tonic-gate
26007c478bd9Sstevel@tonic-gate sndx = ifl->ifl_shstrndx;
26017c478bd9Sstevel@tonic-gate if ((scn = elf_getscn(elf, (size_t)sndx)) == NULL) {
26021007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN),
26035aefb655Srie ifl->ifl_name);
26047c478bd9Sstevel@tonic-gate return (0);
26057c478bd9Sstevel@tonic-gate }
26067c478bd9Sstevel@tonic-gate if ((shdr = elf_getshdr(scn)) == NULL) {
26071007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR),
26085aefb655Srie ifl->ifl_name);
26097c478bd9Sstevel@tonic-gate return (0);
26107c478bd9Sstevel@tonic-gate }
26117c478bd9Sstevel@tonic-gate if ((name = elf_strptr(elf, (size_t)sndx, (size_t)shdr->sh_name)) ==
26127c478bd9Sstevel@tonic-gate NULL) {
26131007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR),
26145aefb655Srie ifl->ifl_name);
26157c478bd9Sstevel@tonic-gate return (0);
26167c478bd9Sstevel@tonic-gate }
26177c478bd9Sstevel@tonic-gate
26187010c12aSrie if (ld_sup_input_section(ofl, ifl, name, &shdr, sndx, scn,
26197010c12aSrie elf) == S_ERROR)
26207c478bd9Sstevel@tonic-gate return (S_ERROR);
26217c478bd9Sstevel@tonic-gate
26227c478bd9Sstevel@tonic-gate /*
26237c478bd9Sstevel@tonic-gate * Reset the name since the shdr->sh_name could have been changed as
26244a8d0ea7SAli Bahrami * part of ld_sup_input_section().
26257c478bd9Sstevel@tonic-gate */
26264a8d0ea7SAli Bahrami if ((name = elf_strptr(elf, (size_t)sndx, (size_t)shdr->sh_name)) ==
26274a8d0ea7SAli Bahrami NULL) {
26281007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR),
26295aefb655Srie ifl->ifl_name);
26307c478bd9Sstevel@tonic-gate return (0);
26317c478bd9Sstevel@tonic-gate }
26327c478bd9Sstevel@tonic-gate
26337c478bd9Sstevel@tonic-gate error = process_strtab(name, ifl, shdr, scn, sndx, FALSE, ofl);
26347c478bd9Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR))
26357c478bd9Sstevel@tonic-gate return (error);
26367c478bd9Sstevel@tonic-gate str = ifl->ifl_isdesc[sndx]->is_indata->d_buf;
26377c478bd9Sstevel@tonic-gate
26387c478bd9Sstevel@tonic-gate /*
26397c478bd9Sstevel@tonic-gate * Determine the state table column from the input file type. Note,
26407c478bd9Sstevel@tonic-gate * shared library sections are not added to the output section list.
26417c478bd9Sstevel@tonic-gate */
26427c478bd9Sstevel@tonic-gate if (ifl->ifl_ehdr->e_type == ET_DYN) {
26437c478bd9Sstevel@tonic-gate column = 1;
26447c478bd9Sstevel@tonic-gate ofl->ofl_soscnt++;
2645ba2be530Sab ident = ld_targ.t_id.id_null;
26467c478bd9Sstevel@tonic-gate } else {
26477c478bd9Sstevel@tonic-gate column = 0;
26487c478bd9Sstevel@tonic-gate ofl->ofl_objscnt++;
2649ba2be530Sab ident = ld_targ.t_id.id_unknown;
26507c478bd9Sstevel@tonic-gate }
26517c478bd9Sstevel@tonic-gate
26525aefb655Srie DBG_CALL(Dbg_file_generic(ofl->ofl_lml, ifl));
26537c478bd9Sstevel@tonic-gate ndx = 0;
265408278a5eSRod Evans vdfisp = vndisp = vsyisp = sifisp = capinfoisp = capisp = NULL;
26557c478bd9Sstevel@tonic-gate scn = NULL;
26567c478bd9Sstevel@tonic-gate while (scn = elf_nextscn(elf, scn)) {
26577c478bd9Sstevel@tonic-gate ndx++;
26580e233487SRod Evans
26597c478bd9Sstevel@tonic-gate /*
26607c478bd9Sstevel@tonic-gate * As we've already processed the .shstrtab don't do it again.
26617c478bd9Sstevel@tonic-gate */
26627c478bd9Sstevel@tonic-gate if (ndx == sndx)
26637c478bd9Sstevel@tonic-gate continue;
26647c478bd9Sstevel@tonic-gate
26657c478bd9Sstevel@tonic-gate if ((shdr = elf_getshdr(scn)) == NULL) {
26661007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR),
26671007fd6fSAli Bahrami ifl->ifl_name);
26687c478bd9Sstevel@tonic-gate return (0);
26697c478bd9Sstevel@tonic-gate }
26707c478bd9Sstevel@tonic-gate name = str + (size_t)(shdr->sh_name);
26717c478bd9Sstevel@tonic-gate
26727010c12aSrie if (ld_sup_input_section(ofl, ifl, name, &shdr, ndx, scn,
26737010c12aSrie elf) == S_ERROR)
26747c478bd9Sstevel@tonic-gate return (S_ERROR);
26757c478bd9Sstevel@tonic-gate
26767c478bd9Sstevel@tonic-gate /*
26777c478bd9Sstevel@tonic-gate * Reset the name since the shdr->sh_name could have been
26784a8d0ea7SAli Bahrami * changed as part of ld_sup_input_section().
26797c478bd9Sstevel@tonic-gate */
26804a8d0ea7SAli Bahrami name = str + (size_t)(shdr->sh_name);
26817c478bd9Sstevel@tonic-gate
26827c478bd9Sstevel@tonic-gate row = shdr->sh_type;
26837c478bd9Sstevel@tonic-gate
2684c9d20e65SRichard Lowe if (section_is_exclude(ofl, shdr)) {
26857c478bd9Sstevel@tonic-gate if ((error = process_exclude(name, ifl, shdr, scn,
26867c478bd9Sstevel@tonic-gate ndx, ofl)) == S_ERROR)
26877c478bd9Sstevel@tonic-gate return (S_ERROR);
26887c478bd9Sstevel@tonic-gate if (error == 1)
26897c478bd9Sstevel@tonic-gate continue;
26907c478bd9Sstevel@tonic-gate }
26917c478bd9Sstevel@tonic-gate
26927c478bd9Sstevel@tonic-gate /*
26937c478bd9Sstevel@tonic-gate * If this is a standard section type process it via the
26947c478bd9Sstevel@tonic-gate * appropriate action routine.
26957c478bd9Sstevel@tonic-gate */
26967c478bd9Sstevel@tonic-gate if (row < SHT_NUM) {
26977c478bd9Sstevel@tonic-gate if (Initial[row][column] != NULL) {
26987c478bd9Sstevel@tonic-gate if (Initial[row][column](name, ifl, shdr, scn,
26997c478bd9Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR)
27007c478bd9Sstevel@tonic-gate return (S_ERROR);
27017c478bd9Sstevel@tonic-gate }
27027c478bd9Sstevel@tonic-gate } else {
27037c478bd9Sstevel@tonic-gate /*
27047c478bd9Sstevel@tonic-gate * If this section is below SHT_LOSUNW then we don't
27057c461073SRichard Lowe * really know what to do with it.
27067c461073SRichard Lowe *
27077c461073SRichard Lowe * If SHF_EXCLUDE is set we're being told we should
27087c461073SRichard Lowe * (or may) ignore the section. Otherwise issue a
27097c461073SRichard Lowe * warning message but do the basic section processing
27107c461073SRichard Lowe * anyway.
27117c478bd9Sstevel@tonic-gate */
27127c461073SRichard Lowe if ((row < (Word)SHT_LOSUNW) &&
27137c461073SRichard Lowe ((shdr->sh_flags & SHF_EXCLUDE) == 0)) {
2714de777a60Sab Conv_inv_buf_t inv_buf;
2715de777a60Sab
27161007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
27175aefb655Srie MSG_INTL(MSG_FIL_INVALSEC), ifl->ifl_name,
27184a8d0ea7SAli Bahrami EC_WORD(ndx), name, conv_sec_type(
27194f680cc6SAli Bahrami ifl->ifl_ehdr->e_ident[EI_OSABI],
27204f680cc6SAli Bahrami ifl->ifl_ehdr->e_machine,
2721ff4c9ae3SRichard Lowe shdr->sh_type, CONV_FMT_ALT_CF, &inv_buf));
2722de777a60Sab }
27237c478bd9Sstevel@tonic-gate
27247c478bd9Sstevel@tonic-gate /*
27257c478bd9Sstevel@tonic-gate * Handle sections greater than SHT_LOSUNW.
27267c478bd9Sstevel@tonic-gate */
27277c478bd9Sstevel@tonic-gate switch (row) {
27287c478bd9Sstevel@tonic-gate case SHT_SUNW_dof:
27297c478bd9Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn,
27307c478bd9Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR)
27317c478bd9Sstevel@tonic-gate return (S_ERROR);
27327c478bd9Sstevel@tonic-gate break;
27337c478bd9Sstevel@tonic-gate case SHT_SUNW_cap:
27347e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27357e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
27367c478bd9Sstevel@tonic-gate return (S_ERROR);
27377c478bd9Sstevel@tonic-gate capisp = ifl->ifl_isdesc[ndx];
27387c478bd9Sstevel@tonic-gate break;
273908278a5eSRod Evans case SHT_SUNW_capinfo:
274008278a5eSRod Evans if (process_section(name, ifl, shdr, scn, ndx,
274108278a5eSRod Evans ld_targ.t_id.id_null, ofl) == S_ERROR)
274208278a5eSRod Evans return (S_ERROR);
274308278a5eSRod Evans capinfoisp = ifl->ifl_isdesc[ndx];
274408278a5eSRod Evans break;
27457c478bd9Sstevel@tonic-gate case SHT_SUNW_DEBUGSTR:
27467c478bd9Sstevel@tonic-gate case SHT_SUNW_DEBUG:
27477c478bd9Sstevel@tonic-gate if (process_debug(name, ifl, shdr, scn,
27487c478bd9Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR)
27497c478bd9Sstevel@tonic-gate return (S_ERROR);
27507c478bd9Sstevel@tonic-gate break;
27517c478bd9Sstevel@tonic-gate case SHT_SUNW_move:
27527e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27537e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
27547c478bd9Sstevel@tonic-gate return (S_ERROR);
27557c478bd9Sstevel@tonic-gate break;
27567c478bd9Sstevel@tonic-gate case SHT_SUNW_syminfo:
27577e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27587e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
27597c478bd9Sstevel@tonic-gate return (S_ERROR);
27607c478bd9Sstevel@tonic-gate sifisp = ifl->ifl_isdesc[ndx];
27617c478bd9Sstevel@tonic-gate break;
27627c478bd9Sstevel@tonic-gate case SHT_SUNW_ANNOTATE:
27630e233487SRod Evans if (process_progbits(name, ifl, shdr, scn,
27640e233487SRod Evans ndx, ident, ofl) == S_ERROR)
27650e233487SRod Evans return (S_ERROR);
27660e233487SRod Evans break;
27677c478bd9Sstevel@tonic-gate case SHT_SUNW_COMDAT:
27687c478bd9Sstevel@tonic-gate if (process_progbits(name, ifl, shdr, scn,
27697c478bd9Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR)
27707c478bd9Sstevel@tonic-gate return (S_ERROR);
27710e233487SRod Evans ifl->ifl_isdesc[ndx]->is_flags |= FLG_IS_COMDAT;
27727c478bd9Sstevel@tonic-gate break;
27737c478bd9Sstevel@tonic-gate case SHT_SUNW_verdef:
27747e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27757e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
27767c478bd9Sstevel@tonic-gate return (S_ERROR);
27777c478bd9Sstevel@tonic-gate vdfisp = ifl->ifl_isdesc[ndx];
27787c478bd9Sstevel@tonic-gate break;
27797c478bd9Sstevel@tonic-gate case SHT_SUNW_verneed:
27807e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27817e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
27827c478bd9Sstevel@tonic-gate return (S_ERROR);
27837c478bd9Sstevel@tonic-gate vndisp = ifl->ifl_isdesc[ndx];
27847c478bd9Sstevel@tonic-gate break;
27857c478bd9Sstevel@tonic-gate case SHT_SUNW_versym:
27867e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27877e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
27887c478bd9Sstevel@tonic-gate return (S_ERROR);
27897c478bd9Sstevel@tonic-gate vsyisp = ifl->ifl_isdesc[ndx];
27907c478bd9Sstevel@tonic-gate break;
27917c478bd9Sstevel@tonic-gate case SHT_SPARC_GOTDATA:
2792ba2be530Sab /*
2793ba2be530Sab * SHT_SPARC_GOTDATA (0x70000000) is in the
2794ba2be530Sab * SHT_LOPROC - SHT_HIPROC range reserved
2795ba2be530Sab * for processor-specific semantics. It is
2796ba2be530Sab * only meaningful for sparc targets.
2797ba2be530Sab */
2798ba2be530Sab if (ld_targ.t_m.m_mach !=
2799ba2be530Sab LD_TARG_BYCLASS(EM_SPARC, EM_SPARCV9))
2800ba2be530Sab goto do_default;
28017e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
28027e16fca0SAli Bahrami ld_targ.t_id.id_gotdata, ofl) == S_ERROR)
28037c478bd9Sstevel@tonic-gate return (S_ERROR);
28047c478bd9Sstevel@tonic-gate break;
2805ba2be530Sab #if defined(_ELF64)
28067c478bd9Sstevel@tonic-gate case SHT_AMD64_UNWIND:
2807ba2be530Sab /*
2808ba2be530Sab * SHT_AMD64_UNWIND (0x70000001) is in the
2809ba2be530Sab * SHT_LOPROC - SHT_HIPROC range reserved
2810ba2be530Sab * for processor-specific semantics. It is
2811ba2be530Sab * only meaningful for amd64 targets.
2812ba2be530Sab */
2813ba2be530Sab if (ld_targ.t_m.m_mach != EM_AMD64)
2814ba2be530Sab goto do_default;
28150e233487SRod Evans
2816ba2be530Sab /*
2817ba2be530Sab * Target is x86, so this really is
2818ba2be530Sab * SHT_AMD64_UNWIND
2819ba2be530Sab */
28207c478bd9Sstevel@tonic-gate if (column == 0) {
28217c478bd9Sstevel@tonic-gate /*
28227c478bd9Sstevel@tonic-gate * column == ET_REL
28237c478bd9Sstevel@tonic-gate */
28240e233487SRod Evans if (process_section(name, ifl, shdr,
28250e233487SRod Evans scn, ndx, ld_targ.t_id.id_unwind,
28260e233487SRod Evans ofl) == S_ERROR)
28277c478bd9Sstevel@tonic-gate return (S_ERROR);
28287e16fca0SAli Bahrami ifl->ifl_isdesc[ndx]->is_flags |=
28297e16fca0SAli Bahrami FLG_IS_EHFRAME;
28307c478bd9Sstevel@tonic-gate }
28317c478bd9Sstevel@tonic-gate break;
28327c478bd9Sstevel@tonic-gate #endif
28337c478bd9Sstevel@tonic-gate default:
2834ba2be530Sab do_default:
28357e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
28367e16fca0SAli Bahrami ((ident == ld_targ.t_id.id_null) ?
28377e16fca0SAli Bahrami ident : ld_targ.t_id.id_user), ofl) ==
28387e16fca0SAli Bahrami S_ERROR)
28397c478bd9Sstevel@tonic-gate return (S_ERROR);
28407c478bd9Sstevel@tonic-gate break;
28417c478bd9Sstevel@tonic-gate }
28427c478bd9Sstevel@tonic-gate }
28430e233487SRod Evans }
28440e233487SRod Evans
28450e233487SRod Evans /*
28460e233487SRod Evans * Now that all input sections have been analyzed, and prior to placing
28470e233487SRod Evans * any input sections to their output sections, process any groups.
28480e233487SRod Evans * Groups can contribute COMDAT items, which may get discarded as part
28490e233487SRod Evans * of placement. In addition, COMDAT names may require transformation
28500e233487SRod Evans * to indicate different output section placement.
28510e233487SRod Evans */
2852a8c23f9dSRichard Lowe if (ifl->ifl_flags & FLG_IF_GROUPS) {
28530e233487SRod Evans for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) {
28540e233487SRod Evans Is_desc *isp;
28550e233487SRod Evans
28560e233487SRod Evans if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
28570e233487SRod Evans (isp->is_shdr->sh_type != SHT_GROUP))
28580e233487SRod Evans continue;
28590e233487SRod Evans
28600e233487SRod Evans if (ld_group_process(isp, ofl) == S_ERROR)
28610e233487SRod Evans return (S_ERROR);
28620e233487SRod Evans }
28630e233487SRod Evans }
28640e233487SRod Evans
2865ef16f6b5SRichard Lowe /*
2866ef16f6b5SRichard Lowe * Now group information has been processed, we can safely validate
2867ef16f6b5SRichard Lowe * that nothing is fishy about the section COMDAT description. We
2868ef16f6b5SRichard Lowe * need to do this prior to placing the section (where any
2869ef16f6b5SRichard Lowe * SHT_SUNW_COMDAT sections will be restored to being PROGBITS)
2870ef16f6b5SRichard Lowe */
2871ef16f6b5SRichard Lowe ld_comdat_validate(ofl, ifl);
2872ef16f6b5SRichard Lowe
28730e233487SRod Evans /*
28741dd9d86fSAli Bahrami * Now that all of the input sections have been processed, place
28751dd9d86fSAli Bahrami * them in the appropriate output sections.
28760e233487SRod Evans */
28770e233487SRod Evans for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) {
28780e233487SRod Evans Is_desc *isp;
28790e233487SRod Evans
28800e233487SRod Evans if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
28810e233487SRod Evans ((isp->is_flags & FLG_IS_PLACE) == 0))
28820e233487SRod Evans continue;
28830e233487SRod Evans
28840e233487SRod Evans /*
28850e233487SRod Evans * Place all non-ordered sections within their appropriate
28860e233487SRod Evans * output section.
28870e233487SRod Evans */
28881dd9d86fSAli Bahrami if ((isp->is_flags & FLG_IS_ORDERED) == 0) {
288969112eddSAli Bahrami if (ld_place_section(ofl, isp, path_info,
28901dd9d86fSAli Bahrami isp->is_keyident, NULL) == (Os_desc *)S_ERROR)
28910e233487SRod Evans return (S_ERROR);
28921dd9d86fSAli Bahrami continue;
28930e233487SRod Evans }
28947c478bd9Sstevel@tonic-gate
28957c478bd9Sstevel@tonic-gate /*
28961dd9d86fSAli Bahrami * Count the number of ordered sections and retain the first
28971dd9d86fSAli Bahrami * ordered section index. This will be used to optimize the
28981dd9d86fSAli Bahrami * ordered section loop that immediately follows this one.
28997c478bd9Sstevel@tonic-gate */
29001dd9d86fSAli Bahrami ordcnt++;
29011dd9d86fSAli Bahrami if (ordndx == 0)
29021dd9d86fSAli Bahrami ordndx = ndx;
29037c478bd9Sstevel@tonic-gate }
29047c478bd9Sstevel@tonic-gate
29057c478bd9Sstevel@tonic-gate /*
29061dd9d86fSAli Bahrami * Having placed all the non-ordered sections, it is now
29071dd9d86fSAli Bahrami * safe to place SHF_ORDERED/SHF_LINK_ORDER sections.
29087c478bd9Sstevel@tonic-gate */
29090e233487SRod Evans if (ifl->ifl_flags & FLG_IF_ORDERED) {
29101dd9d86fSAli Bahrami for (ndx = ordndx; ndx < ifl->ifl_shnum; ndx++) {
29117c478bd9Sstevel@tonic-gate Is_desc *isp;
29127c478bd9Sstevel@tonic-gate
29130e233487SRod Evans if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
29141dd9d86fSAli Bahrami ((isp->is_flags &
29151dd9d86fSAli Bahrami (FLG_IS_PLACE | FLG_IS_ORDERED)) !=
29161dd9d86fSAli Bahrami (FLG_IS_PLACE | FLG_IS_ORDERED)))
29177c478bd9Sstevel@tonic-gate continue;
29187c478bd9Sstevel@tonic-gate
29191dd9d86fSAli Bahrami /* ld_process_ordered() calls ld_place_section() */
292069112eddSAli Bahrami if (ld_process_ordered(ofl, ifl, path_info, ndx) ==
292169112eddSAli Bahrami S_ERROR)
29227c478bd9Sstevel@tonic-gate return (S_ERROR);
29231dd9d86fSAli Bahrami
29241dd9d86fSAli Bahrami /* If we've done them all, stop searching */
29251dd9d86fSAli Bahrami if (--ordcnt == 0)
29261dd9d86fSAli Bahrami break;
29277c478bd9Sstevel@tonic-gate }
29287c478bd9Sstevel@tonic-gate }
29297c478bd9Sstevel@tonic-gate
29307c478bd9Sstevel@tonic-gate /*
29311dd9d86fSAli Bahrami * If this is a shared object explicitly specified on the command
29321dd9d86fSAli Bahrami * line (as opposed to being a dependency of such an object),
29331dd9d86fSAli Bahrami * determine if the user has specified a control definition. This
29341dd9d86fSAli Bahrami * descriptor may specify which version definitions can be used
29351dd9d86fSAli Bahrami * from this object. It may also update the dependency to USED and
29361dd9d86fSAli Bahrami * supply an alternative SONAME.
29377c478bd9Sstevel@tonic-gate */
2938635216b6SRod Evans sdf = NULL;
29397c478bd9Sstevel@tonic-gate if (column && (ifl->ifl_flags & FLG_IF_NEEDED)) {
29407c478bd9Sstevel@tonic-gate const char *base;
29417c478bd9Sstevel@tonic-gate
29427c478bd9Sstevel@tonic-gate /*
29437c478bd9Sstevel@tonic-gate * Use the basename of the input file (typically this is the
29447c478bd9Sstevel@tonic-gate * compilation environment name, ie. libfoo.so).
29457c478bd9Sstevel@tonic-gate */
29467c478bd9Sstevel@tonic-gate if ((base = strrchr(ifl->ifl_name, '/')) == NULL)
29477c478bd9Sstevel@tonic-gate base = ifl->ifl_name;
29487c478bd9Sstevel@tonic-gate else
29497c478bd9Sstevel@tonic-gate base++;
29507c478bd9Sstevel@tonic-gate
295157ef7aa9SRod Evans if ((sdf = sdf_find(base, ofl->ofl_socntl)) != NULL) {
29527c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
29537c478bd9Sstevel@tonic-gate ifl->ifl_sdfdesc = sdf;
29547c478bd9Sstevel@tonic-gate }
29557c478bd9Sstevel@tonic-gate }
29567c478bd9Sstevel@tonic-gate
29577c478bd9Sstevel@tonic-gate /*
295808278a5eSRod Evans * Before symbol processing, process any capabilities. Capabilities
295908278a5eSRod Evans * can reference a string table, which is why this processing is
296008278a5eSRod Evans * carried out after the initial section processing. Capabilities,
296108278a5eSRod Evans * together with -z symbolcap, can require the conversion of global
296208278a5eSRod Evans * symbols to local symbols.
29637c478bd9Sstevel@tonic-gate */
296408278a5eSRod Evans if (capisp && (process_cap(ofl, ifl, capisp) == S_ERROR))
296508278a5eSRod Evans return (S_ERROR);
29667c478bd9Sstevel@tonic-gate
29677c478bd9Sstevel@tonic-gate /*
29687c478bd9Sstevel@tonic-gate * Process any version dependencies. These will establish shared object
29697c478bd9Sstevel@tonic-gate * `needed' entries in the same manner as will be generated from the
29707c478bd9Sstevel@tonic-gate * .dynamic's NEEDED entries.
29717c478bd9Sstevel@tonic-gate */
29721007fd6fSAli Bahrami if (vndisp && ((ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)) ||
29731007fd6fSAli Bahrami OFL_GUIDANCE(ofl, FLG_OFG_NO_DEFS)))
29745aefb655Srie if (ld_vers_need_process(vndisp, ifl, ofl) == S_ERROR)
29757c478bd9Sstevel@tonic-gate return (S_ERROR);
29767c478bd9Sstevel@tonic-gate
29777c478bd9Sstevel@tonic-gate /*
29787c478bd9Sstevel@tonic-gate * Before processing any symbol resolution or relocations process any
29797c478bd9Sstevel@tonic-gate * version sections.
29807c478bd9Sstevel@tonic-gate */
29817c478bd9Sstevel@tonic-gate if (vsyisp)
29821007fd6fSAli Bahrami (void) ld_vers_sym_process(ofl, vsyisp, ifl);
29837c478bd9Sstevel@tonic-gate
29847c478bd9Sstevel@tonic-gate if (ifl->ifl_versym &&
29857c478bd9Sstevel@tonic-gate (vdfisp || (sdf && (sdf->sdf_flags & FLG_SDF_SELECT))))
29865aefb655Srie if (ld_vers_def_process(vdfisp, ifl, ofl) == S_ERROR)
29877c478bd9Sstevel@tonic-gate return (S_ERROR);
29887c478bd9Sstevel@tonic-gate
29897c478bd9Sstevel@tonic-gate /*
29907c478bd9Sstevel@tonic-gate * Having collected the appropriate sections carry out any additional
29917c478bd9Sstevel@tonic-gate * processing if necessary.
29927c478bd9Sstevel@tonic-gate */
29937c478bd9Sstevel@tonic-gate for (ndx = 0; ndx < ifl->ifl_shnum; ndx++) {
29940e233487SRod Evans Is_desc *isp;
29957c478bd9Sstevel@tonic-gate
2996635216b6SRod Evans if ((isp = ifl->ifl_isdesc[ndx]) == NULL)
29977c478bd9Sstevel@tonic-gate continue;
29987c478bd9Sstevel@tonic-gate row = isp->is_shdr->sh_type;
29997c478bd9Sstevel@tonic-gate
30007c478bd9Sstevel@tonic-gate if ((isp->is_flags & FLG_IS_DISCARD) == 0)
30015aefb655Srie ld_sup_section(ofl, isp->is_name, isp->is_shdr, ndx,
30025aefb655Srie isp->is_indata, elf);
30037c478bd9Sstevel@tonic-gate
30047c478bd9Sstevel@tonic-gate /*
300557ef7aa9SRod Evans * If this is a SHT_SUNW_move section from a relocatable file,
300657ef7aa9SRod Evans * keep track of the section for later processing.
30077c478bd9Sstevel@tonic-gate */
30087c478bd9Sstevel@tonic-gate if ((row == SHT_SUNW_move) && (column == 0)) {
300957ef7aa9SRod Evans if (aplist_append(&(ofl->ofl_ismove), isp,
301057ef7aa9SRod Evans AL_CNT_OFL_MOVE) == NULL)
30117c478bd9Sstevel@tonic-gate return (S_ERROR);
30127c478bd9Sstevel@tonic-gate }
30137c478bd9Sstevel@tonic-gate
30147c478bd9Sstevel@tonic-gate /*
30157c478bd9Sstevel@tonic-gate * If this is a standard section type process it via the
30167c478bd9Sstevel@tonic-gate * appropriate action routine.
30177c478bd9Sstevel@tonic-gate */
30187c478bd9Sstevel@tonic-gate if (row < SHT_NUM) {
30190e233487SRod Evans if (Final[row][column] != NULL) {
30200e233487SRod Evans if (Final[row][column](isp, ifl,
30210e233487SRod Evans ofl) == S_ERROR)
30227c478bd9Sstevel@tonic-gate return (S_ERROR);
30230e233487SRod Evans }
30240e233487SRod Evans #if defined(_ELF64)
30250e233487SRod Evans } else if ((row == SHT_AMD64_UNWIND) && (column == 0)) {
30260e233487SRod Evans Os_desc *osp = isp->is_osdesc;
30270e233487SRod Evans
30280e233487SRod Evans /*
30290e233487SRod Evans * SHT_AMD64_UNWIND (0x70000001) is in the SHT_LOPROC -
30300e233487SRod Evans * SHT_HIPROC range reserved for processor-specific
30310e233487SRod Evans * semantics, and is only meaningful for amd64 targets.
30320e233487SRod Evans *
30330e233487SRod Evans * Only process unwind contents from relocatable
30340e233487SRod Evans * objects.
30350e233487SRod Evans */
30360e233487SRod Evans if (osp && (ld_targ.t_m.m_mach == EM_AMD64) &&
30377e16fca0SAli Bahrami (ld_unwind_register(osp, ofl) == S_ERROR))
30380e233487SRod Evans return (S_ERROR);
30390e233487SRod Evans #endif
30407c478bd9Sstevel@tonic-gate }
30417c478bd9Sstevel@tonic-gate }
30427c478bd9Sstevel@tonic-gate
304308278a5eSRod Evans /*
304408278a5eSRod Evans * Following symbol processing, if this relocatable object input file
304508278a5eSRod Evans * provides symbol capabilities, tag the associated symbols so that
304608278a5eSRod Evans * the symbols can be re-assigned to the new capabilities symbol
304708278a5eSRod Evans * section that will be created for the output file.
304808278a5eSRod Evans */
304908278a5eSRod Evans if (capinfoisp && (ifl->ifl_ehdr->e_type == ET_REL) &&
305008278a5eSRod Evans (process_capinfo(ofl, ifl, capinfoisp) == S_ERROR))
305108278a5eSRod Evans return (S_ERROR);
305208278a5eSRod Evans
30537c478bd9Sstevel@tonic-gate /*
30547c478bd9Sstevel@tonic-gate * After processing any symbol resolution, and if this dependency
30557c478bd9Sstevel@tonic-gate * indicates it contains symbols that can't be directly bound to,
30567c478bd9Sstevel@tonic-gate * set the symbols appropriately.
30577c478bd9Sstevel@tonic-gate */
30587c478bd9Sstevel@tonic-gate if (sifisp && ((ifl->ifl_flags & (FLG_IF_NEEDED | FLG_IF_NODIRECT)) ==
30597c478bd9Sstevel@tonic-gate (FLG_IF_NEEDED | FLG_IF_NODIRECT)))
30605aefb655Srie (void) ld_sym_nodirect(sifisp, ifl, ofl);
30617c478bd9Sstevel@tonic-gate
30627c478bd9Sstevel@tonic-gate return (1);
30637c478bd9Sstevel@tonic-gate }
30647c478bd9Sstevel@tonic-gate
30657c478bd9Sstevel@tonic-gate /*
30667c478bd9Sstevel@tonic-gate * Process the current input file. There are basically three types of files
30677c478bd9Sstevel@tonic-gate * that come through here:
30687c478bd9Sstevel@tonic-gate *
3069635216b6SRod Evans * - files explicitly defined on the command line (ie. foo.o or bar.so),
30707c478bd9Sstevel@tonic-gate * in this case only the `name' field is valid.
30717c478bd9Sstevel@tonic-gate *
3072635216b6SRod Evans * - libraries determined from the -l command line option (ie. -lbar),
30737c478bd9Sstevel@tonic-gate * in this case the `soname' field contains the basename of the located
30747c478bd9Sstevel@tonic-gate * file.
30757c478bd9Sstevel@tonic-gate *
30767c478bd9Sstevel@tonic-gate * Any shared object specified via the above two conventions must be recorded
30777c478bd9Sstevel@tonic-gate * as a needed dependency.
30787c478bd9Sstevel@tonic-gate *
3079635216b6SRod Evans * - libraries specified as dependencies of those libraries already obtained
30807c478bd9Sstevel@tonic-gate * via the command line (ie. bar.so has a DT_NEEDED entry of fred.so.1),
30817c478bd9Sstevel@tonic-gate * in this case the `soname' field contains either a full pathname (if the
30827c478bd9Sstevel@tonic-gate * needed entry contained a `/'), or the basename of the located file.
30837c478bd9Sstevel@tonic-gate * These libraries are processed to verify symbol binding but are not
30847c478bd9Sstevel@tonic-gate * recorded as dependencies of the output file being generated.
3085dc0f59e5SAli Bahrami *
3086dc0f59e5SAli Bahrami * entry:
3087dc0f59e5SAli Bahrami * name - File name
3088dc0f59e5SAli Bahrami * soname - SONAME for needed sharable library, as described above
3089dc0f59e5SAli Bahrami * fd - Open file descriptor
3090dc0f59e5SAli Bahrami * elf - Open ELF handle
3091dc0f59e5SAli Bahrami * flags - FLG_IF_ flags applicable to file
3092dc0f59e5SAli Bahrami * ofl - Output file descriptor
3093dc0f59e5SAli Bahrami * rej - Rejection descriptor used to record rejection reason
3094dc0f59e5SAli Bahrami * ifl_ret - NULL, or address of pointer to receive reference to
3095dc0f59e5SAli Bahrami * resulting input descriptor for file. If ifl_ret is non-NULL,
3096dc0f59e5SAli Bahrami * the file cannot be an archive or it will be rejected.
3097dc0f59e5SAli Bahrami *
3098dc0f59e5SAli Bahrami * exit:
3099dc0f59e5SAli Bahrami * If a error occurs in examining the file, S_ERROR is returned.
3100dc0f59e5SAli Bahrami * If the file can be examined, but is not suitable, *rej is updated,
3101dc0f59e5SAli Bahrami * and 0 is returned. If the file is acceptable, 1 is returned, and if
3102dc0f59e5SAli Bahrami * ifl_ret is non-NULL, *ifl_ret is set to contain the pointer to the
3103dc0f59e5SAli Bahrami * resulting input descriptor.
31047c478bd9Sstevel@tonic-gate */
3105dc0f59e5SAli Bahrami uintptr_t
ld_process_ifl(const char * name,const char * soname,int fd,Elf * elf,Word flags,Ofl_desc * ofl,Rej_desc * rej,Ifl_desc ** ifl_ret)31065aefb655Srie ld_process_ifl(const char *name, const char *soname, int fd, Elf *elf,
3107dc0f59e5SAli Bahrami Word flags, Ofl_desc *ofl, Rej_desc *rej, Ifl_desc **ifl_ret)
31087c478bd9Sstevel@tonic-gate {
31097c478bd9Sstevel@tonic-gate Ifl_desc *ifl;
31107c478bd9Sstevel@tonic-gate Ehdr *ehdr;
31117c478bd9Sstevel@tonic-gate uintptr_t error = 0;
31127c478bd9Sstevel@tonic-gate struct stat status;
31137c478bd9Sstevel@tonic-gate Ar_desc *adp;
31147c478bd9Sstevel@tonic-gate Rej_desc _rej;
31157c478bd9Sstevel@tonic-gate
31167c478bd9Sstevel@tonic-gate /*
31177c478bd9Sstevel@tonic-gate * If this file was not extracted from an archive obtain its device
31187c478bd9Sstevel@tonic-gate * information. This will be used to determine if the file has already
31197c478bd9Sstevel@tonic-gate * been processed (rather than simply comparing filenames, the device
31207c478bd9Sstevel@tonic-gate * information provides a quicker comparison and detects linked files).
31217c478bd9Sstevel@tonic-gate */
312256deab07SRod Evans if (fd && ((flags & FLG_IF_EXTRACT) == 0))
31237c478bd9Sstevel@tonic-gate (void) fstat(fd, &status);
31247c478bd9Sstevel@tonic-gate else {
31257c478bd9Sstevel@tonic-gate status.st_dev = 0;
31267c478bd9Sstevel@tonic-gate status.st_ino = 0;
31277c478bd9Sstevel@tonic-gate }
31287c478bd9Sstevel@tonic-gate
31297c478bd9Sstevel@tonic-gate switch (elf_kind(elf)) {
31307c478bd9Sstevel@tonic-gate case ELF_K_AR:
3131dc0f59e5SAli Bahrami /*
3132dc0f59e5SAli Bahrami * If the caller has supplied a non-NULL ifl_ret, then
3133dc0f59e5SAli Bahrami * we cannot process archives, for there will be no
3134dc0f59e5SAli Bahrami * input file descriptor for us to return. In this case,
3135dc0f59e5SAli Bahrami * reject the attempt.
3136dc0f59e5SAli Bahrami */
3137dc0f59e5SAli Bahrami if (ifl_ret != NULL) {
3138dc0f59e5SAli Bahrami _rej.rej_type = SGS_REJ_ARCHIVE;
3139dc0f59e5SAli Bahrami _rej.rej_name = name;
3140dc0f59e5SAli Bahrami DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3141dc0f59e5SAli Bahrami ld_targ.t_m.m_mach));
3142dc0f59e5SAli Bahrami if (rej->rej_type == 0) {
3143dc0f59e5SAli Bahrami *rej = _rej;
3144dc0f59e5SAli Bahrami rej->rej_name = strdup(_rej.rej_name);
3145dc0f59e5SAli Bahrami }
3146dc0f59e5SAli Bahrami return (0);
3147dc0f59e5SAli Bahrami }
3148dc0f59e5SAli Bahrami
31497c478bd9Sstevel@tonic-gate /*
31507c478bd9Sstevel@tonic-gate * Determine if we've already come across this archive file.
31517c478bd9Sstevel@tonic-gate */
31527c478bd9Sstevel@tonic-gate if (!(flags & FLG_IF_EXTRACT)) {
315357ef7aa9SRod Evans Aliste idx;
315457ef7aa9SRod Evans
315557ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_ars, idx, adp)) {
31567c478bd9Sstevel@tonic-gate if ((adp->ad_stdev != status.st_dev) ||
31577c478bd9Sstevel@tonic-gate (adp->ad_stino != status.st_ino))
31587c478bd9Sstevel@tonic-gate continue;
31597c478bd9Sstevel@tonic-gate
31607c478bd9Sstevel@tonic-gate /*
31617c478bd9Sstevel@tonic-gate * We've seen this file before so reuse the
31627c478bd9Sstevel@tonic-gate * original archive descriptor and discard the
3163a6d4d7d5SRod Evans * new elf descriptor. Note that a file
3164a6d4d7d5SRod Evans * descriptor is unnecessary, as the file is
3165a6d4d7d5SRod Evans * already available in memory.
31667c478bd9Sstevel@tonic-gate */
31675aefb655Srie DBG_CALL(Dbg_file_reuse(ofl->ofl_lml, name,
31685aefb655Srie adp->ad_name));
31697c478bd9Sstevel@tonic-gate (void) elf_end(elf);
3170dc0f59e5SAli Bahrami if (!ld_process_archive(name, -1, adp, ofl))
3171dc0f59e5SAli Bahrami return (S_ERROR);
3172dc0f59e5SAli Bahrami return (1);
31737c478bd9Sstevel@tonic-gate }
31747c478bd9Sstevel@tonic-gate }
31757c478bd9Sstevel@tonic-gate
31767c478bd9Sstevel@tonic-gate /*
31777c478bd9Sstevel@tonic-gate * As we haven't processed this file before establish a new
31787c478bd9Sstevel@tonic-gate * archive descriptor.
31797c478bd9Sstevel@tonic-gate */
31805aefb655Srie adp = ld_ar_setup(name, elf, ofl);
3181635216b6SRod Evans if ((adp == NULL) || (adp == (Ar_desc *)S_ERROR))
3182dc0f59e5SAli Bahrami return ((uintptr_t)adp);
31837c478bd9Sstevel@tonic-gate adp->ad_stdev = status.st_dev;
31847c478bd9Sstevel@tonic-gate adp->ad_stino = status.st_ino;
31857c478bd9Sstevel@tonic-gate
31865aefb655Srie ld_sup_file(ofl, name, ELF_K_AR, flags, elf);
31877c478bd9Sstevel@tonic-gate
3188a6d4d7d5SRod Evans /*
3189a6d4d7d5SRod Evans * Indicate that the ELF descriptor no longer requires a file
3190a6d4d7d5SRod Evans * descriptor by reading the entire file. The file is already
3191a6d4d7d5SRod Evans * read via the initial mmap(2) behind elf_begin(3elf), thus
3192a6d4d7d5SRod Evans * this operation is effectively a no-op. However, a side-
3193a6d4d7d5SRod Evans * effect is that the internal file descriptor, maintained in
3194a6d4d7d5SRod Evans * the ELF descriptor, is set to -1. This setting will not
3195a6d4d7d5SRod Evans * be compared with any file descriptor that is passed to
3196a6d4d7d5SRod Evans * elf_begin(), should this archive, or one of the archive
3197a6d4d7d5SRod Evans * members, be processed again from the command line or
3198a6d4d7d5SRod Evans * because of a -z rescan.
3199a6d4d7d5SRod Evans */
3200a6d4d7d5SRod Evans if (elf_cntl(elf, ELF_C_FDREAD) == -1) {
32011007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_CNTL),
3202a6d4d7d5SRod Evans name);
3203dc0f59e5SAli Bahrami return (0);
3204a6d4d7d5SRod Evans }
3205a6d4d7d5SRod Evans
3206dc0f59e5SAli Bahrami if (!ld_process_archive(name, -1, adp, ofl))
3207dc0f59e5SAli Bahrami return (S_ERROR);
3208dc0f59e5SAli Bahrami return (1);
32097c478bd9Sstevel@tonic-gate
32107c478bd9Sstevel@tonic-gate case ELF_K_ELF:
32117c478bd9Sstevel@tonic-gate /*
32127c478bd9Sstevel@tonic-gate * Obtain the elf header so that we can determine what type of
32137c478bd9Sstevel@tonic-gate * elf ELF_K_ELF file this is.
32147c478bd9Sstevel@tonic-gate */
32157c478bd9Sstevel@tonic-gate if ((ehdr = elf_getehdr(elf)) == NULL) {
32167c478bd9Sstevel@tonic-gate int _class = gelf_getclass(elf);
32177c478bd9Sstevel@tonic-gate
32187c478bd9Sstevel@tonic-gate /*
3219dc0f59e5SAli Bahrami * This can fail for a number of reasons. Typically
3220dc0f59e5SAli Bahrami * the object class is incorrect (ie. user is building
3221dc0f59e5SAli Bahrami * 64-bit but managed to point at 32-bit libraries).
3222dc0f59e5SAli Bahrami * Other ELF errors can include a truncated or corrupt
3223dc0f59e5SAli Bahrami * file. Try to get the best error message possible.
32247c478bd9Sstevel@tonic-gate */
3225ba2be530Sab if (ld_targ.t_m.m_class != _class) {
32267c478bd9Sstevel@tonic-gate _rej.rej_type = SGS_REJ_CLASS;
32277c478bd9Sstevel@tonic-gate _rej.rej_info = (uint_t)_class;
32287c478bd9Sstevel@tonic-gate } else {
32297c478bd9Sstevel@tonic-gate _rej.rej_type = SGS_REJ_STR;
32307c478bd9Sstevel@tonic-gate _rej.rej_str = elf_errmsg(-1);
32317c478bd9Sstevel@tonic-gate }
32327c478bd9Sstevel@tonic-gate _rej.rej_name = name;
3233ba2be530Sab DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3234ba2be530Sab ld_targ.t_m.m_mach));
32357c478bd9Sstevel@tonic-gate if (rej->rej_type == 0) {
32367c478bd9Sstevel@tonic-gate *rej = _rej;
32377c478bd9Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name);
32387c478bd9Sstevel@tonic-gate }
3239dc0f59e5SAli Bahrami return (0);
32407c478bd9Sstevel@tonic-gate }
32417c478bd9Sstevel@tonic-gate
3242b6a0e2cdSRichard Lowe if (_gelf_getdynval(elf, DT_SUNW_KMOD) > 0) {
3243b6a0e2cdSRichard Lowe _rej.rej_name = name;
3244b6a0e2cdSRichard Lowe DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3245b6a0e2cdSRichard Lowe ld_targ.t_m.m_mach));
3246b6a0e2cdSRichard Lowe _rej.rej_type = SGS_REJ_KMOD;
3247b6a0e2cdSRichard Lowe _rej.rej_str = elf_errmsg(-1);
3248b6a0e2cdSRichard Lowe _rej.rej_name = name;
3249b6a0e2cdSRichard Lowe
3250b6a0e2cdSRichard Lowe if (rej->rej_type == 0) {
3251b6a0e2cdSRichard Lowe *rej = _rej;
3252b6a0e2cdSRichard Lowe rej->rej_name = strdup(_rej.rej_name);
3253b6a0e2cdSRichard Lowe }
3254b6a0e2cdSRichard Lowe return (0);
3255b6a0e2cdSRichard Lowe }
3256b6a0e2cdSRichard Lowe
32577c478bd9Sstevel@tonic-gate /*
32587c478bd9Sstevel@tonic-gate * Determine if we've already come across this file.
32597c478bd9Sstevel@tonic-gate */
32607c478bd9Sstevel@tonic-gate if (!(flags & FLG_IF_EXTRACT)) {
326157ef7aa9SRod Evans APlist *apl;
326257ef7aa9SRod Evans Aliste idx;
32637c478bd9Sstevel@tonic-gate
32647c478bd9Sstevel@tonic-gate if (ehdr->e_type == ET_REL)
326557ef7aa9SRod Evans apl = ofl->ofl_objs;
32667c478bd9Sstevel@tonic-gate else
326757ef7aa9SRod Evans apl = ofl->ofl_sos;
32687c478bd9Sstevel@tonic-gate
32697c478bd9Sstevel@tonic-gate /*
32707c478bd9Sstevel@tonic-gate * Traverse the appropriate file list and determine if
32717c478bd9Sstevel@tonic-gate * a dev/inode match is found.
32727c478bd9Sstevel@tonic-gate */
327357ef7aa9SRod Evans for (APLIST_TRAVERSE(apl, idx, ifl)) {
32747c478bd9Sstevel@tonic-gate /*
32757c478bd9Sstevel@tonic-gate * Ifl_desc generated via -Nneed, therefore no
32767c478bd9Sstevel@tonic-gate * actual file behind it.
32777c478bd9Sstevel@tonic-gate */
32787c478bd9Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_NEEDSTR)
32797c478bd9Sstevel@tonic-gate continue;
32807c478bd9Sstevel@tonic-gate
32817c478bd9Sstevel@tonic-gate if ((ifl->ifl_stino != status.st_ino) ||
32827c478bd9Sstevel@tonic-gate (ifl->ifl_stdev != status.st_dev))
32837c478bd9Sstevel@tonic-gate continue;
32847c478bd9Sstevel@tonic-gate
32857c478bd9Sstevel@tonic-gate /*
32867c478bd9Sstevel@tonic-gate * Disregard (skip) this image.
32877c478bd9Sstevel@tonic-gate */
32885aefb655Srie DBG_CALL(Dbg_file_skip(ofl->ofl_lml,
32895aefb655Srie ifl->ifl_name, name));
32907c478bd9Sstevel@tonic-gate (void) elf_end(elf);
32917c478bd9Sstevel@tonic-gate
32927c478bd9Sstevel@tonic-gate /*
32937c478bd9Sstevel@tonic-gate * If the file was explicitly defined on the
32947c478bd9Sstevel@tonic-gate * command line (this is always the case for
32957c478bd9Sstevel@tonic-gate * relocatable objects, and is true for shared
32967c478bd9Sstevel@tonic-gate * objects when they weren't specified via -l or
32977c478bd9Sstevel@tonic-gate * were dragged in as an implicit dependency),
32987c478bd9Sstevel@tonic-gate * then warn the user.
32997c478bd9Sstevel@tonic-gate */
33007c478bd9Sstevel@tonic-gate if ((flags & FLG_IF_CMDLINE) ||
33017c478bd9Sstevel@tonic-gate (ifl->ifl_flags & FLG_IF_CMDLINE)) {
33027c478bd9Sstevel@tonic-gate const char *errmsg;
33037c478bd9Sstevel@tonic-gate
33047c478bd9Sstevel@tonic-gate /*
33057c478bd9Sstevel@tonic-gate * Determine whether this is the same
33067c478bd9Sstevel@tonic-gate * file name as originally encountered
33077c478bd9Sstevel@tonic-gate * so as to provide the most
33087c478bd9Sstevel@tonic-gate * descriptive diagnostic.
33097c478bd9Sstevel@tonic-gate */
3310de777a60Sab errmsg =
3311de777a60Sab (strcmp(name, ifl->ifl_name) == 0) ?
3312de777a60Sab MSG_INTL(MSG_FIL_MULINC_1) :
3313de777a60Sab MSG_INTL(MSG_FIL_MULINC_2);
33141007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
33155aefb655Srie errmsg, name, ifl->ifl_name);
33167c478bd9Sstevel@tonic-gate }
3317dc0f59e5SAli Bahrami if (ifl_ret)
3318dc0f59e5SAli Bahrami *ifl_ret = ifl;
3319dc0f59e5SAli Bahrami return (1);
33207c478bd9Sstevel@tonic-gate }
33217c478bd9Sstevel@tonic-gate }
33227c478bd9Sstevel@tonic-gate
33237c478bd9Sstevel@tonic-gate /*
33247c478bd9Sstevel@tonic-gate * At this point, we know we need the file. Establish an input
33257c478bd9Sstevel@tonic-gate * file descriptor and continue processing.
33267c478bd9Sstevel@tonic-gate */
33277c478bd9Sstevel@tonic-gate ifl = ifl_setup(name, ehdr, elf, flags, ofl, rej);
3328635216b6SRod Evans if ((ifl == NULL) || (ifl == (Ifl_desc *)S_ERROR))
3329dc0f59e5SAli Bahrami return ((uintptr_t)ifl);
33307c478bd9Sstevel@tonic-gate ifl->ifl_stdev = status.st_dev;
33317c478bd9Sstevel@tonic-gate ifl->ifl_stino = status.st_ino;
33327c478bd9Sstevel@tonic-gate
33337c478bd9Sstevel@tonic-gate /*
33347c478bd9Sstevel@tonic-gate * If -zignore is in effect, mark this file as a potential
33357c478bd9Sstevel@tonic-gate * candidate (the files use isn't actually determined until
33367c478bd9Sstevel@tonic-gate * symbol resolution and relocation processing are completed).
33377c478bd9Sstevel@tonic-gate */
33387c478bd9Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_IGNORE)
33397c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_IGNORE;
33407c478bd9Sstevel@tonic-gate
33417c478bd9Sstevel@tonic-gate switch (ehdr->e_type) {
33427c478bd9Sstevel@tonic-gate case ET_REL:
3343ba2be530Sab (*ld_targ.t_mr.mr_mach_eflags)(ehdr, ofl);
33447c478bd9Sstevel@tonic-gate error = process_elf(ifl, elf, ofl);
33457c478bd9Sstevel@tonic-gate break;
33467c478bd9Sstevel@tonic-gate case ET_DYN:
33477c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STATIC) ||
33487c478bd9Sstevel@tonic-gate !(ofl->ofl_flags & FLG_OF_DYNLIBS)) {
33491007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
33505aefb655Srie MSG_INTL(MSG_FIL_SOINSTAT), name);
3351dc0f59e5SAli Bahrami return (0);
33527c478bd9Sstevel@tonic-gate }
33537c478bd9Sstevel@tonic-gate
33547c478bd9Sstevel@tonic-gate /*
33557c478bd9Sstevel@tonic-gate * Record any additional shared object information.
33567c478bd9Sstevel@tonic-gate * If no soname is specified (eg. this file was
33577c478bd9Sstevel@tonic-gate * derived from a explicit filename declaration on the
33587c478bd9Sstevel@tonic-gate * command line, ie. bar.so) use the pathname.
33597c478bd9Sstevel@tonic-gate * This entry may be overridden if the files dynamic
33607c478bd9Sstevel@tonic-gate * section specifies an DT_SONAME value.
33617c478bd9Sstevel@tonic-gate */
33627c478bd9Sstevel@tonic-gate if (soname == NULL)
33637c478bd9Sstevel@tonic-gate ifl->ifl_soname = ifl->ifl_name;
33647c478bd9Sstevel@tonic-gate else
33657c478bd9Sstevel@tonic-gate ifl->ifl_soname = soname;
33667c478bd9Sstevel@tonic-gate
33677c478bd9Sstevel@tonic-gate /*
3368f441771bSRod Evans * If direct bindings, lazy loading, group permissions,
3369f441771bSRod Evans * or deferred dependencies need to be established, mark
3370f441771bSRod Evans * this object.
33717c478bd9Sstevel@tonic-gate */
33727c478bd9Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_ZDIRECT)
33737c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DIRECT;
33747c478bd9Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_LAZYLD)
33757c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_LAZYLD;
33767c478bd9Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_GRPPRM)
33777c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_GRPPRM;
3378f441771bSRod Evans if (ofl->ofl_flags1 & FLG_OF1_DEFERRED)
3379f441771bSRod Evans ifl->ifl_flags |=
3380f441771bSRod Evans (FLG_IF_LAZYLD | FLG_IF_DEFERRED);
3381f441771bSRod Evans
33827c478bd9Sstevel@tonic-gate error = process_elf(ifl, elf, ofl);
33837c478bd9Sstevel@tonic-gate
33847c478bd9Sstevel@tonic-gate /*
3385f441771bSRod Evans * Determine whether this dependency requires a syminfo.
33867c478bd9Sstevel@tonic-gate */
3387f441771bSRod Evans if (ifl->ifl_flags & MSK_IF_SYMINFO)
33887c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_SYMINFO;
33897c478bd9Sstevel@tonic-gate
33901007fd6fSAli Bahrami /*
33911007fd6fSAli Bahrami * Guidance: Use -z lazyload/nolazyload.
33921007fd6fSAli Bahrami * libc is exempt from this advice, because it cannot
33931007fd6fSAli Bahrami * be lazy loaded, and requests to do so are ignored.
33941007fd6fSAli Bahrami */
33951007fd6fSAli Bahrami if (OFL_GUIDANCE(ofl, FLG_OFG_NO_LAZY) &&
33961007fd6fSAli Bahrami ((ifl->ifl_flags & FLG_IF_RTLDINF) == 0)) {
33971007fd6fSAli Bahrami ld_eprintf(ofl, ERR_GUIDANCE,
33981007fd6fSAli Bahrami MSG_INTL(MSG_GUIDE_LAZYLOAD));
33991007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_LAZY;
34001007fd6fSAli Bahrami }
34011007fd6fSAli Bahrami
34021007fd6fSAli Bahrami /*
34031007fd6fSAli Bahrami * Guidance: Use -B direct/nodirect or
34041007fd6fSAli Bahrami * -z direct/nodirect.
34051007fd6fSAli Bahrami */
34061007fd6fSAli Bahrami if (OFL_GUIDANCE(ofl, FLG_OFG_NO_DB)) {
34071007fd6fSAli Bahrami ld_eprintf(ofl, ERR_GUIDANCE,
34081007fd6fSAli Bahrami MSG_INTL(MSG_GUIDE_DIRECT));
34091007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_DB;
34101007fd6fSAli Bahrami }
34111007fd6fSAli Bahrami
34127c478bd9Sstevel@tonic-gate break;
34137c478bd9Sstevel@tonic-gate default:
34147c478bd9Sstevel@tonic-gate (void) elf_errno();
34157c478bd9Sstevel@tonic-gate _rej.rej_type = SGS_REJ_UNKFILE;
34167c478bd9Sstevel@tonic-gate _rej.rej_name = name;
3417ba2be530Sab DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3418ba2be530Sab ld_targ.t_m.m_mach));
34197c478bd9Sstevel@tonic-gate if (rej->rej_type == 0) {
34207c478bd9Sstevel@tonic-gate *rej = _rej;
34217c478bd9Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name);
34227c478bd9Sstevel@tonic-gate }
3423dc0f59e5SAli Bahrami return (0);
34247c478bd9Sstevel@tonic-gate }
34257c478bd9Sstevel@tonic-gate break;
34267c478bd9Sstevel@tonic-gate default:
34277c478bd9Sstevel@tonic-gate (void) elf_errno();
34287c478bd9Sstevel@tonic-gate _rej.rej_type = SGS_REJ_UNKFILE;
34297c478bd9Sstevel@tonic-gate _rej.rej_name = name;
3430ba2be530Sab DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3431ba2be530Sab ld_targ.t_m.m_mach));
34327c478bd9Sstevel@tonic-gate if (rej->rej_type == 0) {
34337c478bd9Sstevel@tonic-gate *rej = _rej;
34347c478bd9Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name);
34357c478bd9Sstevel@tonic-gate }
3436dc0f59e5SAli Bahrami return (0);
34377c478bd9Sstevel@tonic-gate }
34387c478bd9Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR))
3439dc0f59e5SAli Bahrami return (error);
3440dc0f59e5SAli Bahrami
3441dc0f59e5SAli Bahrami if (ifl_ret)
3442dc0f59e5SAli Bahrami *ifl_ret = ifl;
3443dc0f59e5SAli Bahrami return (1);
34447c478bd9Sstevel@tonic-gate }
34457c478bd9Sstevel@tonic-gate
34467c478bd9Sstevel@tonic-gate /*
34477c478bd9Sstevel@tonic-gate * Having successfully opened a file, set up the necessary elf structures to
34487c478bd9Sstevel@tonic-gate * process it further. This small section of processing is slightly different
34497c478bd9Sstevel@tonic-gate * from the elf initialization required to process a relocatable object from an
34502926dd2eSrie * archive (see libs.c: ld_process_archive()).
34517c478bd9Sstevel@tonic-gate */
3452dc0f59e5SAli Bahrami uintptr_t
ld_process_open(const char * opath,const char * ofile,int * fd,Ofl_desc * ofl,Word flags,Rej_desc * rej,Ifl_desc ** ifl_ret)34533906e0c2Srie ld_process_open(const char *opath, const char *ofile, int *fd, Ofl_desc *ofl,
3454dc0f59e5SAli Bahrami Word flags, Rej_desc *rej, Ifl_desc **ifl_ret)
34557c478bd9Sstevel@tonic-gate {
34563906e0c2Srie Elf *elf;
34573906e0c2Srie const char *npath = opath;
34583906e0c2Srie const char *nfile = ofile;
34597c478bd9Sstevel@tonic-gate
34603906e0c2Srie if ((elf = elf_begin(*fd, ELF_C_READ, NULL)) == NULL) {
34611007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_BEGIN), npath);
3462dc0f59e5SAli Bahrami return (0);
34637c478bd9Sstevel@tonic-gate }
34647c478bd9Sstevel@tonic-gate
34653906e0c2Srie /*
34663906e0c2Srie * Determine whether the support library wishes to process this open.
34673906e0c2Srie * The support library may return:
34683906e0c2Srie * . a different ELF descriptor (in which case they should have
34693906e0c2Srie * closed the original)
34703906e0c2Srie * . a different file descriptor (in which case they should have
34713906e0c2Srie * closed the original)
34723906e0c2Srie * . a different path and file name (presumably associated with
34733906e0c2Srie * a different file descriptor)
34743906e0c2Srie *
34753906e0c2Srie * A file descriptor of -1, or and ELF descriptor of zero indicates
34763906e0c2Srie * the file should be ignored.
34773906e0c2Srie */
34783906e0c2Srie ld_sup_open(ofl, &npath, &nfile, fd, flags, &elf, NULL, 0,
34793906e0c2Srie elf_kind(elf));
34803906e0c2Srie
34813906e0c2Srie if ((*fd == -1) || (elf == NULL))
3482dc0f59e5SAli Bahrami return (0);
34833906e0c2Srie
3484dc0f59e5SAli Bahrami return (ld_process_ifl(npath, nfile, *fd, elf, flags, ofl, rej,
3485dc0f59e5SAli Bahrami ifl_ret));
34867c478bd9Sstevel@tonic-gate }
34877c478bd9Sstevel@tonic-gate
348856deab07SRod Evans /*
348956deab07SRod Evans * Having successfully mapped a file, set up the necessary elf structures to
349056deab07SRod Evans * process it further. This routine is patterned after ld_process_open() and
349156deab07SRod Evans * is only called by ld.so.1(1) to process a relocatable object.
349256deab07SRod Evans */
349356deab07SRod Evans Ifl_desc *
ld_process_mem(const char * path,const char * file,char * addr,size_t size,Ofl_desc * ofl,Rej_desc * rej)349456deab07SRod Evans ld_process_mem(const char *path, const char *file, char *addr, size_t size,
349556deab07SRod Evans Ofl_desc *ofl, Rej_desc *rej)
349656deab07SRod Evans {
3497dc0f59e5SAli Bahrami Elf *elf;
3498dc0f59e5SAli Bahrami uintptr_t open_ret;
3499dc0f59e5SAli Bahrami Ifl_desc *ifl;
350056deab07SRod Evans
350156deab07SRod Evans if ((elf = elf_memory(addr, size)) == NULL) {
35021007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_MEMORY), path);
350356deab07SRod Evans return (0);
350456deab07SRod Evans }
350556deab07SRod Evans
3506dc0f59e5SAli Bahrami open_ret = ld_process_ifl(path, file, 0, elf, 0, ofl, rej, &ifl);
3507dc0f59e5SAli Bahrami if (open_ret != 1)
3508dc0f59e5SAli Bahrami return ((Ifl_desc *) open_ret);
3509dc0f59e5SAli Bahrami return (ifl);
351056deab07SRod Evans }
351156deab07SRod Evans
35127c478bd9Sstevel@tonic-gate /*
35137c478bd9Sstevel@tonic-gate * Process a required library (i.e. the dependency of a shared object).
35147c478bd9Sstevel@tonic-gate * Combine the directory and filename, check the resultant path size, and try
35157c478bd9Sstevel@tonic-gate * opening the pathname.
35167c478bd9Sstevel@tonic-gate */
35175aefb655Srie static Ifl_desc *
process_req_lib(Sdf_desc * sdf,const char * dir,const char * file,Ofl_desc * ofl,Rej_desc * rej)35187c478bd9Sstevel@tonic-gate process_req_lib(Sdf_desc *sdf, const char *dir, const char *file,
35190e233487SRod Evans Ofl_desc *ofl, Rej_desc *rej)
35207c478bd9Sstevel@tonic-gate {
35217c478bd9Sstevel@tonic-gate size_t dlen, plen;
35227c478bd9Sstevel@tonic-gate int fd;
35237c478bd9Sstevel@tonic-gate char path[PATH_MAX];
35247c478bd9Sstevel@tonic-gate const char *_dir = dir;
35257c478bd9Sstevel@tonic-gate
35267c478bd9Sstevel@tonic-gate /*
35277c478bd9Sstevel@tonic-gate * Determine the sizes of the directory and filename to insure we don't
35287c478bd9Sstevel@tonic-gate * exceed our buffer.
35297c478bd9Sstevel@tonic-gate */
35307c478bd9Sstevel@tonic-gate if ((dlen = strlen(dir)) == 0) {
35317c478bd9Sstevel@tonic-gate _dir = MSG_ORIG(MSG_STR_DOT);
35327c478bd9Sstevel@tonic-gate dlen = 1;
35337c478bd9Sstevel@tonic-gate }
35347c478bd9Sstevel@tonic-gate dlen++;
35357c478bd9Sstevel@tonic-gate plen = dlen + strlen(file) + 1;
35367c478bd9Sstevel@tonic-gate if (plen > PATH_MAX) {
35371007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_PTHTOLONG),
35385aefb655Srie _dir, file);
35397c478bd9Sstevel@tonic-gate return (0);
35407c478bd9Sstevel@tonic-gate }
35417c478bd9Sstevel@tonic-gate
35427c478bd9Sstevel@tonic-gate /*
35437c478bd9Sstevel@tonic-gate * Build the entire pathname and try and open the file.
35447c478bd9Sstevel@tonic-gate */
35457c478bd9Sstevel@tonic-gate (void) strcpy(path, _dir);
35467c478bd9Sstevel@tonic-gate (void) strcat(path, MSG_ORIG(MSG_STR_SLASH));
35477c478bd9Sstevel@tonic-gate (void) strcat(path, file);
35485aefb655Srie DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name,
35495aefb655Srie sdf->sdf_rfile, path));
35507c478bd9Sstevel@tonic-gate
35517c478bd9Sstevel@tonic-gate if ((fd = open(path, O_RDONLY)) == -1)
35527c478bd9Sstevel@tonic-gate return (0);
35537c478bd9Sstevel@tonic-gate else {
3554dc0f59e5SAli Bahrami uintptr_t open_ret;
35557c478bd9Sstevel@tonic-gate Ifl_desc *ifl;
35567c478bd9Sstevel@tonic-gate char *_path;
35577c478bd9Sstevel@tonic-gate
3558635216b6SRod Evans if ((_path = libld_malloc(strlen(path) + 1)) == NULL)
35597c478bd9Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR);
35607c478bd9Sstevel@tonic-gate (void) strcpy(_path, path);
3561dc0f59e5SAli Bahrami open_ret = ld_process_open(_path, &_path[dlen], &fd, ofl,
3562dc0f59e5SAli Bahrami 0, rej, &ifl);
35633906e0c2Srie if (fd != -1)
35643906e0c2Srie (void) close(fd);
3565dc0f59e5SAli Bahrami if (open_ret != 1)
3566dc0f59e5SAli Bahrami return ((Ifl_desc *)open_ret);
35677c478bd9Sstevel@tonic-gate return (ifl);
35687c478bd9Sstevel@tonic-gate }
35697c478bd9Sstevel@tonic-gate }
35707c478bd9Sstevel@tonic-gate
35717c478bd9Sstevel@tonic-gate /*
35727c478bd9Sstevel@tonic-gate * Finish any library processing. Walk the list of so's that have been listed
35737c478bd9Sstevel@tonic-gate * as "included" by shared objects we have previously processed. Examine them,
35747c478bd9Sstevel@tonic-gate * without adding them as explicit dependents of this program, in order to
35757c478bd9Sstevel@tonic-gate * complete our symbol definition process. The search path rules are:
35767c478bd9Sstevel@tonic-gate *
3577635216b6SRod Evans * - use any user supplied paths, i.e. LD_LIBRARY_PATH and -L, then
35787c478bd9Sstevel@tonic-gate *
3579635216b6SRod Evans * - use any RPATH defined within the parent shared object, then
35807c478bd9Sstevel@tonic-gate *
3581635216b6SRod Evans * - use the default directories, i.e. LIBPATH or -YP.
35827c478bd9Sstevel@tonic-gate */
35837c478bd9Sstevel@tonic-gate uintptr_t
ld_finish_libs(Ofl_desc * ofl)35845aefb655Srie ld_finish_libs(Ofl_desc *ofl)
35857c478bd9Sstevel@tonic-gate {
358657ef7aa9SRod Evans Aliste idx1;
35877c478bd9Sstevel@tonic-gate Sdf_desc *sdf;
35887c478bd9Sstevel@tonic-gate Rej_desc rej = { 0 };
35897c478bd9Sstevel@tonic-gate
35907c478bd9Sstevel@tonic-gate /*
35917c478bd9Sstevel@tonic-gate * Make sure we are back in dynamic mode.
35927c478bd9Sstevel@tonic-gate */
35937c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_DYNLIBS;
35947c478bd9Sstevel@tonic-gate
359557ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_soneed, idx1, sdf)) {
359657ef7aa9SRod Evans Aliste idx2;
35972926dd2eSrie char *path, *slash = NULL;
35987c478bd9Sstevel@tonic-gate int fd;
35997c478bd9Sstevel@tonic-gate Ifl_desc *ifl;
36002926dd2eSrie char *file = (char *)sdf->sdf_name;
36017c478bd9Sstevel@tonic-gate
36027c478bd9Sstevel@tonic-gate /*
36037c478bd9Sstevel@tonic-gate * See if this file has already been processed. At the time
36047c478bd9Sstevel@tonic-gate * this implicit dependency was determined there may still have
3605fb1354edSrie * been more explicit dependencies to process. Note, if we ever
36067c478bd9Sstevel@tonic-gate * do parse the command line three times we would be able to
3607fb1354edSrie * do all this checking when processing the dynamic section.
36087c478bd9Sstevel@tonic-gate */
36097c478bd9Sstevel@tonic-gate if (sdf->sdf_file)
36107c478bd9Sstevel@tonic-gate continue;
36117c478bd9Sstevel@tonic-gate
361257ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_sos, idx2, ifl)) {
36137c478bd9Sstevel@tonic-gate if (!(ifl->ifl_flags & FLG_IF_NEEDSTR) &&
36147c478bd9Sstevel@tonic-gate (strcmp(file, ifl->ifl_soname) == 0)) {
36157c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
36167c478bd9Sstevel@tonic-gate break;
36177c478bd9Sstevel@tonic-gate }
36187c478bd9Sstevel@tonic-gate }
36197c478bd9Sstevel@tonic-gate if (sdf->sdf_file)
36207c478bd9Sstevel@tonic-gate continue;
36217c478bd9Sstevel@tonic-gate
36227c478bd9Sstevel@tonic-gate /*
36232926dd2eSrie * If the current path name element embeds a "/", then it's to
36242926dd2eSrie * be taken "as is", with no searching involved. Process all
36252926dd2eSrie * "/" occurrences, so that we can deduce the base file name.
36267c478bd9Sstevel@tonic-gate */
36272926dd2eSrie for (path = file; *path; path++) {
36287c478bd9Sstevel@tonic-gate if (*path == '/')
36292926dd2eSrie slash = path;
36302926dd2eSrie }
36312926dd2eSrie if (slash) {
36325aefb655Srie DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name,
36335aefb655Srie sdf->sdf_rfile, file));
36347c478bd9Sstevel@tonic-gate if ((fd = open(file, O_RDONLY)) == -1) {
36351007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
36365aefb655Srie MSG_INTL(MSG_FIL_NOTFOUND), file,
36375aefb655Srie sdf->sdf_rfile);
36387c478bd9Sstevel@tonic-gate } else {
3639dc0f59e5SAli Bahrami uintptr_t open_ret;
36407c478bd9Sstevel@tonic-gate Rej_desc _rej = { 0 };
36417c478bd9Sstevel@tonic-gate
36421007fd6fSAli Bahrami open_ret = ld_process_open(file, ++slash,
36431007fd6fSAli Bahrami &fd, ofl, 0, &_rej, &ifl);
36443906e0c2Srie if (fd != -1)
36453906e0c2Srie (void) close(fd);
3646dc0f59e5SAli Bahrami if (open_ret == S_ERROR)
36477c478bd9Sstevel@tonic-gate return (S_ERROR);
3648a6d4d7d5SRod Evans
36497c478bd9Sstevel@tonic-gate if (_rej.rej_type) {
3650de777a60Sab Conv_reject_desc_buf_t rej_buf;
3651de777a60Sab
36521007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
36537c478bd9Sstevel@tonic-gate MSG_INTL(reject[_rej.rej_type]),
36547c478bd9Sstevel@tonic-gate _rej.rej_name ? rej.rej_name :
36557c478bd9Sstevel@tonic-gate MSG_INTL(MSG_STR_UNKNOWN),
3656ba2be530Sab conv_reject_desc(&_rej, &rej_buf,
3657ba2be530Sab ld_targ.t_m.m_mach));
36587c478bd9Sstevel@tonic-gate } else
36597c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
36607c478bd9Sstevel@tonic-gate }
36617c478bd9Sstevel@tonic-gate continue;
36627c478bd9Sstevel@tonic-gate }
36637c478bd9Sstevel@tonic-gate
36647c478bd9Sstevel@tonic-gate /*
36657c478bd9Sstevel@tonic-gate * Now search for this file in any user defined directories.
36667c478bd9Sstevel@tonic-gate */
366757ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_ulibdirs, idx2, path)) {
36687c478bd9Sstevel@tonic-gate Rej_desc _rej = { 0 };
36697c478bd9Sstevel@tonic-gate
36707c478bd9Sstevel@tonic-gate ifl = process_req_lib(sdf, path, file, ofl, &_rej);
36717c478bd9Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) {
36727c478bd9Sstevel@tonic-gate return (S_ERROR);
36737c478bd9Sstevel@tonic-gate }
36747c478bd9Sstevel@tonic-gate if (_rej.rej_type) {
36757c478bd9Sstevel@tonic-gate if (rej.rej_type == 0) {
36767c478bd9Sstevel@tonic-gate rej = _rej;
36777c478bd9Sstevel@tonic-gate rej.rej_name = strdup(_rej.rej_name);
36787c478bd9Sstevel@tonic-gate }
36797c478bd9Sstevel@tonic-gate }
36807c478bd9Sstevel@tonic-gate if (ifl) {
36817c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
36827c478bd9Sstevel@tonic-gate break;
36837c478bd9Sstevel@tonic-gate }
36847c478bd9Sstevel@tonic-gate }
36857c478bd9Sstevel@tonic-gate if (sdf->sdf_file)
36867c478bd9Sstevel@tonic-gate continue;
36877c478bd9Sstevel@tonic-gate
36887c478bd9Sstevel@tonic-gate /*
36897c478bd9Sstevel@tonic-gate * Next use the local rules defined within the parent shared
36907c478bd9Sstevel@tonic-gate * object.
36917c478bd9Sstevel@tonic-gate */
36927c478bd9Sstevel@tonic-gate if (sdf->sdf_rpath != NULL) {
36937c478bd9Sstevel@tonic-gate char *rpath, *next;
36947c478bd9Sstevel@tonic-gate
36957c478bd9Sstevel@tonic-gate rpath = libld_malloc(strlen(sdf->sdf_rpath) + 1);
3696635216b6SRod Evans if (rpath == NULL)
36977c478bd9Sstevel@tonic-gate return (S_ERROR);
36987c478bd9Sstevel@tonic-gate (void) strcpy(rpath, sdf->sdf_rpath);
36995aefb655Srie DBG_CALL(Dbg_libs_path(ofl->ofl_lml, rpath,
37005aefb655Srie LA_SER_RUNPATH, sdf->sdf_rfile));
37017c478bd9Sstevel@tonic-gate if ((path = strtok_r(rpath,
37027c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_STR_COLON), &next)) != NULL) {
37037c478bd9Sstevel@tonic-gate do {
37047c478bd9Sstevel@tonic-gate Rej_desc _rej = { 0 };
37057c478bd9Sstevel@tonic-gate
37067c478bd9Sstevel@tonic-gate path = expand(sdf->sdf_rfile, path,
37077c478bd9Sstevel@tonic-gate &next);
37087c478bd9Sstevel@tonic-gate
37097c478bd9Sstevel@tonic-gate ifl = process_req_lib(sdf, path,
3710d840867fSab file, ofl, &_rej);
37117c478bd9Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) {
37127c478bd9Sstevel@tonic-gate return (S_ERROR);
37137c478bd9Sstevel@tonic-gate }
3714d840867fSab if ((_rej.rej_type) &&
3715d840867fSab (rej.rej_type == 0)) {
3716d840867fSab rej = _rej;
3717d840867fSab rej.rej_name =
3718d840867fSab strdup(_rej.rej_name);
37197c478bd9Sstevel@tonic-gate }
37207c478bd9Sstevel@tonic-gate if (ifl) {
37217c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
37227c478bd9Sstevel@tonic-gate break;
37237c478bd9Sstevel@tonic-gate }
37247c478bd9Sstevel@tonic-gate } while ((path = strtok_r(NULL,
37257c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_STR_COLON), &next)) != NULL);
37267c478bd9Sstevel@tonic-gate }
37277c478bd9Sstevel@tonic-gate }
37287c478bd9Sstevel@tonic-gate if (sdf->sdf_file)
37297c478bd9Sstevel@tonic-gate continue;
37307c478bd9Sstevel@tonic-gate
37317c478bd9Sstevel@tonic-gate /*
37327c478bd9Sstevel@tonic-gate * Finally try the default library search directories.
37337c478bd9Sstevel@tonic-gate */
373457ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_dlibdirs, idx2, path)) {
37357c478bd9Sstevel@tonic-gate Rej_desc _rej = { 0 };
37367c478bd9Sstevel@tonic-gate
37377c478bd9Sstevel@tonic-gate ifl = process_req_lib(sdf, path, file, ofl, &rej);
37387c478bd9Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) {
37397c478bd9Sstevel@tonic-gate return (S_ERROR);
37407c478bd9Sstevel@tonic-gate }
37417c478bd9Sstevel@tonic-gate if (_rej.rej_type) {
37427c478bd9Sstevel@tonic-gate if (rej.rej_type == 0) {
37437c478bd9Sstevel@tonic-gate rej = _rej;
37447c478bd9Sstevel@tonic-gate rej.rej_name = strdup(_rej.rej_name);
37457c478bd9Sstevel@tonic-gate }
37467c478bd9Sstevel@tonic-gate }
37477c478bd9Sstevel@tonic-gate if (ifl) {
37487c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
37497c478bd9Sstevel@tonic-gate break;
37507c478bd9Sstevel@tonic-gate }
37517c478bd9Sstevel@tonic-gate }
37527c478bd9Sstevel@tonic-gate if (sdf->sdf_file)
37537c478bd9Sstevel@tonic-gate continue;
37547c478bd9Sstevel@tonic-gate
37557c478bd9Sstevel@tonic-gate /*
37567c478bd9Sstevel@tonic-gate * If we've got this far we haven't found the shared object.
37577c478bd9Sstevel@tonic-gate * If an object was found, but was rejected for some reason,
37587c478bd9Sstevel@tonic-gate * print a diagnostic to that effect, otherwise generate a
37597c478bd9Sstevel@tonic-gate * generic "not found" diagnostic.
37607c478bd9Sstevel@tonic-gate */
37617c478bd9Sstevel@tonic-gate if (rej.rej_type) {
3762de777a60Sab Conv_reject_desc_buf_t rej_buf;
3763de777a60Sab
37641007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
37655aefb655Srie MSG_INTL(reject[rej.rej_type]),
37667c478bd9Sstevel@tonic-gate rej.rej_name ? rej.rej_name :
3767de777a60Sab MSG_INTL(MSG_STR_UNKNOWN),
3768ba2be530Sab conv_reject_desc(&rej, &rej_buf,
3769ba2be530Sab ld_targ.t_m.m_mach));
37707c478bd9Sstevel@tonic-gate } else {
37711007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
37725aefb655Srie MSG_INTL(MSG_FIL_NOTFOUND), file, sdf->sdf_rfile);
37737c478bd9Sstevel@tonic-gate }
37747c478bd9Sstevel@tonic-gate }
37757c478bd9Sstevel@tonic-gate
37767c478bd9Sstevel@tonic-gate /*
37777c478bd9Sstevel@tonic-gate * Finally, now that all objects have been input, make sure any version
37787c478bd9Sstevel@tonic-gate * requirements have been met.
37797c478bd9Sstevel@tonic-gate */
37805aefb655Srie return (ld_vers_verify(ofl));
37817c478bd9Sstevel@tonic-gate }
3782