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.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * Processing of relocatable objects and shared objects.
327c478bd9Sstevel@tonic-gate */
33ba2be530Sab196087
34ba2be530Sab196087 #define ELF_TARGET_AMD64
35ba2be530Sab196087 #define ELF_TARGET_SPARC
36ba2be530Sab196087
377c478bd9Sstevel@tonic-gate #include <stdio.h>
387c478bd9Sstevel@tonic-gate #include <string.h>
397c478bd9Sstevel@tonic-gate #include <fcntl.h>
407c478bd9Sstevel@tonic-gate #include <unistd.h>
417c478bd9Sstevel@tonic-gate #include <link.h>
427c478bd9Sstevel@tonic-gate #include <limits.h>
437c478bd9Sstevel@tonic-gate #include <sys/stat.h>
447c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
457c478bd9Sstevel@tonic-gate #include <debug.h>
467c478bd9Sstevel@tonic-gate #include <msg.h>
477c478bd9Sstevel@tonic-gate #include <_libld.h>
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate * Decide if we can link against this input file.
517c478bd9Sstevel@tonic-gate */
527c478bd9Sstevel@tonic-gate static int
ifl_verify(Ehdr * ehdr,Ofl_desc * ofl,Rej_desc * rej)537c478bd9Sstevel@tonic-gate ifl_verify(Ehdr *ehdr, Ofl_desc *ofl, Rej_desc *rej)
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate * Check the validity of the elf header information for compatibility
577c478bd9Sstevel@tonic-gate * with this machine and our own internal elf library.
587c478bd9Sstevel@tonic-gate */
59ba2be530Sab196087 if ((ehdr->e_machine != ld_targ.t_m.m_mach) &&
60ba2be530Sab196087 ((ehdr->e_machine != ld_targ.t_m.m_machplus) &&
61ba2be530Sab196087 ((ehdr->e_flags & ld_targ.t_m.m_flagsplus) == 0))) {
627c478bd9Sstevel@tonic-gate rej->rej_type = SGS_REJ_MACH;
637c478bd9Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_machine;
647c478bd9Sstevel@tonic-gate return (0);
657c478bd9Sstevel@tonic-gate }
66ba2be530Sab196087 if (ehdr->e_ident[EI_DATA] != ld_targ.t_m.m_data) {
677c478bd9Sstevel@tonic-gate rej->rej_type = SGS_REJ_DATA;
687c478bd9Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_ident[EI_DATA];
697c478bd9Sstevel@tonic-gate return (0);
707c478bd9Sstevel@tonic-gate }
715aefb655Srie if (ehdr->e_version > ofl->ofl_dehdr->e_version) {
727c478bd9Sstevel@tonic-gate rej->rej_type = SGS_REJ_VERSION;
737c478bd9Sstevel@tonic-gate rej->rej_info = (uint_t)ehdr->e_version;
747c478bd9Sstevel@tonic-gate return (0);
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate return (1);
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate * Check sanity of file header and allocate an infile descriptor
817c478bd9Sstevel@tonic-gate * for the file being processed.
827c478bd9Sstevel@tonic-gate */
835aefb655Srie static Ifl_desc *
ifl_setup(const char * name,Ehdr * ehdr,Elf * elf,Word flags,Ofl_desc * ofl,Rej_desc * rej)84d840867fSab196087 ifl_setup(const char *name, Ehdr *ehdr, Elf *elf, Word flags, Ofl_desc *ofl,
857c478bd9Sstevel@tonic-gate Rej_desc *rej)
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate Ifl_desc *ifl;
887c478bd9Sstevel@tonic-gate Rej_desc _rej = { 0 };
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate if (ifl_verify(ehdr, ofl, &_rej) == 0) {
917c478bd9Sstevel@tonic-gate _rej.rej_name = name;
92ba2be530Sab196087 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
93ba2be530Sab196087 ld_targ.t_m.m_mach));
947c478bd9Sstevel@tonic-gate if (rej->rej_type == 0) {
957c478bd9Sstevel@tonic-gate *rej = _rej;
967c478bd9Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name);
977c478bd9Sstevel@tonic-gate }
987c478bd9Sstevel@tonic-gate return (0);
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate
101635216b6SRod Evans if ((ifl = libld_calloc(1, sizeof (Ifl_desc))) == NULL)
1027c478bd9Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR);
1037c478bd9Sstevel@tonic-gate ifl->ifl_name = name;
1047c478bd9Sstevel@tonic-gate ifl->ifl_ehdr = ehdr;
1057c478bd9Sstevel@tonic-gate ifl->ifl_elf = elf;
1067c478bd9Sstevel@tonic-gate ifl->ifl_flags = flags;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate * Is this file using 'extended Section Indexes'. If so, use the
1107c478bd9Sstevel@tonic-gate * e_shnum & e_shstrndx which can be found at:
1117c478bd9Sstevel@tonic-gate *
1127c478bd9Sstevel@tonic-gate * e_shnum == Shdr[0].sh_size
1137c478bd9Sstevel@tonic-gate * e_shstrndx == Shdr[0].sh_link
1147c478bd9Sstevel@tonic-gate */
1157c478bd9Sstevel@tonic-gate if ((ehdr->e_shnum == 0) && (ehdr->e_shoff != 0)) {
1167c478bd9Sstevel@tonic-gate Elf_Scn *scn;
1177c478bd9Sstevel@tonic-gate Shdr *shdr0;
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate if ((scn = elf_getscn(elf, 0)) == NULL) {
1201007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN),
1211007fd6fSAli Bahrami name);
1227c478bd9Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR);
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate if ((shdr0 = elf_getshdr(scn)) == NULL) {
1251007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR),
1261007fd6fSAli Bahrami name);
1277c478bd9Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR);
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate ifl->ifl_shnum = (Word)shdr0->sh_size;
1307c478bd9Sstevel@tonic-gate if (ehdr->e_shstrndx == SHN_XINDEX)
1317c478bd9Sstevel@tonic-gate ifl->ifl_shstrndx = shdr0->sh_link;
1327c478bd9Sstevel@tonic-gate else
1337c478bd9Sstevel@tonic-gate ifl->ifl_shstrndx = ehdr->e_shstrndx;
1347c478bd9Sstevel@tonic-gate } else {
1357c478bd9Sstevel@tonic-gate ifl->ifl_shnum = ehdr->e_shnum;
1367c478bd9Sstevel@tonic-gate ifl->ifl_shstrndx = ehdr->e_shstrndx;
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate if ((ifl->ifl_isdesc = libld_calloc(ifl->ifl_shnum,
140635216b6SRod Evans sizeof (Is_desc *))) == NULL)
1417c478bd9Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR);
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate * Record this new input file on the shared object or relocatable
1457c478bd9Sstevel@tonic-gate * object input file list.
1467c478bd9Sstevel@tonic-gate */
1477c478bd9Sstevel@tonic-gate if (ifl->ifl_ehdr->e_type == ET_DYN) {
14857ef7aa9SRod Evans if (aplist_append(&ofl->ofl_sos, ifl, AL_CNT_OFL_LIBS) == NULL)
14957ef7aa9SRod Evans return ((Ifl_desc *)S_ERROR);
1507c478bd9Sstevel@tonic-gate } else {
15157ef7aa9SRod Evans if (aplist_append(&ofl->ofl_objs, ifl, AL_CNT_OFL_OBJS) == NULL)
15257ef7aa9SRod Evans return ((Ifl_desc *)S_ERROR);
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate return (ifl);
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate /*
1597c478bd9Sstevel@tonic-gate * Process a generic section. The appropriate section information is added
1607c478bd9Sstevel@tonic-gate * to the files input descriptor list.
1617c478bd9Sstevel@tonic-gate */
1625aefb655Srie static uintptr_t
process_section(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)1637c478bd9Sstevel@tonic-gate process_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
1647c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
1657c478bd9Sstevel@tonic-gate {
1667c478bd9Sstevel@tonic-gate Is_desc *isp;
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate * Create a new input section descriptor. If this is a NOBITS
1707c478bd9Sstevel@tonic-gate * section elf_getdata() will still create a data buffer (the buffer
1717c478bd9Sstevel@tonic-gate * will be null and the size will reflect the actual memory size).
1727c478bd9Sstevel@tonic-gate */
173635216b6SRod Evans if ((isp = libld_calloc(sizeof (Is_desc), 1)) == NULL)
1747c478bd9Sstevel@tonic-gate return (S_ERROR);
1757c478bd9Sstevel@tonic-gate isp->is_shdr = shdr;
1767c478bd9Sstevel@tonic-gate isp->is_file = ifl;
1777c478bd9Sstevel@tonic-gate isp->is_name = name;
1787c478bd9Sstevel@tonic-gate isp->is_scnndx = ndx;
17954d82594Sseizo isp->is_flags = FLG_IS_EXTERNAL;
1800e233487SRod Evans isp->is_keyident = ident;
1810e233487SRod Evans
1827c478bd9Sstevel@tonic-gate if ((isp->is_indata = elf_getdata(scn, NULL)) == NULL) {
1831007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETDATA),
1845aefb655Srie ifl->ifl_name);
1857c478bd9Sstevel@tonic-gate return (0);
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate if ((shdr->sh_flags & SHF_EXCLUDE) &&
1897c478bd9Sstevel@tonic-gate ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0)) {
1907c478bd9Sstevel@tonic-gate isp->is_flags |= FLG_IS_DISCARD;
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate * Add the new input section to the files input section list and
1950e233487SRod Evans * flag whether the section needs placing in an output section. This
1960e233487SRod Evans * placement is deferred until all input section processing has been
1970e233487SRod Evans * completed, as SHT_GROUP sections can provide information that will
1980e233487SRod Evans * affect how other sections within the file should be placed.
1997c478bd9Sstevel@tonic-gate */
2007c478bd9Sstevel@tonic-gate ifl->ifl_isdesc[ndx] = isp;
2017c478bd9Sstevel@tonic-gate
2020e233487SRod Evans if (ident) {
2030e233487SRod Evans if (shdr->sh_flags & ALL_SHF_ORDER) {
2047c478bd9Sstevel@tonic-gate isp->is_flags |= FLG_IS_ORDERED;
2050e233487SRod Evans ifl->ifl_flags |= FLG_IF_ORDERED;
2067c478bd9Sstevel@tonic-gate }
2070e233487SRod Evans isp->is_flags |= FLG_IS_PLACE;
2087010c12aSrie }
2097c478bd9Sstevel@tonic-gate return (1);
2107c478bd9Sstevel@tonic-gate }
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate /*
2137c478bd9Sstevel@tonic-gate * Determine the software capabilities of the object being built from the
2147c478bd9Sstevel@tonic-gate * capabilities of the input relocatable objects. One software capability
2157c478bd9Sstevel@tonic-gate * is presently recognized, and represented with the following (sys/elf.h):
2167c478bd9Sstevel@tonic-gate *
2177c478bd9Sstevel@tonic-gate * SF1_SUNW_FPKNWN use/non-use of frame pointer is known, and
2187c478bd9Sstevel@tonic-gate * SF1_SUNW_FPUSED the frame pointer is in use.
2197c478bd9Sstevel@tonic-gate *
2207c478bd9Sstevel@tonic-gate * The resolution of the present fame pointer state, and the capabilities
2217c478bd9Sstevel@tonic-gate * provided by a new input relocatable object are:
2227c478bd9Sstevel@tonic-gate *
2237c478bd9Sstevel@tonic-gate * new input relocatable object
2247c478bd9Sstevel@tonic-gate *
2257c478bd9Sstevel@tonic-gate * present | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown>
2267c478bd9Sstevel@tonic-gate * state | SF1_SUNW_FPUSED | |
2277c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------------------
2287c478bd9Sstevel@tonic-gate * SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN
2297c478bd9Sstevel@tonic-gate * SF1_SUNW_FPUSED | SF1_SUNW_FPUSED | | SF1_SUNW_FPUSED
2307c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------------------
2317c478bd9Sstevel@tonic-gate * SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN
2327c478bd9Sstevel@tonic-gate * | | |
2337c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------------------
2347c478bd9Sstevel@tonic-gate * <unknown> | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown>
2357c478bd9Sstevel@tonic-gate * | SF1_SUNW_FPUSED | |
2367c478bd9Sstevel@tonic-gate */
2377c478bd9Sstevel@tonic-gate static void
sf1_cap(Ofl_desc * ofl,Xword val,Ifl_desc * ifl,Is_desc * cisp)2384a8d0ea7SAli Bahrami sf1_cap(Ofl_desc *ofl, Xword val, Ifl_desc *ifl, Is_desc *cisp)
2397c478bd9Sstevel@tonic-gate {
24069112eddSAli Bahrami #define FP_FLAGS (SF1_SUNW_FPKNWN | SF1_SUNW_FPUSED)
24169112eddSAli Bahrami
2427c478bd9Sstevel@tonic-gate Xword badval;
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate /*
24508278a5eSRod Evans * If a mapfile has established definitions to override any object
24608278a5eSRod Evans * capabilities, ignore any new object capabilities.
2477c478bd9Sstevel@tonic-gate */
24869112eddSAli Bahrami if (ofl->ofl_flags1 & FLG_OF1_OVSFCAP1) {
24908278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
25069112eddSAli Bahrami CA_SUNW_SF_1, val, ld_targ.t_m.m_mach));
2517c478bd9Sstevel@tonic-gate return;
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate
254bebb829dSRod Evans #if !defined(_ELF64)
25508278a5eSRod Evans if (ifl && (ifl->ifl_ehdr->e_type == ET_REL)) {
256bebb829dSRod Evans /*
257bebb829dSRod Evans * The SF1_SUNW_ADDR32 is only meaningful when building a 64-bit
258bebb829dSRod Evans * object. Warn the user, and remove the setting, if we're
259bebb829dSRod Evans * building a 32-bit object.
260bebb829dSRod Evans */
261bebb829dSRod Evans if (val & SF1_SUNW_ADDR32) {
2621007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
2634a8d0ea7SAli Bahrami MSG_INTL(MSG_FIL_INADDR32SF1), ifl->ifl_name,
2644a8d0ea7SAli Bahrami EC_WORD(cisp->is_scnndx), cisp->is_name);
265bebb829dSRod Evans val &= ~SF1_SUNW_ADDR32;
266bebb829dSRod Evans }
267bebb829dSRod Evans }
268bebb829dSRod Evans #endif
2697c478bd9Sstevel@tonic-gate /*
2707c478bd9Sstevel@tonic-gate * If this object doesn't specify any capabilities, ignore it, and
2717c478bd9Sstevel@tonic-gate * leave the state as is.
2727c478bd9Sstevel@tonic-gate */
2737c478bd9Sstevel@tonic-gate if (val == 0)
2747c478bd9Sstevel@tonic-gate return;
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate /*
2777c478bd9Sstevel@tonic-gate * Make sure we only accept known software capabilities. Note, that
2787c478bd9Sstevel@tonic-gate * an F1_SUNW_FPUSED by itself is viewed as bad practice.
2797c478bd9Sstevel@tonic-gate */
2807c478bd9Sstevel@tonic-gate if ((badval = (val & ~SF1_SUNW_MASK)) != 0) {
2811007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1),
2824a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(cisp->is_scnndx), cisp->is_name,
2834a8d0ea7SAli Bahrami EC_XWORD(badval));
2847c478bd9Sstevel@tonic-gate val &= SF1_SUNW_MASK;
2857c478bd9Sstevel@tonic-gate }
28669112eddSAli Bahrami if ((val & FP_FLAGS) == SF1_SUNW_FPUSED) {
2871007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_BADSF1),
2884a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(cisp->is_scnndx), cisp->is_name,
2894a8d0ea7SAli Bahrami EC_XWORD(val));
2907c478bd9Sstevel@tonic-gate return;
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate
293bebb829dSRod Evans /*
294bebb829dSRod Evans * If the input file is not a relocatable object, then we're only here
295bebb829dSRod Evans * to warn the user of any questionable capabilities.
296bebb829dSRod Evans */
297bebb829dSRod Evans if (ifl->ifl_ehdr->e_type != ET_REL) {
298bebb829dSRod Evans #if defined(_ELF64)
299bebb829dSRod Evans /*
300bebb829dSRod Evans * If we're building a 64-bit executable, and we come across a
301bebb829dSRod Evans * dependency that requires a restricted address space, then
302bebb829dSRod Evans * that dependencies requirement can only be satisfied if the
303bebb829dSRod Evans * executable triggers the restricted address space. This is a
304bebb829dSRod Evans * warning rather than a fatal error, as the possibility exists
305bebb829dSRod Evans * that an appropriate dependency will be provided at runtime.
306bebb829dSRod Evans * The runtime linker will refuse to use this dependency.
307bebb829dSRod Evans */
308bebb829dSRod Evans if ((val & SF1_SUNW_ADDR32) && (ofl->ofl_flags & FLG_OF_EXEC) &&
30908278a5eSRod Evans ((ofl->ofl_ocapset.oc_sf_1.cm_val &
31069112eddSAli Bahrami SF1_SUNW_ADDR32) == 0)) {
3111007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
3124a8d0ea7SAli Bahrami MSG_INTL(MSG_FIL_EXADDR32SF1), ifl->ifl_name,
3134a8d0ea7SAli Bahrami EC_WORD(cisp->is_scnndx), cisp->is_name);
314bebb829dSRod Evans }
315bebb829dSRod Evans #endif
316bebb829dSRod Evans return;
317bebb829dSRod Evans }
318bebb829dSRod Evans
31969112eddSAli Bahrami if (DBG_ENABLED) {
32008278a5eSRod Evans Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_CURRENT, CA_SUNW_SF_1,
32108278a5eSRod Evans ofl->ofl_ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach);
32208278a5eSRod Evans Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_NEW, CA_SUNW_SF_1,
323ba2be530Sab196087 val, ld_targ.t_m.m_mach);
32469112eddSAli Bahrami }
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate /*
3277c478bd9Sstevel@tonic-gate * Determine the resolution of the present frame pointer and the
3287c478bd9Sstevel@tonic-gate * new input relocatable objects frame pointer.
3297c478bd9Sstevel@tonic-gate */
33008278a5eSRod Evans if ((ofl->ofl_ocapset.oc_sf_1.cm_val & FP_FLAGS) == FP_FLAGS) {
3317c478bd9Sstevel@tonic-gate /*
3327c478bd9Sstevel@tonic-gate * If the new relocatable object isn't using a frame pointer,
3337c478bd9Sstevel@tonic-gate * reduce the present state to unused.
3347c478bd9Sstevel@tonic-gate */
33569112eddSAli Bahrami if ((val & FP_FLAGS) != FP_FLAGS)
33608278a5eSRod Evans ofl->ofl_ocapset.oc_sf_1.cm_val &= ~SF1_SUNW_FPUSED;
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gate /*
33969112eddSAli Bahrami * Having processed the frame pointer bits, remove them from
34069112eddSAli Bahrami * the value so they don't get OR'd in below.
3417c478bd9Sstevel@tonic-gate */
34269112eddSAli Bahrami val &= ~FP_FLAGS;
34369112eddSAli Bahrami
34408278a5eSRod Evans } else if ((ofl->ofl_ocapset.oc_sf_1.cm_val & SF1_SUNW_FPKNWN) == 0) {
34569112eddSAli Bahrami /*
34669112eddSAli Bahrami * If the present frame pointer state is unknown, mask it out
34769112eddSAli Bahrami * and allow the values from the new relocatable object
34869112eddSAli Bahrami * to overwrite them.
34969112eddSAli Bahrami */
35008278a5eSRod Evans ofl->ofl_ocapset.oc_sf_1.cm_val &= ~FP_FLAGS;
35169112eddSAli Bahrami } else {
35269112eddSAli Bahrami /* Do not take the frame pointer flags from the object */
35369112eddSAli Bahrami val &= ~FP_FLAGS;
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate
35608278a5eSRod Evans ofl->ofl_ocapset.oc_sf_1.cm_val |= val;
35769112eddSAli Bahrami
35808278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_RESOLVED,
35908278a5eSRod Evans CA_SUNW_SF_1, ofl->ofl_ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach));
36069112eddSAli Bahrami
36169112eddSAli Bahrami #undef FP_FLAGS
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate /*
3657c478bd9Sstevel@tonic-gate * Determine the hardware capabilities of the object being built from the
3667c478bd9Sstevel@tonic-gate * capabilities of the input relocatable objects. There's really little to
3677c478bd9Sstevel@tonic-gate * do here, other than to offer diagnostics, hardware capabilities are simply
3687c478bd9Sstevel@tonic-gate * additive.
3697c478bd9Sstevel@tonic-gate */
3707c478bd9Sstevel@tonic-gate static void
hw_cap(Ofl_desc * ofl,Xword tag,Xword val)37108278a5eSRod Evans hw_cap(Ofl_desc *ofl, Xword tag, Xword val)
3727c478bd9Sstevel@tonic-gate {
37308278a5eSRod Evans elfcap_mask_t *hwcap;
37408278a5eSRod Evans ofl_flag_t flags1;
37508278a5eSRod Evans
37608278a5eSRod Evans if (tag == CA_SUNW_HW_1) {
37708278a5eSRod Evans hwcap = &ofl->ofl_ocapset.oc_hw_1.cm_val;
37808278a5eSRod Evans flags1 = FLG_OF1_OVHWCAP1;
37908278a5eSRod Evans } else {
38008278a5eSRod Evans hwcap = &ofl->ofl_ocapset.oc_hw_2.cm_val;
38108278a5eSRod Evans flags1 = FLG_OF1_OVHWCAP2;
38208278a5eSRod Evans }
38308278a5eSRod Evans
3847c478bd9Sstevel@tonic-gate /*
38508278a5eSRod Evans * If a mapfile has established definitions to override any object
38608278a5eSRod Evans * capabilities, ignore any new object capabilities.
3877c478bd9Sstevel@tonic-gate */
38808278a5eSRod Evans if (ofl->ofl_flags1 & flags1) {
38908278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
39008278a5eSRod Evans tag, val, ld_targ.t_m.m_mach));
3917c478bd9Sstevel@tonic-gate return;
3927c478bd9Sstevel@tonic-gate }
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate /*
3957c478bd9Sstevel@tonic-gate * If this object doesn't specify any capabilities, ignore it, and
3967c478bd9Sstevel@tonic-gate * leave the state as is.
3977c478bd9Sstevel@tonic-gate */
3987c478bd9Sstevel@tonic-gate if (val == 0)
3997c478bd9Sstevel@tonic-gate return;
4007c478bd9Sstevel@tonic-gate
40169112eddSAli Bahrami if (DBG_ENABLED) {
40208278a5eSRod Evans Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_CURRENT, CA_SUNW_HW_1,
40308278a5eSRod Evans ofl->ofl_ocapset.oc_hw_1.cm_val, ld_targ.t_m.m_mach);
40408278a5eSRod Evans Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_NEW, CA_SUNW_HW_1,
40508278a5eSRod Evans val, ld_targ.t_m.m_mach);
40669112eddSAli Bahrami }
4077c478bd9Sstevel@tonic-gate
40808278a5eSRod Evans *hwcap |= val;
4097c478bd9Sstevel@tonic-gate
41008278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml, DBG_STATE_RESOLVED, tag,
41108278a5eSRod Evans *hwcap, ld_targ.t_m.m_mach));
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate /*
41508278a5eSRod Evans * Promote a machine capability or platform capability to the output file.
41608278a5eSRod Evans * Multiple instances of these names can be defined.
4177c478bd9Sstevel@tonic-gate */
4187c478bd9Sstevel@tonic-gate static void
str_cap(Ofl_desc * ofl,char * pstr,ofl_flag_t flags,Xword tag,Caplist * list)41908278a5eSRod Evans str_cap(Ofl_desc *ofl, char *pstr, ofl_flag_t flags, Xword tag, Caplist *list)
4207c478bd9Sstevel@tonic-gate {
42108278a5eSRod Evans Capstr *capstr;
42208278a5eSRod Evans Aliste idx;
42308278a5eSRod Evans Boolean found = FALSE;
4247c478bd9Sstevel@tonic-gate
425c75e1b9dSrie /*
42608278a5eSRod Evans * If a mapfile has established definitions to override this capability,
42708278a5eSRod Evans * ignore any new capability.
42808278a5eSRod Evans */
42908278a5eSRod Evans if (ofl->ofl_flags1 & flags) {
43008278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_IGNORED,
43108278a5eSRod Evans tag, pstr));
43208278a5eSRod Evans return;
43308278a5eSRod Evans }
43408278a5eSRod Evans
43508278a5eSRod Evans for (ALIST_TRAVERSE(list->cl_val, idx, capstr)) {
43608278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
43708278a5eSRod Evans DBG_STATE_CURRENT, tag, capstr->cs_str));
43808278a5eSRod Evans if (strcmp(capstr->cs_str, pstr) == 0)
43908278a5eSRod Evans found = TRUE;
44008278a5eSRod Evans }
44108278a5eSRod Evans
44208278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_NEW, tag, pstr));
44308278a5eSRod Evans
44408278a5eSRod Evans if (found == FALSE) {
44508278a5eSRod Evans if ((capstr = alist_append(&list->cl_val, NULL,
44608278a5eSRod Evans sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL) {
44708278a5eSRod Evans ofl->ofl_flags |= FLG_OF_FATAL;
44808278a5eSRod Evans return;
44908278a5eSRod Evans }
45008278a5eSRod Evans capstr->cs_str = pstr;
45108278a5eSRod Evans }
45208278a5eSRod Evans
45308278a5eSRod Evans if (DBG_ENABLED) {
45408278a5eSRod Evans for (ALIST_TRAVERSE(list->cl_val, idx, capstr)) {
45508278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
45608278a5eSRod Evans DBG_STATE_RESOLVED, tag, capstr->cs_str));
45708278a5eSRod Evans }
45808278a5eSRod Evans }
45908278a5eSRod Evans }
46008278a5eSRod Evans
46108278a5eSRod Evans /*
46208278a5eSRod Evans * Promote a capability identifier to the output file. A capability group can
46308278a5eSRod Evans * only have one identifier, and thus only the first identifier seen from any
46408278a5eSRod Evans * input relocatable objects is retained. An explicit user defined identifier,
46508278a5eSRod Evans * rather than an an identifier fabricated by ld(1) with -z symbcap processing,
46608278a5eSRod Evans * takes precedence. Note, a user may have defined an identifier via a mapfile,
46708278a5eSRod Evans * in which case the mapfile identifier is retained.
46808278a5eSRod Evans */
46908278a5eSRod Evans static void
id_cap(Ofl_desc * ofl,char * pstr,oc_flag_t flags)47008278a5eSRod Evans id_cap(Ofl_desc *ofl, char *pstr, oc_flag_t flags)
47108278a5eSRod Evans {
47208278a5eSRod Evans Objcapset *ocapset = &ofl->ofl_ocapset;
47308278a5eSRod Evans
47408278a5eSRod Evans if (ocapset->oc_id.cs_str) {
47508278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_CURRENT,
47608278a5eSRod Evans CA_SUNW_ID, ocapset->oc_id.cs_str));
47708278a5eSRod Evans
47808278a5eSRod Evans if ((ocapset->oc_flags & FLG_OCS_USRDEFID) ||
47908278a5eSRod Evans ((flags & FLG_OCS_USRDEFID) == 0)) {
48008278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
48108278a5eSRod Evans DBG_STATE_IGNORED, CA_SUNW_ID, pstr));
48208278a5eSRod Evans return;
48308278a5eSRod Evans }
48408278a5eSRod Evans }
48508278a5eSRod Evans
48608278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_NEW,
48708278a5eSRod Evans CA_SUNW_ID, pstr));
48808278a5eSRod Evans
48908278a5eSRod Evans ocapset->oc_id.cs_str = pstr;
49008278a5eSRod Evans ocapset->oc_flags |= flags;
49108278a5eSRod Evans
49208278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml, DBG_STATE_RESOLVED,
49308278a5eSRod Evans CA_SUNW_ID, pstr));
49408278a5eSRod Evans }
49508278a5eSRod Evans
49608278a5eSRod Evans /*
49708278a5eSRod Evans * Promote a capabilities group to the object capabilities. This catches a
49808278a5eSRod Evans * corner case. An object capabilities file can be converted to symbol
49908278a5eSRod Evans * capabilities with -z symbolcap. However, if the user has indicated that all
50008278a5eSRod Evans * the symbols should be demoted, we'd be left with a symbol capabilities file,
50108278a5eSRod Evans * with no associated symbols. Catch this case by promoting the symbol
50208278a5eSRod Evans * capabilities back to object capabilities.
50308278a5eSRod Evans */
50408278a5eSRod Evans void
ld_cap_move_symtoobj(Ofl_desc * ofl)50508278a5eSRod Evans ld_cap_move_symtoobj(Ofl_desc *ofl)
50608278a5eSRod Evans {
50708278a5eSRod Evans Cap_group *cgp;
50808278a5eSRod Evans Aliste idx1;
50908278a5eSRod Evans
51008278a5eSRod Evans for (APLIST_TRAVERSE(ofl->ofl_capgroups, idx1, cgp)) {
51108278a5eSRod Evans Objcapset *scapset = &cgp->cg_set;
51208278a5eSRod Evans Capstr *capstr;
51308278a5eSRod Evans Aliste idx2;
51408278a5eSRod Evans
51508278a5eSRod Evans if (scapset->oc_id.cs_str) {
51608278a5eSRod Evans if (scapset->oc_flags & FLG_OCS_USRDEFID)
51708278a5eSRod Evans id_cap(ofl, scapset->oc_id.cs_str,
51808278a5eSRod Evans scapset->oc_flags);
51908278a5eSRod Evans }
52008278a5eSRod Evans if (scapset->oc_plat.cl_val) {
52108278a5eSRod Evans for (ALIST_TRAVERSE(scapset->oc_plat.cl_val, idx2,
52208278a5eSRod Evans capstr)) {
52308278a5eSRod Evans str_cap(ofl, capstr->cs_str, FLG_OF1_OVPLATCAP,
52408278a5eSRod Evans CA_SUNW_PLAT, &ofl->ofl_ocapset.oc_plat);
52508278a5eSRod Evans }
52608278a5eSRod Evans }
52708278a5eSRod Evans if (scapset->oc_mach.cl_val) {
52808278a5eSRod Evans for (ALIST_TRAVERSE(scapset->oc_mach.cl_val, idx2,
52908278a5eSRod Evans capstr)) {
53008278a5eSRod Evans str_cap(ofl, capstr->cs_str, FLG_OF1_OVMACHCAP,
53108278a5eSRod Evans CA_SUNW_MACH, &ofl->ofl_ocapset.oc_mach);
53208278a5eSRod Evans }
53308278a5eSRod Evans }
53408278a5eSRod Evans if (scapset->oc_hw_2.cm_val)
53508278a5eSRod Evans hw_cap(ofl, CA_SUNW_HW_2, scapset->oc_hw_2.cm_val);
53608278a5eSRod Evans
53708278a5eSRod Evans if (scapset->oc_hw_1.cm_val)
53808278a5eSRod Evans hw_cap(ofl, CA_SUNW_HW_1, scapset->oc_hw_1.cm_val);
53908278a5eSRod Evans
54008278a5eSRod Evans if (scapset->oc_sf_1.cm_val)
54108278a5eSRod Evans sf1_cap(ofl, scapset->oc_sf_1.cm_val, NULL, NULL);
54208278a5eSRod Evans }
54308278a5eSRod Evans }
54408278a5eSRod Evans
54508278a5eSRod Evans /*
54608278a5eSRod Evans * Determine whether a capabilities group already exists that describes this
54708278a5eSRod Evans * new capabilities group.
54808278a5eSRod Evans *
54908278a5eSRod Evans * Note, a capability group identifier, CA_SUNW_ID, isn't used as part of the
55008278a5eSRod Evans * comparison. This attribute simply assigns a diagnostic name to the group,
55108278a5eSRod Evans * and in the case of multiple identifiers, the first will be taken.
55208278a5eSRod Evans */
55308278a5eSRod Evans static Cap_group *
get_cap_group(Objcapset * ocapset,Word cnum,Ofl_desc * ofl,Is_desc * isp)55408278a5eSRod Evans get_cap_group(Objcapset *ocapset, Word cnum, Ofl_desc *ofl, Is_desc *isp)
55508278a5eSRod Evans {
55608278a5eSRod Evans Aliste idx;
55708278a5eSRod Evans Cap_group *cgp;
55808278a5eSRod Evans Word ccnum = cnum;
55908278a5eSRod Evans
56008278a5eSRod Evans /*
56108278a5eSRod Evans * If the new capabilities contains a CA_SUNW_ID, drop the count of the
56208278a5eSRod Evans * number of comparable items.
56308278a5eSRod Evans */
56408278a5eSRod Evans if (ocapset->oc_id.cs_str)
56508278a5eSRod Evans ccnum--;
56608278a5eSRod Evans
56708278a5eSRod Evans /*
56808278a5eSRod Evans * Traverse the existing symbols capabilities groups.
56908278a5eSRod Evans */
57008278a5eSRod Evans for (APLIST_TRAVERSE(ofl->ofl_capgroups, idx, cgp)) {
57108278a5eSRod Evans Word onum = cgp->cg_num;
57208278a5eSRod Evans Alist *calp, *oalp;
57308278a5eSRod Evans
57408278a5eSRod Evans if (cgp->cg_set.oc_id.cs_str)
57508278a5eSRod Evans onum--;
57608278a5eSRod Evans
57708278a5eSRod Evans if (onum != ccnum)
57808278a5eSRod Evans continue;
57908278a5eSRod Evans
58008278a5eSRod Evans if (cgp->cg_set.oc_hw_1.cm_val != ocapset->oc_hw_1.cm_val)
58108278a5eSRod Evans continue;
58208278a5eSRod Evans if (cgp->cg_set.oc_sf_1.cm_val != ocapset->oc_sf_1.cm_val)
58308278a5eSRod Evans continue;
58408278a5eSRod Evans if (cgp->cg_set.oc_hw_2.cm_val != ocapset->oc_hw_2.cm_val)
58508278a5eSRod Evans continue;
58608278a5eSRod Evans
58708278a5eSRod Evans calp = cgp->cg_set.oc_plat.cl_val;
58808278a5eSRod Evans oalp = ocapset->oc_plat.cl_val;
58908278a5eSRod Evans if ((calp == NULL) && oalp)
59008278a5eSRod Evans continue;
59108278a5eSRod Evans if (calp && ((oalp == NULL) || cap_names_match(calp, oalp)))
59208278a5eSRod Evans continue;
59308278a5eSRod Evans
59408278a5eSRod Evans calp = cgp->cg_set.oc_mach.cl_val;
59508278a5eSRod Evans oalp = ocapset->oc_mach.cl_val;
59608278a5eSRod Evans if ((calp == NULL) && oalp)
59708278a5eSRod Evans continue;
59808278a5eSRod Evans if (calp && ((oalp == NULL) || cap_names_match(calp, oalp)))
59908278a5eSRod Evans continue;
60008278a5eSRod Evans
60108278a5eSRod Evans /*
60208278a5eSRod Evans * If a matching group is found, then this new group has
60308278a5eSRod Evans * already been supplied by a previous file, and hence the
60408278a5eSRod Evans * existing group can be used. Record this new input section,
60508278a5eSRod Evans * from which we can also derive the input file name, on the
60608278a5eSRod Evans * existing groups input sections.
60708278a5eSRod Evans */
60808278a5eSRod Evans if (aplist_append(&(cgp->cg_secs), isp,
60908278a5eSRod Evans AL_CNT_CAP_SECS) == NULL)
61008278a5eSRod Evans return (NULL);
61108278a5eSRod Evans return (cgp);
61208278a5eSRod Evans }
61308278a5eSRod Evans
61408278a5eSRod Evans /*
61508278a5eSRod Evans * If a capabilities group is not found, create a new one.
61608278a5eSRod Evans */
61708278a5eSRod Evans if (((cgp = libld_calloc(sizeof (Cap_group), 1)) == NULL) ||
61808278a5eSRod Evans (aplist_append(&(ofl->ofl_capgroups), cgp,
61908278a5eSRod Evans AL_CNT_CAP_DESCS) == NULL))
62008278a5eSRod Evans return (NULL);
62108278a5eSRod Evans
62208278a5eSRod Evans /*
62308278a5eSRod Evans * If we're converting object capabilities to symbol capabilities and
62408278a5eSRod Evans * no CA_SUNW_ID is defined, fabricate one. This identifier is appended
62508278a5eSRod Evans * to all symbol names that are converted into capabilities symbols,
62608278a5eSRod Evans * see ld_sym_process().
62708278a5eSRod Evans */
62808278a5eSRod Evans if ((isp->is_file->ifl_flags & FLG_IF_OTOSCAP) &&
62908278a5eSRod Evans (ocapset->oc_id.cs_str == NULL)) {
63008278a5eSRod Evans size_t len;
63108278a5eSRod Evans
63208278a5eSRod Evans /*
63308278a5eSRod Evans * Create an identifier using the group number together with a
63408278a5eSRod Evans * default template. We allocate a buffer large enough for any
63508278a5eSRod Evans * possible number of items (way more than we need).
63608278a5eSRod Evans */
63708278a5eSRod Evans len = MSG_STR_CAPGROUPID_SIZE + CONV_INV_BUFSIZE;
63808278a5eSRod Evans if ((ocapset->oc_id.cs_str = libld_malloc(len)) == NULL)
63908278a5eSRod Evans return (NULL);
64008278a5eSRod Evans
64108278a5eSRod Evans (void) snprintf(ocapset->oc_id.cs_str, len,
64208278a5eSRod Evans MSG_ORIG(MSG_STR_CAPGROUPID),
64308278a5eSRod Evans aplist_nitems(ofl->ofl_capgroups));
64408278a5eSRod Evans cnum++;
64508278a5eSRod Evans }
64608278a5eSRod Evans
64708278a5eSRod Evans cgp->cg_set = *ocapset;
64808278a5eSRod Evans cgp->cg_num = cnum;
64908278a5eSRod Evans
65008278a5eSRod Evans /*
65108278a5eSRod Evans * Null the callers alist's as they've effectively been transferred
65208278a5eSRod Evans * to this new Cap_group.
65308278a5eSRod Evans */
65408278a5eSRod Evans ocapset->oc_plat.cl_val = ocapset->oc_mach.cl_val = NULL;
65508278a5eSRod Evans
65608278a5eSRod Evans /*
65708278a5eSRod Evans * Keep track of which input section, and hence input file, established
65808278a5eSRod Evans * this group.
65908278a5eSRod Evans */
66008278a5eSRod Evans if (aplist_append(&(cgp->cg_secs), isp, AL_CNT_CAP_SECS) == NULL)
66108278a5eSRod Evans return (NULL);
66208278a5eSRod Evans
66308278a5eSRod Evans /*
66408278a5eSRod Evans * Keep track of the number of symbol capabilities entries that will be
66508278a5eSRod Evans * required in the output file. Each group requires a terminating
66608278a5eSRod Evans * CA_SUNW_NULL.
66708278a5eSRod Evans */
66808278a5eSRod Evans ofl->ofl_capsymcnt += (cnum + 1);
66908278a5eSRod Evans return (cgp);
67008278a5eSRod Evans }
67108278a5eSRod Evans
67208278a5eSRod Evans /*
67308278a5eSRod Evans * Capture symbol capability family information. This data structure is focal
67408278a5eSRod Evans * in maintaining all symbol capability relationships, and provides for the
67508278a5eSRod Evans * eventual creation of a capabilities information section, and possibly a
67608278a5eSRod Evans * capabilities chain section.
67708278a5eSRod Evans *
67808278a5eSRod Evans * Capabilities families are lead by a CAPINFO_SUNW_GLOB symbol. This symbol
67908278a5eSRod Evans * provides the visible global symbol that is referenced by all external
68008278a5eSRod Evans * callers. This symbol may have aliases. For example, a weak/global symbol
68108278a5eSRod Evans * pair, such as memcpy()/_memcpy() may lead the same capabilities family.
68208278a5eSRod Evans * Each family contains one or more local symbol members. These members provide
68308278a5eSRod Evans * the capabilities specific functions, and are associated to a capabilities
68408278a5eSRod Evans * group. For example, the capability members memcpy%sun4u and memcpy%sun4v
68508278a5eSRod Evans * might be associated with the memcpy() capability family.
68608278a5eSRod Evans *
68708278a5eSRod Evans * This routine is called when a relocatable object that provides object
68808278a5eSRod Evans * capabilities is transformed into a symbol capabilities object, using the
68908278a5eSRod Evans * -z symbolcap option.
69008278a5eSRod Evans *
69108278a5eSRod Evans * This routine is also called to collect the SUNW_capinfo section information
69208278a5eSRod Evans * of a relocatable object that contains symbol capability definitions.
69308278a5eSRod Evans */
69408278a5eSRod Evans uintptr_t
ld_cap_add_family(Ofl_desc * ofl,Sym_desc * lsdp,Sym_desc * csdp,Cap_group * cgp,APlist ** csyms)69508278a5eSRod Evans ld_cap_add_family(Ofl_desc *ofl, Sym_desc *lsdp, Sym_desc *csdp, Cap_group *cgp,
69608278a5eSRod Evans APlist **csyms)
69708278a5eSRod Evans {
69808278a5eSRod Evans Cap_avlnode qcav, *cav;
69908278a5eSRod Evans avl_tree_t *avlt;
70008278a5eSRod Evans avl_index_t where = 0;
70108278a5eSRod Evans Cap_sym *mcsp;
70208278a5eSRod Evans Aliste idx;
70308278a5eSRod Evans
70408278a5eSRod Evans /*
70508278a5eSRod Evans * Make sure the capability families have an initialized AVL tree.
70608278a5eSRod Evans */
70708278a5eSRod Evans if ((avlt = ofl->ofl_capfamilies) == NULL) {
70808278a5eSRod Evans if ((avlt = libld_calloc(sizeof (avl_tree_t), 1)) == NULL)
70908278a5eSRod Evans return (S_ERROR);
71008278a5eSRod Evans avl_create(avlt, &ld_sym_avl_comp, sizeof (Cap_avlnode),
71108278a5eSRod Evans SGSOFFSETOF(Cap_avlnode, cn_symavlnode.sav_node));
71208278a5eSRod Evans ofl->ofl_capfamilies = avlt;
71308278a5eSRod Evans
71408278a5eSRod Evans /*
71508278a5eSRod Evans * When creating a dynamic object, capability family members
71608278a5eSRod Evans * are maintained in a .SUNW_capchain, the first entry of
71708278a5eSRod Evans * which is the version number of the chain.
71808278a5eSRod Evans */
71908278a5eSRod Evans ofl->ofl_capchaincnt = 1;
72008278a5eSRod Evans }
72108278a5eSRod Evans
72208278a5eSRod Evans /*
72308278a5eSRod Evans * Determine whether a family already exists, and if not, create one
72408278a5eSRod Evans * using the lead family symbol.
72508278a5eSRod Evans */
72608278a5eSRod Evans qcav.cn_symavlnode.sav_hash = (Word)elf_hash(lsdp->sd_name);
72708278a5eSRod Evans qcav.cn_symavlnode.sav_name = lsdp->sd_name;
72808278a5eSRod Evans
72908278a5eSRod Evans if ((cav = avl_find(avlt, &qcav, &where)) == NULL) {
73008278a5eSRod Evans if ((cav = libld_calloc(sizeof (Cap_avlnode), 1)) == NULL)
73108278a5eSRod Evans return (S_ERROR);
73208278a5eSRod Evans cav->cn_symavlnode.sav_hash = qcav.cn_symavlnode.sav_hash;
73308278a5eSRod Evans cav->cn_symavlnode.sav_name = qcav.cn_symavlnode.sav_name;
73408278a5eSRod Evans cav->cn_symavlnode.sav_sdp = lsdp;
73508278a5eSRod Evans
73608278a5eSRod Evans avl_insert(avlt, cav, where);
73708278a5eSRod Evans
73808278a5eSRod Evans /*
73908278a5eSRod Evans * When creating a dynamic object, capability family members
74008278a5eSRod Evans * are maintained in a .SUNW_capchain, each family starts with
74108278a5eSRod Evans * this lead symbol, and is terminated with a 0 element.
74208278a5eSRod Evans */
74308278a5eSRod Evans ofl->ofl_capchaincnt += 2;
74408278a5eSRod Evans }
74508278a5eSRod Evans
74608278a5eSRod Evans /*
74708278a5eSRod Evans * If no group information is provided then this request is to add a
74808278a5eSRod Evans * lead capability symbol, or lead symbol alias. If this is the lead
74908278a5eSRod Evans * symbol there's nothing more to do. Otherwise save the alias.
75008278a5eSRod Evans */
75108278a5eSRod Evans if (cgp == NULL) {
75208278a5eSRod Evans if ((lsdp != csdp) && (aplist_append(&cav->cn_aliases, csdp,
75308278a5eSRod Evans AL_CNT_CAP_ALIASES) == NULL))
75408278a5eSRod Evans return (S_ERROR);
75508278a5eSRod Evans
75608278a5eSRod Evans return (0);
75708278a5eSRod Evans }
75808278a5eSRod Evans
75908278a5eSRod Evans /*
76008278a5eSRod Evans * Determine whether a member of the same group as this new member is
76108278a5eSRod Evans * already defined within this family. If so, we have a multiply
76208278a5eSRod Evans * defined symbol.
76308278a5eSRod Evans */
76408278a5eSRod Evans for (APLIST_TRAVERSE(cav->cn_members, idx, mcsp)) {
76508278a5eSRod Evans Sym_desc *msdp;
76608278a5eSRod Evans
76708278a5eSRod Evans if (cgp != mcsp->cs_group)
76808278a5eSRod Evans continue;
76908278a5eSRod Evans
77008278a5eSRod Evans /*
77108278a5eSRod Evans * Diagnose that a multiple symbol definition exists.
77208278a5eSRod Evans */
77308278a5eSRod Evans msdp = mcsp->cs_sdp;
77408278a5eSRod Evans
7751007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_CAP_MULDEF),
77608278a5eSRod Evans demangle(lsdp->sd_name));
7771007fd6fSAli Bahrami ld_eprintf(ofl, ERR_NONE, MSG_INTL(MSG_CAP_MULDEFSYMS),
77808278a5eSRod Evans msdp->sd_file->ifl_name, msdp->sd_name,
77908278a5eSRod Evans csdp->sd_file->ifl_name, csdp->sd_name);
78008278a5eSRod Evans }
78108278a5eSRod Evans
78208278a5eSRod Evans /*
78308278a5eSRod Evans * Add this capabilities symbol member to the family.
78408278a5eSRod Evans */
78508278a5eSRod Evans if (((mcsp = libld_malloc(sizeof (Cap_sym))) == NULL) ||
78608278a5eSRod Evans (aplist_append(&cav->cn_members, mcsp, AL_CNT_CAP_MEMS) == NULL))
78708278a5eSRod Evans return (S_ERROR);
78808278a5eSRod Evans
78908278a5eSRod Evans mcsp->cs_sdp = csdp;
79008278a5eSRod Evans mcsp->cs_group = cgp;
79108278a5eSRod Evans
79208278a5eSRod Evans /*
79308278a5eSRod Evans * When creating a dynamic object, capability family members are
79408278a5eSRod Evans * maintained in a .SUNW_capchain. Account for this family member.
79508278a5eSRod Evans */
79608278a5eSRod Evans ofl->ofl_capchaincnt++;
79708278a5eSRod Evans
79808278a5eSRod Evans /*
79908278a5eSRod Evans * If this input file is undergoing object capabilities to symbol
80008278a5eSRod Evans * capabilities conversion, then this member is a new local symbol
80108278a5eSRod Evans * that has been generated from an original global symbol. Keep track
80208278a5eSRod Evans * of this symbol so that the output file symbol table can be populated
80308278a5eSRod Evans * with these new symbol entries.
80408278a5eSRod Evans */
80508278a5eSRod Evans if (csyms && (aplist_append(csyms, mcsp, AL_CNT_CAP_SYMS) == NULL))
80608278a5eSRod Evans return (S_ERROR);
80708278a5eSRod Evans
80808278a5eSRod Evans return (0);
80908278a5eSRod Evans }
81008278a5eSRod Evans
81108278a5eSRod Evans /*
81208278a5eSRod Evans * Process a SHT_SUNW_cap capabilities section.
81308278a5eSRod Evans */
81408278a5eSRod Evans static uintptr_t
process_cap(Ofl_desc * ofl,Ifl_desc * ifl,Is_desc * cisp)81508278a5eSRod Evans process_cap(Ofl_desc *ofl, Ifl_desc *ifl, Is_desc *cisp)
81608278a5eSRod Evans {
81708278a5eSRod Evans Objcapset ocapset = { 0 };
81808278a5eSRod Evans Cap_desc *cdp;
81908278a5eSRod Evans Cap *data, *cdata;
82008278a5eSRod Evans char *strs;
82108278a5eSRod Evans Word ndx, cnum;
82208278a5eSRod Evans int objcapndx, descapndx, symcapndx;
82308278a5eSRod Evans int nulls, capstrs = 0;
82408278a5eSRod Evans
82508278a5eSRod Evans /*
82608278a5eSRod Evans * Determine the capabilities data and size.
827c75e1b9dSrie */
828c75e1b9dSrie cdata = (Cap *)cisp->is_indata->d_buf;
829c75e1b9dSrie cnum = (Word)(cisp->is_shdr->sh_size / cisp->is_shdr->sh_entsize);
830c75e1b9dSrie
83108278a5eSRod Evans if ((cdata == NULL) || (cnum == 0))
83208278a5eSRod Evans return (0);
83308278a5eSRod Evans
83408278a5eSRod Evans DBG_CALL(Dbg_cap_sec_title(ofl->ofl_lml, ifl->ifl_name));
83508278a5eSRod Evans
836bebb829dSRod Evans /*
83708278a5eSRod Evans * Traverse the section to determine what capabilities groups are
83808278a5eSRod Evans * available.
83908278a5eSRod Evans *
84008278a5eSRod Evans * A capabilities section can contain one or more, CA_SUNW_NULL
84108278a5eSRod Evans * terminated groups.
84208278a5eSRod Evans *
84308278a5eSRod Evans * - The first group defines the object capabilities.
84408278a5eSRod Evans * - Additional groups define symbol capabilities.
84508278a5eSRod Evans * - Since the initial group is always reserved for object
84608278a5eSRod Evans * capabilities, any object with symbol capabilities must also
84708278a5eSRod Evans * have an object capabilities group. If the object has no object
84808278a5eSRod Evans * capabilities, an empty object group is defined, consisting of a
84908278a5eSRod Evans * CA_SUNW_NULL element in index [0].
85008278a5eSRod Evans * - If any capabilities require references to a named string, then
85108278a5eSRod Evans * the section header sh_info points to the associated string
85208278a5eSRod Evans * table.
85308278a5eSRod Evans * - If an object contains symbol capability groups, then the
85408278a5eSRod Evans * section header sh_link points to the associated capinfo table.
855bebb829dSRod Evans */
85608278a5eSRod Evans objcapndx = 0;
85708278a5eSRod Evans descapndx = symcapndx = -1;
85808278a5eSRod Evans nulls = 0;
85908278a5eSRod Evans
86008278a5eSRod Evans for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
86108278a5eSRod Evans switch (data->c_tag) {
862c75e1b9dSrie case CA_SUNW_NULL:
86308278a5eSRod Evans /*
86408278a5eSRod Evans * If this is the first CA_SUNW_NULL entry, and no
86508278a5eSRod Evans * capabilities group has been found, then this object
86608278a5eSRod Evans * does not define any object capabilities.
86708278a5eSRod Evans */
86808278a5eSRod Evans if (nulls++ == 0) {
86908278a5eSRod Evans if (ndx == 0)
87008278a5eSRod Evans objcapndx = -1;
87108278a5eSRod Evans } else if ((symcapndx == -1) && (descapndx != -1))
87208278a5eSRod Evans symcapndx = descapndx;
87308278a5eSRod Evans
8747c478bd9Sstevel@tonic-gate break;
87508278a5eSRod Evans
87608278a5eSRod Evans case CA_SUNW_PLAT:
87708278a5eSRod Evans case CA_SUNW_MACH:
87808278a5eSRod Evans case CA_SUNW_ID:
87908278a5eSRod Evans capstrs++;
88008278a5eSRod Evans /* FALLTHROUGH */
88108278a5eSRod Evans
88208278a5eSRod Evans case CA_SUNW_HW_1:
88308278a5eSRod Evans case CA_SUNW_SF_1:
88408278a5eSRod Evans case CA_SUNW_HW_2:
88508278a5eSRod Evans /*
88608278a5eSRod Evans * If this is the start of a new group, save it.
88708278a5eSRod Evans */
88808278a5eSRod Evans if (descapndx == -1)
88908278a5eSRod Evans descapndx = ndx;
89008278a5eSRod Evans break;
89108278a5eSRod Evans
8927c478bd9Sstevel@tonic-gate default:
8931007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_UNKCAP),
8941007fd6fSAli Bahrami ifl->ifl_name, EC_WORD(cisp->is_scnndx),
8951007fd6fSAli Bahrami cisp->is_name, data->c_tag);
8967c478bd9Sstevel@tonic-gate }
8977c478bd9Sstevel@tonic-gate }
89808278a5eSRod Evans
89908278a5eSRod Evans /*
90008278a5eSRod Evans * If a string capabilities entry has been found, the capabilities
90108278a5eSRod Evans * section must reference the associated string table.
90208278a5eSRod Evans */
90308278a5eSRod Evans if (capstrs) {
90408278a5eSRod Evans Word info = cisp->is_shdr->sh_info;
90508278a5eSRod Evans
90608278a5eSRod Evans if ((info == 0) || (info > ifl->ifl_shnum)) {
9071007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHINFO),
9081007fd6fSAli Bahrami ifl->ifl_name, EC_WORD(cisp->is_scnndx),
9091007fd6fSAli Bahrami cisp->is_name, EC_XWORD(info));
91008278a5eSRod Evans return (S_ERROR);
91108278a5eSRod Evans }
91208278a5eSRod Evans strs = (char *)ifl->ifl_isdesc[info]->is_indata->d_buf;
91308278a5eSRod Evans }
91408278a5eSRod Evans
91508278a5eSRod Evans /*
91608278a5eSRod Evans * The processing of capabilities groups is as follows:
91708278a5eSRod Evans *
91808278a5eSRod Evans * - if a relocatable object provides only object capabilities, and
91908278a5eSRod Evans * the -z symbolcap option is in effect, then the object
92008278a5eSRod Evans * capabilities are transformed into symbol capabilities and the
92108278a5eSRod Evans * symbol capabilities are carried over to the output file.
92208278a5eSRod Evans * - in all other cases, any capabilities present in an input
92308278a5eSRod Evans * relocatable object are carried from the input object to the
92408278a5eSRod Evans * output without any transformation or conversion.
92508278a5eSRod Evans *
92608278a5eSRod Evans * Capture any object capabilities that are to be carried over to the
92708278a5eSRod Evans * output file.
92808278a5eSRod Evans */
92908278a5eSRod Evans if ((objcapndx == 0) &&
93008278a5eSRod Evans ((symcapndx != -1) || ((ofl->ofl_flags & FLG_OF_OTOSCAP) == 0))) {
93108278a5eSRod Evans for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
93208278a5eSRod Evans /*
93308278a5eSRod Evans * Object capabilities end at the first null.
93408278a5eSRod Evans */
93508278a5eSRod Evans if (data->c_tag == CA_SUNW_NULL)
93608278a5eSRod Evans break;
93708278a5eSRod Evans
93808278a5eSRod Evans /*
93908278a5eSRod Evans * Only the object software capabilities that are
94008278a5eSRod Evans * defined in a relocatable object become part of the
94108278a5eSRod Evans * object software capabilities in the output file.
94208278a5eSRod Evans * However, check the validity of any object software
94308278a5eSRod Evans * capabilities of any dependencies.
94408278a5eSRod Evans */
94508278a5eSRod Evans if (data->c_tag == CA_SUNW_SF_1) {
94608278a5eSRod Evans sf1_cap(ofl, data->c_un.c_val, ifl, cisp);
94708278a5eSRod Evans continue;
94808278a5eSRod Evans }
94908278a5eSRod Evans
95008278a5eSRod Evans /*
95108278a5eSRod Evans * The remaining capability types must come from a
95208278a5eSRod Evans * relocatable object in order to contribute to the
95308278a5eSRod Evans * output.
95408278a5eSRod Evans */
95508278a5eSRod Evans if (ifl->ifl_ehdr->e_type != ET_REL)
95608278a5eSRod Evans continue;
95708278a5eSRod Evans
95808278a5eSRod Evans switch (data->c_tag) {
95908278a5eSRod Evans case CA_SUNW_HW_1:
96008278a5eSRod Evans case CA_SUNW_HW_2:
96108278a5eSRod Evans hw_cap(ofl, data->c_tag, data->c_un.c_val);
96208278a5eSRod Evans break;
96308278a5eSRod Evans
96408278a5eSRod Evans case CA_SUNW_PLAT:
96508278a5eSRod Evans str_cap(ofl, strs + data->c_un.c_ptr,
96608278a5eSRod Evans FLG_OF1_OVPLATCAP, CA_SUNW_PLAT,
96708278a5eSRod Evans &ofl->ofl_ocapset.oc_plat);
96808278a5eSRod Evans break;
96908278a5eSRod Evans
97008278a5eSRod Evans case CA_SUNW_MACH:
97108278a5eSRod Evans str_cap(ofl, strs + data->c_un.c_ptr,
97208278a5eSRod Evans FLG_OF1_OVMACHCAP, CA_SUNW_MACH,
97308278a5eSRod Evans &ofl->ofl_ocapset.oc_mach);
97408278a5eSRod Evans break;
97508278a5eSRod Evans
97608278a5eSRod Evans case CA_SUNW_ID:
97708278a5eSRod Evans id_cap(ofl, strs + data->c_un.c_ptr,
97808278a5eSRod Evans FLG_OCS_USRDEFID);
97908278a5eSRod Evans break;
98008278a5eSRod Evans
98108278a5eSRod Evans default:
98208278a5eSRod Evans assert(0); /* Unknown capability type */
98308278a5eSRod Evans }
98408278a5eSRod Evans }
98508278a5eSRod Evans
98608278a5eSRod Evans /*
98708278a5eSRod Evans * If there are no symbol capabilities, or this objects
98808278a5eSRod Evans * capabilities aren't being transformed into a symbol
98908278a5eSRod Evans * capabilities, then we're done.
99008278a5eSRod Evans */
99108278a5eSRod Evans if ((symcapndx == -1) &&
99208278a5eSRod Evans ((ofl->ofl_flags & FLG_OF_OTOSCAP) == 0))
99308278a5eSRod Evans return (1);
99408278a5eSRod Evans }
99508278a5eSRod Evans
99608278a5eSRod Evans /*
99708278a5eSRod Evans * If these capabilities don't originate from a relocatable object
99808278a5eSRod Evans * there's no further processing required.
99908278a5eSRod Evans */
100008278a5eSRod Evans if (ifl->ifl_ehdr->e_type != ET_REL)
100108278a5eSRod Evans return (1);
100208278a5eSRod Evans
100308278a5eSRod Evans /*
100408278a5eSRod Evans * If this object only defines an object capabilities group, and the
100508278a5eSRod Evans * -z symbolcap option is in effect, then all global function symbols
100608278a5eSRod Evans * and initialized global data symbols are renamed and assigned to the
100708278a5eSRod Evans * transformed symbol capabilities group.
100808278a5eSRod Evans */
100908278a5eSRod Evans if ((objcapndx == 0) &&
101008278a5eSRod Evans (symcapndx == -1) && (ofl->ofl_flags & FLG_OF_OTOSCAP))
101108278a5eSRod Evans ifl->ifl_flags |= FLG_IF_OTOSCAP;
101208278a5eSRod Evans
101308278a5eSRod Evans /*
101408278a5eSRod Evans * Allocate a capabilities descriptor to collect the capabilities data
101508278a5eSRod Evans * for this input file. Allocate a mirror of the raw capabilities data
101608278a5eSRod Evans * that points to the individual symbol capabilities groups. An APlist
101708278a5eSRod Evans * is used, although it will be sparsely populated, as the list provides
101808278a5eSRod Evans * a convenient mechanism for traversal later.
101908278a5eSRod Evans */
102008278a5eSRod Evans if (((cdp = libld_calloc(sizeof (Cap_desc), 1)) == NULL) ||
102108278a5eSRod Evans (aplist_append(&(cdp->ca_groups), NULL, cnum) == NULL))
102208278a5eSRod Evans return (S_ERROR);
102308278a5eSRod Evans
102408278a5eSRod Evans /*
102508278a5eSRod Evans * Clear the allocated APlist data array, and assign the number of
102608278a5eSRod Evans * items as the total number of array items.
102708278a5eSRod Evans */
102808278a5eSRod Evans (void) memset(&cdp->ca_groups->apl_data[0], 0,
102908278a5eSRod Evans (cnum * sizeof (void *)));
103008278a5eSRod Evans cdp->ca_groups->apl_nitems = cnum;
103108278a5eSRod Evans
103208278a5eSRod Evans ifl->ifl_caps = cdp;
103308278a5eSRod Evans
103408278a5eSRod Evans /*
103508278a5eSRod Evans * Traverse the capabilities data, unpacking the data into a
103608278a5eSRod Evans * capabilities set. Process each capabilities set as a unique group.
103708278a5eSRod Evans */
103808278a5eSRod Evans descapndx = -1;
103908278a5eSRod Evans nulls = 0;
104008278a5eSRod Evans
104108278a5eSRod Evans for (ndx = 0, data = cdata; ndx < cnum; ndx++, data++) {
104208278a5eSRod Evans Capstr *capstr;
104308278a5eSRod Evans
104408278a5eSRod Evans switch (data->c_tag) {
104508278a5eSRod Evans case CA_SUNW_NULL:
104608278a5eSRod Evans nulls++;
104708278a5eSRod Evans
104808278a5eSRod Evans /*
104908278a5eSRod Evans * Process the capabilities group that this null entry
105008278a5eSRod Evans * terminates. The capabilities group that is returned
105108278a5eSRod Evans * will either point to this file's data, or to a
105208278a5eSRod Evans * matching capabilities group that has already been
105308278a5eSRod Evans * processed.
105408278a5eSRod Evans *
105508278a5eSRod Evans * Note, if this object defines object capabilities,
105608278a5eSRod Evans * the first group descriptor points to these object
105708278a5eSRod Evans * capabilities. It is only necessary to save this
105808278a5eSRod Evans * descriptor when object capabilities are being
105908278a5eSRod Evans * transformed into symbol capabilities (-z symbolcap).
106008278a5eSRod Evans */
106108278a5eSRod Evans if (descapndx != -1) {
106208278a5eSRod Evans if ((nulls > 1) ||
106308278a5eSRod Evans (ifl->ifl_flags & FLG_IF_OTOSCAP)) {
106408278a5eSRod Evans APlist *alp = cdp->ca_groups;
106508278a5eSRod Evans
106608278a5eSRod Evans if ((alp->apl_data[descapndx] =
106708278a5eSRod Evans get_cap_group(&ocapset,
106808278a5eSRod Evans (ndx - descapndx), ofl,
106908278a5eSRod Evans cisp)) == NULL)
107008278a5eSRod Evans return (S_ERROR);
107108278a5eSRod Evans }
107208278a5eSRod Evans
107308278a5eSRod Evans /*
107408278a5eSRod Evans * Clean up the capabilities data in preparation
107508278a5eSRod Evans * for processing additional groups. If the
107608278a5eSRod Evans * collected capabilities strings were used to
107708278a5eSRod Evans * establish a new output group, they will have
107808278a5eSRod Evans * been saved in get_cap_group(). If these
107908278a5eSRod Evans * descriptors still exist, then an existing
108008278a5eSRod Evans * descriptor has been used to associate with
108108278a5eSRod Evans * this file, and these string descriptors can
108208278a5eSRod Evans * be freed.
108308278a5eSRod Evans */
108408278a5eSRod Evans ocapset.oc_hw_1.cm_val =
108508278a5eSRod Evans ocapset.oc_sf_1.cm_val =
108608278a5eSRod Evans ocapset.oc_hw_2.cm_val = 0;
108708278a5eSRod Evans if (ocapset.oc_plat.cl_val) {
108808278a5eSRod Evans free((void *)ocapset.oc_plat.cl_val);
108908278a5eSRod Evans ocapset.oc_plat.cl_val = NULL;
109008278a5eSRod Evans }
109108278a5eSRod Evans if (ocapset.oc_mach.cl_val) {
109208278a5eSRod Evans free((void *)ocapset.oc_mach.cl_val);
109308278a5eSRod Evans ocapset.oc_mach.cl_val = NULL;
109408278a5eSRod Evans }
109508278a5eSRod Evans descapndx = -1;
109608278a5eSRod Evans }
109708278a5eSRod Evans continue;
109808278a5eSRod Evans
109908278a5eSRod Evans case CA_SUNW_HW_1:
110008278a5eSRod Evans ocapset.oc_hw_1.cm_val = data->c_un.c_val;
110108278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
110208278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_HW_1,
110308278a5eSRod Evans ocapset.oc_hw_1.cm_val, ld_targ.t_m.m_mach));
110408278a5eSRod Evans break;
110508278a5eSRod Evans
110608278a5eSRod Evans case CA_SUNW_SF_1:
110708278a5eSRod Evans ocapset.oc_sf_1.cm_val = data->c_un.c_val;
110808278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
110908278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_SF_1,
111008278a5eSRod Evans ocapset.oc_sf_1.cm_val, ld_targ.t_m.m_mach));
111108278a5eSRod Evans break;
111208278a5eSRod Evans
111308278a5eSRod Evans case CA_SUNW_HW_2:
111408278a5eSRod Evans ocapset.oc_hw_2.cm_val = data->c_un.c_val;
111508278a5eSRod Evans DBG_CALL(Dbg_cap_val_entry(ofl->ofl_lml,
111608278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_HW_2,
111708278a5eSRod Evans ocapset.oc_hw_2.cm_val, ld_targ.t_m.m_mach));
111808278a5eSRod Evans break;
111908278a5eSRod Evans
112008278a5eSRod Evans case CA_SUNW_PLAT:
112108278a5eSRod Evans if ((capstr = alist_append(&ocapset.oc_plat.cl_val,
112208278a5eSRod Evans NULL, sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL)
112308278a5eSRod Evans return (S_ERROR);
112408278a5eSRod Evans capstr->cs_str = strs + data->c_un.c_ptr;
112508278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
112608278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_PLAT, capstr->cs_str));
112708278a5eSRod Evans break;
112808278a5eSRod Evans
112908278a5eSRod Evans case CA_SUNW_MACH:
113008278a5eSRod Evans if ((capstr = alist_append(&ocapset.oc_mach.cl_val,
113108278a5eSRod Evans NULL, sizeof (Capstr), AL_CNT_CAP_NAMES)) == NULL)
113208278a5eSRod Evans return (S_ERROR);
113308278a5eSRod Evans capstr->cs_str = strs + data->c_un.c_ptr;
113408278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
113508278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_MACH, capstr->cs_str));
113608278a5eSRod Evans break;
113708278a5eSRod Evans
113808278a5eSRod Evans case CA_SUNW_ID:
113908278a5eSRod Evans ocapset.oc_id.cs_str = strs + data->c_un.c_ptr;
114008278a5eSRod Evans DBG_CALL(Dbg_cap_ptr_entry(ofl->ofl_lml,
114108278a5eSRod Evans DBG_STATE_ORIGINAL, CA_SUNW_ID,
114208278a5eSRod Evans ocapset.oc_id.cs_str));
114308278a5eSRod Evans break;
114408278a5eSRod Evans }
114508278a5eSRod Evans
114608278a5eSRod Evans /*
114708278a5eSRod Evans * Save the start of this new group.
114808278a5eSRod Evans */
114908278a5eSRod Evans if (descapndx == -1)
115008278a5eSRod Evans descapndx = ndx;
115108278a5eSRod Evans }
115208278a5eSRod Evans return (1);
115308278a5eSRod Evans }
115408278a5eSRod Evans
115508278a5eSRod Evans /*
115608278a5eSRod Evans * Capture any symbol capabilities symbols. An object file that contains symbol
115708278a5eSRod Evans * capabilities has an associated .SUNW_capinfo section. This section
115808278a5eSRod Evans * identifies which symbols are associated to which capabilities, together with
115908278a5eSRod Evans * their associated lead symbol. Each of these symbol pairs are recorded for
116008278a5eSRod Evans * processing later.
116108278a5eSRod Evans */
116208278a5eSRod Evans static uintptr_t
process_capinfo(Ofl_desc * ofl,Ifl_desc * ifl,Is_desc * isp)116308278a5eSRod Evans process_capinfo(Ofl_desc *ofl, Ifl_desc *ifl, Is_desc *isp)
116408278a5eSRod Evans {
116508278a5eSRod Evans Cap_desc *cdp = ifl->ifl_caps;
116608278a5eSRod Evans Capinfo *capinfo = isp->is_indata->d_buf;
116708278a5eSRod Evans Shdr *shdr = isp->is_shdr;
116808278a5eSRod Evans Word cndx, capinfonum;
116908278a5eSRod Evans
117008278a5eSRod Evans capinfonum = (Word)(shdr->sh_size / shdr->sh_entsize);
117108278a5eSRod Evans
117208278a5eSRod Evans if ((cdp == NULL) || (capinfo == NULL) || (capinfonum == 0))
117308278a5eSRod Evans return (0);
117408278a5eSRod Evans
117508278a5eSRod Evans for (cndx = 1, capinfo++; cndx < capinfonum; cndx++, capinfo++) {
117608278a5eSRod Evans Sym_desc *sdp, *lsdp;
117708278a5eSRod Evans Word lndx;
117808278a5eSRod Evans uchar_t gndx;
117908278a5eSRod Evans
118008278a5eSRod Evans if ((gndx = (uchar_t)ELF_C_GROUP(*capinfo)) == 0)
118108278a5eSRod Evans continue;
118208278a5eSRod Evans lndx = (Word)ELF_C_SYM(*capinfo);
118308278a5eSRod Evans
118408278a5eSRod Evans /*
118508278a5eSRod Evans * Catch any anomalies. A capabilities symbol should be valid,
118608278a5eSRod Evans * and the capabilities lead symbol should also be global.
118708278a5eSRod Evans * Note, ld(1) -z symbolcap would create local capabilities
118808278a5eSRod Evans * symbols, but we don't enforce this so as to give the
118908278a5eSRod Evans * compilation environment a little more freedom.
119008278a5eSRod Evans */
119108278a5eSRod Evans if ((sdp = ifl->ifl_oldndx[cndx]) == NULL) {
11921007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
119308278a5eSRod Evans MSG_INTL(MSG_CAPINFO_INVALSYM), ifl->ifl_name,
119408278a5eSRod Evans EC_WORD(isp->is_scnndx), isp->is_name, cndx,
119508278a5eSRod Evans MSG_INTL(MSG_STR_UNKNOWN));
119608278a5eSRod Evans continue;
119708278a5eSRod Evans }
119808278a5eSRod Evans if ((lndx == 0) || (lndx >= ifl->ifl_symscnt) ||
119908278a5eSRod Evans ((lsdp = ifl->ifl_oldndx[lndx]) == NULL) ||
120008278a5eSRod Evans (ELF_ST_BIND(lsdp->sd_sym->st_info) != STB_GLOBAL)) {
12011007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
120208278a5eSRod Evans MSG_INTL(MSG_CAPINFO_INVALLEAD), ifl->ifl_name,
120308278a5eSRod Evans EC_WORD(isp->is_scnndx), isp->is_name, cndx, lsdp ?
120408278a5eSRod Evans demangle(lsdp->sd_name) : MSG_INTL(MSG_STR_UNKNOWN),
120508278a5eSRod Evans lndx);
120608278a5eSRod Evans continue;
120708278a5eSRod Evans }
120808278a5eSRod Evans
120908278a5eSRod Evans /*
121008278a5eSRod Evans * Indicate that this is a capabilities symbol.
121108278a5eSRod Evans */
121208278a5eSRod Evans sdp->sd_flags |= FLG_SY_CAP;
121308278a5eSRod Evans
121408278a5eSRod Evans /*
121508278a5eSRod Evans * Save any global capability symbols. Global capability
121608278a5eSRod Evans * symbols are identified with a CAPINFO_SUNW_GLOB group id.
121708278a5eSRod Evans * The lead symbol for this global capability symbol is either
121808278a5eSRod Evans * the symbol itself, or an alias.
121908278a5eSRod Evans */
122008278a5eSRod Evans if (gndx == CAPINFO_SUNW_GLOB) {
122108278a5eSRod Evans if (ld_cap_add_family(ofl, lsdp, sdp,
122208278a5eSRod Evans NULL, NULL) == S_ERROR)
122308278a5eSRod Evans return (S_ERROR);
122408278a5eSRod Evans continue;
122508278a5eSRod Evans }
122608278a5eSRod Evans
122708278a5eSRod Evans /*
122808278a5eSRod Evans * Track the number of non-global capabilities symbols, as these
122908278a5eSRod Evans * are used to size any symbol tables. If we're generating a
123008278a5eSRod Evans * dynamic object, this symbol will be added to the dynamic
123108278a5eSRod Evans * symbol table, therefore ensure there is space in the dynamic
123208278a5eSRod Evans * string table.
123308278a5eSRod Evans */
123408278a5eSRod Evans ofl->ofl_caploclcnt++;
123508278a5eSRod Evans if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) &&
123608278a5eSRod Evans (st_insert(ofl->ofl_dynstrtab, sdp->sd_name) == -1))
123708278a5eSRod Evans return (S_ERROR);
123808278a5eSRod Evans
123908278a5eSRod Evans /*
124008278a5eSRod Evans * As we're tracking this local symbol as a capabilities symbol,
124108278a5eSRod Evans * reduce the local symbol count to compensate.
124208278a5eSRod Evans */
124308278a5eSRod Evans ofl->ofl_locscnt--;
124408278a5eSRod Evans
124508278a5eSRod Evans /*
124608278a5eSRod Evans * Determine whether the associated lead symbol indicates
124708278a5eSRod Evans * NODYNSORT. If so, remove this local entry from the
124808278a5eSRod Evans * SUNW_dynsort section too. NODYNSORT tagging can only be
124908278a5eSRod Evans * obtained from a mapfile symbol definition, and thus any
125008278a5eSRod Evans * global definition that has this tagging has already been
125108278a5eSRod Evans * instantiated and this instance resolved to it.
125208278a5eSRod Evans */
125308278a5eSRod Evans if (lsdp->sd_flags & FLG_SY_NODYNSORT) {
125408278a5eSRod Evans Sym *lsym = lsdp->sd_sym;
125508278a5eSRod Evans uchar_t ltype = ELF_ST_TYPE(lsym->st_info);
125608278a5eSRod Evans
125708278a5eSRod Evans DYNSORT_COUNT(lsdp, lsym, ltype, --);
125808278a5eSRod Evans lsdp->sd_flags |= FLG_SY_NODYNSORT;
125908278a5eSRod Evans }
126008278a5eSRod Evans
126108278a5eSRod Evans /*
126208278a5eSRod Evans * Track this family member, together with its associated group.
126308278a5eSRod Evans */
126408278a5eSRod Evans if (ld_cap_add_family(ofl, lsdp, sdp,
126508278a5eSRod Evans cdp->ca_groups->apl_data[gndx], NULL) == S_ERROR)
126608278a5eSRod Evans return (S_ERROR);
126708278a5eSRod Evans }
126808278a5eSRod Evans
126908278a5eSRod Evans return (0);
12707c478bd9Sstevel@tonic-gate }
12717c478bd9Sstevel@tonic-gate
12727c478bd9Sstevel@tonic-gate /*
12737c478bd9Sstevel@tonic-gate * Simply process the section so that we have pointers to the data for use
12747c478bd9Sstevel@tonic-gate * in later routines, however don't add the section to the output section
12757c478bd9Sstevel@tonic-gate * list as we will be creating our own replacement sections later (ie.
12767c478bd9Sstevel@tonic-gate * symtab and relocation).
12777c478bd9Sstevel@tonic-gate */
12785aefb655Srie static uintptr_t
12797c478bd9Sstevel@tonic-gate /* ARGSUSED5 */
process_input(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)12807c478bd9Sstevel@tonic-gate process_input(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
12817c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
12827c478bd9Sstevel@tonic-gate {
1283ba2be530Sab196087 return (process_section(name, ifl, shdr, scn, ndx,
1284ba2be530Sab196087 ld_targ.t_id.id_null, ofl));
12857c478bd9Sstevel@tonic-gate }
12867c478bd9Sstevel@tonic-gate
12877c478bd9Sstevel@tonic-gate /*
12887c478bd9Sstevel@tonic-gate * Keep a running count of relocation entries from input relocatable objects for
12897c478bd9Sstevel@tonic-gate * sizing relocation buckets later. If we're building an executable, save any
12907c478bd9Sstevel@tonic-gate * relocations from shared objects to determine if any copy relocation symbol
12917c478bd9Sstevel@tonic-gate * has a displacement relocation against it.
12927c478bd9Sstevel@tonic-gate */
12935aefb655Srie static uintptr_t
12947c478bd9Sstevel@tonic-gate /* ARGSUSED5 */
process_reloc(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)12957c478bd9Sstevel@tonic-gate process_reloc(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
12967c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
12977c478bd9Sstevel@tonic-gate {
12987c478bd9Sstevel@tonic-gate if (process_section(name, ifl,
1299ba2be530Sab196087 shdr, scn, ndx, ld_targ.t_id.id_null, ofl) == S_ERROR)
13007c478bd9Sstevel@tonic-gate return (S_ERROR);
13017c478bd9Sstevel@tonic-gate
13027c478bd9Sstevel@tonic-gate if (ifl->ifl_ehdr->e_type == ET_REL) {
13037c478bd9Sstevel@tonic-gate if (shdr->sh_entsize && (shdr->sh_entsize <= shdr->sh_size))
13047c478bd9Sstevel@tonic-gate /* LINTED */
13057c478bd9Sstevel@tonic-gate ofl->ofl_relocincnt +=
13067c478bd9Sstevel@tonic-gate (Word)(shdr->sh_size / shdr->sh_entsize);
13077c478bd9Sstevel@tonic-gate } else if (ofl->ofl_flags & FLG_OF_EXEC) {
130857ef7aa9SRod Evans if (aplist_append(&ifl->ifl_relsect, ifl->ifl_isdesc[ndx],
130957ef7aa9SRod Evans AL_CNT_IFL_RELSECS) == NULL)
13107c478bd9Sstevel@tonic-gate return (S_ERROR);
13117c478bd9Sstevel@tonic-gate }
13127c478bd9Sstevel@tonic-gate return (1);
13137c478bd9Sstevel@tonic-gate }
13147c478bd9Sstevel@tonic-gate
13157c478bd9Sstevel@tonic-gate /*
13167c478bd9Sstevel@tonic-gate * Process a string table section. A valid section contains an initial and
13177c478bd9Sstevel@tonic-gate * final null byte.
13187c478bd9Sstevel@tonic-gate */
13195aefb655Srie static uintptr_t
process_strtab(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)13207c478bd9Sstevel@tonic-gate process_strtab(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
13217c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
13227c478bd9Sstevel@tonic-gate {
13237c478bd9Sstevel@tonic-gate char *data;
13247c478bd9Sstevel@tonic-gate size_t size;
13257c478bd9Sstevel@tonic-gate Is_desc *isp;
13267c478bd9Sstevel@tonic-gate uintptr_t error;
13277c478bd9Sstevel@tonic-gate
13287c478bd9Sstevel@tonic-gate /*
13297c478bd9Sstevel@tonic-gate * Never include .stab.excl sections in any output file.
13307c478bd9Sstevel@tonic-gate * If the -s flag has been specified strip any .stab sections.
13317c478bd9Sstevel@tonic-gate */
13327c478bd9Sstevel@tonic-gate if (((ofl->ofl_flags & FLG_OF_STRIP) && ident &&
13337c478bd9Sstevel@tonic-gate (strncmp(name, MSG_ORIG(MSG_SCN_STAB), MSG_SCN_STAB_SIZE) == 0)) ||
13347c478bd9Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_STABEXCL)) == 0) && ident)
13357c478bd9Sstevel@tonic-gate return (1);
13367c478bd9Sstevel@tonic-gate
13377c478bd9Sstevel@tonic-gate /*
13387c478bd9Sstevel@tonic-gate * If we got here to process a .shstrtab or .dynstr table, `ident' will
13397c478bd9Sstevel@tonic-gate * be null. Otherwise make sure we don't have a .strtab section as this
13407c478bd9Sstevel@tonic-gate * should not be added to the output section list either.
13417c478bd9Sstevel@tonic-gate */
1342ba2be530Sab196087 if ((ident != ld_targ.t_id.id_null) &&
13437c478bd9Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_STRTAB)) == 0))
1344ba2be530Sab196087 ident = ld_targ.t_id.id_null;
13457c478bd9Sstevel@tonic-gate
13467c478bd9Sstevel@tonic-gate error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
13477c478bd9Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR))
13487c478bd9Sstevel@tonic-gate return (error);
13497c478bd9Sstevel@tonic-gate
13507c478bd9Sstevel@tonic-gate /*
13517c478bd9Sstevel@tonic-gate * String tables should start and end with a NULL byte. Note, it has
13527c478bd9Sstevel@tonic-gate * been known for the assembler to create empty string tables, so check
13537c478bd9Sstevel@tonic-gate * the size before attempting to verify the data itself.
13547c478bd9Sstevel@tonic-gate */
13557c478bd9Sstevel@tonic-gate isp = ifl->ifl_isdesc[ndx];
13567c478bd9Sstevel@tonic-gate size = isp->is_indata->d_size;
13577c478bd9Sstevel@tonic-gate if (size) {
13587c478bd9Sstevel@tonic-gate data = isp->is_indata->d_buf;
13597c478bd9Sstevel@tonic-gate if (data[0] != '\0' || data[size - 1] != '\0')
13601007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
13614a8d0ea7SAli Bahrami MSG_INTL(MSG_FIL_MALSTR), ifl->ifl_name,
13624a8d0ea7SAli Bahrami EC_WORD(isp->is_scnndx), name);
13637c478bd9Sstevel@tonic-gate } else
13647c478bd9Sstevel@tonic-gate isp->is_indata->d_buf = (void *)MSG_ORIG(MSG_STR_EMPTY);
13657c478bd9Sstevel@tonic-gate
13667c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_HSTRTAB;
13677c478bd9Sstevel@tonic-gate return (1);
13687c478bd9Sstevel@tonic-gate }
13697c478bd9Sstevel@tonic-gate
13707c478bd9Sstevel@tonic-gate /*
13717c478bd9Sstevel@tonic-gate * Invalid sections produce a warning and are skipped.
13727c478bd9Sstevel@tonic-gate */
13735aefb655Srie static uintptr_t
13747c478bd9Sstevel@tonic-gate /* ARGSUSED3 */
invalid_section(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)13757c478bd9Sstevel@tonic-gate invalid_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
13767c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
13777c478bd9Sstevel@tonic-gate {
1378de777a60Sab196087 Conv_inv_buf_t inv_buf;
1379de777a60Sab196087
13801007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_INVALSEC),
13814a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(ndx), name,
13824f680cc6SAli Bahrami conv_sec_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
13834f680cc6SAli Bahrami ifl->ifl_ehdr->e_machine, shdr->sh_type, 0, &inv_buf));
13847c478bd9Sstevel@tonic-gate return (1);
13857c478bd9Sstevel@tonic-gate }
13867c478bd9Sstevel@tonic-gate
13877c478bd9Sstevel@tonic-gate /*
13883f768744SAli Bahrami * Compare an input section name to a given string, taking the ELF '%'
13893f768744SAli Bahrami * section naming convention into account. If an input section name
13903f768744SAli Bahrami * contains a '%' character, the '%' and all following characters are
13913f768744SAli Bahrami * ignored in the comparison.
13923f768744SAli Bahrami *
13933f768744SAli Bahrami * entry:
13943f768744SAli Bahrami * is_name - Name of input section
13953f768744SAli Bahrami * match_name - Name to compare to
13963f768744SAli Bahrami * match_len - strlen(match_name)
13973f768744SAli Bahrami *
13983f768744SAli Bahrami * exit:
13993f768744SAli Bahrami * Returns True (1) if the names match, and False (0) otherwise.
14003f768744SAli Bahrami */
14013f768744SAli Bahrami inline static int
is_name_cmp(const char * is_name,const char * match_name,size_t match_len)14023f768744SAli Bahrami is_name_cmp(const char *is_name, const char *match_name, size_t match_len)
14033f768744SAli Bahrami {
14043f768744SAli Bahrami /*
14053f768744SAli Bahrami * If the start of is_name is not a match for name,
14063f768744SAli Bahrami * the match fails.
14073f768744SAli Bahrami */
14083f768744SAli Bahrami if (strncmp(is_name, match_name, match_len) != 0)
14093f768744SAli Bahrami return (0);
14103f768744SAli Bahrami
14113f768744SAli Bahrami /*
14123f768744SAli Bahrami * The prefix matched. The next character must be either '%', or
14133f768744SAli Bahrami * NULL, in order for a match to be true.
14143f768744SAli Bahrami */
14153f768744SAli Bahrami is_name += match_len;
14163f768744SAli Bahrami return ((*is_name == '\0') || (*is_name == '%'));
14173f768744SAli Bahrami }
14183f768744SAli Bahrami
14193f768744SAli Bahrami /*
1420d444b03eSAli Bahrami * Helper routine for process_progbits() to process allocable sections.
1421d444b03eSAli Bahrami *
1422d444b03eSAli Bahrami * entry:
1423d444b03eSAli Bahrami * name, ifl, shdr, ndx, ident, ofl - As passed to process_progbits().
1424d444b03eSAli Bahrami * is_stab_index - TRUE if section is .index.
1425d444b03eSAli Bahrami * is_flags - Additional flags to be added to the input section.
1426d444b03eSAli Bahrami *
1427d444b03eSAli Bahrami * exit:
1428d444b03eSAli Bahrami * The allocable section has been processed. *ident and *is_flags
1429d444b03eSAli Bahrami * are updated as necessary to reflect the changes. Returns TRUE
1430d444b03eSAli Bahrami * for success, FALSE for failure.
1431d444b03eSAli Bahrami */
14323fc1e289SBryan Cantrill /*ARGSUSED*/
1433d444b03eSAli 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)1434d444b03eSAli Bahrami process_progbits_alloc(const char *name, Ifl_desc *ifl, Shdr *shdr,
1435d444b03eSAli Bahrami Word ndx, int *ident, Ofl_desc *ofl, Boolean is_stab_index,
1436d444b03eSAli Bahrami Word *is_flags)
1437d444b03eSAli Bahrami {
1438d444b03eSAli Bahrami Boolean done = FALSE;
1439d444b03eSAli Bahrami
1440d444b03eSAli Bahrami if (name[0] == '.') {
1441d444b03eSAli Bahrami switch (name[1]) {
1442d444b03eSAli Bahrami case 'e':
1443d444b03eSAli Bahrami if (!is_name_cmp(name, MSG_ORIG(MSG_SCN_EHFRAME),
1444d444b03eSAli Bahrami MSG_SCN_EHFRAME_SIZE))
1445d444b03eSAli Bahrami break;
1446d444b03eSAli Bahrami
1447d444b03eSAli Bahrami *ident = ld_targ.t_id.id_unwind;
1448d444b03eSAli Bahrami *is_flags |= FLG_IS_EHFRAME;
1449d444b03eSAli Bahrami done = TRUE;
1450d444b03eSAli Bahrami
1451d444b03eSAli Bahrami /*
14523fc1e289SBryan Cantrill * Historically, the section containing the logic to
14533fc1e289SBryan Cantrill * unwind stack frames -- the .eh_frame section -- was
14543fc1e289SBryan Cantrill * of type SHT_PROGBITS. Apparently the most
14553fc1e289SBryan Cantrill * aesthetically galling aspect of this was not the
14563fc1e289SBryan Cantrill * .eh_frame section's dubious purpose or its filthy
14573fc1e289SBryan Cantrill * implementation, but rather its section type; with the
14583fc1e289SBryan Cantrill * introduction of the AMD64 ABI, a new section header
14593fc1e289SBryan Cantrill * type (SHT_AMD64_UNWIND) was introduced for (and
14603fc1e289SBryan Cantrill * dedicated to) this section. When both the Sun
14613fc1e289SBryan Cantrill * compilers and the GNU compilers had been modified to
14623fc1e289SBryan Cantrill * generate this new section type, the linker became
14633fc1e289SBryan Cantrill * much more pedantic about .eh_frame: it refused to
14643fc1e289SBryan Cantrill * link an AMD64 object that contained a .eh_frame with
14653fc1e289SBryan Cantrill * the legacy SHT_PROGBITS. That this was too fussy is
14663fc1e289SBryan Cantrill * evidenced by searching the net for the error message
14673fc1e289SBryan Cantrill * that it generated ("section type is SHT_PROGBITS:
14683fc1e289SBryan Cantrill * expected SHT_AMD64_UNWIND"), which reveals a myriad
14693fc1e289SBryan Cantrill * of problems, including legacy objects, hand-coded
14703fc1e289SBryan Cantrill * assembly and otherwise cross-platform objects
14713fc1e289SBryan Cantrill * created on other platforms (the GNU toolchain was
14723fc1e289SBryan Cantrill * only modified to create the new section type on
14733fc1e289SBryan Cantrill * Solaris and derivatives). We therefore always accept
14743fc1e289SBryan Cantrill * a .eh_frame of SHT_PROGBITS -- regardless of
14753fc1e289SBryan Cantrill * m_sht_unwind.
1476d444b03eSAli Bahrami */
1477d444b03eSAli Bahrami break;
1478d444b03eSAli Bahrami case 'g':
1479d444b03eSAli Bahrami if (is_name_cmp(name, MSG_ORIG(MSG_SCN_GOT),
1480d444b03eSAli Bahrami MSG_SCN_GOT_SIZE)) {
1481d444b03eSAli Bahrami *ident = ld_targ.t_id.id_null;
1482d444b03eSAli Bahrami done = TRUE;
1483d444b03eSAli Bahrami break;
1484d444b03eSAli Bahrami }
1485d444b03eSAli Bahrami if ((ld_targ.t_m.m_sht_unwind == SHT_PROGBITS) &&
1486d444b03eSAli Bahrami is_name_cmp(name, MSG_ORIG(MSG_SCN_GCC_X_TBL),
1487d444b03eSAli Bahrami MSG_SCN_GCC_X_TBL_SIZE)) {
1488d444b03eSAli Bahrami *ident = ld_targ.t_id.id_unwind;
1489d444b03eSAli Bahrami done = TRUE;
1490d444b03eSAli Bahrami break;
1491d444b03eSAli Bahrami }
1492d444b03eSAli Bahrami break;
1493d444b03eSAli Bahrami case 'p':
1494d444b03eSAli Bahrami if (is_name_cmp(name, MSG_ORIG(MSG_SCN_PLT),
1495d444b03eSAli Bahrami MSG_SCN_PLT_SIZE)) {
1496d444b03eSAli Bahrami *ident = ld_targ.t_id.id_null;
1497d444b03eSAli Bahrami done = TRUE;
1498d444b03eSAli Bahrami }
1499d444b03eSAli Bahrami break;
1500d444b03eSAli Bahrami }
1501d444b03eSAli Bahrami }
1502d444b03eSAli Bahrami if (!done) {
1503d444b03eSAli Bahrami if (is_stab_index) {
1504d444b03eSAli Bahrami /*
1505d444b03eSAli Bahrami * This is a work-around for x86 compilers that have
1506d444b03eSAli Bahrami * set SHF_ALLOC for the .stab.index section.
1507d444b03eSAli Bahrami *
1508d444b03eSAli Bahrami * Because of this, make sure that the .stab.index
1509d444b03eSAli Bahrami * does not end up as the last section in the text
1510d444b03eSAli Bahrami * segment. Older linkers can produce segmentation
1511d444b03eSAli Bahrami * violations when they strip (ld -s) against a
1512d444b03eSAli Bahrami * shared object whose last section in the text
1513d444b03eSAli Bahrami * segment is a .stab.
1514d444b03eSAli Bahrami */
1515d444b03eSAli Bahrami *ident = ld_targ.t_id.id_interp;
1516d444b03eSAli Bahrami } else {
1517d444b03eSAli Bahrami *ident = ld_targ.t_id.id_data;
1518d444b03eSAli Bahrami }
1519d444b03eSAli Bahrami }
1520d444b03eSAli Bahrami
1521d444b03eSAli Bahrami return (TRUE);
1522d444b03eSAli Bahrami }
1523d444b03eSAli Bahrami
1524d444b03eSAli Bahrami /*
15257c478bd9Sstevel@tonic-gate * Process a progbits section.
15267c478bd9Sstevel@tonic-gate */
15275aefb655Srie static uintptr_t
process_progbits(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)15287c478bd9Sstevel@tonic-gate process_progbits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
15297c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
15307c478bd9Sstevel@tonic-gate {
1531d444b03eSAli Bahrami Boolean is_stab_index = FALSE;
15327e16fca0SAli Bahrami Word is_flags = 0;
15337e16fca0SAli Bahrami uintptr_t r;
15347c478bd9Sstevel@tonic-gate
15357c478bd9Sstevel@tonic-gate /*
15367c478bd9Sstevel@tonic-gate * Never include .stab.excl sections in any output file.
15377c478bd9Sstevel@tonic-gate * If the -s flag has been specified strip any .stab sections.
15387c478bd9Sstevel@tonic-gate */
15397c478bd9Sstevel@tonic-gate if (ident && (strncmp(name, MSG_ORIG(MSG_SCN_STAB),
15407c478bd9Sstevel@tonic-gate MSG_SCN_STAB_SIZE) == 0)) {
15417c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STRIP) ||
15427c478bd9Sstevel@tonic-gate (strcmp((name + MSG_SCN_STAB_SIZE),
15437c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_SCN_EXCL)) == 0))
15447c478bd9Sstevel@tonic-gate return (1);
15457c478bd9Sstevel@tonic-gate
15467c478bd9Sstevel@tonic-gate if (strcmp((name + MSG_SCN_STAB_SIZE),
15477c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_SCN_INDEX)) == 0)
1548d444b03eSAli Bahrami is_stab_index = TRUE;
15497c478bd9Sstevel@tonic-gate }
15507c478bd9Sstevel@tonic-gate
15517c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STRIP) && ident) {
15527c478bd9Sstevel@tonic-gate if ((strncmp(name, MSG_ORIG(MSG_SCN_DEBUG),
15537c478bd9Sstevel@tonic-gate MSG_SCN_DEBUG_SIZE) == 0) ||
15547c478bd9Sstevel@tonic-gate (strcmp(name, MSG_ORIG(MSG_SCN_LINE)) == 0))
15557c478bd9Sstevel@tonic-gate return (1);
15567c478bd9Sstevel@tonic-gate }
15577c478bd9Sstevel@tonic-gate
15587c478bd9Sstevel@tonic-gate /*
15597c478bd9Sstevel@tonic-gate * Update the ident to reflect the type of section we've got.
15607c478bd9Sstevel@tonic-gate *
15617c478bd9Sstevel@tonic-gate * If there is any .plt or .got section to generate we'll be creating
15627c478bd9Sstevel@tonic-gate * our own version, so don't allow any input sections of these types to
15637c478bd9Sstevel@tonic-gate * be added to the output section list (why a relocatable object would
15647c478bd9Sstevel@tonic-gate * have a .plt or .got is a mystery, but stranger things have occurred).
15657e16fca0SAli Bahrami *
15667e16fca0SAli Bahrami * If there are any unwind sections, and this is a platform that uses
15677e16fca0SAli Bahrami * SHT_PROGBITS for unwind sections, then set their ident to reflect
15687e16fca0SAli Bahrami * that.
15697c478bd9Sstevel@tonic-gate */
15707c478bd9Sstevel@tonic-gate if (ident) {
15717e16fca0SAli Bahrami if (shdr->sh_flags & SHF_TLS) {
1572ba2be530Sab196087 ident = ld_targ.t_id.id_tls;
15737e16fca0SAli Bahrami } else if ((shdr->sh_flags & ~ALL_SHF_IGNORE) ==
15747e16fca0SAli Bahrami (SHF_ALLOC | SHF_EXECINSTR)) {
1575ba2be530Sab196087 ident = ld_targ.t_id.id_text;
15767e16fca0SAli Bahrami } else if (shdr->sh_flags & SHF_ALLOC) {
1577d444b03eSAli Bahrami if (process_progbits_alloc(name, ifl, shdr, ndx,
1578d444b03eSAli Bahrami &ident, ofl, is_stab_index, &is_flags) == FALSE)
1579d444b03eSAli Bahrami return (S_ERROR);
15807e16fca0SAli Bahrami } else {
1581ba2be530Sab196087 ident = ld_targ.t_id.id_note;
15827c478bd9Sstevel@tonic-gate }
1583d444b03eSAli Bahrami }
15847e16fca0SAli Bahrami
15857e16fca0SAli Bahrami r = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
15867e16fca0SAli Bahrami
15877e16fca0SAli Bahrami /*
15887e16fca0SAli Bahrami * On success, process_section() creates an input section descriptor.
15897e16fca0SAli Bahrami * Now that it exists, we can add any pending input section flags.
15907e16fca0SAli Bahrami */
15917e16fca0SAli Bahrami if ((is_flags != 0) && (r == 1))
15927e16fca0SAli Bahrami ifl->ifl_isdesc[ndx]->is_flags |= is_flags;
15937e16fca0SAli Bahrami
15947e16fca0SAli Bahrami return (r);
15957c478bd9Sstevel@tonic-gate }
15967c478bd9Sstevel@tonic-gate
15977c478bd9Sstevel@tonic-gate /*
15987c478bd9Sstevel@tonic-gate * Handles the SHT_SUNW_{DEBUG,DEBUGSTR) sections.
15997c478bd9Sstevel@tonic-gate */
16005aefb655Srie static uintptr_t
process_debug(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)16017c478bd9Sstevel@tonic-gate process_debug(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
16027c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
16037c478bd9Sstevel@tonic-gate {
16047c478bd9Sstevel@tonic-gate /*
16057c478bd9Sstevel@tonic-gate * Debug information is discarded when the 'ld -s' flag is invoked.
16067c478bd9Sstevel@tonic-gate */
16077c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_STRIP) {
16087c478bd9Sstevel@tonic-gate return (1);
16097c478bd9Sstevel@tonic-gate }
16107c478bd9Sstevel@tonic-gate return (process_progbits(name, ifl, shdr, scn, ndx, ident, ofl));
16117c478bd9Sstevel@tonic-gate }
16127c478bd9Sstevel@tonic-gate
16137c478bd9Sstevel@tonic-gate /*
16147c478bd9Sstevel@tonic-gate * Process a nobits section.
16157c478bd9Sstevel@tonic-gate */
16165aefb655Srie static uintptr_t
process_nobits(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)16177c478bd9Sstevel@tonic-gate process_nobits(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
16187c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
16197c478bd9Sstevel@tonic-gate {
16207c478bd9Sstevel@tonic-gate if (ident) {
16217c478bd9Sstevel@tonic-gate if (shdr->sh_flags & SHF_TLS)
1622ba2be530Sab196087 ident = ld_targ.t_id.id_tlsbss;
1623ba2be530Sab196087 #if defined(_ELF64)
1624ba2be530Sab196087 else if ((shdr->sh_flags & SHF_AMD64_LARGE) &&
1625ba2be530Sab196087 (ld_targ.t_m.m_mach == EM_AMD64))
1626ba2be530Sab196087 ident = ld_targ.t_id.id_lbss;
162754d82594Sseizo #endif
16287c478bd9Sstevel@tonic-gate else
1629ba2be530Sab196087 ident = ld_targ.t_id.id_bss;
16307c478bd9Sstevel@tonic-gate }
16317c478bd9Sstevel@tonic-gate return (process_section(name, ifl, shdr, scn, ndx, ident, ofl));
16327c478bd9Sstevel@tonic-gate }
16337c478bd9Sstevel@tonic-gate
16347c478bd9Sstevel@tonic-gate /*
16357c478bd9Sstevel@tonic-gate * Process a SHT_*_ARRAY section.
16367c478bd9Sstevel@tonic-gate */
16375aefb655Srie static uintptr_t
process_array(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)16387c478bd9Sstevel@tonic-gate process_array(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
16397c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
16407c478bd9Sstevel@tonic-gate {
16410e233487SRod Evans uintptr_t error;
16427c478bd9Sstevel@tonic-gate
16437c478bd9Sstevel@tonic-gate if (ident)
1644ba2be530Sab196087 ident = ld_targ.t_id.id_array;
16457c478bd9Sstevel@tonic-gate
16460e233487SRod Evans error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
16470e233487SRod Evans if ((error == 0) || (error == S_ERROR))
16480e233487SRod Evans return (error);
16497c478bd9Sstevel@tonic-gate
16500e233487SRod Evans return (1);
16510e233487SRod Evans }
16520e233487SRod Evans
16530e233487SRod Evans static uintptr_t
16540e233487SRod Evans /* ARGSUSED1 */
array_process(Is_desc * isc,Ifl_desc * ifl,Ofl_desc * ofl)16550e233487SRod Evans array_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
16560e233487SRod Evans {
16570e233487SRod Evans Os_desc *osp;
16580e233487SRod Evans Shdr *shdr;
16590e233487SRod Evans
16600e233487SRod Evans if ((isc == NULL) || ((osp = isc->is_osdesc) == NULL))
16617c478bd9Sstevel@tonic-gate return (0);
16627c478bd9Sstevel@tonic-gate
16630e233487SRod Evans shdr = isc->is_shdr;
16640e233487SRod Evans
16657c478bd9Sstevel@tonic-gate if ((shdr->sh_type == SHT_FINI_ARRAY) &&
16660e233487SRod Evans (ofl->ofl_osfiniarray == NULL))
16677c478bd9Sstevel@tonic-gate ofl->ofl_osfiniarray = osp;
16687c478bd9Sstevel@tonic-gate else if ((shdr->sh_type == SHT_INIT_ARRAY) &&
16690e233487SRod Evans (ofl->ofl_osinitarray == NULL))
16707c478bd9Sstevel@tonic-gate ofl->ofl_osinitarray = osp;
16717c478bd9Sstevel@tonic-gate else if ((shdr->sh_type == SHT_PREINIT_ARRAY) &&
16720e233487SRod Evans (ofl->ofl_ospreinitarray == NULL))
16737c478bd9Sstevel@tonic-gate ofl->ofl_ospreinitarray = osp;
16747c478bd9Sstevel@tonic-gate
16757c478bd9Sstevel@tonic-gate return (1);
16767c478bd9Sstevel@tonic-gate }
16777c478bd9Sstevel@tonic-gate
16787c478bd9Sstevel@tonic-gate /*
16797c478bd9Sstevel@tonic-gate * Process a SHT_SYMTAB_SHNDX section.
16807c478bd9Sstevel@tonic-gate */
16815aefb655Srie static uintptr_t
process_sym_shndx(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)16827c478bd9Sstevel@tonic-gate process_sym_shndx(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
16837c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
16847c478bd9Sstevel@tonic-gate {
16857c478bd9Sstevel@tonic-gate if (process_input(name, ifl, shdr, scn, ndx, ident, ofl) == S_ERROR)
16867c478bd9Sstevel@tonic-gate return (S_ERROR);
16877c478bd9Sstevel@tonic-gate
16887c478bd9Sstevel@tonic-gate /*
16897c478bd9Sstevel@tonic-gate * Have we already seen the related SYMTAB - if so verify it now.
16907c478bd9Sstevel@tonic-gate */
16917c478bd9Sstevel@tonic-gate if (shdr->sh_link < ndx) {
16927c478bd9Sstevel@tonic-gate Is_desc *isp = ifl->ifl_isdesc[shdr->sh_link];
16937c478bd9Sstevel@tonic-gate
1694635216b6SRod Evans if ((isp == NULL) || ((isp->is_shdr->sh_type != SHT_SYMTAB) &&
16957c478bd9Sstevel@tonic-gate (isp->is_shdr->sh_type != SHT_DYNSYM))) {
16961007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
16974a8d0ea7SAli Bahrami MSG_INTL(MSG_FIL_INVSHLINK), ifl->ifl_name,
16984a8d0ea7SAli Bahrami EC_WORD(ndx), name, EC_XWORD(shdr->sh_link));
16997c478bd9Sstevel@tonic-gate return (S_ERROR);
17007c478bd9Sstevel@tonic-gate }
17017c478bd9Sstevel@tonic-gate isp->is_symshndx = ifl->ifl_isdesc[ndx];
17027c478bd9Sstevel@tonic-gate }
17037c478bd9Sstevel@tonic-gate return (1);
17047c478bd9Sstevel@tonic-gate }
17057c478bd9Sstevel@tonic-gate
17067c478bd9Sstevel@tonic-gate /*
17077c478bd9Sstevel@tonic-gate * Final processing for SHT_SYMTAB_SHNDX section.
17087c478bd9Sstevel@tonic-gate */
17095aefb655Srie static uintptr_t
17107c478bd9Sstevel@tonic-gate /* ARGSUSED2 */
sym_shndx_process(Is_desc * isc,Ifl_desc * ifl,Ofl_desc * ofl)17117c478bd9Sstevel@tonic-gate sym_shndx_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
17127c478bd9Sstevel@tonic-gate {
17137c478bd9Sstevel@tonic-gate if (isc->is_shdr->sh_link > isc->is_scnndx) {
17147c478bd9Sstevel@tonic-gate Is_desc *isp = ifl->ifl_isdesc[isc->is_shdr->sh_link];
17157c478bd9Sstevel@tonic-gate
1716635216b6SRod Evans if ((isp == NULL) || ((isp->is_shdr->sh_type != SHT_SYMTAB) &&
17177c478bd9Sstevel@tonic-gate (isp->is_shdr->sh_type != SHT_DYNSYM))) {
17181007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
17195aefb655Srie MSG_INTL(MSG_FIL_INVSHLINK), isc->is_file->ifl_name,
17204a8d0ea7SAli Bahrami EC_WORD(isc->is_scnndx), isc->is_name,
17214a8d0ea7SAli Bahrami EC_XWORD(isc->is_shdr->sh_link));
17227c478bd9Sstevel@tonic-gate return (S_ERROR);
17237c478bd9Sstevel@tonic-gate }
17247c478bd9Sstevel@tonic-gate isp->is_symshndx = isc;
17257c478bd9Sstevel@tonic-gate }
17267c478bd9Sstevel@tonic-gate return (1);
17277c478bd9Sstevel@tonic-gate }
17287c478bd9Sstevel@tonic-gate
17297c478bd9Sstevel@tonic-gate /*
17307c478bd9Sstevel@tonic-gate * Process .dynamic section from a relocatable object.
17317c478bd9Sstevel@tonic-gate *
17327c478bd9Sstevel@tonic-gate * Note: That the .dynamic section is only considered interesting when
17337c478bd9Sstevel@tonic-gate * dlopen()ing a relocatable object (thus FLG_OF1_RELDYN can only get
17347c478bd9Sstevel@tonic-gate * set when libld is called from ld.so.1).
17357c478bd9Sstevel@tonic-gate */
17367c478bd9Sstevel@tonic-gate /*ARGSUSED*/
17375aefb655Srie static uintptr_t
process_rel_dynamic(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)17387c478bd9Sstevel@tonic-gate process_rel_dynamic(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
17397c478bd9Sstevel@tonic-gate Word ndx, int ident, Ofl_desc *ofl)
17407c478bd9Sstevel@tonic-gate {
17417c478bd9Sstevel@tonic-gate Dyn *dyn;
17427c478bd9Sstevel@tonic-gate Elf_Scn *strscn;
17437c478bd9Sstevel@tonic-gate Elf_Data *dp;
17447c478bd9Sstevel@tonic-gate char *str;
17457c478bd9Sstevel@tonic-gate
17467c478bd9Sstevel@tonic-gate /*
17477c478bd9Sstevel@tonic-gate * Process .dynamic sections from relocatable objects ?
17487c478bd9Sstevel@tonic-gate */
17497c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags1 & FLG_OF1_RELDYN) == 0)
17507c478bd9Sstevel@tonic-gate return (1);
17517c478bd9Sstevel@tonic-gate
17527c478bd9Sstevel@tonic-gate /*
17537c478bd9Sstevel@tonic-gate * Find the string section associated with the .dynamic section.
17547c478bd9Sstevel@tonic-gate */
17557c478bd9Sstevel@tonic-gate if ((strscn = elf_getscn(ifl->ifl_elf, shdr->sh_link)) == NULL) {
17561007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN),
17575aefb655Srie ifl->ifl_name);
17587c478bd9Sstevel@tonic-gate return (0);
17597c478bd9Sstevel@tonic-gate }
17607c478bd9Sstevel@tonic-gate dp = elf_getdata(strscn, NULL);
17617c478bd9Sstevel@tonic-gate str = (char *)dp->d_buf;
17627c478bd9Sstevel@tonic-gate
17637c478bd9Sstevel@tonic-gate /*
17647c478bd9Sstevel@tonic-gate * And get the .dynamic data
17657c478bd9Sstevel@tonic-gate */
17667c478bd9Sstevel@tonic-gate dp = elf_getdata(scn, NULL);
17677c478bd9Sstevel@tonic-gate
17687c478bd9Sstevel@tonic-gate for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) {
1769fb1354edSrie Ifl_desc *difl;
17707c478bd9Sstevel@tonic-gate
17717c478bd9Sstevel@tonic-gate switch (dyn->d_tag) {
17727c478bd9Sstevel@tonic-gate case DT_NEEDED:
17737c478bd9Sstevel@tonic-gate case DT_USED:
177457ef7aa9SRod Evans if (((difl = libld_calloc(1,
177557ef7aa9SRod Evans sizeof (Ifl_desc))) == NULL) ||
177657ef7aa9SRod Evans (aplist_append(&ofl->ofl_sos, difl,
177757ef7aa9SRod Evans AL_CNT_OFL_LIBS) == NULL))
17787c478bd9Sstevel@tonic-gate return (S_ERROR);
1779fb1354edSrie
1780fb1354edSrie difl->ifl_name = MSG_ORIG(MSG_STR_DYNAMIC);
1781fb1354edSrie difl->ifl_soname = str + (size_t)dyn->d_un.d_val;
1782fb1354edSrie difl->ifl_flags = FLG_IF_NEEDSTR;
17837c478bd9Sstevel@tonic-gate break;
17847c478bd9Sstevel@tonic-gate case DT_RPATH:
17857c478bd9Sstevel@tonic-gate case DT_RUNPATH:
17867c478bd9Sstevel@tonic-gate if ((ofl->ofl_rpath = add_string(ofl->ofl_rpath,
17877c478bd9Sstevel@tonic-gate (str + (size_t)dyn->d_un.d_val))) ==
17887c478bd9Sstevel@tonic-gate (const char *)S_ERROR)
17897c478bd9Sstevel@tonic-gate return (S_ERROR);
17907c478bd9Sstevel@tonic-gate break;
1791d840867fSab196087 case DT_VERSYM:
1792d840867fSab196087 /*
1793d840867fSab196087 * The Solaris ld does not put DT_VERSYM in the
1794d840867fSab196087 * dynamic section. If the object has DT_VERSYM,
1795d840867fSab196087 * then it must have been produced by the GNU ld,
1796d840867fSab196087 * and is using the GNU style of versioning.
1797d840867fSab196087 */
1798d840867fSab196087 ifl->ifl_flags |= FLG_IF_GNUVER;
1799d840867fSab196087 break;
18007c478bd9Sstevel@tonic-gate }
18017c478bd9Sstevel@tonic-gate }
18027c478bd9Sstevel@tonic-gate return (1);
18037c478bd9Sstevel@tonic-gate }
18047c478bd9Sstevel@tonic-gate
18057c478bd9Sstevel@tonic-gate /*
18067c478bd9Sstevel@tonic-gate * Expand implicit references. Dependencies can be specified in terms of the
180708278a5eSRod Evans * $ORIGIN, $MACHINE, $PLATFORM, $OSREL and $OSNAME tokens, either from their
180808278a5eSRod Evans * needed name, or via a runpath. In addition runpaths may also specify the
180908278a5eSRod Evans * $ISALIST token.
18107c478bd9Sstevel@tonic-gate *
1811fb1354edSrie * Probably the most common reference to explicit dependencies (via -L) will be
18127c478bd9Sstevel@tonic-gate * sufficient to find any associated implicit dependencies, but just in case we
18137c478bd9Sstevel@tonic-gate * expand any occurrence of these known tokens here.
18147c478bd9Sstevel@tonic-gate *
18157c478bd9Sstevel@tonic-gate * Note, if any errors occur we simply return the original name.
18167c478bd9Sstevel@tonic-gate *
18177c478bd9Sstevel@tonic-gate * This code is remarkably similar to expand() in rtld/common/paths.c.
18187c478bd9Sstevel@tonic-gate */
181908278a5eSRod Evans static char *machine = NULL;
182008278a5eSRod Evans static size_t machine_sz = 0;
1821635216b6SRod Evans static char *platform = NULL;
18227c478bd9Sstevel@tonic-gate static size_t platform_sz = 0;
1823635216b6SRod Evans static Isa_desc *isa = NULL;
1824635216b6SRod Evans static Uts_desc *uts = NULL;
18257c478bd9Sstevel@tonic-gate
18267c478bd9Sstevel@tonic-gate static char *
expand(const char * parent,const char * name,char ** next)18277c478bd9Sstevel@tonic-gate expand(const char *parent, const char *name, char **next)
18287c478bd9Sstevel@tonic-gate {
18297c478bd9Sstevel@tonic-gate char _name[PATH_MAX], *nptr, *_next;
18307c478bd9Sstevel@tonic-gate const char *optr;
18317c478bd9Sstevel@tonic-gate size_t nrem = PATH_MAX - 1;
18327c478bd9Sstevel@tonic-gate int expanded = 0, _expanded, isaflag = 0;
18337c478bd9Sstevel@tonic-gate
18347c478bd9Sstevel@tonic-gate optr = name;
18357c478bd9Sstevel@tonic-gate nptr = _name;
18367c478bd9Sstevel@tonic-gate
18377c478bd9Sstevel@tonic-gate while (*optr) {
18387c478bd9Sstevel@tonic-gate if (nrem == 0)
18397c478bd9Sstevel@tonic-gate return ((char *)name);
18407c478bd9Sstevel@tonic-gate
18417c478bd9Sstevel@tonic-gate if (*optr != '$') {
18427c478bd9Sstevel@tonic-gate *nptr++ = *optr++, nrem--;
18437c478bd9Sstevel@tonic-gate continue;
18447c478bd9Sstevel@tonic-gate }
18457c478bd9Sstevel@tonic-gate
18467c478bd9Sstevel@tonic-gate _expanded = 0;
18477c478bd9Sstevel@tonic-gate
18487c478bd9Sstevel@tonic-gate if (strncmp(optr, MSG_ORIG(MSG_STR_ORIGIN),
18497c478bd9Sstevel@tonic-gate MSG_STR_ORIGIN_SIZE) == 0) {
18507c478bd9Sstevel@tonic-gate char *eptr;
18517c478bd9Sstevel@tonic-gate
18527c478bd9Sstevel@tonic-gate /*
18537c478bd9Sstevel@tonic-gate * For $ORIGIN, expansion is really just a concatenation
18547c478bd9Sstevel@tonic-gate * of the parents directory name. For example, an
1855fb1354edSrie * explicit dependency foo/bar/lib1.so with a dependency
18567c478bd9Sstevel@tonic-gate * on $ORIGIN/lib2.so would be expanded to
18577c478bd9Sstevel@tonic-gate * foo/bar/lib2.so.
18587c478bd9Sstevel@tonic-gate */
1859635216b6SRod Evans if ((eptr = strrchr(parent, '/')) == NULL) {
18607c478bd9Sstevel@tonic-gate *nptr++ = '.';
18617c478bd9Sstevel@tonic-gate nrem--;
18627c478bd9Sstevel@tonic-gate } else {
18637c478bd9Sstevel@tonic-gate size_t len = eptr - parent;
18647c478bd9Sstevel@tonic-gate
18657c478bd9Sstevel@tonic-gate if (len >= nrem)
18667c478bd9Sstevel@tonic-gate return ((char *)name);
18677c478bd9Sstevel@tonic-gate
18687c478bd9Sstevel@tonic-gate (void) strncpy(nptr, parent, len);
18697c478bd9Sstevel@tonic-gate nptr = nptr + len;
18707c478bd9Sstevel@tonic-gate nrem -= len;
18717c478bd9Sstevel@tonic-gate }
18727c478bd9Sstevel@tonic-gate optr += MSG_STR_ORIGIN_SIZE;
18737c478bd9Sstevel@tonic-gate expanded = _expanded = 1;
18747c478bd9Sstevel@tonic-gate
187508278a5eSRod Evans } else if (strncmp(optr, MSG_ORIG(MSG_STR_MACHINE),
187608278a5eSRod Evans MSG_STR_MACHINE_SIZE) == 0) {
187708278a5eSRod Evans /*
187808278a5eSRod Evans * Establish the machine from sysconf - like uname -i.
187908278a5eSRod Evans */
188008278a5eSRod Evans if ((machine == NULL) && (machine_sz == 0)) {
188108278a5eSRod Evans char info[SYS_NMLN];
188208278a5eSRod Evans long size;
188308278a5eSRod Evans
188408278a5eSRod Evans size = sysinfo(SI_MACHINE, info, SYS_NMLN);
188508278a5eSRod Evans if ((size != -1) &&
188608278a5eSRod Evans (machine = libld_malloc((size_t)size))) {
188708278a5eSRod Evans (void) strcpy(machine, info);
188808278a5eSRod Evans machine_sz = (size_t)size - 1;
188908278a5eSRod Evans } else
189008278a5eSRod Evans machine_sz = 1;
189108278a5eSRod Evans }
189208278a5eSRod Evans if (machine) {
189308278a5eSRod Evans if (machine_sz >= nrem)
189408278a5eSRod Evans return ((char *)name);
189508278a5eSRod Evans
189608278a5eSRod Evans (void) strncpy(nptr, machine, machine_sz);
189708278a5eSRod Evans nptr = nptr + machine_sz;
189808278a5eSRod Evans nrem -= machine_sz;
189908278a5eSRod Evans
190008278a5eSRod Evans optr += MSG_STR_MACHINE_SIZE;
190108278a5eSRod Evans expanded = _expanded = 1;
190208278a5eSRod Evans }
190308278a5eSRod Evans
19047c478bd9Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_PLATFORM),
19057c478bd9Sstevel@tonic-gate MSG_STR_PLATFORM_SIZE) == 0) {
19067c478bd9Sstevel@tonic-gate /*
19077c478bd9Sstevel@tonic-gate * Establish the platform from sysconf - like uname -i.
19087c478bd9Sstevel@tonic-gate */
1909635216b6SRod Evans if ((platform == NULL) && (platform_sz == 0)) {
19107c478bd9Sstevel@tonic-gate char info[SYS_NMLN];
19117c478bd9Sstevel@tonic-gate long size;
19127c478bd9Sstevel@tonic-gate
19137c478bd9Sstevel@tonic-gate size = sysinfo(SI_PLATFORM, info, SYS_NMLN);
19147c478bd9Sstevel@tonic-gate if ((size != -1) &&
19157c478bd9Sstevel@tonic-gate (platform = libld_malloc((size_t)size))) {
19167c478bd9Sstevel@tonic-gate (void) strcpy(platform, info);
19177c478bd9Sstevel@tonic-gate platform_sz = (size_t)size - 1;
19187c478bd9Sstevel@tonic-gate } else
19197c478bd9Sstevel@tonic-gate platform_sz = 1;
19207c478bd9Sstevel@tonic-gate }
1921635216b6SRod Evans if (platform) {
19227c478bd9Sstevel@tonic-gate if (platform_sz >= nrem)
19237c478bd9Sstevel@tonic-gate return ((char *)name);
19247c478bd9Sstevel@tonic-gate
19257c478bd9Sstevel@tonic-gate (void) strncpy(nptr, platform, platform_sz);
19267c478bd9Sstevel@tonic-gate nptr = nptr + platform_sz;
19277c478bd9Sstevel@tonic-gate nrem -= platform_sz;
19287c478bd9Sstevel@tonic-gate
19297c478bd9Sstevel@tonic-gate optr += MSG_STR_PLATFORM_SIZE;
19307c478bd9Sstevel@tonic-gate expanded = _expanded = 1;
19317c478bd9Sstevel@tonic-gate }
19327c478bd9Sstevel@tonic-gate
19337c478bd9Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_OSNAME),
19347c478bd9Sstevel@tonic-gate MSG_STR_OSNAME_SIZE) == 0) {
19357c478bd9Sstevel@tonic-gate /*
19367c478bd9Sstevel@tonic-gate * Establish the os name - like uname -s.
19377c478bd9Sstevel@tonic-gate */
1938635216b6SRod Evans if (uts == NULL)
19397c478bd9Sstevel@tonic-gate uts = conv_uts();
19407c478bd9Sstevel@tonic-gate
19417c478bd9Sstevel@tonic-gate if (uts && uts->uts_osnamesz) {
19427c478bd9Sstevel@tonic-gate if (uts->uts_osnamesz >= nrem)
19437c478bd9Sstevel@tonic-gate return ((char *)name);
19447c478bd9Sstevel@tonic-gate
19457c478bd9Sstevel@tonic-gate (void) strncpy(nptr, uts->uts_osname,
19467c478bd9Sstevel@tonic-gate uts->uts_osnamesz);
19477c478bd9Sstevel@tonic-gate nptr = nptr + uts->uts_osnamesz;
19487c478bd9Sstevel@tonic-gate nrem -= uts->uts_osnamesz;
19497c478bd9Sstevel@tonic-gate
19507c478bd9Sstevel@tonic-gate optr += MSG_STR_OSNAME_SIZE;
19517c478bd9Sstevel@tonic-gate expanded = _expanded = 1;
19527c478bd9Sstevel@tonic-gate }
19537c478bd9Sstevel@tonic-gate
19547c478bd9Sstevel@tonic-gate } else if (strncmp(optr, MSG_ORIG(MSG_STR_OSREL),
19557c478bd9Sstevel@tonic-gate MSG_STR_OSREL_SIZE) == 0) {
19567c478bd9Sstevel@tonic-gate /*
19577c478bd9Sstevel@tonic-gate * Establish the os release - like uname -r.
19587c478bd9Sstevel@tonic-gate */
1959635216b6SRod Evans if (uts == NULL)
19607c478bd9Sstevel@tonic-gate uts = conv_uts();
19617c478bd9Sstevel@tonic-gate
19627c478bd9Sstevel@tonic-gate if (uts && uts->uts_osrelsz) {
19637c478bd9Sstevel@tonic-gate if (uts->uts_osrelsz >= nrem)
19647c478bd9Sstevel@tonic-gate return ((char *)name);
19657c478bd9Sstevel@tonic-gate
19667c478bd9Sstevel@tonic-gate (void) strncpy(nptr, uts->uts_osrel,
19677c478bd9Sstevel@tonic-gate uts->uts_osrelsz);
19687c478bd9Sstevel@tonic-gate nptr = nptr + uts->uts_osrelsz;
19697c478bd9Sstevel@tonic-gate nrem -= uts->uts_osrelsz;
19707c478bd9Sstevel@tonic-gate
19717c478bd9Sstevel@tonic-gate optr += MSG_STR_OSREL_SIZE;
19727c478bd9Sstevel@tonic-gate expanded = _expanded = 1;
19737c478bd9Sstevel@tonic-gate }
19747c478bd9Sstevel@tonic-gate
19757c478bd9Sstevel@tonic-gate } else if ((strncmp(optr, MSG_ORIG(MSG_STR_ISALIST),
19767c478bd9Sstevel@tonic-gate MSG_STR_ISALIST_SIZE) == 0) && next && (isaflag++ == 0)) {
19777c478bd9Sstevel@tonic-gate /*
19787c478bd9Sstevel@tonic-gate * Establish instruction sets from sysconf. Note that
19797c478bd9Sstevel@tonic-gate * this is only meaningful from runpaths.
19807c478bd9Sstevel@tonic-gate */
1981635216b6SRod Evans if (isa == NULL)
19827c478bd9Sstevel@tonic-gate isa = conv_isalist();
19837c478bd9Sstevel@tonic-gate
19847c478bd9Sstevel@tonic-gate if (isa && isa->isa_listsz &&
19857c478bd9Sstevel@tonic-gate (nrem > isa->isa_opt->isa_namesz)) {
19867c478bd9Sstevel@tonic-gate size_t mlen, tlen, hlen = optr - name;
19877c478bd9Sstevel@tonic-gate size_t no;
19887c478bd9Sstevel@tonic-gate char *lptr;
19897c478bd9Sstevel@tonic-gate Isa_opt *opt = isa->isa_opt;
19907c478bd9Sstevel@tonic-gate
19917c478bd9Sstevel@tonic-gate (void) strncpy(nptr, opt->isa_name,
19927c478bd9Sstevel@tonic-gate opt->isa_namesz);
19937c478bd9Sstevel@tonic-gate nptr = nptr + opt->isa_namesz;
19947c478bd9Sstevel@tonic-gate nrem -= opt->isa_namesz;
19957c478bd9Sstevel@tonic-gate
19967c478bd9Sstevel@tonic-gate optr += MSG_STR_ISALIST_SIZE;
19977c478bd9Sstevel@tonic-gate expanded = _expanded = 1;
19987c478bd9Sstevel@tonic-gate
19997c478bd9Sstevel@tonic-gate tlen = strlen(optr);
20007c478bd9Sstevel@tonic-gate
20017c478bd9Sstevel@tonic-gate /*
20027c478bd9Sstevel@tonic-gate * As ISALIST expands to a number of elements,
20037c478bd9Sstevel@tonic-gate * establish a new list to return to the caller.
20047c478bd9Sstevel@tonic-gate * This will contain the present path being
20057c478bd9Sstevel@tonic-gate * processed redefined for each isalist option,
20067c478bd9Sstevel@tonic-gate * plus the original remaining list entries.
20077c478bd9Sstevel@tonic-gate */
20087c478bd9Sstevel@tonic-gate mlen = ((hlen + tlen) * (isa->isa_optno - 1)) +
20097c478bd9Sstevel@tonic-gate isa->isa_listsz - opt->isa_namesz;
20107c478bd9Sstevel@tonic-gate if (*next)
20117c478bd9Sstevel@tonic-gate mlen += strlen(*next);
2012635216b6SRod Evans if ((_next = lptr = libld_malloc(mlen)) == NULL)
20137c478bd9Sstevel@tonic-gate return (0);
20147c478bd9Sstevel@tonic-gate
20157c478bd9Sstevel@tonic-gate for (no = 1, opt++; no < isa->isa_optno;
20167c478bd9Sstevel@tonic-gate no++, opt++) {
20177c478bd9Sstevel@tonic-gate (void) strncpy(lptr, name, hlen);
20187c478bd9Sstevel@tonic-gate lptr = lptr + hlen;
20197c478bd9Sstevel@tonic-gate (void) strncpy(lptr, opt->isa_name,
20207c478bd9Sstevel@tonic-gate opt->isa_namesz);
20217c478bd9Sstevel@tonic-gate lptr = lptr + opt->isa_namesz;
20227c478bd9Sstevel@tonic-gate (void) strncpy(lptr, optr, tlen);
20237c478bd9Sstevel@tonic-gate lptr = lptr + tlen;
20247c478bd9Sstevel@tonic-gate *lptr++ = ':';
20257c478bd9Sstevel@tonic-gate }
20267c478bd9Sstevel@tonic-gate if (*next)
20277c478bd9Sstevel@tonic-gate (void) strcpy(lptr, *next);
20287c478bd9Sstevel@tonic-gate else
20297c478bd9Sstevel@tonic-gate *--lptr = '\0';
20307c478bd9Sstevel@tonic-gate }
20317c478bd9Sstevel@tonic-gate }
20327c478bd9Sstevel@tonic-gate
20337c478bd9Sstevel@tonic-gate /*
20347c478bd9Sstevel@tonic-gate * If no expansion occurred skip the $ and continue.
20357c478bd9Sstevel@tonic-gate */
20367c478bd9Sstevel@tonic-gate if (_expanded == 0)
20377c478bd9Sstevel@tonic-gate *nptr++ = *optr++, nrem--;
20387c478bd9Sstevel@tonic-gate }
20397c478bd9Sstevel@tonic-gate
20407c478bd9Sstevel@tonic-gate /*
20417c478bd9Sstevel@tonic-gate * If any ISALIST processing has occurred not only do we return the
20427c478bd9Sstevel@tonic-gate * expanded node we're presently working on, but we must also update the
20437c478bd9Sstevel@tonic-gate * remaining list so that it is effectively prepended with this node
20447c478bd9Sstevel@tonic-gate * expanded to all remaining isalist options. Note that we can only
20457c478bd9Sstevel@tonic-gate * handle one ISALIST per node. For more than one ISALIST to be
20467c478bd9Sstevel@tonic-gate * processed we'd need a better algorithm than above to replace the
20477c478bd9Sstevel@tonic-gate * newly generated list. Whether we want to encourage the number of
20487c478bd9Sstevel@tonic-gate * pathname permutations this would provide is another question. So, for
20497c478bd9Sstevel@tonic-gate * now if more than one ISALIST is encountered we return the original
20507c478bd9Sstevel@tonic-gate * node untouched.
20517c478bd9Sstevel@tonic-gate */
20527c478bd9Sstevel@tonic-gate if (isaflag) {
20537c478bd9Sstevel@tonic-gate if (isaflag == 1)
20547c478bd9Sstevel@tonic-gate *next = _next;
20557c478bd9Sstevel@tonic-gate else
20567c478bd9Sstevel@tonic-gate return ((char *)name);
20577c478bd9Sstevel@tonic-gate }
20587c478bd9Sstevel@tonic-gate
20597c478bd9Sstevel@tonic-gate *nptr = '\0';
20607c478bd9Sstevel@tonic-gate
20617c478bd9Sstevel@tonic-gate if (expanded) {
2062635216b6SRod Evans if ((nptr = libld_malloc(strlen(_name) + 1)) == NULL)
20637c478bd9Sstevel@tonic-gate return ((char *)name);
20647c478bd9Sstevel@tonic-gate (void) strcpy(nptr, _name);
20657c478bd9Sstevel@tonic-gate return (nptr);
20667c478bd9Sstevel@tonic-gate }
20677c478bd9Sstevel@tonic-gate return ((char *)name);
20687c478bd9Sstevel@tonic-gate }
20697c478bd9Sstevel@tonic-gate
20707c478bd9Sstevel@tonic-gate /*
2071d840867fSab196087 * The Solaris ld does not put DT_VERSYM in the dynamic section, but the
2072d840867fSab196087 * GNU ld does, and it is used by the runtime linker to implement their
2073d840867fSab196087 * versioning scheme. Use this fact to determine if the sharable object
2074d840867fSab196087 * was produced by the GNU ld rather than the Solaris one, and to set
2075d840867fSab196087 * FLG_IF_GNUVER if so. This needs to be done before the symbols are
2076d840867fSab196087 * processed, since the answer determines whether we interpret the
2077d840867fSab196087 * symbols versions according to Solaris or GNU rules.
2078d840867fSab196087 */
2079d840867fSab196087 /*ARGSUSED*/
2080d840867fSab196087 static uintptr_t
process_dynamic_isgnu(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)2081d840867fSab196087 process_dynamic_isgnu(const char *name, Ifl_desc *ifl, Shdr *shdr,
2082d840867fSab196087 Elf_Scn *scn, Word ndx, int ident, Ofl_desc *ofl)
2083d840867fSab196087 {
2084d840867fSab196087 Dyn *dyn;
2085d840867fSab196087 Elf_Data *dp;
20860e233487SRod Evans uintptr_t error;
2087d840867fSab196087
20880e233487SRod Evans error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
20890e233487SRod Evans if ((error == 0) || (error == S_ERROR))
20900e233487SRod Evans return (error);
2091d840867fSab196087
2092d840867fSab196087 /* Get the .dynamic data */
2093d840867fSab196087 dp = elf_getdata(scn, NULL);
2094d840867fSab196087
2095d840867fSab196087 for (dyn = (Dyn *)dp->d_buf; dyn->d_tag != DT_NULL; dyn++) {
2096d840867fSab196087 if (dyn->d_tag == DT_VERSYM) {
2097d840867fSab196087 ifl->ifl_flags |= FLG_IF_GNUVER;
2098d840867fSab196087 break;
2099d840867fSab196087 }
2100d840867fSab196087 }
2101d840867fSab196087 return (1);
2102d840867fSab196087 }
2103d840867fSab196087
2104d840867fSab196087 /*
21057c478bd9Sstevel@tonic-gate * Process a dynamic section. If we are processing an explicit shared object
21067c478bd9Sstevel@tonic-gate * then we need to determine if it has a recorded SONAME, if so, this name will
21077c478bd9Sstevel@tonic-gate * be recorded in the output file being generated as the NEEDED entry rather
21087c478bd9Sstevel@tonic-gate * than the shared objects filename itself.
21097c478bd9Sstevel@tonic-gate * If the mode of the link-edit indicates that no undefined symbols should
21107c478bd9Sstevel@tonic-gate * remain, then we also need to build up a list of any additional shared object
21117c478bd9Sstevel@tonic-gate * dependencies this object may have. In this case save any NEEDED entries
21127c478bd9Sstevel@tonic-gate * together with any associated run-path specifications. This information is
21137c478bd9Sstevel@tonic-gate * recorded on the `ofl_soneed' list and will be analyzed after all explicit
21147c478bd9Sstevel@tonic-gate * file processing has been completed (refer finish_libs()).
21157c478bd9Sstevel@tonic-gate */
21165aefb655Srie static uintptr_t
process_dynamic(Is_desc * isc,Ifl_desc * ifl,Ofl_desc * ofl)21177c478bd9Sstevel@tonic-gate process_dynamic(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
21187c478bd9Sstevel@tonic-gate {
21197c478bd9Sstevel@tonic-gate Dyn *data, *dyn;
21207c478bd9Sstevel@tonic-gate char *str, *rpath = NULL;
21217c478bd9Sstevel@tonic-gate const char *soname, *needed;
21221007fd6fSAli Bahrami Boolean no_undef;
21237c478bd9Sstevel@tonic-gate
21247c478bd9Sstevel@tonic-gate data = (Dyn *)isc->is_indata->d_buf;
21257c478bd9Sstevel@tonic-gate str = (char *)ifl->ifl_isdesc[isc->is_shdr->sh_link]->is_indata->d_buf;
21267c478bd9Sstevel@tonic-gate
21271007fd6fSAli Bahrami /* Determine if we need to examine the runpaths and NEEDED entries */
21281007fd6fSAli Bahrami no_undef = (ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)) ||
21291007fd6fSAli Bahrami OFL_GUIDANCE(ofl, FLG_OFG_NO_DEFS);
21301007fd6fSAli Bahrami
21317c478bd9Sstevel@tonic-gate /*
21327c478bd9Sstevel@tonic-gate * First loop through the dynamic section looking for a run path.
21337c478bd9Sstevel@tonic-gate */
21341007fd6fSAli Bahrami if (no_undef) {
21357c478bd9Sstevel@tonic-gate for (dyn = data; dyn->d_tag != DT_NULL; dyn++) {
21367c478bd9Sstevel@tonic-gate if ((dyn->d_tag != DT_RPATH) &&
21377c478bd9Sstevel@tonic-gate (dyn->d_tag != DT_RUNPATH))
21387c478bd9Sstevel@tonic-gate continue;
21397c478bd9Sstevel@tonic-gate if ((rpath = str + (size_t)dyn->d_un.d_val) == NULL)
21407c478bd9Sstevel@tonic-gate continue;
21417c478bd9Sstevel@tonic-gate break;
21427c478bd9Sstevel@tonic-gate }
21437c478bd9Sstevel@tonic-gate }
21447c478bd9Sstevel@tonic-gate
21457c478bd9Sstevel@tonic-gate /*
21467c478bd9Sstevel@tonic-gate * Now look for any needed dependencies (which may use the rpath)
21477c478bd9Sstevel@tonic-gate * or a new SONAME.
21487c478bd9Sstevel@tonic-gate */
21497c478bd9Sstevel@tonic-gate for (dyn = data; dyn->d_tag != DT_NULL; dyn++) {
21507c478bd9Sstevel@tonic-gate if (dyn->d_tag == DT_SONAME) {
21517c478bd9Sstevel@tonic-gate if ((soname = str + (size_t)dyn->d_un.d_val) == NULL)
21527c478bd9Sstevel@tonic-gate continue;
21537c478bd9Sstevel@tonic-gate
21547c478bd9Sstevel@tonic-gate /*
21557c478bd9Sstevel@tonic-gate * Update the input file structure with this new name.
21567c478bd9Sstevel@tonic-gate */
21577c478bd9Sstevel@tonic-gate ifl->ifl_soname = soname;
21587c478bd9Sstevel@tonic-gate
21597c478bd9Sstevel@tonic-gate } else if ((dyn->d_tag == DT_NEEDED) ||
21607c478bd9Sstevel@tonic-gate (dyn->d_tag == DT_USED)) {
216157ef7aa9SRod Evans Sdf_desc *sdf;
216257ef7aa9SRod Evans
21631007fd6fSAli Bahrami if (!no_undef)
21647c478bd9Sstevel@tonic-gate continue;
21657c478bd9Sstevel@tonic-gate if ((needed = str + (size_t)dyn->d_un.d_val) == NULL)
21667c478bd9Sstevel@tonic-gate continue;
21677c478bd9Sstevel@tonic-gate
21687c478bd9Sstevel@tonic-gate /*
21697c478bd9Sstevel@tonic-gate * Determine if this needed entry is already recorded on
21707c478bd9Sstevel@tonic-gate * the shared object needed list, if not create a new
21717c478bd9Sstevel@tonic-gate * definition for later processing (see finish_libs()).
21727c478bd9Sstevel@tonic-gate */
217357ef7aa9SRod Evans needed = expand(ifl->ifl_name, needed, NULL);
21747c478bd9Sstevel@tonic-gate
217557ef7aa9SRod Evans if ((sdf = sdf_find(needed, ofl->ofl_soneed)) == NULL) {
21767c478bd9Sstevel@tonic-gate if ((sdf = sdf_add(needed,
21777c478bd9Sstevel@tonic-gate &ofl->ofl_soneed)) == (Sdf_desc *)S_ERROR)
21787c478bd9Sstevel@tonic-gate return (S_ERROR);
21797c478bd9Sstevel@tonic-gate sdf->sdf_rfile = ifl->ifl_name;
21807c478bd9Sstevel@tonic-gate }
21817c478bd9Sstevel@tonic-gate
21827c478bd9Sstevel@tonic-gate /*
21837c478bd9Sstevel@tonic-gate * Record the runpath (Note that we take the first
21847c478bd9Sstevel@tonic-gate * runpath which is exactly what ld.so.1 would do during
21857c478bd9Sstevel@tonic-gate * its dependency processing).
21867c478bd9Sstevel@tonic-gate */
2187635216b6SRod Evans if (rpath && (sdf->sdf_rpath == NULL))
21887c478bd9Sstevel@tonic-gate sdf->sdf_rpath = rpath;
21897c478bd9Sstevel@tonic-gate
21907c478bd9Sstevel@tonic-gate } else if (dyn->d_tag == DT_FLAGS_1) {
21917c478bd9Sstevel@tonic-gate if (dyn->d_un.d_val & (DF_1_INITFIRST | DF_1_INTERPOSE))
21927c478bd9Sstevel@tonic-gate ifl->ifl_flags &= ~FLG_IF_LAZYLD;
21937c478bd9Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_DISPRELPND)
21947c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DISPPEND;
21957c478bd9Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_DISPRELDNE)
21967c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DISPDONE;
21977c478bd9Sstevel@tonic-gate if (dyn->d_un.d_val & DF_1_NODIRECT)
21987c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_NODIRECT;
21997c478bd9Sstevel@tonic-gate
22001007fd6fSAli Bahrami /*
22011007fd6fSAli Bahrami * If we are building an executable, and this
22021007fd6fSAli Bahrami * dependency is tagged as an interposer, then
22031007fd6fSAli Bahrami * assume that it is required even if symbol
22041007fd6fSAli Bahrami * resolution uncovers no evident use.
22051007fd6fSAli Bahrami *
22061007fd6fSAli Bahrami * If we are building a shared object, then an
22071007fd6fSAli Bahrami * interposer dependency has no special meaning, and we
22081007fd6fSAli Bahrami * treat it as a regular dependency. By definition, all
22091007fd6fSAli Bahrami * interposers must be visible to the runtime linker
22101007fd6fSAli Bahrami * at initialization time, and cannot be added later.
22111007fd6fSAli Bahrami */
22121007fd6fSAli Bahrami if ((dyn->d_un.d_val & DF_1_INTERPOSE) &&
22131007fd6fSAli Bahrami (ofl->ofl_flags & FLG_OF_EXEC))
22141007fd6fSAli Bahrami ifl->ifl_flags |= FLG_IF_DEPREQD;
22151007fd6fSAli Bahrami
22167c478bd9Sstevel@tonic-gate } else if ((dyn->d_tag == DT_AUDIT) &&
22177c478bd9Sstevel@tonic-gate (ifl->ifl_flags & FLG_IF_NEEDED)) {
22187c478bd9Sstevel@tonic-gate /*
22197c478bd9Sstevel@tonic-gate * Record audit string as DT_DEPAUDIT.
22207c478bd9Sstevel@tonic-gate */
22217c478bd9Sstevel@tonic-gate if ((ofl->ofl_depaudit = add_string(ofl->ofl_depaudit,
22227c478bd9Sstevel@tonic-gate (str + (size_t)dyn->d_un.d_val))) ==
22237c478bd9Sstevel@tonic-gate (const char *)S_ERROR)
22247c478bd9Sstevel@tonic-gate return (S_ERROR);
22257c478bd9Sstevel@tonic-gate
22267c478bd9Sstevel@tonic-gate } else if (dyn->d_tag == DT_SUNW_RTLDINF) {
22277c478bd9Sstevel@tonic-gate /*
2228f441771bSRod Evans * If this dependency has the DT_SUNW_RTLDINF .dynamic
2229f441771bSRod Evans * entry, then ensure no specialized dependency
2230f441771bSRod Evans * processing is in effect. This tag identifies libc,
2231f441771bSRod Evans * which provides critical startup information (TLS
2232f441771bSRod Evans * routines, threads initialization, etc.) that must
2233f441771bSRod Evans * be exercised as part of process initialization.
22347c478bd9Sstevel@tonic-gate */
2235f441771bSRod Evans ifl->ifl_flags &= ~MSK_IF_POSFLAG1;
22361007fd6fSAli Bahrami
22371007fd6fSAli Bahrami /*
22381007fd6fSAli Bahrami * libc is not subject to the usual guidance checks
22391007fd6fSAli Bahrami * for lazy loading. It cannot be lazy loaded, libld
22401007fd6fSAli Bahrami * ignores the request, and rtld would ignore the
22411007fd6fSAli Bahrami * setting if it were present.
22421007fd6fSAli Bahrami */
22431007fd6fSAli Bahrami ifl->ifl_flags |= FLG_IF_RTLDINF;
22447c478bd9Sstevel@tonic-gate }
22457c478bd9Sstevel@tonic-gate }
22467c478bd9Sstevel@tonic-gate
22477c478bd9Sstevel@tonic-gate /*
22487c478bd9Sstevel@tonic-gate * Perform some SONAME sanity checks.
22497c478bd9Sstevel@tonic-gate */
22507c478bd9Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_NEEDED) {
22517c478bd9Sstevel@tonic-gate Ifl_desc *sifl;
225257ef7aa9SRod Evans Aliste idx;
22537c478bd9Sstevel@tonic-gate
22547c478bd9Sstevel@tonic-gate /*
22557c478bd9Sstevel@tonic-gate * Determine if anyone else will cause the same SONAME to be
22567c478bd9Sstevel@tonic-gate * used (this is either caused by two different files having the
22577c478bd9Sstevel@tonic-gate * same SONAME, or by one file SONAME actually matching another
22587c478bd9Sstevel@tonic-gate * file basename (if no SONAME is specified within a shared
22597c478bd9Sstevel@tonic-gate * library its basename will be used)). Probably rare, but some
22607c478bd9Sstevel@tonic-gate * idiot will do it.
22617c478bd9Sstevel@tonic-gate */
226257ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_sos, idx, sifl)) {
22637c478bd9Sstevel@tonic-gate if ((strcmp(ifl->ifl_soname, sifl->ifl_soname) == 0) &&
22647c478bd9Sstevel@tonic-gate (ifl != sifl)) {
22657c478bd9Sstevel@tonic-gate const char *hint, *iflb, *siflb;
22667c478bd9Sstevel@tonic-gate
22677c478bd9Sstevel@tonic-gate /*
22687c478bd9Sstevel@tonic-gate * Determine the basename of each file. Perhaps
22697c478bd9Sstevel@tonic-gate * there are multiple copies of the same file
22707c478bd9Sstevel@tonic-gate * being brought in using different -L search
22717c478bd9Sstevel@tonic-gate * paths, and if so give an extra hint in the
22727c478bd9Sstevel@tonic-gate * error message.
22737c478bd9Sstevel@tonic-gate */
22747c478bd9Sstevel@tonic-gate iflb = strrchr(ifl->ifl_name, '/');
22757c478bd9Sstevel@tonic-gate if (iflb == NULL)
22767c478bd9Sstevel@tonic-gate iflb = ifl->ifl_name;
22777c478bd9Sstevel@tonic-gate else
22787c478bd9Sstevel@tonic-gate iflb++;
22797c478bd9Sstevel@tonic-gate
22807c478bd9Sstevel@tonic-gate siflb = strrchr(sifl->ifl_name, '/');
22817c478bd9Sstevel@tonic-gate if (siflb == NULL)
22827c478bd9Sstevel@tonic-gate siflb = sifl->ifl_name;
22837c478bd9Sstevel@tonic-gate else
22847c478bd9Sstevel@tonic-gate siflb++;
22857c478bd9Sstevel@tonic-gate
22867c478bd9Sstevel@tonic-gate if (strcmp(iflb, siflb) == 0)
22877c478bd9Sstevel@tonic-gate hint = MSG_INTL(MSG_REC_CNFLTHINT);
22887c478bd9Sstevel@tonic-gate else
22897c478bd9Sstevel@tonic-gate hint = MSG_ORIG(MSG_STR_EMPTY);
22907c478bd9Sstevel@tonic-gate
22911007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
22925aefb655Srie MSG_INTL(MSG_REC_OBJCNFLT), sifl->ifl_name,
22935aefb655Srie ifl->ifl_name, sifl->ifl_soname, hint);
22947c478bd9Sstevel@tonic-gate return (0);
22957c478bd9Sstevel@tonic-gate }
22967c478bd9Sstevel@tonic-gate }
22977c478bd9Sstevel@tonic-gate
22987c478bd9Sstevel@tonic-gate /*
22997c478bd9Sstevel@tonic-gate * If the SONAME is the same as the name the user wishes to
23007c478bd9Sstevel@tonic-gate * record when building a dynamic library (refer -h option),
23017c478bd9Sstevel@tonic-gate * we also have a name clash.
23027c478bd9Sstevel@tonic-gate */
23037c478bd9Sstevel@tonic-gate if (ofl->ofl_soname &&
23047c478bd9Sstevel@tonic-gate (strcmp(ofl->ofl_soname, ifl->ifl_soname) == 0)) {
23051007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
23065aefb655Srie MSG_INTL(MSG_REC_OPTCNFLT), ifl->ifl_name,
2307551cffe3SAli Bahrami MSG_INTL(MSG_MARG_SONAME), ifl->ifl_soname);
23087c478bd9Sstevel@tonic-gate return (0);
23097c478bd9Sstevel@tonic-gate }
23107c478bd9Sstevel@tonic-gate }
23117c478bd9Sstevel@tonic-gate return (1);
23127c478bd9Sstevel@tonic-gate }
23137c478bd9Sstevel@tonic-gate
23147c478bd9Sstevel@tonic-gate /*
23157e16fca0SAli Bahrami * Process a progbits section from a relocatable object (ET_REL).
23167e16fca0SAli Bahrami * This is used on non-amd64 objects to recognize .eh_frame sections.
23177e16fca0SAli Bahrami */
23187e16fca0SAli Bahrami /*ARGSUSED1*/
23197e16fca0SAli Bahrami static uintptr_t
process_progbits_final(Is_desc * isc,Ifl_desc * ifl,Ofl_desc * ofl)23207e16fca0SAli Bahrami process_progbits_final(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
23217e16fca0SAli Bahrami {
23227e16fca0SAli Bahrami if (isc->is_osdesc && (isc->is_flags & FLG_IS_EHFRAME) &&
23237e16fca0SAli Bahrami (ld_unwind_register(isc->is_osdesc, ofl) == S_ERROR))
23247e16fca0SAli Bahrami return (S_ERROR);
23257e16fca0SAli Bahrami
23267e16fca0SAli Bahrami return (1);
23277e16fca0SAli Bahrami }
23287e16fca0SAli Bahrami
23297e16fca0SAli Bahrami /*
23300e233487SRod Evans * Process a group section.
23310e233487SRod Evans */
23320e233487SRod Evans static uintptr_t
process_group(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,int ident,Ofl_desc * ofl)23330e233487SRod Evans process_group(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
23340e233487SRod Evans Word ndx, int ident, Ofl_desc *ofl)
23350e233487SRod Evans {
23360e233487SRod Evans uintptr_t error;
23370e233487SRod Evans
23380e233487SRod Evans error = process_section(name, ifl, shdr, scn, ndx, ident, ofl);
23390e233487SRod Evans if ((error == 0) || (error == S_ERROR))
23400e233487SRod Evans return (error);
23410e233487SRod Evans
23420e233487SRod Evans /*
23430e233487SRod Evans * Indicate that this input file has groups to process. Groups are
23440e233487SRod Evans * processed after all input sections have been processed.
23450e233487SRod Evans */
2346a8c23f9dSRichard Lowe ifl->ifl_flags |= FLG_IF_GROUPS;
23470e233487SRod Evans
23480e233487SRod Evans return (1);
23490e233487SRod Evans }
23500e233487SRod Evans
23510e233487SRod Evans /*
23527c478bd9Sstevel@tonic-gate * Process a relocation entry. At this point all input sections from this
23537c478bd9Sstevel@tonic-gate * input file have been assigned an input section descriptor which is saved
23547c478bd9Sstevel@tonic-gate * in the `ifl_isdesc' array.
23557c478bd9Sstevel@tonic-gate */
23565aefb655Srie static uintptr_t
rel_process(Is_desc * isc,Ifl_desc * ifl,Ofl_desc * ofl)23577c478bd9Sstevel@tonic-gate rel_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
23587c478bd9Sstevel@tonic-gate {
23597c478bd9Sstevel@tonic-gate Word rndx;
23607c478bd9Sstevel@tonic-gate Is_desc *risc;
23617c478bd9Sstevel@tonic-gate Os_desc *osp;
23627c478bd9Sstevel@tonic-gate Shdr *shdr = isc->is_shdr;
2363de777a60Sab196087 Conv_inv_buf_t inv_buf;
23647c478bd9Sstevel@tonic-gate
23657c478bd9Sstevel@tonic-gate /*
23667c478bd9Sstevel@tonic-gate * Make sure this is a valid relocation we can handle.
23677c478bd9Sstevel@tonic-gate */
2368ba2be530Sab196087 if (shdr->sh_type != ld_targ.t_m.m_rel_sht_type) {
23691007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVALSEC),
23704a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(isc->is_scnndx), isc->is_name,
23714f680cc6SAli Bahrami conv_sec_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
23724f680cc6SAli Bahrami ifl->ifl_ehdr->e_machine, shdr->sh_type, 0, &inv_buf));
23737c478bd9Sstevel@tonic-gate return (0);
23747c478bd9Sstevel@tonic-gate }
23757c478bd9Sstevel@tonic-gate
23767c478bd9Sstevel@tonic-gate /*
23777c478bd9Sstevel@tonic-gate * From the relocation section header information determine which
23787c478bd9Sstevel@tonic-gate * section needs the actual relocation. Determine which output section
23797c478bd9Sstevel@tonic-gate * this input section has been assigned to and add to its relocation
23807c478bd9Sstevel@tonic-gate * list. Note that the relocation section may be null if it is not
23817c478bd9Sstevel@tonic-gate * required (ie. .debug, .stabs, etc).
23827c478bd9Sstevel@tonic-gate */
23837c478bd9Sstevel@tonic-gate rndx = shdr->sh_info;
23847c478bd9Sstevel@tonic-gate if (rndx >= ifl->ifl_shnum) {
23857c478bd9Sstevel@tonic-gate /*
23867c478bd9Sstevel@tonic-gate * Broken input file.
23877c478bd9Sstevel@tonic-gate */
23881007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHINFO),
23894a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(isc->is_scnndx), isc->is_name,
23904a8d0ea7SAli Bahrami EC_XWORD(rndx));
23917c478bd9Sstevel@tonic-gate return (0);
23927c478bd9Sstevel@tonic-gate }
23937c478bd9Sstevel@tonic-gate if (rndx == 0) {
239457ef7aa9SRod Evans if (aplist_append(&ofl->ofl_extrarels, isc,
239557ef7aa9SRod Evans AL_CNT_OFL_RELS) == NULL)
23967c478bd9Sstevel@tonic-gate return (S_ERROR);
239757ef7aa9SRod Evans
239857ef7aa9SRod Evans } else if ((risc = ifl->ifl_isdesc[rndx]) != NULL) {
23997c478bd9Sstevel@tonic-gate /*
24007c478bd9Sstevel@tonic-gate * Discard relocations if they are against a section
24017c478bd9Sstevel@tonic-gate * which has been discarded.
24027c478bd9Sstevel@tonic-gate */
24037c478bd9Sstevel@tonic-gate if (risc->is_flags & FLG_IS_DISCARD)
24047c478bd9Sstevel@tonic-gate return (1);
240557ef7aa9SRod Evans
240657ef7aa9SRod Evans if ((osp = risc->is_osdesc) == NULL) {
24077c478bd9Sstevel@tonic-gate if (risc->is_shdr->sh_type == SHT_SUNW_move) {
24087c478bd9Sstevel@tonic-gate /*
240957ef7aa9SRod Evans * This section is processed later in
241057ef7aa9SRod Evans * process_movereloc().
24117c478bd9Sstevel@tonic-gate */
241257ef7aa9SRod Evans if (aplist_append(&ofl->ofl_ismoverel,
241357ef7aa9SRod Evans isc, AL_CNT_OFL_MOVE) == NULL)
24147c478bd9Sstevel@tonic-gate return (S_ERROR);
24157c478bd9Sstevel@tonic-gate return (1);
24167c478bd9Sstevel@tonic-gate }
24171007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
24185aefb655Srie MSG_INTL(MSG_FIL_INVRELOC1), ifl->ifl_name,
24194a8d0ea7SAli Bahrami EC_WORD(isc->is_scnndx), isc->is_name,
24204a8d0ea7SAli Bahrami EC_WORD(risc->is_scnndx), risc->is_name);
24217c478bd9Sstevel@tonic-gate return (0);
24227c478bd9Sstevel@tonic-gate }
24236b3ba5bdSAli Bahrami if (aplist_append(&osp->os_relisdescs, isc,
24246b3ba5bdSAli Bahrami AL_CNT_OS_RELISDESCS) == NULL)
24257c478bd9Sstevel@tonic-gate return (S_ERROR);
24267c478bd9Sstevel@tonic-gate }
24277c478bd9Sstevel@tonic-gate return (1);
24287c478bd9Sstevel@tonic-gate }
24297c478bd9Sstevel@tonic-gate
24307c478bd9Sstevel@tonic-gate /*
24317c478bd9Sstevel@tonic-gate * SHF_EXCLUDE flags is set for this section.
24327c478bd9Sstevel@tonic-gate */
24337c478bd9Sstevel@tonic-gate static uintptr_t
process_exclude(const char * name,Ifl_desc * ifl,Shdr * shdr,Elf_Scn * scn,Word ndx,Ofl_desc * ofl)24347c478bd9Sstevel@tonic-gate process_exclude(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
24357c478bd9Sstevel@tonic-gate Word ndx, Ofl_desc *ofl)
24367c478bd9Sstevel@tonic-gate {
24377c478bd9Sstevel@tonic-gate /*
24387c478bd9Sstevel@tonic-gate * Sections SHT_SYMTAB and SHT_DYNDYM, even if SHF_EXCLUDE is on, might
24397c478bd9Sstevel@tonic-gate * be needed for ld processing. These sections need to be in the
24407c478bd9Sstevel@tonic-gate * internal table. Later it will be determined whether they can be
24417c478bd9Sstevel@tonic-gate * eliminated or not.
24427c478bd9Sstevel@tonic-gate */
24437c478bd9Sstevel@tonic-gate if (shdr->sh_type == SHT_SYMTAB || shdr->sh_type == SHT_DYNSYM)
24447c478bd9Sstevel@tonic-gate return (0);
24457c478bd9Sstevel@tonic-gate
24467c478bd9Sstevel@tonic-gate /*
24477c478bd9Sstevel@tonic-gate * Other checks
24487c478bd9Sstevel@tonic-gate */
24497c478bd9Sstevel@tonic-gate if (shdr->sh_flags & SHF_ALLOC) {
24507c478bd9Sstevel@tonic-gate /*
24517c478bd9Sstevel@tonic-gate * A conflict, issue an warning message, and ignore the section.
24527c478bd9Sstevel@tonic-gate */
24531007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_FIL_EXCLUDE),
24544a8d0ea7SAli Bahrami ifl->ifl_name, EC_WORD(ndx), name);
24557c478bd9Sstevel@tonic-gate return (0);
24567c478bd9Sstevel@tonic-gate }
24577c478bd9Sstevel@tonic-gate
24587c478bd9Sstevel@tonic-gate /*
24597c478bd9Sstevel@tonic-gate * This sections is not going to the output file.
24607c478bd9Sstevel@tonic-gate */
24617c478bd9Sstevel@tonic-gate return (process_section(name, ifl, shdr, scn, ndx, 0, ofl));
24627c478bd9Sstevel@tonic-gate }
24637c478bd9Sstevel@tonic-gate
24647c478bd9Sstevel@tonic-gate /*
24657c478bd9Sstevel@tonic-gate * Section processing state table. `Initial' describes the required initial
24667c478bd9Sstevel@tonic-gate * procedure to be called (if any), `Final' describes the final processing
24677c478bd9Sstevel@tonic-gate * procedure (ie. things that can only be done when all required sections
24687c478bd9Sstevel@tonic-gate * have been collected).
24697c478bd9Sstevel@tonic-gate */
24707e16fca0SAli Bahrami typedef uintptr_t (* initial_func_t)(const char *, Ifl_desc *, Shdr *,
24717e16fca0SAli Bahrami Elf_Scn *, Word, int, Ofl_desc *);
24727c478bd9Sstevel@tonic-gate
24737e16fca0SAli Bahrami static initial_func_t Initial[SHT_NUM][2] = {
24747c478bd9Sstevel@tonic-gate /* ET_REL ET_DYN */
24757c478bd9Sstevel@tonic-gate
24767c478bd9Sstevel@tonic-gate /* SHT_NULL */ invalid_section, invalid_section,
24777c478bd9Sstevel@tonic-gate /* SHT_PROGBITS */ process_progbits, process_progbits,
24787c478bd9Sstevel@tonic-gate /* SHT_SYMTAB */ process_input, process_input,
24797c478bd9Sstevel@tonic-gate /* SHT_STRTAB */ process_strtab, process_strtab,
24807c478bd9Sstevel@tonic-gate /* SHT_RELA */ process_reloc, process_reloc,
24817c478bd9Sstevel@tonic-gate /* SHT_HASH */ invalid_section, NULL,
2482d840867fSab196087 /* SHT_DYNAMIC */ process_rel_dynamic, process_dynamic_isgnu,
24837c478bd9Sstevel@tonic-gate /* SHT_NOTE */ process_section, NULL,
24847c478bd9Sstevel@tonic-gate /* SHT_NOBITS */ process_nobits, process_nobits,
24857c478bd9Sstevel@tonic-gate /* SHT_REL */ process_reloc, process_reloc,
24867c478bd9Sstevel@tonic-gate /* SHT_SHLIB */ process_section, invalid_section,
24877c478bd9Sstevel@tonic-gate /* SHT_DYNSYM */ invalid_section, process_input,
24887c478bd9Sstevel@tonic-gate /* SHT_UNKNOWN12 */ process_progbits, process_progbits,
24897c478bd9Sstevel@tonic-gate /* SHT_UNKNOWN13 */ process_progbits, process_progbits,
24907c478bd9Sstevel@tonic-gate /* SHT_INIT_ARRAY */ process_array, NULL,
24917c478bd9Sstevel@tonic-gate /* SHT_FINI_ARRAY */ process_array, NULL,
24927c478bd9Sstevel@tonic-gate /* SHT_PREINIT_ARRAY */ process_array, NULL,
24930e233487SRod Evans /* SHT_GROUP */ process_group, invalid_section,
24947c478bd9Sstevel@tonic-gate /* SHT_SYMTAB_SHNDX */ process_sym_shndx, NULL
24957c478bd9Sstevel@tonic-gate };
24967c478bd9Sstevel@tonic-gate
24977e16fca0SAli Bahrami typedef uintptr_t (* final_func_t)(Is_desc *, Ifl_desc *, Ofl_desc *);
24987e16fca0SAli Bahrami
24997e16fca0SAli Bahrami static final_func_t Final[SHT_NUM][2] = {
25007e16fca0SAli Bahrami /* ET_REL ET_DYN */
25017c478bd9Sstevel@tonic-gate
25027c478bd9Sstevel@tonic-gate /* SHT_NULL */ NULL, NULL,
25037e16fca0SAli Bahrami /* SHT_PROGBITS */ process_progbits_final, NULL,
25045aefb655Srie /* SHT_SYMTAB */ ld_sym_process, ld_sym_process,
25057c478bd9Sstevel@tonic-gate /* SHT_STRTAB */ NULL, NULL,
25067c478bd9Sstevel@tonic-gate /* SHT_RELA */ rel_process, NULL,
25077c478bd9Sstevel@tonic-gate /* SHT_HASH */ NULL, NULL,
25087c478bd9Sstevel@tonic-gate /* SHT_DYNAMIC */ NULL, process_dynamic,
25097c478bd9Sstevel@tonic-gate /* SHT_NOTE */ NULL, NULL,
25107c478bd9Sstevel@tonic-gate /* SHT_NOBITS */ NULL, NULL,
25117c478bd9Sstevel@tonic-gate /* SHT_REL */ rel_process, NULL,
25127c478bd9Sstevel@tonic-gate /* SHT_SHLIB */ NULL, NULL,
25135aefb655Srie /* SHT_DYNSYM */ NULL, ld_sym_process,
25147c478bd9Sstevel@tonic-gate /* SHT_UNKNOWN12 */ NULL, NULL,
25157c478bd9Sstevel@tonic-gate /* SHT_UNKNOWN13 */ NULL, NULL,
25160e233487SRod Evans /* SHT_INIT_ARRAY */ array_process, NULL,
25170e233487SRod Evans /* SHT_FINI_ARRAY */ array_process, NULL,
25180e233487SRod Evans /* SHT_PREINIT_ARRAY */ array_process, NULL,
25197c478bd9Sstevel@tonic-gate /* SHT_GROUP */ NULL, NULL,
25207c478bd9Sstevel@tonic-gate /* SHT_SYMTAB_SHNDX */ sym_shndx_process, NULL
25217c478bd9Sstevel@tonic-gate };
25227c478bd9Sstevel@tonic-gate
25237c478bd9Sstevel@tonic-gate #define MAXNDXSIZE 10
25247c478bd9Sstevel@tonic-gate
25257c478bd9Sstevel@tonic-gate /*
25267c478bd9Sstevel@tonic-gate * Process an elf file. Each section is compared against the section state
25277c478bd9Sstevel@tonic-gate * table to determine whether it should be processed (saved), ignored, or
25287c478bd9Sstevel@tonic-gate * is invalid for the type of input file being processed.
25297c478bd9Sstevel@tonic-gate */
25305aefb655Srie static uintptr_t
process_elf(Ifl_desc * ifl,Elf * elf,Ofl_desc * ofl)25317c478bd9Sstevel@tonic-gate process_elf(Ifl_desc *ifl, Elf *elf, Ofl_desc *ofl)
25327c478bd9Sstevel@tonic-gate {
25337c478bd9Sstevel@tonic-gate Elf_Scn *scn;
25347c478bd9Sstevel@tonic-gate Shdr *shdr;
25350e233487SRod Evans Word ndx, sndx, ordndx = 0, ordcnt = 0;
25364a8d0ea7SAli Bahrami char *str, *name;
25377c478bd9Sstevel@tonic-gate Word row, column;
25387c478bd9Sstevel@tonic-gate int ident;
25397c478bd9Sstevel@tonic-gate uintptr_t error;
254008278a5eSRod Evans Is_desc *vdfisp, *vndisp, *vsyisp, *sifisp;
254108278a5eSRod Evans Is_desc *capinfoisp, *capisp;
25427c478bd9Sstevel@tonic-gate Sdf_desc *sdf;
254369112eddSAli Bahrami Place_path_info path_info_buf, *path_info;
254469112eddSAli Bahrami
254569112eddSAli Bahrami /*
254669112eddSAli Bahrami * Path information buffer used by ld_place_section() and related
254769112eddSAli Bahrami * routines. This information is used to evaluate entrance criteria
254869112eddSAli Bahrami * with non-empty file matching lists (ec_files).
254969112eddSAli Bahrami */
255069112eddSAli Bahrami path_info = ld_place_path_info_init(ofl, ifl, &path_info_buf);
25517c478bd9Sstevel@tonic-gate
25527c478bd9Sstevel@tonic-gate /*
25537c478bd9Sstevel@tonic-gate * First process the .shstrtab section so that later sections can
25547c478bd9Sstevel@tonic-gate * reference their name.
25557c478bd9Sstevel@tonic-gate */
25565aefb655Srie ld_sup_file(ofl, ifl->ifl_name, elf_kind(elf), ifl->ifl_flags, elf);
25577c478bd9Sstevel@tonic-gate
25587c478bd9Sstevel@tonic-gate sndx = ifl->ifl_shstrndx;
25597c478bd9Sstevel@tonic-gate if ((scn = elf_getscn(elf, (size_t)sndx)) == NULL) {
25601007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSCN),
25615aefb655Srie ifl->ifl_name);
25627c478bd9Sstevel@tonic-gate return (0);
25637c478bd9Sstevel@tonic-gate }
25647c478bd9Sstevel@tonic-gate if ((shdr = elf_getshdr(scn)) == NULL) {
25651007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR),
25665aefb655Srie ifl->ifl_name);
25677c478bd9Sstevel@tonic-gate return (0);
25687c478bd9Sstevel@tonic-gate }
25697c478bd9Sstevel@tonic-gate if ((name = elf_strptr(elf, (size_t)sndx, (size_t)shdr->sh_name)) ==
25707c478bd9Sstevel@tonic-gate NULL) {
25711007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR),
25725aefb655Srie ifl->ifl_name);
25737c478bd9Sstevel@tonic-gate return (0);
25747c478bd9Sstevel@tonic-gate }
25757c478bd9Sstevel@tonic-gate
25767010c12aSrie if (ld_sup_input_section(ofl, ifl, name, &shdr, sndx, scn,
25777010c12aSrie elf) == S_ERROR)
25787c478bd9Sstevel@tonic-gate return (S_ERROR);
25797c478bd9Sstevel@tonic-gate
25807c478bd9Sstevel@tonic-gate /*
25817c478bd9Sstevel@tonic-gate * Reset the name since the shdr->sh_name could have been changed as
25824a8d0ea7SAli Bahrami * part of ld_sup_input_section().
25837c478bd9Sstevel@tonic-gate */
25844a8d0ea7SAli Bahrami if ((name = elf_strptr(elf, (size_t)sndx, (size_t)shdr->sh_name)) ==
25854a8d0ea7SAli Bahrami NULL) {
25861007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_STRPTR),
25875aefb655Srie ifl->ifl_name);
25887c478bd9Sstevel@tonic-gate return (0);
25897c478bd9Sstevel@tonic-gate }
25907c478bd9Sstevel@tonic-gate
25917c478bd9Sstevel@tonic-gate error = process_strtab(name, ifl, shdr, scn, sndx, FALSE, ofl);
25927c478bd9Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR))
25937c478bd9Sstevel@tonic-gate return (error);
25947c478bd9Sstevel@tonic-gate str = ifl->ifl_isdesc[sndx]->is_indata->d_buf;
25957c478bd9Sstevel@tonic-gate
25967c478bd9Sstevel@tonic-gate /*
25977c478bd9Sstevel@tonic-gate * Determine the state table column from the input file type. Note,
25987c478bd9Sstevel@tonic-gate * shared library sections are not added to the output section list.
25997c478bd9Sstevel@tonic-gate */
26007c478bd9Sstevel@tonic-gate if (ifl->ifl_ehdr->e_type == ET_DYN) {
26017c478bd9Sstevel@tonic-gate column = 1;
26027c478bd9Sstevel@tonic-gate ofl->ofl_soscnt++;
2603ba2be530Sab196087 ident = ld_targ.t_id.id_null;
26047c478bd9Sstevel@tonic-gate } else {
26057c478bd9Sstevel@tonic-gate column = 0;
26067c478bd9Sstevel@tonic-gate ofl->ofl_objscnt++;
2607ba2be530Sab196087 ident = ld_targ.t_id.id_unknown;
26087c478bd9Sstevel@tonic-gate }
26097c478bd9Sstevel@tonic-gate
26105aefb655Srie DBG_CALL(Dbg_file_generic(ofl->ofl_lml, ifl));
26117c478bd9Sstevel@tonic-gate ndx = 0;
261208278a5eSRod Evans vdfisp = vndisp = vsyisp = sifisp = capinfoisp = capisp = NULL;
26137c478bd9Sstevel@tonic-gate scn = NULL;
26147c478bd9Sstevel@tonic-gate while (scn = elf_nextscn(elf, scn)) {
26157c478bd9Sstevel@tonic-gate ndx++;
26160e233487SRod Evans
26177c478bd9Sstevel@tonic-gate /*
26187c478bd9Sstevel@tonic-gate * As we've already processed the .shstrtab don't do it again.
26197c478bd9Sstevel@tonic-gate */
26207c478bd9Sstevel@tonic-gate if (ndx == sndx)
26217c478bd9Sstevel@tonic-gate continue;
26227c478bd9Sstevel@tonic-gate
26237c478bd9Sstevel@tonic-gate if ((shdr = elf_getshdr(scn)) == NULL) {
26241007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_GETSHDR),
26251007fd6fSAli Bahrami ifl->ifl_name);
26267c478bd9Sstevel@tonic-gate return (0);
26277c478bd9Sstevel@tonic-gate }
26287c478bd9Sstevel@tonic-gate name = str + (size_t)(shdr->sh_name);
26297c478bd9Sstevel@tonic-gate
26307010c12aSrie if (ld_sup_input_section(ofl, ifl, name, &shdr, ndx, scn,
26317010c12aSrie elf) == S_ERROR)
26327c478bd9Sstevel@tonic-gate return (S_ERROR);
26337c478bd9Sstevel@tonic-gate
26347c478bd9Sstevel@tonic-gate /*
26357c478bd9Sstevel@tonic-gate * Reset the name since the shdr->sh_name could have been
26364a8d0ea7SAli Bahrami * changed as part of ld_sup_input_section().
26377c478bd9Sstevel@tonic-gate */
26387c478bd9Sstevel@tonic-gate name = str + (size_t)(shdr->sh_name);
26397c478bd9Sstevel@tonic-gate
26407c478bd9Sstevel@tonic-gate row = shdr->sh_type;
26417c478bd9Sstevel@tonic-gate
26427c478bd9Sstevel@tonic-gate /*
26437c478bd9Sstevel@tonic-gate * If the section has the SHF_EXCLUDE flag on, and we're not
26447c478bd9Sstevel@tonic-gate * generating a relocatable object, exclude the section.
26457c478bd9Sstevel@tonic-gate */
26467c478bd9Sstevel@tonic-gate if (((shdr->sh_flags & SHF_EXCLUDE) != 0) &&
26477c478bd9Sstevel@tonic-gate ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0)) {
26487c478bd9Sstevel@tonic-gate if ((error = process_exclude(name, ifl, shdr, scn,
26497c478bd9Sstevel@tonic-gate ndx, ofl)) == S_ERROR)
26507c478bd9Sstevel@tonic-gate return (S_ERROR);
26517c478bd9Sstevel@tonic-gate if (error == 1)
26527c478bd9Sstevel@tonic-gate continue;
26537c478bd9Sstevel@tonic-gate }
26547c478bd9Sstevel@tonic-gate
26557c478bd9Sstevel@tonic-gate /*
26567c478bd9Sstevel@tonic-gate * If this is a standard section type process it via the
26577c478bd9Sstevel@tonic-gate * appropriate action routine.
26587c478bd9Sstevel@tonic-gate */
26597c478bd9Sstevel@tonic-gate if (row < SHT_NUM) {
26607c478bd9Sstevel@tonic-gate if (Initial[row][column] != NULL) {
26617c478bd9Sstevel@tonic-gate if (Initial[row][column](name, ifl, shdr, scn,
26627c478bd9Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR)
26637c478bd9Sstevel@tonic-gate return (S_ERROR);
26647c478bd9Sstevel@tonic-gate }
26657c478bd9Sstevel@tonic-gate } else {
26667c478bd9Sstevel@tonic-gate /*
26677c478bd9Sstevel@tonic-gate * If this section is below SHT_LOSUNW then we don't
26687c478bd9Sstevel@tonic-gate * really know what to do with it, issue a warning
26697c478bd9Sstevel@tonic-gate * message but do the basic section processing anyway.
26707c478bd9Sstevel@tonic-gate */
2671de777a60Sab196087 if (row < (Word)SHT_LOSUNW) {
2672de777a60Sab196087 Conv_inv_buf_t inv_buf;
2673de777a60Sab196087
26741007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
26755aefb655Srie MSG_INTL(MSG_FIL_INVALSEC), ifl->ifl_name,
26764a8d0ea7SAli Bahrami EC_WORD(ndx), name, conv_sec_type(
26774f680cc6SAli Bahrami ifl->ifl_ehdr->e_ident[EI_OSABI],
26784f680cc6SAli Bahrami ifl->ifl_ehdr->e_machine,
2679de777a60Sab196087 shdr->sh_type, 0, &inv_buf));
2680de777a60Sab196087 }
26817c478bd9Sstevel@tonic-gate
26827c478bd9Sstevel@tonic-gate /*
26837c478bd9Sstevel@tonic-gate * Handle sections greater than SHT_LOSUNW.
26847c478bd9Sstevel@tonic-gate */
26857c478bd9Sstevel@tonic-gate switch (row) {
26867c478bd9Sstevel@tonic-gate case SHT_SUNW_dof:
26877c478bd9Sstevel@tonic-gate if (process_section(name, ifl, shdr, scn,
26887c478bd9Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR)
26897c478bd9Sstevel@tonic-gate return (S_ERROR);
26907c478bd9Sstevel@tonic-gate break;
26917c478bd9Sstevel@tonic-gate case SHT_SUNW_cap:
26927e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
26937e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
26947c478bd9Sstevel@tonic-gate return (S_ERROR);
26957c478bd9Sstevel@tonic-gate capisp = ifl->ifl_isdesc[ndx];
26967c478bd9Sstevel@tonic-gate break;
269708278a5eSRod Evans case SHT_SUNW_capinfo:
269808278a5eSRod Evans if (process_section(name, ifl, shdr, scn, ndx,
269908278a5eSRod Evans ld_targ.t_id.id_null, ofl) == S_ERROR)
270008278a5eSRod Evans return (S_ERROR);
270108278a5eSRod Evans capinfoisp = ifl->ifl_isdesc[ndx];
270208278a5eSRod Evans break;
27037c478bd9Sstevel@tonic-gate case SHT_SUNW_DEBUGSTR:
27047c478bd9Sstevel@tonic-gate case SHT_SUNW_DEBUG:
27057c478bd9Sstevel@tonic-gate if (process_debug(name, ifl, shdr, scn,
27067c478bd9Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR)
27077c478bd9Sstevel@tonic-gate return (S_ERROR);
27087c478bd9Sstevel@tonic-gate break;
27097c478bd9Sstevel@tonic-gate case SHT_SUNW_move:
27107e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27117e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
27127c478bd9Sstevel@tonic-gate return (S_ERROR);
27137c478bd9Sstevel@tonic-gate break;
27147c478bd9Sstevel@tonic-gate case SHT_SUNW_syminfo:
27157e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27167e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
27177c478bd9Sstevel@tonic-gate return (S_ERROR);
27187c478bd9Sstevel@tonic-gate sifisp = ifl->ifl_isdesc[ndx];
27197c478bd9Sstevel@tonic-gate break;
27207c478bd9Sstevel@tonic-gate case SHT_SUNW_ANNOTATE:
27210e233487SRod Evans if (process_progbits(name, ifl, shdr, scn,
27220e233487SRod Evans ndx, ident, ofl) == S_ERROR)
27230e233487SRod Evans return (S_ERROR);
27240e233487SRod Evans break;
27257c478bd9Sstevel@tonic-gate case SHT_SUNW_COMDAT:
27267c478bd9Sstevel@tonic-gate if (process_progbits(name, ifl, shdr, scn,
27277c478bd9Sstevel@tonic-gate ndx, ident, ofl) == S_ERROR)
27287c478bd9Sstevel@tonic-gate return (S_ERROR);
27290e233487SRod Evans ifl->ifl_isdesc[ndx]->is_flags |= FLG_IS_COMDAT;
27307c478bd9Sstevel@tonic-gate break;
27317c478bd9Sstevel@tonic-gate case SHT_SUNW_verdef:
27327e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27337e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
27347c478bd9Sstevel@tonic-gate return (S_ERROR);
27357c478bd9Sstevel@tonic-gate vdfisp = ifl->ifl_isdesc[ndx];
27367c478bd9Sstevel@tonic-gate break;
27377c478bd9Sstevel@tonic-gate case SHT_SUNW_verneed:
27387e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27397e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
27407c478bd9Sstevel@tonic-gate return (S_ERROR);
27417c478bd9Sstevel@tonic-gate vndisp = ifl->ifl_isdesc[ndx];
27427c478bd9Sstevel@tonic-gate break;
27437c478bd9Sstevel@tonic-gate case SHT_SUNW_versym:
27447e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27457e16fca0SAli Bahrami ld_targ.t_id.id_null, ofl) == S_ERROR)
27467c478bd9Sstevel@tonic-gate return (S_ERROR);
27477c478bd9Sstevel@tonic-gate vsyisp = ifl->ifl_isdesc[ndx];
27487c478bd9Sstevel@tonic-gate break;
27497c478bd9Sstevel@tonic-gate case SHT_SPARC_GOTDATA:
2750ba2be530Sab196087 /*
2751ba2be530Sab196087 * SHT_SPARC_GOTDATA (0x70000000) is in the
2752ba2be530Sab196087 * SHT_LOPROC - SHT_HIPROC range reserved
2753ba2be530Sab196087 * for processor-specific semantics. It is
2754ba2be530Sab196087 * only meaningful for sparc targets.
2755ba2be530Sab196087 */
2756ba2be530Sab196087 if (ld_targ.t_m.m_mach !=
2757ba2be530Sab196087 LD_TARG_BYCLASS(EM_SPARC, EM_SPARCV9))
2758ba2be530Sab196087 goto do_default;
27597e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27607e16fca0SAli Bahrami ld_targ.t_id.id_gotdata, ofl) == S_ERROR)
27617c478bd9Sstevel@tonic-gate return (S_ERROR);
27627c478bd9Sstevel@tonic-gate break;
2763ba2be530Sab196087 #if defined(_ELF64)
27647c478bd9Sstevel@tonic-gate case SHT_AMD64_UNWIND:
2765ba2be530Sab196087 /*
2766ba2be530Sab196087 * SHT_AMD64_UNWIND (0x70000001) is in the
2767ba2be530Sab196087 * SHT_LOPROC - SHT_HIPROC range reserved
2768ba2be530Sab196087 * for processor-specific semantics. It is
2769ba2be530Sab196087 * only meaningful for amd64 targets.
2770ba2be530Sab196087 */
2771ba2be530Sab196087 if (ld_targ.t_m.m_mach != EM_AMD64)
2772ba2be530Sab196087 goto do_default;
27730e233487SRod Evans
2774ba2be530Sab196087 /*
2775ba2be530Sab196087 * Target is x86, so this really is
2776ba2be530Sab196087 * SHT_AMD64_UNWIND
2777ba2be530Sab196087 */
27787c478bd9Sstevel@tonic-gate if (column == 0) {
27797c478bd9Sstevel@tonic-gate /*
27807c478bd9Sstevel@tonic-gate * column == ET_REL
27817c478bd9Sstevel@tonic-gate */
27820e233487SRod Evans if (process_section(name, ifl, shdr,
27830e233487SRod Evans scn, ndx, ld_targ.t_id.id_unwind,
27840e233487SRod Evans ofl) == S_ERROR)
27857c478bd9Sstevel@tonic-gate return (S_ERROR);
27867e16fca0SAli Bahrami ifl->ifl_isdesc[ndx]->is_flags |=
27877e16fca0SAli Bahrami FLG_IS_EHFRAME;
27887c478bd9Sstevel@tonic-gate }
27897c478bd9Sstevel@tonic-gate break;
27907c478bd9Sstevel@tonic-gate #endif
27917c478bd9Sstevel@tonic-gate default:
2792ba2be530Sab196087 do_default:
27937e16fca0SAli Bahrami if (process_section(name, ifl, shdr, scn, ndx,
27947e16fca0SAli Bahrami ((ident == ld_targ.t_id.id_null) ?
27957e16fca0SAli Bahrami ident : ld_targ.t_id.id_user), ofl) ==
27967e16fca0SAli Bahrami S_ERROR)
27977c478bd9Sstevel@tonic-gate return (S_ERROR);
27987c478bd9Sstevel@tonic-gate break;
27997c478bd9Sstevel@tonic-gate }
28007c478bd9Sstevel@tonic-gate }
28017c478bd9Sstevel@tonic-gate }
28027c478bd9Sstevel@tonic-gate
28037c478bd9Sstevel@tonic-gate /*
28040e233487SRod Evans * Now that all input sections have been analyzed, and prior to placing
28050e233487SRod Evans * any input sections to their output sections, process any groups.
28060e233487SRod Evans * Groups can contribute COMDAT items, which may get discarded as part
28070e233487SRod Evans * of placement. In addition, COMDAT names may require transformation
28080e233487SRod Evans * to indicate different output section placement.
28097c478bd9Sstevel@tonic-gate */
2810a8c23f9dSRichard Lowe if (ifl->ifl_flags & FLG_IF_GROUPS) {
28110e233487SRod Evans for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) {
28127c478bd9Sstevel@tonic-gate Is_desc *isp;
28137c478bd9Sstevel@tonic-gate
28140e233487SRod Evans if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
28150e233487SRod Evans (isp->is_shdr->sh_type != SHT_GROUP))
28167c478bd9Sstevel@tonic-gate continue;
28177c478bd9Sstevel@tonic-gate
28180e233487SRod Evans if (ld_group_process(isp, ofl) == S_ERROR)
28197c478bd9Sstevel@tonic-gate return (S_ERROR);
28200e233487SRod Evans }
28210e233487SRod Evans }
28227c478bd9Sstevel@tonic-gate
28237c478bd9Sstevel@tonic-gate /*
2824*ef16f6b5SRichard Lowe * Now group information has been processed, we can safely validate
2825*ef16f6b5SRichard Lowe * that nothing is fishy about the section COMDAT description. We
2826*ef16f6b5SRichard Lowe * need to do this prior to placing the section (where any
2827*ef16f6b5SRichard Lowe * SHT_SUNW_COMDAT sections will be restored to being PROGBITS)
2828*ef16f6b5SRichard Lowe */
2829*ef16f6b5SRichard Lowe ld_comdat_validate(ofl, ifl);
2830*ef16f6b5SRichard Lowe
2831*ef16f6b5SRichard Lowe /*
28321dd9d86fSAli Bahrami * Now that all of the input sections have been processed, place
28331dd9d86fSAli Bahrami * them in the appropriate output sections.
28347c478bd9Sstevel@tonic-gate */
28350e233487SRod Evans for (ndx = 1; ndx < ifl->ifl_shnum; ndx++) {
28360e233487SRod Evans Is_desc *isp;
28370e233487SRod Evans
28380e233487SRod Evans if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
28390e233487SRod Evans ((isp->is_flags & FLG_IS_PLACE) == 0))
28400e233487SRod Evans continue;
28410e233487SRod Evans
28420e233487SRod Evans /*
28430e233487SRod Evans * Place all non-ordered sections within their appropriate
28440e233487SRod Evans * output section.
28450e233487SRod Evans */
28461dd9d86fSAli Bahrami if ((isp->is_flags & FLG_IS_ORDERED) == 0) {
284769112eddSAli Bahrami if (ld_place_section(ofl, isp, path_info,
28481dd9d86fSAli Bahrami isp->is_keyident, NULL) == (Os_desc *)S_ERROR)
28497c478bd9Sstevel@tonic-gate return (S_ERROR);
28501dd9d86fSAli Bahrami continue;
28510e233487SRod Evans }
28520e233487SRod Evans
28530e233487SRod Evans /*
28541dd9d86fSAli Bahrami * Count the number of ordered sections and retain the first
28551dd9d86fSAli Bahrami * ordered section index. This will be used to optimize the
28561dd9d86fSAli Bahrami * ordered section loop that immediately follows this one.
28570e233487SRod Evans */
28580e233487SRod Evans ordcnt++;
28590e233487SRod Evans if (ordndx == 0)
28600e233487SRod Evans ordndx = ndx;
28610e233487SRod Evans }
28620e233487SRod Evans
28630e233487SRod Evans /*
28641dd9d86fSAli Bahrami * Having placed all the non-ordered sections, it is now
28651dd9d86fSAli Bahrami * safe to place SHF_ORDERED/SHF_LINK_ORDER sections.
28660e233487SRod Evans */
28670e233487SRod Evans if (ifl->ifl_flags & FLG_IF_ORDERED) {
28681dd9d86fSAli Bahrami for (ndx = ordndx; ndx < ifl->ifl_shnum; ndx++) {
28690e233487SRod Evans Is_desc *isp;
28700e233487SRod Evans
28710e233487SRod Evans if (((isp = ifl->ifl_isdesc[ndx]) == NULL) ||
28721dd9d86fSAli Bahrami ((isp->is_flags &
28731dd9d86fSAli Bahrami (FLG_IS_PLACE | FLG_IS_ORDERED)) !=
28741dd9d86fSAli Bahrami (FLG_IS_PLACE | FLG_IS_ORDERED)))
28750e233487SRod Evans continue;
28760e233487SRod Evans
28771dd9d86fSAli Bahrami /* ld_process_ordered() calls ld_place_section() */
287869112eddSAli Bahrami if (ld_process_ordered(ofl, ifl, path_info, ndx) ==
287969112eddSAli Bahrami S_ERROR)
28800e233487SRod Evans return (S_ERROR);
28811dd9d86fSAli Bahrami
28821dd9d86fSAli Bahrami /* If we've done them all, stop searching */
28831dd9d86fSAli Bahrami if (--ordcnt == 0)
28841dd9d86fSAli Bahrami break;
28857c478bd9Sstevel@tonic-gate }
28867c478bd9Sstevel@tonic-gate }
28877c478bd9Sstevel@tonic-gate
28887c478bd9Sstevel@tonic-gate /*
28891dd9d86fSAli Bahrami * If this is a shared object explicitly specified on the command
28901dd9d86fSAli Bahrami * line (as opposed to being a dependency of such an object),
28911dd9d86fSAli Bahrami * determine if the user has specified a control definition. This
28921dd9d86fSAli Bahrami * descriptor may specify which version definitions can be used
28931dd9d86fSAli Bahrami * from this object. It may also update the dependency to USED and
28941dd9d86fSAli Bahrami * supply an alternative SONAME.
28957c478bd9Sstevel@tonic-gate */
2896635216b6SRod Evans sdf = NULL;
28977c478bd9Sstevel@tonic-gate if (column && (ifl->ifl_flags & FLG_IF_NEEDED)) {
28987c478bd9Sstevel@tonic-gate const char *base;
28997c478bd9Sstevel@tonic-gate
29007c478bd9Sstevel@tonic-gate /*
29017c478bd9Sstevel@tonic-gate * Use the basename of the input file (typically this is the
29027c478bd9Sstevel@tonic-gate * compilation environment name, ie. libfoo.so).
29037c478bd9Sstevel@tonic-gate */
29047c478bd9Sstevel@tonic-gate if ((base = strrchr(ifl->ifl_name, '/')) == NULL)
29057c478bd9Sstevel@tonic-gate base = ifl->ifl_name;
29067c478bd9Sstevel@tonic-gate else
29077c478bd9Sstevel@tonic-gate base++;
29087c478bd9Sstevel@tonic-gate
290957ef7aa9SRod Evans if ((sdf = sdf_find(base, ofl->ofl_socntl)) != NULL) {
29107c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
29117c478bd9Sstevel@tonic-gate ifl->ifl_sdfdesc = sdf;
29127c478bd9Sstevel@tonic-gate }
29137c478bd9Sstevel@tonic-gate }
29147c478bd9Sstevel@tonic-gate
29157c478bd9Sstevel@tonic-gate /*
291608278a5eSRod Evans * Before symbol processing, process any capabilities. Capabilities
291708278a5eSRod Evans * can reference a string table, which is why this processing is
291808278a5eSRod Evans * carried out after the initial section processing. Capabilities,
291908278a5eSRod Evans * together with -z symbolcap, can require the conversion of global
292008278a5eSRod Evans * symbols to local symbols.
29217c478bd9Sstevel@tonic-gate */
292208278a5eSRod Evans if (capisp && (process_cap(ofl, ifl, capisp) == S_ERROR))
292308278a5eSRod Evans return (S_ERROR);
29247c478bd9Sstevel@tonic-gate
29257c478bd9Sstevel@tonic-gate /*
29267c478bd9Sstevel@tonic-gate * Process any version dependencies. These will establish shared object
29277c478bd9Sstevel@tonic-gate * `needed' entries in the same manner as will be generated from the
29287c478bd9Sstevel@tonic-gate * .dynamic's NEEDED entries.
29297c478bd9Sstevel@tonic-gate */
29301007fd6fSAli Bahrami if (vndisp && ((ofl->ofl_flags & (FLG_OF_NOUNDEF | FLG_OF_SYMBOLIC)) ||
29311007fd6fSAli Bahrami OFL_GUIDANCE(ofl, FLG_OFG_NO_DEFS)))
29325aefb655Srie if (ld_vers_need_process(vndisp, ifl, ofl) == S_ERROR)
29337c478bd9Sstevel@tonic-gate return (S_ERROR);
29347c478bd9Sstevel@tonic-gate
29357c478bd9Sstevel@tonic-gate /*
29367c478bd9Sstevel@tonic-gate * Before processing any symbol resolution or relocations process any
29377c478bd9Sstevel@tonic-gate * version sections.
29387c478bd9Sstevel@tonic-gate */
29397c478bd9Sstevel@tonic-gate if (vsyisp)
29401007fd6fSAli Bahrami (void) ld_vers_sym_process(ofl, vsyisp, ifl);
29417c478bd9Sstevel@tonic-gate
29427c478bd9Sstevel@tonic-gate if (ifl->ifl_versym &&
29437c478bd9Sstevel@tonic-gate (vdfisp || (sdf && (sdf->sdf_flags & FLG_SDF_SELECT))))
29445aefb655Srie if (ld_vers_def_process(vdfisp, ifl, ofl) == S_ERROR)
29457c478bd9Sstevel@tonic-gate return (S_ERROR);
29467c478bd9Sstevel@tonic-gate
29477c478bd9Sstevel@tonic-gate /*
29487c478bd9Sstevel@tonic-gate * Having collected the appropriate sections carry out any additional
29497c478bd9Sstevel@tonic-gate * processing if necessary.
29507c478bd9Sstevel@tonic-gate */
29517c478bd9Sstevel@tonic-gate for (ndx = 0; ndx < ifl->ifl_shnum; ndx++) {
29527c478bd9Sstevel@tonic-gate Is_desc *isp;
29537c478bd9Sstevel@tonic-gate
2954635216b6SRod Evans if ((isp = ifl->ifl_isdesc[ndx]) == NULL)
29557c478bd9Sstevel@tonic-gate continue;
29567c478bd9Sstevel@tonic-gate row = isp->is_shdr->sh_type;
29577c478bd9Sstevel@tonic-gate
29587c478bd9Sstevel@tonic-gate if ((isp->is_flags & FLG_IS_DISCARD) == 0)
29595aefb655Srie ld_sup_section(ofl, isp->is_name, isp->is_shdr, ndx,
29607c478bd9Sstevel@tonic-gate isp->is_indata, elf);
29617c478bd9Sstevel@tonic-gate
29627c478bd9Sstevel@tonic-gate /*
296357ef7aa9SRod Evans * If this is a SHT_SUNW_move section from a relocatable file,
296457ef7aa9SRod Evans * keep track of the section for later processing.
29657c478bd9Sstevel@tonic-gate */
29667c478bd9Sstevel@tonic-gate if ((row == SHT_SUNW_move) && (column == 0)) {
296757ef7aa9SRod Evans if (aplist_append(&(ofl->ofl_ismove), isp,
296857ef7aa9SRod Evans AL_CNT_OFL_MOVE) == NULL)
29697c478bd9Sstevel@tonic-gate return (S_ERROR);
29707c478bd9Sstevel@tonic-gate }
29717c478bd9Sstevel@tonic-gate
29727c478bd9Sstevel@tonic-gate /*
29737c478bd9Sstevel@tonic-gate * If this is a standard section type process it via the
29747c478bd9Sstevel@tonic-gate * appropriate action routine.
29757c478bd9Sstevel@tonic-gate */
29767c478bd9Sstevel@tonic-gate if (row < SHT_NUM) {
29770e233487SRod Evans if (Final[row][column] != NULL) {
29780e233487SRod Evans if (Final[row][column](isp, ifl,
29790e233487SRod Evans ofl) == S_ERROR)
29807c478bd9Sstevel@tonic-gate return (S_ERROR);
29817c478bd9Sstevel@tonic-gate }
29820e233487SRod Evans #if defined(_ELF64)
29830e233487SRod Evans } else if ((row == SHT_AMD64_UNWIND) && (column == 0)) {
29840e233487SRod Evans Os_desc *osp = isp->is_osdesc;
29850e233487SRod Evans
29860e233487SRod Evans /*
29870e233487SRod Evans * SHT_AMD64_UNWIND (0x70000001) is in the SHT_LOPROC -
29880e233487SRod Evans * SHT_HIPROC range reserved for processor-specific
29890e233487SRod Evans * semantics, and is only meaningful for amd64 targets.
29900e233487SRod Evans *
29910e233487SRod Evans * Only process unwind contents from relocatable
29920e233487SRod Evans * objects.
29930e233487SRod Evans */
29940e233487SRod Evans if (osp && (ld_targ.t_m.m_mach == EM_AMD64) &&
29957e16fca0SAli Bahrami (ld_unwind_register(osp, ofl) == S_ERROR))
29960e233487SRod Evans return (S_ERROR);
29970e233487SRod Evans #endif
29980e233487SRod Evans }
29997c478bd9Sstevel@tonic-gate }
30007c478bd9Sstevel@tonic-gate
30017c478bd9Sstevel@tonic-gate /*
300208278a5eSRod Evans * Following symbol processing, if this relocatable object input file
300308278a5eSRod Evans * provides symbol capabilities, tag the associated symbols so that
300408278a5eSRod Evans * the symbols can be re-assigned to the new capabilities symbol
300508278a5eSRod Evans * section that will be created for the output file.
300608278a5eSRod Evans */
300708278a5eSRod Evans if (capinfoisp && (ifl->ifl_ehdr->e_type == ET_REL) &&
300808278a5eSRod Evans (process_capinfo(ofl, ifl, capinfoisp) == S_ERROR))
300908278a5eSRod Evans return (S_ERROR);
301008278a5eSRod Evans
301108278a5eSRod Evans /*
30127c478bd9Sstevel@tonic-gate * After processing any symbol resolution, and if this dependency
30137c478bd9Sstevel@tonic-gate * indicates it contains symbols that can't be directly bound to,
30147c478bd9Sstevel@tonic-gate * set the symbols appropriately.
30157c478bd9Sstevel@tonic-gate */
30167c478bd9Sstevel@tonic-gate if (sifisp && ((ifl->ifl_flags & (FLG_IF_NEEDED | FLG_IF_NODIRECT)) ==
30177c478bd9Sstevel@tonic-gate (FLG_IF_NEEDED | FLG_IF_NODIRECT)))
30185aefb655Srie (void) ld_sym_nodirect(sifisp, ifl, ofl);
30197c478bd9Sstevel@tonic-gate
30207c478bd9Sstevel@tonic-gate return (1);
30217c478bd9Sstevel@tonic-gate }
30227c478bd9Sstevel@tonic-gate
30237c478bd9Sstevel@tonic-gate /*
30247c478bd9Sstevel@tonic-gate * Process the current input file. There are basically three types of files
30257c478bd9Sstevel@tonic-gate * that come through here:
30267c478bd9Sstevel@tonic-gate *
3027635216b6SRod Evans * - files explicitly defined on the command line (ie. foo.o or bar.so),
30287c478bd9Sstevel@tonic-gate * in this case only the `name' field is valid.
30297c478bd9Sstevel@tonic-gate *
3030635216b6SRod Evans * - libraries determined from the -l command line option (ie. -lbar),
30317c478bd9Sstevel@tonic-gate * in this case the `soname' field contains the basename of the located
30327c478bd9Sstevel@tonic-gate * file.
30337c478bd9Sstevel@tonic-gate *
30347c478bd9Sstevel@tonic-gate * Any shared object specified via the above two conventions must be recorded
30357c478bd9Sstevel@tonic-gate * as a needed dependency.
30367c478bd9Sstevel@tonic-gate *
3037635216b6SRod Evans * - libraries specified as dependencies of those libraries already obtained
30387c478bd9Sstevel@tonic-gate * via the command line (ie. bar.so has a DT_NEEDED entry of fred.so.1),
30397c478bd9Sstevel@tonic-gate * in this case the `soname' field contains either a full pathname (if the
30407c478bd9Sstevel@tonic-gate * needed entry contained a `/'), or the basename of the located file.
30417c478bd9Sstevel@tonic-gate * These libraries are processed to verify symbol binding but are not
30427c478bd9Sstevel@tonic-gate * recorded as dependencies of the output file being generated.
3043dc0f59e5SAli Bahrami *
3044dc0f59e5SAli Bahrami * entry:
3045dc0f59e5SAli Bahrami * name - File name
3046dc0f59e5SAli Bahrami * soname - SONAME for needed sharable library, as described above
3047dc0f59e5SAli Bahrami * fd - Open file descriptor
3048dc0f59e5SAli Bahrami * elf - Open ELF handle
3049dc0f59e5SAli Bahrami * flags - FLG_IF_ flags applicable to file
3050dc0f59e5SAli Bahrami * ofl - Output file descriptor
3051dc0f59e5SAli Bahrami * rej - Rejection descriptor used to record rejection reason
3052dc0f59e5SAli Bahrami * ifl_ret - NULL, or address of pointer to receive reference to
3053dc0f59e5SAli Bahrami * resulting input descriptor for file. If ifl_ret is non-NULL,
3054dc0f59e5SAli Bahrami * the file cannot be an archive or it will be rejected.
3055dc0f59e5SAli Bahrami *
3056dc0f59e5SAli Bahrami * exit:
3057dc0f59e5SAli Bahrami * If a error occurs in examining the file, S_ERROR is returned.
3058dc0f59e5SAli Bahrami * If the file can be examined, but is not suitable, *rej is updated,
3059dc0f59e5SAli Bahrami * and 0 is returned. If the file is acceptable, 1 is returned, and if
3060dc0f59e5SAli Bahrami * ifl_ret is non-NULL, *ifl_ret is set to contain the pointer to the
3061dc0f59e5SAli Bahrami * resulting input descriptor.
30627c478bd9Sstevel@tonic-gate */
3063dc0f59e5SAli 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)30645aefb655Srie ld_process_ifl(const char *name, const char *soname, int fd, Elf *elf,
3065dc0f59e5SAli Bahrami Word flags, Ofl_desc *ofl, Rej_desc *rej, Ifl_desc **ifl_ret)
30667c478bd9Sstevel@tonic-gate {
30677c478bd9Sstevel@tonic-gate Ifl_desc *ifl;
30687c478bd9Sstevel@tonic-gate Ehdr *ehdr;
30697c478bd9Sstevel@tonic-gate uintptr_t error = 0;
30707c478bd9Sstevel@tonic-gate struct stat status;
30717c478bd9Sstevel@tonic-gate Ar_desc *adp;
30727c478bd9Sstevel@tonic-gate Rej_desc _rej;
30737c478bd9Sstevel@tonic-gate
30747c478bd9Sstevel@tonic-gate /*
30757c478bd9Sstevel@tonic-gate * If this file was not extracted from an archive obtain its device
30767c478bd9Sstevel@tonic-gate * information. This will be used to determine if the file has already
30777c478bd9Sstevel@tonic-gate * been processed (rather than simply comparing filenames, the device
30787c478bd9Sstevel@tonic-gate * information provides a quicker comparison and detects linked files).
30797c478bd9Sstevel@tonic-gate */
308056deab07SRod Evans if (fd && ((flags & FLG_IF_EXTRACT) == 0))
30817c478bd9Sstevel@tonic-gate (void) fstat(fd, &status);
30827c478bd9Sstevel@tonic-gate else {
30837c478bd9Sstevel@tonic-gate status.st_dev = 0;
30847c478bd9Sstevel@tonic-gate status.st_ino = 0;
30857c478bd9Sstevel@tonic-gate }
30867c478bd9Sstevel@tonic-gate
30877c478bd9Sstevel@tonic-gate switch (elf_kind(elf)) {
30887c478bd9Sstevel@tonic-gate case ELF_K_AR:
30897c478bd9Sstevel@tonic-gate /*
3090dc0f59e5SAli Bahrami * If the caller has supplied a non-NULL ifl_ret, then
3091dc0f59e5SAli Bahrami * we cannot process archives, for there will be no
3092dc0f59e5SAli Bahrami * input file descriptor for us to return. In this case,
3093dc0f59e5SAli Bahrami * reject the attempt.
3094dc0f59e5SAli Bahrami */
3095dc0f59e5SAli Bahrami if (ifl_ret != NULL) {
3096dc0f59e5SAli Bahrami _rej.rej_type = SGS_REJ_ARCHIVE;
3097dc0f59e5SAli Bahrami _rej.rej_name = name;
3098dc0f59e5SAli Bahrami DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3099dc0f59e5SAli Bahrami ld_targ.t_m.m_mach));
3100dc0f59e5SAli Bahrami if (rej->rej_type == 0) {
3101dc0f59e5SAli Bahrami *rej = _rej;
3102dc0f59e5SAli Bahrami rej->rej_name = strdup(_rej.rej_name);
3103dc0f59e5SAli Bahrami }
3104dc0f59e5SAli Bahrami return (0);
3105dc0f59e5SAli Bahrami }
3106dc0f59e5SAli Bahrami
3107dc0f59e5SAli Bahrami /*
31087c478bd9Sstevel@tonic-gate * Determine if we've already come across this archive file.
31097c478bd9Sstevel@tonic-gate */
31107c478bd9Sstevel@tonic-gate if (!(flags & FLG_IF_EXTRACT)) {
311157ef7aa9SRod Evans Aliste idx;
311257ef7aa9SRod Evans
311357ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_ars, idx, adp)) {
31147c478bd9Sstevel@tonic-gate if ((adp->ad_stdev != status.st_dev) ||
31157c478bd9Sstevel@tonic-gate (adp->ad_stino != status.st_ino))
31167c478bd9Sstevel@tonic-gate continue;
31177c478bd9Sstevel@tonic-gate
31187c478bd9Sstevel@tonic-gate /*
31197c478bd9Sstevel@tonic-gate * We've seen this file before so reuse the
31207c478bd9Sstevel@tonic-gate * original archive descriptor and discard the
3121a6d4d7d5SRod Evans * new elf descriptor. Note that a file
3122a6d4d7d5SRod Evans * descriptor is unnecessary, as the file is
3123a6d4d7d5SRod Evans * already available in memory.
31247c478bd9Sstevel@tonic-gate */
31255aefb655Srie DBG_CALL(Dbg_file_reuse(ofl->ofl_lml, name,
31265aefb655Srie adp->ad_name));
31277c478bd9Sstevel@tonic-gate (void) elf_end(elf);
3128dc0f59e5SAli Bahrami if (!ld_process_archive(name, -1, adp, ofl))
3129dc0f59e5SAli Bahrami return (S_ERROR);
3130dc0f59e5SAli Bahrami return (1);
31317c478bd9Sstevel@tonic-gate }
31327c478bd9Sstevel@tonic-gate }
31337c478bd9Sstevel@tonic-gate
31347c478bd9Sstevel@tonic-gate /*
31357c478bd9Sstevel@tonic-gate * As we haven't processed this file before establish a new
31367c478bd9Sstevel@tonic-gate * archive descriptor.
31377c478bd9Sstevel@tonic-gate */
31385aefb655Srie adp = ld_ar_setup(name, elf, ofl);
3139635216b6SRod Evans if ((adp == NULL) || (adp == (Ar_desc *)S_ERROR))
3140dc0f59e5SAli Bahrami return ((uintptr_t)adp);
31417c478bd9Sstevel@tonic-gate adp->ad_stdev = status.st_dev;
31427c478bd9Sstevel@tonic-gate adp->ad_stino = status.st_ino;
31437c478bd9Sstevel@tonic-gate
31445aefb655Srie ld_sup_file(ofl, name, ELF_K_AR, flags, elf);
31457c478bd9Sstevel@tonic-gate
3146a6d4d7d5SRod Evans /*
3147a6d4d7d5SRod Evans * Indicate that the ELF descriptor no longer requires a file
3148a6d4d7d5SRod Evans * descriptor by reading the entire file. The file is already
3149a6d4d7d5SRod Evans * read via the initial mmap(2) behind elf_begin(3elf), thus
3150a6d4d7d5SRod Evans * this operation is effectively a no-op. However, a side-
3151a6d4d7d5SRod Evans * effect is that the internal file descriptor, maintained in
3152a6d4d7d5SRod Evans * the ELF descriptor, is set to -1. This setting will not
3153a6d4d7d5SRod Evans * be compared with any file descriptor that is passed to
3154a6d4d7d5SRod Evans * elf_begin(), should this archive, or one of the archive
3155a6d4d7d5SRod Evans * members, be processed again from the command line or
3156a6d4d7d5SRod Evans * because of a -z rescan.
3157a6d4d7d5SRod Evans */
3158a6d4d7d5SRod Evans if (elf_cntl(elf, ELF_C_FDREAD) == -1) {
31591007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_CNTL),
3160a6d4d7d5SRod Evans name);
3161dc0f59e5SAli Bahrami return (0);
3162a6d4d7d5SRod Evans }
3163a6d4d7d5SRod Evans
3164dc0f59e5SAli Bahrami if (!ld_process_archive(name, -1, adp, ofl))
3165dc0f59e5SAli Bahrami return (S_ERROR);
3166dc0f59e5SAli Bahrami return (1);
31677c478bd9Sstevel@tonic-gate
31687c478bd9Sstevel@tonic-gate case ELF_K_ELF:
31697c478bd9Sstevel@tonic-gate /*
31707c478bd9Sstevel@tonic-gate * Obtain the elf header so that we can determine what type of
31717c478bd9Sstevel@tonic-gate * elf ELF_K_ELF file this is.
31727c478bd9Sstevel@tonic-gate */
31737c478bd9Sstevel@tonic-gate if ((ehdr = elf_getehdr(elf)) == NULL) {
31747c478bd9Sstevel@tonic-gate int _class = gelf_getclass(elf);
31757c478bd9Sstevel@tonic-gate
31767c478bd9Sstevel@tonic-gate /*
3177dc0f59e5SAli Bahrami * This can fail for a number of reasons. Typically
3178dc0f59e5SAli Bahrami * the object class is incorrect (ie. user is building
3179dc0f59e5SAli Bahrami * 64-bit but managed to point at 32-bit libraries).
3180dc0f59e5SAli Bahrami * Other ELF errors can include a truncated or corrupt
3181dc0f59e5SAli Bahrami * file. Try to get the best error message possible.
31827c478bd9Sstevel@tonic-gate */
3183ba2be530Sab196087 if (ld_targ.t_m.m_class != _class) {
31847c478bd9Sstevel@tonic-gate _rej.rej_type = SGS_REJ_CLASS;
31857c478bd9Sstevel@tonic-gate _rej.rej_info = (uint_t)_class;
31867c478bd9Sstevel@tonic-gate } else {
31877c478bd9Sstevel@tonic-gate _rej.rej_type = SGS_REJ_STR;
31887c478bd9Sstevel@tonic-gate _rej.rej_str = elf_errmsg(-1);
31897c478bd9Sstevel@tonic-gate }
31907c478bd9Sstevel@tonic-gate _rej.rej_name = name;
3191ba2be530Sab196087 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3192ba2be530Sab196087 ld_targ.t_m.m_mach));
31937c478bd9Sstevel@tonic-gate if (rej->rej_type == 0) {
31947c478bd9Sstevel@tonic-gate *rej = _rej;
31957c478bd9Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name);
31967c478bd9Sstevel@tonic-gate }
3197dc0f59e5SAli Bahrami return (0);
31987c478bd9Sstevel@tonic-gate }
31997c478bd9Sstevel@tonic-gate
32007c478bd9Sstevel@tonic-gate /*
32017c478bd9Sstevel@tonic-gate * Determine if we've already come across this file.
32027c478bd9Sstevel@tonic-gate */
32037c478bd9Sstevel@tonic-gate if (!(flags & FLG_IF_EXTRACT)) {
320457ef7aa9SRod Evans APlist *apl;
320557ef7aa9SRod Evans Aliste idx;
32067c478bd9Sstevel@tonic-gate
32077c478bd9Sstevel@tonic-gate if (ehdr->e_type == ET_REL)
320857ef7aa9SRod Evans apl = ofl->ofl_objs;
32097c478bd9Sstevel@tonic-gate else
321057ef7aa9SRod Evans apl = ofl->ofl_sos;
32117c478bd9Sstevel@tonic-gate
32127c478bd9Sstevel@tonic-gate /*
32137c478bd9Sstevel@tonic-gate * Traverse the appropriate file list and determine if
32147c478bd9Sstevel@tonic-gate * a dev/inode match is found.
32157c478bd9Sstevel@tonic-gate */
321657ef7aa9SRod Evans for (APLIST_TRAVERSE(apl, idx, ifl)) {
32177c478bd9Sstevel@tonic-gate /*
32187c478bd9Sstevel@tonic-gate * Ifl_desc generated via -Nneed, therefore no
32197c478bd9Sstevel@tonic-gate * actual file behind it.
32207c478bd9Sstevel@tonic-gate */
32217c478bd9Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_NEEDSTR)
32227c478bd9Sstevel@tonic-gate continue;
32237c478bd9Sstevel@tonic-gate
32247c478bd9Sstevel@tonic-gate if ((ifl->ifl_stino != status.st_ino) ||
32257c478bd9Sstevel@tonic-gate (ifl->ifl_stdev != status.st_dev))
32267c478bd9Sstevel@tonic-gate continue;
32277c478bd9Sstevel@tonic-gate
32287c478bd9Sstevel@tonic-gate /*
32297c478bd9Sstevel@tonic-gate * Disregard (skip) this image.
32307c478bd9Sstevel@tonic-gate */
32315aefb655Srie DBG_CALL(Dbg_file_skip(ofl->ofl_lml,
32325aefb655Srie ifl->ifl_name, name));
32337c478bd9Sstevel@tonic-gate (void) elf_end(elf);
32347c478bd9Sstevel@tonic-gate
32357c478bd9Sstevel@tonic-gate /*
32367c478bd9Sstevel@tonic-gate * If the file was explicitly defined on the
32377c478bd9Sstevel@tonic-gate * command line (this is always the case for
32387c478bd9Sstevel@tonic-gate * relocatable objects, and is true for shared
32397c478bd9Sstevel@tonic-gate * objects when they weren't specified via -l or
32407c478bd9Sstevel@tonic-gate * were dragged in as an implicit dependency),
32417c478bd9Sstevel@tonic-gate * then warn the user.
32427c478bd9Sstevel@tonic-gate */
32437c478bd9Sstevel@tonic-gate if ((flags & FLG_IF_CMDLINE) ||
32447c478bd9Sstevel@tonic-gate (ifl->ifl_flags & FLG_IF_CMDLINE)) {
32457c478bd9Sstevel@tonic-gate const char *errmsg;
32467c478bd9Sstevel@tonic-gate
32477c478bd9Sstevel@tonic-gate /*
32487c478bd9Sstevel@tonic-gate * Determine whether this is the same
32497c478bd9Sstevel@tonic-gate * file name as originally encountered
32507c478bd9Sstevel@tonic-gate * so as to provide the most
32517c478bd9Sstevel@tonic-gate * descriptive diagnostic.
32527c478bd9Sstevel@tonic-gate */
3253d840867fSab196087 errmsg =
3254de777a60Sab196087 (strcmp(name, ifl->ifl_name) == 0) ?
3255de777a60Sab196087 MSG_INTL(MSG_FIL_MULINC_1) :
3256d840867fSab196087 MSG_INTL(MSG_FIL_MULINC_2);
32571007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
32585aefb655Srie errmsg, name, ifl->ifl_name);
32597c478bd9Sstevel@tonic-gate }
3260dc0f59e5SAli Bahrami if (ifl_ret)
3261dc0f59e5SAli Bahrami *ifl_ret = ifl;
3262dc0f59e5SAli Bahrami return (1);
32637c478bd9Sstevel@tonic-gate }
32647c478bd9Sstevel@tonic-gate }
32657c478bd9Sstevel@tonic-gate
32667c478bd9Sstevel@tonic-gate /*
32677c478bd9Sstevel@tonic-gate * At this point, we know we need the file. Establish an input
32687c478bd9Sstevel@tonic-gate * file descriptor and continue processing.
32697c478bd9Sstevel@tonic-gate */
32707c478bd9Sstevel@tonic-gate ifl = ifl_setup(name, ehdr, elf, flags, ofl, rej);
3271635216b6SRod Evans if ((ifl == NULL) || (ifl == (Ifl_desc *)S_ERROR))
3272dc0f59e5SAli Bahrami return ((uintptr_t)ifl);
32737c478bd9Sstevel@tonic-gate ifl->ifl_stdev = status.st_dev;
32747c478bd9Sstevel@tonic-gate ifl->ifl_stino = status.st_ino;
32757c478bd9Sstevel@tonic-gate
32767c478bd9Sstevel@tonic-gate /*
32777c478bd9Sstevel@tonic-gate * If -zignore is in effect, mark this file as a potential
32787c478bd9Sstevel@tonic-gate * candidate (the files use isn't actually determined until
32797c478bd9Sstevel@tonic-gate * symbol resolution and relocation processing are completed).
32807c478bd9Sstevel@tonic-gate */
32817c478bd9Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_IGNORE)
32827c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_IGNORE;
32837c478bd9Sstevel@tonic-gate
32847c478bd9Sstevel@tonic-gate switch (ehdr->e_type) {
32857c478bd9Sstevel@tonic-gate case ET_REL:
3286ba2be530Sab196087 (*ld_targ.t_mr.mr_mach_eflags)(ehdr, ofl);
32877c478bd9Sstevel@tonic-gate error = process_elf(ifl, elf, ofl);
32887c478bd9Sstevel@tonic-gate break;
32897c478bd9Sstevel@tonic-gate case ET_DYN:
32907c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_STATIC) ||
32917c478bd9Sstevel@tonic-gate !(ofl->ofl_flags & FLG_OF_DYNLIBS)) {
32921007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL,
32935aefb655Srie MSG_INTL(MSG_FIL_SOINSTAT), name);
3294dc0f59e5SAli Bahrami return (0);
32957c478bd9Sstevel@tonic-gate }
32967c478bd9Sstevel@tonic-gate
32977c478bd9Sstevel@tonic-gate /*
32987c478bd9Sstevel@tonic-gate * Record any additional shared object information.
32997c478bd9Sstevel@tonic-gate * If no soname is specified (eg. this file was
33007c478bd9Sstevel@tonic-gate * derived from a explicit filename declaration on the
33017c478bd9Sstevel@tonic-gate * command line, ie. bar.so) use the pathname.
33027c478bd9Sstevel@tonic-gate * This entry may be overridden if the files dynamic
33037c478bd9Sstevel@tonic-gate * section specifies an DT_SONAME value.
33047c478bd9Sstevel@tonic-gate */
33057c478bd9Sstevel@tonic-gate if (soname == NULL)
33067c478bd9Sstevel@tonic-gate ifl->ifl_soname = ifl->ifl_name;
33077c478bd9Sstevel@tonic-gate else
33087c478bd9Sstevel@tonic-gate ifl->ifl_soname = soname;
33097c478bd9Sstevel@tonic-gate
33107c478bd9Sstevel@tonic-gate /*
3311f441771bSRod Evans * If direct bindings, lazy loading, group permissions,
3312f441771bSRod Evans * or deferred dependencies need to be established, mark
3313f441771bSRod Evans * this object.
33147c478bd9Sstevel@tonic-gate */
33157c478bd9Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_ZDIRECT)
33167c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_DIRECT;
33177c478bd9Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_LAZYLD)
33187c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_LAZYLD;
33197c478bd9Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_GRPPRM)
33207c478bd9Sstevel@tonic-gate ifl->ifl_flags |= FLG_IF_GRPPRM;
3321f441771bSRod Evans if (ofl->ofl_flags1 & FLG_OF1_DEFERRED)
3322f441771bSRod Evans ifl->ifl_flags |=
3323f441771bSRod Evans (FLG_IF_LAZYLD | FLG_IF_DEFERRED);
3324f441771bSRod Evans
33257c478bd9Sstevel@tonic-gate error = process_elf(ifl, elf, ofl);
33267c478bd9Sstevel@tonic-gate
33277c478bd9Sstevel@tonic-gate /*
3328f441771bSRod Evans * Determine whether this dependency requires a syminfo.
33297c478bd9Sstevel@tonic-gate */
3330f441771bSRod Evans if (ifl->ifl_flags & MSK_IF_SYMINFO)
33317c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_SYMINFO;
33327c478bd9Sstevel@tonic-gate
33331007fd6fSAli Bahrami /*
33341007fd6fSAli Bahrami * Guidance: Use -z lazyload/nolazyload.
33351007fd6fSAli Bahrami * libc is exempt from this advice, because it cannot
33361007fd6fSAli Bahrami * be lazy loaded, and requests to do so are ignored.
33371007fd6fSAli Bahrami */
33381007fd6fSAli Bahrami if (OFL_GUIDANCE(ofl, FLG_OFG_NO_LAZY) &&
33391007fd6fSAli Bahrami ((ifl->ifl_flags & FLG_IF_RTLDINF) == 0)) {
33401007fd6fSAli Bahrami ld_eprintf(ofl, ERR_GUIDANCE,
33411007fd6fSAli Bahrami MSG_INTL(MSG_GUIDE_LAZYLOAD));
33421007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_LAZY;
33431007fd6fSAli Bahrami }
33441007fd6fSAli Bahrami
33451007fd6fSAli Bahrami /*
33461007fd6fSAli Bahrami * Guidance: Use -B direct/nodirect or
33471007fd6fSAli Bahrami * -z direct/nodirect.
33481007fd6fSAli Bahrami */
33491007fd6fSAli Bahrami if (OFL_GUIDANCE(ofl, FLG_OFG_NO_DB)) {
33501007fd6fSAli Bahrami ld_eprintf(ofl, ERR_GUIDANCE,
33511007fd6fSAli Bahrami MSG_INTL(MSG_GUIDE_DIRECT));
33521007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_DB;
33531007fd6fSAli Bahrami }
33541007fd6fSAli Bahrami
33557c478bd9Sstevel@tonic-gate break;
33567c478bd9Sstevel@tonic-gate default:
33577c478bd9Sstevel@tonic-gate (void) elf_errno();
33587c478bd9Sstevel@tonic-gate _rej.rej_type = SGS_REJ_UNKFILE;
33597c478bd9Sstevel@tonic-gate _rej.rej_name = name;
3360ba2be530Sab196087 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3361ba2be530Sab196087 ld_targ.t_m.m_mach));
33627c478bd9Sstevel@tonic-gate if (rej->rej_type == 0) {
33637c478bd9Sstevel@tonic-gate *rej = _rej;
33647c478bd9Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name);
33657c478bd9Sstevel@tonic-gate }
3366dc0f59e5SAli Bahrami return (0);
33677c478bd9Sstevel@tonic-gate }
33687c478bd9Sstevel@tonic-gate break;
33697c478bd9Sstevel@tonic-gate default:
33707c478bd9Sstevel@tonic-gate (void) elf_errno();
33717c478bd9Sstevel@tonic-gate _rej.rej_type = SGS_REJ_UNKFILE;
33727c478bd9Sstevel@tonic-gate _rej.rej_name = name;
3373ba2be530Sab196087 DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
3374ba2be530Sab196087 ld_targ.t_m.m_mach));
33757c478bd9Sstevel@tonic-gate if (rej->rej_type == 0) {
33767c478bd9Sstevel@tonic-gate *rej = _rej;
33777c478bd9Sstevel@tonic-gate rej->rej_name = strdup(_rej.rej_name);
33787c478bd9Sstevel@tonic-gate }
3379dc0f59e5SAli Bahrami return (0);
33807c478bd9Sstevel@tonic-gate }
33817c478bd9Sstevel@tonic-gate if ((error == 0) || (error == S_ERROR))
3382dc0f59e5SAli Bahrami return (error);
3383dc0f59e5SAli Bahrami
3384dc0f59e5SAli Bahrami if (ifl_ret)
3385dc0f59e5SAli Bahrami *ifl_ret = ifl;
3386dc0f59e5SAli Bahrami return (1);
33877c478bd9Sstevel@tonic-gate }
33887c478bd9Sstevel@tonic-gate
33897c478bd9Sstevel@tonic-gate /*
33907c478bd9Sstevel@tonic-gate * Having successfully opened a file, set up the necessary elf structures to
33917c478bd9Sstevel@tonic-gate * process it further. This small section of processing is slightly different
33927c478bd9Sstevel@tonic-gate * from the elf initialization required to process a relocatable object from an
33932926dd2eSrie * archive (see libs.c: ld_process_archive()).
33947c478bd9Sstevel@tonic-gate */
3395dc0f59e5SAli 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)33963906e0c2Srie ld_process_open(const char *opath, const char *ofile, int *fd, Ofl_desc *ofl,
3397dc0f59e5SAli Bahrami Word flags, Rej_desc *rej, Ifl_desc **ifl_ret)
33987c478bd9Sstevel@tonic-gate {
33997c478bd9Sstevel@tonic-gate Elf *elf;
34003906e0c2Srie const char *npath = opath;
34013906e0c2Srie const char *nfile = ofile;
34027c478bd9Sstevel@tonic-gate
34033906e0c2Srie if ((elf = elf_begin(*fd, ELF_C_READ, NULL)) == NULL) {
34041007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_BEGIN), npath);
3405dc0f59e5SAli Bahrami return (0);
34067c478bd9Sstevel@tonic-gate }
34077c478bd9Sstevel@tonic-gate
34083906e0c2Srie /*
34093906e0c2Srie * Determine whether the support library wishes to process this open.
34103906e0c2Srie * The support library may return:
34113906e0c2Srie * . a different ELF descriptor (in which case they should have
34123906e0c2Srie * closed the original)
34133906e0c2Srie * . a different file descriptor (in which case they should have
34143906e0c2Srie * closed the original)
34153906e0c2Srie * . a different path and file name (presumably associated with
34163906e0c2Srie * a different file descriptor)
34173906e0c2Srie *
34183906e0c2Srie * A file descriptor of -1, or and ELF descriptor of zero indicates
34193906e0c2Srie * the file should be ignored.
34203906e0c2Srie */
34213906e0c2Srie ld_sup_open(ofl, &npath, &nfile, fd, flags, &elf, NULL, 0,
34223906e0c2Srie elf_kind(elf));
34233906e0c2Srie
34243906e0c2Srie if ((*fd == -1) || (elf == NULL))
3425dc0f59e5SAli Bahrami return (0);
34263906e0c2Srie
3427dc0f59e5SAli Bahrami return (ld_process_ifl(npath, nfile, *fd, elf, flags, ofl, rej,
3428dc0f59e5SAli Bahrami ifl_ret));
34297c478bd9Sstevel@tonic-gate }
34307c478bd9Sstevel@tonic-gate
34317c478bd9Sstevel@tonic-gate /*
343256deab07SRod Evans * Having successfully mapped a file, set up the necessary elf structures to
343356deab07SRod Evans * process it further. This routine is patterned after ld_process_open() and
343456deab07SRod Evans * is only called by ld.so.1(1) to process a relocatable object.
343556deab07SRod Evans */
343656deab07SRod Evans Ifl_desc *
ld_process_mem(const char * path,const char * file,char * addr,size_t size,Ofl_desc * ofl,Rej_desc * rej)343756deab07SRod Evans ld_process_mem(const char *path, const char *file, char *addr, size_t size,
343856deab07SRod Evans Ofl_desc *ofl, Rej_desc *rej)
343956deab07SRod Evans {
344056deab07SRod Evans Elf *elf;
3441dc0f59e5SAli Bahrami uintptr_t open_ret;
3442dc0f59e5SAli Bahrami Ifl_desc *ifl;
344356deab07SRod Evans
344456deab07SRod Evans if ((elf = elf_memory(addr, size)) == NULL) {
34451007fd6fSAli Bahrami ld_eprintf(ofl, ERR_ELF, MSG_INTL(MSG_ELF_MEMORY), path);
344656deab07SRod Evans return (0);
344756deab07SRod Evans }
344856deab07SRod Evans
3449dc0f59e5SAli Bahrami open_ret = ld_process_ifl(path, file, 0, elf, 0, ofl, rej, &ifl);
3450dc0f59e5SAli Bahrami if (open_ret != 1)
3451dc0f59e5SAli Bahrami return ((Ifl_desc *) open_ret);
3452dc0f59e5SAli Bahrami return (ifl);
345356deab07SRod Evans }
345456deab07SRod Evans
345556deab07SRod Evans /*
34567c478bd9Sstevel@tonic-gate * Process a required library (i.e. the dependency of a shared object).
34577c478bd9Sstevel@tonic-gate * Combine the directory and filename, check the resultant path size, and try
34587c478bd9Sstevel@tonic-gate * opening the pathname.
34597c478bd9Sstevel@tonic-gate */
34605aefb655Srie static Ifl_desc *
process_req_lib(Sdf_desc * sdf,const char * dir,const char * file,Ofl_desc * ofl,Rej_desc * rej)34617c478bd9Sstevel@tonic-gate process_req_lib(Sdf_desc *sdf, const char *dir, const char *file,
34627c478bd9Sstevel@tonic-gate Ofl_desc *ofl, Rej_desc *rej)
34637c478bd9Sstevel@tonic-gate {
34647c478bd9Sstevel@tonic-gate size_t dlen, plen;
34657c478bd9Sstevel@tonic-gate int fd;
34667c478bd9Sstevel@tonic-gate char path[PATH_MAX];
34677c478bd9Sstevel@tonic-gate const char *_dir = dir;
34687c478bd9Sstevel@tonic-gate
34697c478bd9Sstevel@tonic-gate /*
34707c478bd9Sstevel@tonic-gate * Determine the sizes of the directory and filename to insure we don't
34717c478bd9Sstevel@tonic-gate * exceed our buffer.
34727c478bd9Sstevel@tonic-gate */
34737c478bd9Sstevel@tonic-gate if ((dlen = strlen(dir)) == 0) {
34747c478bd9Sstevel@tonic-gate _dir = MSG_ORIG(MSG_STR_DOT);
34757c478bd9Sstevel@tonic-gate dlen = 1;
34767c478bd9Sstevel@tonic-gate }
34777c478bd9Sstevel@tonic-gate dlen++;
34787c478bd9Sstevel@tonic-gate plen = dlen + strlen(file) + 1;
34797c478bd9Sstevel@tonic-gate if (plen > PATH_MAX) {
34801007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_PTHTOLONG),
34815aefb655Srie _dir, file);
34827c478bd9Sstevel@tonic-gate return (0);
34837c478bd9Sstevel@tonic-gate }
34847c478bd9Sstevel@tonic-gate
34857c478bd9Sstevel@tonic-gate /*
34867c478bd9Sstevel@tonic-gate * Build the entire pathname and try and open the file.
34877c478bd9Sstevel@tonic-gate */
34887c478bd9Sstevel@tonic-gate (void) strcpy(path, _dir);
34897c478bd9Sstevel@tonic-gate (void) strcat(path, MSG_ORIG(MSG_STR_SLASH));
34907c478bd9Sstevel@tonic-gate (void) strcat(path, file);
34915aefb655Srie DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name,
34925aefb655Srie sdf->sdf_rfile, path));
34937c478bd9Sstevel@tonic-gate
34947c478bd9Sstevel@tonic-gate if ((fd = open(path, O_RDONLY)) == -1)
34957c478bd9Sstevel@tonic-gate return (0);
34967c478bd9Sstevel@tonic-gate else {
3497dc0f59e5SAli Bahrami uintptr_t open_ret;
34987c478bd9Sstevel@tonic-gate Ifl_desc *ifl;
34997c478bd9Sstevel@tonic-gate char *_path;
35007c478bd9Sstevel@tonic-gate
3501635216b6SRod Evans if ((_path = libld_malloc(strlen(path) + 1)) == NULL)
35027c478bd9Sstevel@tonic-gate return ((Ifl_desc *)S_ERROR);
35037c478bd9Sstevel@tonic-gate (void) strcpy(_path, path);
3504dc0f59e5SAli Bahrami open_ret = ld_process_open(_path, &_path[dlen], &fd, ofl,
3505dc0f59e5SAli Bahrami 0, rej, &ifl);
35063906e0c2Srie if (fd != -1)
35077c478bd9Sstevel@tonic-gate (void) close(fd);
3508dc0f59e5SAli Bahrami if (open_ret != 1)
3509dc0f59e5SAli Bahrami return ((Ifl_desc *)open_ret);
35107c478bd9Sstevel@tonic-gate return (ifl);
35117c478bd9Sstevel@tonic-gate }
35127c478bd9Sstevel@tonic-gate }
35137c478bd9Sstevel@tonic-gate
35147c478bd9Sstevel@tonic-gate /*
35157c478bd9Sstevel@tonic-gate * Finish any library processing. Walk the list of so's that have been listed
35167c478bd9Sstevel@tonic-gate * as "included" by shared objects we have previously processed. Examine them,
35177c478bd9Sstevel@tonic-gate * without adding them as explicit dependents of this program, in order to
35187c478bd9Sstevel@tonic-gate * complete our symbol definition process. The search path rules are:
35197c478bd9Sstevel@tonic-gate *
3520635216b6SRod Evans * - use any user supplied paths, i.e. LD_LIBRARY_PATH and -L, then
35217c478bd9Sstevel@tonic-gate *
3522635216b6SRod Evans * - use any RPATH defined within the parent shared object, then
35237c478bd9Sstevel@tonic-gate *
3524635216b6SRod Evans * - use the default directories, i.e. LIBPATH or -YP.
35257c478bd9Sstevel@tonic-gate */
35267c478bd9Sstevel@tonic-gate uintptr_t
ld_finish_libs(Ofl_desc * ofl)35275aefb655Srie ld_finish_libs(Ofl_desc *ofl)
35287c478bd9Sstevel@tonic-gate {
352957ef7aa9SRod Evans Aliste idx1;
35307c478bd9Sstevel@tonic-gate Sdf_desc *sdf;
35317c478bd9Sstevel@tonic-gate Rej_desc rej = { 0 };
35327c478bd9Sstevel@tonic-gate
35337c478bd9Sstevel@tonic-gate /*
35347c478bd9Sstevel@tonic-gate * Make sure we are back in dynamic mode.
35357c478bd9Sstevel@tonic-gate */
35367c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_DYNLIBS;
35377c478bd9Sstevel@tonic-gate
353857ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_soneed, idx1, sdf)) {
353957ef7aa9SRod Evans Aliste idx2;
35402926dd2eSrie char *path, *slash = NULL;
35417c478bd9Sstevel@tonic-gate int fd;
35427c478bd9Sstevel@tonic-gate Ifl_desc *ifl;
35432926dd2eSrie char *file = (char *)sdf->sdf_name;
35447c478bd9Sstevel@tonic-gate
35457c478bd9Sstevel@tonic-gate /*
35467c478bd9Sstevel@tonic-gate * See if this file has already been processed. At the time
35477c478bd9Sstevel@tonic-gate * this implicit dependency was determined there may still have
3548fb1354edSrie * been more explicit dependencies to process. Note, if we ever
35497c478bd9Sstevel@tonic-gate * do parse the command line three times we would be able to
3550fb1354edSrie * do all this checking when processing the dynamic section.
35517c478bd9Sstevel@tonic-gate */
35527c478bd9Sstevel@tonic-gate if (sdf->sdf_file)
35537c478bd9Sstevel@tonic-gate continue;
35547c478bd9Sstevel@tonic-gate
355557ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_sos, idx2, ifl)) {
35567c478bd9Sstevel@tonic-gate if (!(ifl->ifl_flags & FLG_IF_NEEDSTR) &&
35577c478bd9Sstevel@tonic-gate (strcmp(file, ifl->ifl_soname) == 0)) {
35587c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
35597c478bd9Sstevel@tonic-gate break;
35607c478bd9Sstevel@tonic-gate }
35617c478bd9Sstevel@tonic-gate }
35627c478bd9Sstevel@tonic-gate if (sdf->sdf_file)
35637c478bd9Sstevel@tonic-gate continue;
35647c478bd9Sstevel@tonic-gate
35657c478bd9Sstevel@tonic-gate /*
35662926dd2eSrie * If the current path name element embeds a "/", then it's to
35672926dd2eSrie * be taken "as is", with no searching involved. Process all
35682926dd2eSrie * "/" occurrences, so that we can deduce the base file name.
35697c478bd9Sstevel@tonic-gate */
35702926dd2eSrie for (path = file; *path; path++) {
35717c478bd9Sstevel@tonic-gate if (*path == '/')
35722926dd2eSrie slash = path;
35732926dd2eSrie }
35742926dd2eSrie if (slash) {
35755aefb655Srie DBG_CALL(Dbg_libs_req(ofl->ofl_lml, sdf->sdf_name,
35765aefb655Srie sdf->sdf_rfile, file));
35777c478bd9Sstevel@tonic-gate if ((fd = open(file, O_RDONLY)) == -1) {
35781007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
35795aefb655Srie MSG_INTL(MSG_FIL_NOTFOUND), file,
35805aefb655Srie sdf->sdf_rfile);
35817c478bd9Sstevel@tonic-gate } else {
3582dc0f59e5SAli Bahrami uintptr_t open_ret;
35837c478bd9Sstevel@tonic-gate Rej_desc _rej = { 0 };
35847c478bd9Sstevel@tonic-gate
35851007fd6fSAli Bahrami open_ret = ld_process_open(file, ++slash,
35861007fd6fSAli Bahrami &fd, ofl, 0, &_rej, &ifl);
35873906e0c2Srie if (fd != -1)
35887c478bd9Sstevel@tonic-gate (void) close(fd);
3589dc0f59e5SAli Bahrami if (open_ret == S_ERROR)
35907c478bd9Sstevel@tonic-gate return (S_ERROR);
3591a6d4d7d5SRod Evans
35927c478bd9Sstevel@tonic-gate if (_rej.rej_type) {
3593de777a60Sab196087 Conv_reject_desc_buf_t rej_buf;
3594de777a60Sab196087
35951007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
35967c478bd9Sstevel@tonic-gate MSG_INTL(reject[_rej.rej_type]),
35977c478bd9Sstevel@tonic-gate _rej.rej_name ? rej.rej_name :
35987c478bd9Sstevel@tonic-gate MSG_INTL(MSG_STR_UNKNOWN),
3599ba2be530Sab196087 conv_reject_desc(&_rej, &rej_buf,
3600ba2be530Sab196087 ld_targ.t_m.m_mach));
36017c478bd9Sstevel@tonic-gate } else
36027c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
36037c478bd9Sstevel@tonic-gate }
36047c478bd9Sstevel@tonic-gate continue;
36057c478bd9Sstevel@tonic-gate }
36067c478bd9Sstevel@tonic-gate
36077c478bd9Sstevel@tonic-gate /*
36087c478bd9Sstevel@tonic-gate * Now search for this file in any user defined directories.
36097c478bd9Sstevel@tonic-gate */
361057ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_ulibdirs, idx2, path)) {
36117c478bd9Sstevel@tonic-gate Rej_desc _rej = { 0 };
36127c478bd9Sstevel@tonic-gate
36137c478bd9Sstevel@tonic-gate ifl = process_req_lib(sdf, path, file, ofl, &_rej);
36147c478bd9Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) {
36157c478bd9Sstevel@tonic-gate return (S_ERROR);
36167c478bd9Sstevel@tonic-gate }
36177c478bd9Sstevel@tonic-gate if (_rej.rej_type) {
36187c478bd9Sstevel@tonic-gate if (rej.rej_type == 0) {
36197c478bd9Sstevel@tonic-gate rej = _rej;
36207c478bd9Sstevel@tonic-gate rej.rej_name = strdup(_rej.rej_name);
36217c478bd9Sstevel@tonic-gate }
36227c478bd9Sstevel@tonic-gate }
36237c478bd9Sstevel@tonic-gate if (ifl) {
36247c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
36257c478bd9Sstevel@tonic-gate break;
36267c478bd9Sstevel@tonic-gate }
36277c478bd9Sstevel@tonic-gate }
36287c478bd9Sstevel@tonic-gate if (sdf->sdf_file)
36297c478bd9Sstevel@tonic-gate continue;
36307c478bd9Sstevel@tonic-gate
36317c478bd9Sstevel@tonic-gate /*
36327c478bd9Sstevel@tonic-gate * Next use the local rules defined within the parent shared
36337c478bd9Sstevel@tonic-gate * object.
36347c478bd9Sstevel@tonic-gate */
36357c478bd9Sstevel@tonic-gate if (sdf->sdf_rpath != NULL) {
36367c478bd9Sstevel@tonic-gate char *rpath, *next;
36377c478bd9Sstevel@tonic-gate
36387c478bd9Sstevel@tonic-gate rpath = libld_malloc(strlen(sdf->sdf_rpath) + 1);
3639635216b6SRod Evans if (rpath == NULL)
36407c478bd9Sstevel@tonic-gate return (S_ERROR);
36417c478bd9Sstevel@tonic-gate (void) strcpy(rpath, sdf->sdf_rpath);
36425aefb655Srie DBG_CALL(Dbg_libs_path(ofl->ofl_lml, rpath,
36435aefb655Srie LA_SER_RUNPATH, sdf->sdf_rfile));
36447c478bd9Sstevel@tonic-gate if ((path = strtok_r(rpath,
36457c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_STR_COLON), &next)) != NULL) {
36467c478bd9Sstevel@tonic-gate do {
36477c478bd9Sstevel@tonic-gate Rej_desc _rej = { 0 };
36487c478bd9Sstevel@tonic-gate
36497c478bd9Sstevel@tonic-gate path = expand(sdf->sdf_rfile, path,
36507c478bd9Sstevel@tonic-gate &next);
36517c478bd9Sstevel@tonic-gate
36527c478bd9Sstevel@tonic-gate ifl = process_req_lib(sdf, path,
36537c478bd9Sstevel@tonic-gate file, ofl, &_rej);
36547c478bd9Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) {
36557c478bd9Sstevel@tonic-gate return (S_ERROR);
36567c478bd9Sstevel@tonic-gate }
3657d840867fSab196087 if ((_rej.rej_type) &&
3658d840867fSab196087 (rej.rej_type == 0)) {
36597c478bd9Sstevel@tonic-gate rej = _rej;
36607c478bd9Sstevel@tonic-gate rej.rej_name =
36617c478bd9Sstevel@tonic-gate strdup(_rej.rej_name);
36627c478bd9Sstevel@tonic-gate }
36637c478bd9Sstevel@tonic-gate if (ifl) {
36647c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
36657c478bd9Sstevel@tonic-gate break;
36667c478bd9Sstevel@tonic-gate }
36677c478bd9Sstevel@tonic-gate } while ((path = strtok_r(NULL,
36687c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_STR_COLON), &next)) != NULL);
36697c478bd9Sstevel@tonic-gate }
36707c478bd9Sstevel@tonic-gate }
36717c478bd9Sstevel@tonic-gate if (sdf->sdf_file)
36727c478bd9Sstevel@tonic-gate continue;
36737c478bd9Sstevel@tonic-gate
36747c478bd9Sstevel@tonic-gate /*
36757c478bd9Sstevel@tonic-gate * Finally try the default library search directories.
36767c478bd9Sstevel@tonic-gate */
367757ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_dlibdirs, idx2, path)) {
36787c478bd9Sstevel@tonic-gate Rej_desc _rej = { 0 };
36797c478bd9Sstevel@tonic-gate
36807c478bd9Sstevel@tonic-gate ifl = process_req_lib(sdf, path, file, ofl, &rej);
36817c478bd9Sstevel@tonic-gate if (ifl == (Ifl_desc *)S_ERROR) {
36827c478bd9Sstevel@tonic-gate return (S_ERROR);
36837c478bd9Sstevel@tonic-gate }
36847c478bd9Sstevel@tonic-gate if (_rej.rej_type) {
36857c478bd9Sstevel@tonic-gate if (rej.rej_type == 0) {
36867c478bd9Sstevel@tonic-gate rej = _rej;
36877c478bd9Sstevel@tonic-gate rej.rej_name = strdup(_rej.rej_name);
36887c478bd9Sstevel@tonic-gate }
36897c478bd9Sstevel@tonic-gate }
36907c478bd9Sstevel@tonic-gate if (ifl) {
36917c478bd9Sstevel@tonic-gate sdf->sdf_file = ifl;
36927c478bd9Sstevel@tonic-gate break;
36937c478bd9Sstevel@tonic-gate }
36947c478bd9Sstevel@tonic-gate }
36957c478bd9Sstevel@tonic-gate if (sdf->sdf_file)
36967c478bd9Sstevel@tonic-gate continue;
36977c478bd9Sstevel@tonic-gate
36987c478bd9Sstevel@tonic-gate /*
36997c478bd9Sstevel@tonic-gate * If we've got this far we haven't found the shared object.
37007c478bd9Sstevel@tonic-gate * If an object was found, but was rejected for some reason,
37017c478bd9Sstevel@tonic-gate * print a diagnostic to that effect, otherwise generate a
37027c478bd9Sstevel@tonic-gate * generic "not found" diagnostic.
37037c478bd9Sstevel@tonic-gate */
37047c478bd9Sstevel@tonic-gate if (rej.rej_type) {
3705de777a60Sab196087 Conv_reject_desc_buf_t rej_buf;
3706de777a60Sab196087
37071007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
37085aefb655Srie MSG_INTL(reject[rej.rej_type]),
37097c478bd9Sstevel@tonic-gate rej.rej_name ? rej.rej_name :
3710de777a60Sab196087 MSG_INTL(MSG_STR_UNKNOWN),
3711ba2be530Sab196087 conv_reject_desc(&rej, &rej_buf,
3712ba2be530Sab196087 ld_targ.t_m.m_mach));
37137c478bd9Sstevel@tonic-gate } else {
37141007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING,
37155aefb655Srie MSG_INTL(MSG_FIL_NOTFOUND), file, sdf->sdf_rfile);
37167c478bd9Sstevel@tonic-gate }
37177c478bd9Sstevel@tonic-gate }
37187c478bd9Sstevel@tonic-gate
37197c478bd9Sstevel@tonic-gate /*
37207c478bd9Sstevel@tonic-gate * Finally, now that all objects have been input, make sure any version
37217c478bd9Sstevel@tonic-gate * requirements have been met.
37227c478bd9Sstevel@tonic-gate */
37235aefb655Srie return (ld_vers_verify(ofl));
37247c478bd9Sstevel@tonic-gate }
3725