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 */ 215aefb655Srie 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright (c) 1988 AT&T 247c478bd9Sstevel@tonic-gate * All Rights Reserved 257c478bd9Sstevel@tonic-gate * 26bb3b4f6cSRod Evans * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 277c478bd9Sstevel@tonic-gate * Use is subject to license terms. 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * Update the new output file image, perform virtual address, offset and 327c478bd9Sstevel@tonic-gate * displacement calculations on the program headers and sections headers, 337c478bd9Sstevel@tonic-gate * and generate any new output section information. 347c478bd9Sstevel@tonic-gate */ 35ba2be530Sab 36ba2be530Sab #define ELF_TARGET_AMD64 37ba2be530Sab 387c478bd9Sstevel@tonic-gate #include <stdio.h> 397c478bd9Sstevel@tonic-gate #include <string.h> 40fdf855a7Sseizo #include <unistd.h> 415aefb655Srie #include <debug.h> 427c478bd9Sstevel@tonic-gate #include "msg.h" 437c478bd9Sstevel@tonic-gate #include "_libld.h" 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 469039eeafSab * Comparison routine used by qsort() for sorting of the global symbol list 477c478bd9Sstevel@tonic-gate * based off of the hashbuckets the symbol will eventually be deposited in. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate static int 507c478bd9Sstevel@tonic-gate sym_hash_compare(Sym_s_list * s1, Sym_s_list * s2) 517c478bd9Sstevel@tonic-gate { 527c478bd9Sstevel@tonic-gate return (s1->sl_hval - s2->sl_hval); 537c478bd9Sstevel@tonic-gate } 547c478bd9Sstevel@tonic-gate 55d579eb63Sab /* 56d579eb63Sab * Comparison routine used by qsort() for sorting of dyn[sym|tls]sort section 57d579eb63Sab * indices based on the address of the symbols they reference. The 58d579eb63Sab * use of the global dynsort_compare_syms variable is needed because 59d579eb63Sab * we need to examine the symbols the indices reference. It is safe, because 60d579eb63Sab * the linker is single threaded. 61d579eb63Sab */ 62d579eb63Sab Sym *dynsort_compare_syms; 63d579eb63Sab 64d579eb63Sab static int 65d579eb63Sab dynsort_compare(const void *idx1, const void *idx2) 66d579eb63Sab { 67d579eb63Sab Sym *s1 = dynsort_compare_syms + *((const Word *) idx1); 68d579eb63Sab Sym *s2 = dynsort_compare_syms + *((const Word *) idx2); 69d579eb63Sab 70d579eb63Sab /* 71d579eb63Sab * Note: the logical computation for this is 72d579eb63Sab * (st_value1 - st_value2) 73d579eb63Sab * However, that is only correct if the address type is smaller 74d579eb63Sab * than a pointer. Writing it this way makes it immune to the 75d579eb63Sab * class (32 or 64-bit) of the linker. 76d579eb63Sab */ 77d579eb63Sab return ((s1->st_value < s2->st_value) ? -1 : 78d579eb63Sab (s1->st_value > s2->st_value)); 79d579eb63Sab } 80d579eb63Sab 81d579eb63Sab /* 82d579eb63Sab * Scan the sorted symbols, and issue warnings if there are any duplicate 83d579eb63Sab * values in the list. We only do this if -zverbose is set, or we are 84d579eb63Sab * running with LD_DEBUG defined 85d579eb63Sab * 86d579eb63Sab * entry: 87d579eb63Sab * ofl - Output file descriptor 88d579eb63Sab * ldynsym - Pointer to start of .SUNW_ldynsym section that the 89d579eb63Sab * sort section indexes reference. 90d579eb63Sab * symsort - Pointer to start of .SUNW_dynsymsort or .SUNW_dyntlssort 91d579eb63Sab * section. 92d579eb63Sab * n - # of indices in symsort array 93d579eb63Sab * secname - Name of the symsort section. 94d579eb63Sab * 95d579eb63Sab * exit: 96d579eb63Sab * If the symsort section contains indexes to more than one 97d579eb63Sab * symbol with the same address value, a warning is issued. 98d579eb63Sab */ 99d579eb63Sab static void 100d579eb63Sab dynsort_dupwarn(Ofl_desc *ofl, Sym *ldynsym, const char *str, 101d579eb63Sab Word *symsort, Word n, const char *secname) 102d579eb63Sab { 103d579eb63Sab int zverbose = (ofl->ofl_flags & FLG_OF_VERBOSE) != 0; 104d579eb63Sab Word ndx, cmp_ndx; 105d579eb63Sab Addr addr, cmp_addr; 106d579eb63Sab 107d579eb63Sab /* Nothing to do if -zverbose or LD_DEBUG are not active */ 108d579eb63Sab if (!(zverbose || DBG_ENABLED)) 109d579eb63Sab return; 110d579eb63Sab 111d579eb63Sab cmp_ndx = 0; 112d579eb63Sab cmp_addr = ldynsym[symsort[cmp_ndx]].st_value; 113d579eb63Sab for (ndx = 1; ndx < n; ndx++) { 114d579eb63Sab addr = ldynsym[symsort[ndx]].st_value; 115d579eb63Sab if (cmp_addr == addr) { 116d579eb63Sab if (zverbose) 117d579eb63Sab eprintf(ofl->ofl_lml, ERR_WARNING, 118d579eb63Sab MSG_INTL(MSG_SYM_DUPSORTADDR), secname, 119d579eb63Sab str + ldynsym[symsort[cmp_ndx]].st_name, 120d579eb63Sab str + ldynsym[symsort[ndx]].st_name, 121d579eb63Sab EC_ADDR(addr)); 122d579eb63Sab DBG_CALL(Dbg_syms_dup_sort_addr(ofl->ofl_lml, secname, 123d579eb63Sab str + ldynsym[symsort[cmp_ndx]].st_name, 124d579eb63Sab str + ldynsym[symsort[ndx]].st_name, 125d579eb63Sab EC_ADDR(addr))); 126d579eb63Sab } else { /* Not a dup. Move reference up */ 127d579eb63Sab cmp_ndx = ndx; 128d579eb63Sab cmp_addr = addr; 129d579eb63Sab } 130d579eb63Sab } 131d579eb63Sab } 132d579eb63Sab 133d579eb63Sab 1347c478bd9Sstevel@tonic-gate /* 1357c478bd9Sstevel@tonic-gate * Build and update any output symbol tables. Here we work on all the symbol 1367c478bd9Sstevel@tonic-gate * tables at once to reduce the duplication of symbol and string manipulation. 1377c478bd9Sstevel@tonic-gate * Symbols and their associated strings are copied from the read-only input 1387c478bd9Sstevel@tonic-gate * file images to the output image and their values and index's updated in the 1397c478bd9Sstevel@tonic-gate * output image. 1407c478bd9Sstevel@tonic-gate */ 1415aefb655Srie static Addr 1427c478bd9Sstevel@tonic-gate update_osym(Ofl_desc *ofl) 1437c478bd9Sstevel@tonic-gate { 144d579eb63Sab /* 145d579eb63Sab * There are several places in this function where we wish 146d579eb63Sab * to insert a symbol index to the combined .SUNW_ldynsym/.dynsym 147d579eb63Sab * symbol table into one of the two sort sections (.SUNW_dynsymsort 148d579eb63Sab * or .SUNW_dyntlssort), if that symbol has the right attributes. 149d579eb63Sab * This macro is used to generate the necessary code from a single 150d579eb63Sab * specification. 151d579eb63Sab * 152d579eb63Sab * entry: 153d579eb63Sab * _sdp, _sym, _type - As per DYNSORT_COUNT. See _libld.h 154d579eb63Sab * _sym_ndx - Index that _sym will have in the combined 155d579eb63Sab * .SUNW_ldynsym/.dynsym symbol table. 156d579eb63Sab */ 157d579eb63Sab #define ADD_TO_DYNSORT(_sdp, _sym, _type, _sym_ndx) \ 158d579eb63Sab { \ 159d579eb63Sab Word *_dynsort_arr, *_dynsort_ndx; \ 160d579eb63Sab \ 161d579eb63Sab if (dynsymsort_symtype[_type]) { \ 162d579eb63Sab _dynsort_arr = dynsymsort; \ 163d579eb63Sab _dynsort_ndx = &dynsymsort_ndx; \ 164d579eb63Sab } else if (_type == STT_TLS) { \ 165d579eb63Sab _dynsort_arr = dyntlssort; \ 166d579eb63Sab _dynsort_ndx = &dyntlssort_ndx; \ 167d579eb63Sab } else { \ 168d579eb63Sab _dynsort_arr = NULL; \ 169d579eb63Sab } \ 170d579eb63Sab if ((_dynsort_arr != NULL) && DYNSORT_TEST_ATTR(_sdp, _sym)) \ 171d579eb63Sab _dynsort_arr[(*_dynsort_ndx)++] = _sym_ndx; \ 172d579eb63Sab } 173d579eb63Sab 174d579eb63Sab 1757c478bd9Sstevel@tonic-gate Sym_desc *sdp; 1767c478bd9Sstevel@tonic-gate Sym_avlnode *sav; 17757ef7aa9SRod Evans Sg_desc *sgp, *tsgp = NULL, *dsgp = NULL, *esgp = NULL; 17857ef7aa9SRod Evans Os_desc *osp, *iosp = NULL, *fosp = NULL; 17957ef7aa9SRod Evans Is_desc *isc; 1807c478bd9Sstevel@tonic-gate Ifl_desc *ifl; 1817c478bd9Sstevel@tonic-gate Word bssndx, etext_ndx, edata_ndx = 0, end_ndx, start_ndx; 1827c478bd9Sstevel@tonic-gate Word end_abs = 0, etext_abs = 0, edata_abs; 18335450702SAli Bahrami Word tlsbssndx = 0, parexpnndx; 184ba2be530Sab #if defined(_ELF64) 18554d82594Sseizo Word lbssndx = 0; 18654d82594Sseizo Addr lbssaddr = 0; 18754d82594Sseizo #endif 1887c478bd9Sstevel@tonic-gate Addr bssaddr, etext = 0, edata = 0, end = 0, start = 0; 1897c478bd9Sstevel@tonic-gate Addr tlsbssaddr = 0; 190b26cc8daSAli Bahrami Addr parexpnbase, parexpnaddr; 1917c478bd9Sstevel@tonic-gate int start_set = 0; 19257ef7aa9SRod Evans Sym _sym = {0}, *sym, *symtab = NULL; 19357ef7aa9SRod Evans Sym *dynsym = NULL, *ldynsym = NULL; 1947c478bd9Sstevel@tonic-gate Word symtab_ndx = 0; /* index into .symtab */ 195ca4eed8bSAli Bahrami Word symtab_gbl_bndx; /* .symtab ndx 1st global */ 1969039eeafSab Word ldynsym_ndx = 0; /* index into .SUNW_ldynsym */ 1979039eeafSab Word dynsym_ndx = 0; /* index into .dynsym */ 1987c478bd9Sstevel@tonic-gate Word scopesym_ndx = 0; /* index into scoped symbols */ 199ca4eed8bSAli Bahrami Word scopesym_bndx = 0; /* .symtab ndx 1st scoped sym */ 2009039eeafSab Word ldynscopesym_ndx = 0; /* index to ldynsym scoped syms */ 201d579eb63Sab Word *dynsymsort = NULL; /* SUNW_dynsymsort index vector */ 202d579eb63Sab Word *dyntlssort = NULL; /* SUNW_dyntlssort index vector */ 203d579eb63Sab Word dynsymsort_ndx; /* index dynsymsort array */ 204d579eb63Sab Word dyntlssort_ndx; /* index dyntlssort array */ 2059039eeafSab Word *symndx; /* Symbol index (for relocation use) */ 20657ef7aa9SRod Evans Word *symshndx = NULL; /* .symtab_shndx table */ 20757ef7aa9SRod Evans Word *dynshndx = NULL; /* .dynsym_shndx table */ 20857ef7aa9SRod Evans Word *ldynshndx = NULL; /* .SUNW_ldynsym_shndx table */ 20957ef7aa9SRod Evans Word ldynsym_cnt = NULL; /* # of items in .SUNW_ldynsym */ 2107c478bd9Sstevel@tonic-gate Str_tbl *shstrtab; 2117c478bd9Sstevel@tonic-gate Str_tbl *strtab; 2127c478bd9Sstevel@tonic-gate Str_tbl *dynstr; 2137c478bd9Sstevel@tonic-gate Word *hashtab; /* hash table pointer */ 2147c478bd9Sstevel@tonic-gate Word *hashbkt; /* hash table bucket pointer */ 2157c478bd9Sstevel@tonic-gate Word *hashchain; /* hash table chain pointer */ 2167c478bd9Sstevel@tonic-gate Word hashval; /* value of hash function */ 2177c478bd9Sstevel@tonic-gate Wk_desc *wkp; 21857ef7aa9SRod Evans Alist *weak = NULL; 2191d9df23bSab ofl_flag_t flags = ofl->ofl_flags; 2207c478bd9Sstevel@tonic-gate Word dtflags_1 = ofl->ofl_dtflags_1; 2217c478bd9Sstevel@tonic-gate Versym *versym; 2227c478bd9Sstevel@tonic-gate Gottable *gottable; /* used for display got debugging */ 2237c478bd9Sstevel@tonic-gate /* information */ 2247c478bd9Sstevel@tonic-gate Syminfo *syminfo; 2257c478bd9Sstevel@tonic-gate Sym_s_list *sorted_syms; /* table to hold sorted symbols */ 2267c478bd9Sstevel@tonic-gate Word ssndx; /* global index into sorted_syms */ 2277c478bd9Sstevel@tonic-gate Word scndx; /* scoped index into sorted_syms */ 228cce0e03bSab size_t stoff; /* string offset */ 22957ef7aa9SRod Evans Aliste idx1; 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate /* 2327c478bd9Sstevel@tonic-gate * Initialize pointers to the symbol table entries and the symbol 2337c478bd9Sstevel@tonic-gate * table strings. Skip the first symbol entry and the first string 2347c478bd9Sstevel@tonic-gate * table byte. Note that if we are not generating any output symbol 2357c478bd9Sstevel@tonic-gate * tables we must still generate and update an internal copies so 2367c478bd9Sstevel@tonic-gate * that the relocation phase has the correct information. 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_STRIP) || (flags & FLG_OF_RELOBJ) || 2397c478bd9Sstevel@tonic-gate ((flags & FLG_OF_STATIC) && ofl->ofl_osversym)) { 2407c478bd9Sstevel@tonic-gate symtab = (Sym *)ofl->ofl_ossymtab->os_outdata->d_buf; 2417c478bd9Sstevel@tonic-gate symtab[symtab_ndx++] = _sym; 2427c478bd9Sstevel@tonic-gate if (ofl->ofl_ossymshndx) 243d840867fSab symshndx = 244d840867fSab (Word *)ofl->ofl_ossymshndx->os_outdata->d_buf; 2457c478bd9Sstevel@tonic-gate } 2469039eeafSab if (OFL_ALLOW_DYNSYM(ofl)) { 2477c478bd9Sstevel@tonic-gate dynsym = (Sym *)ofl->ofl_osdynsym->os_outdata->d_buf; 2487c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx++] = _sym; 2499039eeafSab /* 2509039eeafSab * If we are also constructing a .SUNW_ldynsym section 2519039eeafSab * to contain local function symbols, then set it up too. 2529039eeafSab */ 2539039eeafSab if (ofl->ofl_osldynsym) { 2549039eeafSab ldynsym = (Sym *)ofl->ofl_osldynsym->os_outdata->d_buf; 2559039eeafSab ldynsym[ldynsym_ndx++] = _sym; 256d579eb63Sab ldynsym_cnt = 1 + ofl->ofl_dynlocscnt + 257d579eb63Sab ofl->ofl_dynscopecnt; 258d579eb63Sab 259d579eb63Sab /* 260d579eb63Sab * If there is a SUNW_ldynsym, then there may also 261d579eb63Sab * be a .SUNW_dynsymsort and/or .SUNW_dyntlssort 262d579eb63Sab * sections, used to collect indices of function 263d579eb63Sab * and data symbols sorted by address order. 264d579eb63Sab */ 265d579eb63Sab if (ofl->ofl_osdynsymsort) { /* .SUNW_dynsymsort */ 266d579eb63Sab dynsymsort = (Word *) 267d579eb63Sab ofl->ofl_osdynsymsort->os_outdata->d_buf; 268d579eb63Sab dynsymsort_ndx = 0; 269d579eb63Sab } 270d579eb63Sab if (ofl->ofl_osdyntlssort) { /* .SUNW_dyntlssort */ 271d579eb63Sab dyntlssort = (Word *) 272d579eb63Sab ofl->ofl_osdyntlssort->os_outdata->d_buf; 273d579eb63Sab dyntlssort_ndx = 0; 274d579eb63Sab } 2759039eeafSab } 2769039eeafSab 2777c478bd9Sstevel@tonic-gate /* 2787c478bd9Sstevel@tonic-gate * Initialize the hash table. 2797c478bd9Sstevel@tonic-gate */ 2807c478bd9Sstevel@tonic-gate hashtab = (Word *)(ofl->ofl_oshash->os_outdata->d_buf); 2817c478bd9Sstevel@tonic-gate hashbkt = &hashtab[2]; 2827c478bd9Sstevel@tonic-gate hashchain = &hashtab[2 + ofl->ofl_hashbkts]; 2837c478bd9Sstevel@tonic-gate hashtab[0] = ofl->ofl_hashbkts; 2847c478bd9Sstevel@tonic-gate hashtab[1] = ofl->ofl_dynshdrcnt + ofl->ofl_globcnt + 2857c478bd9Sstevel@tonic-gate ofl->ofl_lregsymcnt + 1; 2867c478bd9Sstevel@tonic-gate if (ofl->ofl_osdynshndx) 287d840867fSab dynshndx = 288d840867fSab (Word *)ofl->ofl_osdynshndx->os_outdata->d_buf; 2899039eeafSab if (ofl->ofl_osldynshndx) 290d840867fSab ldynshndx = 291d840867fSab (Word *)ofl->ofl_osldynshndx->os_outdata->d_buf; 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate /* 2957c478bd9Sstevel@tonic-gate * symndx is the symbol index to be used for relocation processing. It 2967c478bd9Sstevel@tonic-gate * points to the relevant symtab's (.dynsym or .symtab) symbol ndx. 2977c478bd9Sstevel@tonic-gate */ 2987c478bd9Sstevel@tonic-gate if (dynsym) 2997c478bd9Sstevel@tonic-gate symndx = &dynsym_ndx; 3007c478bd9Sstevel@tonic-gate else 3017c478bd9Sstevel@tonic-gate symndx = &symtab_ndx; 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate /* 3047c478bd9Sstevel@tonic-gate * If we have version definitions initialize the version symbol index 3057c478bd9Sstevel@tonic-gate * table. There is one entry for each symbol which contains the symbols 3067c478bd9Sstevel@tonic-gate * version index. 3077c478bd9Sstevel@tonic-gate */ 308090a8d9eSAli Bahrami if (!(flags & FLG_OF_NOVERSEC) && 309090a8d9eSAli Bahrami (flags & (FLG_OF_VERNEED | FLG_OF_VERDEF))) { 3107c478bd9Sstevel@tonic-gate versym = (Versym *)ofl->ofl_osversym->os_outdata->d_buf; 311*28bda19cSRod Evans versym[0] = NULL; 3127c478bd9Sstevel@tonic-gate } else 313*28bda19cSRod Evans versym = NULL; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate /* 3167c478bd9Sstevel@tonic-gate * If syminfo section exists be prepared to fill it in. 3177c478bd9Sstevel@tonic-gate */ 3187c478bd9Sstevel@tonic-gate if (ofl->ofl_ossyminfo) { 3197c478bd9Sstevel@tonic-gate syminfo = ofl->ofl_ossyminfo->os_outdata->d_buf; 3207c478bd9Sstevel@tonic-gate syminfo[0].si_flags = SYMINFO_CURRENT; 3217c478bd9Sstevel@tonic-gate } else 322*28bda19cSRod Evans syminfo = NULL; 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate /* 3257c478bd9Sstevel@tonic-gate * Setup our string tables. 3267c478bd9Sstevel@tonic-gate */ 3277c478bd9Sstevel@tonic-gate shstrtab = ofl->ofl_shdrsttab; 3287c478bd9Sstevel@tonic-gate strtab = ofl->ofl_strtab; 3297c478bd9Sstevel@tonic-gate dynstr = ofl->ofl_dynstrtab; 3307c478bd9Sstevel@tonic-gate 3315aefb655Srie DBG_CALL(Dbg_syms_sec_title(ofl->ofl_lml)); 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate /* 3349039eeafSab * Put output file name to the first .symtab and .SUNW_ldynsym symbol. 3357c478bd9Sstevel@tonic-gate */ 3367c478bd9Sstevel@tonic-gate if (symtab) { 3377c478bd9Sstevel@tonic-gate (void) st_setstring(strtab, ofl->ofl_name, &stoff); 3387c478bd9Sstevel@tonic-gate sym = &symtab[symtab_ndx++]; 3397c478bd9Sstevel@tonic-gate /* LINTED */ 3407c478bd9Sstevel@tonic-gate sym->st_name = stoff; 3417c478bd9Sstevel@tonic-gate sym->st_value = 0; 3427c478bd9Sstevel@tonic-gate sym->st_size = 0; 3437c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(STB_LOCAL, STT_FILE); 3447c478bd9Sstevel@tonic-gate sym->st_other = 0; 3457c478bd9Sstevel@tonic-gate sym->st_shndx = SHN_ABS; 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate if (versym && !dynsym) 3487c478bd9Sstevel@tonic-gate versym[1] = 0; 3497c478bd9Sstevel@tonic-gate } 350d579eb63Sab if (ldynsym) { 3519039eeafSab (void) st_setstring(dynstr, ofl->ofl_name, &stoff); 3529039eeafSab sym = &ldynsym[ldynsym_ndx]; 3539039eeafSab /* LINTED */ 3549039eeafSab sym->st_name = stoff; 3559039eeafSab sym->st_value = 0; 3569039eeafSab sym->st_size = 0; 3579039eeafSab sym->st_info = ELF_ST_INFO(STB_LOCAL, STT_FILE); 3589039eeafSab sym->st_other = 0; 3599039eeafSab sym->st_shndx = SHN_ABS; 3609039eeafSab 3619039eeafSab /* Scoped symbols get filled in global loop below */ 3629039eeafSab ldynscopesym_ndx = ldynsym_ndx + 1; 3639039eeafSab ldynsym_ndx += ofl->ofl_dynscopecnt; 3649039eeafSab } 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate /* 3677c478bd9Sstevel@tonic-gate * If we are to display GOT summary information, then allocate 3687c478bd9Sstevel@tonic-gate * the buffer to 'cache' the GOT symbols into now. 3697c478bd9Sstevel@tonic-gate */ 3705aefb655Srie if (DBG_ENABLED) { 371d326b23bSrie if ((ofl->ofl_gottable = gottable = 37257ef7aa9SRod Evans libld_calloc(ofl->ofl_gotcnt, sizeof (Gottable))) == NULL) 3737c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 3747c478bd9Sstevel@tonic-gate } 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate /* 3777c478bd9Sstevel@tonic-gate * Traverse the program headers. Determine the last executable segment 3787c478bd9Sstevel@tonic-gate * and the last data segment so that we can update etext and edata. If 3797c478bd9Sstevel@tonic-gate * we have empty segments (reservations) record them for setting _end. 3807c478bd9Sstevel@tonic-gate */ 38157ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_segs, idx1, sgp)) { 3820bc07c75Srie Phdr *phd = &(sgp->sg_phdr); 383cce0e03bSab Os_desc *osp; 38457ef7aa9SRod Evans Aliste idx2; 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate if (phd->p_type == PT_LOAD) { 3870bc07c75Srie if (sgp->sg_osdescs != NULL) { 388d840867fSab Word _flags = phd->p_flags & (PF_W | PF_R); 3890bc07c75Srie 390d840867fSab if (_flags == PF_R) 391d840867fSab tsgp = sgp; 392d840867fSab else if (_flags == (PF_W | PF_R)) 393d840867fSab dsgp = sgp; 3947c478bd9Sstevel@tonic-gate } else if (sgp->sg_flags & FLG_SG_EMPTY) 395d840867fSab esgp = sgp; 3967c478bd9Sstevel@tonic-gate } 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate /* 3997c478bd9Sstevel@tonic-gate * Generate a section symbol for each output section. 4007c478bd9Sstevel@tonic-gate */ 40157ef7aa9SRod Evans for (APLIST_TRAVERSE(sgp->sg_osdescs, idx2, osp)) { 4027c478bd9Sstevel@tonic-gate Word sectndx; 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate sym = &_sym; 4057c478bd9Sstevel@tonic-gate sym->st_value = osp->os_shdr->sh_addr; 4067c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(STB_LOCAL, STT_SECTION); 4077c478bd9Sstevel@tonic-gate /* LINTED */ 4087c478bd9Sstevel@tonic-gate sectndx = elf_ndxscn(osp->os_scn); 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate if (symtab) { 4117c478bd9Sstevel@tonic-gate if (sectndx >= SHN_LORESERVE) { 4127c478bd9Sstevel@tonic-gate symshndx[symtab_ndx] = sectndx; 4137c478bd9Sstevel@tonic-gate sym->st_shndx = SHN_XINDEX; 4147c478bd9Sstevel@tonic-gate } else { 4157c478bd9Sstevel@tonic-gate /* LINTED */ 4167c478bd9Sstevel@tonic-gate sym->st_shndx = (Half)sectndx; 4177c478bd9Sstevel@tonic-gate } 4187c478bd9Sstevel@tonic-gate symtab[symtab_ndx++] = *sym; 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate if (dynsym && (osp->os_flags & FLG_OS_OUTREL)) 4227c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx++] = *sym; 4237c478bd9Sstevel@tonic-gate 42457ef7aa9SRod Evans if ((dynsym == NULL) || 42557ef7aa9SRod Evans (osp->os_flags & FLG_OS_OUTREL)) { 4267c478bd9Sstevel@tonic-gate if (versym) 4277c478bd9Sstevel@tonic-gate versym[*symndx - 1] = 0; 42857ef7aa9SRod Evans osp->os_identndx = *symndx - 1; 4295aefb655Srie DBG_CALL(Dbg_syms_sec_entry(ofl->ofl_lml, 43057ef7aa9SRod Evans osp->os_identndx, sgp, osp)); 4317c478bd9Sstevel@tonic-gate } 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate /* 4347c478bd9Sstevel@tonic-gate * Generate the .shstrtab for this section. 4357c478bd9Sstevel@tonic-gate */ 4367c478bd9Sstevel@tonic-gate (void) st_setstring(shstrtab, osp->os_name, &stoff); 4377c478bd9Sstevel@tonic-gate osp->os_shdr->sh_name = (Word)stoff; 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate /* 4407c478bd9Sstevel@tonic-gate * Find the section index for our special symbols. 4417c478bd9Sstevel@tonic-gate */ 4427c478bd9Sstevel@tonic-gate if (sgp == tsgp) { 4437c478bd9Sstevel@tonic-gate /* LINTED */ 4447c478bd9Sstevel@tonic-gate etext_ndx = elf_ndxscn(osp->os_scn); 4457c478bd9Sstevel@tonic-gate } else if (dsgp == sgp) { 4467c478bd9Sstevel@tonic-gate if (osp->os_shdr->sh_type != SHT_NOBITS) { 4477c478bd9Sstevel@tonic-gate /* LINTED */ 4487c478bd9Sstevel@tonic-gate edata_ndx = elf_ndxscn(osp->os_scn); 4497c478bd9Sstevel@tonic-gate } 4507c478bd9Sstevel@tonic-gate } 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate if (start_set == 0) { 4537c478bd9Sstevel@tonic-gate start = sgp->sg_phdr.p_vaddr; 4547c478bd9Sstevel@tonic-gate /* LINTED */ 4557c478bd9Sstevel@tonic-gate start_ndx = elf_ndxscn(osp->os_scn); 4567c478bd9Sstevel@tonic-gate start_set++; 4577c478bd9Sstevel@tonic-gate } 458c1c6f601Srie 459c1c6f601Srie /* 460c1c6f601Srie * While we're here, determine whether a .init or .fini 461c1c6f601Srie * section exist. 462c1c6f601Srie */ 46357ef7aa9SRod Evans if ((iosp == NULL) && (strcmp(osp->os_name, 464c1c6f601Srie MSG_ORIG(MSG_SCN_INIT)) == 0)) 465c1c6f601Srie iosp = osp; 46657ef7aa9SRod Evans if ((fosp == NULL) && (strcmp(osp->os_name, 467c1c6f601Srie MSG_ORIG(MSG_SCN_FINI)) == 0)) 468c1c6f601Srie fosp = osp; 4697c478bd9Sstevel@tonic-gate } 4707c478bd9Sstevel@tonic-gate } 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate /* 4737c478bd9Sstevel@tonic-gate * Add local register symbols to the .dynsym. These are required as 4747c478bd9Sstevel@tonic-gate * DT_REGISTER .dynamic entries must have a symbol to reference. 4757c478bd9Sstevel@tonic-gate */ 4767c478bd9Sstevel@tonic-gate if (ofl->ofl_regsyms && dynsym) { 4777c478bd9Sstevel@tonic-gate int ndx; 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate for (ndx = 0; ndx < ofl->ofl_regsymsno; ndx++) { 48057ef7aa9SRod Evans Sym_desc *rsdp; 4817c478bd9Sstevel@tonic-gate 48257ef7aa9SRod Evans if ((rsdp = ofl->ofl_regsyms[ndx]) == NULL) 4837c478bd9Sstevel@tonic-gate continue; 4847c478bd9Sstevel@tonic-gate 48560758829Srie if (((rsdp->sd_flags1 & FLG_SY1_HIDDEN) == 0) && 4867c478bd9Sstevel@tonic-gate (ELF_ST_BIND(rsdp->sd_sym->st_info) != STB_LOCAL)) 4877c478bd9Sstevel@tonic-gate continue; 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx] = *(rsdp->sd_sym); 4907c478bd9Sstevel@tonic-gate rsdp->sd_symndx = *symndx; 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate if (dynsym[dynsym_ndx].st_name) { 4937c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, rsdp->sd_name, 4947c478bd9Sstevel@tonic-gate &stoff); 4957c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx].st_name = stoff; 4967c478bd9Sstevel@tonic-gate } 4977c478bd9Sstevel@tonic-gate dynsym_ndx++; 4987c478bd9Sstevel@tonic-gate } 4997c478bd9Sstevel@tonic-gate } 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate /* 5027c478bd9Sstevel@tonic-gate * Having traversed all the output segments, warn the user if the 5037c478bd9Sstevel@tonic-gate * traditional text or data segments don't exist. Otherwise from these 5047c478bd9Sstevel@tonic-gate * segments establish the values for `etext', `edata', `end', `END', 5057c478bd9Sstevel@tonic-gate * and `START'. 5067c478bd9Sstevel@tonic-gate */ 5077c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_RELOBJ)) { 50857ef7aa9SRod Evans Sg_desc *sgp; 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate if (tsgp) 5117c478bd9Sstevel@tonic-gate etext = tsgp->sg_phdr.p_vaddr + tsgp->sg_phdr.p_filesz; 5127c478bd9Sstevel@tonic-gate else { 5137c478bd9Sstevel@tonic-gate etext = (Addr)0; 5147c478bd9Sstevel@tonic-gate etext_ndx = SHN_ABS; 5157c478bd9Sstevel@tonic-gate etext_abs = 1; 5161d9df23bSab if (flags & FLG_OF_VERBOSE) 5175aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 5187c478bd9Sstevel@tonic-gate MSG_INTL(MSG_UPD_NOREADSEG)); 5197c478bd9Sstevel@tonic-gate } 5207c478bd9Sstevel@tonic-gate if (dsgp) { 5217c478bd9Sstevel@tonic-gate edata = dsgp->sg_phdr.p_vaddr + dsgp->sg_phdr.p_filesz; 5227c478bd9Sstevel@tonic-gate } else { 5237c478bd9Sstevel@tonic-gate edata = (Addr)0; 5247c478bd9Sstevel@tonic-gate edata_ndx = SHN_ABS; 5257c478bd9Sstevel@tonic-gate edata_abs = 1; 5261d9df23bSab if (flags & FLG_OF_VERBOSE) 5275aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 5287c478bd9Sstevel@tonic-gate MSG_INTL(MSG_UPD_NORDWRSEG)); 5297c478bd9Sstevel@tonic-gate } 5307c478bd9Sstevel@tonic-gate 53157ef7aa9SRod Evans if (dsgp == NULL) { 5327c478bd9Sstevel@tonic-gate if (tsgp) 5337c478bd9Sstevel@tonic-gate sgp = tsgp; 5347c478bd9Sstevel@tonic-gate else 5357c478bd9Sstevel@tonic-gate sgp = 0; 53657ef7aa9SRod Evans } else if (tsgp == NULL) 5377c478bd9Sstevel@tonic-gate sgp = dsgp; 5387c478bd9Sstevel@tonic-gate else if (dsgp->sg_phdr.p_vaddr > tsgp->sg_phdr.p_vaddr) 5397c478bd9Sstevel@tonic-gate sgp = dsgp; 5407c478bd9Sstevel@tonic-gate else if (dsgp->sg_phdr.p_vaddr < tsgp->sg_phdr.p_vaddr) 5417c478bd9Sstevel@tonic-gate sgp = tsgp; 5427c478bd9Sstevel@tonic-gate else { 5437c478bd9Sstevel@tonic-gate /* 5447c478bd9Sstevel@tonic-gate * One of the segments must be of zero size. 5457c478bd9Sstevel@tonic-gate */ 5467c478bd9Sstevel@tonic-gate if (tsgp->sg_phdr.p_memsz) 5477c478bd9Sstevel@tonic-gate sgp = tsgp; 5487c478bd9Sstevel@tonic-gate else 5497c478bd9Sstevel@tonic-gate sgp = dsgp; 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate if (esgp && (esgp->sg_phdr.p_vaddr > sgp->sg_phdr.p_vaddr)) 5537c478bd9Sstevel@tonic-gate sgp = esgp; 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate if (sgp) { 5567c478bd9Sstevel@tonic-gate end = sgp->sg_phdr.p_vaddr + sgp->sg_phdr.p_memsz; 5577c478bd9Sstevel@tonic-gate 558fdf855a7Sseizo /* 559fdf855a7Sseizo * If the last loadable segment is a read-only segment, 560fdf855a7Sseizo * then the application which uses the symbol _end to 561fdf855a7Sseizo * find the beginning of writable heap area may cause 562fdf855a7Sseizo * segmentation violation. We adjust the value of the 563fdf855a7Sseizo * _end to skip to the next page boundary. 564fdf855a7Sseizo * 565fdf855a7Sseizo * 6401812 System interface which returs beginning 566fdf855a7Sseizo * heap would be nice. 567fdf855a7Sseizo * When the above RFE is implemented, the changes below 568fdf855a7Sseizo * could be changed in a better way. 569fdf855a7Sseizo */ 570fdf855a7Sseizo if ((sgp->sg_phdr.p_flags & PF_W) == 0) 57160758829Srie end = (Addr)S_ROUND(end, sysconf(_SC_PAGESIZE)); 572fdf855a7Sseizo 5737c478bd9Sstevel@tonic-gate /* 5747c478bd9Sstevel@tonic-gate * If we're dealing with a memory reservation there are 5757c478bd9Sstevel@tonic-gate * no sections to establish an index for _end, so assign 5767c478bd9Sstevel@tonic-gate * it as an absolute. 5777c478bd9Sstevel@tonic-gate */ 5780bc07c75Srie if (sgp->sg_osdescs != NULL) { 5790bc07c75Srie /* 5800bc07c75Srie * Determine the last section for this segment. 5810bc07c75Srie */ 582cce0e03bSab Os_desc *osp = sgp->sg_osdescs->apl_data 583cce0e03bSab [sgp->sg_osdescs->apl_nitems - 1]; 584cce0e03bSab 5850bc07c75Srie /* LINTED */ 586cce0e03bSab end_ndx = elf_ndxscn(osp->os_scn); 5877c478bd9Sstevel@tonic-gate } else { 5887c478bd9Sstevel@tonic-gate end_ndx = SHN_ABS; 5897c478bd9Sstevel@tonic-gate end_abs = 1; 5907c478bd9Sstevel@tonic-gate } 5917c478bd9Sstevel@tonic-gate } else { 5927c478bd9Sstevel@tonic-gate end = (Addr) 0; 5937c478bd9Sstevel@tonic-gate end_ndx = SHN_ABS; 5947c478bd9Sstevel@tonic-gate end_abs = 1; 5955aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 5965aefb655Srie MSG_INTL(MSG_UPD_NOSEG)); 5977c478bd9Sstevel@tonic-gate } 5987c478bd9Sstevel@tonic-gate } 5997c478bd9Sstevel@tonic-gate 6005aefb655Srie DBG_CALL(Dbg_syms_up_title(ofl->ofl_lml)); 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate /* 6037c478bd9Sstevel@tonic-gate * Initialize the scoped symbol table entry point. This is for all 6047c478bd9Sstevel@tonic-gate * the global symbols that have been scoped to locals and will be 6057c478bd9Sstevel@tonic-gate * filled in during global symbol processing so that we don't have 6067c478bd9Sstevel@tonic-gate * to traverse the globals symbol hash array more than once. 6077c478bd9Sstevel@tonic-gate */ 6087c478bd9Sstevel@tonic-gate if (symtab) { 609ca4eed8bSAli Bahrami scopesym_bndx = symtab_ndx; 610ca4eed8bSAli Bahrami scopesym_ndx = scopesym_bndx; 6117c478bd9Sstevel@tonic-gate symtab_ndx += ofl->ofl_scopecnt; 6127c478bd9Sstevel@tonic-gate } 6137c478bd9Sstevel@tonic-gate 6147c478bd9Sstevel@tonic-gate /* 61535450702SAli Bahrami * If expanding partially expanded symbols under '-z nopartial', 61635450702SAli Bahrami * prepare to do that. 6177c478bd9Sstevel@tonic-gate */ 61835450702SAli Bahrami if (ofl->ofl_isparexpn) { 61935450702SAli Bahrami osp = ofl->ofl_isparexpn->is_osdesc; 620b26cc8daSAli Bahrami parexpnbase = parexpnaddr = (Addr)(osp->os_shdr->sh_addr + 62135450702SAli Bahrami ofl->ofl_isparexpn->is_indata->d_off); 6227c478bd9Sstevel@tonic-gate /* LINTED */ 62335450702SAli Bahrami parexpnndx = elf_ndxscn(osp->os_scn); 62457ef7aa9SRod Evans ofl->ofl_parexpnndx = osp->os_identndx; 6257c478bd9Sstevel@tonic-gate } 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate /* 6287c478bd9Sstevel@tonic-gate * If we are generating a .symtab collect all the local symbols, 6297c478bd9Sstevel@tonic-gate * assigning a new virtual address or displacement (value). 6307c478bd9Sstevel@tonic-gate */ 63157ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_objs, idx1, ifl)) { 63257ef7aa9SRod Evans Xword lndx, local; 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate /* 6357c478bd9Sstevel@tonic-gate * Check that we have local symbols to process. If the user 6367c478bd9Sstevel@tonic-gate * has indicated scoping then scan the global symbols also 6377c478bd9Sstevel@tonic-gate * looking for entries from this file to reduce to locals. 6387c478bd9Sstevel@tonic-gate */ 6397c478bd9Sstevel@tonic-gate if ((local = ifl->ifl_locscnt) == 0) 6407c478bd9Sstevel@tonic-gate continue; 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate for (lndx = 1; lndx < local; lndx++) { 6437c478bd9Sstevel@tonic-gate Gotndx *gnp; 644d579eb63Sab uchar_t type; 6457c478bd9Sstevel@tonic-gate Word *_symshndx; 6469039eeafSab int enter_in_symtab, enter_in_ldynsym; 6479039eeafSab int update_done; 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate sdp = ifl->ifl_oldndx[lndx]; 6507c478bd9Sstevel@tonic-gate sym = sdp->sd_sym; 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate /* 6537c478bd9Sstevel@tonic-gate * Assign a got offset if necessary. 6547c478bd9Sstevel@tonic-gate */ 655ba2be530Sab if ((ld_targ.t_mr.mr_assign_got != NULL) && 656ba2be530Sab (*ld_targ.t_mr.mr_assign_got)(ofl, sdp) == S_ERROR) 6577c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 658ba2be530Sab 6595aefb655Srie if (DBG_ENABLED) { 66057ef7aa9SRod Evans Aliste idx2; 66157ef7aa9SRod Evans 66257ef7aa9SRod Evans for (ALIST_TRAVERSE(sdp->sd_GOTndxs, 66357ef7aa9SRod Evans idx2, gnp)) { 664d840867fSab gottable->gt_sym = sdp; 665d840867fSab gottable->gt_gndx.gn_gotndx = 666d840867fSab gnp->gn_gotndx; 667d840867fSab gottable->gt_gndx.gn_addend = 668d840867fSab gnp->gn_addend; 669d840867fSab gottable++; 670d840867fSab } 6717c478bd9Sstevel@tonic-gate } 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate if ((type = ELF_ST_TYPE(sym->st_info)) == STT_SECTION) 6747c478bd9Sstevel@tonic-gate continue; 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate /* 6777c478bd9Sstevel@tonic-gate * Ignore any symbols that have been marked as invalid 6787c478bd9Sstevel@tonic-gate * during input processing. Providing these aren't used 6797c478bd9Sstevel@tonic-gate * for relocation they'll just be dropped from the 6807c478bd9Sstevel@tonic-gate * output image. 6817c478bd9Sstevel@tonic-gate */ 6827c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_INVALID) 6837c478bd9Sstevel@tonic-gate continue; 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate /* 6867c478bd9Sstevel@tonic-gate * If the section that this symbol was associated 6877c478bd9Sstevel@tonic-gate * with has been discarded - then we discard 6887c478bd9Sstevel@tonic-gate * the local symbol along with it. 6897c478bd9Sstevel@tonic-gate */ 6907c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_ISDISC) 6917c478bd9Sstevel@tonic-gate continue; 6927c478bd9Sstevel@tonic-gate 693ca4eed8bSAli Bahrami /* 694ca4eed8bSAli Bahrami * If this symbol is from a different file 695ca4eed8bSAli Bahrami * than the input descriptor we are processing, 696ca4eed8bSAli Bahrami * treat it as if it has FLG_SY_ISDISC set. 697ca4eed8bSAli Bahrami * This happens when sloppy_comdat_reloc() 698ca4eed8bSAli Bahrami * replaces a symbol to a discarded comdat section 699ca4eed8bSAli Bahrami * with an equivalent symbol from a different 700ca4eed8bSAli Bahrami * file. We only want to enter such a symbol 701ca4eed8bSAli Bahrami * once --- as part of the file that actually 702ca4eed8bSAli Bahrami * supplies it. 703ca4eed8bSAli Bahrami */ 704ca4eed8bSAli Bahrami if (ifl != sdp->sd_file) 705ca4eed8bSAli Bahrami continue; 706ca4eed8bSAli Bahrami 707ca4eed8bSAli Bahrami 7087c478bd9Sstevel@tonic-gate /* 7097c478bd9Sstevel@tonic-gate * Generate an output symbol to represent this input 7107c478bd9Sstevel@tonic-gate * symbol. Even if the symbol table is to be stripped 7117c478bd9Sstevel@tonic-gate * we still need to update any local symbols that are 7127c478bd9Sstevel@tonic-gate * used during relocation. 7137c478bd9Sstevel@tonic-gate */ 7149039eeafSab enter_in_symtab = symtab && 71544bac77bSrie (!(ofl->ofl_flags & FLG_OF_REDLSYM) || 71657ef7aa9SRod Evans sdp->sd_move); 7179039eeafSab enter_in_ldynsym = ldynsym && sdp->sd_name && 718d579eb63Sab ldynsym_symtype[type] && 71944bac77bSrie !(ofl->ofl_flags & FLG_OF_REDLSYM); 72057ef7aa9SRod Evans _symshndx = NULL; 72157ef7aa9SRod Evans 7229039eeafSab if (enter_in_symtab) { 7237c478bd9Sstevel@tonic-gate if (!dynsym) 7247c478bd9Sstevel@tonic-gate sdp->sd_symndx = *symndx; 7257c478bd9Sstevel@tonic-gate symtab[symtab_ndx] = *sym; 7267c478bd9Sstevel@tonic-gate /* 7277c478bd9Sstevel@tonic-gate * Provided this isn't an unnamed register 7287c478bd9Sstevel@tonic-gate * symbol, update its name. 7297c478bd9Sstevel@tonic-gate */ 7307c478bd9Sstevel@tonic-gate if (((sdp->sd_flags & FLG_SY_REGSYM) == 0) || 7317c478bd9Sstevel@tonic-gate symtab[symtab_ndx].st_name) { 7327c478bd9Sstevel@tonic-gate (void) st_setstring(strtab, 7337c478bd9Sstevel@tonic-gate sdp->sd_name, &stoff); 7347c478bd9Sstevel@tonic-gate symtab[symtab_ndx].st_name = stoff; 7357c478bd9Sstevel@tonic-gate } 7367c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_CLEAN; 7377c478bd9Sstevel@tonic-gate if (symshndx) 7387c478bd9Sstevel@tonic-gate _symshndx = &symshndx[symtab_ndx]; 7397c478bd9Sstevel@tonic-gate sdp->sd_sym = sym = &symtab[symtab_ndx++]; 7407c478bd9Sstevel@tonic-gate 7417c478bd9Sstevel@tonic-gate if ((sdp->sd_flags & FLG_SY_SPECSEC) && 7429039eeafSab (sym->st_shndx == SHN_ABS) && 7439039eeafSab !enter_in_ldynsym) 7447c478bd9Sstevel@tonic-gate continue; 7459039eeafSab } else if (enter_in_ldynsym) { 7469039eeafSab /* 7479039eeafSab * Not using symtab, but we do have ldynsym 7489039eeafSab * available. 7499039eeafSab */ 7509039eeafSab ldynsym[ldynsym_ndx] = *sym; 7519039eeafSab (void) st_setstring(dynstr, sdp->sd_name, 752d840867fSab &stoff); 7539039eeafSab ldynsym[ldynsym_ndx].st_name = stoff; 7549039eeafSab 7559039eeafSab sdp->sd_flags &= ~FLG_SY_CLEAN; 7569039eeafSab if (ldynshndx) 7579039eeafSab _symshndx = &ldynshndx[ldynsym_ndx]; 758d579eb63Sab sdp->sd_sym = sym = &ldynsym[ldynsym_ndx]; 759d579eb63Sab /* Add it to sort section if it qualifies */ 760d579eb63Sab ADD_TO_DYNSORT(sdp, sym, type, ldynsym_ndx); 761d579eb63Sab ldynsym_ndx++; 7629039eeafSab } else { /* Not using symtab or ldynsym */ 7637c478bd9Sstevel@tonic-gate /* 7647c478bd9Sstevel@tonic-gate * If this symbol requires modifying to provide 7657c478bd9Sstevel@tonic-gate * for a relocation or move table update, make 7667c478bd9Sstevel@tonic-gate * a copy of it. 7677c478bd9Sstevel@tonic-gate */ 7687c478bd9Sstevel@tonic-gate if (!(sdp->sd_flags & FLG_SY_UPREQD) && 76957ef7aa9SRod Evans !(sdp->sd_move)) 7707c478bd9Sstevel@tonic-gate continue; 7717c478bd9Sstevel@tonic-gate if ((sdp->sd_flags & FLG_SY_SPECSEC) && 7727c478bd9Sstevel@tonic-gate (sym->st_shndx == SHN_ABS)) 7737c478bd9Sstevel@tonic-gate continue; 7747c478bd9Sstevel@tonic-gate 7755aefb655Srie if (ld_sym_copy(sdp) == S_ERROR) 7767c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 7777c478bd9Sstevel@tonic-gate sym = sdp->sd_sym; 7787c478bd9Sstevel@tonic-gate } 7797c478bd9Sstevel@tonic-gate 7807c478bd9Sstevel@tonic-gate /* 7817c478bd9Sstevel@tonic-gate * Update the symbols contents if necessary. 7827c478bd9Sstevel@tonic-gate */ 7839039eeafSab update_done = 0; 7847c478bd9Sstevel@tonic-gate if (type == STT_FILE) { 7857c478bd9Sstevel@tonic-gate sdp->sd_shndx = sym->st_shndx = SHN_ABS; 7867c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_SPECSEC; 7879039eeafSab update_done = 1; 7887c478bd9Sstevel@tonic-gate } 7897c478bd9Sstevel@tonic-gate 7907c478bd9Sstevel@tonic-gate /* 7917c478bd9Sstevel@tonic-gate * If we are expanding the locally bound partially 7927c478bd9Sstevel@tonic-gate * initialized symbols, then update the address here. 7937c478bd9Sstevel@tonic-gate */ 79435450702SAli Bahrami if (ofl->ofl_isparexpn && 7959039eeafSab (sdp->sd_flags & FLG_SY_PAREXPN) && !update_done) { 79635450702SAli Bahrami sym->st_shndx = parexpnndx; 79735450702SAli Bahrami sdp->sd_isc = ofl->ofl_isparexpn; 798b26cc8daSAli Bahrami sym->st_value = parexpnaddr; 79935450702SAli Bahrami parexpnaddr += sym->st_size; 800b26cc8daSAli Bahrami if ((flags & FLG_OF_RELOBJ) == 0) 801b26cc8daSAli Bahrami sym->st_value -= parexpnbase; 8027c478bd9Sstevel@tonic-gate } 8037c478bd9Sstevel@tonic-gate 8047c478bd9Sstevel@tonic-gate /* 8057c478bd9Sstevel@tonic-gate * If this isn't an UNDEF symbol (ie. an input section 8067c478bd9Sstevel@tonic-gate * is associated), update the symbols value and index. 8077c478bd9Sstevel@tonic-gate */ 8089039eeafSab if (((isc = sdp->sd_isc) != 0) && !update_done) { 8097c478bd9Sstevel@tonic-gate Word sectndx; 8107c478bd9Sstevel@tonic-gate 8117c478bd9Sstevel@tonic-gate osp = isc->is_osdesc; 8127c478bd9Sstevel@tonic-gate /* LINTED */ 8137c478bd9Sstevel@tonic-gate sym->st_value += 8147c478bd9Sstevel@tonic-gate (Off)_elf_getxoff(isc->is_indata); 8157c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_RELOBJ)) { 8167c478bd9Sstevel@tonic-gate sym->st_value += osp->os_shdr->sh_addr; 8177c478bd9Sstevel@tonic-gate /* 8187c478bd9Sstevel@tonic-gate * TLS symbols are relative to 8197c478bd9Sstevel@tonic-gate * the TLS segment. 8207c478bd9Sstevel@tonic-gate */ 821d579eb63Sab if ((type == STT_TLS) && 822d579eb63Sab (ofl->ofl_tlsphdr)) { 8237c478bd9Sstevel@tonic-gate sym->st_value -= 8247c478bd9Sstevel@tonic-gate ofl->ofl_tlsphdr->p_vaddr; 8259039eeafSab } 8267c478bd9Sstevel@tonic-gate } 8277c478bd9Sstevel@tonic-gate /* LINTED */ 8287c478bd9Sstevel@tonic-gate if ((sdp->sd_shndx = sectndx = 8297c478bd9Sstevel@tonic-gate elf_ndxscn(osp->os_scn)) >= SHN_LORESERVE) { 8307c478bd9Sstevel@tonic-gate if (_symshndx) { 8317c478bd9Sstevel@tonic-gate *_symshndx = sectndx; 8327c478bd9Sstevel@tonic-gate } 8337c478bd9Sstevel@tonic-gate sym->st_shndx = SHN_XINDEX; 8347c478bd9Sstevel@tonic-gate } else { 8357c478bd9Sstevel@tonic-gate /* LINTED */ 8367c478bd9Sstevel@tonic-gate sym->st_shndx = sectndx; 8377c478bd9Sstevel@tonic-gate } 8387c478bd9Sstevel@tonic-gate } 8399039eeafSab 8409039eeafSab /* 8419039eeafSab * If entering the symbol in both the symtab and the 8429039eeafSab * ldynsym, then the one in symtab needs to be 8439039eeafSab * copied to ldynsym. If it is only in the ldynsym, 8449039eeafSab * then the code above already set it up and we have 8459039eeafSab * nothing more to do here. 8469039eeafSab */ 8479039eeafSab if (enter_in_symtab && enter_in_ldynsym) { 8489039eeafSab ldynsym[ldynsym_ndx] = *sym; 8499039eeafSab (void) st_setstring(dynstr, sdp->sd_name, 850d840867fSab &stoff); 8519039eeafSab ldynsym[ldynsym_ndx].st_name = stoff; 8529039eeafSab 8539039eeafSab if (_symshndx && ldynshndx) 8549039eeafSab ldynshndx[ldynsym_ndx] = *_symshndx; 8559039eeafSab 856d579eb63Sab /* Add it to sort section if it qualifies */ 857d579eb63Sab ADD_TO_DYNSORT(sdp, sym, type, ldynsym_ndx); 858d579eb63Sab 8599039eeafSab ldynsym_ndx++; 8609039eeafSab } 8617c478bd9Sstevel@tonic-gate } 8627c478bd9Sstevel@tonic-gate } 863ca4eed8bSAli Bahrami symtab_gbl_bndx = symtab_ndx; /* .symtab index of 1st global entry */ 8647c478bd9Sstevel@tonic-gate 8657c478bd9Sstevel@tonic-gate /* 8667c478bd9Sstevel@tonic-gate * Two special symbols are `_init' and `_fini'. If these are supplied 8677c478bd9Sstevel@tonic-gate * by crti.o then they are used to represent the total concatenation of 868c1c6f601Srie * the `.init' and `.fini' sections. 869c1c6f601Srie * 870c1c6f601Srie * First, determine whether any .init or .fini sections exist. If these 871c1c6f601Srie * sections exist when a dynamic object is being built, but no `_init' 872c1c6f601Srie * or `_fini' symbols are found, then the user is probably building this 873c1c6f601Srie * object directly from ld(1) rather than using a compiler driver that 874c1c6f601Srie * provides the symbols via crt's. 875c1c6f601Srie * 876c1c6f601Srie * If the .init or .fini section exist, and their associated symbols, 877c1c6f601Srie * determine the size of the sections and updated the symbols value 878c1c6f601Srie * accordingly. 8797c478bd9Sstevel@tonic-gate */ 8805aefb655Srie if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_INIT_U), SYM_NOHASH, 0, 8817c478bd9Sstevel@tonic-gate ofl)) != NULL) && (sdp->sd_ref == REF_REL_NEED) && sdp->sd_isc && 882c1c6f601Srie (sdp->sd_isc->is_osdesc == iosp)) { 8835aefb655Srie if (ld_sym_copy(sdp) == S_ERROR) 8847c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 88560758829Srie sdp->sd_sym->st_size = sdp->sd_isc->is_osdesc->os_shdr->sh_size; 88660758829Srie 887c1c6f601Srie } else if (iosp && !(flags & FLG_OF_RELOBJ)) { 888c1c6f601Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_SYM_NOCRT), 889c1c6f601Srie MSG_ORIG(MSG_SYM_INIT_U), MSG_ORIG(MSG_SCN_INIT)); 8907c478bd9Sstevel@tonic-gate } 891c1c6f601Srie 8925aefb655Srie if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_FINI_U), SYM_NOHASH, 0, 8937c478bd9Sstevel@tonic-gate ofl)) != NULL) && (sdp->sd_ref == REF_REL_NEED) && sdp->sd_isc && 894c1c6f601Srie (sdp->sd_isc->is_osdesc == fosp)) { 8955aefb655Srie if (ld_sym_copy(sdp) == S_ERROR) 8967c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 89760758829Srie sdp->sd_sym->st_size = sdp->sd_isc->is_osdesc->os_shdr->sh_size; 89860758829Srie 899c1c6f601Srie } else if (fosp && !(flags & FLG_OF_RELOBJ)) { 900c1c6f601Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_SYM_NOCRT), 901c1c6f601Srie MSG_ORIG(MSG_SYM_FINI_U), MSG_ORIG(MSG_SCN_FINI)); 9027c478bd9Sstevel@tonic-gate } 9037c478bd9Sstevel@tonic-gate 9047c478bd9Sstevel@tonic-gate /* 9057c478bd9Sstevel@tonic-gate * Assign .bss information for use with updating COMMON symbols. 9067c478bd9Sstevel@tonic-gate */ 9077c478bd9Sstevel@tonic-gate if (ofl->ofl_isbss) { 90857ef7aa9SRod Evans isc = ofl->ofl_isbss; 90957ef7aa9SRod Evans osp = isc->is_osdesc; 9107c478bd9Sstevel@tonic-gate 9117c478bd9Sstevel@tonic-gate bssaddr = osp->os_shdr->sh_addr + 91257ef7aa9SRod Evans (Off)_elf_getxoff(isc->is_indata); 9137c478bd9Sstevel@tonic-gate /* LINTED */ 9147c478bd9Sstevel@tonic-gate bssndx = elf_ndxscn(osp->os_scn); 9157c478bd9Sstevel@tonic-gate } 9167c478bd9Sstevel@tonic-gate 917ba2be530Sab #if defined(_ELF64) 91854d82594Sseizo /* 919ba2be530Sab * For amd64 target, assign .lbss information for use 920ba2be530Sab * with updating LCOMMON symbols. 92154d82594Sseizo */ 922ba2be530Sab if ((ld_targ.t_m.m_mach == EM_AMD64) && ofl->ofl_islbss) { 92354d82594Sseizo osp = ofl->ofl_islbss->is_osdesc; 92454d82594Sseizo 92554d82594Sseizo lbssaddr = osp->os_shdr->sh_addr + 926d840867fSab (Off)_elf_getxoff(ofl->ofl_islbss->is_indata); 92754d82594Sseizo /* LINTED */ 92854d82594Sseizo lbssndx = elf_ndxscn(osp->os_scn); 92954d82594Sseizo } 93054d82594Sseizo #endif 93154d82594Sseizo 9327c478bd9Sstevel@tonic-gate /* 9337c478bd9Sstevel@tonic-gate * Assign .tlsbss information for use with updating COMMON symbols. 9347c478bd9Sstevel@tonic-gate */ 9357c478bd9Sstevel@tonic-gate if (ofl->ofl_istlsbss) { 9367c478bd9Sstevel@tonic-gate osp = ofl->ofl_istlsbss->is_osdesc; 9377c478bd9Sstevel@tonic-gate tlsbssaddr = osp->os_shdr->sh_addr + 938d840867fSab (Off)_elf_getxoff(ofl->ofl_istlsbss->is_indata); 9397c478bd9Sstevel@tonic-gate /* LINTED */ 9407c478bd9Sstevel@tonic-gate tlsbssndx = elf_ndxscn(osp->os_scn); 9417c478bd9Sstevel@tonic-gate } 9427c478bd9Sstevel@tonic-gate 9437c478bd9Sstevel@tonic-gate if ((sorted_syms = libld_calloc(ofl->ofl_globcnt + 94457ef7aa9SRod Evans ofl->ofl_elimcnt + ofl->ofl_scopecnt, 94557ef7aa9SRod Evans sizeof (*sorted_syms))) == NULL) 9467c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 9477c478bd9Sstevel@tonic-gate 9487c478bd9Sstevel@tonic-gate scndx = 0; 9497c478bd9Sstevel@tonic-gate ssndx = ofl->ofl_scopecnt + ofl->ofl_elimcnt; 9507c478bd9Sstevel@tonic-gate 9517c478bd9Sstevel@tonic-gate /* 952*28bda19cSRod Evans * Traverse the internal symbol table updating global symbol information 953*28bda19cSRod Evans * and allocating common. 9547c478bd9Sstevel@tonic-gate */ 9557c478bd9Sstevel@tonic-gate for (sav = avl_first(&ofl->ofl_symavl); sav; 9567c478bd9Sstevel@tonic-gate sav = AVL_NEXT(&ofl->ofl_symavl, sav)) { 95757ef7aa9SRod Evans Sym *symptr; 9587c478bd9Sstevel@tonic-gate int local; 95954d82594Sseizo int restore; 9607c478bd9Sstevel@tonic-gate 9617c478bd9Sstevel@tonic-gate sdp = sav->sav_symdesc; 9627c478bd9Sstevel@tonic-gate 9637c478bd9Sstevel@tonic-gate /* 96460758829Srie * Ignore any symbols that have been marked as invalid during 96560758829Srie * input processing. Providing these aren't used for 96660758829Srie * relocation, they will be dropped from the output image. 9677c478bd9Sstevel@tonic-gate */ 9687c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_INVALID) { 9695aefb655Srie DBG_CALL(Dbg_syms_old(ofl, sdp)); 9705aefb655Srie DBG_CALL(Dbg_syms_ignore(ofl, sdp)); 9717c478bd9Sstevel@tonic-gate continue; 9727c478bd9Sstevel@tonic-gate } 9737c478bd9Sstevel@tonic-gate 9747c478bd9Sstevel@tonic-gate /* 97560758829Srie * Only needed symbols are copied to the output symbol table. 9767c478bd9Sstevel@tonic-gate */ 9777c478bd9Sstevel@tonic-gate if (sdp->sd_ref == REF_DYN_SEEN) 9787c478bd9Sstevel@tonic-gate continue; 9797c478bd9Sstevel@tonic-gate 98060758829Srie if ((sdp->sd_flags1 & FLG_SY1_HIDDEN) && 9817c478bd9Sstevel@tonic-gate (flags & FLG_OF_PROCRED)) 9827c478bd9Sstevel@tonic-gate local = 1; 9837c478bd9Sstevel@tonic-gate else 9847c478bd9Sstevel@tonic-gate local = 0; 9857c478bd9Sstevel@tonic-gate 9867c478bd9Sstevel@tonic-gate if (local || (ofl->ofl_hashbkts == 0)) { 9877c478bd9Sstevel@tonic-gate sorted_syms[scndx++].sl_sdp = sdp; 9887c478bd9Sstevel@tonic-gate } else { 9897c478bd9Sstevel@tonic-gate sorted_syms[ssndx].sl_hval = sdp->sd_aux->sa_hash % 9907c478bd9Sstevel@tonic-gate ofl->ofl_hashbkts; 9917c478bd9Sstevel@tonic-gate sorted_syms[ssndx].sl_sdp = sdp; 9927c478bd9Sstevel@tonic-gate ssndx++; 9937c478bd9Sstevel@tonic-gate } 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate /* 996c1c6f601Srie * Note - expand the COMMON symbols here because an address 997c1c6f601Srie * must be assigned to them in the same order that space was 998c1c6f601Srie * calculated in sym_validate(). If this ordering isn't 999c1c6f601Srie * followed differing alignment requirements can throw us all 1000c1c6f601Srie * out of whack. 10017c478bd9Sstevel@tonic-gate * 1002c1c6f601Srie * The expanded .bss global symbol is handled here as well. 10037c478bd9Sstevel@tonic-gate * 1004c1c6f601Srie * The actual adding entries into the symbol table still occurs 1005c1c6f601Srie * below in hashbucket order. 10067c478bd9Sstevel@tonic-gate */ 10077c478bd9Sstevel@tonic-gate symptr = sdp->sd_sym; 100854d82594Sseizo restore = 0; 10097c478bd9Sstevel@tonic-gate if ((sdp->sd_flags & FLG_SY_PAREXPN) || 10107c478bd9Sstevel@tonic-gate ((sdp->sd_flags & FLG_SY_SPECSEC) && 10117c478bd9Sstevel@tonic-gate (sdp->sd_shndx = symptr->st_shndx) == SHN_COMMON)) { 10127c478bd9Sstevel@tonic-gate 10137c478bd9Sstevel@tonic-gate /* 101435450702SAli Bahrami * An expanded symbol goes to a special .data section 101535450702SAli Bahrami * prepared for that purpose (ofl->ofl_isparexpn). 1016c1c6f601Srie * Assign COMMON allocations to .bss. 10177c478bd9Sstevel@tonic-gate * Otherwise leave it as is. 10187c478bd9Sstevel@tonic-gate */ 10197c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_PAREXPN) { 10207c478bd9Sstevel@tonic-gate restore = 1; 102135450702SAli Bahrami sdp->sd_shndx = parexpnndx; 10227c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 10237c478bd9Sstevel@tonic-gate symptr->st_value = (Xword) S_ROUND( 102435450702SAli Bahrami parexpnaddr, symptr->st_value); 102535450702SAli Bahrami parexpnaddr = symptr->st_value + 1026d840867fSab symptr->st_size; 102735450702SAli Bahrami sdp->sd_isc = ofl->ofl_isparexpn; 10287c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_COMMEXP; 1029c1c6f601Srie 10307c478bd9Sstevel@tonic-gate } else if (ELF_ST_TYPE(symptr->st_info) != STT_TLS && 10317c478bd9Sstevel@tonic-gate (local || !(flags & FLG_OF_RELOBJ))) { 10327c478bd9Sstevel@tonic-gate restore = 1; 10337c478bd9Sstevel@tonic-gate sdp->sd_shndx = bssndx; 10347c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 103560758829Srie symptr->st_value = (Xword)S_ROUND(bssaddr, 1036d840867fSab symptr->st_value); 10377c478bd9Sstevel@tonic-gate bssaddr = symptr->st_value + symptr->st_size; 10387c478bd9Sstevel@tonic-gate sdp->sd_isc = ofl->ofl_isbss; 10397c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_COMMEXP; 1040c1c6f601Srie 10417c478bd9Sstevel@tonic-gate } else if (ELF_ST_TYPE(symptr->st_info) == STT_TLS && 10427c478bd9Sstevel@tonic-gate (local || !(flags & FLG_OF_RELOBJ))) { 10437c478bd9Sstevel@tonic-gate restore = 1; 10447c478bd9Sstevel@tonic-gate sdp->sd_shndx = tlsbssndx; 10457c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 10467c478bd9Sstevel@tonic-gate symptr->st_value = (Xword)S_ROUND(tlsbssaddr, 1047d840867fSab symptr->st_value); 10487c478bd9Sstevel@tonic-gate tlsbssaddr = symptr->st_value + symptr->st_size; 10497c478bd9Sstevel@tonic-gate sdp->sd_isc = ofl->ofl_istlsbss; 10507c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_COMMEXP; 10517c478bd9Sstevel@tonic-gate /* 1052dd94ecefSrie * TLS symbols are relative to the TLS segment. 10537c478bd9Sstevel@tonic-gate */ 10547c478bd9Sstevel@tonic-gate symptr->st_value -= ofl->ofl_tlsphdr->p_vaddr; 10557c478bd9Sstevel@tonic-gate } 1056ba2be530Sab #if defined(_ELF64) 1057ba2be530Sab } else if ((ld_targ.t_m.m_mach == EM_AMD64) && 1058ba2be530Sab (sdp->sd_flags & FLG_SY_SPECSEC) && 105954d82594Sseizo ((sdp->sd_shndx = symptr->st_shndx) == 106054d82594Sseizo SHN_X86_64_LCOMMON) && 106154d82594Sseizo ((local || !(flags & FLG_OF_RELOBJ)))) { 106254d82594Sseizo restore = 1; 106354d82594Sseizo sdp->sd_shndx = lbssndx; 106454d82594Sseizo sdp->sd_flags &= ~FLG_SY_SPECSEC; 106560758829Srie symptr->st_value = (Xword)S_ROUND(lbssaddr, 1066d840867fSab symptr->st_value); 106754d82594Sseizo lbssaddr = symptr->st_value + symptr->st_size; 106854d82594Sseizo sdp->sd_isc = ofl->ofl_islbss; 106954d82594Sseizo sdp->sd_flags |= FLG_SY_COMMEXP; 107054d82594Sseizo #endif 107154d82594Sseizo } 10727c478bd9Sstevel@tonic-gate 107354d82594Sseizo if (restore != 0) { 1074d579eb63Sab uchar_t type, bind; 1075c1c6f601Srie 107654d82594Sseizo /* 1077c1c6f601Srie * Make sure this COMMON symbol is returned to the same 1078c1c6f601Srie * binding as was defined in the original relocatable 107954d82594Sseizo * object reference. 108054d82594Sseizo */ 108154d82594Sseizo type = ELF_ST_TYPE(symptr->st_info); 108254d82594Sseizo if (sdp->sd_flags & FLG_SY_GLOBREF) 108354d82594Sseizo bind = STB_GLOBAL; 108454d82594Sseizo else 108554d82594Sseizo bind = STB_WEAK; 10867c478bd9Sstevel@tonic-gate 108754d82594Sseizo symptr->st_info = ELF_ST_INFO(bind, type); 10887c478bd9Sstevel@tonic-gate } 10897c478bd9Sstevel@tonic-gate } 10907c478bd9Sstevel@tonic-gate 10917c478bd9Sstevel@tonic-gate if (ofl->ofl_hashbkts) { 10927c478bd9Sstevel@tonic-gate qsort(sorted_syms + ofl->ofl_scopecnt + ofl->ofl_elimcnt, 10937c478bd9Sstevel@tonic-gate ofl->ofl_globcnt, sizeof (Sym_s_list), 10947c478bd9Sstevel@tonic-gate (int (*)(const void *, const void *))sym_hash_compare); 10957c478bd9Sstevel@tonic-gate } 10967c478bd9Sstevel@tonic-gate 10977c478bd9Sstevel@tonic-gate for (ssndx = 0; ssndx < (ofl->ofl_elimcnt + ofl->ofl_scopecnt + 10987c478bd9Sstevel@tonic-gate ofl->ofl_globcnt); ssndx++) { 10997c478bd9Sstevel@tonic-gate const char *name; 11007c478bd9Sstevel@tonic-gate Sym *sym; 11017c478bd9Sstevel@tonic-gate Sym_aux *sap; 11027c478bd9Sstevel@tonic-gate Half spec; 11039039eeafSab int local = 0, dynlocal = 0, enter_in_symtab; 11047c478bd9Sstevel@tonic-gate Gotndx *gnp; 11057c478bd9Sstevel@tonic-gate Word sectndx; 11067c478bd9Sstevel@tonic-gate 11077c478bd9Sstevel@tonic-gate sdp = sorted_syms[ssndx].sl_sdp; 11087c478bd9Sstevel@tonic-gate sectndx = 0; 11097c478bd9Sstevel@tonic-gate 11107c478bd9Sstevel@tonic-gate if (symtab) 11117c478bd9Sstevel@tonic-gate enter_in_symtab = 1; 11127c478bd9Sstevel@tonic-gate else 11137c478bd9Sstevel@tonic-gate enter_in_symtab = 0; 11147c478bd9Sstevel@tonic-gate 11157c478bd9Sstevel@tonic-gate /* 11167c478bd9Sstevel@tonic-gate * Assign a got offset if necessary. 11177c478bd9Sstevel@tonic-gate */ 1118ba2be530Sab if ((ld_targ.t_mr.mr_assign_got != NULL) && 1119ba2be530Sab (*ld_targ.t_mr.mr_assign_got)(ofl, sdp) == S_ERROR) 11207c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 1121c1c6f601Srie 11225aefb655Srie if (DBG_ENABLED) { 112357ef7aa9SRod Evans Aliste idx2; 112457ef7aa9SRod Evans 112557ef7aa9SRod Evans for (ALIST_TRAVERSE(sdp->sd_GOTndxs, idx2, gnp)) { 1126d326b23bSrie gottable->gt_sym = sdp; 1127d326b23bSrie gottable->gt_gndx.gn_gotndx = gnp->gn_gotndx; 1128d326b23bSrie gottable->gt_gndx.gn_addend = gnp->gn_addend; 1129d326b23bSrie gottable++; 11307c478bd9Sstevel@tonic-gate } 11317c478bd9Sstevel@tonic-gate 11327c478bd9Sstevel@tonic-gate if (sdp->sd_aux && sdp->sd_aux->sa_PLTGOTndx) { 1133d326b23bSrie gottable->gt_sym = sdp; 1134d326b23bSrie gottable->gt_gndx.gn_gotndx = 11357c478bd9Sstevel@tonic-gate sdp->sd_aux->sa_PLTGOTndx; 1136d326b23bSrie gottable++; 11377c478bd9Sstevel@tonic-gate } 11387c478bd9Sstevel@tonic-gate } 11397c478bd9Sstevel@tonic-gate 11407c478bd9Sstevel@tonic-gate 11417c478bd9Sstevel@tonic-gate /* 11427c478bd9Sstevel@tonic-gate * If this symbol has been marked as being reduced to local 11437c478bd9Sstevel@tonic-gate * scope then it will have to be placed in the scoped portion 11447c478bd9Sstevel@tonic-gate * of the .symtab. Retain the appropriate index for use in 11457c478bd9Sstevel@tonic-gate * version symbol indexing and relocation. 11467c478bd9Sstevel@tonic-gate */ 1147d4517e84Srie if ((sdp->sd_flags1 & FLG_SY1_HIDDEN) && 11487c478bd9Sstevel@tonic-gate (flags & FLG_OF_PROCRED)) { 11497c478bd9Sstevel@tonic-gate local = 1; 11507c478bd9Sstevel@tonic-gate if (!(sdp->sd_flags1 & FLG_SY1_ELIM) && !dynsym) 11517c478bd9Sstevel@tonic-gate sdp->sd_symndx = scopesym_ndx; 11527c478bd9Sstevel@tonic-gate else 11537c478bd9Sstevel@tonic-gate sdp->sd_symndx = 0; 11547c478bd9Sstevel@tonic-gate 11559039eeafSab if (sdp->sd_flags1 & FLG_SY1_ELIM) { 11567c478bd9Sstevel@tonic-gate enter_in_symtab = 0; 11579039eeafSab } else if (ldynsym && sdp->sd_sym->st_name && 1158d579eb63Sab ldynsym_symtype[ 1159d579eb63Sab ELF_ST_TYPE(sdp->sd_sym->st_info)]) { 11609039eeafSab dynlocal = 1; 11619039eeafSab } 11629039eeafSab } else { 11637c478bd9Sstevel@tonic-gate sdp->sd_symndx = *symndx; 11649039eeafSab } 11657c478bd9Sstevel@tonic-gate 11667c478bd9Sstevel@tonic-gate /* 11677c478bd9Sstevel@tonic-gate * Copy basic symbol and string information. 11687c478bd9Sstevel@tonic-gate */ 11697c478bd9Sstevel@tonic-gate name = sdp->sd_name; 11707c478bd9Sstevel@tonic-gate sap = sdp->sd_aux; 11717c478bd9Sstevel@tonic-gate 11727c478bd9Sstevel@tonic-gate /* 11737c478bd9Sstevel@tonic-gate * If we require to record version symbol indexes, update the 11747c478bd9Sstevel@tonic-gate * associated version symbol information for all defined 11757c478bd9Sstevel@tonic-gate * symbols. If a version definition is required any zero value 11767c478bd9Sstevel@tonic-gate * symbol indexes would have been flagged as undefined symbol 11777c478bd9Sstevel@tonic-gate * errors, however if we're just scoping these need to fall into 11787c478bd9Sstevel@tonic-gate * the base of global symbols. 11797c478bd9Sstevel@tonic-gate */ 11807c478bd9Sstevel@tonic-gate if (sdp->sd_symndx && versym) { 11817c478bd9Sstevel@tonic-gate Half vndx = 0; 11827c478bd9Sstevel@tonic-gate 1183090a8d9eSAli Bahrami if (sdp->sd_flags & FLG_SY_MVTOCOMM) { 11847c478bd9Sstevel@tonic-gate vndx = VER_NDX_GLOBAL; 1185090a8d9eSAli Bahrami } else if (sdp->sd_ref == REF_REL_NEED) { 11867c478bd9Sstevel@tonic-gate Half symflags1 = sdp->sd_flags1; 11877c478bd9Sstevel@tonic-gate 11887c478bd9Sstevel@tonic-gate vndx = sap->sa_overndx; 11897c478bd9Sstevel@tonic-gate if ((vndx == 0) && 11907c478bd9Sstevel@tonic-gate (sdp->sd_sym->st_shndx != SHN_UNDEF)) { 119160758829Srie if (symflags1 & FLG_SY1_HIDDEN) 11927c478bd9Sstevel@tonic-gate vndx = VER_NDX_LOCAL; 11937c478bd9Sstevel@tonic-gate else 11947c478bd9Sstevel@tonic-gate vndx = VER_NDX_GLOBAL; 11957c478bd9Sstevel@tonic-gate } 1196090a8d9eSAli Bahrami } else if ((sdp->sd_ref == REF_DYN_NEED) && 1197090a8d9eSAli Bahrami (sap->sa_dverndx > 0) && 1198090a8d9eSAli Bahrami (sap->sa_dverndx <= sdp->sd_file->ifl_vercnt) && 1199090a8d9eSAli Bahrami (sdp->sd_file->ifl_verndx != NULL)) { 1200090a8d9eSAli Bahrami /* Use index of verneed record */ 1201090a8d9eSAli Bahrami vndx = sdp->sd_file->ifl_verndx 1202090a8d9eSAli Bahrami [sap->sa_dverndx].vi_overndx; 12037c478bd9Sstevel@tonic-gate } 12047c478bd9Sstevel@tonic-gate versym[sdp->sd_symndx] = vndx; 12057c478bd9Sstevel@tonic-gate } 12067c478bd9Sstevel@tonic-gate 12077c478bd9Sstevel@tonic-gate /* 12087c478bd9Sstevel@tonic-gate * If we are creating the .syminfo section then set per symbol 12097c478bd9Sstevel@tonic-gate * flags here. 12107c478bd9Sstevel@tonic-gate */ 12117c478bd9Sstevel@tonic-gate if (sdp->sd_symndx && syminfo && 12127c478bd9Sstevel@tonic-gate !(sdp->sd_flags & FLG_SY_NOTAVAIL)) { 12137c478bd9Sstevel@tonic-gate int ndx = sdp->sd_symndx; 121457ef7aa9SRod Evans APlist **alpp = &(ofl->ofl_syminfsyms); 12157c478bd9Sstevel@tonic-gate 12167c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_MVTOCOMM) 12177c478bd9Sstevel@tonic-gate /* 12187c478bd9Sstevel@tonic-gate * Identify a copy relocation symbol. 12197c478bd9Sstevel@tonic-gate */ 12207c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= SYMINFO_FLG_COPY; 12217c478bd9Sstevel@tonic-gate 12227c478bd9Sstevel@tonic-gate if (sdp->sd_ref == REF_DYN_NEED) { 12237c478bd9Sstevel@tonic-gate /* 12247c478bd9Sstevel@tonic-gate * A reference is bound to a needed dependency. 1225*28bda19cSRod Evans * Save the syminfo entry, so that when the 1226*28bda19cSRod Evans * .dynamic section has been updated, a 1227*28bda19cSRod Evans * DT_NEEDED entry can be associated 1228*28bda19cSRod Evans * (see update_osyminfo()). 12297c478bd9Sstevel@tonic-gate */ 123057ef7aa9SRod Evans if (aplist_append(alpp, sdp, 123157ef7aa9SRod Evans AL_CNT_OFL_SYMINFOSYMS) == NULL) 12327c478bd9Sstevel@tonic-gate return (0); 12337c478bd9Sstevel@tonic-gate 1234*28bda19cSRod Evans /* 1235*28bda19cSRod Evans * Flag that the symbol has a direct association 1236*28bda19cSRod Evans * with the external reference (this is an old 1237*28bda19cSRod Evans * tagging, that has no real effect by itself). 1238*28bda19cSRod Evans * And flag whether this reference is lazy 1239*28bda19cSRod Evans * loadable. 1240*28bda19cSRod Evans */ 12417c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= SYMINFO_FLG_DIRECT; 12427c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_LAZYLD) 12437c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 12447c478bd9Sstevel@tonic-gate SYMINFO_FLG_LAZYLOAD; 12457c478bd9Sstevel@tonic-gate 12467c478bd9Sstevel@tonic-gate /* 12477c478bd9Sstevel@tonic-gate * Enable direct symbol bindings if: 12487c478bd9Sstevel@tonic-gate * 124957ef7aa9SRod Evans * - Symbol was identified with the DIRECT 12507c478bd9Sstevel@tonic-gate * keyword in a mapfile. 12517c478bd9Sstevel@tonic-gate * 125257ef7aa9SRod Evans * - Symbol reference has been bound to a 12537c478bd9Sstevel@tonic-gate * dependency which was specified as 12547c478bd9Sstevel@tonic-gate * requiring direct bindings with -zdirect. 12557c478bd9Sstevel@tonic-gate * 125657ef7aa9SRod Evans * - All symbol references are required to 12577c478bd9Sstevel@tonic-gate * use direct bindings via -Bdirect. 12587c478bd9Sstevel@tonic-gate */ 12597c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_DIR) 12607c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 12617c478bd9Sstevel@tonic-gate SYMINFO_FLG_DIRECTBIND; 12627c478bd9Sstevel@tonic-gate 12637c478bd9Sstevel@tonic-gate } else if ((sdp->sd_flags & FLG_SY_EXTERN) && 12647c478bd9Sstevel@tonic-gate (sdp->sd_sym->st_shndx == SHN_UNDEF)) { 12657c478bd9Sstevel@tonic-gate /* 12667c478bd9Sstevel@tonic-gate * If this symbol has been explicitly defined 12677c478bd9Sstevel@tonic-gate * as external, and remains unresolved, mark 12687c478bd9Sstevel@tonic-gate * it as external. 12697c478bd9Sstevel@tonic-gate */ 12707c478bd9Sstevel@tonic-gate syminfo[ndx].si_boundto = SYMINFO_BT_EXTERN; 12717c478bd9Sstevel@tonic-gate 12729a411307Srie } else if ((sdp->sd_flags & FLG_SY_PARENT) && 12739a411307Srie (sdp->sd_sym->st_shndx == SHN_UNDEF)) { 12747c478bd9Sstevel@tonic-gate /* 12759a411307Srie * If this symbol has been explicitly defined 12769a411307Srie * to be a reference to a parent object, 12779a411307Srie * indicate whether a direct binding should be 12787c478bd9Sstevel@tonic-gate * established. 12797c478bd9Sstevel@tonic-gate */ 12807c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= SYMINFO_FLG_DIRECT; 12817c478bd9Sstevel@tonic-gate syminfo[ndx].si_boundto = SYMINFO_BT_PARENT; 12827c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_DIR) 12837c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 12847c478bd9Sstevel@tonic-gate SYMINFO_FLG_DIRECTBIND; 12857c478bd9Sstevel@tonic-gate 12867c478bd9Sstevel@tonic-gate } else if (sdp->sd_flags & FLG_SY_STDFLTR) { 12877c478bd9Sstevel@tonic-gate /* 12887c478bd9Sstevel@tonic-gate * A filter definition. Although this symbol 12897c478bd9Sstevel@tonic-gate * can only be a stub, it might be necessary to 12907c478bd9Sstevel@tonic-gate * prevent external direct bindings. 12917c478bd9Sstevel@tonic-gate */ 12927c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= SYMINFO_FLG_FILTER; 12937c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_NDIR) 12947c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 12957c478bd9Sstevel@tonic-gate SYMINFO_FLG_NOEXTDIRECT; 12967c478bd9Sstevel@tonic-gate 12977c478bd9Sstevel@tonic-gate } else if (sdp->sd_flags & FLG_SY_AUXFLTR) { 12987c478bd9Sstevel@tonic-gate /* 12997c478bd9Sstevel@tonic-gate * An auxiliary filter definition. By nature, 13007c478bd9Sstevel@tonic-gate * this definition is direct, in that should the 13017c478bd9Sstevel@tonic-gate * filtee lookup fail, we'll fall back to this 13027c478bd9Sstevel@tonic-gate * object. It may still be necesssary to 13037c478bd9Sstevel@tonic-gate * prevent external direct bindings. 13047c478bd9Sstevel@tonic-gate */ 13057c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= SYMINFO_FLG_AUXILIARY; 13067c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_NDIR) 13077c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 13087c478bd9Sstevel@tonic-gate SYMINFO_FLG_NOEXTDIRECT; 13097c478bd9Sstevel@tonic-gate 13107c478bd9Sstevel@tonic-gate } else if ((sdp->sd_ref == REF_REL_NEED) && 13117c478bd9Sstevel@tonic-gate (sdp->sd_sym->st_shndx != SHN_UNDEF)) { 13129a411307Srie 13137c478bd9Sstevel@tonic-gate /* 13147c478bd9Sstevel@tonic-gate * This definition exists within the object 13157c478bd9Sstevel@tonic-gate * being created. Flag whether it is necessary 13167c478bd9Sstevel@tonic-gate * to prevent external direct bindings. 13177c478bd9Sstevel@tonic-gate */ 13187c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_NDIR) { 13197c478bd9Sstevel@tonic-gate syminfo[ndx].si_boundto = 13207c478bd9Sstevel@tonic-gate SYMINFO_BT_NONE; 13217c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 13227c478bd9Sstevel@tonic-gate SYMINFO_FLG_NOEXTDIRECT; 13237c478bd9Sstevel@tonic-gate } 13247c478bd9Sstevel@tonic-gate 13259a411307Srie /* 13269a411307Srie * Indicate that this symbol is acting as an 13279a411307Srie * individual interposer. 13289a411307Srie */ 13299a411307Srie if (sdp->sd_flags & FLG_SY_INTPOSE) { 13309a411307Srie syminfo[ndx].si_flags |= 13319a411307Srie SYMINFO_FLG_INTERPOSE; 13329a411307Srie } 13339a411307Srie 13347c478bd9Sstevel@tonic-gate /* 13357c478bd9Sstevel@tonic-gate * If external bindings are allowed, or this is 13367c478bd9Sstevel@tonic-gate * a translator symbol, indicate the binding, 13377c478bd9Sstevel@tonic-gate * and a direct binding if necessary. 13387c478bd9Sstevel@tonic-gate */ 13397c478bd9Sstevel@tonic-gate if (((sdp->sd_flags1 & FLG_SY1_NDIR) == 0) || 13407c478bd9Sstevel@tonic-gate ((dtflags_1 & DF_1_TRANS) && sdp->sd_aux && 13417c478bd9Sstevel@tonic-gate sdp->sd_aux->sa_bindto)) { 13427c478bd9Sstevel@tonic-gate 13437c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 13447c478bd9Sstevel@tonic-gate SYMINFO_FLG_DIRECT; 13457c478bd9Sstevel@tonic-gate 13467c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_DIR) 13477c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 13487c478bd9Sstevel@tonic-gate SYMINFO_FLG_DIRECTBIND; 13497c478bd9Sstevel@tonic-gate 13507c478bd9Sstevel@tonic-gate /* 13517c478bd9Sstevel@tonic-gate * If this is a translator, the symbols 13527c478bd9Sstevel@tonic-gate * boundto element will indicate the 13537c478bd9Sstevel@tonic-gate * dependency to which it should resolve 13547c478bd9Sstevel@tonic-gate * rather than itself. Save this info 13557c478bd9Sstevel@tonic-gate * for updating after the .dynamic 13567c478bd9Sstevel@tonic-gate * section has been created. 13577c478bd9Sstevel@tonic-gate */ 13587c478bd9Sstevel@tonic-gate if ((dtflags_1 & DF_1_TRANS) && 13597c478bd9Sstevel@tonic-gate sdp->sd_aux && 13607c478bd9Sstevel@tonic-gate sdp->sd_aux->sa_bindto) { 136157ef7aa9SRod Evans if (aplist_append(alpp, sdp, 136257ef7aa9SRod Evans AL_CNT_OFL_SYMINFOSYMS) == 136357ef7aa9SRod Evans NULL) 13647c478bd9Sstevel@tonic-gate return (0); 13657c478bd9Sstevel@tonic-gate } else { 13667c478bd9Sstevel@tonic-gate syminfo[ndx].si_boundto = 13677c478bd9Sstevel@tonic-gate SYMINFO_BT_SELF; 13687c478bd9Sstevel@tonic-gate } 13697c478bd9Sstevel@tonic-gate } 13707c478bd9Sstevel@tonic-gate } 13717c478bd9Sstevel@tonic-gate } 13727c478bd9Sstevel@tonic-gate 13737c478bd9Sstevel@tonic-gate /* 13747c478bd9Sstevel@tonic-gate * Note that the `sym' value is reset to be one of the new 13757c478bd9Sstevel@tonic-gate * symbol table entries. This symbol will be updated further 13767c478bd9Sstevel@tonic-gate * depending on the type of the symbol. Process the .symtab 13777c478bd9Sstevel@tonic-gate * first, followed by the .dynsym, thus the `sym' value will 13787c478bd9Sstevel@tonic-gate * remain as the .dynsym value when the .dynsym is present. 1379c1c6f601Srie * This ensures that any versioning symbols st_name value will 13809039eeafSab * be appropriate for the string table used by version 13817c478bd9Sstevel@tonic-gate * entries. 13827c478bd9Sstevel@tonic-gate */ 13837c478bd9Sstevel@tonic-gate if (enter_in_symtab) { 13847c478bd9Sstevel@tonic-gate Word _symndx; 13857c478bd9Sstevel@tonic-gate 13867c478bd9Sstevel@tonic-gate if (local) 13877c478bd9Sstevel@tonic-gate _symndx = scopesym_ndx; 13887c478bd9Sstevel@tonic-gate else 13897c478bd9Sstevel@tonic-gate _symndx = symtab_ndx; 13909039eeafSab 13917c478bd9Sstevel@tonic-gate symtab[_symndx] = *sdp->sd_sym; 13927c478bd9Sstevel@tonic-gate sdp->sd_sym = sym = &symtab[_symndx]; 13937c478bd9Sstevel@tonic-gate (void) st_setstring(strtab, name, &stoff); 13947c478bd9Sstevel@tonic-gate sym->st_name = stoff; 13957c478bd9Sstevel@tonic-gate } 13969039eeafSab if (dynlocal) { 13979039eeafSab ldynsym[ldynscopesym_ndx] = *sdp->sd_sym; 13989039eeafSab sdp->sd_sym = sym = &ldynsym[ldynscopesym_ndx]; 13999039eeafSab (void) st_setstring(dynstr, name, &stoff); 14009039eeafSab ldynsym[ldynscopesym_ndx].st_name = stoff; 1401d579eb63Sab /* Add it to sort section if it qualifies */ 1402d579eb63Sab ADD_TO_DYNSORT(sdp, sym, ELF_ST_TYPE(sym->st_info), 1403d579eb63Sab ldynscopesym_ndx); 14049039eeafSab } 14057c478bd9Sstevel@tonic-gate 14067c478bd9Sstevel@tonic-gate if (dynsym && !local) { 14077c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx] = *sdp->sd_sym; 140860758829Srie 14097c478bd9Sstevel@tonic-gate /* 14107c478bd9Sstevel@tonic-gate * Provided this isn't an unnamed register symbol, 141160758829Srie * update the symbols name and hash value. 14127c478bd9Sstevel@tonic-gate */ 14137c478bd9Sstevel@tonic-gate if (((sdp->sd_flags & FLG_SY_REGSYM) == 0) || 14147c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx].st_name) { 1415d840867fSab (void) st_setstring(dynstr, name, &stoff); 1416d840867fSab dynsym[dynsym_ndx].st_name = stoff; 141760758829Srie 1418d840867fSab if (stoff) { 1419d840867fSab Word _hashndx; 142060758829Srie 142160758829Srie hashval = 142260758829Srie sap->sa_hash % ofl->ofl_hashbkts; 142360758829Srie 1424d840867fSab /* LINTED */ 1425d840867fSab if (_hashndx = hashbkt[hashval]) { 142660758829Srie while (hashchain[_hashndx]) { 1427d840867fSab _hashndx = 1428d840867fSab hashchain[_hashndx]; 142960758829Srie } 1430d840867fSab hashchain[_hashndx] = 1431d840867fSab sdp->sd_symndx; 1432d840867fSab } else { 1433d840867fSab hashbkt[hashval] = 1434d840867fSab sdp->sd_symndx; 1435d840867fSab } 14367c478bd9Sstevel@tonic-gate } 14377c478bd9Sstevel@tonic-gate } 14387c478bd9Sstevel@tonic-gate sdp->sd_sym = sym = &dynsym[dynsym_ndx]; 143960758829Srie 1440d579eb63Sab /* 1441d579eb63Sab * Add it to sort section if it qualifies. 1442d579eb63Sab * The indexes in that section are relative to the 1443d579eb63Sab * the adjacent SUNW_ldynsym/dymsym pair, so we 1444d579eb63Sab * add the number of items in SUNW_ldynsym to the 1445d579eb63Sab * dynsym index. 1446d579eb63Sab */ 1447d579eb63Sab ADD_TO_DYNSORT(sdp, sym, ELF_ST_TYPE(sym->st_info), 1448d579eb63Sab ldynsym_cnt + dynsym_ndx); 14497c478bd9Sstevel@tonic-gate } 14509039eeafSab if (!enter_in_symtab && (!dynsym || (local && !dynlocal))) { 14517c478bd9Sstevel@tonic-gate if (!(sdp->sd_flags & FLG_SY_UPREQD)) 14527c478bd9Sstevel@tonic-gate continue; 14537c478bd9Sstevel@tonic-gate sym = sdp->sd_sym; 14547c478bd9Sstevel@tonic-gate } else 14557c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_CLEAN; 14567c478bd9Sstevel@tonic-gate 14577c478bd9Sstevel@tonic-gate 14587c478bd9Sstevel@tonic-gate /* 14597c478bd9Sstevel@tonic-gate * If we have a weak data symbol for which we need the real 14607c478bd9Sstevel@tonic-gate * symbol also, save this processing until later. 14617c478bd9Sstevel@tonic-gate * 14627c478bd9Sstevel@tonic-gate * The exception to this is if the weak/strong have PLT's 14637c478bd9Sstevel@tonic-gate * assigned to them. In that case we don't do the post-weak 14647c478bd9Sstevel@tonic-gate * processing because the PLT's must be maintained so that we 14657c478bd9Sstevel@tonic-gate * can do 'interpositioning' on both of the symbols. 14667c478bd9Sstevel@tonic-gate */ 14677c478bd9Sstevel@tonic-gate if ((sap->sa_linkndx) && 14687c478bd9Sstevel@tonic-gate (ELF_ST_BIND(sym->st_info) == STB_WEAK) && 14697c478bd9Sstevel@tonic-gate (!sap->sa_PLTndx)) { 147057ef7aa9SRod Evans Sym_desc *_sdp; 147157ef7aa9SRod Evans 147257ef7aa9SRod Evans _sdp = sdp->sd_file->ifl_oldndx[sap->sa_linkndx]; 14737c478bd9Sstevel@tonic-gate 14747c478bd9Sstevel@tonic-gate if (_sdp->sd_ref != REF_DYN_SEEN) { 147557ef7aa9SRod Evans Wk_desc wk; 14767c478bd9Sstevel@tonic-gate 14779039eeafSab if (enter_in_symtab) { 147857ef7aa9SRod Evans if (local) { 147957ef7aa9SRod Evans wk.wk_symtab = 14807c478bd9Sstevel@tonic-gate &symtab[scopesym_ndx]; 148157ef7aa9SRod Evans scopesym_ndx++; 148257ef7aa9SRod Evans } else { 148357ef7aa9SRod Evans wk.wk_symtab = 14847c478bd9Sstevel@tonic-gate &symtab[symtab_ndx]; 148557ef7aa9SRod Evans symtab_ndx++; 148657ef7aa9SRod Evans } 14873e831575SAli Bahrami } else { 14883e831575SAli Bahrami wk.wk_symtab = NULL; 14899039eeafSab } 14909039eeafSab if (dynsym) { 14919039eeafSab if (!local) { 149257ef7aa9SRod Evans wk.wk_dynsym = 14939039eeafSab &dynsym[dynsym_ndx]; 149457ef7aa9SRod Evans dynsym_ndx++; 14959039eeafSab } else if (dynlocal) { 149657ef7aa9SRod Evans wk.wk_dynsym = 14979039eeafSab &ldynsym[ldynscopesym_ndx]; 149857ef7aa9SRod Evans ldynscopesym_ndx++; 14999039eeafSab } 15003e831575SAli Bahrami } else { 15013e831575SAli Bahrami wk.wk_dynsym = NULL; 15029039eeafSab } 150357ef7aa9SRod Evans wk.wk_weak = sdp; 150457ef7aa9SRod Evans wk.wk_alias = _sdp; 15057c478bd9Sstevel@tonic-gate 150657ef7aa9SRod Evans if (alist_append(&weak, &wk, 150757ef7aa9SRod Evans sizeof (Wk_desc), AL_CNT_WEAK) == NULL) 15087c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 15097c478bd9Sstevel@tonic-gate 15107c478bd9Sstevel@tonic-gate continue; 15117c478bd9Sstevel@tonic-gate } 15127c478bd9Sstevel@tonic-gate } 15137c478bd9Sstevel@tonic-gate 15145aefb655Srie DBG_CALL(Dbg_syms_old(ofl, sdp)); 15157c478bd9Sstevel@tonic-gate 15167c478bd9Sstevel@tonic-gate spec = NULL; 15177c478bd9Sstevel@tonic-gate /* 15187c478bd9Sstevel@tonic-gate * assign new symbol value. 15197c478bd9Sstevel@tonic-gate */ 15207c478bd9Sstevel@tonic-gate sectndx = sdp->sd_shndx; 15217c478bd9Sstevel@tonic-gate if (sectndx == SHN_UNDEF) { 15227c478bd9Sstevel@tonic-gate if (((sdp->sd_flags & FLG_SY_REGSYM) == 0) && 15237c478bd9Sstevel@tonic-gate (sym->st_value != 0)) { 15245aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 15255aefb655Srie MSG_INTL(MSG_SYM_NOTNULL), 15267c478bd9Sstevel@tonic-gate demangle(name), sdp->sd_file->ifl_name); 15277c478bd9Sstevel@tonic-gate } 15287c478bd9Sstevel@tonic-gate 15297c478bd9Sstevel@tonic-gate /* 15307c478bd9Sstevel@tonic-gate * Undefined weak global, if we are generating a static 15317c478bd9Sstevel@tonic-gate * executable, output as an absolute zero. Otherwise 15327c478bd9Sstevel@tonic-gate * leave it as is, ld.so.1 will skip symbols of this 15337c478bd9Sstevel@tonic-gate * type (this technique allows applications and 15347c478bd9Sstevel@tonic-gate * libraries to test for the existence of a symbol as an 15357c478bd9Sstevel@tonic-gate * indication of the presence or absence of certain 15367c478bd9Sstevel@tonic-gate * functionality). 15377c478bd9Sstevel@tonic-gate */ 15387c478bd9Sstevel@tonic-gate if (((flags & (FLG_OF_STATIC | FLG_OF_EXEC)) == 15397c478bd9Sstevel@tonic-gate (FLG_OF_STATIC | FLG_OF_EXEC)) && 15407c478bd9Sstevel@tonic-gate (ELF_ST_BIND(sym->st_info) == STB_WEAK)) { 15417c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_SPECSEC; 15427c478bd9Sstevel@tonic-gate sdp->sd_shndx = sectndx = SHN_ABS; 15437c478bd9Sstevel@tonic-gate } 15447c478bd9Sstevel@tonic-gate } else if ((sdp->sd_flags & FLG_SY_SPECSEC) && 15457c478bd9Sstevel@tonic-gate (sectndx == SHN_COMMON)) { 15467c478bd9Sstevel@tonic-gate /* COMMONs have already been processed */ 15477c478bd9Sstevel@tonic-gate /* EMPTY */ 15487c478bd9Sstevel@tonic-gate ; 15497c478bd9Sstevel@tonic-gate } else { 15507c478bd9Sstevel@tonic-gate if ((sdp->sd_flags & FLG_SY_SPECSEC) && 15517c478bd9Sstevel@tonic-gate (sectndx == SHN_ABS)) 15527c478bd9Sstevel@tonic-gate spec = sdp->sd_aux->sa_symspec; 15537c478bd9Sstevel@tonic-gate 15547c478bd9Sstevel@tonic-gate /* LINTED */ 15557c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_COMMEXP) { 15567c478bd9Sstevel@tonic-gate /* 15577c478bd9Sstevel@tonic-gate * This is (or was) a COMMON symbol which was 15587c478bd9Sstevel@tonic-gate * processed above - no processing 15597c478bd9Sstevel@tonic-gate * required here. 15607c478bd9Sstevel@tonic-gate */ 15617c478bd9Sstevel@tonic-gate ; 15627c478bd9Sstevel@tonic-gate } else if (sdp->sd_ref == REF_DYN_NEED) { 1563d579eb63Sab uchar_t type, bind; 15647c478bd9Sstevel@tonic-gate 15657c478bd9Sstevel@tonic-gate sectndx = SHN_UNDEF; 15667c478bd9Sstevel@tonic-gate sym->st_value = 0; 15677c478bd9Sstevel@tonic-gate sym->st_size = 0; 15687c478bd9Sstevel@tonic-gate 15697c478bd9Sstevel@tonic-gate /* 15707c478bd9Sstevel@tonic-gate * Make sure this undefined symbol is returned 15717c478bd9Sstevel@tonic-gate * to the same binding as was defined in the 15727c478bd9Sstevel@tonic-gate * original relocatable object reference. 15737c478bd9Sstevel@tonic-gate */ 15747c478bd9Sstevel@tonic-gate type = ELF_ST_TYPE(sym-> st_info); 15757c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_GLOBREF) 15767c478bd9Sstevel@tonic-gate bind = STB_GLOBAL; 15777c478bd9Sstevel@tonic-gate else 15787c478bd9Sstevel@tonic-gate bind = STB_WEAK; 15797c478bd9Sstevel@tonic-gate 15807c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(bind, type); 15817c478bd9Sstevel@tonic-gate 15827c478bd9Sstevel@tonic-gate } else if (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) && 15837c478bd9Sstevel@tonic-gate (sdp->sd_ref == REF_REL_NEED)) { 15847c478bd9Sstevel@tonic-gate osp = sdp->sd_isc->is_osdesc; 15857c478bd9Sstevel@tonic-gate /* LINTED */ 15867c478bd9Sstevel@tonic-gate sectndx = elf_ndxscn(osp->os_scn); 15877c478bd9Sstevel@tonic-gate 15887c478bd9Sstevel@tonic-gate /* 15897c478bd9Sstevel@tonic-gate * In an executable, the new symbol value is the 15907c478bd9Sstevel@tonic-gate * old value (offset into defining section) plus 15917c478bd9Sstevel@tonic-gate * virtual address of defining section. In a 15927c478bd9Sstevel@tonic-gate * relocatable, the new value is the old value 15937c478bd9Sstevel@tonic-gate * plus the displacement of the section within 15947c478bd9Sstevel@tonic-gate * the file. 15957c478bd9Sstevel@tonic-gate */ 15967c478bd9Sstevel@tonic-gate /* LINTED */ 15977c478bd9Sstevel@tonic-gate sym->st_value += 15987c478bd9Sstevel@tonic-gate (Off)_elf_getxoff(sdp->sd_isc->is_indata); 15997c478bd9Sstevel@tonic-gate 16007c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_RELOBJ)) { 16017c478bd9Sstevel@tonic-gate sym->st_value += osp->os_shdr->sh_addr; 16027c478bd9Sstevel@tonic-gate /* 16037c478bd9Sstevel@tonic-gate * TLS symbols are relative to 16047c478bd9Sstevel@tonic-gate * the TLS segment. 16057c478bd9Sstevel@tonic-gate */ 16067c478bd9Sstevel@tonic-gate if ((ELF_ST_TYPE(sym->st_info) == 16077c478bd9Sstevel@tonic-gate STT_TLS) && (ofl->ofl_tlsphdr)) 16087c478bd9Sstevel@tonic-gate sym->st_value -= 16097c478bd9Sstevel@tonic-gate ofl->ofl_tlsphdr->p_vaddr; 16107c478bd9Sstevel@tonic-gate } 16117c478bd9Sstevel@tonic-gate } 16127c478bd9Sstevel@tonic-gate } 16137c478bd9Sstevel@tonic-gate 16147c478bd9Sstevel@tonic-gate if (spec) { 16157c478bd9Sstevel@tonic-gate switch (spec) { 16167c478bd9Sstevel@tonic-gate case SDAUX_ID_ETEXT: 16177c478bd9Sstevel@tonic-gate sym->st_value = etext; 16187c478bd9Sstevel@tonic-gate sectndx = etext_ndx; 16197c478bd9Sstevel@tonic-gate if (etext_abs) 16207c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_SPECSEC; 16217c478bd9Sstevel@tonic-gate else 16227c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 16237c478bd9Sstevel@tonic-gate break; 16247c478bd9Sstevel@tonic-gate case SDAUX_ID_EDATA: 16257c478bd9Sstevel@tonic-gate sym->st_value = edata; 16267c478bd9Sstevel@tonic-gate sectndx = edata_ndx; 16277c478bd9Sstevel@tonic-gate if (edata_abs) 16287c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_SPECSEC; 16297c478bd9Sstevel@tonic-gate else 16307c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 16317c478bd9Sstevel@tonic-gate break; 16327c478bd9Sstevel@tonic-gate case SDAUX_ID_END: 16337c478bd9Sstevel@tonic-gate sym->st_value = end; 16347c478bd9Sstevel@tonic-gate sectndx = end_ndx; 16357c478bd9Sstevel@tonic-gate if (end_abs) 16367c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_SPECSEC; 16377c478bd9Sstevel@tonic-gate else 16387c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 16397c478bd9Sstevel@tonic-gate break; 16407c478bd9Sstevel@tonic-gate case SDAUX_ID_START: 16417c478bd9Sstevel@tonic-gate sym->st_value = start; 16427c478bd9Sstevel@tonic-gate sectndx = start_ndx; 16437c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 16447c478bd9Sstevel@tonic-gate break; 16457c478bd9Sstevel@tonic-gate case SDAUX_ID_DYN: 16467c478bd9Sstevel@tonic-gate if (flags & FLG_OF_DYNAMIC) { 16477c478bd9Sstevel@tonic-gate sym->st_value = ofl-> 16487c478bd9Sstevel@tonic-gate ofl_osdynamic->os_shdr->sh_addr; 16497c478bd9Sstevel@tonic-gate /* LINTED */ 16507c478bd9Sstevel@tonic-gate sectndx = elf_ndxscn( 16517c478bd9Sstevel@tonic-gate ofl->ofl_osdynamic->os_scn); 16527c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 16537c478bd9Sstevel@tonic-gate } 16547c478bd9Sstevel@tonic-gate break; 16557c478bd9Sstevel@tonic-gate case SDAUX_ID_PLT: 16567c478bd9Sstevel@tonic-gate if (ofl->ofl_osplt) { 16577c478bd9Sstevel@tonic-gate sym->st_value = ofl-> 16587c478bd9Sstevel@tonic-gate ofl_osplt->os_shdr->sh_addr; 16597c478bd9Sstevel@tonic-gate /* LINTED */ 16607c478bd9Sstevel@tonic-gate sectndx = elf_ndxscn( 16617c478bd9Sstevel@tonic-gate ofl->ofl_osplt->os_scn); 16627c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 16637c478bd9Sstevel@tonic-gate } 16647c478bd9Sstevel@tonic-gate break; 16657c478bd9Sstevel@tonic-gate case SDAUX_ID_GOT: 16667c478bd9Sstevel@tonic-gate /* 16677c478bd9Sstevel@tonic-gate * Symbol bias for negative growing tables is 16687c478bd9Sstevel@tonic-gate * stored in symbol's value during 16697c478bd9Sstevel@tonic-gate * allocate_got(). 16707c478bd9Sstevel@tonic-gate */ 16717c478bd9Sstevel@tonic-gate sym->st_value += ofl-> 16727c478bd9Sstevel@tonic-gate ofl_osgot->os_shdr->sh_addr; 16737c478bd9Sstevel@tonic-gate /* LINTED */ 16747c478bd9Sstevel@tonic-gate sectndx = elf_ndxscn(ofl-> 16757c478bd9Sstevel@tonic-gate ofl_osgot->os_scn); 16767c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 16777c478bd9Sstevel@tonic-gate break; 16787c478bd9Sstevel@tonic-gate default: 16797c478bd9Sstevel@tonic-gate /* NOTHING */ 16807c478bd9Sstevel@tonic-gate ; 16817c478bd9Sstevel@tonic-gate } 16827c478bd9Sstevel@tonic-gate } 16837c478bd9Sstevel@tonic-gate 16847c478bd9Sstevel@tonic-gate /* 16857c478bd9Sstevel@tonic-gate * If a plt index has been assigned to an undefined function, 16867c478bd9Sstevel@tonic-gate * update the symbols value to the appropriate .plt address. 16877c478bd9Sstevel@tonic-gate */ 16887c478bd9Sstevel@tonic-gate if ((flags & FLG_OF_DYNAMIC) && (flags & FLG_OF_EXEC) && 16897c478bd9Sstevel@tonic-gate (sdp->sd_file) && 16907c478bd9Sstevel@tonic-gate (sdp->sd_file->ifl_ehdr->e_type == ET_DYN) && 16917c478bd9Sstevel@tonic-gate (ELF_ST_TYPE(sym->st_info) == STT_FUNC) && 16927c478bd9Sstevel@tonic-gate !(flags & FLG_OF_BFLAG)) { 16937c478bd9Sstevel@tonic-gate if (sap->sa_PLTndx) 1694ba2be530Sab sym->st_value = 1695ba2be530Sab (*ld_targ.t_mr.mr_calc_plt_addr)(sdp, ofl); 16967c478bd9Sstevel@tonic-gate } 16977c478bd9Sstevel@tonic-gate 16987c478bd9Sstevel@tonic-gate /* 16997c478bd9Sstevel@tonic-gate * Finish updating the symbols. 17007c478bd9Sstevel@tonic-gate */ 17017c478bd9Sstevel@tonic-gate 17027c478bd9Sstevel@tonic-gate /* 17037c478bd9Sstevel@tonic-gate * Sym Update: if scoped local - set local binding 17047c478bd9Sstevel@tonic-gate */ 17057c478bd9Sstevel@tonic-gate if (local) 17067c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(STB_LOCAL, 17077c478bd9Sstevel@tonic-gate ELF_ST_TYPE(sym->st_info)); 17087c478bd9Sstevel@tonic-gate 17097c478bd9Sstevel@tonic-gate /* 17107c478bd9Sstevel@tonic-gate * Sym Updated: If both the .symtab and .dynsym 17117c478bd9Sstevel@tonic-gate * are present then we've actually updated the information in 17127c478bd9Sstevel@tonic-gate * the .dynsym, therefore copy this same information to the 17137c478bd9Sstevel@tonic-gate * .symtab entry. 17147c478bd9Sstevel@tonic-gate */ 17157c478bd9Sstevel@tonic-gate sdp->sd_shndx = sectndx; 17169039eeafSab if (enter_in_symtab && dynsym && (!local || dynlocal)) { 17179039eeafSab Word _symndx = dynlocal ? scopesym_ndx : symtab_ndx; 17189039eeafSab 17199039eeafSab symtab[_symndx].st_value = sym->st_value; 17209039eeafSab symtab[_symndx].st_size = sym->st_size; 17219039eeafSab symtab[_symndx].st_info = sym->st_info; 17229039eeafSab symtab[_symndx].st_other = sym->st_other; 17237c478bd9Sstevel@tonic-gate } 17247c478bd9Sstevel@tonic-gate 17257c478bd9Sstevel@tonic-gate if (enter_in_symtab) { 17267c478bd9Sstevel@tonic-gate Word _symndx; 17277c478bd9Sstevel@tonic-gate 17287c478bd9Sstevel@tonic-gate if (local) 17297c478bd9Sstevel@tonic-gate _symndx = scopesym_ndx++; 17307c478bd9Sstevel@tonic-gate else 17317c478bd9Sstevel@tonic-gate _symndx = symtab_ndx++; 17327c478bd9Sstevel@tonic-gate if (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) && 17337c478bd9Sstevel@tonic-gate (sectndx >= SHN_LORESERVE)) { 173457ef7aa9SRod Evans assert(symshndx != NULL); 17357c478bd9Sstevel@tonic-gate symshndx[_symndx] = sectndx; 17367c478bd9Sstevel@tonic-gate symtab[_symndx].st_shndx = SHN_XINDEX; 17377c478bd9Sstevel@tonic-gate } else { 17387c478bd9Sstevel@tonic-gate /* LINTED */ 17397c478bd9Sstevel@tonic-gate symtab[_symndx].st_shndx = (Half)sectndx; 17407c478bd9Sstevel@tonic-gate } 17417c478bd9Sstevel@tonic-gate } 17427c478bd9Sstevel@tonic-gate 17439039eeafSab if (dynsym && (!local || dynlocal)) { 17449039eeafSab /* 17459039eeafSab * dynsym and ldynsym are distinct tables, so 17469039eeafSab * we use indirection to access the right one 17479039eeafSab * and the related extended section index array. 17489039eeafSab */ 17499039eeafSab Word _symndx; 17509039eeafSab Sym *_dynsym; 17519039eeafSab Word *_dynshndx; 17529039eeafSab 17539039eeafSab if (!local) { 17549039eeafSab _symndx = dynsym_ndx++; 17559039eeafSab _dynsym = dynsym; 17569039eeafSab _dynshndx = dynshndx; 17579039eeafSab } else { 17589039eeafSab _symndx = ldynscopesym_ndx++; 17599039eeafSab _dynsym = ldynsym; 17609039eeafSab _dynshndx = ldynshndx; 17619039eeafSab } 17627c478bd9Sstevel@tonic-gate if (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) && 17637c478bd9Sstevel@tonic-gate (sectndx >= SHN_LORESERVE)) { 176457ef7aa9SRod Evans assert(_dynshndx != NULL); 17659039eeafSab _dynshndx[_symndx] = sectndx; 17669039eeafSab _dynsym[_symndx].st_shndx = SHN_XINDEX; 17677c478bd9Sstevel@tonic-gate } else { 17687c478bd9Sstevel@tonic-gate /* LINTED */ 17699039eeafSab _dynsym[_symndx].st_shndx = (Half)sectndx; 17707c478bd9Sstevel@tonic-gate } 17717c478bd9Sstevel@tonic-gate } 17727c478bd9Sstevel@tonic-gate 17735aefb655Srie DBG_CALL(Dbg_syms_new(ofl, sym, sdp)); 17747c478bd9Sstevel@tonic-gate } 17757c478bd9Sstevel@tonic-gate 17767c478bd9Sstevel@tonic-gate /* 17777c478bd9Sstevel@tonic-gate * Now that all the symbols have been processed update any weak symbols 17787c478bd9Sstevel@tonic-gate * information (ie. copy all information except `st_name'). As both 17797c478bd9Sstevel@tonic-gate * symbols will be represented in the output, return the weak symbol to 17807c478bd9Sstevel@tonic-gate * its correct type. 17817c478bd9Sstevel@tonic-gate */ 178257ef7aa9SRod Evans for (ALIST_TRAVERSE(weak, idx1, wkp)) { 178357ef7aa9SRod Evans Sym_desc *sdp, *_sdp; 178457ef7aa9SRod Evans Sym *sym, *_sym, *__sym; 1785d579eb63Sab uchar_t bind; 17867c478bd9Sstevel@tonic-gate 17877c478bd9Sstevel@tonic-gate sdp = wkp->wk_weak; 17887c478bd9Sstevel@tonic-gate _sdp = wkp->wk_alias; 17893e831575SAli Bahrami _sym = __sym = _sdp->sd_sym; 17907c478bd9Sstevel@tonic-gate 17917c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_WEAKDEF; 17927c478bd9Sstevel@tonic-gate 17937c478bd9Sstevel@tonic-gate /* 17947c478bd9Sstevel@tonic-gate * If the symbol definition has been scoped then assign it to 17957c478bd9Sstevel@tonic-gate * be local, otherwise if it's from a shared object then we need 17967c478bd9Sstevel@tonic-gate * to maintain the binding of the original reference. 17977c478bd9Sstevel@tonic-gate */ 179860758829Srie if (sdp->sd_flags1 & FLG_SY1_HIDDEN) { 17997c478bd9Sstevel@tonic-gate if (flags & FLG_OF_PROCRED) 18007c478bd9Sstevel@tonic-gate bind = STB_LOCAL; 18017c478bd9Sstevel@tonic-gate else 18027c478bd9Sstevel@tonic-gate bind = STB_WEAK; 18037c478bd9Sstevel@tonic-gate } else if ((sdp->sd_ref == REF_DYN_NEED) && 18047c478bd9Sstevel@tonic-gate (sdp->sd_flags & FLG_SY_GLOBREF)) 18057c478bd9Sstevel@tonic-gate bind = STB_GLOBAL; 18067c478bd9Sstevel@tonic-gate else 18077c478bd9Sstevel@tonic-gate bind = STB_WEAK; 18087c478bd9Sstevel@tonic-gate 18095aefb655Srie DBG_CALL(Dbg_syms_old(ofl, sdp)); 18103e831575SAli Bahrami if ((sym = wkp->wk_symtab) != NULL) { 18117c478bd9Sstevel@tonic-gate sym->st_value = _sym->st_value; 18127c478bd9Sstevel@tonic-gate sym->st_size = _sym->st_size; 18137c478bd9Sstevel@tonic-gate sym->st_other = _sym->st_other; 18147c478bd9Sstevel@tonic-gate sym->st_shndx = _sym->st_shndx; 18157c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(bind, 18167c478bd9Sstevel@tonic-gate ELF_ST_TYPE(sym->st_info)); 18177c478bd9Sstevel@tonic-gate __sym = sym; 18187c478bd9Sstevel@tonic-gate } 18193e831575SAli Bahrami if ((sym = wkp->wk_dynsym) != NULL) { 18207c478bd9Sstevel@tonic-gate sym->st_value = _sym->st_value; 18217c478bd9Sstevel@tonic-gate sym->st_size = _sym->st_size; 18227c478bd9Sstevel@tonic-gate sym->st_other = _sym->st_other; 18237c478bd9Sstevel@tonic-gate sym->st_shndx = _sym->st_shndx; 18247c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(bind, 18257c478bd9Sstevel@tonic-gate ELF_ST_TYPE(sym->st_info)); 18267c478bd9Sstevel@tonic-gate __sym = sym; 18277c478bd9Sstevel@tonic-gate } 18285aefb655Srie DBG_CALL(Dbg_syms_new(ofl, __sym, sdp)); 18297c478bd9Sstevel@tonic-gate } 18307c478bd9Sstevel@tonic-gate 18317c478bd9Sstevel@tonic-gate /* 18325aefb655Srie * Now display GOT debugging information if required. 18337c478bd9Sstevel@tonic-gate */ 1834ba2be530Sab DBG_CALL(Dbg_got_display(ofl, 0, 0, 1835ba2be530Sab ld_targ.t_m.m_got_xnumber, ld_targ.t_m.m_got_entsize)); 18367c478bd9Sstevel@tonic-gate 18377c478bd9Sstevel@tonic-gate /* 18389039eeafSab * Update the section headers information. sh_info is 18399039eeafSab * supposed to contain the offset at which the first 18409039eeafSab * global symbol resides in the symbol table, while 18419039eeafSab * sh_link contains the section index of the associated 18429039eeafSab * string table. 18437c478bd9Sstevel@tonic-gate */ 18447c478bd9Sstevel@tonic-gate if (symtab) { 184560758829Srie Shdr *shdr = ofl->ofl_ossymtab->os_shdr; 18467c478bd9Sstevel@tonic-gate 1847ca4eed8bSAli Bahrami shdr->sh_info = symtab_gbl_bndx; 18487c478bd9Sstevel@tonic-gate /* LINTED */ 18497c478bd9Sstevel@tonic-gate shdr->sh_link = (Word)elf_ndxscn(ofl->ofl_osstrtab->os_scn); 18507c478bd9Sstevel@tonic-gate if (symshndx) { 18517c478bd9Sstevel@tonic-gate shdr = ofl->ofl_ossymshndx->os_shdr; 18527c478bd9Sstevel@tonic-gate shdr->sh_link = 1853d840867fSab (Word)elf_ndxscn(ofl->ofl_ossymtab->os_scn); 18547c478bd9Sstevel@tonic-gate } 1855ca4eed8bSAli Bahrami 1856ca4eed8bSAli Bahrami /* 1857ca4eed8bSAli Bahrami * Ensure that the expected number of symbols 1858ca4eed8bSAli Bahrami * were entered into the right spots: 1859ca4eed8bSAli Bahrami * - Scoped symbols in the right range 1860ca4eed8bSAli Bahrami * - Globals start at the right spot 1861ca4eed8bSAli Bahrami * (correct number of locals entered) 1862ca4eed8bSAli Bahrami * - The table is exactly filled 1863ca4eed8bSAli Bahrami * (correct number of globals entered) 1864ca4eed8bSAli Bahrami */ 1865ca4eed8bSAli Bahrami assert((scopesym_bndx + ofl->ofl_scopecnt) == scopesym_ndx); 1866ca4eed8bSAli Bahrami assert(shdr->sh_info == (ofl->ofl_shdrcnt + 1867ca4eed8bSAli Bahrami ofl->ofl_locscnt + ofl->ofl_scopecnt + 2)); 1868ca4eed8bSAli Bahrami assert((shdr->sh_info + ofl->ofl_globcnt) == symtab_ndx); 18697c478bd9Sstevel@tonic-gate } 18707c478bd9Sstevel@tonic-gate if (dynsym) { 187160758829Srie Shdr *shdr = ofl->ofl_osdynsym->os_shdr; 18727c478bd9Sstevel@tonic-gate 18739039eeafSab shdr->sh_info = 1 + ofl->ofl_dynshdrcnt + ofl->ofl_lregsymcnt; 18747c478bd9Sstevel@tonic-gate /* LINTED */ 18757c478bd9Sstevel@tonic-gate shdr->sh_link = (Word)elf_ndxscn(ofl->ofl_osdynstr->os_scn); 18767c478bd9Sstevel@tonic-gate 18777c478bd9Sstevel@tonic-gate ofl->ofl_oshash->os_shdr->sh_link = 18787c478bd9Sstevel@tonic-gate /* LINTED */ 18797c478bd9Sstevel@tonic-gate (Word)elf_ndxscn(ofl->ofl_osdynsym->os_scn); 18807c478bd9Sstevel@tonic-gate if (dynshndx) { 18817c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osdynshndx->os_shdr; 18827c478bd9Sstevel@tonic-gate shdr->sh_link = 1883d840867fSab (Word)elf_ndxscn(ofl->ofl_osdynsym->os_scn); 18847c478bd9Sstevel@tonic-gate } 18857c478bd9Sstevel@tonic-gate } 18869039eeafSab if (ldynsym) { 188760758829Srie Shdr *shdr = ofl->ofl_osldynsym->os_shdr; 18889039eeafSab 18899039eeafSab /* ldynsym has no globals, so give index one past the end */ 18909039eeafSab shdr->sh_info = ldynsym_ndx; 18919039eeafSab 18929039eeafSab /* 18939039eeafSab * The ldynsym and dynsym must be adjacent. The 18949039eeafSab * idea is that rtld should be able to start with 18959039eeafSab * the ldynsym and march straight through the end 18969039eeafSab * of dynsym, seeing them as a single symbol table, 18979039eeafSab * despite the fact that they are in distinct sections. 18989039eeafSab * Ensure that this happened correctly. 18999039eeafSab * 19009039eeafSab * Note that I use ldynsym_ndx here instead of the 19019039eeafSab * computation I used to set the section size 1902d579eb63Sab * (found in ldynsym_cnt). The two will agree, unless 1903d579eb63Sab * we somehow miscounted symbols or failed to insert them 1904d579eb63Sab * all. Using ldynsym_ndx here catches that error in 1905d579eb63Sab * addition to checking for adjacency. 19069039eeafSab */ 19079039eeafSab assert(dynsym == (ldynsym + ldynsym_ndx)); 19089039eeafSab 19099039eeafSab 19109039eeafSab /* LINTED */ 19119039eeafSab shdr->sh_link = (Word)elf_ndxscn(ofl->ofl_osdynstr->os_scn); 19129039eeafSab 19139039eeafSab if (ldynshndx) { 19149039eeafSab shdr = ofl->ofl_osldynshndx->os_shdr; 19159039eeafSab shdr->sh_link = 1916d840867fSab (Word)elf_ndxscn(ofl->ofl_osldynsym->os_scn); 19179039eeafSab } 1918d579eb63Sab 1919d579eb63Sab /* 1920d579eb63Sab * The presence of .SUNW_ldynsym means that there may be 1921d579eb63Sab * associated sort sections, one for regular symbols 1922d579eb63Sab * and the other for TLS. Each sort section needs the 1923d579eb63Sab * following done: 1924d579eb63Sab * - Section header link references .SUNW_ldynsym 1925d579eb63Sab * - Should have received the expected # of items 1926d579eb63Sab * - Sorted by increasing address 1927d579eb63Sab */ 1928d579eb63Sab if (ofl->ofl_osdynsymsort) { /* .SUNW_dynsymsort */ 1929d579eb63Sab ofl->ofl_osdynsymsort->os_shdr->sh_link = 1930d579eb63Sab (Word)elf_ndxscn(ofl->ofl_osldynsym->os_scn); 1931d579eb63Sab assert(ofl->ofl_dynsymsortcnt == dynsymsort_ndx); 193260758829Srie 1933d579eb63Sab if (dynsymsort_ndx > 1) { 1934d579eb63Sab dynsort_compare_syms = ldynsym; 1935d579eb63Sab qsort(dynsymsort, dynsymsort_ndx, 1936d579eb63Sab sizeof (*dynsymsort), dynsort_compare); 1937a194faf8Srie dynsort_dupwarn(ofl, ldynsym, 1938a194faf8Srie st_getstrbuf(dynstr), 1939d579eb63Sab dynsymsort, dynsymsort_ndx, 1940d579eb63Sab MSG_ORIG(MSG_SCN_DYNSYMSORT)); 1941d579eb63Sab } 1942d579eb63Sab } 1943d579eb63Sab if (ofl->ofl_osdyntlssort) { /* .SUNW_dyntlssort */ 1944d579eb63Sab ofl->ofl_osdyntlssort->os_shdr->sh_link = 1945d579eb63Sab (Word)elf_ndxscn(ofl->ofl_osldynsym->os_scn); 1946d579eb63Sab assert(ofl->ofl_dyntlssortcnt == dyntlssort_ndx); 194760758829Srie 1948d579eb63Sab if (dyntlssort_ndx > 1) { 1949d579eb63Sab dynsort_compare_syms = ldynsym; 1950d579eb63Sab qsort(dyntlssort, dyntlssort_ndx, 1951d579eb63Sab sizeof (*dyntlssort), dynsort_compare); 1952a194faf8Srie dynsort_dupwarn(ofl, ldynsym, 1953a194faf8Srie st_getstrbuf(dynstr), 1954d579eb63Sab dyntlssort, dyntlssort_ndx, 1955d579eb63Sab MSG_ORIG(MSG_SCN_DYNTLSSORT)); 1956d579eb63Sab } 1957d579eb63Sab } 19589039eeafSab } 19597c478bd9Sstevel@tonic-gate 19607c478bd9Sstevel@tonic-gate /* 19617c478bd9Sstevel@tonic-gate * Used by ld.so.1 only. 19627c478bd9Sstevel@tonic-gate */ 19637c478bd9Sstevel@tonic-gate return (etext); 1964d579eb63Sab 1965d579eb63Sab #undef ADD_TO_DYNSORT 19667c478bd9Sstevel@tonic-gate } 19677c478bd9Sstevel@tonic-gate 19687c478bd9Sstevel@tonic-gate /* 19697c478bd9Sstevel@tonic-gate * Build the dynamic section. 19701d9df23bSab * 19711d9df23bSab * This routine must be maintained in parallel with make_dynamic() 19721d9df23bSab * in sections.c 19737c478bd9Sstevel@tonic-gate */ 19745aefb655Srie static int 19757c478bd9Sstevel@tonic-gate update_odynamic(Ofl_desc *ofl) 19767c478bd9Sstevel@tonic-gate { 197757ef7aa9SRod Evans Aliste idx; 19787c478bd9Sstevel@tonic-gate Ifl_desc *ifl; 19797c478bd9Sstevel@tonic-gate Sym_desc *sdp; 19807c478bd9Sstevel@tonic-gate Shdr *shdr; 19817c478bd9Sstevel@tonic-gate Dyn *_dyn = (Dyn *)ofl->ofl_osdynamic->os_outdata->d_buf; 19827c478bd9Sstevel@tonic-gate Dyn *dyn; 19837c478bd9Sstevel@tonic-gate Str_tbl *dynstr; 1984cce0e03bSab size_t stoff; 19851d9df23bSab ofl_flag_t flags = ofl->ofl_flags; 19861d9df23bSab int not_relobj = !(flags & FLG_OF_RELOBJ); 19873244bcaaSab Word cnt; 19887c478bd9Sstevel@tonic-gate 19891d9df23bSab /* 19901d9df23bSab * A relocatable object with a dynamic section is possible, though 19911d9df23bSab * rare. One use for this feature is to produce drivers 19921d9df23bSab * for the kernel, loaded by krtld. 19931d9df23bSab * 19941d9df23bSab * Only a limited subset of DT_ entries apply to relocatable 19951d9df23bSab * objects: 19961d9df23bSab * 19971d9df23bSab * DT_NEEDED 19981d9df23bSab * DT_RUNPATH/DT_RPATH 19991d9df23bSab * DT_FLAGS 20001d9df23bSab * DT_FLAGS1 20011d9df23bSab * DT_SUNW_STRPAD 20021d9df23bSab * DT_LDMACH 20031d9df23bSab */ 20047c478bd9Sstevel@tonic-gate dynstr = ofl->ofl_dynstrtab; 20057c478bd9Sstevel@tonic-gate ofl->ofl_osdynamic->os_shdr->sh_link = 20067c478bd9Sstevel@tonic-gate /* LINTED */ 20077c478bd9Sstevel@tonic-gate (Word)elf_ndxscn(ofl->ofl_osdynstr->os_scn); 20087c478bd9Sstevel@tonic-gate 20097c478bd9Sstevel@tonic-gate dyn = _dyn; 20107c478bd9Sstevel@tonic-gate 201157ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_sos, idx, ifl)) { 20127c478bd9Sstevel@tonic-gate if ((ifl->ifl_flags & 20137c478bd9Sstevel@tonic-gate (FLG_IF_IGNORE | FLG_IF_DEPREQD)) == FLG_IF_IGNORE) 20147c478bd9Sstevel@tonic-gate continue; 20157c478bd9Sstevel@tonic-gate 20167c478bd9Sstevel@tonic-gate /* 20177c478bd9Sstevel@tonic-gate * Create and set up the DT_POSFLAG_1 entry here if required. 20187c478bd9Sstevel@tonic-gate */ 20197c478bd9Sstevel@tonic-gate if ((ifl->ifl_flags & (FLG_IF_LAZYLD|FLG_IF_GRPPRM)) && 20201d9df23bSab (ifl->ifl_flags & (FLG_IF_NEEDED)) && not_relobj) { 20217c478bd9Sstevel@tonic-gate dyn->d_tag = DT_POSFLAG_1; 20227c478bd9Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_LAZYLD) 20237c478bd9Sstevel@tonic-gate dyn->d_un.d_val = DF_P1_LAZYLOAD; 20247c478bd9Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_GRPPRM) 20257c478bd9Sstevel@tonic-gate dyn->d_un.d_val |= DF_P1_GROUPPERM; 20267c478bd9Sstevel@tonic-gate dyn++; 20277c478bd9Sstevel@tonic-gate } 20287c478bd9Sstevel@tonic-gate 20297c478bd9Sstevel@tonic-gate if (ifl->ifl_flags & (FLG_IF_NEEDED | FLG_IF_NEEDSTR)) 20307c478bd9Sstevel@tonic-gate dyn->d_tag = DT_NEEDED; 20317c478bd9Sstevel@tonic-gate else 20327c478bd9Sstevel@tonic-gate continue; 20337c478bd9Sstevel@tonic-gate 20347c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, ifl->ifl_soname, &stoff); 20357c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 20367c478bd9Sstevel@tonic-gate /* LINTED */ 20377c478bd9Sstevel@tonic-gate ifl->ifl_neededndx = (Half)(((uintptr_t)dyn - (uintptr_t)_dyn) / 20387c478bd9Sstevel@tonic-gate sizeof (Dyn)); 20397c478bd9Sstevel@tonic-gate dyn++; 20407c478bd9Sstevel@tonic-gate } 20417c478bd9Sstevel@tonic-gate 20421d9df23bSab if (not_relobj) { 20431d9df23bSab if (ofl->ofl_dtsfltrs != NULL) { 20441d9df23bSab Dfltr_desc *dftp; 20457c478bd9Sstevel@tonic-gate 20461d9df23bSab for (ALIST_TRAVERSE(ofl->ofl_dtsfltrs, idx, dftp)) { 20471d9df23bSab if (dftp->dft_flag == FLG_SY_AUXFLTR) 20481d9df23bSab dyn->d_tag = DT_SUNW_AUXILIARY; 20491d9df23bSab else 20501d9df23bSab dyn->d_tag = DT_SUNW_FILTER; 20517c478bd9Sstevel@tonic-gate 20521d9df23bSab (void) st_setstring(dynstr, dftp->dft_str, 20531d9df23bSab &stoff); 20541d9df23bSab dyn->d_un.d_val = stoff; 20551d9df23bSab dftp->dft_ndx = (Half)(((uintptr_t)dyn - 20561d9df23bSab (uintptr_t)_dyn) / sizeof (Dyn)); 20571d9df23bSab dyn++; 20581d9df23bSab } 20591d9df23bSab } 20601d9df23bSab if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_INIT_U), 20611d9df23bSab SYM_NOHASH, 0, ofl)) != NULL) && 20621d9df23bSab (sdp->sd_ref == REF_REL_NEED) && 20631d9df23bSab (sdp->sd_sym->st_shndx != SHN_UNDEF)) { 20641d9df23bSab dyn->d_tag = DT_INIT; 20651d9df23bSab dyn->d_un.d_ptr = sdp->sd_sym->st_value; 20661d9df23bSab dyn++; 20671d9df23bSab } 20681d9df23bSab if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_FINI_U), 20691d9df23bSab SYM_NOHASH, 0, ofl)) != NULL) && 20701d9df23bSab (sdp->sd_ref == REF_REL_NEED) && 20711d9df23bSab (sdp->sd_sym->st_shndx != SHN_UNDEF)) { 20721d9df23bSab dyn->d_tag = DT_FINI; 20731d9df23bSab dyn->d_un.d_ptr = sdp->sd_sym->st_value; 20741d9df23bSab dyn++; 20751d9df23bSab } 20761d9df23bSab if (ofl->ofl_soname) { 20771d9df23bSab dyn->d_tag = DT_SONAME; 20781d9df23bSab (void) st_setstring(dynstr, ofl->ofl_soname, &stoff); 20797c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 20807c478bd9Sstevel@tonic-gate dyn++; 20817c478bd9Sstevel@tonic-gate } 20821d9df23bSab if (ofl->ofl_filtees) { 20831d9df23bSab if (flags & FLG_OF_AUX) { 20841d9df23bSab dyn->d_tag = DT_AUXILIARY; 20851d9df23bSab } else { 20861d9df23bSab dyn->d_tag = DT_FILTER; 20871d9df23bSab } 20881d9df23bSab (void) st_setstring(dynstr, ofl->ofl_filtees, &stoff); 20891d9df23bSab dyn->d_un.d_val = stoff; 20901d9df23bSab dyn++; 20917c478bd9Sstevel@tonic-gate } 20927c478bd9Sstevel@tonic-gate } 20931d9df23bSab 20947c478bd9Sstevel@tonic-gate if (ofl->ofl_rpath) { 20957c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, ofl->ofl_rpath, &stoff); 20967c478bd9Sstevel@tonic-gate dyn->d_tag = DT_RUNPATH; 20977c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 20987c478bd9Sstevel@tonic-gate dyn++; 20997c478bd9Sstevel@tonic-gate dyn->d_tag = DT_RPATH; 21007c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 21017c478bd9Sstevel@tonic-gate dyn++; 21027c478bd9Sstevel@tonic-gate } 21037c478bd9Sstevel@tonic-gate 21041d9df23bSab if (not_relobj) { 210557ef7aa9SRod Evans Aliste idx; 210657ef7aa9SRod Evans 21071d9df23bSab if (ofl->ofl_config) { 21081d9df23bSab dyn->d_tag = DT_CONFIG; 21091d9df23bSab (void) st_setstring(dynstr, ofl->ofl_config, &stoff); 21101d9df23bSab dyn->d_un.d_val = stoff; 21111d9df23bSab dyn++; 21121d9df23bSab } 21131d9df23bSab if (ofl->ofl_depaudit) { 21141d9df23bSab dyn->d_tag = DT_DEPAUDIT; 21151d9df23bSab (void) st_setstring(dynstr, ofl->ofl_depaudit, &stoff); 21161d9df23bSab dyn->d_un.d_val = stoff; 21171d9df23bSab dyn++; 21181d9df23bSab } 21191d9df23bSab if (ofl->ofl_audit) { 21201d9df23bSab dyn->d_tag = DT_AUDIT; 21211d9df23bSab (void) st_setstring(dynstr, ofl->ofl_audit, &stoff); 21221d9df23bSab dyn->d_un.d_val = stoff; 21231d9df23bSab dyn++; 21241d9df23bSab } 21257c478bd9Sstevel@tonic-gate 21267c478bd9Sstevel@tonic-gate dyn->d_tag = DT_HASH; 21277c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = ofl->ofl_oshash->os_shdr->sh_addr; 21287c478bd9Sstevel@tonic-gate dyn++; 21297c478bd9Sstevel@tonic-gate 21307c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osdynstr->os_shdr; 21317c478bd9Sstevel@tonic-gate dyn->d_tag = DT_STRTAB; 21327c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 21337c478bd9Sstevel@tonic-gate dyn++; 21347c478bd9Sstevel@tonic-gate 21357c478bd9Sstevel@tonic-gate dyn->d_tag = DT_STRSZ; 21367c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_size; 21377c478bd9Sstevel@tonic-gate dyn++; 21387c478bd9Sstevel@tonic-gate 21397c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osdynsym->os_shdr; 21407c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SYMTAB; 21417c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 21427c478bd9Sstevel@tonic-gate dyn++; 21437c478bd9Sstevel@tonic-gate 21447c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SYMENT; 21457c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_entsize; 21467c478bd9Sstevel@tonic-gate dyn++; 21477c478bd9Sstevel@tonic-gate 21489039eeafSab if (ofl->ofl_osldynsym) { 21499039eeafSab /* 21509039eeafSab * We have arranged for the .SUNW_ldynsym data to be 21519039eeafSab * immediately in front of the .dynsym data. 21529039eeafSab * This means that you could start at the top 21539039eeafSab * of .SUNW_ldynsym and see the data for both tables 21549039eeafSab * without a break. This is the view we want to 21559039eeafSab * provide for DT_SUNW_SYMTAB, which is why we 21569039eeafSab * add the lengths together. 21579039eeafSab */ 21589039eeafSab Shdr *lshdr = ofl->ofl_osldynsym->os_shdr; 21599039eeafSab dyn->d_tag = DT_SUNW_SYMTAB; 21609039eeafSab dyn->d_un.d_ptr = lshdr->sh_addr; 21619039eeafSab dyn++; 21629039eeafSab 21639039eeafSab dyn->d_tag = DT_SUNW_SYMSZ; 21649039eeafSab dyn->d_un.d_val = lshdr->sh_size + shdr->sh_size; 21659039eeafSab dyn++; 21669039eeafSab } 21679039eeafSab 2168d579eb63Sab if (ofl->ofl_osdynsymsort || ofl->ofl_osdyntlssort) { 2169d579eb63Sab dyn->d_tag = DT_SUNW_SORTENT; 2170d579eb63Sab dyn->d_un.d_val = sizeof (Word); 2171d579eb63Sab dyn++; 2172d579eb63Sab } 2173d579eb63Sab 2174d579eb63Sab if (ofl->ofl_osdynsymsort) { 2175d579eb63Sab dyn->d_tag = DT_SUNW_SYMSORT; 2176d579eb63Sab dyn->d_un.d_ptr = 2177d579eb63Sab ofl->ofl_osdynsymsort->os_shdr->sh_addr; 2178d579eb63Sab dyn++; 2179d579eb63Sab 2180d579eb63Sab dyn->d_tag = DT_SUNW_SYMSORTSZ; 2181d579eb63Sab dyn->d_un.d_val = 2182d579eb63Sab ofl->ofl_osdynsymsort->os_shdr->sh_size; 2183d579eb63Sab dyn++; 2184d579eb63Sab } 2185d579eb63Sab 2186d579eb63Sab if (ofl->ofl_osdyntlssort) { 2187d579eb63Sab dyn->d_tag = DT_SUNW_TLSSORT; 2188d579eb63Sab dyn->d_un.d_ptr = 2189d579eb63Sab ofl->ofl_osdyntlssort->os_shdr->sh_addr; 2190d579eb63Sab dyn++; 2191d579eb63Sab 2192d579eb63Sab dyn->d_tag = DT_SUNW_TLSSORTSZ; 2193d579eb63Sab dyn->d_un.d_val = 2194d579eb63Sab ofl->ofl_osdyntlssort->os_shdr->sh_size; 2195d579eb63Sab dyn++; 2196d579eb63Sab } 2197d579eb63Sab 21987c478bd9Sstevel@tonic-gate /* 21997c478bd9Sstevel@tonic-gate * Reserve the DT_CHECKSUM entry. Its value will be filled in 22007c478bd9Sstevel@tonic-gate * after the complete image is built. 22017c478bd9Sstevel@tonic-gate */ 22027c478bd9Sstevel@tonic-gate dyn->d_tag = DT_CHECKSUM; 22037c478bd9Sstevel@tonic-gate ofl->ofl_checksum = &dyn->d_un.d_val; 22047c478bd9Sstevel@tonic-gate dyn++; 22057c478bd9Sstevel@tonic-gate 2206d840867fSab /* 2207d840867fSab * Versioning sections: DT_VERDEF and DT_VERNEED. 2208d840867fSab * 2209d840867fSab * The Solaris ld does not produce DT_VERSYM, but the GNU ld 2210d840867fSab * does, in order to support their style of versioning, which 2211d840867fSab * differs from ours: 2212d840867fSab * 2213d840867fSab * - The top bit of the 16-bit Versym index is 2214d840867fSab * not part of the version, but is interpreted 2215d840867fSab * as a "hidden bit". 2216d840867fSab * 2217d840867fSab * - External (SHN_UNDEF) symbols can have non-zero 2218d840867fSab * Versym values, which specify versions in 2219d840867fSab * referenced objects, via the Verneed section. 2220d840867fSab * 2221d840867fSab * - The vna_other field of the Vernaux structures 2222d840867fSab * found in the Verneed section are not zero as 2223d840867fSab * with Solaris, but instead contain the version 2224d840867fSab * index to be used by Versym indices to reference 2225d840867fSab * the given external version. 2226d840867fSab * 2227d840867fSab * The Solaris ld, rtld, and elfdump programs all interpret the 2228d840867fSab * presence of DT_VERSYM as meaning that GNU versioning rules 2229d840867fSab * apply to the given file. If DT_VERSYM is not present, 2230d840867fSab * then Solaris versioning rules apply. If we should ever need 2231d840867fSab * to change our ld so that it does issue DT_VERSYM, then 2232d840867fSab * this rule for detecting GNU versioning will no longer work. 2233d840867fSab * In that case, we will have to invent a way to explicitly 2234d840867fSab * specify the style of versioning in use, perhaps via a 2235d840867fSab * new dynamic entry named something like DT_SUNW_VERSIONSTYLE, 2236d840867fSab * where the d_un.d_val value specifies which style is to be 2237d840867fSab * used. 2238d840867fSab */ 22397c478bd9Sstevel@tonic-gate if ((flags & (FLG_OF_VERDEF | FLG_OF_NOVERSEC)) == 22407c478bd9Sstevel@tonic-gate FLG_OF_VERDEF) { 22417c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osverdef->os_shdr; 22427c478bd9Sstevel@tonic-gate dyn->d_tag = DT_VERDEF; 22437c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 22447c478bd9Sstevel@tonic-gate dyn++; 22457c478bd9Sstevel@tonic-gate dyn->d_tag = DT_VERDEFNUM; 22467c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_info; 22477c478bd9Sstevel@tonic-gate dyn++; 22487c478bd9Sstevel@tonic-gate } 22497c478bd9Sstevel@tonic-gate if ((flags & (FLG_OF_VERNEED | FLG_OF_NOVERSEC)) == 22507c478bd9Sstevel@tonic-gate FLG_OF_VERNEED) { 22517c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osverneed->os_shdr; 22527c478bd9Sstevel@tonic-gate dyn->d_tag = DT_VERNEED; 22537c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 22547c478bd9Sstevel@tonic-gate dyn++; 22557c478bd9Sstevel@tonic-gate dyn->d_tag = DT_VERNEEDNUM; 22567c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_info; 22577c478bd9Sstevel@tonic-gate dyn++; 22587c478bd9Sstevel@tonic-gate } 2259d840867fSab 22601d9df23bSab if ((flags & FLG_OF_COMREL) && ofl->ofl_relocrelcnt) { 2261ba2be530Sab dyn->d_tag = ld_targ.t_m.m_rel_dt_count; 22627c478bd9Sstevel@tonic-gate dyn->d_un.d_val = ofl->ofl_relocrelcnt; 22637c478bd9Sstevel@tonic-gate dyn++; 22647c478bd9Sstevel@tonic-gate } 22657c478bd9Sstevel@tonic-gate if (flags & FLG_OF_TEXTREL) { 22667c478bd9Sstevel@tonic-gate /* 22677c478bd9Sstevel@tonic-gate * Only the presence of this entry is used in this 22687c478bd9Sstevel@tonic-gate * implementation, not the value stored. 22697c478bd9Sstevel@tonic-gate */ 22707c478bd9Sstevel@tonic-gate dyn->d_tag = DT_TEXTREL; 22717c478bd9Sstevel@tonic-gate dyn->d_un.d_val = 0; 22727c478bd9Sstevel@tonic-gate dyn++; 22737c478bd9Sstevel@tonic-gate } 22747c478bd9Sstevel@tonic-gate 22757c478bd9Sstevel@tonic-gate if (ofl->ofl_osfiniarray) { 22767c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osfiniarray->os_shdr; 22777c478bd9Sstevel@tonic-gate 22787c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FINI_ARRAY; 22797c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 22807c478bd9Sstevel@tonic-gate dyn++; 22817c478bd9Sstevel@tonic-gate 22827c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FINI_ARRAYSZ; 22837c478bd9Sstevel@tonic-gate dyn->d_un.d_val = shdr->sh_size; 22847c478bd9Sstevel@tonic-gate dyn++; 22857c478bd9Sstevel@tonic-gate } 22867c478bd9Sstevel@tonic-gate 22877c478bd9Sstevel@tonic-gate if (ofl->ofl_osinitarray) { 22887c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osinitarray->os_shdr; 22897c478bd9Sstevel@tonic-gate 22907c478bd9Sstevel@tonic-gate dyn->d_tag = DT_INIT_ARRAY; 22917c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 22927c478bd9Sstevel@tonic-gate dyn++; 22937c478bd9Sstevel@tonic-gate 22947c478bd9Sstevel@tonic-gate dyn->d_tag = DT_INIT_ARRAYSZ; 22957c478bd9Sstevel@tonic-gate dyn->d_un.d_val = shdr->sh_size; 22967c478bd9Sstevel@tonic-gate dyn++; 22977c478bd9Sstevel@tonic-gate } 22987c478bd9Sstevel@tonic-gate 22997c478bd9Sstevel@tonic-gate if (ofl->ofl_ospreinitarray) { 23007c478bd9Sstevel@tonic-gate shdr = ofl->ofl_ospreinitarray->os_shdr; 23017c478bd9Sstevel@tonic-gate 23027c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PREINIT_ARRAY; 23037c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 23047c478bd9Sstevel@tonic-gate dyn++; 23057c478bd9Sstevel@tonic-gate 23067c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PREINIT_ARRAYSZ; 23077c478bd9Sstevel@tonic-gate dyn->d_un.d_val = shdr->sh_size; 23087c478bd9Sstevel@tonic-gate dyn++; 23097c478bd9Sstevel@tonic-gate } 23107c478bd9Sstevel@tonic-gate 23117c478bd9Sstevel@tonic-gate if (ofl->ofl_pltcnt) { 23127c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osplt->os_relosdesc->os_shdr; 23137c478bd9Sstevel@tonic-gate 23147c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PLTRELSZ; 23157c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_size; 23167c478bd9Sstevel@tonic-gate dyn++; 23177c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PLTREL; 2318ba2be530Sab dyn->d_un.d_ptr = ld_targ.t_m.m_rel_dt_type; 23197c478bd9Sstevel@tonic-gate dyn++; 23207c478bd9Sstevel@tonic-gate dyn->d_tag = DT_JMPREL; 23217c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 23227c478bd9Sstevel@tonic-gate dyn++; 23237c478bd9Sstevel@tonic-gate } 23247c478bd9Sstevel@tonic-gate if (ofl->ofl_pltpad) { 23257c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osplt->os_shdr; 23267c478bd9Sstevel@tonic-gate 23277c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PLTPAD; 232860758829Srie if (ofl->ofl_pltcnt) { 23297c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr + 2330ba2be530Sab ld_targ.t_m.m_plt_reservsz + 2331ba2be530Sab ofl->ofl_pltcnt * ld_targ.t_m.m_plt_entsize; 233260758829Srie } else 23337c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 23347c478bd9Sstevel@tonic-gate dyn++; 23357c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PLTPADSZ; 2336ba2be530Sab dyn->d_un.d_val = ofl->ofl_pltpad * 2337ba2be530Sab ld_targ.t_m.m_plt_entsize; 23387c478bd9Sstevel@tonic-gate dyn++; 23397c478bd9Sstevel@tonic-gate } 23407c478bd9Sstevel@tonic-gate if (ofl->ofl_relocsz) { 2341ba2be530Sab dyn->d_tag = ld_targ.t_m.m_rel_dt_type; 23427c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = ofl->ofl_osrelhead->os_shdr->sh_addr; 23437c478bd9Sstevel@tonic-gate dyn++; 2344ba2be530Sab dyn->d_tag = ld_targ.t_m.m_rel_dt_size; 23457c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = ofl->ofl_relocsz; 23467c478bd9Sstevel@tonic-gate dyn++; 2347ba2be530Sab dyn->d_tag = ld_targ.t_m.m_rel_dt_ent; 23487c478bd9Sstevel@tonic-gate if (ofl->ofl_osrelhead->os_shdr->sh_type == SHT_REL) 23497c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = sizeof (Rel); 23507c478bd9Sstevel@tonic-gate else 23517c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = sizeof (Rela); 23527c478bd9Sstevel@tonic-gate dyn++; 23537c478bd9Sstevel@tonic-gate } 23547c478bd9Sstevel@tonic-gate if (ofl->ofl_ossyminfo) { 23557c478bd9Sstevel@tonic-gate shdr = ofl->ofl_ossyminfo->os_shdr; 23567c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SYMINFO; 23577c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 23587c478bd9Sstevel@tonic-gate dyn++; 23597c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SYMINSZ; 23607c478bd9Sstevel@tonic-gate dyn->d_un.d_val = shdr->sh_size; 23617c478bd9Sstevel@tonic-gate dyn++; 23627c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SYMINENT; 23637c478bd9Sstevel@tonic-gate dyn->d_un.d_val = sizeof (Syminfo); 23647c478bd9Sstevel@tonic-gate dyn++; 23657c478bd9Sstevel@tonic-gate } 23667c478bd9Sstevel@tonic-gate if (ofl->ofl_osmove) { 236757ef7aa9SRod Evans Os_desc *osp; 23687c478bd9Sstevel@tonic-gate 23697c478bd9Sstevel@tonic-gate dyn->d_tag = DT_MOVEENT; 23707c478bd9Sstevel@tonic-gate osp = ofl->ofl_osmove; 23717c478bd9Sstevel@tonic-gate dyn->d_un.d_val = osp->os_shdr->sh_entsize; 23727c478bd9Sstevel@tonic-gate dyn++; 23737c478bd9Sstevel@tonic-gate dyn->d_tag = DT_MOVESZ; 23747c478bd9Sstevel@tonic-gate dyn->d_un.d_val = osp->os_shdr->sh_size; 23757c478bd9Sstevel@tonic-gate dyn++; 23767c478bd9Sstevel@tonic-gate dyn->d_tag = DT_MOVETAB; 23777c478bd9Sstevel@tonic-gate dyn->d_un.d_val = osp->os_shdr->sh_addr; 23787c478bd9Sstevel@tonic-gate dyn++; 23797c478bd9Sstevel@tonic-gate } 23807c478bd9Sstevel@tonic-gate if (ofl->ofl_regsymcnt) { 23817c478bd9Sstevel@tonic-gate int ndx; 23827c478bd9Sstevel@tonic-gate 23837c478bd9Sstevel@tonic-gate for (ndx = 0; ndx < ofl->ofl_regsymsno; ndx++) { 238457ef7aa9SRod Evans if ((sdp = ofl->ofl_regsyms[ndx]) == NULL) 23857c478bd9Sstevel@tonic-gate continue; 23867c478bd9Sstevel@tonic-gate 2387ba2be530Sab dyn->d_tag = ld_targ.t_m.m_dt_register; 23887c478bd9Sstevel@tonic-gate dyn->d_un.d_val = sdp->sd_symndx; 23897c478bd9Sstevel@tonic-gate dyn++; 23907c478bd9Sstevel@tonic-gate } 23917c478bd9Sstevel@tonic-gate } 23927c478bd9Sstevel@tonic-gate 239357ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_rtldinfo, idx, sdp)) { 23947c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SUNW_RTLDINF; 23957c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = sdp->sd_sym->st_value; 23967c478bd9Sstevel@tonic-gate dyn++; 23977c478bd9Sstevel@tonic-gate } 23987c478bd9Sstevel@tonic-gate 23997c478bd9Sstevel@tonic-gate if (ofl->ofl_osdynamic->os_sgdesc && 24007c478bd9Sstevel@tonic-gate (ofl->ofl_osdynamic->os_sgdesc->sg_phdr.p_flags & PF_W)) { 24017c478bd9Sstevel@tonic-gate if (ofl->ofl_osinterp) { 24027c478bd9Sstevel@tonic-gate dyn->d_tag = DT_DEBUG; 24037c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = 0; 24047c478bd9Sstevel@tonic-gate dyn++; 24057c478bd9Sstevel@tonic-gate } 24067c478bd9Sstevel@tonic-gate 24077c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FEATURE_1; 24087c478bd9Sstevel@tonic-gate if (ofl->ofl_osmove) 24097c478bd9Sstevel@tonic-gate dyn->d_un.d_val = 0; 24107c478bd9Sstevel@tonic-gate else 24117c478bd9Sstevel@tonic-gate dyn->d_un.d_val = DTF_1_PARINIT; 24127c478bd9Sstevel@tonic-gate dyn++; 24137c478bd9Sstevel@tonic-gate } 24147c478bd9Sstevel@tonic-gate 24157c478bd9Sstevel@tonic-gate if (ofl->ofl_oscap) { 24167c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SUNW_CAP; 24177c478bd9Sstevel@tonic-gate dyn->d_un.d_val = ofl->ofl_oscap->os_shdr->sh_addr; 24187c478bd9Sstevel@tonic-gate dyn++; 24197c478bd9Sstevel@tonic-gate } 24207c478bd9Sstevel@tonic-gate 24211d9df23bSab if (flags & FLG_OF_SYMBOLIC) { 24221d9df23bSab dyn->d_tag = DT_SYMBOLIC; 24231d9df23bSab dyn->d_un.d_val = 0; 24241d9df23bSab dyn++; 24251d9df23bSab } 24267c478bd9Sstevel@tonic-gate } 24271d9df23bSab 24287c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FLAGS; 24297c478bd9Sstevel@tonic-gate dyn->d_un.d_val = ofl->ofl_dtflags; 24307c478bd9Sstevel@tonic-gate dyn++; 24317c478bd9Sstevel@tonic-gate 24327c478bd9Sstevel@tonic-gate /* 24337c478bd9Sstevel@tonic-gate * If -Bdirect was specified, but some NODIRECT symbols were specified 24347c478bd9Sstevel@tonic-gate * via a mapfile, or -znodirect was used on the command line, then 24357c478bd9Sstevel@tonic-gate * clear the DF_1_DIRECT flag. The resultant object will use per-symbol 24367c478bd9Sstevel@tonic-gate * direct bindings rather than be enabled for global direct bindings. 2437*28bda19cSRod Evans * 2438*28bda19cSRod Evans * If any no-direct bindings exist within this object, set the 2439*28bda19cSRod Evans * DF_1_NODIRECT flag. ld(1) recognizes this flag when processing 2440*28bda19cSRod Evans * dependencies, and performs extra work to ensure that no direct 2441*28bda19cSRod Evans * bindings are established to the no-direct symbols that exist 2442*28bda19cSRod Evans * within these dependencies. 24437c478bd9Sstevel@tonic-gate */ 2444*28bda19cSRod Evans if (ofl->ofl_flags1 & FLG_OF1_NGLBDIR) 24457c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 &= ~DF_1_DIRECT; 2446*28bda19cSRod Evans if (ofl->ofl_flags1 & FLG_OF1_NDIRECT) 244760758829Srie ofl->ofl_dtflags_1 |= DF_1_NODIRECT; 24487c478bd9Sstevel@tonic-gate 24497c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FLAGS_1; 24507c478bd9Sstevel@tonic-gate dyn->d_un.d_val = ofl->ofl_dtflags_1; 24517c478bd9Sstevel@tonic-gate dyn++; 24527c478bd9Sstevel@tonic-gate 24533244bcaaSab dyn->d_tag = DT_SUNW_STRPAD; 24543244bcaaSab dyn->d_un.d_val = DYNSTR_EXTRA_PAD; 24553244bcaaSab dyn++; 24563244bcaaSab 2457ba2be530Sab dyn->d_tag = DT_SUNW_LDMACH; 2458ba2be530Sab dyn->d_un.d_val = ld_sunw_ldmach(); 2459ba2be530Sab dyn++; 2460ba2be530Sab 2461ba2be530Sab (*ld_targ.t_mr.mr_mach_update_odynamic)(ofl, &dyn); 24627c478bd9Sstevel@tonic-gate 24633244bcaaSab for (cnt = 1 + DYNAMIC_EXTRA_ELTS; cnt--; dyn++) { 24643244bcaaSab dyn->d_tag = DT_NULL; 24653244bcaaSab dyn->d_un.d_val = 0; 24663244bcaaSab } 24677c478bd9Sstevel@tonic-gate 24685b59e4caSab /* 24695b59e4caSab * Ensure that we wrote the right number of entries. If not, 24705b59e4caSab * we either miscounted in make_dynamic(), or we did something wrong 24715b59e4caSab * in this function. 24725b59e4caSab */ 24735b59e4caSab assert((ofl->ofl_osdynamic->os_shdr->sh_size / 24745b59e4caSab ofl->ofl_osdynamic->os_shdr->sh_entsize) == 24753244bcaaSab ((uintptr_t)dyn - (uintptr_t)_dyn) / sizeof (*dyn)); 24765b59e4caSab 24777c478bd9Sstevel@tonic-gate return (1); 24787c478bd9Sstevel@tonic-gate } 24797c478bd9Sstevel@tonic-gate 24807c478bd9Sstevel@tonic-gate /* 24817c478bd9Sstevel@tonic-gate * Build the version definition section 24827c478bd9Sstevel@tonic-gate */ 24835aefb655Srie static int 24847c478bd9Sstevel@tonic-gate update_overdef(Ofl_desc *ofl) 24857c478bd9Sstevel@tonic-gate { 248657ef7aa9SRod Evans Aliste idx1; 24877c478bd9Sstevel@tonic-gate Ver_desc *vdp, *_vdp; 24887c478bd9Sstevel@tonic-gate Verdef *vdf, *_vdf; 24897c478bd9Sstevel@tonic-gate int num = 0; 2490090a8d9eSAli Bahrami Os_desc *strosp; 24917c478bd9Sstevel@tonic-gate 24927c478bd9Sstevel@tonic-gate /* 24937c478bd9Sstevel@tonic-gate * Traverse the version descriptors and update the version structures 24947c478bd9Sstevel@tonic-gate * to point to the dynstr name in preparation for building the version 24957c478bd9Sstevel@tonic-gate * section structure. 24967c478bd9Sstevel@tonic-gate */ 249757ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_verdesc, idx1, vdp)) { 249857ef7aa9SRod Evans Sym_desc *sdp; 24997c478bd9Sstevel@tonic-gate 25007c478bd9Sstevel@tonic-gate if (vdp->vd_flags & VER_FLG_BASE) { 25017c478bd9Sstevel@tonic-gate const char *name = vdp->vd_name; 2502cce0e03bSab size_t stoff; 25037c478bd9Sstevel@tonic-gate 25047c478bd9Sstevel@tonic-gate /* 25057c478bd9Sstevel@tonic-gate * Create a new string table entry to represent the base 25067c478bd9Sstevel@tonic-gate * version name (there is no corresponding symbol for 25077c478bd9Sstevel@tonic-gate * this). 25087c478bd9Sstevel@tonic-gate */ 25097c478bd9Sstevel@tonic-gate if (!(ofl->ofl_flags & FLG_OF_DYNAMIC)) { 25107c478bd9Sstevel@tonic-gate (void) st_setstring(ofl->ofl_strtab, 2511d840867fSab name, &stoff); 25127c478bd9Sstevel@tonic-gate /* LINTED */ 2513cce0e03bSab vdp->vd_name = (const char *)stoff; 25147c478bd9Sstevel@tonic-gate } else { 25157c478bd9Sstevel@tonic-gate (void) st_setstring(ofl->ofl_dynstrtab, 2516d840867fSab name, &stoff); 25177c478bd9Sstevel@tonic-gate /* LINTED */ 2518cce0e03bSab vdp->vd_name = (const char *)stoff; 25197c478bd9Sstevel@tonic-gate } 25207c478bd9Sstevel@tonic-gate } else { 25215aefb655Srie sdp = ld_sym_find(vdp->vd_name, vdp->vd_hash, 0, ofl); 25227c478bd9Sstevel@tonic-gate /* LINTED */ 25237c478bd9Sstevel@tonic-gate vdp->vd_name = (const char *) 2524d840867fSab (uintptr_t)sdp->sd_sym->st_name; 25257c478bd9Sstevel@tonic-gate } 25267c478bd9Sstevel@tonic-gate } 25277c478bd9Sstevel@tonic-gate 25287c478bd9Sstevel@tonic-gate _vdf = vdf = (Verdef *)ofl->ofl_osverdef->os_outdata->d_buf; 25297c478bd9Sstevel@tonic-gate 25307c478bd9Sstevel@tonic-gate /* 25317c478bd9Sstevel@tonic-gate * Traverse the version descriptors and update the version section to 25327c478bd9Sstevel@tonic-gate * reflect each version and its associated dependencies. 25337c478bd9Sstevel@tonic-gate */ 253457ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_verdesc, idx1, vdp)) { 253557ef7aa9SRod Evans Aliste idx2; 25367c478bd9Sstevel@tonic-gate Half cnt = 1; 253757ef7aa9SRod Evans Verdaux *vdap, *_vdap; 25387c478bd9Sstevel@tonic-gate 25397c478bd9Sstevel@tonic-gate _vdap = vdap = (Verdaux *)(vdf + 1); 25407c478bd9Sstevel@tonic-gate 25417c478bd9Sstevel@tonic-gate vdf->vd_version = VER_DEF_CURRENT; 25427c478bd9Sstevel@tonic-gate vdf->vd_flags = vdp->vd_flags & MSK_VER_USER; 25437c478bd9Sstevel@tonic-gate vdf->vd_ndx = vdp->vd_ndx; 25447c478bd9Sstevel@tonic-gate vdf->vd_hash = vdp->vd_hash; 25457c478bd9Sstevel@tonic-gate 25467c478bd9Sstevel@tonic-gate /* LINTED */ 25477c478bd9Sstevel@tonic-gate vdap->vda_name = (uintptr_t)vdp->vd_name; 25487c478bd9Sstevel@tonic-gate vdap++; 25497c478bd9Sstevel@tonic-gate /* LINTED */ 25507c478bd9Sstevel@tonic-gate _vdap->vda_next = (Word)((uintptr_t)vdap - (uintptr_t)_vdap); 25517c478bd9Sstevel@tonic-gate 25527c478bd9Sstevel@tonic-gate /* 25537c478bd9Sstevel@tonic-gate * Traverse this versions dependency list generating the 25547c478bd9Sstevel@tonic-gate * appropriate version dependency entries. 25557c478bd9Sstevel@tonic-gate */ 255657ef7aa9SRod Evans for (APLIST_TRAVERSE(vdp->vd_deps, idx2, _vdp)) { 25577c478bd9Sstevel@tonic-gate /* LINTED */ 25587c478bd9Sstevel@tonic-gate vdap->vda_name = (uintptr_t)_vdp->vd_name; 25597c478bd9Sstevel@tonic-gate _vdap = vdap; 25607c478bd9Sstevel@tonic-gate vdap++, cnt++; 25617c478bd9Sstevel@tonic-gate /* LINTED */ 25627c478bd9Sstevel@tonic-gate _vdap->vda_next = (Word)((uintptr_t)vdap - 25637c478bd9Sstevel@tonic-gate (uintptr_t)_vdap); 25647c478bd9Sstevel@tonic-gate } 25657c478bd9Sstevel@tonic-gate _vdap->vda_next = 0; 25667c478bd9Sstevel@tonic-gate 25677c478bd9Sstevel@tonic-gate /* 25687c478bd9Sstevel@tonic-gate * Record the versions auxiliary array offset and the associated 25697c478bd9Sstevel@tonic-gate * dependency count. 25707c478bd9Sstevel@tonic-gate */ 25717c478bd9Sstevel@tonic-gate /* LINTED */ 25727c478bd9Sstevel@tonic-gate vdf->vd_aux = (Word)((uintptr_t)(vdf + 1) - (uintptr_t)vdf); 25737c478bd9Sstevel@tonic-gate vdf->vd_cnt = cnt; 25747c478bd9Sstevel@tonic-gate 25757c478bd9Sstevel@tonic-gate /* 25767c478bd9Sstevel@tonic-gate * Record the next versions offset and update the version 25777c478bd9Sstevel@tonic-gate * pointer. Remember the previous version offset as the very 25787c478bd9Sstevel@tonic-gate * last structures next pointer should be null. 25797c478bd9Sstevel@tonic-gate */ 25807c478bd9Sstevel@tonic-gate _vdf = vdf; 25817c478bd9Sstevel@tonic-gate vdf = (Verdef *)vdap, num++; 25827c478bd9Sstevel@tonic-gate /* LINTED */ 25837c478bd9Sstevel@tonic-gate _vdf->vd_next = (Word)((uintptr_t)vdf - (uintptr_t)_vdf); 25847c478bd9Sstevel@tonic-gate } 25857c478bd9Sstevel@tonic-gate _vdf->vd_next = 0; 25867c478bd9Sstevel@tonic-gate 25877c478bd9Sstevel@tonic-gate /* 25887c478bd9Sstevel@tonic-gate * Record the string table association with the version definition 25897c478bd9Sstevel@tonic-gate * section, and the symbol table associated with the version symbol 25907c478bd9Sstevel@tonic-gate * table (the actual contents of the version symbol table are filled 25917c478bd9Sstevel@tonic-gate * in during symbol update). 25927c478bd9Sstevel@tonic-gate */ 25937c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_RELOBJ) || 25947c478bd9Sstevel@tonic-gate (ofl->ofl_flags & FLG_OF_STATIC)) { 25957c478bd9Sstevel@tonic-gate strosp = ofl->ofl_osstrtab; 25967c478bd9Sstevel@tonic-gate } else { 25977c478bd9Sstevel@tonic-gate strosp = ofl->ofl_osdynstr; 25987c478bd9Sstevel@tonic-gate } 25997c478bd9Sstevel@tonic-gate /* LINTED */ 26007c478bd9Sstevel@tonic-gate ofl->ofl_osverdef->os_shdr->sh_link = (Word)elf_ndxscn(strosp->os_scn); 26017c478bd9Sstevel@tonic-gate 26027c478bd9Sstevel@tonic-gate /* 26037c478bd9Sstevel@tonic-gate * The version definition sections `info' field is used to indicate the 26047c478bd9Sstevel@tonic-gate * number of entries in this section. 26057c478bd9Sstevel@tonic-gate */ 26067c478bd9Sstevel@tonic-gate ofl->ofl_osverdef->os_shdr->sh_info = num; 26077c478bd9Sstevel@tonic-gate 26087c478bd9Sstevel@tonic-gate return (1); 26097c478bd9Sstevel@tonic-gate } 26107c478bd9Sstevel@tonic-gate 2611090a8d9eSAli Bahrami /* 2612090a8d9eSAli Bahrami * Finish the version symbol index section 2613090a8d9eSAli Bahrami */ 2614090a8d9eSAli Bahrami static int 2615090a8d9eSAli Bahrami update_oversym(Ofl_desc *ofl) 2616090a8d9eSAli Bahrami { 2617090a8d9eSAli Bahrami Os_desc *symosp; 2618090a8d9eSAli Bahrami 2619090a8d9eSAli Bahrami /* 2620090a8d9eSAli Bahrami * Record the string table association with the version definition 2621090a8d9eSAli Bahrami * section, and the symbol table associated with the version symbol 2622090a8d9eSAli Bahrami * table (the actual contents of the version symbol table are filled 2623090a8d9eSAli Bahrami * in during symbol update). 2624090a8d9eSAli Bahrami */ 2625090a8d9eSAli Bahrami if ((ofl->ofl_flags & FLG_OF_RELOBJ) || 2626090a8d9eSAli Bahrami (ofl->ofl_flags & FLG_OF_STATIC)) { 2627090a8d9eSAli Bahrami symosp = ofl->ofl_ossymtab; 2628090a8d9eSAli Bahrami } else { 2629090a8d9eSAli Bahrami symosp = ofl->ofl_osdynsym; 2630090a8d9eSAli Bahrami } 2631090a8d9eSAli Bahrami 2632090a8d9eSAli Bahrami /* LINTED */ 2633090a8d9eSAli Bahrami ofl->ofl_osversym->os_shdr->sh_link = (Word)elf_ndxscn(symosp->os_scn); 2634090a8d9eSAli Bahrami 2635090a8d9eSAli Bahrami return (1); 2636090a8d9eSAli Bahrami } 2637090a8d9eSAli Bahrami 26387c478bd9Sstevel@tonic-gate /* 26397c478bd9Sstevel@tonic-gate * Build the version needed section 26407c478bd9Sstevel@tonic-gate */ 26415aefb655Srie static int 26427c478bd9Sstevel@tonic-gate update_overneed(Ofl_desc *ofl) 26437c478bd9Sstevel@tonic-gate { 264457ef7aa9SRod Evans Aliste idx1; 26457c478bd9Sstevel@tonic-gate Ifl_desc *ifl; 26467c478bd9Sstevel@tonic-gate Verneed *vnd, *_vnd; 26477c478bd9Sstevel@tonic-gate Str_tbl *dynstr; 2648090a8d9eSAli Bahrami Word num = 0; 26497c478bd9Sstevel@tonic-gate 26507c478bd9Sstevel@tonic-gate dynstr = ofl->ofl_dynstrtab; 26517c478bd9Sstevel@tonic-gate _vnd = vnd = (Verneed *)ofl->ofl_osverneed->os_outdata->d_buf; 26527c478bd9Sstevel@tonic-gate 26537c478bd9Sstevel@tonic-gate /* 26547c478bd9Sstevel@tonic-gate * Traverse the shared object list looking for dependencies that have 26557c478bd9Sstevel@tonic-gate * versions defined within them. 26567c478bd9Sstevel@tonic-gate */ 265757ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_sos, idx1, ifl)) { 26587c478bd9Sstevel@tonic-gate Half _cnt; 2659090a8d9eSAli Bahrami Word cnt = 0; 26607c478bd9Sstevel@tonic-gate Vernaux *_vnap, *vnap; 2661cce0e03bSab size_t stoff; 26627c478bd9Sstevel@tonic-gate 26637c478bd9Sstevel@tonic-gate if (!(ifl->ifl_flags & FLG_IF_VERNEED)) 26647c478bd9Sstevel@tonic-gate continue; 26657c478bd9Sstevel@tonic-gate 26667c478bd9Sstevel@tonic-gate vnd->vn_version = VER_NEED_CURRENT; 26677c478bd9Sstevel@tonic-gate 26687c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, ifl->ifl_soname, &stoff); 26697c478bd9Sstevel@tonic-gate vnd->vn_file = stoff; 26707c478bd9Sstevel@tonic-gate 26717c478bd9Sstevel@tonic-gate _vnap = vnap = (Vernaux *)(vnd + 1); 26727c478bd9Sstevel@tonic-gate 2673090a8d9eSAli Bahrami /* 2674090a8d9eSAli Bahrami * Traverse the version index list recording 2675090a8d9eSAli Bahrami * each version as a needed dependency. 2676090a8d9eSAli Bahrami */ 2677090a8d9eSAli Bahrami for (_cnt = 0; _cnt <= ifl->ifl_vercnt; _cnt++) { 2678090a8d9eSAli Bahrami Ver_index *vip = &ifl->ifl_verndx[_cnt]; 26797c478bd9Sstevel@tonic-gate 2680090a8d9eSAli Bahrami if (vip->vi_flags & FLG_VER_REFER) { 2681090a8d9eSAli Bahrami (void) st_setstring(dynstr, vip->vi_name, 2682090a8d9eSAli Bahrami &stoff); 2683090a8d9eSAli Bahrami vnap->vna_name = stoff; 2684090a8d9eSAli Bahrami 2685090a8d9eSAli Bahrami if (vip->vi_desc) { 2686090a8d9eSAli Bahrami vnap->vna_hash = vip->vi_desc->vd_hash; 2687090a8d9eSAli Bahrami vnap->vna_flags = 2688090a8d9eSAli Bahrami vip->vi_desc->vd_flags; 2689090a8d9eSAli Bahrami } else { 2690090a8d9eSAli Bahrami vnap->vna_hash = 0; 2691090a8d9eSAli Bahrami vnap->vna_flags = 0; 26927c478bd9Sstevel@tonic-gate } 2693090a8d9eSAli Bahrami vnap->vna_other = vip->vi_overndx; 2694090a8d9eSAli Bahrami 2695090a8d9eSAli Bahrami /* 2696090a8d9eSAli Bahrami * If version A inherits version B, then 2697090a8d9eSAli Bahrami * B is implicit in A. It suffices for ld.so.1 2698090a8d9eSAli Bahrami * to verify A at runtime and skip B. The 2699090a8d9eSAli Bahrami * version normalization process sets the INFO 2700090a8d9eSAli Bahrami * flag for the versions we want ld.so.1 to 27014a8d0ea7SAli Bahrami * skip. 2702090a8d9eSAli Bahrami */ 27034a8d0ea7SAli Bahrami if (vip->vi_flags & VER_FLG_INFO) 2704090a8d9eSAli Bahrami vnap->vna_flags |= VER_FLG_INFO; 2705090a8d9eSAli Bahrami 2706090a8d9eSAli Bahrami _vnap = vnap; 2707090a8d9eSAli Bahrami vnap++, cnt++; 2708090a8d9eSAli Bahrami _vnap->vna_next = 2709090a8d9eSAli Bahrami /* LINTED */ 2710090a8d9eSAli Bahrami (Word)((uintptr_t)vnap - (uintptr_t)_vnap); 27117c478bd9Sstevel@tonic-gate } 27127c478bd9Sstevel@tonic-gate } 2713090a8d9eSAli Bahrami 27147c478bd9Sstevel@tonic-gate _vnap->vna_next = 0; 27157c478bd9Sstevel@tonic-gate 27167c478bd9Sstevel@tonic-gate /* 27177c478bd9Sstevel@tonic-gate * Record the versions auxiliary array offset and 27187c478bd9Sstevel@tonic-gate * the associated dependency count. 27197c478bd9Sstevel@tonic-gate */ 27207c478bd9Sstevel@tonic-gate /* LINTED */ 27217c478bd9Sstevel@tonic-gate vnd->vn_aux = (Word)((uintptr_t)(vnd + 1) - (uintptr_t)vnd); 27227c478bd9Sstevel@tonic-gate /* LINTED */ 27237c478bd9Sstevel@tonic-gate vnd->vn_cnt = (Half)cnt; 27247c478bd9Sstevel@tonic-gate 27257c478bd9Sstevel@tonic-gate /* 27267c478bd9Sstevel@tonic-gate * Record the next versions offset and update the version 27277c478bd9Sstevel@tonic-gate * pointer. Remember the previous version offset as the very 27287c478bd9Sstevel@tonic-gate * last structures next pointer should be null. 27297c478bd9Sstevel@tonic-gate */ 27307c478bd9Sstevel@tonic-gate _vnd = vnd; 27317c478bd9Sstevel@tonic-gate vnd = (Verneed *)vnap, num++; 27327c478bd9Sstevel@tonic-gate /* LINTED */ 27337c478bd9Sstevel@tonic-gate _vnd->vn_next = (Word)((uintptr_t)vnd - (uintptr_t)_vnd); 27347c478bd9Sstevel@tonic-gate } 27357c478bd9Sstevel@tonic-gate _vnd->vn_next = 0; 27367c478bd9Sstevel@tonic-gate 27377c478bd9Sstevel@tonic-gate /* 27387c478bd9Sstevel@tonic-gate * Record association on string table section and use the 27397c478bd9Sstevel@tonic-gate * `info' field to indicate the number of entries in this 27407c478bd9Sstevel@tonic-gate * section. 27417c478bd9Sstevel@tonic-gate */ 27427c478bd9Sstevel@tonic-gate ofl->ofl_osverneed->os_shdr->sh_link = 27437c478bd9Sstevel@tonic-gate /* LINTED */ 27447c478bd9Sstevel@tonic-gate (Word)elf_ndxscn(ofl->ofl_osdynstr->os_scn); 27457c478bd9Sstevel@tonic-gate ofl->ofl_osverneed->os_shdr->sh_info = num; 27467c478bd9Sstevel@tonic-gate 27477c478bd9Sstevel@tonic-gate return (1); 27487c478bd9Sstevel@tonic-gate } 27497c478bd9Sstevel@tonic-gate 27507c478bd9Sstevel@tonic-gate 27517c478bd9Sstevel@tonic-gate /* 27527c478bd9Sstevel@tonic-gate * Update syminfo section. 27537c478bd9Sstevel@tonic-gate */ 27545aefb655Srie static uintptr_t 275557ef7aa9SRod Evans update_osyminfo(Ofl_desc *ofl) 27567c478bd9Sstevel@tonic-gate { 275757ef7aa9SRod Evans Os_desc *symosp, *infosp = ofl->ofl_ossyminfo; 275857ef7aa9SRod Evans Syminfo *sip = infosp->os_outdata->d_buf; 275957ef7aa9SRod Evans Shdr *shdr = infosp->os_shdr; 27607c478bd9Sstevel@tonic-gate char *strtab; 2761cce0e03bSab Aliste idx; 276257ef7aa9SRod Evans Sym_desc *sdp; 276357ef7aa9SRod Evans Sfltr_desc *sftp; 27647c478bd9Sstevel@tonic-gate 27657c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_RELOBJ) { 27667c478bd9Sstevel@tonic-gate symosp = ofl->ofl_ossymtab; 27677c478bd9Sstevel@tonic-gate strtab = ofl->ofl_osstrtab->os_outdata->d_buf; 27687c478bd9Sstevel@tonic-gate } else { 27697c478bd9Sstevel@tonic-gate symosp = ofl->ofl_osdynsym; 27707c478bd9Sstevel@tonic-gate strtab = ofl->ofl_osdynstr->os_outdata->d_buf; 27717c478bd9Sstevel@tonic-gate } 27727c478bd9Sstevel@tonic-gate 27737c478bd9Sstevel@tonic-gate /* LINTED */ 27747c478bd9Sstevel@tonic-gate infosp->os_shdr->sh_link = (Word)elf_ndxscn(symosp->os_scn); 27757c478bd9Sstevel@tonic-gate if (ofl->ofl_osdynamic) 27767c478bd9Sstevel@tonic-gate infosp->os_shdr->sh_info = 27777c478bd9Sstevel@tonic-gate /* LINTED */ 27787c478bd9Sstevel@tonic-gate (Word)elf_ndxscn(ofl->ofl_osdynamic->os_scn); 27797c478bd9Sstevel@tonic-gate 27807c478bd9Sstevel@tonic-gate /* 27817c478bd9Sstevel@tonic-gate * Update any references with the index into the dynamic table. 27827c478bd9Sstevel@tonic-gate */ 278357ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_syminfsyms, idx, sdp)) { 278457ef7aa9SRod Evans Ifl_desc *ifl; 278557ef7aa9SRod Evans 27867c478bd9Sstevel@tonic-gate if (sdp->sd_aux && sdp->sd_aux->sa_bindto) 27877c478bd9Sstevel@tonic-gate ifl = sdp->sd_aux->sa_bindto; 27887c478bd9Sstevel@tonic-gate else 27897c478bd9Sstevel@tonic-gate ifl = sdp->sd_file; 27907c478bd9Sstevel@tonic-gate sip[sdp->sd_symndx].si_boundto = ifl->ifl_neededndx; 27917c478bd9Sstevel@tonic-gate } 27927c478bd9Sstevel@tonic-gate 27937c478bd9Sstevel@tonic-gate /* 27947c478bd9Sstevel@tonic-gate * Update any filtee references with the index into the dynamic table. 27957c478bd9Sstevel@tonic-gate */ 2796cce0e03bSab for (ALIST_TRAVERSE(ofl->ofl_symfltrs, idx, sftp)) { 2797cce0e03bSab Dfltr_desc *dftp; 27987c478bd9Sstevel@tonic-gate 2799cce0e03bSab dftp = alist_item(ofl->ofl_dtsfltrs, sftp->sft_idx); 28007c478bd9Sstevel@tonic-gate sip[sftp->sft_sdp->sd_symndx].si_boundto = dftp->dft_ndx; 28017c478bd9Sstevel@tonic-gate } 28027c478bd9Sstevel@tonic-gate 28037c478bd9Sstevel@tonic-gate /* 28047c478bd9Sstevel@tonic-gate * Display debugging information about section. 28057c478bd9Sstevel@tonic-gate */ 28065aefb655Srie DBG_CALL(Dbg_syminfo_title(ofl->ofl_lml)); 28075aefb655Srie if (DBG_ENABLED) { 28085aefb655Srie Word _cnt, cnt = shdr->sh_size / shdr->sh_entsize; 280957ef7aa9SRod Evans Sym *symtab = symosp->os_outdata->d_buf; 281057ef7aa9SRod Evans Dyn *dyn; 28117c478bd9Sstevel@tonic-gate 28127c478bd9Sstevel@tonic-gate if (ofl->ofl_osdynamic) 28137c478bd9Sstevel@tonic-gate dyn = ofl->ofl_osdynamic->os_outdata->d_buf; 28147c478bd9Sstevel@tonic-gate else 281557ef7aa9SRod Evans dyn = NULL; 28167c478bd9Sstevel@tonic-gate 28177c478bd9Sstevel@tonic-gate for (_cnt = 1; _cnt < cnt; _cnt++) { 28187c478bd9Sstevel@tonic-gate if (sip[_cnt].si_flags || sip[_cnt].si_boundto) 28197c478bd9Sstevel@tonic-gate /* LINTED */ 28205aefb655Srie DBG_CALL(Dbg_syminfo_entry(ofl->ofl_lml, _cnt, 28217c478bd9Sstevel@tonic-gate &sip[_cnt], &symtab[_cnt], strtab, dyn)); 28227c478bd9Sstevel@tonic-gate } 28237c478bd9Sstevel@tonic-gate } 28247c478bd9Sstevel@tonic-gate return (1); 28257c478bd9Sstevel@tonic-gate } 28267c478bd9Sstevel@tonic-gate 28277c478bd9Sstevel@tonic-gate /* 28287c478bd9Sstevel@tonic-gate * Build the output elf header. 28297c478bd9Sstevel@tonic-gate */ 28305aefb655Srie static uintptr_t 28317c478bd9Sstevel@tonic-gate update_oehdr(Ofl_desc * ofl) 28327c478bd9Sstevel@tonic-gate { 28335aefb655Srie Ehdr *ehdr = ofl->ofl_nehdr; 28347c478bd9Sstevel@tonic-gate 28357c478bd9Sstevel@tonic-gate /* 28367c478bd9Sstevel@tonic-gate * If an entry point symbol has already been established (refer 28377c478bd9Sstevel@tonic-gate * sym_validate()) simply update the elf header entry point with the 28387c478bd9Sstevel@tonic-gate * symbols value. If no entry point is defined it will have been filled 28397c478bd9Sstevel@tonic-gate * with the start address of the first section within the text segment 28407c478bd9Sstevel@tonic-gate * (refer update_outfile()). 28417c478bd9Sstevel@tonic-gate */ 28427c478bd9Sstevel@tonic-gate if (ofl->ofl_entry) 28437c478bd9Sstevel@tonic-gate ehdr->e_entry = 2844d840867fSab ((Sym_desc *)(ofl->ofl_entry))->sd_sym->st_value; 28457c478bd9Sstevel@tonic-gate 28467c478bd9Sstevel@tonic-gate /* 28477c478bd9Sstevel@tonic-gate * Note. it may be necessary to update the `e_flags' field in the 28487c478bd9Sstevel@tonic-gate * machine dependent section. 28497c478bd9Sstevel@tonic-gate */ 2850ba2be530Sab ehdr->e_ident[EI_DATA] = ld_targ.t_m.m_data; 28515aefb655Srie ehdr->e_machine = ofl->ofl_dehdr->e_machine; 28525aefb655Srie ehdr->e_flags = ofl->ofl_dehdr->e_flags; 28535aefb655Srie ehdr->e_version = ofl->ofl_dehdr->e_version; 28545aefb655Srie 2855ba2be530Sab if (ehdr->e_machine != ld_targ.t_m.m_mach) { 2856ba2be530Sab if (ehdr->e_machine != ld_targ.t_m.m_machplus) 28577c478bd9Sstevel@tonic-gate return (S_ERROR); 2858ba2be530Sab if ((ehdr->e_flags & ld_targ.t_m.m_flagsplus) == 0) 28597c478bd9Sstevel@tonic-gate return (S_ERROR); 28607c478bd9Sstevel@tonic-gate } 28617c478bd9Sstevel@tonic-gate 28627c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_SHAROBJ) 28637c478bd9Sstevel@tonic-gate ehdr->e_type = ET_DYN; 28647c478bd9Sstevel@tonic-gate else if (ofl->ofl_flags & FLG_OF_RELOBJ) 28657c478bd9Sstevel@tonic-gate ehdr->e_type = ET_REL; 28667c478bd9Sstevel@tonic-gate else 28677c478bd9Sstevel@tonic-gate ehdr->e_type = ET_EXEC; 28687c478bd9Sstevel@tonic-gate 28697c478bd9Sstevel@tonic-gate return (1); 28707c478bd9Sstevel@tonic-gate } 28717c478bd9Sstevel@tonic-gate 28727c478bd9Sstevel@tonic-gate /* 28737c478bd9Sstevel@tonic-gate * Perform move table expansion. 28747c478bd9Sstevel@tonic-gate */ 287557ef7aa9SRod Evans static void 287657ef7aa9SRod Evans expand_move(Ofl_desc *ofl, Sym_desc *sdp, Move *mvp) 28777c478bd9Sstevel@tonic-gate { 28787c478bd9Sstevel@tonic-gate Os_desc *osp; 287957ef7aa9SRod Evans uchar_t *taddr, *taddr0; 28807c478bd9Sstevel@tonic-gate Sxword offset; 288157ef7aa9SRod Evans Half cnt; 288257ef7aa9SRod Evans uint_t stride; 28837c478bd9Sstevel@tonic-gate 288435450702SAli Bahrami osp = ofl->ofl_isparexpn->is_osdesc; 2885b26cc8daSAli Bahrami offset = sdp->sd_sym->st_value - osp->os_shdr->sh_addr; 288657ef7aa9SRod Evans 288757ef7aa9SRod Evans taddr0 = taddr = osp->os_outdata->d_buf; 28887c478bd9Sstevel@tonic-gate taddr += offset; 288957ef7aa9SRod Evans taddr = taddr + mvp->m_poffset; 289057ef7aa9SRod Evans 289157ef7aa9SRod Evans for (cnt = 0; cnt < mvp->m_repeat; cnt++) { 28927c478bd9Sstevel@tonic-gate /* LINTED */ 289357ef7aa9SRod Evans DBG_CALL(Dbg_move_expand(ofl->ofl_lml, mvp, 28945aefb655Srie (Addr)(taddr - taddr0))); 289557ef7aa9SRod Evans stride = (uint_t)mvp->m_stride + 1; 289657ef7aa9SRod Evans 289757ef7aa9SRod Evans /* 289857ef7aa9SRod Evans * Update the target address based upon the move entry size. 289957ef7aa9SRod Evans * This size was validated in ld_process_move(). 290057ef7aa9SRod Evans */ 29017c478bd9Sstevel@tonic-gate /* LINTED */ 290257ef7aa9SRod Evans switch (ELF_M_SIZE(mvp->m_info)) { 29037c478bd9Sstevel@tonic-gate case 1: 29047c478bd9Sstevel@tonic-gate /* LINTED */ 290557ef7aa9SRod Evans *taddr = (uchar_t)mvp->m_value; 29067c478bd9Sstevel@tonic-gate taddr += stride; 29077c478bd9Sstevel@tonic-gate break; 29087c478bd9Sstevel@tonic-gate case 2: 29097c478bd9Sstevel@tonic-gate /* LINTED */ 291057ef7aa9SRod Evans *((Half *)taddr) = (Half)mvp->m_value; 291157ef7aa9SRod Evans taddr += 2 * stride; 29127c478bd9Sstevel@tonic-gate break; 29137c478bd9Sstevel@tonic-gate case 4: 29147c478bd9Sstevel@tonic-gate /* LINTED */ 291557ef7aa9SRod Evans *((Word *)taddr) = (Word)mvp->m_value; 291657ef7aa9SRod Evans taddr += 4 * stride; 29177c478bd9Sstevel@tonic-gate break; 29187c478bd9Sstevel@tonic-gate case 8: 29197c478bd9Sstevel@tonic-gate /* LINTED */ 292057ef7aa9SRod Evans *((u_longlong_t *)taddr) = mvp->m_value; 292157ef7aa9SRod Evans taddr += 8 * stride; 29227c478bd9Sstevel@tonic-gate break; 29237c478bd9Sstevel@tonic-gate } 29247c478bd9Sstevel@tonic-gate } 29257c478bd9Sstevel@tonic-gate } 29267c478bd9Sstevel@tonic-gate 29277c478bd9Sstevel@tonic-gate /* 29287c478bd9Sstevel@tonic-gate * Update Move sections. 29297c478bd9Sstevel@tonic-gate */ 293057ef7aa9SRod Evans static void 29317c478bd9Sstevel@tonic-gate update_move(Ofl_desc *ofl) 29327c478bd9Sstevel@tonic-gate { 29337c478bd9Sstevel@tonic-gate Word ndx = 0; 29341d9df23bSab ofl_flag_t flags = ofl->ofl_flags; 293557ef7aa9SRod Evans Move *omvp; 293657ef7aa9SRod Evans Aliste idx1; 293757ef7aa9SRod Evans Sym_desc *sdp; 29387c478bd9Sstevel@tonic-gate 29397c478bd9Sstevel@tonic-gate /* 29407c478bd9Sstevel@tonic-gate * Determine the index of the symbol table that will be referenced by 294157ef7aa9SRod Evans * the Move section. 29427c478bd9Sstevel@tonic-gate */ 29439039eeafSab if (OFL_ALLOW_DYNSYM(ofl)) 29447c478bd9Sstevel@tonic-gate /* LINTED */ 29457c478bd9Sstevel@tonic-gate ndx = (Word) elf_ndxscn(ofl->ofl_osdynsym->os_scn); 29467c478bd9Sstevel@tonic-gate else if (!(flags & FLG_OF_STRIP) || (flags & FLG_OF_RELOBJ)) 29477c478bd9Sstevel@tonic-gate /* LINTED */ 29487c478bd9Sstevel@tonic-gate ndx = (Word) elf_ndxscn(ofl->ofl_ossymtab->os_scn); 29497c478bd9Sstevel@tonic-gate 29507c478bd9Sstevel@tonic-gate /* 295157ef7aa9SRod Evans * Update sh_link of the Move section, and point to the new Move data. 29527c478bd9Sstevel@tonic-gate */ 29537c478bd9Sstevel@tonic-gate if (ofl->ofl_osmove) { 29547c478bd9Sstevel@tonic-gate ofl->ofl_osmove->os_shdr->sh_link = ndx; 295557ef7aa9SRod Evans omvp = (Move *)ofl->ofl_osmove->os_outdata->d_buf; 29567c478bd9Sstevel@tonic-gate } 29577c478bd9Sstevel@tonic-gate 29587c478bd9Sstevel@tonic-gate /* 29597c478bd9Sstevel@tonic-gate * Update symbol entry index 29607c478bd9Sstevel@tonic-gate */ 296157ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_parsyms, idx1, sdp)) { 296257ef7aa9SRod Evans Aliste idx2; 296357ef7aa9SRod Evans Mv_desc *mdp; 29647c478bd9Sstevel@tonic-gate 29657c478bd9Sstevel@tonic-gate /* 29667c478bd9Sstevel@tonic-gate * Expand move table 29677c478bd9Sstevel@tonic-gate */ 296857ef7aa9SRod Evans if (sdp->sd_flags & FLG_SY_PAREXPN) { 296957ef7aa9SRod Evans const char *str; 29707c478bd9Sstevel@tonic-gate 29711d9df23bSab if (flags & FLG_OF_STATIC) 297257ef7aa9SRod Evans str = MSG_INTL(MSG_PSYM_EXPREASON1); 29737c478bd9Sstevel@tonic-gate else if (ofl->ofl_flags1 & FLG_OF1_NOPARTI) 297457ef7aa9SRod Evans str = MSG_INTL(MSG_PSYM_EXPREASON2); 29757c478bd9Sstevel@tonic-gate else 297657ef7aa9SRod Evans str = MSG_INTL(MSG_PSYM_EXPREASON3); 297757ef7aa9SRod Evans 29785aefb655Srie DBG_CALL(Dbg_move_parexpn(ofl->ofl_lml, 297957ef7aa9SRod Evans sdp->sd_name, str)); 298057ef7aa9SRod Evans 298157ef7aa9SRod Evans for (ALIST_TRAVERSE(sdp->sd_move, idx2, mdp)) { 29825aefb655Srie DBG_CALL(Dbg_move_entry1(ofl->ofl_lml, 0, 298357ef7aa9SRod Evans mdp->md_move, sdp)); 298457ef7aa9SRod Evans expand_move(ofl, sdp, mdp->md_move); 29857c478bd9Sstevel@tonic-gate } 29867c478bd9Sstevel@tonic-gate continue; 29877c478bd9Sstevel@tonic-gate } 29887c478bd9Sstevel@tonic-gate 29897c478bd9Sstevel@tonic-gate /* 29907c478bd9Sstevel@tonic-gate * Process move table 29917c478bd9Sstevel@tonic-gate */ 299257ef7aa9SRod Evans DBG_CALL(Dbg_move_outmove(ofl->ofl_lml, sdp->sd_name)); 299357ef7aa9SRod Evans 299457ef7aa9SRod Evans for (ALIST_TRAVERSE(sdp->sd_move, idx2, mdp)) { 299557ef7aa9SRod Evans Move *imvp; 29967c478bd9Sstevel@tonic-gate int idx = 1; 299760758829Srie Sym *sym; 299860758829Srie 299957ef7aa9SRod Evans imvp = mdp->md_move; 300060758829Srie sym = sdp->sd_sym; 30017c478bd9Sstevel@tonic-gate 300257ef7aa9SRod Evans DBG_CALL(Dbg_move_entry1(ofl->ofl_lml, 1, imvp, sdp)); 300360758829Srie 300457ef7aa9SRod Evans *omvp = *imvp; 30051d9df23bSab if ((flags & FLG_OF_RELOBJ) == 0) { 300660758829Srie if (ELF_ST_BIND(sym->st_info) == STB_LOCAL) { 300757ef7aa9SRod Evans Os_desc *osp = sdp->sd_isc->is_osdesc; 300857ef7aa9SRod Evans Word ndx = osp->os_identndx; 300960758829Srie 301057ef7aa9SRod Evans omvp->m_info = 3011d840867fSab /* LINTED */ 301257ef7aa9SRod Evans ELF_M_INFO(ndx, imvp->m_info); 301360758829Srie 301460758829Srie if (ELF_ST_TYPE(sym->st_info) != 3015d840867fSab STT_SECTION) { 301657ef7aa9SRod Evans omvp->m_poffset = 301757ef7aa9SRod Evans sym->st_value - 301857ef7aa9SRod Evans osp->os_shdr->sh_addr + 301957ef7aa9SRod Evans imvp->m_poffset; 3020d840867fSab } 30217c478bd9Sstevel@tonic-gate } else { 302257ef7aa9SRod Evans omvp->m_info = 3023d840867fSab /* LINTED */ 3024d840867fSab ELF_M_INFO(sdp->sd_symndx, 302557ef7aa9SRod Evans imvp->m_info); 30267c478bd9Sstevel@tonic-gate } 30277c478bd9Sstevel@tonic-gate } else { 30287c478bd9Sstevel@tonic-gate Boolean isredloc = FALSE; 30297c478bd9Sstevel@tonic-gate 303060758829Srie if ((ELF_ST_BIND(sym->st_info) == STB_LOCAL) && 303144bac77bSrie (ofl->ofl_flags & FLG_OF_REDLSYM)) 30327c478bd9Sstevel@tonic-gate isredloc = TRUE; 30337c478bd9Sstevel@tonic-gate 303457ef7aa9SRod Evans if (isredloc && !(sdp->sd_move)) { 303557ef7aa9SRod Evans Os_desc *osp = sdp->sd_isc->is_osdesc; 303657ef7aa9SRod Evans Word ndx = osp->os_identndx; 303760758829Srie 303857ef7aa9SRod Evans omvp->m_info = 3039d840867fSab /* LINTED */ 304057ef7aa9SRod Evans ELF_M_INFO(ndx, imvp->m_info); 304157ef7aa9SRod Evans 304257ef7aa9SRod Evans omvp->m_poffset += sym->st_value; 30437c478bd9Sstevel@tonic-gate } else { 30447c478bd9Sstevel@tonic-gate if (isredloc) 3045d840867fSab DBG_CALL(Dbg_syms_reduce(ofl, 304657ef7aa9SRod Evans DBG_SYM_REDUCE_RETAIN, 304757ef7aa9SRod Evans sdp, idx, 3048d840867fSab ofl->ofl_osmove->os_name)); 30497c478bd9Sstevel@tonic-gate 305057ef7aa9SRod Evans omvp->m_info = 3051d840867fSab /* LINTED */ 3052d840867fSab ELF_M_INFO(sdp->sd_symndx, 305357ef7aa9SRod Evans imvp->m_info); 30547c478bd9Sstevel@tonic-gate } 30557c478bd9Sstevel@tonic-gate } 305657ef7aa9SRod Evans 305757ef7aa9SRod Evans DBG_CALL(Dbg_move_entry1(ofl->ofl_lml, 0, omvp, sdp)); 305857ef7aa9SRod Evans omvp++; 30597c478bd9Sstevel@tonic-gate idx++; 30607c478bd9Sstevel@tonic-gate } 30617c478bd9Sstevel@tonic-gate } 30627c478bd9Sstevel@tonic-gate } 30637c478bd9Sstevel@tonic-gate 30647c478bd9Sstevel@tonic-gate /* 306557ef7aa9SRod Evans * Scan through the SHT_GROUP output sections. Update their sh_link/sh_info 306657ef7aa9SRod Evans * fields as well as the section contents. 30677c478bd9Sstevel@tonic-gate */ 30685aefb655Srie static uintptr_t 30690e233487SRod Evans update_ogroup(Ofl_desc *ofl) 30707c478bd9Sstevel@tonic-gate { 307157ef7aa9SRod Evans Aliste idx; 30727c478bd9Sstevel@tonic-gate Os_desc *osp; 30737c478bd9Sstevel@tonic-gate uintptr_t error = 0; 30747c478bd9Sstevel@tonic-gate 307557ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_osgroups, idx, osp)) { 30767c478bd9Sstevel@tonic-gate Is_desc *isp; 30777c478bd9Sstevel@tonic-gate Ifl_desc *ifl; 30787c478bd9Sstevel@tonic-gate Shdr *shdr = osp->os_shdr; 30797c478bd9Sstevel@tonic-gate Sym_desc *sdp; 30807c478bd9Sstevel@tonic-gate Xword i, grpcnt; 30817c478bd9Sstevel@tonic-gate Word *gdata; 30827c478bd9Sstevel@tonic-gate 30837c478bd9Sstevel@tonic-gate /* 30847c478bd9Sstevel@tonic-gate * Since input GROUP sections always create unique 30857c478bd9Sstevel@tonic-gate * output GROUP sections - we know there is only one 30867c478bd9Sstevel@tonic-gate * item on the list. 30877c478bd9Sstevel@tonic-gate */ 30881dd9d86fSAli Bahrami isp = ld_os_first_isdesc(osp); 30897c478bd9Sstevel@tonic-gate 30907c478bd9Sstevel@tonic-gate ifl = isp->is_file; 30917c478bd9Sstevel@tonic-gate sdp = ifl->ifl_oldndx[isp->is_shdr->sh_info]; 30927c478bd9Sstevel@tonic-gate shdr->sh_link = (Word)elf_ndxscn(ofl->ofl_ossymtab->os_scn); 30937c478bd9Sstevel@tonic-gate shdr->sh_info = sdp->sd_symndx; 30947c478bd9Sstevel@tonic-gate 30957c478bd9Sstevel@tonic-gate /* 30967c478bd9Sstevel@tonic-gate * Scan through the group data section and update 30977c478bd9Sstevel@tonic-gate * all of the links to new values. 30987c478bd9Sstevel@tonic-gate */ 30997c478bd9Sstevel@tonic-gate grpcnt = shdr->sh_size / shdr->sh_entsize; 31007c478bd9Sstevel@tonic-gate gdata = (Word *)osp->os_outdata->d_buf; 31017c478bd9Sstevel@tonic-gate 31020e233487SRod Evans for (i = 1; i < grpcnt; i++) { 31030e233487SRod Evans Os_desc *_osp; 31040e233487SRod Evans Is_desc *_isp = ifl->ifl_isdesc[gdata[i]]; 31057c478bd9Sstevel@tonic-gate 31067c478bd9Sstevel@tonic-gate /* 31077c478bd9Sstevel@tonic-gate * If the referenced section didn't make it to the 31087c478bd9Sstevel@tonic-gate * output file - just zero out the entry. 31097c478bd9Sstevel@tonic-gate */ 31100e233487SRod Evans if ((_osp = _isp->is_osdesc) == NULL) 31117c478bd9Sstevel@tonic-gate gdata[i] = 0; 31127c478bd9Sstevel@tonic-gate else 31137c478bd9Sstevel@tonic-gate gdata[i] = (Word)elf_ndxscn(_osp->os_scn); 31147c478bd9Sstevel@tonic-gate } 31157c478bd9Sstevel@tonic-gate } 31167c478bd9Sstevel@tonic-gate return (error); 31177c478bd9Sstevel@tonic-gate } 31187c478bd9Sstevel@tonic-gate 31195aefb655Srie static void 31203244bcaaSab update_ostrtab(Os_desc *osp, Str_tbl *stp, uint_t extra) 31217c478bd9Sstevel@tonic-gate { 31227c478bd9Sstevel@tonic-gate Elf_Data *data; 31233244bcaaSab 312457ef7aa9SRod Evans if (osp == NULL) 31257c478bd9Sstevel@tonic-gate return; 31267c478bd9Sstevel@tonic-gate 31277c478bd9Sstevel@tonic-gate data = osp->os_outdata; 31283244bcaaSab assert(data->d_size == (st_getstrtab_sz(stp) + extra)); 3129cce0e03bSab (void) st_setstrbuf(stp, data->d_buf, data->d_size - extra); 31303244bcaaSab /* If leaving an extra hole at the end, zero it */ 31313244bcaaSab if (extra > 0) 31323244bcaaSab (void) memset((char *)data->d_buf + data->d_size - extra, 31333244bcaaSab 0x0, extra); 31347c478bd9Sstevel@tonic-gate } 31357c478bd9Sstevel@tonic-gate 31367c478bd9Sstevel@tonic-gate /* 31377c478bd9Sstevel@tonic-gate * Translate the shdr->sh_{link, info} from its input section value to that 31387c478bd9Sstevel@tonic-gate * of the corresponding shdr->sh_{link, info} output section value. 31397c478bd9Sstevel@tonic-gate */ 31405aefb655Srie static Word 31415aefb655Srie translate_link(Ofl_desc *ofl, Os_desc *osp, Word link, const char *msg) 31427c478bd9Sstevel@tonic-gate { 314357ef7aa9SRod Evans Is_desc *isp; 314457ef7aa9SRod Evans Ifl_desc *ifl; 31457c478bd9Sstevel@tonic-gate 31467c478bd9Sstevel@tonic-gate /* 31477c478bd9Sstevel@tonic-gate * Don't translate the special section numbers. 31487c478bd9Sstevel@tonic-gate */ 31497c478bd9Sstevel@tonic-gate if (link >= SHN_LORESERVE) 31507c478bd9Sstevel@tonic-gate return (link); 31517c478bd9Sstevel@tonic-gate 31527c478bd9Sstevel@tonic-gate /* 31537c478bd9Sstevel@tonic-gate * Does this output section translate back to an input file. If not 31547c478bd9Sstevel@tonic-gate * then there is no translation to do. In this case we will assume that 31557c478bd9Sstevel@tonic-gate * if sh_link has a value, it's the right value. 31567c478bd9Sstevel@tonic-gate */ 31571dd9d86fSAli Bahrami isp = ld_os_first_isdesc(osp); 31587c478bd9Sstevel@tonic-gate if ((ifl = isp->is_file) == NULL) 31597c478bd9Sstevel@tonic-gate return (link); 31607c478bd9Sstevel@tonic-gate 31617c478bd9Sstevel@tonic-gate /* 31627c478bd9Sstevel@tonic-gate * Sanity check to make sure that the sh_{link, info} value 31637c478bd9Sstevel@tonic-gate * is within range for the input file. 31647c478bd9Sstevel@tonic-gate */ 31657c478bd9Sstevel@tonic-gate if (link >= ifl->ifl_shnum) { 31665aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, msg, ifl->ifl_name, 31674a8d0ea7SAli Bahrami EC_WORD(isp->is_scnndx), isp->is_name, EC_XWORD(link)); 31687c478bd9Sstevel@tonic-gate return (link); 31697c478bd9Sstevel@tonic-gate } 31707c478bd9Sstevel@tonic-gate 31717c478bd9Sstevel@tonic-gate /* 31727c478bd9Sstevel@tonic-gate * Follow the link to the input section. 31737c478bd9Sstevel@tonic-gate */ 317457ef7aa9SRod Evans if ((isp = ifl->ifl_isdesc[link]) == NULL) 31757c478bd9Sstevel@tonic-gate return (0); 317657ef7aa9SRod Evans if ((osp = isp->is_osdesc) == NULL) 31777c478bd9Sstevel@tonic-gate return (0); 31787c478bd9Sstevel@tonic-gate 31797c478bd9Sstevel@tonic-gate /* LINTED */ 31807c478bd9Sstevel@tonic-gate return ((Word)elf_ndxscn(osp->os_scn)); 31817c478bd9Sstevel@tonic-gate } 31827c478bd9Sstevel@tonic-gate 31837c478bd9Sstevel@tonic-gate /* 31847c478bd9Sstevel@tonic-gate * Having created all of the necessary sections, segments, and associated 31857c478bd9Sstevel@tonic-gate * headers, fill in the program headers and update any other data in the 31867c478bd9Sstevel@tonic-gate * output image. Some general rules: 31877c478bd9Sstevel@tonic-gate * 318857ef7aa9SRod Evans * - If an interpreter is required always generate a PT_PHDR entry as 31897c478bd9Sstevel@tonic-gate * well. It is this entry that triggers the kernel into passing the 319070d3e49eSrie * interpreter an aux vector instead of just a file descriptor. 31917c478bd9Sstevel@tonic-gate * 319257ef7aa9SRod Evans * - When generating an image that will be interpreted (ie. a dynamic 31937c478bd9Sstevel@tonic-gate * executable, a shared object, or a static executable that has been 319470d3e49eSrie * provided with an interpreter - weird, but possible), make the initial 31957c478bd9Sstevel@tonic-gate * loadable segment include both the ehdr and phdr[]. Both of these 319670d3e49eSrie * tables are used by the interpreter therefore it seems more intuitive 31977c478bd9Sstevel@tonic-gate * to explicitly defined them as part of the mapped image rather than 319870d3e49eSrie * relying on page rounding by the interpreter to allow their access. 31997c478bd9Sstevel@tonic-gate * 320057ef7aa9SRod Evans * - When generating a static image that does not require an interpreter 32017c478bd9Sstevel@tonic-gate * have the first loadable segment indicate the address of the first 32027c478bd9Sstevel@tonic-gate * .section as the start address (things like /kernel/unix and ufsboot 32037c478bd9Sstevel@tonic-gate * expect this behavior). 32047c478bd9Sstevel@tonic-gate */ 32057c478bd9Sstevel@tonic-gate uintptr_t 32065aefb655Srie ld_update_outfile(Ofl_desc *ofl) 32077c478bd9Sstevel@tonic-gate { 3208bb3b4f6cSRod Evans Addr size, etext, vaddr; 320957ef7aa9SRod Evans Sg_desc *sgp; 321057ef7aa9SRod Evans Sg_desc *dtracesgp = NULL, *capsgp = NULL, *intpsgp = NULL; 3211cce0e03bSab Os_desc *osp; 321257ef7aa9SRod Evans int phdrndx = 0, segndx = -1, secndx, intppndx, intpsndx; 3213d1827f25Srie int dtracepndx, dtracesndx, cappndx, capsndx; 32145aefb655Srie Ehdr *ehdr = ofl->ofl_nehdr; 32157c478bd9Sstevel@tonic-gate Shdr *hshdr; 321657ef7aa9SRod Evans Phdr *_phdr = NULL; 3217d1827f25Srie Word phdrsz = (ehdr->e_phnum * ehdr->e_phentsize), shscnndx; 32181d9df23bSab ofl_flag_t flags = ofl->ofl_flags; 32191d9df23bSab Word ehdrsz = ehdr->e_ehsize; 32207c478bd9Sstevel@tonic-gate Boolean nobits; 32217c478bd9Sstevel@tonic-gate Off offset; 322257ef7aa9SRod Evans Aliste idx1; 32237c478bd9Sstevel@tonic-gate 3224bb3b4f6cSRod Evans /* 3225bb3b4f6cSRod Evans * Initialize the starting address for the first segment. Executables 3226bb3b4f6cSRod Evans * have different starting addresses depending upon the target ABI, 3227bb3b4f6cSRod Evans * where as shared objects have a starting address of 0. If this is 3228bb3b4f6cSRod Evans * a 64-bit executable that is being constructed to run in a restricted 3229bb3b4f6cSRod Evans * address space, use an alternative origin that will provide more free 3230bb3b4f6cSRod Evans * address space for the the eventual process. 3231bb3b4f6cSRod Evans */ 3232bb3b4f6cSRod Evans if (ofl->ofl_flags & FLG_OF_EXEC) { 3233bb3b4f6cSRod Evans #if defined(_ELF64) 3234bb3b4f6cSRod Evans if (ofl->ofl_sfcap_1 & SF1_SUNW_ADDR32) 3235bb3b4f6cSRod Evans vaddr = ld_targ.t_m.m_segm_aorigin; 3236bb3b4f6cSRod Evans else 3237bb3b4f6cSRod Evans #endif 3238bb3b4f6cSRod Evans vaddr = ld_targ.t_m.m_segm_origin; 3239bb3b4f6cSRod Evans } else 3240bb3b4f6cSRod Evans vaddr = 0; 3241bb3b4f6cSRod Evans 32427c478bd9Sstevel@tonic-gate /* 32437c478bd9Sstevel@tonic-gate * Loop through the segment descriptors and pick out what we need. 32447c478bd9Sstevel@tonic-gate */ 32455aefb655Srie DBG_CALL(Dbg_seg_title(ofl->ofl_lml)); 324657ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_segs, idx1, sgp)) { 3247d1827f25Srie Phdr *phdr = &(sgp->sg_phdr); 32487c478bd9Sstevel@tonic-gate Xword p_align; 324957ef7aa9SRod Evans Aliste idx2; 32507c478bd9Sstevel@tonic-gate 32517c478bd9Sstevel@tonic-gate segndx++; 32527c478bd9Sstevel@tonic-gate 32537c478bd9Sstevel@tonic-gate /* 32547c478bd9Sstevel@tonic-gate * If an interpreter is required generate a PT_INTERP and 32557c478bd9Sstevel@tonic-gate * PT_PHDR program header entry. The PT_PHDR entry describes 32567c478bd9Sstevel@tonic-gate * the program header table itself. This information will be 32577c478bd9Sstevel@tonic-gate * passed via the aux vector to the interpreter (ld.so.1). 32587c478bd9Sstevel@tonic-gate * The program header array is actually part of the first 32597c478bd9Sstevel@tonic-gate * loadable segment (and the PT_PHDR entry is the first entry), 32607c478bd9Sstevel@tonic-gate * therefore its virtual address isn't known until the first 32617c478bd9Sstevel@tonic-gate * loadable segment is processed. 32627c478bd9Sstevel@tonic-gate */ 32637c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_PHDR) { 32647c478bd9Sstevel@tonic-gate if (ofl->ofl_osinterp) { 32657c478bd9Sstevel@tonic-gate phdr->p_offset = ehdr->e_phoff; 32667c478bd9Sstevel@tonic-gate phdr->p_filesz = phdr->p_memsz = phdrsz; 3267d1827f25Srie 32685aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 32697c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 32707c478bd9Sstevel@tonic-gate } 32717c478bd9Sstevel@tonic-gate continue; 32727c478bd9Sstevel@tonic-gate } 32737c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_INTERP) { 32747c478bd9Sstevel@tonic-gate if (ofl->ofl_osinterp) { 327557ef7aa9SRod Evans intpsgp = sgp; 327657ef7aa9SRod Evans intpsndx = segndx; 327757ef7aa9SRod Evans intppndx = phdrndx++; 32787c478bd9Sstevel@tonic-gate } 32797c478bd9Sstevel@tonic-gate continue; 32807c478bd9Sstevel@tonic-gate } 32817c478bd9Sstevel@tonic-gate 32827c478bd9Sstevel@tonic-gate /* 3283d1827f25Srie * If we are creating a PT_SUNWDTRACE segment, remember where 3284d1827f25Srie * the program header is. The header values are assigned after 3285d1827f25Srie * update_osym() has completed and the symbol table addresses 3286*28bda19cSRod Evans * have been updated. 32877c478bd9Sstevel@tonic-gate */ 32887c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_SUNWDTRACE) { 3289*28bda19cSRod Evans if (ofl->ofl_dtracesym && 32907c478bd9Sstevel@tonic-gate ((flags & FLG_OF_RELOBJ) == 0)) { 3291d1827f25Srie dtracesgp = sgp; 3292d1827f25Srie dtracesndx = segndx; 3293d1827f25Srie dtracepndx = phdrndx++; 32947c478bd9Sstevel@tonic-gate } 32957c478bd9Sstevel@tonic-gate continue; 32967c478bd9Sstevel@tonic-gate } 32977c478bd9Sstevel@tonic-gate 32987c478bd9Sstevel@tonic-gate /* 32997c478bd9Sstevel@tonic-gate * If a hardware/software capabilities section is required, 33007c478bd9Sstevel@tonic-gate * generate the PT_SUNWCAP header. Note, as this comes before 33017c478bd9Sstevel@tonic-gate * the first loadable segment, we don't yet know its real 33027c478bd9Sstevel@tonic-gate * virtual address. This is updated later. 33037c478bd9Sstevel@tonic-gate */ 33047c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_SUNWCAP) { 33057c478bd9Sstevel@tonic-gate if (ofl->ofl_oscap) { 3306d1827f25Srie capsgp = sgp; 3307d1827f25Srie capsndx = segndx; 3308d1827f25Srie cappndx = phdrndx++; 33097c478bd9Sstevel@tonic-gate } 33107c478bd9Sstevel@tonic-gate continue; 33117c478bd9Sstevel@tonic-gate } 33127c478bd9Sstevel@tonic-gate 33137c478bd9Sstevel@tonic-gate /* 33147c478bd9Sstevel@tonic-gate * As the dynamic program header occurs after the loadable 33157c478bd9Sstevel@tonic-gate * headers in the segment descriptor table, all the address 33167c478bd9Sstevel@tonic-gate * information for the .dynamic output section will have been 33177c478bd9Sstevel@tonic-gate * figured out by now. 33187c478bd9Sstevel@tonic-gate */ 33197c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_DYNAMIC) { 33209039eeafSab if (OFL_ALLOW_DYNSYM(ofl)) { 3321d1827f25Srie Shdr *shdr = ofl->ofl_osdynamic->os_shdr; 33227c478bd9Sstevel@tonic-gate 33237c478bd9Sstevel@tonic-gate phdr->p_vaddr = shdr->sh_addr; 33247c478bd9Sstevel@tonic-gate phdr->p_offset = shdr->sh_offset; 33257c478bd9Sstevel@tonic-gate phdr->p_filesz = shdr->sh_size; 3326ba2be530Sab phdr->p_flags = ld_targ.t_m.m_dataseg_perm; 3327d1827f25Srie 33285aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 33297c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 33307c478bd9Sstevel@tonic-gate } 33317c478bd9Sstevel@tonic-gate continue; 33327c478bd9Sstevel@tonic-gate } 3333d1827f25Srie 3334d1827f25Srie /* 33357e16fca0SAli Bahrami * As the unwind (.eh_frame_hdr) program header occurs after 33367e16fca0SAli Bahrami * the loadable headers in the segment descriptor table, all 33377e16fca0SAli Bahrami * the address information for the .eh_frame output section 33387e16fca0SAli Bahrami * will have been figured out by now. 3339d1827f25Srie */ 33407e16fca0SAli Bahrami if (phdr->p_type == PT_SUNW_UNWIND) { 33417c478bd9Sstevel@tonic-gate Shdr *shdr; 3342d1827f25Srie 33437e16fca0SAli Bahrami if (ofl->ofl_unwindhdr == NULL) 33447c478bd9Sstevel@tonic-gate continue; 3345d1827f25Srie 33467c478bd9Sstevel@tonic-gate shdr = ofl->ofl_unwindhdr->os_shdr; 33477c478bd9Sstevel@tonic-gate 33487c478bd9Sstevel@tonic-gate phdr->p_flags = PF_R; 33497c478bd9Sstevel@tonic-gate phdr->p_vaddr = shdr->sh_addr; 33507c478bd9Sstevel@tonic-gate phdr->p_memsz = shdr->sh_size; 33517c478bd9Sstevel@tonic-gate phdr->p_filesz = shdr->sh_size; 33527c478bd9Sstevel@tonic-gate phdr->p_offset = shdr->sh_offset; 33537c478bd9Sstevel@tonic-gate phdr->p_align = shdr->sh_addralign; 33547c478bd9Sstevel@tonic-gate phdr->p_paddr = 0; 33557c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 33567c478bd9Sstevel@tonic-gate continue; 33577c478bd9Sstevel@tonic-gate } 33587e16fca0SAli Bahrami 3359d1827f25Srie /* 3360d1827f25Srie * As the TLS program header occurs after the loadable 3361d1827f25Srie * headers in the segment descriptor table, all the address 3362d1827f25Srie * information for the .tls output section will have been 3363d1827f25Srie * figured out by now. 3364d1827f25Srie */ 33657c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_TLS) { 336657ef7aa9SRod Evans Os_desc *tlsosp; 336757ef7aa9SRod Evans Shdr *firstshdr = NULL, *lastfileshdr = NULL; 336857ef7aa9SRod Evans Shdr *lastshdr; 336957ef7aa9SRod Evans Aliste idx; 33707c478bd9Sstevel@tonic-gate 337157ef7aa9SRod Evans if (ofl->ofl_ostlsseg == NULL) 33727c478bd9Sstevel@tonic-gate continue; 3373dd94ecefSrie 3374f79d60b6Srie /* 3375f79d60b6Srie * Scan through the sections that have contributed TLS. 3376f79d60b6Srie * Remember the first and last so as to determine the 3377f79d60b6Srie * TLS memory size requirement. Remember the last 3378f79d60b6Srie * non-nobits section to determine the TLS data 3379f79d60b6Srie * contribution, which determines the TLS file size. 3380f79d60b6Srie */ 338157ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_ostlsseg, idx, tlsosp)) { 3382dd94ecefSrie Shdr *tlsshdr = tlsosp->os_shdr; 3383dd94ecefSrie 338457ef7aa9SRod Evans if (firstshdr == NULL) 3385f79d60b6Srie firstshdr = tlsshdr; 3386f79d60b6Srie if (tlsshdr->sh_type != SHT_NOBITS) 3387f79d60b6Srie lastfileshdr = tlsshdr; 3388f79d60b6Srie lastshdr = tlsshdr; 33897c478bd9Sstevel@tonic-gate } 3390dd94ecefSrie 3391dd94ecefSrie phdr->p_flags = PF_R | PF_W; 33927c478bd9Sstevel@tonic-gate phdr->p_vaddr = firstshdr->sh_addr; 33937c478bd9Sstevel@tonic-gate phdr->p_offset = firstshdr->sh_offset; 3394dd94ecefSrie phdr->p_align = firstshdr->sh_addralign; 3395f79d60b6Srie 3396f79d60b6Srie if (lastfileshdr) 3397f79d60b6Srie phdr->p_filesz = lastfileshdr->sh_offset + 3398f79d60b6Srie lastfileshdr->sh_size - phdr->p_offset; 3399f79d60b6Srie else 3400f79d60b6Srie phdr->p_filesz = 0; 3401f79d60b6Srie 3402f79d60b6Srie phdr->p_memsz = lastshdr->sh_offset + 3403f79d60b6Srie lastshdr->sh_size - phdr->p_offset; 3404dd94ecefSrie 34055aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 3406d1827f25Srie ofl->ofl_phdr[phdrndx] = *phdr; 3407d1827f25Srie ofl->ofl_tlsphdr = &ofl->ofl_phdr[phdrndx++]; 34087c478bd9Sstevel@tonic-gate continue; 34097c478bd9Sstevel@tonic-gate } 34107c478bd9Sstevel@tonic-gate 34117c478bd9Sstevel@tonic-gate /* 34127c478bd9Sstevel@tonic-gate * If this is an empty segment declaration, it will occur after 3413d1827f25Srie * all other loadable segments. As empty segments can be 3414d1827f25Srie * defind with fixed addresses, make sure that no loadable 3415d1827f25Srie * segments overlap. This might occur as the object evolves 3416d1827f25Srie * and the loadable segments grow, thus encroaching upon an 3417d1827f25Srie * existing segment reservation. 3418d1827f25Srie * 3419d1827f25Srie * Segments are only created for dynamic objects, thus this 3420d1827f25Srie * checking can be skipped when building a relocatable object. 34217c478bd9Sstevel@tonic-gate */ 34221d9df23bSab if (!(flags & FLG_OF_RELOBJ) && 34237c478bd9Sstevel@tonic-gate (sgp->sg_flags & FLG_SG_EMPTY)) { 3424d1827f25Srie int i; 34257c478bd9Sstevel@tonic-gate Addr v_e; 34267c478bd9Sstevel@tonic-gate 34277c478bd9Sstevel@tonic-gate vaddr = phdr->p_vaddr; 34287c478bd9Sstevel@tonic-gate phdr->p_memsz = sgp->sg_length; 34295aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 34307c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 34317c478bd9Sstevel@tonic-gate 34327c478bd9Sstevel@tonic-gate if (phdr->p_type != PT_LOAD) 34337c478bd9Sstevel@tonic-gate continue; 34347c478bd9Sstevel@tonic-gate 34357c478bd9Sstevel@tonic-gate v_e = vaddr + phdr->p_memsz; 3436d1827f25Srie 34377c478bd9Sstevel@tonic-gate /* 34387c478bd9Sstevel@tonic-gate * Check overlaps 34397c478bd9Sstevel@tonic-gate */ 34407c478bd9Sstevel@tonic-gate for (i = 0; i < phdrndx - 1; i++) { 34417c478bd9Sstevel@tonic-gate Addr p_s = (ofl->ofl_phdr[i]).p_vaddr; 34427c478bd9Sstevel@tonic-gate Addr p_e; 34437c478bd9Sstevel@tonic-gate 34447c478bd9Sstevel@tonic-gate if ((ofl->ofl_phdr[i]).p_type != PT_LOAD) 34457c478bd9Sstevel@tonic-gate continue; 34467c478bd9Sstevel@tonic-gate 34477c478bd9Sstevel@tonic-gate p_e = p_s + (ofl->ofl_phdr[i]).p_memsz; 34487c478bd9Sstevel@tonic-gate if (((p_s <= vaddr) && (p_e > vaddr)) || 34497c478bd9Sstevel@tonic-gate ((vaddr <= p_s) && (v_e > p_s))) 34505aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 34517c478bd9Sstevel@tonic-gate MSG_INTL(MSG_UPD_SEGOVERLAP), 34525aefb655Srie ofl->ofl_name, EC_ADDR(p_e), 34535aefb655Srie sgp->sg_name, EC_ADDR(vaddr)); 34547c478bd9Sstevel@tonic-gate } 34557c478bd9Sstevel@tonic-gate continue; 34567c478bd9Sstevel@tonic-gate } 34577c478bd9Sstevel@tonic-gate 34587c478bd9Sstevel@tonic-gate /* 34597c478bd9Sstevel@tonic-gate * Having processed any of the special program headers any 34607c478bd9Sstevel@tonic-gate * remaining headers will be built to express individual 34617c478bd9Sstevel@tonic-gate * segments. Segments are only built if they have output 34627c478bd9Sstevel@tonic-gate * section descriptors associated with them (ie. some form of 34637c478bd9Sstevel@tonic-gate * input section has been matched to this segment). 34647c478bd9Sstevel@tonic-gate */ 34650bc07c75Srie if (sgp->sg_osdescs == NULL) 34667c478bd9Sstevel@tonic-gate continue; 34677c478bd9Sstevel@tonic-gate 34687c478bd9Sstevel@tonic-gate /* 34697c478bd9Sstevel@tonic-gate * Determine the segments offset and size from the section 34707c478bd9Sstevel@tonic-gate * information provided from elf_update(). 34717c478bd9Sstevel@tonic-gate * Allow for multiple NOBITS sections. 34727c478bd9Sstevel@tonic-gate */ 3473cce0e03bSab osp = sgp->sg_osdescs->apl_data[0]; 347454d82594Sseizo hshdr = osp->os_shdr; 34757c478bd9Sstevel@tonic-gate 34767c478bd9Sstevel@tonic-gate phdr->p_filesz = 0; 34777c478bd9Sstevel@tonic-gate phdr->p_memsz = 0; 34787c478bd9Sstevel@tonic-gate phdr->p_offset = offset = hshdr->sh_offset; 34790bc07c75Srie 348054d82594Sseizo nobits = ((hshdr->sh_type == SHT_NOBITS) && 34810bc07c75Srie ((sgp->sg_flags & FLG_SG_PHREQ) == 0)); 34820bc07c75Srie 348357ef7aa9SRod Evans for (APLIST_TRAVERSE(sgp->sg_osdescs, idx2, osp)) { 3484cce0e03bSab Shdr *shdr = osp->os_shdr; 34857c478bd9Sstevel@tonic-gate 34867c478bd9Sstevel@tonic-gate p_align = 0; 34877c478bd9Sstevel@tonic-gate if (shdr->sh_addralign > p_align) 34887c478bd9Sstevel@tonic-gate p_align = shdr->sh_addralign; 34890bc07c75Srie 34907c478bd9Sstevel@tonic-gate offset = (Off)S_ROUND(offset, shdr->sh_addralign); 34917c478bd9Sstevel@tonic-gate offset += shdr->sh_size; 34920bc07c75Srie 34937c478bd9Sstevel@tonic-gate if (shdr->sh_type != SHT_NOBITS) { 34947c478bd9Sstevel@tonic-gate if (nobits) { 34955aefb655Srie eprintf(ofl->ofl_lml, ERR_FATAL, 34967c478bd9Sstevel@tonic-gate MSG_INTL(MSG_UPD_NOBITS)); 34977c478bd9Sstevel@tonic-gate return (S_ERROR); 34987c478bd9Sstevel@tonic-gate } 34997c478bd9Sstevel@tonic-gate phdr->p_filesz = offset - phdr->p_offset; 350054d82594Sseizo } else if ((sgp->sg_flags & FLG_SG_PHREQ) == 0) 35017c478bd9Sstevel@tonic-gate nobits = TRUE; 35027c478bd9Sstevel@tonic-gate } 35037c478bd9Sstevel@tonic-gate phdr->p_memsz = offset - hshdr->sh_offset; 35047c478bd9Sstevel@tonic-gate 35057c478bd9Sstevel@tonic-gate /* 35067c478bd9Sstevel@tonic-gate * If this is the first loadable segment of a dynamic object, 350770d3e49eSrie * or an interpreter has been specified (a static object built 350870d3e49eSrie * with an interpreter will still be given a PT_HDR entry), then 35097c478bd9Sstevel@tonic-gate * compensate for the elf header and program header array. Both 35107c478bd9Sstevel@tonic-gate * of these are actually part of the loadable segment as they 351170d3e49eSrie * may be inspected by the interpreter. Adjust the segments 35127c478bd9Sstevel@tonic-gate * size and offset accordingly. 35137c478bd9Sstevel@tonic-gate */ 351457ef7aa9SRod Evans if ((_phdr == NULL) && (phdr->p_type == PT_LOAD) && 35157c478bd9Sstevel@tonic-gate ((ofl->ofl_osinterp) || (flags & FLG_OF_DYNAMIC)) && 35164899432aSab (!(ofl->ofl_dtflags_1 & DF_1_NOHDR))) { 35177c478bd9Sstevel@tonic-gate size = (Addr)S_ROUND((phdrsz + ehdrsz), 35187c478bd9Sstevel@tonic-gate hshdr->sh_addralign); 35197c478bd9Sstevel@tonic-gate phdr->p_offset -= size; 35207c478bd9Sstevel@tonic-gate phdr->p_filesz += size; 35217c478bd9Sstevel@tonic-gate phdr->p_memsz += size; 35227c478bd9Sstevel@tonic-gate } 35237c478bd9Sstevel@tonic-gate 35247c478bd9Sstevel@tonic-gate /* 35257c478bd9Sstevel@tonic-gate * If a segment size symbol is required (specified via a 35267c478bd9Sstevel@tonic-gate * mapfile) update its value. 35277c478bd9Sstevel@tonic-gate */ 35287c478bd9Sstevel@tonic-gate if (sgp->sg_sizesym != NULL) 35297c478bd9Sstevel@tonic-gate sgp->sg_sizesym->sd_sym->st_value = phdr->p_memsz; 35307c478bd9Sstevel@tonic-gate 35317c478bd9Sstevel@tonic-gate /* 35327c478bd9Sstevel@tonic-gate * If no file content has been assigned to this segment (it 35337c478bd9Sstevel@tonic-gate * only contains no-bits sections), then reset the offset for 35347c478bd9Sstevel@tonic-gate * consistency. 35357c478bd9Sstevel@tonic-gate */ 35367c478bd9Sstevel@tonic-gate if (phdr->p_filesz == 0) 35377c478bd9Sstevel@tonic-gate phdr->p_offset = 0; 35387c478bd9Sstevel@tonic-gate 35397c478bd9Sstevel@tonic-gate /* 35407c478bd9Sstevel@tonic-gate * If a virtual address has been specified for this segment 354157ef7aa9SRod Evans * (presumably from a mapfile) use it and make sure the 35427c478bd9Sstevel@tonic-gate * previous segment does not run into this segment. 35437c478bd9Sstevel@tonic-gate */ 354435450702SAli Bahrami if (phdr->p_type == PT_LOAD) { 35457c478bd9Sstevel@tonic-gate if ((sgp->sg_flags & FLG_SG_VADDR)) { 35467c478bd9Sstevel@tonic-gate if (_phdr && (vaddr > phdr->p_vaddr) && 35477c478bd9Sstevel@tonic-gate (phdr->p_type == PT_LOAD)) 35485aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 35497c478bd9Sstevel@tonic-gate MSG_INTL(MSG_UPD_SEGOVERLAP), 35507c478bd9Sstevel@tonic-gate ofl->ofl_name, EC_ADDR(vaddr), 35517c478bd9Sstevel@tonic-gate sgp->sg_name, 35527c478bd9Sstevel@tonic-gate EC_ADDR(phdr->p_vaddr)); 35537c478bd9Sstevel@tonic-gate vaddr = phdr->p_vaddr; 35547c478bd9Sstevel@tonic-gate phdr->p_align = 0; 35557c478bd9Sstevel@tonic-gate } else { 35567c478bd9Sstevel@tonic-gate vaddr = phdr->p_vaddr = 35577c478bd9Sstevel@tonic-gate (Addr)S_ROUND(vaddr, phdr->p_align); 35587c478bd9Sstevel@tonic-gate } 35597c478bd9Sstevel@tonic-gate } 35607c478bd9Sstevel@tonic-gate 35617c478bd9Sstevel@tonic-gate /* 35627c478bd9Sstevel@tonic-gate * Adjust the address offset and p_align if needed. 35637c478bd9Sstevel@tonic-gate */ 35643906e0c2Srie if (((sgp->sg_flags & FLG_SG_VADDR) == 0) && 35653906e0c2Srie ((ofl->ofl_dtflags_1 & DF_1_NOHDR) == 0)) { 35667c478bd9Sstevel@tonic-gate if (phdr->p_align != 0) 35677c478bd9Sstevel@tonic-gate vaddr += phdr->p_offset % phdr->p_align; 35687c478bd9Sstevel@tonic-gate else 35697c478bd9Sstevel@tonic-gate vaddr += phdr->p_offset; 35707c478bd9Sstevel@tonic-gate phdr->p_vaddr = vaddr; 35717c478bd9Sstevel@tonic-gate } 35727c478bd9Sstevel@tonic-gate 35737c478bd9Sstevel@tonic-gate /* 35747c478bd9Sstevel@tonic-gate * If an interpreter is required set the virtual address of the 35757c478bd9Sstevel@tonic-gate * PT_PHDR program header now that we know the virtual address 35767c478bd9Sstevel@tonic-gate * of the loadable segment that contains it. Update the 35777c478bd9Sstevel@tonic-gate * PT_SUNWCAP header similarly. 35787c478bd9Sstevel@tonic-gate */ 357957ef7aa9SRod Evans if ((_phdr == NULL) && (phdr->p_type == PT_LOAD)) { 35807c478bd9Sstevel@tonic-gate _phdr = phdr; 35817c478bd9Sstevel@tonic-gate 3582d1827f25Srie if ((ofl->ofl_dtflags_1 & DF_1_NOHDR) == 0) { 35837c478bd9Sstevel@tonic-gate if (ofl->ofl_osinterp) 35847c478bd9Sstevel@tonic-gate ofl->ofl_phdr[0].p_vaddr = 35857c478bd9Sstevel@tonic-gate vaddr + ehdrsz; 35867c478bd9Sstevel@tonic-gate 35877c478bd9Sstevel@tonic-gate /* 35887c478bd9Sstevel@tonic-gate * Finally, if we're creating a dynamic object 358970d3e49eSrie * (or a static object in which an interpreter 35907c478bd9Sstevel@tonic-gate * is specified) update the vaddr to reflect 35917c478bd9Sstevel@tonic-gate * the address of the first section within this 35927c478bd9Sstevel@tonic-gate * segment. 35937c478bd9Sstevel@tonic-gate */ 35947c478bd9Sstevel@tonic-gate if ((ofl->ofl_osinterp) || 35957c478bd9Sstevel@tonic-gate (flags & FLG_OF_DYNAMIC)) 35967c478bd9Sstevel@tonic-gate vaddr += size; 35977c478bd9Sstevel@tonic-gate } else { 35987c478bd9Sstevel@tonic-gate /* 3599d1827f25Srie * If the DF_1_NOHDR flag was set, and an 3600d1827f25Srie * interpreter is being generated, the PT_PHDR 36017c478bd9Sstevel@tonic-gate * will not be part of any loadable segment. 36027c478bd9Sstevel@tonic-gate */ 3603d1827f25Srie if (ofl->ofl_osinterp) { 3604d1827f25Srie ofl->ofl_phdr[0].p_vaddr = 0; 3605d1827f25Srie ofl->ofl_phdr[0].p_memsz = 0; 3606d1827f25Srie ofl->ofl_phdr[0].p_flags = 0; 3607d1827f25Srie } 36087c478bd9Sstevel@tonic-gate } 36097c478bd9Sstevel@tonic-gate } 36107c478bd9Sstevel@tonic-gate 36117c478bd9Sstevel@tonic-gate /* 3612c1c6f601Srie * Ensure the ELF entry point defaults to zero. Typically, this 3613c1c6f601Srie * value is overridden in update_oehdr() to one of the standard 3614c1c6f601Srie * entry points. Historically, this default was set to the 3615c1c6f601Srie * address of first executable section, but this has since been 3616c1c6f601Srie * found to be more confusing than it is helpful. 36177c478bd9Sstevel@tonic-gate */ 3618c1c6f601Srie ehdr->e_entry = 0; 36197c478bd9Sstevel@tonic-gate 36205aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 36217c478bd9Sstevel@tonic-gate 36227c478bd9Sstevel@tonic-gate /* 36237c478bd9Sstevel@tonic-gate * Traverse the output section descriptors for this segment so 36247c478bd9Sstevel@tonic-gate * that we can update the section headers addresses. We've 36257c478bd9Sstevel@tonic-gate * calculated the virtual address of the initial section within 36267c478bd9Sstevel@tonic-gate * this segment, so each successive section can be calculated 36277c478bd9Sstevel@tonic-gate * based on their offsets from each other. 36287c478bd9Sstevel@tonic-gate */ 36297c478bd9Sstevel@tonic-gate secndx = 0; 36307c478bd9Sstevel@tonic-gate hshdr = 0; 363157ef7aa9SRod Evans for (APLIST_TRAVERSE(sgp->sg_osdescs, idx2, osp)) { 3632cce0e03bSab Shdr *shdr = osp->os_shdr; 36337c478bd9Sstevel@tonic-gate 36347c478bd9Sstevel@tonic-gate if (shdr->sh_link) 363560758829Srie shdr->sh_link = translate_link(ofl, osp, 363660758829Srie shdr->sh_link, MSG_INTL(MSG_FIL_INVSHLINK)); 36377c478bd9Sstevel@tonic-gate 36387c478bd9Sstevel@tonic-gate if (shdr->sh_info && (shdr->sh_flags & SHF_INFO_LINK)) 363960758829Srie shdr->sh_info = translate_link(ofl, osp, 364060758829Srie shdr->sh_info, MSG_INTL(MSG_FIL_INVSHINFO)); 36417c478bd9Sstevel@tonic-gate 36427c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_RELOBJ) && 364335450702SAli Bahrami (phdr->p_type == PT_LOAD)) { 36447c478bd9Sstevel@tonic-gate if (hshdr) 36457c478bd9Sstevel@tonic-gate vaddr += (shdr->sh_offset - 36467c478bd9Sstevel@tonic-gate hshdr->sh_offset); 36477c478bd9Sstevel@tonic-gate 36487c478bd9Sstevel@tonic-gate shdr->sh_addr = vaddr; 36497c478bd9Sstevel@tonic-gate hshdr = shdr; 36507c478bd9Sstevel@tonic-gate } 36517c478bd9Sstevel@tonic-gate 36527c478bd9Sstevel@tonic-gate DBG_CALL(Dbg_seg_os(ofl, osp, secndx)); 36537c478bd9Sstevel@tonic-gate secndx++; 36547c478bd9Sstevel@tonic-gate } 36557c478bd9Sstevel@tonic-gate 36567c478bd9Sstevel@tonic-gate /* 36577c478bd9Sstevel@tonic-gate * Establish the virtual address of the end of the last section 36587c478bd9Sstevel@tonic-gate * in this segment so that the next segments offset can be 36597c478bd9Sstevel@tonic-gate * calculated from this. 36607c478bd9Sstevel@tonic-gate */ 36617c478bd9Sstevel@tonic-gate if (hshdr) 36627c478bd9Sstevel@tonic-gate vaddr += hshdr->sh_size; 36637c478bd9Sstevel@tonic-gate 36647c478bd9Sstevel@tonic-gate /* 36657c478bd9Sstevel@tonic-gate * Output sections for this segment complete. Adjust the 36667c478bd9Sstevel@tonic-gate * virtual offset for the last sections size, and make sure we 36677c478bd9Sstevel@tonic-gate * haven't exceeded any maximum segment length specification. 36687c478bd9Sstevel@tonic-gate */ 36697c478bd9Sstevel@tonic-gate if ((sgp->sg_length != 0) && (sgp->sg_length < phdr->p_memsz)) { 36705aefb655Srie eprintf(ofl->ofl_lml, ERR_FATAL, 36715aefb655Srie MSG_INTL(MSG_UPD_LARGSIZE), ofl->ofl_name, 36725aefb655Srie sgp->sg_name, EC_XWORD(phdr->p_memsz), 36737c478bd9Sstevel@tonic-gate EC_XWORD(sgp->sg_length)); 36747c478bd9Sstevel@tonic-gate return (S_ERROR); 36757c478bd9Sstevel@tonic-gate } 36767c478bd9Sstevel@tonic-gate 36777c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_NOTE) { 36787c478bd9Sstevel@tonic-gate phdr->p_vaddr = 0; 36797c478bd9Sstevel@tonic-gate phdr->p_paddr = 0; 36807c478bd9Sstevel@tonic-gate phdr->p_align = 0; 36817c478bd9Sstevel@tonic-gate phdr->p_memsz = 0; 36827c478bd9Sstevel@tonic-gate } 3683d1827f25Srie 36847c478bd9Sstevel@tonic-gate if ((phdr->p_type != PT_NULL) && !(flags & FLG_OF_RELOBJ)) 36857c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 36867c478bd9Sstevel@tonic-gate } 36877c478bd9Sstevel@tonic-gate 36887c478bd9Sstevel@tonic-gate /* 36897c478bd9Sstevel@tonic-gate * Update any new output sections. When building the initial output 36907c478bd9Sstevel@tonic-gate * image, a number of sections were created but left uninitialized (eg. 36917c478bd9Sstevel@tonic-gate * .dynsym, .dynstr, .symtab, .symtab, etc.). Here we update these 36927c478bd9Sstevel@tonic-gate * sections with the appropriate data. Other sections may still be 36937c478bd9Sstevel@tonic-gate * modified via reloc_process(). 36947c478bd9Sstevel@tonic-gate * 369570d3e49eSrie * Copy the interpreter name into the .interp section. 36967c478bd9Sstevel@tonic-gate */ 36977c478bd9Sstevel@tonic-gate if (ofl->ofl_interp) 36987c478bd9Sstevel@tonic-gate (void) strcpy((char *)ofl->ofl_osinterp->os_outdata->d_buf, 36997c478bd9Sstevel@tonic-gate ofl->ofl_interp); 37007c478bd9Sstevel@tonic-gate 37017c478bd9Sstevel@tonic-gate /* 37027c478bd9Sstevel@tonic-gate * Update the .shstrtab, .strtab and .dynstr sections. 37037c478bd9Sstevel@tonic-gate */ 37043244bcaaSab update_ostrtab(ofl->ofl_osshstrtab, ofl->ofl_shdrsttab, 0); 37053244bcaaSab update_ostrtab(ofl->ofl_osstrtab, ofl->ofl_strtab, 0); 37063244bcaaSab update_ostrtab(ofl->ofl_osdynstr, ofl->ofl_dynstrtab, DYNSTR_EXTRA_PAD); 37077c478bd9Sstevel@tonic-gate 37087c478bd9Sstevel@tonic-gate /* 37097c478bd9Sstevel@tonic-gate * Build any output symbol tables, the symbols information is copied 37107c478bd9Sstevel@tonic-gate * and updated into the new output image. 37117c478bd9Sstevel@tonic-gate */ 37127c478bd9Sstevel@tonic-gate if ((etext = update_osym(ofl)) == (Addr)S_ERROR) 37137c478bd9Sstevel@tonic-gate return (S_ERROR); 37147c478bd9Sstevel@tonic-gate 371557ef7aa9SRod Evans /* 371657ef7aa9SRod Evans * If we have an PT_INTERP phdr, update it now from the associated 371757ef7aa9SRod Evans * section information. 371857ef7aa9SRod Evans */ 371957ef7aa9SRod Evans if (intpsgp) { 372057ef7aa9SRod Evans Phdr *phdr = &(intpsgp->sg_phdr); 372157ef7aa9SRod Evans Shdr *shdr = ofl->ofl_osinterp->os_shdr; 372257ef7aa9SRod Evans 372357ef7aa9SRod Evans phdr->p_vaddr = shdr->sh_addr; 372457ef7aa9SRod Evans phdr->p_offset = shdr->sh_offset; 372557ef7aa9SRod Evans phdr->p_memsz = phdr->p_filesz = shdr->sh_size; 372657ef7aa9SRod Evans phdr->p_flags = PF_R; 372757ef7aa9SRod Evans 372857ef7aa9SRod Evans DBG_CALL(Dbg_seg_entry(ofl, intpsndx, intpsgp)); 372957ef7aa9SRod Evans ofl->ofl_phdr[intppndx] = *phdr; 373057ef7aa9SRod Evans } 373157ef7aa9SRod Evans 37327c478bd9Sstevel@tonic-gate /* 37337c478bd9Sstevel@tonic-gate * If we have a PT_SUNWDTRACE phdr, update it now with the address of 37347c478bd9Sstevel@tonic-gate * the symbol. It's only now been updated via update_sym(). 37357c478bd9Sstevel@tonic-gate */ 3736d1827f25Srie if (dtracesgp && ofl->ofl_dtracesym) { 3737d1827f25Srie Phdr *aphdr, *phdr = &(dtracesgp->sg_phdr); 37387c478bd9Sstevel@tonic-gate Sym_desc *sdp = ofl->ofl_dtracesym; 37397c478bd9Sstevel@tonic-gate 3740d1827f25Srie phdr->p_vaddr = sdp->sd_sym->st_value; 3741d1827f25Srie phdr->p_memsz = sdp->sd_sym->st_size; 37427c478bd9Sstevel@tonic-gate 37437c478bd9Sstevel@tonic-gate /* 37447c478bd9Sstevel@tonic-gate * Take permisions of the segment the symbol is associated with. 37457c478bd9Sstevel@tonic-gate */ 3746d1827f25Srie aphdr = &sdp->sd_isc->is_osdesc->os_sgdesc->sg_phdr; 3747d1827f25Srie assert(aphdr); 3748d1827f25Srie phdr->p_flags = aphdr->p_flags; 3749d1827f25Srie 3750d1827f25Srie DBG_CALL(Dbg_seg_entry(ofl, dtracesndx, dtracesgp)); 3751d1827f25Srie ofl->ofl_phdr[dtracepndx] = *phdr; 3752d1827f25Srie } 3753d1827f25Srie 3754d1827f25Srie /* 3755d1827f25Srie * If we have a PT_SUNWCAP phdr, update it now from the associated 3756d1827f25Srie * section information. 3757d1827f25Srie */ 3758d1827f25Srie if (capsgp && ofl->ofl_oscap) { 3759d1827f25Srie Phdr *phdr = &(capsgp->sg_phdr); 3760d1827f25Srie Shdr *shdr = ofl->ofl_oscap->os_shdr; 3761d1827f25Srie 3762d1827f25Srie phdr->p_vaddr = shdr->sh_addr; 3763d1827f25Srie phdr->p_offset = shdr->sh_offset; 376457ef7aa9SRod Evans phdr->p_memsz = phdr->p_filesz = shdr->sh_size; 3765d1827f25Srie phdr->p_flags = PF_R; 3766d1827f25Srie 3767d1827f25Srie DBG_CALL(Dbg_seg_entry(ofl, capsndx, capsgp)); 3768d1827f25Srie ofl->ofl_phdr[cappndx] = *phdr; 37697c478bd9Sstevel@tonic-gate } 37707c478bd9Sstevel@tonic-gate 37717c478bd9Sstevel@tonic-gate /* 37727c478bd9Sstevel@tonic-gate * Update the GROUP sections. 37737c478bd9Sstevel@tonic-gate */ 37747c478bd9Sstevel@tonic-gate if (update_ogroup(ofl) == S_ERROR) 37757c478bd9Sstevel@tonic-gate return (S_ERROR); 37767c478bd9Sstevel@tonic-gate 37777c478bd9Sstevel@tonic-gate /* 37787c478bd9Sstevel@tonic-gate * Update Move Table. 37797c478bd9Sstevel@tonic-gate */ 378057ef7aa9SRod Evans if (ofl->ofl_osmove || ofl->ofl_isparexpn) 378157ef7aa9SRod Evans update_move(ofl); 37827c478bd9Sstevel@tonic-gate 37837c478bd9Sstevel@tonic-gate /* 37847c478bd9Sstevel@tonic-gate * Build any output headers, version information, dynamic structure and 37857c478bd9Sstevel@tonic-gate * syminfo structure. 37867c478bd9Sstevel@tonic-gate */ 37877c478bd9Sstevel@tonic-gate if (update_oehdr(ofl) == S_ERROR) 37887c478bd9Sstevel@tonic-gate return (S_ERROR); 3789090a8d9eSAli Bahrami if (!(flags & FLG_OF_NOVERSEC)) { 3790090a8d9eSAli Bahrami if ((flags & FLG_OF_VERDEF) && 3791090a8d9eSAli Bahrami (update_overdef(ofl) == S_ERROR)) 3792090a8d9eSAli Bahrami return (S_ERROR); 3793090a8d9eSAli Bahrami if ((flags & FLG_OF_VERNEED) && 3794090a8d9eSAli Bahrami (update_overneed(ofl) == S_ERROR)) 37957c478bd9Sstevel@tonic-gate return (S_ERROR); 3796090a8d9eSAli Bahrami if ((flags & (FLG_OF_VERNEED | FLG_OF_VERDEF)) && 3797090a8d9eSAli Bahrami (update_oversym(ofl) == S_ERROR)) 37987c478bd9Sstevel@tonic-gate return (S_ERROR); 3799090a8d9eSAli Bahrami } 38007c478bd9Sstevel@tonic-gate if (flags & FLG_OF_DYNAMIC) { 38017c478bd9Sstevel@tonic-gate if (update_odynamic(ofl) == S_ERROR) 38027c478bd9Sstevel@tonic-gate return (S_ERROR); 38037c478bd9Sstevel@tonic-gate if (ofl->ofl_ossyminfo) 38047c478bd9Sstevel@tonic-gate if (update_osyminfo(ofl) == S_ERROR) 38057c478bd9Sstevel@tonic-gate return (S_ERROR); 38067c478bd9Sstevel@tonic-gate } 38077c478bd9Sstevel@tonic-gate 38081da7e599SAli Bahrami /* 38091da7e599SAli Bahrami * Sanity test: First and last data byte of a string table 38101da7e599SAli Bahrami * must be NULL. 38111da7e599SAli Bahrami */ 38121da7e599SAli Bahrami assert((ofl->ofl_osshstrtab == NULL) || 38131da7e599SAli Bahrami (*((char *)ofl->ofl_osshstrtab->os_outdata->d_buf) == '\0')); 38141da7e599SAli Bahrami assert((ofl->ofl_osshstrtab == NULL) || 38151da7e599SAli Bahrami (*(((char *)ofl->ofl_osshstrtab->os_outdata->d_buf) + 38161da7e599SAli Bahrami ofl->ofl_osshstrtab->os_outdata->d_size - 1) == '\0')); 38171da7e599SAli Bahrami 38181da7e599SAli Bahrami assert((ofl->ofl_osstrtab == NULL) || 38191da7e599SAli Bahrami (*((char *)ofl->ofl_osstrtab->os_outdata->d_buf) == '\0')); 38201da7e599SAli Bahrami assert((ofl->ofl_osstrtab == NULL) || 38211da7e599SAli Bahrami (*(((char *)ofl->ofl_osstrtab->os_outdata->d_buf) + 38221da7e599SAli Bahrami ofl->ofl_osstrtab->os_outdata->d_size - 1) == '\0')); 38231da7e599SAli Bahrami 38241da7e599SAli Bahrami assert((ofl->ofl_osdynstr == NULL) || 38251da7e599SAli Bahrami (*((char *)ofl->ofl_osdynstr->os_outdata->d_buf) == '\0')); 38261da7e599SAli Bahrami assert((ofl->ofl_osdynstr == NULL) || 38271da7e599SAli Bahrami (*(((char *)ofl->ofl_osdynstr->os_outdata->d_buf) + 38281da7e599SAli Bahrami ofl->ofl_osdynstr->os_outdata->d_size - DYNSTR_EXTRA_PAD - 1) == 38291da7e599SAli Bahrami '\0')); 38301da7e599SAli Bahrami 38317c478bd9Sstevel@tonic-gate /* 38327c478bd9Sstevel@tonic-gate * Emit Strtab diagnostics. 38337c478bd9Sstevel@tonic-gate */ 38345aefb655Srie DBG_CALL(Dbg_sec_strtab(ofl->ofl_lml, ofl->ofl_osshstrtab, 38355aefb655Srie ofl->ofl_shdrsttab)); 38365aefb655Srie DBG_CALL(Dbg_sec_strtab(ofl->ofl_lml, ofl->ofl_osstrtab, 38375aefb655Srie ofl->ofl_strtab)); 38385aefb655Srie DBG_CALL(Dbg_sec_strtab(ofl->ofl_lml, ofl->ofl_osdynstr, 38395aefb655Srie ofl->ofl_dynstrtab)); 38407c478bd9Sstevel@tonic-gate 38417c478bd9Sstevel@tonic-gate /* 38427c478bd9Sstevel@tonic-gate * Initialize the section headers string table index within the elf 38437c478bd9Sstevel@tonic-gate * header. 38447c478bd9Sstevel@tonic-gate */ 38457c478bd9Sstevel@tonic-gate /* LINTED */ 38467c478bd9Sstevel@tonic-gate if ((shscnndx = elf_ndxscn(ofl->ofl_osshstrtab->os_scn)) < 38477c478bd9Sstevel@tonic-gate SHN_LORESERVE) { 38485aefb655Srie ofl->ofl_nehdr->e_shstrndx = 38497c478bd9Sstevel@tonic-gate /* LINTED */ 38507c478bd9Sstevel@tonic-gate (Half)shscnndx; 38517c478bd9Sstevel@tonic-gate } else { 38527c478bd9Sstevel@tonic-gate /* 38537c478bd9Sstevel@tonic-gate * If the STRTAB section index doesn't fit into 38547c478bd9Sstevel@tonic-gate * e_shstrndx, then we store it in 'shdr[0].st_link'. 38557c478bd9Sstevel@tonic-gate */ 38567c478bd9Sstevel@tonic-gate Elf_Scn *scn; 38577c478bd9Sstevel@tonic-gate Shdr *shdr0; 38585aefb655Srie 38597c478bd9Sstevel@tonic-gate if ((scn = elf_getscn(ofl->ofl_elf, 0)) == NULL) { 38605aefb655Srie eprintf(ofl->ofl_lml, ERR_ELF, 38615aefb655Srie MSG_INTL(MSG_ELF_GETSCN), ofl->ofl_name); 38627c478bd9Sstevel@tonic-gate return (S_ERROR); 38637c478bd9Sstevel@tonic-gate } 38647c478bd9Sstevel@tonic-gate if ((shdr0 = elf_getshdr(scn)) == NULL) { 38655aefb655Srie eprintf(ofl->ofl_lml, ERR_ELF, 38665aefb655Srie MSG_INTL(MSG_ELF_GETSHDR), ofl->ofl_name); 38677c478bd9Sstevel@tonic-gate return (S_ERROR); 38687c478bd9Sstevel@tonic-gate } 38695aefb655Srie ofl->ofl_nehdr->e_shstrndx = SHN_XINDEX; 38707c478bd9Sstevel@tonic-gate shdr0->sh_link = shscnndx; 38717c478bd9Sstevel@tonic-gate } 38727c478bd9Sstevel@tonic-gate 38737c478bd9Sstevel@tonic-gate return ((uintptr_t)etext); 38747c478bd9Sstevel@tonic-gate } 3875