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 * 265aefb655Srie * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 277c478bd9Sstevel@tonic-gate * Use is subject to license terms. 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * Update the new output file image, perform virtual address, offset and 337c478bd9Sstevel@tonic-gate * displacement calculations on the program headers and sections headers, 347c478bd9Sstevel@tonic-gate * and generate any new output section information. 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate #include <stdio.h> 377c478bd9Sstevel@tonic-gate #include <string.h> 385aefb655Srie #include <debug.h> 397c478bd9Sstevel@tonic-gate #include "msg.h" 407c478bd9Sstevel@tonic-gate #include "_libld.h" 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * Comparison routine used by qsort() for sorting of the global yymbol list 447c478bd9Sstevel@tonic-gate * based off of the hashbuckets the symbol will eventually be deposited in. 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate static int 477c478bd9Sstevel@tonic-gate sym_hash_compare(Sym_s_list * s1, Sym_s_list * s2) 487c478bd9Sstevel@tonic-gate { 497c478bd9Sstevel@tonic-gate return (s1->sl_hval - s2->sl_hval); 507c478bd9Sstevel@tonic-gate } 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * Build and update any output symbol tables. Here we work on all the symbol 547c478bd9Sstevel@tonic-gate * tables at once to reduce the duplication of symbol and string manipulation. 557c478bd9Sstevel@tonic-gate * Symbols and their associated strings are copied from the read-only input 567c478bd9Sstevel@tonic-gate * file images to the output image and their values and index's updated in the 577c478bd9Sstevel@tonic-gate * output image. 587c478bd9Sstevel@tonic-gate */ 595aefb655Srie static Addr 607c478bd9Sstevel@tonic-gate update_osym(Ofl_desc *ofl) 617c478bd9Sstevel@tonic-gate { 62*0bc07c75Srie Listnode *lnp1; 637c478bd9Sstevel@tonic-gate Sym_desc *sdp; 647c478bd9Sstevel@tonic-gate Sym_avlnode *sav; 657c478bd9Sstevel@tonic-gate Sg_desc *sgp, *tsgp = 0, *dsgp = 0, *esgp = 0; 667c478bd9Sstevel@tonic-gate Os_desc *osp; 677c478bd9Sstevel@tonic-gate Ifl_desc *ifl; 687c478bd9Sstevel@tonic-gate Word bssndx, etext_ndx, edata_ndx = 0, end_ndx, start_ndx; 697c478bd9Sstevel@tonic-gate Word end_abs = 0, etext_abs = 0, edata_abs; 707c478bd9Sstevel@tonic-gate Word tlsbssndx = 0, sunwbssndx = 0, sunwdata1ndx; 7154d82594Sseizo #if (defined(__i386) || defined(__amd64)) && defined(_ELF64) 7254d82594Sseizo Word lbssndx = 0; 7354d82594Sseizo Addr lbssaddr = 0; 7454d82594Sseizo #endif 757c478bd9Sstevel@tonic-gate Addr bssaddr, etext = 0, edata = 0, end = 0, start = 0; 767c478bd9Sstevel@tonic-gate Addr tlsbssaddr = 0; 777c478bd9Sstevel@tonic-gate Addr sunwbssaddr = 0, sunwdata1addr; 787c478bd9Sstevel@tonic-gate int start_set = 0; 797c478bd9Sstevel@tonic-gate Sym _sym = {0}, *sym, *symtab = 0, *dynsym = 0; 807c478bd9Sstevel@tonic-gate Word symtab_ndx = 0; /* index into .symtab */ 817c478bd9Sstevel@tonic-gate Word dynsym_ndx = 0; /* index into .dynsym */ 827c478bd9Sstevel@tonic-gate Word scopesym_ndx = 0; /* index into scoped symbols */ 837c478bd9Sstevel@tonic-gate Word *symndx = 0; /* Symbol index (for relocation use) */ 847c478bd9Sstevel@tonic-gate Word *symshndx = 0; /* .symtab_shndx table */ 857c478bd9Sstevel@tonic-gate Word *dynshndx = 0; /* .dynsym_shndx table */ 867c478bd9Sstevel@tonic-gate Str_tbl *shstrtab; 877c478bd9Sstevel@tonic-gate Str_tbl *strtab; 887c478bd9Sstevel@tonic-gate Str_tbl *dynstr; 897c478bd9Sstevel@tonic-gate Word *hashtab; /* hash table pointer */ 907c478bd9Sstevel@tonic-gate Word *hashbkt; /* hash table bucket pointer */ 917c478bd9Sstevel@tonic-gate Word *hashchain; /* hash table chain pointer */ 927c478bd9Sstevel@tonic-gate Word hashval; /* value of hash function */ 937c478bd9Sstevel@tonic-gate Wk_desc *wkp; 947c478bd9Sstevel@tonic-gate List weak = {NULL, NULL}; 957c478bd9Sstevel@tonic-gate Word flags = ofl->ofl_flags; 967c478bd9Sstevel@tonic-gate Word dtflags_1 = ofl->ofl_dtflags_1; 977c478bd9Sstevel@tonic-gate Versym *versym; 987c478bd9Sstevel@tonic-gate Gottable *gottable; /* used for display got debugging */ 997c478bd9Sstevel@tonic-gate /* information */ 1007c478bd9Sstevel@tonic-gate Gottable *_gottable; 1017c478bd9Sstevel@tonic-gate Syminfo *syminfo; 1027c478bd9Sstevel@tonic-gate Sym_s_list *sorted_syms; /* table to hold sorted symbols */ 1037c478bd9Sstevel@tonic-gate Word ssndx; /* global index into sorted_syms */ 1047c478bd9Sstevel@tonic-gate Word scndx; /* scoped index into sorted_syms */ 1057c478bd9Sstevel@tonic-gate uint_t stoff; /* string offset */ 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * Initialize pointers to the symbol table entries and the symbol 1097c478bd9Sstevel@tonic-gate * table strings. Skip the first symbol entry and the first string 1107c478bd9Sstevel@tonic-gate * table byte. Note that if we are not generating any output symbol 1117c478bd9Sstevel@tonic-gate * tables we must still generate and update an internal copies so 1127c478bd9Sstevel@tonic-gate * that the relocation phase has the correct information. 1137c478bd9Sstevel@tonic-gate */ 1147c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_STRIP) || (flags & FLG_OF_RELOBJ) || 1157c478bd9Sstevel@tonic-gate ((flags & FLG_OF_STATIC) && ofl->ofl_osversym)) { 1167c478bd9Sstevel@tonic-gate symtab = (Sym *)ofl->ofl_ossymtab->os_outdata->d_buf; 1177c478bd9Sstevel@tonic-gate symtab[symtab_ndx++] = _sym; 1187c478bd9Sstevel@tonic-gate if (ofl->ofl_ossymshndx) 1197c478bd9Sstevel@tonic-gate symshndx = (Word *)ofl->ofl_ossymshndx->os_outdata->d_buf; 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate if ((flags & FLG_OF_DYNAMIC) && !(flags & FLG_OF_RELOBJ)) { 1227c478bd9Sstevel@tonic-gate dynsym = (Sym *)ofl->ofl_osdynsym->os_outdata->d_buf; 1237c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx++] = _sym; 1247c478bd9Sstevel@tonic-gate /* 1257c478bd9Sstevel@tonic-gate * Initialize the hash table. 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate hashtab = (Word *)(ofl->ofl_oshash->os_outdata->d_buf); 1287c478bd9Sstevel@tonic-gate hashbkt = &hashtab[2]; 1297c478bd9Sstevel@tonic-gate hashchain = &hashtab[2 + ofl->ofl_hashbkts]; 1307c478bd9Sstevel@tonic-gate hashtab[0] = ofl->ofl_hashbkts; 1317c478bd9Sstevel@tonic-gate hashtab[1] = ofl->ofl_dynshdrcnt + ofl->ofl_globcnt + 1327c478bd9Sstevel@tonic-gate ofl->ofl_lregsymcnt + 1; 1337c478bd9Sstevel@tonic-gate if (ofl->ofl_osdynshndx) 1347c478bd9Sstevel@tonic-gate dynshndx = (Word *)ofl->ofl_osdynshndx->os_outdata->d_buf; 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* 1387c478bd9Sstevel@tonic-gate * symndx is the symbol index to be used for relocation processing. It 1397c478bd9Sstevel@tonic-gate * points to the relevant symtab's (.dynsym or .symtab) symbol ndx. 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate if (dynsym) 1427c478bd9Sstevel@tonic-gate symndx = &dynsym_ndx; 1437c478bd9Sstevel@tonic-gate else 1447c478bd9Sstevel@tonic-gate symndx = &symtab_ndx; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* 1477c478bd9Sstevel@tonic-gate * If we have version definitions initialize the version symbol index 1487c478bd9Sstevel@tonic-gate * table. There is one entry for each symbol which contains the symbols 1497c478bd9Sstevel@tonic-gate * version index. 1507c478bd9Sstevel@tonic-gate */ 1517c478bd9Sstevel@tonic-gate if ((flags & (FLG_OF_VERDEF | FLG_OF_NOVERSEC)) == FLG_OF_VERDEF) { 1527c478bd9Sstevel@tonic-gate versym = (Versym *)ofl->ofl_osversym->os_outdata->d_buf; 1537c478bd9Sstevel@tonic-gate versym[0] = 0; 1547c478bd9Sstevel@tonic-gate } else 1557c478bd9Sstevel@tonic-gate versym = 0; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* 1587c478bd9Sstevel@tonic-gate * If syminfo section exists be prepared to fill it in. 1597c478bd9Sstevel@tonic-gate */ 1607c478bd9Sstevel@tonic-gate if (ofl->ofl_ossyminfo) { 1617c478bd9Sstevel@tonic-gate syminfo = ofl->ofl_ossyminfo->os_outdata->d_buf; 1627c478bd9Sstevel@tonic-gate syminfo[0].si_flags = SYMINFO_CURRENT; 1637c478bd9Sstevel@tonic-gate } else 1647c478bd9Sstevel@tonic-gate syminfo = 0; 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * Setup our string tables. 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate shstrtab = ofl->ofl_shdrsttab; 1707c478bd9Sstevel@tonic-gate strtab = ofl->ofl_strtab; 1717c478bd9Sstevel@tonic-gate dynstr = ofl->ofl_dynstrtab; 1727c478bd9Sstevel@tonic-gate 1735aefb655Srie DBG_CALL(Dbg_syms_sec_title(ofl->ofl_lml)); 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate /* 1767c478bd9Sstevel@tonic-gate * Add the output file name to the first .symtab symbol. 1777c478bd9Sstevel@tonic-gate */ 1787c478bd9Sstevel@tonic-gate if (symtab) { 1797c478bd9Sstevel@tonic-gate (void) st_setstring(strtab, ofl->ofl_name, &stoff); 1807c478bd9Sstevel@tonic-gate sym = &symtab[symtab_ndx++]; 1817c478bd9Sstevel@tonic-gate /* LINTED */ 1827c478bd9Sstevel@tonic-gate sym->st_name = stoff; 1837c478bd9Sstevel@tonic-gate sym->st_value = 0; 1847c478bd9Sstevel@tonic-gate sym->st_size = 0; 1857c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(STB_LOCAL, STT_FILE); 1867c478bd9Sstevel@tonic-gate sym->st_other = 0; 1877c478bd9Sstevel@tonic-gate sym->st_shndx = SHN_ABS; 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate if (versym && !dynsym) 1907c478bd9Sstevel@tonic-gate versym[1] = 0; 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate /* 1947c478bd9Sstevel@tonic-gate * If we are to display GOT summary information, then allocate 1957c478bd9Sstevel@tonic-gate * the buffer to 'cache' the GOT symbols into now. 1967c478bd9Sstevel@tonic-gate */ 1975aefb655Srie if (DBG_ENABLED) { 1987c478bd9Sstevel@tonic-gate if ((_gottable = gottable = libld_calloc(ofl->ofl_gotcnt, 1997c478bd9Sstevel@tonic-gate sizeof (Gottable))) == 0) 2007c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate /* 2047c478bd9Sstevel@tonic-gate * Traverse the program headers. Determine the last executable segment 2057c478bd9Sstevel@tonic-gate * and the last data segment so that we can update etext and edata. If 2067c478bd9Sstevel@tonic-gate * we have empty segments (reservations) record them for setting _end. 2077c478bd9Sstevel@tonic-gate */ 2087c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_segs, lnp1, sgp)) { 209*0bc07c75Srie Phdr *phd = &(sgp->sg_phdr); 210*0bc07c75Srie Os_desc **ospp; 211*0bc07c75Srie Aliste off; 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate if (phd->p_type == PT_LOAD) { 214*0bc07c75Srie if (sgp->sg_osdescs != NULL) { 215*0bc07c75Srie Word _flags = phd->p_flags & (PF_W | PF_R); 216*0bc07c75Srie 21754d82594Sseizo if (_flags == PF_R) { 21854d82594Sseizo #if (defined(__i386) || defined(__amd64)) && defined(_ELF64) 219*0bc07c75Srie Shdr *shdr; 220*0bc07c75Srie 221*0bc07c75Srie osp = (Os_desc *)sgp->sg_osdescs->al_data[0]; 222*0bc07c75Srie shdr = osp->os_shdr; 223*0bc07c75Srie 22454d82594Sseizo if (((shdr->sh_flags & SHF_AMD64_LARGE)) == 0) 225*0bc07c75Srie tsgp = sgp; 22654d82594Sseizo #else 22754d82594Sseizo tsgp = sgp; 22854d82594Sseizo #endif 22954d82594Sseizo } else if (_flags == (PF_W | PF_R)) 23054d82594Sseizo dsgp = sgp; 2317c478bd9Sstevel@tonic-gate } else if (sgp->sg_flags & FLG_SG_EMPTY) 23254d82594Sseizo esgp = sgp; 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * Generate a section symbol for each output section. 2377c478bd9Sstevel@tonic-gate */ 238*0bc07c75Srie for (ALIST_TRAVERSE(sgp->sg_osdescs, off, ospp)) { 2397c478bd9Sstevel@tonic-gate Word sectndx; 2407c478bd9Sstevel@tonic-gate 241*0bc07c75Srie osp = *ospp; 242*0bc07c75Srie 2437c478bd9Sstevel@tonic-gate sym = &_sym; 2447c478bd9Sstevel@tonic-gate sym->st_value = osp->os_shdr->sh_addr; 2457c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(STB_LOCAL, STT_SECTION); 2467c478bd9Sstevel@tonic-gate /* LINTED */ 2477c478bd9Sstevel@tonic-gate sectndx = elf_ndxscn(osp->os_scn); 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate if (symtab) { 2507c478bd9Sstevel@tonic-gate if (sectndx >= SHN_LORESERVE) { 2517c478bd9Sstevel@tonic-gate symshndx[symtab_ndx] = sectndx; 2527c478bd9Sstevel@tonic-gate sym->st_shndx = SHN_XINDEX; 2537c478bd9Sstevel@tonic-gate } else { 2547c478bd9Sstevel@tonic-gate /* LINTED */ 2557c478bd9Sstevel@tonic-gate sym->st_shndx = (Half)sectndx; 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate symtab[symtab_ndx++] = *sym; 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate if (dynsym && (osp->os_flags & FLG_OS_OUTREL)) 2617c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx++] = *sym; 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate if ((dynsym == 0) || (osp->os_flags & FLG_OS_OUTREL)) { 2647c478bd9Sstevel@tonic-gate if (versym) 2657c478bd9Sstevel@tonic-gate versym[*symndx - 1] = 0; 2667c478bd9Sstevel@tonic-gate osp->os_scnsymndx = *symndx - 1; 2675aefb655Srie DBG_CALL(Dbg_syms_sec_entry(ofl->ofl_lml, 2685aefb655Srie osp->os_scnsymndx, sgp, osp)); 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate /* 2727c478bd9Sstevel@tonic-gate * Generate the .shstrtab for this section. 2737c478bd9Sstevel@tonic-gate */ 2747c478bd9Sstevel@tonic-gate (void) st_setstring(shstrtab, osp->os_name, &stoff); 2757c478bd9Sstevel@tonic-gate osp->os_shdr->sh_name = (Word)stoff; 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate /* 2787c478bd9Sstevel@tonic-gate * Find the section index for our special symbols. 2797c478bd9Sstevel@tonic-gate */ 2807c478bd9Sstevel@tonic-gate if (sgp == tsgp) { 2817c478bd9Sstevel@tonic-gate /* LINTED */ 2827c478bd9Sstevel@tonic-gate etext_ndx = elf_ndxscn(osp->os_scn); 2837c478bd9Sstevel@tonic-gate } else if (dsgp == sgp) { 2847c478bd9Sstevel@tonic-gate if (osp->os_shdr->sh_type != SHT_NOBITS) { 2857c478bd9Sstevel@tonic-gate /* LINTED */ 2867c478bd9Sstevel@tonic-gate edata_ndx = elf_ndxscn(osp->os_scn); 2877c478bd9Sstevel@tonic-gate } 2887c478bd9Sstevel@tonic-gate } 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate if (start_set == 0) { 2917c478bd9Sstevel@tonic-gate start = sgp->sg_phdr.p_vaddr; 2927c478bd9Sstevel@tonic-gate /* LINTED */ 2937c478bd9Sstevel@tonic-gate start_ndx = elf_ndxscn(osp->os_scn); 2947c478bd9Sstevel@tonic-gate start_set++; 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate /* 3007c478bd9Sstevel@tonic-gate * Add local register symbols to the .dynsym. These are required as 3017c478bd9Sstevel@tonic-gate * DT_REGISTER .dynamic entries must have a symbol to reference. 3027c478bd9Sstevel@tonic-gate */ 3037c478bd9Sstevel@tonic-gate if (ofl->ofl_regsyms && dynsym) { 3047c478bd9Sstevel@tonic-gate int ndx; 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate for (ndx = 0; ndx < ofl->ofl_regsymsno; ndx++) { 3077c478bd9Sstevel@tonic-gate Sym_desc * rsdp; 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate if ((rsdp = ofl->ofl_regsyms[ndx]) == 0) 3107c478bd9Sstevel@tonic-gate continue; 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate if (((rsdp->sd_flags1 & FLG_SY1_LOCL) == 0) && 3137c478bd9Sstevel@tonic-gate (ELF_ST_BIND(rsdp->sd_sym->st_info) != STB_LOCAL)) 3147c478bd9Sstevel@tonic-gate continue; 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx] = *(rsdp->sd_sym); 3177c478bd9Sstevel@tonic-gate rsdp->sd_symndx = *symndx; 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate if (dynsym[dynsym_ndx].st_name) { 3207c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, rsdp->sd_name, 3217c478bd9Sstevel@tonic-gate &stoff); 3227c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx].st_name = stoff; 3237c478bd9Sstevel@tonic-gate } 3247c478bd9Sstevel@tonic-gate dynsym_ndx++; 3257c478bd9Sstevel@tonic-gate } 3267c478bd9Sstevel@tonic-gate } 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate /* 3297c478bd9Sstevel@tonic-gate * Having traversed all the output segments, warn the user if the 3307c478bd9Sstevel@tonic-gate * traditional text or data segments don't exist. Otherwise from these 3317c478bd9Sstevel@tonic-gate * segments establish the values for `etext', `edata', `end', `END', 3327c478bd9Sstevel@tonic-gate * and `START'. 3337c478bd9Sstevel@tonic-gate */ 3347c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_RELOBJ)) { 3357c478bd9Sstevel@tonic-gate Sg_desc * sgp; 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate if (tsgp) 3387c478bd9Sstevel@tonic-gate etext = tsgp->sg_phdr.p_vaddr + tsgp->sg_phdr.p_filesz; 3397c478bd9Sstevel@tonic-gate else { 3407c478bd9Sstevel@tonic-gate etext = (Addr)0; 3417c478bd9Sstevel@tonic-gate etext_ndx = SHN_ABS; 3427c478bd9Sstevel@tonic-gate etext_abs = 1; 3437c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_VERBOSE) 3445aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 3457c478bd9Sstevel@tonic-gate MSG_INTL(MSG_UPD_NOREADSEG)); 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate if (dsgp) { 3487c478bd9Sstevel@tonic-gate edata = dsgp->sg_phdr.p_vaddr + dsgp->sg_phdr.p_filesz; 3497c478bd9Sstevel@tonic-gate } else { 3507c478bd9Sstevel@tonic-gate edata = (Addr)0; 3517c478bd9Sstevel@tonic-gate edata_ndx = SHN_ABS; 3527c478bd9Sstevel@tonic-gate edata_abs = 1; 3537c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_VERBOSE) 3545aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 3557c478bd9Sstevel@tonic-gate MSG_INTL(MSG_UPD_NORDWRSEG)); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate if (dsgp == 0) { 3597c478bd9Sstevel@tonic-gate if (tsgp) 3607c478bd9Sstevel@tonic-gate sgp = tsgp; 3617c478bd9Sstevel@tonic-gate else 3627c478bd9Sstevel@tonic-gate sgp = 0; 3637c478bd9Sstevel@tonic-gate } else if (tsgp == 0) 3647c478bd9Sstevel@tonic-gate sgp = dsgp; 3657c478bd9Sstevel@tonic-gate else if (dsgp->sg_phdr.p_vaddr > tsgp->sg_phdr.p_vaddr) 3667c478bd9Sstevel@tonic-gate sgp = dsgp; 3677c478bd9Sstevel@tonic-gate else if (dsgp->sg_phdr.p_vaddr < tsgp->sg_phdr.p_vaddr) 3687c478bd9Sstevel@tonic-gate sgp = tsgp; 3697c478bd9Sstevel@tonic-gate else { 3707c478bd9Sstevel@tonic-gate /* 3717c478bd9Sstevel@tonic-gate * One of the segments must be of zero size. 3727c478bd9Sstevel@tonic-gate */ 3737c478bd9Sstevel@tonic-gate if (tsgp->sg_phdr.p_memsz) 3747c478bd9Sstevel@tonic-gate sgp = tsgp; 3757c478bd9Sstevel@tonic-gate else 3767c478bd9Sstevel@tonic-gate sgp = dsgp; 3777c478bd9Sstevel@tonic-gate } 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate if (esgp && (esgp->sg_phdr.p_vaddr > sgp->sg_phdr.p_vaddr)) 3807c478bd9Sstevel@tonic-gate sgp = esgp; 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate if (sgp) { 3837c478bd9Sstevel@tonic-gate end = sgp->sg_phdr.p_vaddr + sgp->sg_phdr.p_memsz; 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate /* 3867c478bd9Sstevel@tonic-gate * If we're dealing with a memory reservation there are 3877c478bd9Sstevel@tonic-gate * no sections to establish an index for _end, so assign 3887c478bd9Sstevel@tonic-gate * it as an absolute. 3897c478bd9Sstevel@tonic-gate */ 390*0bc07c75Srie if (sgp->sg_osdescs != NULL) { 391*0bc07c75Srie Os_desc **ospp; 392*0bc07c75Srie Alist *alp = sgp->sg_osdescs; 393*0bc07c75Srie Aliste last = alp->al_next - alp->al_size; 3947c478bd9Sstevel@tonic-gate 395*0bc07c75Srie /* 396*0bc07c75Srie * Determine the last section for this segment. 397*0bc07c75Srie */ 398*0bc07c75Srie /* LINTED */ 399*0bc07c75Srie ospp = (Os_desc **)((char *)alp + last); 4007c478bd9Sstevel@tonic-gate /* LINTED */ 401*0bc07c75Srie end_ndx = elf_ndxscn((*ospp)->os_scn); 4027c478bd9Sstevel@tonic-gate } else { 4037c478bd9Sstevel@tonic-gate end_ndx = SHN_ABS; 4047c478bd9Sstevel@tonic-gate end_abs = 1; 4057c478bd9Sstevel@tonic-gate } 4067c478bd9Sstevel@tonic-gate } else { 4077c478bd9Sstevel@tonic-gate end = (Addr) 0; 4087c478bd9Sstevel@tonic-gate end_ndx = SHN_ABS; 4097c478bd9Sstevel@tonic-gate end_abs = 1; 4105aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 4115aefb655Srie MSG_INTL(MSG_UPD_NOSEG)); 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate 4155aefb655Srie DBG_CALL(Dbg_syms_up_title(ofl->ofl_lml)); 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate /* 4187c478bd9Sstevel@tonic-gate * Initialize the scoped symbol table entry point. This is for all 4197c478bd9Sstevel@tonic-gate * the global symbols that have been scoped to locals and will be 4207c478bd9Sstevel@tonic-gate * filled in during global symbol processing so that we don't have 4217c478bd9Sstevel@tonic-gate * to traverse the globals symbol hash array more than once. 4227c478bd9Sstevel@tonic-gate */ 4237c478bd9Sstevel@tonic-gate if (symtab) { 4247c478bd9Sstevel@tonic-gate scopesym_ndx = symtab_ndx; 4257c478bd9Sstevel@tonic-gate symtab_ndx += ofl->ofl_scopecnt; 4267c478bd9Sstevel@tonic-gate } 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate /* 4297c478bd9Sstevel@tonic-gate * Assign .sunwdata1 information 4307c478bd9Sstevel@tonic-gate */ 4317c478bd9Sstevel@tonic-gate if (ofl->ofl_issunwdata1) { 4327c478bd9Sstevel@tonic-gate osp = ofl->ofl_issunwdata1->is_osdesc; 4337c478bd9Sstevel@tonic-gate sunwdata1addr = (Addr)(osp->os_shdr->sh_addr + 4347c478bd9Sstevel@tonic-gate ofl->ofl_issunwdata1->is_indata->d_off); 4357c478bd9Sstevel@tonic-gate /* LINTED */ 4367c478bd9Sstevel@tonic-gate sunwdata1ndx = elf_ndxscn(osp->os_scn); 4377c478bd9Sstevel@tonic-gate ofl->ofl_sunwdata1ndx = osp->os_scnsymndx; 4387c478bd9Sstevel@tonic-gate } 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate /* 4417c478bd9Sstevel@tonic-gate * If we are generating a .symtab collect all the local symbols, 4427c478bd9Sstevel@tonic-gate * assigning a new virtual address or displacement (value). 4437c478bd9Sstevel@tonic-gate */ 4447c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_objs, lnp1, ifl)) { 4457c478bd9Sstevel@tonic-gate Xword lndx, local; 4467c478bd9Sstevel@tonic-gate Is_desc * isc; 4477c478bd9Sstevel@tonic-gate 4487c478bd9Sstevel@tonic-gate /* 4497c478bd9Sstevel@tonic-gate * Check that we have local symbols to process. If the user 4507c478bd9Sstevel@tonic-gate * has indicated scoping then scan the global symbols also 4517c478bd9Sstevel@tonic-gate * looking for entries from this file to reduce to locals. 4527c478bd9Sstevel@tonic-gate */ 4537c478bd9Sstevel@tonic-gate if ((local = ifl->ifl_locscnt) == 0) 4547c478bd9Sstevel@tonic-gate continue; 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate for (lndx = 1; lndx < local; lndx++) { 4577c478bd9Sstevel@tonic-gate Listnode *lnp2; 4587c478bd9Sstevel@tonic-gate Gotndx *gnp; 4597c478bd9Sstevel@tonic-gate unsigned char type; 4607c478bd9Sstevel@tonic-gate Word *_symshndx; 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate sdp = ifl->ifl_oldndx[lndx]; 4637c478bd9Sstevel@tonic-gate sym = sdp->sd_sym; 4647c478bd9Sstevel@tonic-gate 4655aefb655Srie #if defined(sparc) || defined(__sparcv9) 4667c478bd9Sstevel@tonic-gate /* 4677c478bd9Sstevel@tonic-gate * Assign a got offset if necessary. 4687c478bd9Sstevel@tonic-gate */ 4695aefb655Srie if (ld_assign_got(ofl, sdp) == S_ERROR) 4707c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 4717c478bd9Sstevel@tonic-gate #elif defined(i386) || defined(__amd64) 4727c478bd9Sstevel@tonic-gate /* nothing to do */ 4737c478bd9Sstevel@tonic-gate #else 4747c478bd9Sstevel@tonic-gate #error Unknown architecture! 4757c478bd9Sstevel@tonic-gate #endif 4765aefb655Srie if (DBG_ENABLED) { 4777c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&sdp->sd_GOTndxs, lnp2, gnp)) { 4787c478bd9Sstevel@tonic-gate _gottable->gt_sym = sdp; 4797c478bd9Sstevel@tonic-gate _gottable->gt_gndx.gn_gotndx = gnp->gn_gotndx; 4807c478bd9Sstevel@tonic-gate _gottable->gt_gndx.gn_addend = gnp->gn_addend; 4817c478bd9Sstevel@tonic-gate _gottable++; 4827c478bd9Sstevel@tonic-gate } 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate if ((type = ELF_ST_TYPE(sym->st_info)) == STT_SECTION) 4867c478bd9Sstevel@tonic-gate continue; 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate /* 4897c478bd9Sstevel@tonic-gate * Ignore any symbols that have been marked as invalid 4907c478bd9Sstevel@tonic-gate * during input processing. Providing these aren't used 4917c478bd9Sstevel@tonic-gate * for relocation they'll just be dropped from the 4927c478bd9Sstevel@tonic-gate * output image. 4937c478bd9Sstevel@tonic-gate */ 4947c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_INVALID) 4957c478bd9Sstevel@tonic-gate continue; 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate /* 4987c478bd9Sstevel@tonic-gate * If the section that this symbol was associated 4997c478bd9Sstevel@tonic-gate * with has been discarded - then we discard 5007c478bd9Sstevel@tonic-gate * the local symbol along with it. 5017c478bd9Sstevel@tonic-gate */ 5027c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_ISDISC) 5037c478bd9Sstevel@tonic-gate continue; 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate /* 5067c478bd9Sstevel@tonic-gate * Generate an output symbol to represent this input 5077c478bd9Sstevel@tonic-gate * symbol. Even if the symbol table is to be stripped 5087c478bd9Sstevel@tonic-gate * we still need to update any local symbols that are 5097c478bd9Sstevel@tonic-gate * used during relocation. 5107c478bd9Sstevel@tonic-gate */ 5117c478bd9Sstevel@tonic-gate _symshndx = 0; 5127c478bd9Sstevel@tonic-gate if (symtab && (!(ofl->ofl_flags1 & FLG_OF1_REDLSYM) || 5137c478bd9Sstevel@tonic-gate (sdp->sd_psyminfo))) { 5147c478bd9Sstevel@tonic-gate if (!dynsym) 5157c478bd9Sstevel@tonic-gate sdp->sd_symndx = *symndx; 5167c478bd9Sstevel@tonic-gate symtab[symtab_ndx] = *sym; 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate /* 5197c478bd9Sstevel@tonic-gate * Provided this isn't an unnamed register 5207c478bd9Sstevel@tonic-gate * symbol, update its name. 5217c478bd9Sstevel@tonic-gate */ 5227c478bd9Sstevel@tonic-gate if (((sdp->sd_flags & FLG_SY_REGSYM) == 0) || 5237c478bd9Sstevel@tonic-gate symtab[symtab_ndx].st_name) { 5247c478bd9Sstevel@tonic-gate (void) st_setstring(strtab, 5257c478bd9Sstevel@tonic-gate sdp->sd_name, &stoff); 5267c478bd9Sstevel@tonic-gate symtab[symtab_ndx].st_name = stoff; 5277c478bd9Sstevel@tonic-gate } 5287c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_CLEAN; 5297c478bd9Sstevel@tonic-gate if (symshndx) 5307c478bd9Sstevel@tonic-gate _symshndx = &symshndx[symtab_ndx]; 5317c478bd9Sstevel@tonic-gate sdp->sd_sym = sym = &symtab[symtab_ndx++]; 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate if ((sdp->sd_flags & FLG_SY_SPECSEC) && 5347c478bd9Sstevel@tonic-gate (sym->st_shndx == SHN_ABS)) 5357c478bd9Sstevel@tonic-gate continue; 5367c478bd9Sstevel@tonic-gate } else { 5377c478bd9Sstevel@tonic-gate /* 5387c478bd9Sstevel@tonic-gate * If this symbol requires modifying to provide 5397c478bd9Sstevel@tonic-gate * for a relocation or move table update, make 5407c478bd9Sstevel@tonic-gate * a copy of it. 5417c478bd9Sstevel@tonic-gate */ 5427c478bd9Sstevel@tonic-gate if (!(sdp->sd_flags & FLG_SY_UPREQD) && 5437c478bd9Sstevel@tonic-gate !(sdp->sd_psyminfo)) 5447c478bd9Sstevel@tonic-gate continue; 5457c478bd9Sstevel@tonic-gate if ((sdp->sd_flags & FLG_SY_SPECSEC) && 5467c478bd9Sstevel@tonic-gate (sym->st_shndx == SHN_ABS)) 5477c478bd9Sstevel@tonic-gate continue; 5487c478bd9Sstevel@tonic-gate 5495aefb655Srie if (ld_sym_copy(sdp) == S_ERROR) 5507c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 5517c478bd9Sstevel@tonic-gate sym = sdp->sd_sym; 5527c478bd9Sstevel@tonic-gate } 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate /* 5557c478bd9Sstevel@tonic-gate * Update the symbols contents if necessary. 5567c478bd9Sstevel@tonic-gate */ 5577c478bd9Sstevel@tonic-gate if (type == STT_FILE) { 5587c478bd9Sstevel@tonic-gate sdp->sd_shndx = sym->st_shndx = SHN_ABS; 5597c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_SPECSEC; 5607c478bd9Sstevel@tonic-gate continue; 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate 5637c478bd9Sstevel@tonic-gate /* 5647c478bd9Sstevel@tonic-gate * If we are expanding the locally bound partially 5657c478bd9Sstevel@tonic-gate * initialized symbols, then update the address here. 5667c478bd9Sstevel@tonic-gate */ 5677c478bd9Sstevel@tonic-gate if (ofl->ofl_issunwdata1 && 5687c478bd9Sstevel@tonic-gate (sdp->sd_flags & FLG_SY_PAREXPN)) { 5697c478bd9Sstevel@tonic-gate static Addr laddr = 0; 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate sym->st_shndx = sunwdata1ndx; 5727c478bd9Sstevel@tonic-gate sdp->sd_isc = ofl->ofl_issunwdata1; 5737c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_RELOBJ) 5747c478bd9Sstevel@tonic-gate sym->st_value = sunwdata1addr; 5757c478bd9Sstevel@tonic-gate else { 5767c478bd9Sstevel@tonic-gate sym->st_value = laddr; 5777c478bd9Sstevel@tonic-gate laddr += sym->st_size; 5787c478bd9Sstevel@tonic-gate } 5797c478bd9Sstevel@tonic-gate sunwdata1addr += sym->st_size; 5807c478bd9Sstevel@tonic-gate } 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate /* 5837c478bd9Sstevel@tonic-gate * If this isn't an UNDEF symbol (ie. an input section 5847c478bd9Sstevel@tonic-gate * is associated), update the symbols value and index. 5857c478bd9Sstevel@tonic-gate */ 5867c478bd9Sstevel@tonic-gate if ((isc = sdp->sd_isc) != 0) { 5877c478bd9Sstevel@tonic-gate Word sectndx; 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate osp = isc->is_osdesc; 5907c478bd9Sstevel@tonic-gate /* LINTED */ 5917c478bd9Sstevel@tonic-gate sym->st_value += 5927c478bd9Sstevel@tonic-gate (Off)_elf_getxoff(isc->is_indata); 5937c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_RELOBJ)) { 5947c478bd9Sstevel@tonic-gate sym->st_value += osp->os_shdr->sh_addr; 5957c478bd9Sstevel@tonic-gate /* 5967c478bd9Sstevel@tonic-gate * TLS symbols are relative to 5977c478bd9Sstevel@tonic-gate * the TLS segment. 5987c478bd9Sstevel@tonic-gate */ 5997c478bd9Sstevel@tonic-gate if ((ELF_ST_TYPE(sym->st_info) == 6007c478bd9Sstevel@tonic-gate STT_TLS) && (ofl->ofl_tlsphdr)) 6017c478bd9Sstevel@tonic-gate sym->st_value -= 6027c478bd9Sstevel@tonic-gate ofl->ofl_tlsphdr->p_vaddr; 6037c478bd9Sstevel@tonic-gate } 6047c478bd9Sstevel@tonic-gate /* LINTED */ 6057c478bd9Sstevel@tonic-gate if ((sdp->sd_shndx = sectndx = 6067c478bd9Sstevel@tonic-gate elf_ndxscn(osp->os_scn)) >= SHN_LORESERVE) { 6077c478bd9Sstevel@tonic-gate if (_symshndx) { 6087c478bd9Sstevel@tonic-gate *_symshndx = sectndx; 6097c478bd9Sstevel@tonic-gate } 6107c478bd9Sstevel@tonic-gate sym->st_shndx = SHN_XINDEX; 6117c478bd9Sstevel@tonic-gate } else { 6127c478bd9Sstevel@tonic-gate /* LINTED */ 6137c478bd9Sstevel@tonic-gate sym->st_shndx = sectndx; 6147c478bd9Sstevel@tonic-gate } 6157c478bd9Sstevel@tonic-gate } 6167c478bd9Sstevel@tonic-gate } 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate /* 6207c478bd9Sstevel@tonic-gate * Two special symbols are `_init' and `_fini'. If these are supplied 6217c478bd9Sstevel@tonic-gate * by crti.o then they are used to represent the total concatenation of 6227c478bd9Sstevel@tonic-gate * the `.init' and `.fini' sections. In this case determine the size of 6237c478bd9Sstevel@tonic-gate * these sections and updated the symbols value accordingly. 6247c478bd9Sstevel@tonic-gate */ 6255aefb655Srie if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_INIT_U), SYM_NOHASH, 0, 6267c478bd9Sstevel@tonic-gate ofl)) != NULL) && (sdp->sd_ref == REF_REL_NEED) && sdp->sd_isc && 6277c478bd9Sstevel@tonic-gate (strcmp(sdp->sd_isc->is_name, MSG_ORIG(MSG_SCN_INIT)) == 0)) { 6287c478bd9Sstevel@tonic-gate 6295aefb655Srie if (ld_sym_copy(sdp) == S_ERROR) 6307c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 6317c478bd9Sstevel@tonic-gate sdp->sd_sym->st_size = 6327c478bd9Sstevel@tonic-gate sdp->sd_isc->is_osdesc->os_shdr->sh_size; 6337c478bd9Sstevel@tonic-gate } 6345aefb655Srie if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_FINI_U), SYM_NOHASH, 0, 6357c478bd9Sstevel@tonic-gate ofl)) != NULL) && (sdp->sd_ref == REF_REL_NEED) && sdp->sd_isc && 6367c478bd9Sstevel@tonic-gate (strcmp(sdp->sd_isc->is_name, MSG_ORIG(MSG_SCN_FINI)) == 0)) { 6375aefb655Srie if (ld_sym_copy(sdp) == S_ERROR) 6387c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 6397c478bd9Sstevel@tonic-gate sdp->sd_sym->st_size = 6407c478bd9Sstevel@tonic-gate sdp->sd_isc->is_osdesc->os_shdr->sh_size; 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate 6437c478bd9Sstevel@tonic-gate /* 6447c478bd9Sstevel@tonic-gate * Assign .bss information for use with updating COMMON symbols. 6457c478bd9Sstevel@tonic-gate */ 6467c478bd9Sstevel@tonic-gate if (ofl->ofl_isbss) { 6477c478bd9Sstevel@tonic-gate osp = ofl->ofl_isbss->is_osdesc; 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate bssaddr = osp->os_shdr->sh_addr + 6507c478bd9Sstevel@tonic-gate (Off)_elf_getxoff(ofl->ofl_isbss->is_indata); 6517c478bd9Sstevel@tonic-gate /* LINTED */ 6527c478bd9Sstevel@tonic-gate bssndx = elf_ndxscn(osp->os_scn); 6537c478bd9Sstevel@tonic-gate } 6547c478bd9Sstevel@tonic-gate 65554d82594Sseizo #if (defined(__i386) || defined(__amd64)) && defined(_ELF64) 65654d82594Sseizo /* 65754d82594Sseizo * Assign .lbss information for use with updating LCOMMON symbols. 65854d82594Sseizo */ 65954d82594Sseizo if (ofl->ofl_islbss) { 66054d82594Sseizo osp = ofl->ofl_islbss->is_osdesc; 66154d82594Sseizo 66254d82594Sseizo lbssaddr = osp->os_shdr->sh_addr + 66354d82594Sseizo (Off)_elf_getxoff(ofl->ofl_islbss->is_indata); 66454d82594Sseizo /* LINTED */ 66554d82594Sseizo lbssndx = elf_ndxscn(osp->os_scn); 66654d82594Sseizo } 66754d82594Sseizo #endif 66854d82594Sseizo 6697c478bd9Sstevel@tonic-gate /* 6707c478bd9Sstevel@tonic-gate * Assign .tlsbss information for use with updating COMMON symbols. 6717c478bd9Sstevel@tonic-gate */ 6727c478bd9Sstevel@tonic-gate if (ofl->ofl_istlsbss) { 6737c478bd9Sstevel@tonic-gate osp = ofl->ofl_istlsbss->is_osdesc; 6747c478bd9Sstevel@tonic-gate tlsbssaddr = osp->os_shdr->sh_addr + 6757c478bd9Sstevel@tonic-gate (Off)_elf_getxoff(ofl->ofl_istlsbss->is_indata); 6767c478bd9Sstevel@tonic-gate /* LINTED */ 6777c478bd9Sstevel@tonic-gate tlsbssndx = elf_ndxscn(osp->os_scn); 6787c478bd9Sstevel@tonic-gate } 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate /* 6817c478bd9Sstevel@tonic-gate * Assign .SUNWbss information for use with updating COMMON symbols. 6827c478bd9Sstevel@tonic-gate */ 6837c478bd9Sstevel@tonic-gate if (ofl->ofl_issunwbss) { 6847c478bd9Sstevel@tonic-gate osp = ofl->ofl_issunwbss->is_osdesc; 6857c478bd9Sstevel@tonic-gate sunwbssaddr = (Addr)(osp->os_shdr->sh_addr + 6867c478bd9Sstevel@tonic-gate ofl->ofl_issunwbss->is_indata->d_off); 6877c478bd9Sstevel@tonic-gate /* LINTED */ 6887c478bd9Sstevel@tonic-gate sunwbssndx = elf_ndxscn(osp->os_scn); 6897c478bd9Sstevel@tonic-gate } 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate 6927c478bd9Sstevel@tonic-gate if ((sorted_syms = libld_calloc(ofl->ofl_globcnt + 6937c478bd9Sstevel@tonic-gate ofl->ofl_elimcnt + ofl->ofl_scopecnt, sizeof (*sorted_syms))) == 0) 6947c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate scndx = 0; 6977c478bd9Sstevel@tonic-gate ssndx = ofl->ofl_scopecnt + ofl->ofl_elimcnt; 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate /* 7007c478bd9Sstevel@tonic-gate * Traverse the internal symbol table updating information and 7017c478bd9Sstevel@tonic-gate * allocating common. 7027c478bd9Sstevel@tonic-gate */ 7037c478bd9Sstevel@tonic-gate for (sav = avl_first(&ofl->ofl_symavl); sav; 7047c478bd9Sstevel@tonic-gate sav = AVL_NEXT(&ofl->ofl_symavl, sav)) { 7057c478bd9Sstevel@tonic-gate Sym * symptr; 7067c478bd9Sstevel@tonic-gate int local; 70754d82594Sseizo int restore; 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate sdp = sav->sav_symdesc; 7107c478bd9Sstevel@tonic-gate 7117c478bd9Sstevel@tonic-gate /* 7127c478bd9Sstevel@tonic-gate * Ignore any symbols that have been marked as 7137c478bd9Sstevel@tonic-gate * invalid during input processing. Providing 7147c478bd9Sstevel@tonic-gate * these aren't used for relocation they'll 7157c478bd9Sstevel@tonic-gate * just be dropped from the output image. 7167c478bd9Sstevel@tonic-gate */ 7177c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_INVALID) { 7185aefb655Srie DBG_CALL(Dbg_syms_old(ofl, sdp)); 7195aefb655Srie DBG_CALL(Dbg_syms_ignore(ofl, sdp)); 7207c478bd9Sstevel@tonic-gate continue; 7217c478bd9Sstevel@tonic-gate } 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate /* 7247c478bd9Sstevel@tonic-gate * Only needed symbols will be copied to the 7257c478bd9Sstevel@tonic-gate * output symbol table. 7267c478bd9Sstevel@tonic-gate */ 7277c478bd9Sstevel@tonic-gate if (sdp->sd_ref == REF_DYN_SEEN) 7287c478bd9Sstevel@tonic-gate continue; 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate if ((sdp->sd_flags1 & FLG_SY1_LOCL) && 7317c478bd9Sstevel@tonic-gate (flags & FLG_OF_PROCRED)) 7327c478bd9Sstevel@tonic-gate local = 1; 7337c478bd9Sstevel@tonic-gate else 7347c478bd9Sstevel@tonic-gate local = 0; 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate if (local || (ofl->ofl_hashbkts == 0)) { 7377c478bd9Sstevel@tonic-gate sorted_syms[scndx++].sl_sdp = sdp; 7387c478bd9Sstevel@tonic-gate } else { 7397c478bd9Sstevel@tonic-gate sorted_syms[ssndx].sl_hval = sdp->sd_aux->sa_hash % 7407c478bd9Sstevel@tonic-gate ofl->ofl_hashbkts; 7417c478bd9Sstevel@tonic-gate sorted_syms[ssndx].sl_sdp = sdp; 7427c478bd9Sstevel@tonic-gate ssndx++; 7437c478bd9Sstevel@tonic-gate } 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate /* 7467c478bd9Sstevel@tonic-gate * Note - we expand the COMMON symbols here 7477c478bd9Sstevel@tonic-gate * because we *must* assign addresses to them 7487c478bd9Sstevel@tonic-gate * in the same order that we calculated space 7497c478bd9Sstevel@tonic-gate * in sym_validate(). If we don't then 7507c478bd9Sstevel@tonic-gate * differing alignment requirements can 7517c478bd9Sstevel@tonic-gate * throw us all out of whack. 7527c478bd9Sstevel@tonic-gate * 7537c478bd9Sstevel@tonic-gate * The expanded .bss global symbol is handled 7547c478bd9Sstevel@tonic-gate * here as well. 7557c478bd9Sstevel@tonic-gate * 7567c478bd9Sstevel@tonic-gate * The actual adding entries into the symbol 7577c478bd9Sstevel@tonic-gate * table still occurs below in hashbucket order. 7587c478bd9Sstevel@tonic-gate */ 7597c478bd9Sstevel@tonic-gate symptr = sdp->sd_sym; 76054d82594Sseizo restore = 0; 7617c478bd9Sstevel@tonic-gate if ((sdp->sd_flags & FLG_SY_PAREXPN) || 7627c478bd9Sstevel@tonic-gate ((sdp->sd_flags & FLG_SY_SPECSEC) && 7637c478bd9Sstevel@tonic-gate (sdp->sd_shndx = symptr->st_shndx) == SHN_COMMON)) { 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate /* 7667c478bd9Sstevel@tonic-gate * If this this is an expanded symbol, 7677c478bd9Sstevel@tonic-gate * it goes to sunwdata1. 7687c478bd9Sstevel@tonic-gate * 7697c478bd9Sstevel@tonic-gate * If this is a partial initialized 7707c478bd9Sstevel@tonic-gate * global symbol and the output is a 7717c478bd9Sstevel@tonic-gate * shared object, it goes to sunwbss. 7727c478bd9Sstevel@tonic-gate * 7737c478bd9Sstevel@tonic-gate * If allocating common assign it an 7747c478bd9Sstevel@tonic-gate * address in the .bss section. 7757c478bd9Sstevel@tonic-gate * 7767c478bd9Sstevel@tonic-gate * Otherwise leave it as is. 7777c478bd9Sstevel@tonic-gate */ 7787c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_PAREXPN) { 7797c478bd9Sstevel@tonic-gate restore = 1; 7807c478bd9Sstevel@tonic-gate sdp->sd_shndx = sunwdata1ndx; 7817c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 7827c478bd9Sstevel@tonic-gate symptr->st_value = (Xword) S_ROUND( 7837c478bd9Sstevel@tonic-gate sunwdata1addr, symptr->st_value); 7847c478bd9Sstevel@tonic-gate sunwdata1addr = symptr->st_value + 7857c478bd9Sstevel@tonic-gate symptr->st_size; 7867c478bd9Sstevel@tonic-gate sdp->sd_isc = ofl->ofl_issunwdata1; 7877c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_COMMEXP; 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate } else if ((sdp->sd_psyminfo != (Psym_info *)NULL) && 7907c478bd9Sstevel@tonic-gate (ofl->ofl_flags & FLG_OF_SHAROBJ) && 7917c478bd9Sstevel@tonic-gate (ELF_ST_BIND(symptr->st_info) != STB_LOCAL)) { 7927c478bd9Sstevel@tonic-gate restore = 1; 7937c478bd9Sstevel@tonic-gate sdp->sd_shndx = sunwbssndx; 7947c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 7957c478bd9Sstevel@tonic-gate symptr->st_value = (Xword) 7967c478bd9Sstevel@tonic-gate S_ROUND(sunwbssaddr, symptr->st_value); 7977c478bd9Sstevel@tonic-gate sunwbssaddr = symptr->st_value + 7987c478bd9Sstevel@tonic-gate symptr->st_size; 7997c478bd9Sstevel@tonic-gate sdp->sd_isc = ofl->ofl_issunwbss; 8007c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_COMMEXP; 8017c478bd9Sstevel@tonic-gate } else if (ELF_ST_TYPE(symptr->st_info) != STT_TLS && 8027c478bd9Sstevel@tonic-gate (local || !(flags & FLG_OF_RELOBJ))) { 8037c478bd9Sstevel@tonic-gate restore = 1; 8047c478bd9Sstevel@tonic-gate sdp->sd_shndx = bssndx; 8057c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 8067c478bd9Sstevel@tonic-gate symptr->st_value = (Xword) S_ROUND(bssaddr, 8077c478bd9Sstevel@tonic-gate symptr->st_value); 8087c478bd9Sstevel@tonic-gate bssaddr = symptr->st_value + symptr->st_size; 8097c478bd9Sstevel@tonic-gate sdp->sd_isc = ofl->ofl_isbss; 8107c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_COMMEXP; 8117c478bd9Sstevel@tonic-gate } else if (ELF_ST_TYPE(symptr->st_info) == STT_TLS && 8127c478bd9Sstevel@tonic-gate (local || !(flags & FLG_OF_RELOBJ))) { 8137c478bd9Sstevel@tonic-gate restore = 1; 8147c478bd9Sstevel@tonic-gate sdp->sd_shndx = tlsbssndx; 8157c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 8167c478bd9Sstevel@tonic-gate symptr->st_value = (Xword)S_ROUND(tlsbssaddr, 8177c478bd9Sstevel@tonic-gate symptr->st_value); 8187c478bd9Sstevel@tonic-gate tlsbssaddr = symptr->st_value + symptr->st_size; 8197c478bd9Sstevel@tonic-gate sdp->sd_isc = ofl->ofl_istlsbss; 8207c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_COMMEXP; 8217c478bd9Sstevel@tonic-gate /* 822dd94ecefSrie * TLS symbols are relative to the TLS segment. 8237c478bd9Sstevel@tonic-gate */ 8247c478bd9Sstevel@tonic-gate symptr->st_value -= ofl->ofl_tlsphdr->p_vaddr; 8257c478bd9Sstevel@tonic-gate } 82654d82594Sseizo #if (defined(__i386) || defined(__amd64)) && defined(_ELF64) 82754d82594Sseizo } else if ((sdp->sd_flags & FLG_SY_SPECSEC) && 82854d82594Sseizo ((sdp->sd_shndx = symptr->st_shndx) == 82954d82594Sseizo SHN_X86_64_LCOMMON) && 83054d82594Sseizo ((local || !(flags & FLG_OF_RELOBJ)))) { 83154d82594Sseizo restore = 1; 83254d82594Sseizo sdp->sd_shndx = lbssndx; 83354d82594Sseizo sdp->sd_flags &= ~FLG_SY_SPECSEC; 83454d82594Sseizo symptr->st_value = (Xword) S_ROUND(lbssaddr, 83554d82594Sseizo symptr->st_value); 83654d82594Sseizo lbssaddr = symptr->st_value + symptr->st_size; 83754d82594Sseizo sdp->sd_isc = ofl->ofl_islbss; 83854d82594Sseizo sdp->sd_flags |= FLG_SY_COMMEXP; 83954d82594Sseizo #endif 84054d82594Sseizo } 8417c478bd9Sstevel@tonic-gate 84254d82594Sseizo if (restore != 0) { 84354d82594Sseizo unsigned char type, bind; 84454d82594Sseizo /* 84554d82594Sseizo * Make sure this COMMON 84654d82594Sseizo * symbol is returned to the 84754d82594Sseizo * same binding as was defined 84854d82594Sseizo * in the original relocatable 84954d82594Sseizo * object reference. 85054d82594Sseizo */ 85154d82594Sseizo type = ELF_ST_TYPE(symptr->st_info); 85254d82594Sseizo if (sdp->sd_flags & FLG_SY_GLOBREF) 85354d82594Sseizo bind = STB_GLOBAL; 85454d82594Sseizo else 85554d82594Sseizo bind = STB_WEAK; 8567c478bd9Sstevel@tonic-gate 85754d82594Sseizo symptr->st_info = ELF_ST_INFO(bind, type); 8587c478bd9Sstevel@tonic-gate } 8597c478bd9Sstevel@tonic-gate } 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate if (ofl->ofl_hashbkts) { 8627c478bd9Sstevel@tonic-gate qsort(sorted_syms + ofl->ofl_scopecnt + ofl->ofl_elimcnt, 8637c478bd9Sstevel@tonic-gate ofl->ofl_globcnt, sizeof (Sym_s_list), 8647c478bd9Sstevel@tonic-gate (int (*)(const void *, const void *))sym_hash_compare); 8657c478bd9Sstevel@tonic-gate } 8667c478bd9Sstevel@tonic-gate 8677c478bd9Sstevel@tonic-gate for (ssndx = 0; ssndx < (ofl->ofl_elimcnt + ofl->ofl_scopecnt + 8687c478bd9Sstevel@tonic-gate ofl->ofl_globcnt); ssndx++) { 8697c478bd9Sstevel@tonic-gate const char *name; 8707c478bd9Sstevel@tonic-gate Sym *sym; 8717c478bd9Sstevel@tonic-gate Sym_aux *sap; 8727c478bd9Sstevel@tonic-gate Half spec; 8737c478bd9Sstevel@tonic-gate int local = 0, enter_in_symtab; 8747c478bd9Sstevel@tonic-gate Listnode *lnp2; 8757c478bd9Sstevel@tonic-gate Gotndx *gnp; 8767c478bd9Sstevel@tonic-gate Word sectndx; 8777c478bd9Sstevel@tonic-gate 8787c478bd9Sstevel@tonic-gate sdp = sorted_syms[ssndx].sl_sdp; 8797c478bd9Sstevel@tonic-gate sectndx = 0; 8807c478bd9Sstevel@tonic-gate 8817c478bd9Sstevel@tonic-gate if (symtab) 8827c478bd9Sstevel@tonic-gate enter_in_symtab = 1; 8837c478bd9Sstevel@tonic-gate else 8847c478bd9Sstevel@tonic-gate enter_in_symtab = 0; 8857c478bd9Sstevel@tonic-gate 8867c478bd9Sstevel@tonic-gate /* 8877c478bd9Sstevel@tonic-gate * Assign a got offset if necessary. 8887c478bd9Sstevel@tonic-gate */ 8895aefb655Srie #if defined(sparc) || defined(__sparcv9) 8905aefb655Srie if (ld_assign_got(ofl, sdp) == S_ERROR) 8917c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 8925aefb655Srie #elif defined(i386) || defined(__amd64) 8937c478bd9Sstevel@tonic-gate /* nothing to do */ 8947c478bd9Sstevel@tonic-gate #else 8957c478bd9Sstevel@tonic-gate #error Unknown architecture! 8967c478bd9Sstevel@tonic-gate #endif 8975aefb655Srie if (DBG_ENABLED) { 8987c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&sdp->sd_GOTndxs, lnp2, gnp)) { 8997c478bd9Sstevel@tonic-gate _gottable->gt_sym = sdp; 9007c478bd9Sstevel@tonic-gate _gottable->gt_gndx.gn_gotndx = gnp->gn_gotndx; 9017c478bd9Sstevel@tonic-gate _gottable->gt_gndx.gn_addend = gnp->gn_addend; 9027c478bd9Sstevel@tonic-gate _gottable++; 9037c478bd9Sstevel@tonic-gate } 9047c478bd9Sstevel@tonic-gate 9057c478bd9Sstevel@tonic-gate if (sdp->sd_aux && sdp->sd_aux->sa_PLTGOTndx) { 9067c478bd9Sstevel@tonic-gate _gottable->gt_sym = sdp; 9077c478bd9Sstevel@tonic-gate _gottable->gt_gndx.gn_gotndx = 9087c478bd9Sstevel@tonic-gate sdp->sd_aux->sa_PLTGOTndx; 9097c478bd9Sstevel@tonic-gate _gottable++; 9107c478bd9Sstevel@tonic-gate } 9117c478bd9Sstevel@tonic-gate } 9127c478bd9Sstevel@tonic-gate 9137c478bd9Sstevel@tonic-gate 9147c478bd9Sstevel@tonic-gate /* 9157c478bd9Sstevel@tonic-gate * If this symbol has been marked as being reduced to local 9167c478bd9Sstevel@tonic-gate * scope then it will have to be placed in the scoped portion 9177c478bd9Sstevel@tonic-gate * of the .symtab. Retain the appropriate index for use in 9187c478bd9Sstevel@tonic-gate * version symbol indexing and relocation. 9197c478bd9Sstevel@tonic-gate */ 9207c478bd9Sstevel@tonic-gate if ((sdp->sd_flags1 & FLG_SY1_LOCL) && 9217c478bd9Sstevel@tonic-gate (flags & FLG_OF_PROCRED)) { 9227c478bd9Sstevel@tonic-gate local = 1; 9237c478bd9Sstevel@tonic-gate if (!(sdp->sd_flags1 & FLG_SY1_ELIM) && !dynsym) 9247c478bd9Sstevel@tonic-gate sdp->sd_symndx = scopesym_ndx; 9257c478bd9Sstevel@tonic-gate else 9267c478bd9Sstevel@tonic-gate sdp->sd_symndx = 0; 9277c478bd9Sstevel@tonic-gate 9287c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_ELIM) 9297c478bd9Sstevel@tonic-gate enter_in_symtab = 0; 9307c478bd9Sstevel@tonic-gate } else 9317c478bd9Sstevel@tonic-gate sdp->sd_symndx = *symndx; 9327c478bd9Sstevel@tonic-gate 9337c478bd9Sstevel@tonic-gate /* 9347c478bd9Sstevel@tonic-gate * Copy basic symbol and string information. 9357c478bd9Sstevel@tonic-gate */ 9367c478bd9Sstevel@tonic-gate name = sdp->sd_name; 9377c478bd9Sstevel@tonic-gate sap = sdp->sd_aux; 9387c478bd9Sstevel@tonic-gate 9397c478bd9Sstevel@tonic-gate /* 9407c478bd9Sstevel@tonic-gate * If we require to record version symbol indexes, update the 9417c478bd9Sstevel@tonic-gate * associated version symbol information for all defined 9427c478bd9Sstevel@tonic-gate * symbols. If a version definition is required any zero value 9437c478bd9Sstevel@tonic-gate * symbol indexes would have been flagged as undefined symbol 9447c478bd9Sstevel@tonic-gate * errors, however if we're just scoping these need to fall into 9457c478bd9Sstevel@tonic-gate * the base of global symbols. 9467c478bd9Sstevel@tonic-gate */ 9477c478bd9Sstevel@tonic-gate if (sdp->sd_symndx && versym) { 9487c478bd9Sstevel@tonic-gate Half vndx = 0; 9497c478bd9Sstevel@tonic-gate 9507c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_MVTOCOMM) 9517c478bd9Sstevel@tonic-gate vndx = VER_NDX_GLOBAL; 9527c478bd9Sstevel@tonic-gate else if (sdp->sd_ref == REF_REL_NEED) { 9537c478bd9Sstevel@tonic-gate Half symflags1 = sdp->sd_flags1; 9547c478bd9Sstevel@tonic-gate 9557c478bd9Sstevel@tonic-gate vndx = sap->sa_overndx; 9567c478bd9Sstevel@tonic-gate if ((vndx == 0) && 9577c478bd9Sstevel@tonic-gate (sdp->sd_sym->st_shndx != SHN_UNDEF)) { 9587c478bd9Sstevel@tonic-gate if (symflags1 & FLG_SY1_ELIM) 9597c478bd9Sstevel@tonic-gate vndx = VER_NDX_ELIMINATE; 9607c478bd9Sstevel@tonic-gate else if (symflags1 & FLG_SY1_LOCL) 9617c478bd9Sstevel@tonic-gate vndx = VER_NDX_LOCAL; 9627c478bd9Sstevel@tonic-gate else 9637c478bd9Sstevel@tonic-gate vndx = VER_NDX_GLOBAL; 9647c478bd9Sstevel@tonic-gate } 9657c478bd9Sstevel@tonic-gate } 9667c478bd9Sstevel@tonic-gate versym[sdp->sd_symndx] = vndx; 9677c478bd9Sstevel@tonic-gate } 9687c478bd9Sstevel@tonic-gate 9697c478bd9Sstevel@tonic-gate /* 9707c478bd9Sstevel@tonic-gate * If we are creating the .syminfo section then set per symbol 9717c478bd9Sstevel@tonic-gate * flags here. 9727c478bd9Sstevel@tonic-gate */ 9737c478bd9Sstevel@tonic-gate if (sdp->sd_symndx && syminfo && 9747c478bd9Sstevel@tonic-gate !(sdp->sd_flags & FLG_SY_NOTAVAIL)) { 9757c478bd9Sstevel@tonic-gate int ndx = sdp->sd_symndx; 9767c478bd9Sstevel@tonic-gate List *sip = &(ofl->ofl_syminfsyms); 9777c478bd9Sstevel@tonic-gate 9787c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_MVTOCOMM) 9797c478bd9Sstevel@tonic-gate /* 9807c478bd9Sstevel@tonic-gate * Identify a copy relocation symbol. 9817c478bd9Sstevel@tonic-gate */ 9827c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= SYMINFO_FLG_COPY; 9837c478bd9Sstevel@tonic-gate 9847c478bd9Sstevel@tonic-gate if (sdp->sd_ref == REF_DYN_NEED) { 9857c478bd9Sstevel@tonic-gate /* 9867c478bd9Sstevel@tonic-gate * A reference is bound to a needed dependency. 9877c478bd9Sstevel@tonic-gate * Save this symbol descriptor, as its boundto 9887c478bd9Sstevel@tonic-gate * element will need updating after the .dynamic 9897c478bd9Sstevel@tonic-gate * section has been created. Flag whether this 9907c478bd9Sstevel@tonic-gate * reference is lazy loadable, and if a direct 9917c478bd9Sstevel@tonic-gate * binding is to be established. 9927c478bd9Sstevel@tonic-gate */ 9937c478bd9Sstevel@tonic-gate if (list_appendc(sip, sdp) == 0) 9947c478bd9Sstevel@tonic-gate return (0); 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= SYMINFO_FLG_DIRECT; 9977c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_LAZYLD) 9987c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 9997c478bd9Sstevel@tonic-gate SYMINFO_FLG_LAZYLOAD; 10007c478bd9Sstevel@tonic-gate 10017c478bd9Sstevel@tonic-gate /* 10027c478bd9Sstevel@tonic-gate * Enable direct symbol bindings if: 10037c478bd9Sstevel@tonic-gate * 10047c478bd9Sstevel@tonic-gate * . Symbol was identified with the DIRECT 10057c478bd9Sstevel@tonic-gate * keyword in a mapfile. 10067c478bd9Sstevel@tonic-gate * 10077c478bd9Sstevel@tonic-gate * . Symbol reference has been bound to a 10087c478bd9Sstevel@tonic-gate * dependency which was specified as 10097c478bd9Sstevel@tonic-gate * requiring direct bindings with -zdirect. 10107c478bd9Sstevel@tonic-gate * 10117c478bd9Sstevel@tonic-gate * . All symbol references are required to 10127c478bd9Sstevel@tonic-gate * use direct bindings via -Bdirect. 10137c478bd9Sstevel@tonic-gate */ 10147c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_DIR) 10157c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 10167c478bd9Sstevel@tonic-gate SYMINFO_FLG_DIRECTBIND; 10177c478bd9Sstevel@tonic-gate 10187c478bd9Sstevel@tonic-gate } else if ((sdp->sd_flags & FLG_SY_EXTERN) && 10197c478bd9Sstevel@tonic-gate (sdp->sd_sym->st_shndx == SHN_UNDEF)) { 10207c478bd9Sstevel@tonic-gate /* 10217c478bd9Sstevel@tonic-gate * If this symbol has been explicitly defined 10227c478bd9Sstevel@tonic-gate * as external, and remains unresolved, mark 10237c478bd9Sstevel@tonic-gate * it as external. 10247c478bd9Sstevel@tonic-gate */ 10257c478bd9Sstevel@tonic-gate syminfo[ndx].si_boundto = SYMINFO_BT_EXTERN; 10267c478bd9Sstevel@tonic-gate 10277c478bd9Sstevel@tonic-gate } else if (sdp->sd_flags & FLG_SY_PARENT) { 10287c478bd9Sstevel@tonic-gate /* 10297c478bd9Sstevel@tonic-gate * A reference to a parent object. Indicate 10307c478bd9Sstevel@tonic-gate * whether a direct binding should be 10317c478bd9Sstevel@tonic-gate * established. 10327c478bd9Sstevel@tonic-gate */ 10337c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= SYMINFO_FLG_DIRECT; 10347c478bd9Sstevel@tonic-gate syminfo[ndx].si_boundto = SYMINFO_BT_PARENT; 10357c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_DIR) 10367c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 10377c478bd9Sstevel@tonic-gate SYMINFO_FLG_DIRECTBIND; 10387c478bd9Sstevel@tonic-gate 10397c478bd9Sstevel@tonic-gate } else if (sdp->sd_flags & FLG_SY_STDFLTR) { 10407c478bd9Sstevel@tonic-gate /* 10417c478bd9Sstevel@tonic-gate * A filter definition. Although this symbol 10427c478bd9Sstevel@tonic-gate * can only be a stub, it might be necessary to 10437c478bd9Sstevel@tonic-gate * prevent external direct bindings. 10447c478bd9Sstevel@tonic-gate */ 10457c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= SYMINFO_FLG_FILTER; 10467c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_NDIR) 10477c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 10487c478bd9Sstevel@tonic-gate SYMINFO_FLG_NOEXTDIRECT; 10497c478bd9Sstevel@tonic-gate 10507c478bd9Sstevel@tonic-gate } else if (sdp->sd_flags & FLG_SY_AUXFLTR) { 10517c478bd9Sstevel@tonic-gate /* 10527c478bd9Sstevel@tonic-gate * An auxiliary filter definition. By nature, 10537c478bd9Sstevel@tonic-gate * this definition is direct, in that should the 10547c478bd9Sstevel@tonic-gate * filtee lookup fail, we'll fall back to this 10557c478bd9Sstevel@tonic-gate * object. It may still be necesssary to 10567c478bd9Sstevel@tonic-gate * prevent external direct bindings. 10577c478bd9Sstevel@tonic-gate */ 10587c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= SYMINFO_FLG_AUXILIARY; 10597c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_NDIR) 10607c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 10617c478bd9Sstevel@tonic-gate SYMINFO_FLG_NOEXTDIRECT; 10627c478bd9Sstevel@tonic-gate 10637c478bd9Sstevel@tonic-gate } else if ((sdp->sd_ref == REF_REL_NEED) && 10647c478bd9Sstevel@tonic-gate (sdp->sd_sym->st_shndx != SHN_UNDEF)) { 10657c478bd9Sstevel@tonic-gate /* 10667c478bd9Sstevel@tonic-gate * This definition exists within the object 10677c478bd9Sstevel@tonic-gate * being created. Flag whether it is necessary 10687c478bd9Sstevel@tonic-gate * to prevent external direct bindings. 10697c478bd9Sstevel@tonic-gate */ 10707c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_NDIR) { 10717c478bd9Sstevel@tonic-gate syminfo[ndx].si_boundto = 10727c478bd9Sstevel@tonic-gate SYMINFO_BT_NONE; 10737c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 10747c478bd9Sstevel@tonic-gate SYMINFO_FLG_NOEXTDIRECT; 10757c478bd9Sstevel@tonic-gate } 10767c478bd9Sstevel@tonic-gate 10777c478bd9Sstevel@tonic-gate /* 10787c478bd9Sstevel@tonic-gate * If external bindings are allowed, or this is 10797c478bd9Sstevel@tonic-gate * a translator symbol, indicate the binding, 10807c478bd9Sstevel@tonic-gate * and a direct binding if necessary. 10817c478bd9Sstevel@tonic-gate */ 10827c478bd9Sstevel@tonic-gate if (((sdp->sd_flags1 & FLG_SY1_NDIR) == 0) || 10837c478bd9Sstevel@tonic-gate ((dtflags_1 & DF_1_TRANS) && sdp->sd_aux && 10847c478bd9Sstevel@tonic-gate sdp->sd_aux->sa_bindto)) { 10857c478bd9Sstevel@tonic-gate 10867c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 10877c478bd9Sstevel@tonic-gate SYMINFO_FLG_DIRECT; 10887c478bd9Sstevel@tonic-gate 10897c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_DIR) 10907c478bd9Sstevel@tonic-gate syminfo[ndx].si_flags |= 10917c478bd9Sstevel@tonic-gate SYMINFO_FLG_DIRECTBIND; 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate /* 10947c478bd9Sstevel@tonic-gate * If this is a translator, the symbols 10957c478bd9Sstevel@tonic-gate * boundto element will indicate the 10967c478bd9Sstevel@tonic-gate * dependency to which it should resolve 10977c478bd9Sstevel@tonic-gate * rather than itself. Save this info 10987c478bd9Sstevel@tonic-gate * for updating after the .dynamic 10997c478bd9Sstevel@tonic-gate * section has been created. 11007c478bd9Sstevel@tonic-gate */ 11017c478bd9Sstevel@tonic-gate if ((dtflags_1 & DF_1_TRANS) && 11027c478bd9Sstevel@tonic-gate sdp->sd_aux && 11037c478bd9Sstevel@tonic-gate sdp->sd_aux->sa_bindto) { 11047c478bd9Sstevel@tonic-gate if (list_appendc(sip, sdp) == 0) 11057c478bd9Sstevel@tonic-gate return (0); 11067c478bd9Sstevel@tonic-gate } else { 11077c478bd9Sstevel@tonic-gate syminfo[ndx].si_boundto = 11087c478bd9Sstevel@tonic-gate SYMINFO_BT_SELF; 11097c478bd9Sstevel@tonic-gate } 11107c478bd9Sstevel@tonic-gate } 11117c478bd9Sstevel@tonic-gate } 11127c478bd9Sstevel@tonic-gate } 11137c478bd9Sstevel@tonic-gate 11147c478bd9Sstevel@tonic-gate /* 11157c478bd9Sstevel@tonic-gate * Note that the `sym' value is reset to be one of the new 11167c478bd9Sstevel@tonic-gate * symbol table entries. This symbol will be updated further 11177c478bd9Sstevel@tonic-gate * depending on the type of the symbol. Process the .symtab 11187c478bd9Sstevel@tonic-gate * first, followed by the .dynsym, thus the `sym' value will 11197c478bd9Sstevel@tonic-gate * remain as the .dynsym value when the .dynsym is present. 11207c478bd9Sstevel@tonic-gate * This insures that any versioning symbols st_name value will 11217c478bd9Sstevel@tonic-gate * be appropriate for the string table used to by version 11227c478bd9Sstevel@tonic-gate * entries. 11237c478bd9Sstevel@tonic-gate */ 11247c478bd9Sstevel@tonic-gate if (enter_in_symtab) { 11257c478bd9Sstevel@tonic-gate Word _symndx; 11267c478bd9Sstevel@tonic-gate 11277c478bd9Sstevel@tonic-gate if (local) 11287c478bd9Sstevel@tonic-gate _symndx = scopesym_ndx; 11297c478bd9Sstevel@tonic-gate else 11307c478bd9Sstevel@tonic-gate _symndx = symtab_ndx; 11317c478bd9Sstevel@tonic-gate symtab[_symndx] = *sdp->sd_sym; 11327c478bd9Sstevel@tonic-gate sdp->sd_sym = sym = &symtab[_symndx]; 11337c478bd9Sstevel@tonic-gate (void) st_setstring(strtab, name, &stoff); 11347c478bd9Sstevel@tonic-gate sym->st_name = stoff; 11357c478bd9Sstevel@tonic-gate } 11367c478bd9Sstevel@tonic-gate 11377c478bd9Sstevel@tonic-gate if (dynsym && !local) { 11387c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx] = *sdp->sd_sym; 11397c478bd9Sstevel@tonic-gate 11407c478bd9Sstevel@tonic-gate /* 11417c478bd9Sstevel@tonic-gate * Provided this isn't an unnamed register symbol, 11427c478bd9Sstevel@tonic-gate * update its name and hash value. 11437c478bd9Sstevel@tonic-gate */ 11447c478bd9Sstevel@tonic-gate if (((sdp->sd_flags & FLG_SY_REGSYM) == 0) || 11457c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx].st_name) { 11467c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, name, &stoff); 11477c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx].st_name = stoff; 11487c478bd9Sstevel@tonic-gate if (stoff) { 11497c478bd9Sstevel@tonic-gate Word _hashndx; 11507c478bd9Sstevel@tonic-gate hashval = 11517c478bd9Sstevel@tonic-gate sap->sa_hash % ofl->ofl_hashbkts; 11527c478bd9Sstevel@tonic-gate /* LINTED */ 11537c478bd9Sstevel@tonic-gate if (_hashndx = hashbkt[hashval]) { 11547c478bd9Sstevel@tonic-gate while (hashchain[_hashndx]) 11557c478bd9Sstevel@tonic-gate _hashndx = 11567c478bd9Sstevel@tonic-gate hashchain[_hashndx]; 11577c478bd9Sstevel@tonic-gate hashchain[_hashndx] = 11587c478bd9Sstevel@tonic-gate sdp->sd_symndx; 11597c478bd9Sstevel@tonic-gate } else 11607c478bd9Sstevel@tonic-gate hashbkt[hashval] = 11617c478bd9Sstevel@tonic-gate sdp->sd_symndx; 11627c478bd9Sstevel@tonic-gate } 11637c478bd9Sstevel@tonic-gate } 11647c478bd9Sstevel@tonic-gate sdp->sd_sym = sym = &dynsym[dynsym_ndx]; 11657c478bd9Sstevel@tonic-gate } 11667c478bd9Sstevel@tonic-gate if (!enter_in_symtab && (!dynsym || local)) { 11677c478bd9Sstevel@tonic-gate if (!(sdp->sd_flags & FLG_SY_UPREQD)) 11687c478bd9Sstevel@tonic-gate continue; 11697c478bd9Sstevel@tonic-gate sym = sdp->sd_sym; 11707c478bd9Sstevel@tonic-gate } else 11717c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_CLEAN; 11727c478bd9Sstevel@tonic-gate 11737c478bd9Sstevel@tonic-gate 11747c478bd9Sstevel@tonic-gate /* 11757c478bd9Sstevel@tonic-gate * If we have a weak data symbol for which we need the real 11767c478bd9Sstevel@tonic-gate * symbol also, save this processing until later. 11777c478bd9Sstevel@tonic-gate * 11787c478bd9Sstevel@tonic-gate * The exception to this is if the weak/strong have PLT's 11797c478bd9Sstevel@tonic-gate * assigned to them. In that case we don't do the post-weak 11807c478bd9Sstevel@tonic-gate * processing because the PLT's must be maintained so that we 11817c478bd9Sstevel@tonic-gate * can do 'interpositioning' on both of the symbols. 11827c478bd9Sstevel@tonic-gate */ 11837c478bd9Sstevel@tonic-gate if ((sap->sa_linkndx) && 11847c478bd9Sstevel@tonic-gate (ELF_ST_BIND(sym->st_info) == STB_WEAK) && 11857c478bd9Sstevel@tonic-gate (!sap->sa_PLTndx)) { 11867c478bd9Sstevel@tonic-gate Sym_desc * _sdp = 11877c478bd9Sstevel@tonic-gate sdp->sd_file->ifl_oldndx[sap->sa_linkndx]; 11887c478bd9Sstevel@tonic-gate 11897c478bd9Sstevel@tonic-gate if (_sdp->sd_ref != REF_DYN_SEEN) { 11907c478bd9Sstevel@tonic-gate if ((wkp = 11917c478bd9Sstevel@tonic-gate libld_calloc(sizeof (Wk_desc), 1)) == 0) 11927c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 11937c478bd9Sstevel@tonic-gate 11947c478bd9Sstevel@tonic-gate if (enter_in_symtab) 11957c478bd9Sstevel@tonic-gate if (local) 11967c478bd9Sstevel@tonic-gate wkp->wk_symtab = 11977c478bd9Sstevel@tonic-gate &symtab[scopesym_ndx]; 11987c478bd9Sstevel@tonic-gate else 11997c478bd9Sstevel@tonic-gate wkp->wk_symtab = 12007c478bd9Sstevel@tonic-gate &symtab[symtab_ndx]; 12017c478bd9Sstevel@tonic-gate if (dynsym && !local) 12027c478bd9Sstevel@tonic-gate wkp->wk_dynsym = &dynsym[dynsym_ndx]; 12037c478bd9Sstevel@tonic-gate wkp->wk_weak = sdp; 12047c478bd9Sstevel@tonic-gate wkp->wk_alias = _sdp; 12057c478bd9Sstevel@tonic-gate 12067c478bd9Sstevel@tonic-gate if (!(list_appendc(&weak, wkp))) 12077c478bd9Sstevel@tonic-gate return ((Addr)S_ERROR); 12087c478bd9Sstevel@tonic-gate 12097c478bd9Sstevel@tonic-gate if (enter_in_symtab) 12107c478bd9Sstevel@tonic-gate if (local) 12117c478bd9Sstevel@tonic-gate scopesym_ndx++; 12127c478bd9Sstevel@tonic-gate else 12137c478bd9Sstevel@tonic-gate symtab_ndx++; 12147c478bd9Sstevel@tonic-gate if (dynsym && !local) 12157c478bd9Sstevel@tonic-gate dynsym_ndx++; 12167c478bd9Sstevel@tonic-gate continue; 12177c478bd9Sstevel@tonic-gate } 12187c478bd9Sstevel@tonic-gate } 12197c478bd9Sstevel@tonic-gate 12205aefb655Srie DBG_CALL(Dbg_syms_old(ofl, sdp)); 12217c478bd9Sstevel@tonic-gate 12227c478bd9Sstevel@tonic-gate spec = NULL; 12237c478bd9Sstevel@tonic-gate /* 12247c478bd9Sstevel@tonic-gate * assign new symbol value. 12257c478bd9Sstevel@tonic-gate */ 12267c478bd9Sstevel@tonic-gate sectndx = sdp->sd_shndx; 12277c478bd9Sstevel@tonic-gate if (sectndx == SHN_UNDEF) { 12287c478bd9Sstevel@tonic-gate if (((sdp->sd_flags & FLG_SY_REGSYM) == 0) && 12297c478bd9Sstevel@tonic-gate (sym->st_value != 0)) { 12305aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 12315aefb655Srie MSG_INTL(MSG_SYM_NOTNULL), 12327c478bd9Sstevel@tonic-gate demangle(name), sdp->sd_file->ifl_name); 12337c478bd9Sstevel@tonic-gate } 12347c478bd9Sstevel@tonic-gate 12357c478bd9Sstevel@tonic-gate /* 12367c478bd9Sstevel@tonic-gate * Undefined weak global, if we are generating a static 12377c478bd9Sstevel@tonic-gate * executable, output as an absolute zero. Otherwise 12387c478bd9Sstevel@tonic-gate * leave it as is, ld.so.1 will skip symbols of this 12397c478bd9Sstevel@tonic-gate * type (this technique allows applications and 12407c478bd9Sstevel@tonic-gate * libraries to test for the existence of a symbol as an 12417c478bd9Sstevel@tonic-gate * indication of the presence or absence of certain 12427c478bd9Sstevel@tonic-gate * functionality). 12437c478bd9Sstevel@tonic-gate */ 12447c478bd9Sstevel@tonic-gate if (((flags & (FLG_OF_STATIC | FLG_OF_EXEC)) == 12457c478bd9Sstevel@tonic-gate (FLG_OF_STATIC | FLG_OF_EXEC)) && 12467c478bd9Sstevel@tonic-gate (ELF_ST_BIND(sym->st_info) == STB_WEAK)) { 12477c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_SPECSEC; 12487c478bd9Sstevel@tonic-gate sdp->sd_shndx = sectndx = SHN_ABS; 12497c478bd9Sstevel@tonic-gate } 12507c478bd9Sstevel@tonic-gate } else if ((sdp->sd_flags & FLG_SY_SPECSEC) && 12517c478bd9Sstevel@tonic-gate (sectndx == SHN_COMMON)) { 12527c478bd9Sstevel@tonic-gate /* COMMONs have already been processed */ 12537c478bd9Sstevel@tonic-gate /* EMPTY */ 12547c478bd9Sstevel@tonic-gate ; 12557c478bd9Sstevel@tonic-gate } else { 12567c478bd9Sstevel@tonic-gate if ((sdp->sd_flags & FLG_SY_SPECSEC) && 12577c478bd9Sstevel@tonic-gate (sectndx == SHN_ABS)) 12587c478bd9Sstevel@tonic-gate spec = sdp->sd_aux->sa_symspec; 12597c478bd9Sstevel@tonic-gate 12607c478bd9Sstevel@tonic-gate /* LINTED */ 12617c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_COMMEXP) { 12627c478bd9Sstevel@tonic-gate /* 12637c478bd9Sstevel@tonic-gate * This is (or was) a COMMON symbol which was 12647c478bd9Sstevel@tonic-gate * processed above - no processing 12657c478bd9Sstevel@tonic-gate * required here. 12667c478bd9Sstevel@tonic-gate */ 12677c478bd9Sstevel@tonic-gate ; 12687c478bd9Sstevel@tonic-gate } else if (sdp->sd_ref == REF_DYN_NEED) { 12697c478bd9Sstevel@tonic-gate unsigned char type, bind; 12707c478bd9Sstevel@tonic-gate 12717c478bd9Sstevel@tonic-gate sectndx = SHN_UNDEF; 12727c478bd9Sstevel@tonic-gate sym->st_value = 0; 12737c478bd9Sstevel@tonic-gate sym->st_size = 0; 12747c478bd9Sstevel@tonic-gate 12757c478bd9Sstevel@tonic-gate /* 12767c478bd9Sstevel@tonic-gate * Make sure this undefined symbol is returned 12777c478bd9Sstevel@tonic-gate * to the same binding as was defined in the 12787c478bd9Sstevel@tonic-gate * original relocatable object reference. 12797c478bd9Sstevel@tonic-gate */ 12807c478bd9Sstevel@tonic-gate type = ELF_ST_TYPE(sym-> st_info); 12817c478bd9Sstevel@tonic-gate if (sdp->sd_flags & FLG_SY_GLOBREF) 12827c478bd9Sstevel@tonic-gate bind = STB_GLOBAL; 12837c478bd9Sstevel@tonic-gate else 12847c478bd9Sstevel@tonic-gate bind = STB_WEAK; 12857c478bd9Sstevel@tonic-gate 12867c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(bind, type); 12877c478bd9Sstevel@tonic-gate 12887c478bd9Sstevel@tonic-gate } else if (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) && 12897c478bd9Sstevel@tonic-gate (sdp->sd_ref == REF_REL_NEED)) { 12907c478bd9Sstevel@tonic-gate osp = sdp->sd_isc->is_osdesc; 12917c478bd9Sstevel@tonic-gate /* LINTED */ 12927c478bd9Sstevel@tonic-gate sectndx = elf_ndxscn(osp->os_scn); 12937c478bd9Sstevel@tonic-gate 12947c478bd9Sstevel@tonic-gate /* 12957c478bd9Sstevel@tonic-gate * In an executable, the new symbol value is the 12967c478bd9Sstevel@tonic-gate * old value (offset into defining section) plus 12977c478bd9Sstevel@tonic-gate * virtual address of defining section. In a 12987c478bd9Sstevel@tonic-gate * relocatable, the new value is the old value 12997c478bd9Sstevel@tonic-gate * plus the displacement of the section within 13007c478bd9Sstevel@tonic-gate * the file. 13017c478bd9Sstevel@tonic-gate */ 13027c478bd9Sstevel@tonic-gate /* LINTED */ 13037c478bd9Sstevel@tonic-gate sym->st_value += 13047c478bd9Sstevel@tonic-gate (Off)_elf_getxoff(sdp->sd_isc->is_indata); 13057c478bd9Sstevel@tonic-gate 13067c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_RELOBJ)) { 13077c478bd9Sstevel@tonic-gate sym->st_value += osp->os_shdr->sh_addr; 13087c478bd9Sstevel@tonic-gate /* 13097c478bd9Sstevel@tonic-gate * TLS symbols are relative to 13107c478bd9Sstevel@tonic-gate * the TLS segment. 13117c478bd9Sstevel@tonic-gate */ 13127c478bd9Sstevel@tonic-gate if ((ELF_ST_TYPE(sym->st_info) == 13137c478bd9Sstevel@tonic-gate STT_TLS) && (ofl->ofl_tlsphdr)) 13147c478bd9Sstevel@tonic-gate sym->st_value -= 13157c478bd9Sstevel@tonic-gate ofl->ofl_tlsphdr->p_vaddr; 13167c478bd9Sstevel@tonic-gate } 13177c478bd9Sstevel@tonic-gate } 13187c478bd9Sstevel@tonic-gate } 13197c478bd9Sstevel@tonic-gate 13207c478bd9Sstevel@tonic-gate if (spec) { 13217c478bd9Sstevel@tonic-gate switch (spec) { 13227c478bd9Sstevel@tonic-gate case SDAUX_ID_ETEXT: 13237c478bd9Sstevel@tonic-gate sym->st_value = etext; 13247c478bd9Sstevel@tonic-gate sectndx = etext_ndx; 13257c478bd9Sstevel@tonic-gate if (etext_abs) 13267c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_SPECSEC; 13277c478bd9Sstevel@tonic-gate else 13287c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 13297c478bd9Sstevel@tonic-gate break; 13307c478bd9Sstevel@tonic-gate case SDAUX_ID_EDATA: 13317c478bd9Sstevel@tonic-gate sym->st_value = edata; 13327c478bd9Sstevel@tonic-gate sectndx = edata_ndx; 13337c478bd9Sstevel@tonic-gate if (edata_abs) 13347c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_SPECSEC; 13357c478bd9Sstevel@tonic-gate else 13367c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 13377c478bd9Sstevel@tonic-gate break; 13387c478bd9Sstevel@tonic-gate case SDAUX_ID_END: 13397c478bd9Sstevel@tonic-gate sym->st_value = end; 13407c478bd9Sstevel@tonic-gate sectndx = end_ndx; 13417c478bd9Sstevel@tonic-gate if (end_abs) 13427c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_SPECSEC; 13437c478bd9Sstevel@tonic-gate else 13447c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 13457c478bd9Sstevel@tonic-gate break; 13467c478bd9Sstevel@tonic-gate case SDAUX_ID_START: 13477c478bd9Sstevel@tonic-gate sym->st_value = start; 13487c478bd9Sstevel@tonic-gate sectndx = start_ndx; 13497c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 13507c478bd9Sstevel@tonic-gate break; 13517c478bd9Sstevel@tonic-gate case SDAUX_ID_DYN: 13527c478bd9Sstevel@tonic-gate if (flags & FLG_OF_DYNAMIC) { 13537c478bd9Sstevel@tonic-gate sym->st_value = ofl-> 13547c478bd9Sstevel@tonic-gate ofl_osdynamic->os_shdr->sh_addr; 13557c478bd9Sstevel@tonic-gate /* LINTED */ 13567c478bd9Sstevel@tonic-gate sectndx = elf_ndxscn( 13577c478bd9Sstevel@tonic-gate ofl->ofl_osdynamic->os_scn); 13587c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 13597c478bd9Sstevel@tonic-gate } 13607c478bd9Sstevel@tonic-gate break; 13617c478bd9Sstevel@tonic-gate case SDAUX_ID_PLT: 13627c478bd9Sstevel@tonic-gate if (ofl->ofl_osplt) { 13637c478bd9Sstevel@tonic-gate sym->st_value = ofl-> 13647c478bd9Sstevel@tonic-gate ofl_osplt->os_shdr->sh_addr; 13657c478bd9Sstevel@tonic-gate /* LINTED */ 13667c478bd9Sstevel@tonic-gate sectndx = elf_ndxscn( 13677c478bd9Sstevel@tonic-gate ofl->ofl_osplt->os_scn); 13687c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 13697c478bd9Sstevel@tonic-gate } 13707c478bd9Sstevel@tonic-gate break; 13717c478bd9Sstevel@tonic-gate case SDAUX_ID_GOT: 13727c478bd9Sstevel@tonic-gate /* 13737c478bd9Sstevel@tonic-gate * Symbol bias for negative growing tables is 13747c478bd9Sstevel@tonic-gate * stored in symbol's value during 13757c478bd9Sstevel@tonic-gate * allocate_got(). 13767c478bd9Sstevel@tonic-gate */ 13777c478bd9Sstevel@tonic-gate sym->st_value += ofl-> 13787c478bd9Sstevel@tonic-gate ofl_osgot->os_shdr->sh_addr; 13797c478bd9Sstevel@tonic-gate /* LINTED */ 13807c478bd9Sstevel@tonic-gate sectndx = elf_ndxscn(ofl-> 13817c478bd9Sstevel@tonic-gate ofl_osgot->os_scn); 13827c478bd9Sstevel@tonic-gate sdp->sd_flags &= ~FLG_SY_SPECSEC; 13837c478bd9Sstevel@tonic-gate break; 13847c478bd9Sstevel@tonic-gate default: 13857c478bd9Sstevel@tonic-gate /* NOTHING */ 13867c478bd9Sstevel@tonic-gate ; 13877c478bd9Sstevel@tonic-gate } 13887c478bd9Sstevel@tonic-gate } 13897c478bd9Sstevel@tonic-gate 13907c478bd9Sstevel@tonic-gate /* 13917c478bd9Sstevel@tonic-gate * If a plt index has been assigned to an undefined function, 13927c478bd9Sstevel@tonic-gate * update the symbols value to the appropriate .plt address. 13937c478bd9Sstevel@tonic-gate */ 13947c478bd9Sstevel@tonic-gate if ((flags & FLG_OF_DYNAMIC) && (flags & FLG_OF_EXEC) && 13957c478bd9Sstevel@tonic-gate (sdp->sd_file) && 13967c478bd9Sstevel@tonic-gate (sdp->sd_file->ifl_ehdr->e_type == ET_DYN) && 13977c478bd9Sstevel@tonic-gate (ELF_ST_TYPE(sym->st_info) == STT_FUNC) && 13987c478bd9Sstevel@tonic-gate !(flags & FLG_OF_BFLAG)) { 13997c478bd9Sstevel@tonic-gate if (sap->sa_PLTndx) 14005aefb655Srie sym->st_value = ld_calc_plt_addr(sdp, ofl); 14017c478bd9Sstevel@tonic-gate } 14027c478bd9Sstevel@tonic-gate 14037c478bd9Sstevel@tonic-gate /* 14047c478bd9Sstevel@tonic-gate * Finish updating the symbols. 14057c478bd9Sstevel@tonic-gate */ 14067c478bd9Sstevel@tonic-gate 14077c478bd9Sstevel@tonic-gate /* 14087c478bd9Sstevel@tonic-gate * Sym Update: if scoped local - set local binding 14097c478bd9Sstevel@tonic-gate */ 14107c478bd9Sstevel@tonic-gate if (local) 14117c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(STB_LOCAL, 14127c478bd9Sstevel@tonic-gate ELF_ST_TYPE(sym->st_info)); 14137c478bd9Sstevel@tonic-gate 14147c478bd9Sstevel@tonic-gate /* 14157c478bd9Sstevel@tonic-gate * Sym Updated: If both the .symtab and .dynsym 14167c478bd9Sstevel@tonic-gate * are present then we've actually updated the information in 14177c478bd9Sstevel@tonic-gate * the .dynsym, therefore copy this same information to the 14187c478bd9Sstevel@tonic-gate * .symtab entry. 14197c478bd9Sstevel@tonic-gate */ 14207c478bd9Sstevel@tonic-gate sdp->sd_shndx = sectndx; 14217c478bd9Sstevel@tonic-gate if (enter_in_symtab && dynsym && !local) { 14227c478bd9Sstevel@tonic-gate symtab[symtab_ndx].st_value = sym->st_value; 14237c478bd9Sstevel@tonic-gate symtab[symtab_ndx].st_size = sym->st_size; 14247c478bd9Sstevel@tonic-gate symtab[symtab_ndx].st_info = sym->st_info; 14257c478bd9Sstevel@tonic-gate symtab[symtab_ndx].st_other = sym->st_other; 14267c478bd9Sstevel@tonic-gate } 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate 14297c478bd9Sstevel@tonic-gate if (enter_in_symtab) { 14307c478bd9Sstevel@tonic-gate Word _symndx; 14317c478bd9Sstevel@tonic-gate 14327c478bd9Sstevel@tonic-gate if (local) 14337c478bd9Sstevel@tonic-gate _symndx = scopesym_ndx++; 14347c478bd9Sstevel@tonic-gate else 14357c478bd9Sstevel@tonic-gate _symndx = symtab_ndx++; 14367c478bd9Sstevel@tonic-gate if (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) && 14377c478bd9Sstevel@tonic-gate (sectndx >= SHN_LORESERVE)) { 14387c478bd9Sstevel@tonic-gate assert(symshndx != 0); 14397c478bd9Sstevel@tonic-gate symshndx[_symndx] = sectndx; 14407c478bd9Sstevel@tonic-gate symtab[_symndx].st_shndx = SHN_XINDEX; 14417c478bd9Sstevel@tonic-gate } else { 14427c478bd9Sstevel@tonic-gate /* LINTED */ 14437c478bd9Sstevel@tonic-gate symtab[_symndx].st_shndx = (Half)sectndx; 14447c478bd9Sstevel@tonic-gate } 14457c478bd9Sstevel@tonic-gate } 14467c478bd9Sstevel@tonic-gate 14477c478bd9Sstevel@tonic-gate if (dynsym && !local) { 14487c478bd9Sstevel@tonic-gate if (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) && 14497c478bd9Sstevel@tonic-gate (sectndx >= SHN_LORESERVE)) { 14507c478bd9Sstevel@tonic-gate assert(dynshndx != 0); 14517c478bd9Sstevel@tonic-gate dynshndx[dynsym_ndx] = sectndx; 14527c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx].st_shndx = SHN_XINDEX; 14537c478bd9Sstevel@tonic-gate } else { 14547c478bd9Sstevel@tonic-gate /* LINTED */ 14557c478bd9Sstevel@tonic-gate dynsym[dynsym_ndx].st_shndx = (Half)sectndx; 14567c478bd9Sstevel@tonic-gate } 14577c478bd9Sstevel@tonic-gate dynsym_ndx++; 14587c478bd9Sstevel@tonic-gate } 14597c478bd9Sstevel@tonic-gate 14605aefb655Srie DBG_CALL(Dbg_syms_new(ofl, sym, sdp)); 14617c478bd9Sstevel@tonic-gate } 14627c478bd9Sstevel@tonic-gate 14637c478bd9Sstevel@tonic-gate /* 14647c478bd9Sstevel@tonic-gate * Now that all the symbols have been processed update any weak symbols 14657c478bd9Sstevel@tonic-gate * information (ie. copy all information except `st_name'). As both 14667c478bd9Sstevel@tonic-gate * symbols will be represented in the output, return the weak symbol to 14677c478bd9Sstevel@tonic-gate * its correct type. 14687c478bd9Sstevel@tonic-gate */ 14697c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&weak, lnp1, wkp)) { 14707c478bd9Sstevel@tonic-gate Sym_desc * sdp, * _sdp; 14717c478bd9Sstevel@tonic-gate Sym * sym, * _sym, * __sym; 14727c478bd9Sstevel@tonic-gate unsigned char bind; 14737c478bd9Sstevel@tonic-gate 14747c478bd9Sstevel@tonic-gate sdp = wkp->wk_weak; 14757c478bd9Sstevel@tonic-gate _sdp = wkp->wk_alias; 14767c478bd9Sstevel@tonic-gate _sym = _sdp->sd_sym; 14777c478bd9Sstevel@tonic-gate 14787c478bd9Sstevel@tonic-gate sdp->sd_flags |= FLG_SY_WEAKDEF; 14797c478bd9Sstevel@tonic-gate 14807c478bd9Sstevel@tonic-gate /* 14817c478bd9Sstevel@tonic-gate * If the symbol definition has been scoped then assign it to 14827c478bd9Sstevel@tonic-gate * be local, otherwise if it's from a shared object then we need 14837c478bd9Sstevel@tonic-gate * to maintain the binding of the original reference. 14847c478bd9Sstevel@tonic-gate */ 14857c478bd9Sstevel@tonic-gate if (sdp->sd_flags1 & FLG_SY1_LOCL) { 14867c478bd9Sstevel@tonic-gate if (flags & FLG_OF_PROCRED) 14877c478bd9Sstevel@tonic-gate bind = STB_LOCAL; 14887c478bd9Sstevel@tonic-gate else 14897c478bd9Sstevel@tonic-gate bind = STB_WEAK; 14907c478bd9Sstevel@tonic-gate } else if ((sdp->sd_ref == REF_DYN_NEED) && 14917c478bd9Sstevel@tonic-gate (sdp->sd_flags & FLG_SY_GLOBREF)) 14927c478bd9Sstevel@tonic-gate bind = STB_GLOBAL; 14937c478bd9Sstevel@tonic-gate else 14947c478bd9Sstevel@tonic-gate bind = STB_WEAK; 14957c478bd9Sstevel@tonic-gate 14965aefb655Srie DBG_CALL(Dbg_syms_old(ofl, sdp)); 14977c478bd9Sstevel@tonic-gate if ((sym = wkp->wk_symtab) != 0) { 14987c478bd9Sstevel@tonic-gate sym = wkp->wk_symtab; 14997c478bd9Sstevel@tonic-gate sym->st_value = _sym->st_value; 15007c478bd9Sstevel@tonic-gate sym->st_size = _sym->st_size; 15017c478bd9Sstevel@tonic-gate sym->st_other = _sym->st_other; 15027c478bd9Sstevel@tonic-gate sym->st_shndx = _sym->st_shndx; 15037c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(bind, 15047c478bd9Sstevel@tonic-gate ELF_ST_TYPE(sym->st_info)); 15057c478bd9Sstevel@tonic-gate __sym = sym; 15067c478bd9Sstevel@tonic-gate } 15077c478bd9Sstevel@tonic-gate if ((sym = wkp->wk_dynsym) != 0) { 15087c478bd9Sstevel@tonic-gate sym = wkp->wk_dynsym; 15097c478bd9Sstevel@tonic-gate sym->st_value = _sym->st_value; 15107c478bd9Sstevel@tonic-gate sym->st_size = _sym->st_size; 15117c478bd9Sstevel@tonic-gate sym->st_other = _sym->st_other; 15127c478bd9Sstevel@tonic-gate sym->st_shndx = _sym->st_shndx; 15137c478bd9Sstevel@tonic-gate sym->st_info = ELF_ST_INFO(bind, 15147c478bd9Sstevel@tonic-gate ELF_ST_TYPE(sym->st_info)); 15157c478bd9Sstevel@tonic-gate __sym = sym; 15167c478bd9Sstevel@tonic-gate } 15175aefb655Srie DBG_CALL(Dbg_syms_new(ofl, __sym, sdp)); 15187c478bd9Sstevel@tonic-gate } 15197c478bd9Sstevel@tonic-gate 15207c478bd9Sstevel@tonic-gate /* 15215aefb655Srie * Now display GOT debugging information if required. 15227c478bd9Sstevel@tonic-gate */ 15235aefb655Srie DBG_CALL(Dbg_got_display(ofl, gottable)); 15247c478bd9Sstevel@tonic-gate 15257c478bd9Sstevel@tonic-gate /* 15267c478bd9Sstevel@tonic-gate * Update the section headers information. 15277c478bd9Sstevel@tonic-gate */ 15287c478bd9Sstevel@tonic-gate if (symtab) { 15297c478bd9Sstevel@tonic-gate Shdr * shdr = ofl->ofl_ossymtab->os_shdr; 15307c478bd9Sstevel@tonic-gate 15317c478bd9Sstevel@tonic-gate shdr->sh_info = ofl->ofl_shdrcnt + ofl->ofl_locscnt + 15327c478bd9Sstevel@tonic-gate ofl->ofl_scopecnt + 2; 15337c478bd9Sstevel@tonic-gate /* LINTED */ 15347c478bd9Sstevel@tonic-gate shdr->sh_link = (Word)elf_ndxscn(ofl->ofl_osstrtab->os_scn); 15357c478bd9Sstevel@tonic-gate if (symshndx) { 15367c478bd9Sstevel@tonic-gate shdr = ofl->ofl_ossymshndx->os_shdr; 15377c478bd9Sstevel@tonic-gate shdr->sh_link = 15387c478bd9Sstevel@tonic-gate (Word)elf_ndxscn(ofl->ofl_ossymtab->os_scn); 15397c478bd9Sstevel@tonic-gate } 15407c478bd9Sstevel@tonic-gate } 15417c478bd9Sstevel@tonic-gate if (dynsym) { 15427c478bd9Sstevel@tonic-gate Shdr * shdr = ofl->ofl_osdynsym->os_shdr; 15437c478bd9Sstevel@tonic-gate 15447c478bd9Sstevel@tonic-gate shdr->sh_info = ofl->ofl_dynshdrcnt + ofl->ofl_lregsymcnt + 1; 15457c478bd9Sstevel@tonic-gate /* LINTED */ 15467c478bd9Sstevel@tonic-gate shdr->sh_link = (Word)elf_ndxscn(ofl->ofl_osdynstr->os_scn); 15477c478bd9Sstevel@tonic-gate 15487c478bd9Sstevel@tonic-gate ofl->ofl_oshash->os_shdr->sh_link = 15497c478bd9Sstevel@tonic-gate /* LINTED */ 15507c478bd9Sstevel@tonic-gate (Word)elf_ndxscn(ofl->ofl_osdynsym->os_scn); 15517c478bd9Sstevel@tonic-gate if (dynshndx) { 15527c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osdynshndx->os_shdr; 15537c478bd9Sstevel@tonic-gate shdr->sh_link = 15547c478bd9Sstevel@tonic-gate (Word)elf_ndxscn(ofl->ofl_osdynsym->os_scn); 15557c478bd9Sstevel@tonic-gate } 15567c478bd9Sstevel@tonic-gate } 15577c478bd9Sstevel@tonic-gate 15587c478bd9Sstevel@tonic-gate /* 15597c478bd9Sstevel@tonic-gate * Used by ld.so.1 only. 15607c478bd9Sstevel@tonic-gate */ 15617c478bd9Sstevel@tonic-gate return (etext); 15627c478bd9Sstevel@tonic-gate } 15637c478bd9Sstevel@tonic-gate 15647c478bd9Sstevel@tonic-gate /* 15657c478bd9Sstevel@tonic-gate * Build the dynamic section. 15667c478bd9Sstevel@tonic-gate */ 15675aefb655Srie static int 15687c478bd9Sstevel@tonic-gate update_odynamic(Ofl_desc *ofl) 15697c478bd9Sstevel@tonic-gate { 15707c478bd9Sstevel@tonic-gate Listnode *lnp; 15717c478bd9Sstevel@tonic-gate Ifl_desc *ifl; 15727c478bd9Sstevel@tonic-gate Sym_desc *sdp; 15737c478bd9Sstevel@tonic-gate Shdr *shdr; 15747c478bd9Sstevel@tonic-gate Dyn *_dyn = (Dyn *)ofl->ofl_osdynamic->os_outdata->d_buf; 15757c478bd9Sstevel@tonic-gate Dyn *dyn; 15767c478bd9Sstevel@tonic-gate Str_tbl *dynstr; 15777c478bd9Sstevel@tonic-gate uint_t stoff; 15787c478bd9Sstevel@tonic-gate Word flags = ofl->ofl_flags; 15797c478bd9Sstevel@tonic-gate 15807c478bd9Sstevel@tonic-gate dynstr = ofl->ofl_dynstrtab; 15817c478bd9Sstevel@tonic-gate ofl->ofl_osdynamic->os_shdr->sh_link = 15827c478bd9Sstevel@tonic-gate /* LINTED */ 15837c478bd9Sstevel@tonic-gate (Word)elf_ndxscn(ofl->ofl_osdynstr->os_scn); 15847c478bd9Sstevel@tonic-gate 15857c478bd9Sstevel@tonic-gate dyn = _dyn; 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_sos, lnp, ifl)) { 15887c478bd9Sstevel@tonic-gate if ((ifl->ifl_flags & 15897c478bd9Sstevel@tonic-gate (FLG_IF_IGNORE | FLG_IF_DEPREQD)) == FLG_IF_IGNORE) 15907c478bd9Sstevel@tonic-gate continue; 15917c478bd9Sstevel@tonic-gate 15927c478bd9Sstevel@tonic-gate /* 15937c478bd9Sstevel@tonic-gate * Create and set up the DT_POSFLAG_1 entry here if required. 15947c478bd9Sstevel@tonic-gate */ 15957c478bd9Sstevel@tonic-gate if ((ifl->ifl_flags & (FLG_IF_LAZYLD|FLG_IF_GRPPRM)) && 15967c478bd9Sstevel@tonic-gate (ifl->ifl_flags & (FLG_IF_NEEDED))) { 15977c478bd9Sstevel@tonic-gate dyn->d_tag = DT_POSFLAG_1; 15987c478bd9Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_LAZYLD) 15997c478bd9Sstevel@tonic-gate dyn->d_un.d_val = DF_P1_LAZYLOAD; 16007c478bd9Sstevel@tonic-gate if (ifl->ifl_flags & FLG_IF_GRPPRM) 16017c478bd9Sstevel@tonic-gate dyn->d_un.d_val |= DF_P1_GROUPPERM; 16027c478bd9Sstevel@tonic-gate dyn++; 16037c478bd9Sstevel@tonic-gate } 16047c478bd9Sstevel@tonic-gate 16057c478bd9Sstevel@tonic-gate if (ifl->ifl_flags & (FLG_IF_NEEDED | FLG_IF_NEEDSTR)) 16067c478bd9Sstevel@tonic-gate dyn->d_tag = DT_NEEDED; 16077c478bd9Sstevel@tonic-gate else 16087c478bd9Sstevel@tonic-gate continue; 16097c478bd9Sstevel@tonic-gate 16107c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, ifl->ifl_soname, &stoff); 16117c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 16127c478bd9Sstevel@tonic-gate /* LINTED */ 16137c478bd9Sstevel@tonic-gate ifl->ifl_neededndx = (Half)(((uintptr_t)dyn - (uintptr_t)_dyn) / 16147c478bd9Sstevel@tonic-gate sizeof (Dyn)); 16157c478bd9Sstevel@tonic-gate dyn++; 16167c478bd9Sstevel@tonic-gate } 16177c478bd9Sstevel@tonic-gate 16187c478bd9Sstevel@tonic-gate if (ofl->ofl_dtsfltrs) { 16197c478bd9Sstevel@tonic-gate Dfltr_desc * dftp; 16207c478bd9Sstevel@tonic-gate Aliste off; 16217c478bd9Sstevel@tonic-gate 16227c478bd9Sstevel@tonic-gate for (ALIST_TRAVERSE(ofl->ofl_dtsfltrs, off, dftp)) { 16237c478bd9Sstevel@tonic-gate if (dftp->dft_flag == FLG_SY_AUXFLTR) 16247c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SUNW_AUXILIARY; 16257c478bd9Sstevel@tonic-gate else 16267c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SUNW_FILTER; 16277c478bd9Sstevel@tonic-gate 16287c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, dftp->dft_str, &stoff); 16297c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 16307c478bd9Sstevel@tonic-gate dftp->dft_ndx = (Half)(((uintptr_t)dyn - 16317c478bd9Sstevel@tonic-gate (uintptr_t)_dyn) / sizeof (Dyn)); 16327c478bd9Sstevel@tonic-gate dyn++; 16337c478bd9Sstevel@tonic-gate } 16347c478bd9Sstevel@tonic-gate } 16355aefb655Srie if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_INIT_U), 16367c478bd9Sstevel@tonic-gate SYM_NOHASH, 0, ofl)) != NULL) && 16377c478bd9Sstevel@tonic-gate sdp->sd_ref == REF_REL_NEED) { 16387c478bd9Sstevel@tonic-gate dyn->d_tag = DT_INIT; 16397c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = sdp->sd_sym->st_value; 16407c478bd9Sstevel@tonic-gate dyn++; 16417c478bd9Sstevel@tonic-gate } 16425aefb655Srie if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_FINI_U), 16437c478bd9Sstevel@tonic-gate SYM_NOHASH, 0, ofl)) != NULL) && 16447c478bd9Sstevel@tonic-gate sdp->sd_ref == REF_REL_NEED) { 16457c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FINI; 16467c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = sdp->sd_sym->st_value; 16477c478bd9Sstevel@tonic-gate dyn++; 16487c478bd9Sstevel@tonic-gate } 16497c478bd9Sstevel@tonic-gate if (ofl->ofl_soname) { 16507c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SONAME; 16517c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, ofl->ofl_soname, &stoff); 16527c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 16537c478bd9Sstevel@tonic-gate dyn++; 16547c478bd9Sstevel@tonic-gate } 16557c478bd9Sstevel@tonic-gate if (ofl->ofl_filtees) { 16567c478bd9Sstevel@tonic-gate if (flags & FLG_OF_AUX) { 16577c478bd9Sstevel@tonic-gate dyn->d_tag = DT_AUXILIARY; 16587c478bd9Sstevel@tonic-gate } else { 16597c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FILTER; 16607c478bd9Sstevel@tonic-gate } 16617c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, ofl->ofl_filtees, &stoff); 16627c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 16637c478bd9Sstevel@tonic-gate dyn++; 16647c478bd9Sstevel@tonic-gate } 16657c478bd9Sstevel@tonic-gate if (ofl->ofl_rpath) { 16667c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, ofl->ofl_rpath, &stoff); 16677c478bd9Sstevel@tonic-gate dyn->d_tag = DT_RUNPATH; 16687c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 16697c478bd9Sstevel@tonic-gate dyn++; 16707c478bd9Sstevel@tonic-gate dyn->d_tag = DT_RPATH; 16717c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 16727c478bd9Sstevel@tonic-gate dyn++; 16737c478bd9Sstevel@tonic-gate } 16747c478bd9Sstevel@tonic-gate if (ofl->ofl_config) { 16757c478bd9Sstevel@tonic-gate dyn->d_tag = DT_CONFIG; 16767c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, ofl->ofl_config, &stoff); 16777c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 16787c478bd9Sstevel@tonic-gate dyn++; 16797c478bd9Sstevel@tonic-gate } 16807c478bd9Sstevel@tonic-gate if (ofl->ofl_depaudit) { 16817c478bd9Sstevel@tonic-gate dyn->d_tag = DT_DEPAUDIT; 16827c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, ofl->ofl_depaudit, &stoff); 16837c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 16847c478bd9Sstevel@tonic-gate dyn++; 16857c478bd9Sstevel@tonic-gate } 16867c478bd9Sstevel@tonic-gate if (ofl->ofl_audit) { 16877c478bd9Sstevel@tonic-gate dyn->d_tag = DT_AUDIT; 16887c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, ofl->ofl_audit, &stoff); 16897c478bd9Sstevel@tonic-gate dyn->d_un.d_val = stoff; 16907c478bd9Sstevel@tonic-gate dyn++; 16917c478bd9Sstevel@tonic-gate } 16927c478bd9Sstevel@tonic-gate 16937c478bd9Sstevel@tonic-gate /* 16947c478bd9Sstevel@tonic-gate * The following DT_* entries do not apply to relocatable objects. 16957c478bd9Sstevel@tonic-gate */ 16967c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_RELOBJ)) { 16977c478bd9Sstevel@tonic-gate 16987c478bd9Sstevel@tonic-gate dyn->d_tag = DT_HASH; 16997c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = ofl->ofl_oshash->os_shdr->sh_addr; 17007c478bd9Sstevel@tonic-gate dyn++; 17017c478bd9Sstevel@tonic-gate 17027c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osdynstr->os_shdr; 17037c478bd9Sstevel@tonic-gate dyn->d_tag = DT_STRTAB; 17047c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 17057c478bd9Sstevel@tonic-gate dyn++; 17067c478bd9Sstevel@tonic-gate 17077c478bd9Sstevel@tonic-gate dyn->d_tag = DT_STRSZ; 17087c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_size; 17097c478bd9Sstevel@tonic-gate dyn++; 17107c478bd9Sstevel@tonic-gate 17117c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osdynsym->os_shdr; 17127c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SYMTAB; 17137c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 17147c478bd9Sstevel@tonic-gate dyn++; 17157c478bd9Sstevel@tonic-gate 17167c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SYMENT; 17177c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_entsize; 17187c478bd9Sstevel@tonic-gate dyn++; 17197c478bd9Sstevel@tonic-gate 17207c478bd9Sstevel@tonic-gate /* 17217c478bd9Sstevel@tonic-gate * Reserve the DT_CHECKSUM entry. Its value will be filled in 17227c478bd9Sstevel@tonic-gate * after the complete image is built. 17237c478bd9Sstevel@tonic-gate */ 17247c478bd9Sstevel@tonic-gate dyn->d_tag = DT_CHECKSUM; 17257c478bd9Sstevel@tonic-gate ofl->ofl_checksum = &dyn->d_un.d_val; 17267c478bd9Sstevel@tonic-gate dyn++; 17277c478bd9Sstevel@tonic-gate 17287c478bd9Sstevel@tonic-gate if ((flags & (FLG_OF_VERDEF | FLG_OF_NOVERSEC)) == 17297c478bd9Sstevel@tonic-gate FLG_OF_VERDEF) { 17307c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osverdef->os_shdr; 17317c478bd9Sstevel@tonic-gate dyn->d_tag = DT_VERDEF; 17327c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 17337c478bd9Sstevel@tonic-gate dyn++; 17347c478bd9Sstevel@tonic-gate dyn->d_tag = DT_VERDEFNUM; 17357c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_info; 17367c478bd9Sstevel@tonic-gate dyn++; 17377c478bd9Sstevel@tonic-gate } 17387c478bd9Sstevel@tonic-gate if ((flags & (FLG_OF_VERNEED | FLG_OF_NOVERSEC)) == 17397c478bd9Sstevel@tonic-gate FLG_OF_VERNEED) { 17407c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osverneed->os_shdr; 17417c478bd9Sstevel@tonic-gate dyn->d_tag = DT_VERNEED; 17427c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 17437c478bd9Sstevel@tonic-gate dyn++; 17447c478bd9Sstevel@tonic-gate dyn->d_tag = DT_VERNEEDNUM; 17457c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_info; 17467c478bd9Sstevel@tonic-gate dyn++; 17477c478bd9Sstevel@tonic-gate } 17487c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags1 & FLG_OF1_RELCNT) && 17497c478bd9Sstevel@tonic-gate ofl->ofl_relocrelcnt) { 17507c478bd9Sstevel@tonic-gate dyn->d_tag = M_REL_DT_COUNT; 17517c478bd9Sstevel@tonic-gate dyn->d_un.d_val = ofl->ofl_relocrelcnt; 17527c478bd9Sstevel@tonic-gate dyn++; 17537c478bd9Sstevel@tonic-gate } 17547c478bd9Sstevel@tonic-gate if (flags & FLG_OF_TEXTREL) { 17557c478bd9Sstevel@tonic-gate /* 17567c478bd9Sstevel@tonic-gate * Only the presence of this entry is used in this 17577c478bd9Sstevel@tonic-gate * implementation, not the value stored. 17587c478bd9Sstevel@tonic-gate */ 17597c478bd9Sstevel@tonic-gate dyn->d_tag = DT_TEXTREL; 17607c478bd9Sstevel@tonic-gate dyn->d_un.d_val = 0; 17617c478bd9Sstevel@tonic-gate dyn++; 17627c478bd9Sstevel@tonic-gate } 17637c478bd9Sstevel@tonic-gate 17647c478bd9Sstevel@tonic-gate if (ofl->ofl_osfiniarray) { 17657c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osfiniarray->os_shdr; 17667c478bd9Sstevel@tonic-gate 17677c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FINI_ARRAY; 17687c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 17697c478bd9Sstevel@tonic-gate dyn++; 17707c478bd9Sstevel@tonic-gate 17717c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FINI_ARRAYSZ; 17727c478bd9Sstevel@tonic-gate dyn->d_un.d_val = shdr->sh_size; 17737c478bd9Sstevel@tonic-gate dyn++; 17747c478bd9Sstevel@tonic-gate } 17757c478bd9Sstevel@tonic-gate 17767c478bd9Sstevel@tonic-gate if (ofl->ofl_osinitarray) { 17777c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osinitarray->os_shdr; 17787c478bd9Sstevel@tonic-gate 17797c478bd9Sstevel@tonic-gate dyn->d_tag = DT_INIT_ARRAY; 17807c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 17817c478bd9Sstevel@tonic-gate dyn++; 17827c478bd9Sstevel@tonic-gate 17837c478bd9Sstevel@tonic-gate dyn->d_tag = DT_INIT_ARRAYSZ; 17847c478bd9Sstevel@tonic-gate dyn->d_un.d_val = shdr->sh_size; 17857c478bd9Sstevel@tonic-gate dyn++; 17867c478bd9Sstevel@tonic-gate } 17877c478bd9Sstevel@tonic-gate 17887c478bd9Sstevel@tonic-gate if (ofl->ofl_ospreinitarray) { 17897c478bd9Sstevel@tonic-gate shdr = ofl->ofl_ospreinitarray->os_shdr; 17907c478bd9Sstevel@tonic-gate 17917c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PREINIT_ARRAY; 17927c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 17937c478bd9Sstevel@tonic-gate dyn++; 17947c478bd9Sstevel@tonic-gate 17957c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PREINIT_ARRAYSZ; 17967c478bd9Sstevel@tonic-gate dyn->d_un.d_val = shdr->sh_size; 17977c478bd9Sstevel@tonic-gate dyn++; 17987c478bd9Sstevel@tonic-gate } 17997c478bd9Sstevel@tonic-gate 18007c478bd9Sstevel@tonic-gate if (ofl->ofl_pltcnt) { 18017c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osplt->os_relosdesc->os_shdr; 18027c478bd9Sstevel@tonic-gate 18037c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PLTRELSZ; 18047c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_size; 18057c478bd9Sstevel@tonic-gate dyn++; 18067c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PLTREL; 18077c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = M_REL_DT_TYPE; 18087c478bd9Sstevel@tonic-gate dyn++; 18097c478bd9Sstevel@tonic-gate dyn->d_tag = DT_JMPREL; 18107c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 18117c478bd9Sstevel@tonic-gate dyn++; 18127c478bd9Sstevel@tonic-gate } 18137c478bd9Sstevel@tonic-gate if (ofl->ofl_pltpad) { 18147c478bd9Sstevel@tonic-gate shdr = ofl->ofl_osplt->os_shdr; 18157c478bd9Sstevel@tonic-gate 18167c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PLTPAD; 18177c478bd9Sstevel@tonic-gate if (ofl->ofl_pltcnt) 18187c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr + 18197c478bd9Sstevel@tonic-gate M_PLT_RESERVSZ + 18207c478bd9Sstevel@tonic-gate ofl->ofl_pltcnt * M_PLT_ENTSIZE; 18217c478bd9Sstevel@tonic-gate else 18227c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 18237c478bd9Sstevel@tonic-gate dyn++; 18247c478bd9Sstevel@tonic-gate dyn->d_tag = DT_PLTPADSZ; 18257c478bd9Sstevel@tonic-gate dyn->d_un.d_val = ofl->ofl_pltpad * 18267c478bd9Sstevel@tonic-gate M_PLT_ENTSIZE; 18277c478bd9Sstevel@tonic-gate dyn++; 18287c478bd9Sstevel@tonic-gate } 18297c478bd9Sstevel@tonic-gate if (ofl->ofl_relocsz) { 18307c478bd9Sstevel@tonic-gate dyn->d_tag = M_REL_DT_TYPE; 18317c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = ofl->ofl_osrelhead->os_shdr->sh_addr; 18327c478bd9Sstevel@tonic-gate dyn++; 18337c478bd9Sstevel@tonic-gate dyn->d_tag = M_REL_DT_SIZE; 18347c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = ofl->ofl_relocsz; 18357c478bd9Sstevel@tonic-gate dyn++; 18367c478bd9Sstevel@tonic-gate dyn->d_tag = M_REL_DT_ENT; 18377c478bd9Sstevel@tonic-gate if (ofl->ofl_osrelhead->os_shdr->sh_type == SHT_REL) 18387c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = sizeof (Rel); 18397c478bd9Sstevel@tonic-gate else 18407c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = sizeof (Rela); 18417c478bd9Sstevel@tonic-gate dyn++; 18427c478bd9Sstevel@tonic-gate } 18437c478bd9Sstevel@tonic-gate if (ofl->ofl_ossyminfo) { 18447c478bd9Sstevel@tonic-gate shdr = ofl->ofl_ossyminfo->os_shdr; 18457c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SYMINFO; 18467c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = shdr->sh_addr; 18477c478bd9Sstevel@tonic-gate dyn++; 18487c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SYMINSZ; 18497c478bd9Sstevel@tonic-gate dyn->d_un.d_val = shdr->sh_size; 18507c478bd9Sstevel@tonic-gate dyn++; 18517c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SYMINENT; 18527c478bd9Sstevel@tonic-gate dyn->d_un.d_val = sizeof (Syminfo); 18537c478bd9Sstevel@tonic-gate dyn++; 18547c478bd9Sstevel@tonic-gate } 18557c478bd9Sstevel@tonic-gate if (ofl->ofl_osmove) { 18567c478bd9Sstevel@tonic-gate Os_desc * osp; 18577c478bd9Sstevel@tonic-gate 18587c478bd9Sstevel@tonic-gate dyn->d_tag = DT_MOVEENT; 18597c478bd9Sstevel@tonic-gate osp = ofl->ofl_osmove; 18607c478bd9Sstevel@tonic-gate dyn->d_un.d_val = osp->os_shdr->sh_entsize; 18617c478bd9Sstevel@tonic-gate dyn++; 18627c478bd9Sstevel@tonic-gate dyn->d_tag = DT_MOVESZ; 18637c478bd9Sstevel@tonic-gate dyn->d_un.d_val = osp->os_shdr->sh_size; 18647c478bd9Sstevel@tonic-gate dyn++; 18657c478bd9Sstevel@tonic-gate dyn->d_tag = DT_MOVETAB; 18667c478bd9Sstevel@tonic-gate dyn->d_un.d_val = osp->os_shdr->sh_addr; 18677c478bd9Sstevel@tonic-gate dyn++; 18687c478bd9Sstevel@tonic-gate } 18697c478bd9Sstevel@tonic-gate if (ofl->ofl_regsymcnt) { 18707c478bd9Sstevel@tonic-gate int ndx; 18717c478bd9Sstevel@tonic-gate 18727c478bd9Sstevel@tonic-gate for (ndx = 0; ndx < ofl->ofl_regsymsno; ndx++) { 18737c478bd9Sstevel@tonic-gate if ((sdp = ofl->ofl_regsyms[ndx]) == 0) 18747c478bd9Sstevel@tonic-gate continue; 18757c478bd9Sstevel@tonic-gate 18767c478bd9Sstevel@tonic-gate dyn->d_tag = M_DT_REGISTER; 18777c478bd9Sstevel@tonic-gate dyn->d_un.d_val = sdp->sd_symndx; 18787c478bd9Sstevel@tonic-gate dyn++; 18797c478bd9Sstevel@tonic-gate } 18807c478bd9Sstevel@tonic-gate } 18817c478bd9Sstevel@tonic-gate 18827c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_rtldinfo, lnp, sdp)) { 18837c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SUNW_RTLDINF; 18847c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = sdp->sd_sym->st_value; 18857c478bd9Sstevel@tonic-gate dyn++; 18867c478bd9Sstevel@tonic-gate } 18877c478bd9Sstevel@tonic-gate 18887c478bd9Sstevel@tonic-gate if (ofl->ofl_osdynamic->os_sgdesc && 18897c478bd9Sstevel@tonic-gate (ofl->ofl_osdynamic->os_sgdesc->sg_phdr.p_flags & PF_W)) { 18907c478bd9Sstevel@tonic-gate if (ofl->ofl_osinterp) { 18917c478bd9Sstevel@tonic-gate dyn->d_tag = DT_DEBUG; 18927c478bd9Sstevel@tonic-gate dyn->d_un.d_ptr = 0; 18937c478bd9Sstevel@tonic-gate dyn++; 18947c478bd9Sstevel@tonic-gate } 18957c478bd9Sstevel@tonic-gate 18967c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FEATURE_1; 18977c478bd9Sstevel@tonic-gate if (ofl->ofl_osmove) 18987c478bd9Sstevel@tonic-gate dyn->d_un.d_val = 0; 18997c478bd9Sstevel@tonic-gate else 19007c478bd9Sstevel@tonic-gate dyn->d_un.d_val = DTF_1_PARINIT; 19017c478bd9Sstevel@tonic-gate dyn++; 19027c478bd9Sstevel@tonic-gate } 19037c478bd9Sstevel@tonic-gate 19047c478bd9Sstevel@tonic-gate if (ofl->ofl_oscap) { 19057c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SUNW_CAP; 19067c478bd9Sstevel@tonic-gate dyn->d_un.d_val = ofl->ofl_oscap->os_shdr->sh_addr; 19077c478bd9Sstevel@tonic-gate dyn++; 19087c478bd9Sstevel@tonic-gate } 19097c478bd9Sstevel@tonic-gate } 19107c478bd9Sstevel@tonic-gate 19117c478bd9Sstevel@tonic-gate if (flags & FLG_OF_SYMBOLIC) { 19127c478bd9Sstevel@tonic-gate dyn->d_tag = DT_SYMBOLIC; 19137c478bd9Sstevel@tonic-gate dyn->d_un.d_val = 0; 19147c478bd9Sstevel@tonic-gate dyn++; 19157c478bd9Sstevel@tonic-gate } 19167c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FLAGS; 19177c478bd9Sstevel@tonic-gate dyn->d_un.d_val = ofl->ofl_dtflags; 19187c478bd9Sstevel@tonic-gate dyn++; 19197c478bd9Sstevel@tonic-gate 19207c478bd9Sstevel@tonic-gate /* 19217c478bd9Sstevel@tonic-gate * If -Bdirect was specified, but some NODIRECT symbols were specified 19227c478bd9Sstevel@tonic-gate * via a mapfile, or -znodirect was used on the command line, then 19237c478bd9Sstevel@tonic-gate * clear the DF_1_DIRECT flag. The resultant object will use per-symbol 19247c478bd9Sstevel@tonic-gate * direct bindings rather than be enabled for global direct bindings. 19257c478bd9Sstevel@tonic-gate */ 19267c478bd9Sstevel@tonic-gate if (ofl->ofl_flags1 & FLG_OF1_NDIRECT) 19277c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 &= ~DF_1_DIRECT; 19287c478bd9Sstevel@tonic-gate 19297c478bd9Sstevel@tonic-gate dyn->d_tag = DT_FLAGS_1; 19307c478bd9Sstevel@tonic-gate dyn->d_un.d_val = ofl->ofl_dtflags_1; 19317c478bd9Sstevel@tonic-gate dyn++; 19327c478bd9Sstevel@tonic-gate 19335aefb655Srie ld_mach_update_odynamic(ofl, &dyn); 19347c478bd9Sstevel@tonic-gate 19357c478bd9Sstevel@tonic-gate dyn->d_tag = DT_NULL; 19367c478bd9Sstevel@tonic-gate dyn->d_un.d_val = 0; 19377c478bd9Sstevel@tonic-gate 19387c478bd9Sstevel@tonic-gate return (1); 19397c478bd9Sstevel@tonic-gate } 19407c478bd9Sstevel@tonic-gate 19417c478bd9Sstevel@tonic-gate /* 19427c478bd9Sstevel@tonic-gate * Build the version definition section 19437c478bd9Sstevel@tonic-gate */ 19445aefb655Srie static int 19457c478bd9Sstevel@tonic-gate update_overdef(Ofl_desc *ofl) 19467c478bd9Sstevel@tonic-gate { 19477c478bd9Sstevel@tonic-gate Listnode *lnp1, *lnp2; 19487c478bd9Sstevel@tonic-gate Ver_desc *vdp, *_vdp; 19497c478bd9Sstevel@tonic-gate Verdef *vdf, *_vdf; 19507c478bd9Sstevel@tonic-gate int num = 0; 19517c478bd9Sstevel@tonic-gate Os_desc *strosp, *symosp; 19527c478bd9Sstevel@tonic-gate 19537c478bd9Sstevel@tonic-gate /* 19547c478bd9Sstevel@tonic-gate * Traverse the version descriptors and update the version structures 19557c478bd9Sstevel@tonic-gate * to point to the dynstr name in preparation for building the version 19567c478bd9Sstevel@tonic-gate * section structure. 19577c478bd9Sstevel@tonic-gate */ 19587c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_verdesc, lnp1, vdp)) { 19597c478bd9Sstevel@tonic-gate Sym_desc * sdp; 19607c478bd9Sstevel@tonic-gate 19617c478bd9Sstevel@tonic-gate if (vdp->vd_flags & VER_FLG_BASE) { 19627c478bd9Sstevel@tonic-gate const char *name = vdp->vd_name; 19637c478bd9Sstevel@tonic-gate uint_t stoff; 19647c478bd9Sstevel@tonic-gate 19657c478bd9Sstevel@tonic-gate /* 19667c478bd9Sstevel@tonic-gate * Create a new string table entry to represent the base 19677c478bd9Sstevel@tonic-gate * version name (there is no corresponding symbol for 19687c478bd9Sstevel@tonic-gate * this). 19697c478bd9Sstevel@tonic-gate */ 19707c478bd9Sstevel@tonic-gate if (!(ofl->ofl_flags & FLG_OF_DYNAMIC)) { 19717c478bd9Sstevel@tonic-gate (void) st_setstring(ofl->ofl_strtab, 19727c478bd9Sstevel@tonic-gate name, &stoff); 19737c478bd9Sstevel@tonic-gate /* LINTED */ 19747c478bd9Sstevel@tonic-gate vdp->vd_name = (const char *)(uintptr_t)stoff; 19757c478bd9Sstevel@tonic-gate } else { 19767c478bd9Sstevel@tonic-gate (void) st_setstring(ofl->ofl_dynstrtab, 19777c478bd9Sstevel@tonic-gate name, &stoff); 19787c478bd9Sstevel@tonic-gate /* LINTED */ 19797c478bd9Sstevel@tonic-gate vdp->vd_name = (const char *)(uintptr_t)stoff; 19807c478bd9Sstevel@tonic-gate } 19817c478bd9Sstevel@tonic-gate } else { 19825aefb655Srie sdp = ld_sym_find(vdp->vd_name, vdp->vd_hash, 0, ofl); 19837c478bd9Sstevel@tonic-gate /* LINTED */ 19847c478bd9Sstevel@tonic-gate vdp->vd_name = (const char *) 19857c478bd9Sstevel@tonic-gate (uintptr_t)sdp->sd_sym->st_name; 19867c478bd9Sstevel@tonic-gate } 19877c478bd9Sstevel@tonic-gate } 19887c478bd9Sstevel@tonic-gate 19897c478bd9Sstevel@tonic-gate _vdf = vdf = (Verdef *)ofl->ofl_osverdef->os_outdata->d_buf; 19907c478bd9Sstevel@tonic-gate 19917c478bd9Sstevel@tonic-gate /* 19927c478bd9Sstevel@tonic-gate * Traverse the version descriptors and update the version section to 19937c478bd9Sstevel@tonic-gate * reflect each version and its associated dependencies. 19947c478bd9Sstevel@tonic-gate */ 19957c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_verdesc, lnp1, vdp)) { 19967c478bd9Sstevel@tonic-gate Half cnt = 1; 19977c478bd9Sstevel@tonic-gate Verdaux * vdap, * _vdap; 19987c478bd9Sstevel@tonic-gate 19997c478bd9Sstevel@tonic-gate _vdap = vdap = (Verdaux *)(vdf + 1); 20007c478bd9Sstevel@tonic-gate 20017c478bd9Sstevel@tonic-gate vdf->vd_version = VER_DEF_CURRENT; 20027c478bd9Sstevel@tonic-gate vdf->vd_flags = vdp->vd_flags & MSK_VER_USER; 20037c478bd9Sstevel@tonic-gate vdf->vd_ndx = vdp->vd_ndx; 20047c478bd9Sstevel@tonic-gate vdf->vd_hash = vdp->vd_hash; 20057c478bd9Sstevel@tonic-gate 20067c478bd9Sstevel@tonic-gate /* LINTED */ 20077c478bd9Sstevel@tonic-gate vdap->vda_name = (uintptr_t)vdp->vd_name; 20087c478bd9Sstevel@tonic-gate vdap++; 20097c478bd9Sstevel@tonic-gate /* LINTED */ 20107c478bd9Sstevel@tonic-gate _vdap->vda_next = (Word)((uintptr_t)vdap - (uintptr_t)_vdap); 20117c478bd9Sstevel@tonic-gate 20127c478bd9Sstevel@tonic-gate /* 20137c478bd9Sstevel@tonic-gate * Traverse this versions dependency list generating the 20147c478bd9Sstevel@tonic-gate * appropriate version dependency entries. 20157c478bd9Sstevel@tonic-gate */ 20167c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&vdp->vd_deps, lnp2, _vdp)) { 20177c478bd9Sstevel@tonic-gate /* LINTED */ 20187c478bd9Sstevel@tonic-gate vdap->vda_name = (uintptr_t)_vdp->vd_name; 20197c478bd9Sstevel@tonic-gate _vdap = vdap; 20207c478bd9Sstevel@tonic-gate vdap++, cnt++; 20217c478bd9Sstevel@tonic-gate /* LINTED */ 20227c478bd9Sstevel@tonic-gate _vdap->vda_next = (Word)((uintptr_t)vdap - 20237c478bd9Sstevel@tonic-gate (uintptr_t)_vdap); 20247c478bd9Sstevel@tonic-gate } 20257c478bd9Sstevel@tonic-gate _vdap->vda_next = 0; 20267c478bd9Sstevel@tonic-gate 20277c478bd9Sstevel@tonic-gate /* 20287c478bd9Sstevel@tonic-gate * Record the versions auxiliary array offset and the associated 20297c478bd9Sstevel@tonic-gate * dependency count. 20307c478bd9Sstevel@tonic-gate */ 20317c478bd9Sstevel@tonic-gate /* LINTED */ 20327c478bd9Sstevel@tonic-gate vdf->vd_aux = (Word)((uintptr_t)(vdf + 1) - (uintptr_t)vdf); 20337c478bd9Sstevel@tonic-gate vdf->vd_cnt = cnt; 20347c478bd9Sstevel@tonic-gate 20357c478bd9Sstevel@tonic-gate /* 20367c478bd9Sstevel@tonic-gate * Record the next versions offset and update the version 20377c478bd9Sstevel@tonic-gate * pointer. Remember the previous version offset as the very 20387c478bd9Sstevel@tonic-gate * last structures next pointer should be null. 20397c478bd9Sstevel@tonic-gate */ 20407c478bd9Sstevel@tonic-gate _vdf = vdf; 20417c478bd9Sstevel@tonic-gate vdf = (Verdef *)vdap, num++; 20427c478bd9Sstevel@tonic-gate /* LINTED */ 20437c478bd9Sstevel@tonic-gate _vdf->vd_next = (Word)((uintptr_t)vdf - (uintptr_t)_vdf); 20447c478bd9Sstevel@tonic-gate } 20457c478bd9Sstevel@tonic-gate _vdf->vd_next = 0; 20467c478bd9Sstevel@tonic-gate 20477c478bd9Sstevel@tonic-gate /* 20487c478bd9Sstevel@tonic-gate * Record the string table association with the version definition 20497c478bd9Sstevel@tonic-gate * section, and the symbol table associated with the version symbol 20507c478bd9Sstevel@tonic-gate * table (the actual contents of the version symbol table are filled 20517c478bd9Sstevel@tonic-gate * in during symbol update). 20527c478bd9Sstevel@tonic-gate */ 20537c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_RELOBJ) || 20547c478bd9Sstevel@tonic-gate (ofl->ofl_flags & FLG_OF_STATIC)) { 20557c478bd9Sstevel@tonic-gate strosp = ofl->ofl_osstrtab; 20567c478bd9Sstevel@tonic-gate symosp = ofl->ofl_ossymtab; 20577c478bd9Sstevel@tonic-gate } else { 20587c478bd9Sstevel@tonic-gate strosp = ofl->ofl_osdynstr; 20597c478bd9Sstevel@tonic-gate symosp = ofl->ofl_osdynsym; 20607c478bd9Sstevel@tonic-gate } 20617c478bd9Sstevel@tonic-gate /* LINTED */ 20627c478bd9Sstevel@tonic-gate ofl->ofl_osverdef->os_shdr->sh_link = (Word)elf_ndxscn(strosp->os_scn); 20637c478bd9Sstevel@tonic-gate /* LINTED */ 20647c478bd9Sstevel@tonic-gate ofl->ofl_osversym->os_shdr->sh_link = (Word)elf_ndxscn(symosp->os_scn); 20657c478bd9Sstevel@tonic-gate 20667c478bd9Sstevel@tonic-gate /* 20677c478bd9Sstevel@tonic-gate * The version definition sections `info' field is used to indicate the 20687c478bd9Sstevel@tonic-gate * number of entries in this section. 20697c478bd9Sstevel@tonic-gate */ 20707c478bd9Sstevel@tonic-gate ofl->ofl_osverdef->os_shdr->sh_info = num; 20717c478bd9Sstevel@tonic-gate 20727c478bd9Sstevel@tonic-gate return (1); 20737c478bd9Sstevel@tonic-gate } 20747c478bd9Sstevel@tonic-gate 20757c478bd9Sstevel@tonic-gate /* 20767c478bd9Sstevel@tonic-gate * Build the version needed section 20777c478bd9Sstevel@tonic-gate */ 20785aefb655Srie static int 20797c478bd9Sstevel@tonic-gate update_overneed(Ofl_desc *ofl) 20807c478bd9Sstevel@tonic-gate { 20817c478bd9Sstevel@tonic-gate Listnode *lnp; 20827c478bd9Sstevel@tonic-gate Ifl_desc *ifl; 20837c478bd9Sstevel@tonic-gate Verneed *vnd, *_vnd; 20847c478bd9Sstevel@tonic-gate Str_tbl *dynstr; 20857c478bd9Sstevel@tonic-gate Word num = 0, cnt = 0; 20867c478bd9Sstevel@tonic-gate 20877c478bd9Sstevel@tonic-gate dynstr = ofl->ofl_dynstrtab; 20887c478bd9Sstevel@tonic-gate _vnd = vnd = (Verneed *)ofl->ofl_osverneed->os_outdata->d_buf; 20897c478bd9Sstevel@tonic-gate 20907c478bd9Sstevel@tonic-gate /* 20917c478bd9Sstevel@tonic-gate * Traverse the shared object list looking for dependencies that have 20927c478bd9Sstevel@tonic-gate * versions defined within them. 20937c478bd9Sstevel@tonic-gate */ 20947c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_sos, lnp, ifl)) { 20957c478bd9Sstevel@tonic-gate Half _cnt; 20967c478bd9Sstevel@tonic-gate Vernaux *_vnap, *vnap; 20977c478bd9Sstevel@tonic-gate Sdf_desc *sdf = ifl->ifl_sdfdesc; 20987c478bd9Sstevel@tonic-gate uint_t stoff; 20997c478bd9Sstevel@tonic-gate 21007c478bd9Sstevel@tonic-gate if (!(ifl->ifl_flags & FLG_IF_VERNEED)) 21017c478bd9Sstevel@tonic-gate continue; 21027c478bd9Sstevel@tonic-gate 21037c478bd9Sstevel@tonic-gate vnd->vn_version = VER_NEED_CURRENT; 21047c478bd9Sstevel@tonic-gate 21057c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, ifl->ifl_soname, &stoff); 21067c478bd9Sstevel@tonic-gate vnd->vn_file = stoff; 21077c478bd9Sstevel@tonic-gate 21087c478bd9Sstevel@tonic-gate _vnap = vnap = (Vernaux *)(vnd + 1); 21097c478bd9Sstevel@tonic-gate 21107c478bd9Sstevel@tonic-gate if (sdf && (sdf->sdf_flags & FLG_SDF_SPECVER)) { 21117c478bd9Sstevel@tonic-gate Sdv_desc * sdv; 21127c478bd9Sstevel@tonic-gate Listnode * lnp2; 21137c478bd9Sstevel@tonic-gate 21147c478bd9Sstevel@tonic-gate /* 21157c478bd9Sstevel@tonic-gate * If version needed definitions were specified in 21167c478bd9Sstevel@tonic-gate * a mapfile ($VERSION=*) then record those 21177c478bd9Sstevel@tonic-gate * definitions. 21187c478bd9Sstevel@tonic-gate */ 21197c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&sdf->sdf_verneed, lnp2, sdv)) { 21207c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, 21217c478bd9Sstevel@tonic-gate sdv->sdv_name, &stoff); 21227c478bd9Sstevel@tonic-gate vnap->vna_name = stoff; 21237c478bd9Sstevel@tonic-gate /* LINTED */ 21247c478bd9Sstevel@tonic-gate vnap->vna_hash = (Word)elf_hash(sdv->sdv_name); 21257c478bd9Sstevel@tonic-gate vnap->vna_flags = 0; 21267c478bd9Sstevel@tonic-gate vnap->vna_other = 0; 21277c478bd9Sstevel@tonic-gate _vnap = vnap; 21287c478bd9Sstevel@tonic-gate vnap++; 21297c478bd9Sstevel@tonic-gate cnt++; 21307c478bd9Sstevel@tonic-gate /* LINTED */ 21317c478bd9Sstevel@tonic-gate _vnap->vna_next = (Word)((uintptr_t)vnap - 21327c478bd9Sstevel@tonic-gate (uintptr_t)_vnap); 21337c478bd9Sstevel@tonic-gate } 21347c478bd9Sstevel@tonic-gate } else { 21357c478bd9Sstevel@tonic-gate 21367c478bd9Sstevel@tonic-gate /* 21377c478bd9Sstevel@tonic-gate * Traverse the version index list recording 21387c478bd9Sstevel@tonic-gate * each version as a needed dependency. 21397c478bd9Sstevel@tonic-gate */ 21407c478bd9Sstevel@tonic-gate for (cnt = _cnt = 0; _cnt <= ifl->ifl_vercnt; 21417c478bd9Sstevel@tonic-gate _cnt++) { 21427c478bd9Sstevel@tonic-gate Ver_index * vip = &ifl->ifl_verndx[_cnt]; 21437c478bd9Sstevel@tonic-gate 21447c478bd9Sstevel@tonic-gate if (vip->vi_flags & FLG_VER_REFER) { 21457c478bd9Sstevel@tonic-gate (void) st_setstring(dynstr, 21467c478bd9Sstevel@tonic-gate vip->vi_name, &stoff); 21477c478bd9Sstevel@tonic-gate vnap->vna_name = stoff; 21487c478bd9Sstevel@tonic-gate if (vip->vi_desc) { 21497c478bd9Sstevel@tonic-gate vnap->vna_hash = 21507c478bd9Sstevel@tonic-gate vip->vi_desc->vd_hash; 21517c478bd9Sstevel@tonic-gate vnap->vna_flags = 21527c478bd9Sstevel@tonic-gate vip->vi_desc->vd_flags; 21537c478bd9Sstevel@tonic-gate } else { 21547c478bd9Sstevel@tonic-gate vnap->vna_hash = 0; 21557c478bd9Sstevel@tonic-gate vnap->vna_flags = 0; 21567c478bd9Sstevel@tonic-gate } 21577c478bd9Sstevel@tonic-gate vnap->vna_other = 0; 21587c478bd9Sstevel@tonic-gate 21597c478bd9Sstevel@tonic-gate _vnap = vnap; 21607c478bd9Sstevel@tonic-gate vnap++, cnt++; 21617c478bd9Sstevel@tonic-gate _vnap->vna_next = 21627c478bd9Sstevel@tonic-gate /* LINTED */ 21637c478bd9Sstevel@tonic-gate (Word)((uintptr_t)vnap - 21647c478bd9Sstevel@tonic-gate (uintptr_t)_vnap); 21657c478bd9Sstevel@tonic-gate } 21667c478bd9Sstevel@tonic-gate } 21677c478bd9Sstevel@tonic-gate } 21687c478bd9Sstevel@tonic-gate _vnap->vna_next = 0; 21697c478bd9Sstevel@tonic-gate 21707c478bd9Sstevel@tonic-gate /* 21717c478bd9Sstevel@tonic-gate * Record the versions auxiliary array offset and 21727c478bd9Sstevel@tonic-gate * the associated dependency count. 21737c478bd9Sstevel@tonic-gate */ 21747c478bd9Sstevel@tonic-gate /* LINTED */ 21757c478bd9Sstevel@tonic-gate vnd->vn_aux = (Word)((uintptr_t)(vnd + 1) - (uintptr_t)vnd); 21767c478bd9Sstevel@tonic-gate /* LINTED */ 21777c478bd9Sstevel@tonic-gate vnd->vn_cnt = (Half)cnt; 21787c478bd9Sstevel@tonic-gate 21797c478bd9Sstevel@tonic-gate /* 21807c478bd9Sstevel@tonic-gate * Record the next versions offset and update the version 21817c478bd9Sstevel@tonic-gate * pointer. Remember the previous version offset as the very 21827c478bd9Sstevel@tonic-gate * last structures next pointer should be null. 21837c478bd9Sstevel@tonic-gate */ 21847c478bd9Sstevel@tonic-gate _vnd = vnd; 21857c478bd9Sstevel@tonic-gate vnd = (Verneed *)vnap, num++; 21867c478bd9Sstevel@tonic-gate /* LINTED */ 21877c478bd9Sstevel@tonic-gate _vnd->vn_next = (Word)((uintptr_t)vnd - (uintptr_t)_vnd); 21887c478bd9Sstevel@tonic-gate } 21897c478bd9Sstevel@tonic-gate _vnd->vn_next = 0; 21907c478bd9Sstevel@tonic-gate 21917c478bd9Sstevel@tonic-gate /* 21927c478bd9Sstevel@tonic-gate * Record association on string table section and use the 21937c478bd9Sstevel@tonic-gate * `info' field to indicate the number of entries in this 21947c478bd9Sstevel@tonic-gate * section. 21957c478bd9Sstevel@tonic-gate */ 21967c478bd9Sstevel@tonic-gate ofl->ofl_osverneed->os_shdr->sh_link = 21977c478bd9Sstevel@tonic-gate /* LINTED */ 21987c478bd9Sstevel@tonic-gate (Word)elf_ndxscn(ofl->ofl_osdynstr->os_scn); 21997c478bd9Sstevel@tonic-gate ofl->ofl_osverneed->os_shdr->sh_info = num; 22007c478bd9Sstevel@tonic-gate 22017c478bd9Sstevel@tonic-gate return (1); 22027c478bd9Sstevel@tonic-gate } 22037c478bd9Sstevel@tonic-gate 22047c478bd9Sstevel@tonic-gate 22057c478bd9Sstevel@tonic-gate /* 22067c478bd9Sstevel@tonic-gate * Update syminfo section. 22077c478bd9Sstevel@tonic-gate */ 22085aefb655Srie static uintptr_t 22097c478bd9Sstevel@tonic-gate update_osyminfo(Ofl_desc * ofl) 22107c478bd9Sstevel@tonic-gate { 22117c478bd9Sstevel@tonic-gate Os_desc * symosp, * infosp = ofl->ofl_ossyminfo; 22127c478bd9Sstevel@tonic-gate Syminfo * sip = infosp->os_outdata->d_buf; 22137c478bd9Sstevel@tonic-gate Shdr * shdr = infosp->os_shdr; 22147c478bd9Sstevel@tonic-gate char *strtab; 22157c478bd9Sstevel@tonic-gate Listnode * lnp; 22167c478bd9Sstevel@tonic-gate Sym_desc * sdp; 22177c478bd9Sstevel@tonic-gate Aliste off; 22187c478bd9Sstevel@tonic-gate Sfltr_desc * sftp; 22197c478bd9Sstevel@tonic-gate 22207c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_RELOBJ) { 22217c478bd9Sstevel@tonic-gate symosp = ofl->ofl_ossymtab; 22227c478bd9Sstevel@tonic-gate strtab = ofl->ofl_osstrtab->os_outdata->d_buf; 22237c478bd9Sstevel@tonic-gate } else { 22247c478bd9Sstevel@tonic-gate symosp = ofl->ofl_osdynsym; 22257c478bd9Sstevel@tonic-gate strtab = ofl->ofl_osdynstr->os_outdata->d_buf; 22267c478bd9Sstevel@tonic-gate } 22277c478bd9Sstevel@tonic-gate 22287c478bd9Sstevel@tonic-gate /* LINTED */ 22297c478bd9Sstevel@tonic-gate infosp->os_shdr->sh_link = (Word)elf_ndxscn(symosp->os_scn); 22307c478bd9Sstevel@tonic-gate if (ofl->ofl_osdynamic) 22317c478bd9Sstevel@tonic-gate infosp->os_shdr->sh_info = 22327c478bd9Sstevel@tonic-gate /* LINTED */ 22337c478bd9Sstevel@tonic-gate (Word)elf_ndxscn(ofl->ofl_osdynamic->os_scn); 22347c478bd9Sstevel@tonic-gate 22357c478bd9Sstevel@tonic-gate /* 22367c478bd9Sstevel@tonic-gate * Update any references with the index into the dynamic table. 22377c478bd9Sstevel@tonic-gate */ 22387c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_syminfsyms, lnp, sdp)) { 22397c478bd9Sstevel@tonic-gate Ifl_desc * ifl; 22407c478bd9Sstevel@tonic-gate if (sdp->sd_aux && sdp->sd_aux->sa_bindto) 22417c478bd9Sstevel@tonic-gate ifl = sdp->sd_aux->sa_bindto; 22427c478bd9Sstevel@tonic-gate else 22437c478bd9Sstevel@tonic-gate ifl = sdp->sd_file; 22447c478bd9Sstevel@tonic-gate sip[sdp->sd_symndx].si_boundto = ifl->ifl_neededndx; 22457c478bd9Sstevel@tonic-gate } 22467c478bd9Sstevel@tonic-gate 22477c478bd9Sstevel@tonic-gate /* 22487c478bd9Sstevel@tonic-gate * Update any filtee references with the index into the dynamic table. 22497c478bd9Sstevel@tonic-gate */ 22507c478bd9Sstevel@tonic-gate for (ALIST_TRAVERSE(ofl->ofl_symfltrs, off, sftp)) { 22517c478bd9Sstevel@tonic-gate Dfltr_desc * dftp; 22527c478bd9Sstevel@tonic-gate 22537c478bd9Sstevel@tonic-gate /* LINTED */ 22547c478bd9Sstevel@tonic-gate dftp = (Dfltr_desc *)((char *)ofl->ofl_dtsfltrs + 22557c478bd9Sstevel@tonic-gate sftp->sft_off); 22567c478bd9Sstevel@tonic-gate sip[sftp->sft_sdp->sd_symndx].si_boundto = dftp->dft_ndx; 22577c478bd9Sstevel@tonic-gate } 22587c478bd9Sstevel@tonic-gate 22597c478bd9Sstevel@tonic-gate /* 22607c478bd9Sstevel@tonic-gate * Display debugging information about section. 22617c478bd9Sstevel@tonic-gate */ 22625aefb655Srie DBG_CALL(Dbg_syminfo_title(ofl->ofl_lml)); 22635aefb655Srie if (DBG_ENABLED) { 22645aefb655Srie Word _cnt, cnt = shdr->sh_size / shdr->sh_entsize; 22657c478bd9Sstevel@tonic-gate Sym * symtab = symosp->os_outdata->d_buf; 22667c478bd9Sstevel@tonic-gate Dyn * dyn; 22677c478bd9Sstevel@tonic-gate 22687c478bd9Sstevel@tonic-gate if (ofl->ofl_osdynamic) 22697c478bd9Sstevel@tonic-gate dyn = ofl->ofl_osdynamic->os_outdata->d_buf; 22707c478bd9Sstevel@tonic-gate else 22717c478bd9Sstevel@tonic-gate dyn = 0; 22727c478bd9Sstevel@tonic-gate 22737c478bd9Sstevel@tonic-gate for (_cnt = 1; _cnt < cnt; _cnt++) { 22747c478bd9Sstevel@tonic-gate if (sip[_cnt].si_flags || sip[_cnt].si_boundto) 22757c478bd9Sstevel@tonic-gate /* LINTED */ 22765aefb655Srie DBG_CALL(Dbg_syminfo_entry(ofl->ofl_lml, _cnt, 22777c478bd9Sstevel@tonic-gate &sip[_cnt], &symtab[_cnt], strtab, dyn)); 22787c478bd9Sstevel@tonic-gate } 22797c478bd9Sstevel@tonic-gate } 22807c478bd9Sstevel@tonic-gate return (1); 22817c478bd9Sstevel@tonic-gate } 22827c478bd9Sstevel@tonic-gate 22837c478bd9Sstevel@tonic-gate /* 22847c478bd9Sstevel@tonic-gate * Build the output elf header. 22857c478bd9Sstevel@tonic-gate */ 22865aefb655Srie static uintptr_t 22877c478bd9Sstevel@tonic-gate update_oehdr(Ofl_desc * ofl) 22887c478bd9Sstevel@tonic-gate { 22895aefb655Srie Ehdr *ehdr = ofl->ofl_nehdr; 22907c478bd9Sstevel@tonic-gate 22917c478bd9Sstevel@tonic-gate /* 22927c478bd9Sstevel@tonic-gate * If an entry point symbol has already been established (refer 22937c478bd9Sstevel@tonic-gate * sym_validate()) simply update the elf header entry point with the 22947c478bd9Sstevel@tonic-gate * symbols value. If no entry point is defined it will have been filled 22957c478bd9Sstevel@tonic-gate * with the start address of the first section within the text segment 22967c478bd9Sstevel@tonic-gate * (refer update_outfile()). 22977c478bd9Sstevel@tonic-gate */ 22987c478bd9Sstevel@tonic-gate if (ofl->ofl_entry) 22997c478bd9Sstevel@tonic-gate ehdr->e_entry = 23007c478bd9Sstevel@tonic-gate ((Sym_desc *)(ofl->ofl_entry))->sd_sym->st_value; 23017c478bd9Sstevel@tonic-gate 23027c478bd9Sstevel@tonic-gate /* 23037c478bd9Sstevel@tonic-gate * Note. it may be necessary to update the `e_flags' field in the 23047c478bd9Sstevel@tonic-gate * machine dependent section. 23057c478bd9Sstevel@tonic-gate */ 23067c478bd9Sstevel@tonic-gate ehdr->e_ident[EI_DATA] = M_DATA; 23075aefb655Srie ehdr->e_machine = ofl->ofl_dehdr->e_machine; 23085aefb655Srie ehdr->e_flags = ofl->ofl_dehdr->e_flags; 23095aefb655Srie ehdr->e_version = ofl->ofl_dehdr->e_version; 23105aefb655Srie 23115aefb655Srie if (ehdr->e_machine != M_MACH) { 23125aefb655Srie if (ehdr->e_machine != M_MACHPLUS) 23137c478bd9Sstevel@tonic-gate return (S_ERROR); 23145aefb655Srie if ((ehdr->e_flags & M_FLAGSPLUS) == 0) 23157c478bd9Sstevel@tonic-gate return (S_ERROR); 23167c478bd9Sstevel@tonic-gate } 23177c478bd9Sstevel@tonic-gate 23187c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_SHAROBJ) 23197c478bd9Sstevel@tonic-gate ehdr->e_type = ET_DYN; 23207c478bd9Sstevel@tonic-gate else if (ofl->ofl_flags & FLG_OF_RELOBJ) 23217c478bd9Sstevel@tonic-gate ehdr->e_type = ET_REL; 23227c478bd9Sstevel@tonic-gate else 23237c478bd9Sstevel@tonic-gate ehdr->e_type = ET_EXEC; 23247c478bd9Sstevel@tonic-gate 23257c478bd9Sstevel@tonic-gate return (1); 23267c478bd9Sstevel@tonic-gate } 23277c478bd9Sstevel@tonic-gate 23287c478bd9Sstevel@tonic-gate /* 23297c478bd9Sstevel@tonic-gate * Perform move table expansion. 23307c478bd9Sstevel@tonic-gate */ 23317c478bd9Sstevel@tonic-gate static uintptr_t 23327c478bd9Sstevel@tonic-gate expand_move(Ofl_desc *ofl, Sym_desc *sdp, Move *u1) 23337c478bd9Sstevel@tonic-gate { 23347c478bd9Sstevel@tonic-gate Move *mv; 23357c478bd9Sstevel@tonic-gate Os_desc *osp; 23367c478bd9Sstevel@tonic-gate unsigned char *taddr, *taddr0; 23377c478bd9Sstevel@tonic-gate Sxword offset; 23387c478bd9Sstevel@tonic-gate int i; 23397c478bd9Sstevel@tonic-gate Addr base1; 23407c478bd9Sstevel@tonic-gate unsigned int stride; 23417c478bd9Sstevel@tonic-gate 23427c478bd9Sstevel@tonic-gate osp = ofl->ofl_issunwdata1->is_osdesc; 23437c478bd9Sstevel@tonic-gate base1 = (Addr)(osp->os_shdr->sh_addr + 23447c478bd9Sstevel@tonic-gate ofl->ofl_issunwdata1->is_indata->d_off); 23457c478bd9Sstevel@tonic-gate taddr0 = taddr = osp->os_outdata->d_buf; 23467c478bd9Sstevel@tonic-gate mv = u1; 23477c478bd9Sstevel@tonic-gate 23487c478bd9Sstevel@tonic-gate offset = sdp->sd_sym->st_value - base1; 23497c478bd9Sstevel@tonic-gate taddr += offset; 23507c478bd9Sstevel@tonic-gate taddr = taddr + mv->m_poffset; 23517c478bd9Sstevel@tonic-gate for (i = 0; i < mv->m_repeat; i++) { 23527c478bd9Sstevel@tonic-gate /* LINTED */ 23535aefb655Srie DBG_CALL(Dbg_move_expand(ofl->ofl_lml, mv, 23545aefb655Srie (Addr)(taddr - taddr0))); 23557c478bd9Sstevel@tonic-gate stride = (unsigned int)mv->m_stride + 1; 23567c478bd9Sstevel@tonic-gate /* LINTED */ 23577c478bd9Sstevel@tonic-gate switch (ELF_M_SIZE(mv->m_info)) { 23587c478bd9Sstevel@tonic-gate case 1: 23597c478bd9Sstevel@tonic-gate /* LINTED */ 23607c478bd9Sstevel@tonic-gate *taddr = (unsigned char)mv->m_value; 23617c478bd9Sstevel@tonic-gate taddr += stride; 23627c478bd9Sstevel@tonic-gate break; 23637c478bd9Sstevel@tonic-gate case 2: 23647c478bd9Sstevel@tonic-gate /* LINTED */ 23657c478bd9Sstevel@tonic-gate *((Half *)taddr) = (Half)mv->m_value; 23667c478bd9Sstevel@tonic-gate taddr += 2*stride; 23677c478bd9Sstevel@tonic-gate break; 23687c478bd9Sstevel@tonic-gate case 4: 23697c478bd9Sstevel@tonic-gate /* LINTED */ 23707c478bd9Sstevel@tonic-gate *((Word *)taddr) = (Word)mv->m_value; 23717c478bd9Sstevel@tonic-gate taddr += 4*stride; 23727c478bd9Sstevel@tonic-gate break; 23737c478bd9Sstevel@tonic-gate case 8: 23747c478bd9Sstevel@tonic-gate /* LINTED */ 23757c478bd9Sstevel@tonic-gate *((unsigned long long *)taddr) = 23767c478bd9Sstevel@tonic-gate mv->m_value; 23777c478bd9Sstevel@tonic-gate taddr += 8*stride; 23787c478bd9Sstevel@tonic-gate break; 23797c478bd9Sstevel@tonic-gate default: 23807c478bd9Sstevel@tonic-gate /* 23817c478bd9Sstevel@tonic-gate * Should never come here since this is already 23827c478bd9Sstevel@tonic-gate * checked at sunwmove_preprocess(). 23837c478bd9Sstevel@tonic-gate */ 23847c478bd9Sstevel@tonic-gate return (S_ERROR); 23857c478bd9Sstevel@tonic-gate } 23867c478bd9Sstevel@tonic-gate } 23877c478bd9Sstevel@tonic-gate return (1); 23887c478bd9Sstevel@tonic-gate } 23897c478bd9Sstevel@tonic-gate 23907c478bd9Sstevel@tonic-gate /* 23917c478bd9Sstevel@tonic-gate * Update Move sections. 23927c478bd9Sstevel@tonic-gate */ 23935aefb655Srie static uintptr_t 23947c478bd9Sstevel@tonic-gate update_move(Ofl_desc *ofl) 23957c478bd9Sstevel@tonic-gate { 23967c478bd9Sstevel@tonic-gate Word ndx = 0; 23977c478bd9Sstevel@tonic-gate Is_desc * isp; 23987c478bd9Sstevel@tonic-gate Word flags = ofl->ofl_flags; 23997c478bd9Sstevel@tonic-gate Move * mv1, * mv2; 24007c478bd9Sstevel@tonic-gate Listnode * lnp1; 24017c478bd9Sstevel@tonic-gate Psym_info * psym; 24027c478bd9Sstevel@tonic-gate 24037c478bd9Sstevel@tonic-gate /* 24047c478bd9Sstevel@tonic-gate * Determine the index of the symbol table that will be referenced by 24057c478bd9Sstevel@tonic-gate * the relocation entries. 24067c478bd9Sstevel@tonic-gate */ 24077c478bd9Sstevel@tonic-gate if ((flags & (FLG_OF_DYNAMIC|FLG_OF_RELOBJ)) == FLG_OF_DYNAMIC) 24087c478bd9Sstevel@tonic-gate /* LINTED */ 24097c478bd9Sstevel@tonic-gate ndx = (Word) elf_ndxscn(ofl->ofl_osdynsym->os_scn); 24107c478bd9Sstevel@tonic-gate else if (!(flags & FLG_OF_STRIP) || (flags & FLG_OF_RELOBJ)) 24117c478bd9Sstevel@tonic-gate /* LINTED */ 24127c478bd9Sstevel@tonic-gate ndx = (Word) elf_ndxscn(ofl->ofl_ossymtab->os_scn); 24137c478bd9Sstevel@tonic-gate 24147c478bd9Sstevel@tonic-gate /* 24157c478bd9Sstevel@tonic-gate * update sh_link and mv pointer for updating move table. 24167c478bd9Sstevel@tonic-gate */ 24177c478bd9Sstevel@tonic-gate if (ofl->ofl_osmove) { 24187c478bd9Sstevel@tonic-gate ofl->ofl_osmove->os_shdr->sh_link = ndx; 24197c478bd9Sstevel@tonic-gate mv1 = (Move *) ofl->ofl_osmove->os_outdata->d_buf; 24207c478bd9Sstevel@tonic-gate } 24217c478bd9Sstevel@tonic-gate 24227c478bd9Sstevel@tonic-gate /* 24237c478bd9Sstevel@tonic-gate * Update symbol entry index 24247c478bd9Sstevel@tonic-gate */ 24257c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_parsym, lnp1, psym)) { 24267c478bd9Sstevel@tonic-gate Listnode * lnp2; 24277c478bd9Sstevel@tonic-gate Mv_itm * mvp; 24287c478bd9Sstevel@tonic-gate Sym_desc *sdp; 24297c478bd9Sstevel@tonic-gate 24307c478bd9Sstevel@tonic-gate /* 24317c478bd9Sstevel@tonic-gate * Expand move table 24327c478bd9Sstevel@tonic-gate */ 24337c478bd9Sstevel@tonic-gate if (psym->psym_symd->sd_flags & FLG_SY_PAREXPN) { 24347c478bd9Sstevel@tonic-gate const char *s; 24357c478bd9Sstevel@tonic-gate 24367c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_STATIC) 24377c478bd9Sstevel@tonic-gate s = MSG_INTL(MSG_PSYM_EXPREASON1); 24387c478bd9Sstevel@tonic-gate else if (ofl->ofl_flags1 & FLG_OF1_NOPARTI) 24397c478bd9Sstevel@tonic-gate s = MSG_INTL(MSG_PSYM_EXPREASON2); 24407c478bd9Sstevel@tonic-gate else 24417c478bd9Sstevel@tonic-gate s = MSG_INTL(MSG_PSYM_EXPREASON3); 24425aefb655Srie DBG_CALL(Dbg_move_parexpn(ofl->ofl_lml, 24435aefb655Srie psym->psym_symd->sd_name, s)); 24447c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&(psym->psym_mvs), lnp2, mvp)) { 24457c478bd9Sstevel@tonic-gate if ((mvp->mv_flag & FLG_MV_OUTSECT) == 0) 24467c478bd9Sstevel@tonic-gate continue; 24477c478bd9Sstevel@tonic-gate mv2 = mvp->mv_ientry; 24487c478bd9Sstevel@tonic-gate sdp = psym->psym_symd; 24495aefb655Srie DBG_CALL(Dbg_move_entry1(ofl->ofl_lml, 0, 24505aefb655Srie mv2, sdp)); 24517c478bd9Sstevel@tonic-gate (void) expand_move(ofl, sdp, mv2); 24527c478bd9Sstevel@tonic-gate } 24537c478bd9Sstevel@tonic-gate continue; 24547c478bd9Sstevel@tonic-gate } 24557c478bd9Sstevel@tonic-gate 24567c478bd9Sstevel@tonic-gate /* 24577c478bd9Sstevel@tonic-gate * Process move table 24587c478bd9Sstevel@tonic-gate */ 24595aefb655Srie DBG_CALL(Dbg_move_outmove(ofl->ofl_lml, 24605aefb655Srie psym->psym_symd->sd_name)); 24617c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&(psym->psym_mvs), lnp2, mvp)) { 24627c478bd9Sstevel@tonic-gate int idx = 1; 24637c478bd9Sstevel@tonic-gate if ((mvp->mv_flag & FLG_MV_OUTSECT) == 0) 24647c478bd9Sstevel@tonic-gate continue; 24657c478bd9Sstevel@tonic-gate isp = mvp->mv_isp; 24667c478bd9Sstevel@tonic-gate mv2 = mvp->mv_ientry; 24677c478bd9Sstevel@tonic-gate sdp = isp->is_file->ifl_oldndx[ 24687c478bd9Sstevel@tonic-gate ELF_M_SYM(mv2->m_info)]; 24697c478bd9Sstevel@tonic-gate 24705aefb655Srie DBG_CALL(Dbg_move_entry1(ofl->ofl_lml, 0, mv2, sdp)); 24717c478bd9Sstevel@tonic-gate *mv1 = *mv2; 24727c478bd9Sstevel@tonic-gate if ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) { 24737c478bd9Sstevel@tonic-gate if (ELF_ST_BIND(sdp->sd_sym->st_info) == 24747c478bd9Sstevel@tonic-gate STB_LOCAL) { 24757c478bd9Sstevel@tonic-gate Half symbssndx = 24767c478bd9Sstevel@tonic-gate ofl->ofl_isbss->is_osdesc->os_scnsymndx; 24777c478bd9Sstevel@tonic-gate mv1->m_info = 24787c478bd9Sstevel@tonic-gate /* LINTED */ 24797c478bd9Sstevel@tonic-gate ELF_M_INFO(symbssndx, mv2->m_info); 24807c478bd9Sstevel@tonic-gate if (ELF_ST_TYPE(sdp->sd_sym->st_info) != 24817c478bd9Sstevel@tonic-gate STT_SECTION) { 24827c478bd9Sstevel@tonic-gate mv1->m_poffset = sdp->sd_sym->st_value - 24837c478bd9Sstevel@tonic-gate ofl->ofl_isbss-> 24847c478bd9Sstevel@tonic-gate is_osdesc->os_shdr->sh_addr + 24857c478bd9Sstevel@tonic-gate mv2->m_poffset; 24867c478bd9Sstevel@tonic-gate } 24877c478bd9Sstevel@tonic-gate } else { 24887c478bd9Sstevel@tonic-gate mv1->m_info = 24897c478bd9Sstevel@tonic-gate /* LINTED */ 24907c478bd9Sstevel@tonic-gate ELF_M_INFO(sdp->sd_symndx, mv2->m_info); 24917c478bd9Sstevel@tonic-gate } 24927c478bd9Sstevel@tonic-gate } else { 24937c478bd9Sstevel@tonic-gate Boolean isredloc = FALSE; 24947c478bd9Sstevel@tonic-gate 24957c478bd9Sstevel@tonic-gate if ((ELF_ST_BIND(sdp->sd_sym->st_info) == 24967c478bd9Sstevel@tonic-gate STB_LOCAL) && 24977c478bd9Sstevel@tonic-gate (ofl->ofl_flags1 & FLG_OF1_REDLSYM)) 24987c478bd9Sstevel@tonic-gate isredloc = TRUE; 24997c478bd9Sstevel@tonic-gate 25007c478bd9Sstevel@tonic-gate if (isredloc && !(sdp->sd_psyminfo)) { 25017c478bd9Sstevel@tonic-gate Word symndx = 25027c478bd9Sstevel@tonic-gate sdp->sd_isc->is_osdesc->os_scnsymndx; 25037c478bd9Sstevel@tonic-gate mv1->m_info = 25047c478bd9Sstevel@tonic-gate /* LINTED */ 25057c478bd9Sstevel@tonic-gate ELF_M_INFO(symndx, mv2->m_info); 25067c478bd9Sstevel@tonic-gate mv1->m_poffset += sdp->sd_sym->st_value; 25077c478bd9Sstevel@tonic-gate } else { 25087c478bd9Sstevel@tonic-gate if (isredloc) 25095aefb655Srie DBG_CALL(Dbg_syms_reduce(ofl, 25105aefb655Srie DBG_SYM_REDUCE_RETAIN, sdp, 25117c478bd9Sstevel@tonic-gate idx, ofl->ofl_osmove->os_name)); 25127c478bd9Sstevel@tonic-gate 25137c478bd9Sstevel@tonic-gate mv1->m_info = 25147c478bd9Sstevel@tonic-gate /* LINTED */ 25157c478bd9Sstevel@tonic-gate ELF_M_INFO(sdp->sd_symndx, mv2->m_info); 25167c478bd9Sstevel@tonic-gate } 25177c478bd9Sstevel@tonic-gate } 25185aefb655Srie DBG_CALL(Dbg_move_entry1(ofl->ofl_lml, 1, mv1, sdp)); 25197c478bd9Sstevel@tonic-gate mv1++; 25207c478bd9Sstevel@tonic-gate idx++; 25217c478bd9Sstevel@tonic-gate } 25227c478bd9Sstevel@tonic-gate } 25237c478bd9Sstevel@tonic-gate return (1); 25247c478bd9Sstevel@tonic-gate } 25257c478bd9Sstevel@tonic-gate 25267c478bd9Sstevel@tonic-gate 25277c478bd9Sstevel@tonic-gate /* 25287c478bd9Sstevel@tonic-gate * Scan through the SHT_GROUP output sections. Update their 25297c478bd9Sstevel@tonic-gate * sh_link/sh_info fields as well as the section contents. 25307c478bd9Sstevel@tonic-gate */ 25315aefb655Srie static uintptr_t 25327c478bd9Sstevel@tonic-gate update_ogroup(Ofl_desc * ofl) 25337c478bd9Sstevel@tonic-gate { 25347c478bd9Sstevel@tonic-gate Listnode *lnp; 25357c478bd9Sstevel@tonic-gate Os_desc *osp; 25367c478bd9Sstevel@tonic-gate uintptr_t error = 0; 25377c478bd9Sstevel@tonic-gate 25387c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_osgroups, lnp, osp)) { 25397c478bd9Sstevel@tonic-gate Is_desc *isp; 25407c478bd9Sstevel@tonic-gate Ifl_desc *ifl; 25417c478bd9Sstevel@tonic-gate Shdr *shdr = osp->os_shdr; 25427c478bd9Sstevel@tonic-gate Sym_desc *sdp; 25437c478bd9Sstevel@tonic-gate Xword i, grpcnt; 25447c478bd9Sstevel@tonic-gate Word *gdata; 25457c478bd9Sstevel@tonic-gate 25467c478bd9Sstevel@tonic-gate /* 25477c478bd9Sstevel@tonic-gate * Since input GROUP sections always create unique 25487c478bd9Sstevel@tonic-gate * output GROUP sections - we know there is only one 25497c478bd9Sstevel@tonic-gate * item on the list. 25507c478bd9Sstevel@tonic-gate */ 25517c478bd9Sstevel@tonic-gate isp = (Is_desc *)osp->os_isdescs.head->data; 25527c478bd9Sstevel@tonic-gate 25537c478bd9Sstevel@tonic-gate ifl = isp->is_file; 25547c478bd9Sstevel@tonic-gate sdp = ifl->ifl_oldndx[isp->is_shdr->sh_info]; 25557c478bd9Sstevel@tonic-gate shdr->sh_link = (Word)elf_ndxscn(ofl->ofl_ossymtab->os_scn); 25567c478bd9Sstevel@tonic-gate shdr->sh_info = sdp->sd_symndx; 25577c478bd9Sstevel@tonic-gate 25587c478bd9Sstevel@tonic-gate /* 25597c478bd9Sstevel@tonic-gate * Scan through the group data section and update 25607c478bd9Sstevel@tonic-gate * all of the links to new values. 25617c478bd9Sstevel@tonic-gate */ 25627c478bd9Sstevel@tonic-gate grpcnt = shdr->sh_size / shdr->sh_entsize; 25637c478bd9Sstevel@tonic-gate gdata = (Word *)osp->os_outdata->d_buf; 25647c478bd9Sstevel@tonic-gate for (i = 1; i < grpcnt; i++) { 25657c478bd9Sstevel@tonic-gate Is_desc * _isp; 25667c478bd9Sstevel@tonic-gate Os_desc * _osp; 25677c478bd9Sstevel@tonic-gate 25687c478bd9Sstevel@tonic-gate /* 25697c478bd9Sstevel@tonic-gate * Perform a sanity check that the section index 25707c478bd9Sstevel@tonic-gate * stored in the SHT_GROUP section is valid 25717c478bd9Sstevel@tonic-gate * for the file it came from. 25727c478bd9Sstevel@tonic-gate */ 25737c478bd9Sstevel@tonic-gate if (gdata[i] >= ifl->ifl_shnum) { 25745aefb655Srie eprintf(ofl->ofl_lml, ERR_FATAL, 25755aefb655Srie MSG_INTL(MSG_GRP_INVALNDX), isp->is_name, 25765aefb655Srie ifl->ifl_name, i, gdata[i]); 25777c478bd9Sstevel@tonic-gate error = S_ERROR; 25787c478bd9Sstevel@tonic-gate gdata[i] = 0; 25797c478bd9Sstevel@tonic-gate continue; 25807c478bd9Sstevel@tonic-gate } 25817c478bd9Sstevel@tonic-gate 25827c478bd9Sstevel@tonic-gate _isp = ifl->ifl_isdesc[gdata[i]]; 25837c478bd9Sstevel@tonic-gate 25847c478bd9Sstevel@tonic-gate /* 25857c478bd9Sstevel@tonic-gate * If the referenced section didn't make it to the 25867c478bd9Sstevel@tonic-gate * output file - just zero out the entry. 25877c478bd9Sstevel@tonic-gate */ 25887c478bd9Sstevel@tonic-gate if ((_osp = _isp->is_osdesc) == 0) 25897c478bd9Sstevel@tonic-gate gdata[i] = 0; 25907c478bd9Sstevel@tonic-gate else 25917c478bd9Sstevel@tonic-gate gdata[i] = (Word)elf_ndxscn(_osp->os_scn); 25927c478bd9Sstevel@tonic-gate } 25937c478bd9Sstevel@tonic-gate } 25947c478bd9Sstevel@tonic-gate return (error); 25957c478bd9Sstevel@tonic-gate } 25967c478bd9Sstevel@tonic-gate 25975aefb655Srie static void 25987c478bd9Sstevel@tonic-gate update_ostrtab(Os_desc *osp, Str_tbl *stp) 25997c478bd9Sstevel@tonic-gate { 26007c478bd9Sstevel@tonic-gate Elf_Data *data; 26017c478bd9Sstevel@tonic-gate if (osp == 0) 26027c478bd9Sstevel@tonic-gate return; 26037c478bd9Sstevel@tonic-gate 26047c478bd9Sstevel@tonic-gate data = osp->os_outdata; 26057c478bd9Sstevel@tonic-gate assert(data->d_size == st_getstrtab_sz(stp)); 26067c478bd9Sstevel@tonic-gate (void) st_setstrbuf(stp, data->d_buf, (uint_t)data->d_size); 26077c478bd9Sstevel@tonic-gate } 26087c478bd9Sstevel@tonic-gate 26097c478bd9Sstevel@tonic-gate /* 26107c478bd9Sstevel@tonic-gate * Translate the shdr->sh_{link, info} from its input section value to that 26117c478bd9Sstevel@tonic-gate * of the corresponding shdr->sh_{link, info} output section value. 26127c478bd9Sstevel@tonic-gate */ 26135aefb655Srie static Word 26145aefb655Srie translate_link(Ofl_desc *ofl, Os_desc *osp, Word link, const char *msg) 26157c478bd9Sstevel@tonic-gate { 26167c478bd9Sstevel@tonic-gate Is_desc * isp; 26177c478bd9Sstevel@tonic-gate Ifl_desc * ifl; 26187c478bd9Sstevel@tonic-gate 26197c478bd9Sstevel@tonic-gate /* 26207c478bd9Sstevel@tonic-gate * Don't translate the special section numbers. 26217c478bd9Sstevel@tonic-gate */ 26227c478bd9Sstevel@tonic-gate if (link >= SHN_LORESERVE) 26237c478bd9Sstevel@tonic-gate return (link); 26247c478bd9Sstevel@tonic-gate 26257c478bd9Sstevel@tonic-gate /* 26267c478bd9Sstevel@tonic-gate * Does this output section translate back to an input file. If not 26277c478bd9Sstevel@tonic-gate * then there is no translation to do. In this case we will assume that 26287c478bd9Sstevel@tonic-gate * if sh_link has a value, it's the right value. 26297c478bd9Sstevel@tonic-gate */ 26307c478bd9Sstevel@tonic-gate isp = (Is_desc *)osp->os_isdescs.head->data; 26317c478bd9Sstevel@tonic-gate if ((ifl = isp->is_file) == NULL) 26327c478bd9Sstevel@tonic-gate return (link); 26337c478bd9Sstevel@tonic-gate 26347c478bd9Sstevel@tonic-gate /* 26357c478bd9Sstevel@tonic-gate * Sanity check to make sure that the sh_{link, info} value 26367c478bd9Sstevel@tonic-gate * is within range for the input file. 26377c478bd9Sstevel@tonic-gate */ 26387c478bd9Sstevel@tonic-gate if (link >= ifl->ifl_shnum) { 26395aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, msg, ifl->ifl_name, 26407c478bd9Sstevel@tonic-gate isp->is_name, EC_XWORD(link)); 26417c478bd9Sstevel@tonic-gate return (link); 26427c478bd9Sstevel@tonic-gate } 26437c478bd9Sstevel@tonic-gate 26447c478bd9Sstevel@tonic-gate /* 26457c478bd9Sstevel@tonic-gate * Follow the link to the input section. 26467c478bd9Sstevel@tonic-gate */ 26477c478bd9Sstevel@tonic-gate if ((isp = ifl->ifl_isdesc[link]) == 0) 26487c478bd9Sstevel@tonic-gate return (0); 26497c478bd9Sstevel@tonic-gate if ((osp = isp->is_osdesc) == 0) 26507c478bd9Sstevel@tonic-gate return (0); 26517c478bd9Sstevel@tonic-gate 26527c478bd9Sstevel@tonic-gate /* LINTED */ 26537c478bd9Sstevel@tonic-gate return ((Word)elf_ndxscn(osp->os_scn)); 26547c478bd9Sstevel@tonic-gate } 26557c478bd9Sstevel@tonic-gate 26567c478bd9Sstevel@tonic-gate /* 26577c478bd9Sstevel@tonic-gate * Having created all of the necessary sections, segments, and associated 26587c478bd9Sstevel@tonic-gate * headers, fill in the program headers and update any other data in the 26597c478bd9Sstevel@tonic-gate * output image. Some general rules: 26607c478bd9Sstevel@tonic-gate * 26617c478bd9Sstevel@tonic-gate * o If an interpretor is required always generate a PT_PHDR entry as 26627c478bd9Sstevel@tonic-gate * well. It is this entry that triggers the kernel into passing the 26637c478bd9Sstevel@tonic-gate * interpretor an aux vector instead of just a file descriptor. 26647c478bd9Sstevel@tonic-gate * 26657c478bd9Sstevel@tonic-gate * o When generating an image that will be interpreted (ie. a dynamic 26667c478bd9Sstevel@tonic-gate * executable, a shared object, or a static executable that has been 26677c478bd9Sstevel@tonic-gate * provided with an interpretor - weird, but possible), make the initial 26687c478bd9Sstevel@tonic-gate * loadable segment include both the ehdr and phdr[]. Both of these 26697c478bd9Sstevel@tonic-gate * tables are used by the interpretor therefore it seems more intuitive 26707c478bd9Sstevel@tonic-gate * to explicitly defined them as part of the mapped image rather than 26717c478bd9Sstevel@tonic-gate * relying on page rounding by the interpretor to allow their access. 26727c478bd9Sstevel@tonic-gate * 26737c478bd9Sstevel@tonic-gate * o When generating a static image that does not require an interpretor 26747c478bd9Sstevel@tonic-gate * have the first loadable segment indicate the address of the first 26757c478bd9Sstevel@tonic-gate * .section as the start address (things like /kernel/unix and ufsboot 26767c478bd9Sstevel@tonic-gate * expect this behavior). 26777c478bd9Sstevel@tonic-gate */ 26787c478bd9Sstevel@tonic-gate uintptr_t 26795aefb655Srie ld_update_outfile(Ofl_desc *ofl) 26807c478bd9Sstevel@tonic-gate { 26817c478bd9Sstevel@tonic-gate Addr size, etext, vaddr = ofl->ofl_segorigin; 26827c478bd9Sstevel@tonic-gate Listnode *lnp1, *lnp2; 26837c478bd9Sstevel@tonic-gate Sg_desc *sgp; 2684*0bc07c75Srie Os_desc **ospp, *osp; 26857c478bd9Sstevel@tonic-gate int phdrndx = 0, capndx = 0, segndx = -1, secndx; 26865aefb655Srie Ehdr *ehdr = ofl->ofl_nehdr; 26877c478bd9Sstevel@tonic-gate Shdr *hshdr; 26887c478bd9Sstevel@tonic-gate Phdr *_phdr = 0, *dtracephdr = 0; 26897c478bd9Sstevel@tonic-gate Word phdrsz = ehdr->e_phnum *ehdr->e_phentsize, shscnndx; 26907c478bd9Sstevel@tonic-gate Word flags = ofl->ofl_flags, ehdrsz = ehdr->e_ehsize; 26917c478bd9Sstevel@tonic-gate Boolean nobits; 26927c478bd9Sstevel@tonic-gate Off offset; 2693*0bc07c75Srie Aliste off; 26947c478bd9Sstevel@tonic-gate 26957c478bd9Sstevel@tonic-gate /* 26967c478bd9Sstevel@tonic-gate * Loop through the segment descriptors and pick out what we need. 26977c478bd9Sstevel@tonic-gate */ 26985aefb655Srie DBG_CALL(Dbg_seg_title(ofl->ofl_lml)); 26997c478bd9Sstevel@tonic-gate for (LIST_TRAVERSE(&ofl->ofl_segs, lnp1, sgp)) { 27007c478bd9Sstevel@tonic-gate Phdr * phdr = &(sgp->sg_phdr); 27017c478bd9Sstevel@tonic-gate Xword p_align; 27027c478bd9Sstevel@tonic-gate 27037c478bd9Sstevel@tonic-gate segndx++; 27047c478bd9Sstevel@tonic-gate 27057c478bd9Sstevel@tonic-gate /* 27067c478bd9Sstevel@tonic-gate * If an interpreter is required generate a PT_INTERP and 27077c478bd9Sstevel@tonic-gate * PT_PHDR program header entry. The PT_PHDR entry describes 27087c478bd9Sstevel@tonic-gate * the program header table itself. This information will be 27097c478bd9Sstevel@tonic-gate * passed via the aux vector to the interpreter (ld.so.1). 27107c478bd9Sstevel@tonic-gate * The program header array is actually part of the first 27117c478bd9Sstevel@tonic-gate * loadable segment (and the PT_PHDR entry is the first entry), 27127c478bd9Sstevel@tonic-gate * therefore its virtual address isn't known until the first 27137c478bd9Sstevel@tonic-gate * loadable segment is processed. 27147c478bd9Sstevel@tonic-gate */ 27157c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_PHDR) { 27167c478bd9Sstevel@tonic-gate if (ofl->ofl_osinterp) { 27177c478bd9Sstevel@tonic-gate phdr->p_offset = ehdr->e_phoff; 27187c478bd9Sstevel@tonic-gate phdr->p_filesz = phdr->p_memsz = phdrsz; 27195aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 27207c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 27217c478bd9Sstevel@tonic-gate } 27227c478bd9Sstevel@tonic-gate continue; 27237c478bd9Sstevel@tonic-gate } 27247c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_INTERP) { 27257c478bd9Sstevel@tonic-gate if (ofl->ofl_osinterp) { 27267c478bd9Sstevel@tonic-gate Shdr * shdr = ofl->ofl_osinterp->os_shdr; 27277c478bd9Sstevel@tonic-gate 27287c478bd9Sstevel@tonic-gate phdr->p_vaddr = phdr->p_memsz = 0; 27297c478bd9Sstevel@tonic-gate phdr->p_offset = shdr->sh_offset; 27307c478bd9Sstevel@tonic-gate phdr->p_filesz = shdr->sh_size; 27315aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 27327c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 27337c478bd9Sstevel@tonic-gate } 27347c478bd9Sstevel@tonic-gate continue; 27357c478bd9Sstevel@tonic-gate } 27367c478bd9Sstevel@tonic-gate 27377c478bd9Sstevel@tonic-gate /* 27387c478bd9Sstevel@tonic-gate * If we are creating a PT_SUNWDTRACE segment, 27397c478bd9Sstevel@tonic-gate * just remember where the program header is. 27407c478bd9Sstevel@tonic-gate * 27417c478bd9Sstevel@tonic-gate * It's actual values will be assigned after 27427c478bd9Sstevel@tonic-gate * update_osym() has completed and the symbol 27437c478bd9Sstevel@tonic-gate * table addresses have been udpated. 27447c478bd9Sstevel@tonic-gate */ 27457c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_SUNWDTRACE) { 27467c478bd9Sstevel@tonic-gate if ((ofl->ofl_dtracesym) && 27477c478bd9Sstevel@tonic-gate ((flags & FLG_OF_RELOBJ) == 0)) { 27487c478bd9Sstevel@tonic-gate dtracephdr = &ofl->ofl_phdr[phdrndx]; 27497c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 27507c478bd9Sstevel@tonic-gate } 27517c478bd9Sstevel@tonic-gate continue; 27527c478bd9Sstevel@tonic-gate } 27537c478bd9Sstevel@tonic-gate 27547c478bd9Sstevel@tonic-gate /* 27557c478bd9Sstevel@tonic-gate * If a hardware/software capabilities section is required, 27567c478bd9Sstevel@tonic-gate * generate the PT_SUNWCAP header. Note, as this comes before 27577c478bd9Sstevel@tonic-gate * the first loadable segment, we don't yet know its real 27587c478bd9Sstevel@tonic-gate * virtual address. This is updated later. 27597c478bd9Sstevel@tonic-gate */ 27607c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_SUNWCAP) { 27617c478bd9Sstevel@tonic-gate if (ofl->ofl_oscap) { 27627c478bd9Sstevel@tonic-gate Shdr * shdr = ofl->ofl_oscap->os_shdr; 27637c478bd9Sstevel@tonic-gate 27647c478bd9Sstevel@tonic-gate phdr->p_vaddr = shdr->sh_addr; 27657c478bd9Sstevel@tonic-gate phdr->p_offset = shdr->sh_offset; 27667c478bd9Sstevel@tonic-gate phdr->p_filesz = shdr->sh_size; 27677c478bd9Sstevel@tonic-gate phdr->p_flags = PF_R; 27685aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 27697c478bd9Sstevel@tonic-gate capndx = phdrndx; 27707c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 27717c478bd9Sstevel@tonic-gate } 27727c478bd9Sstevel@tonic-gate continue; 27737c478bd9Sstevel@tonic-gate } 27747c478bd9Sstevel@tonic-gate 27757c478bd9Sstevel@tonic-gate /* 27767c478bd9Sstevel@tonic-gate * As the dynamic program header occurs after the loadable 27777c478bd9Sstevel@tonic-gate * headers in the segment descriptor table, all the address 27787c478bd9Sstevel@tonic-gate * information for the .dynamic output section will have been 27797c478bd9Sstevel@tonic-gate * figured out by now. 27807c478bd9Sstevel@tonic-gate */ 27817c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_DYNAMIC) { 27827c478bd9Sstevel@tonic-gate if ((flags & (FLG_OF_DYNAMIC | FLG_OF_RELOBJ)) == 27837c478bd9Sstevel@tonic-gate FLG_OF_DYNAMIC) { 27847c478bd9Sstevel@tonic-gate Shdr * shdr = ofl->ofl_osdynamic->os_shdr; 27857c478bd9Sstevel@tonic-gate 27867c478bd9Sstevel@tonic-gate phdr->p_vaddr = shdr->sh_addr; 27877c478bd9Sstevel@tonic-gate phdr->p_offset = shdr->sh_offset; 27887c478bd9Sstevel@tonic-gate phdr->p_filesz = shdr->sh_size; 27897c478bd9Sstevel@tonic-gate phdr->p_flags = M_DATASEG_PERM; 27905aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 27917c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 27927c478bd9Sstevel@tonic-gate } 27937c478bd9Sstevel@tonic-gate continue; 27947c478bd9Sstevel@tonic-gate } 27955aefb655Srie #if defined(__x86) && defined(_ELF64) 27967c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_SUNW_UNWIND) { 27977c478bd9Sstevel@tonic-gate Shdr *shdr; 27987c478bd9Sstevel@tonic-gate if (ofl->ofl_unwindhdr == 0) 27997c478bd9Sstevel@tonic-gate continue; 28007c478bd9Sstevel@tonic-gate shdr = ofl->ofl_unwindhdr->os_shdr; 28017c478bd9Sstevel@tonic-gate 28027c478bd9Sstevel@tonic-gate phdr->p_flags = PF_R; 28037c478bd9Sstevel@tonic-gate phdr->p_vaddr = shdr->sh_addr; 28047c478bd9Sstevel@tonic-gate phdr->p_memsz = shdr->sh_size; 28057c478bd9Sstevel@tonic-gate phdr->p_filesz = shdr->sh_size; 28067c478bd9Sstevel@tonic-gate phdr->p_offset = shdr->sh_offset; 28077c478bd9Sstevel@tonic-gate phdr->p_align = shdr->sh_addralign; 28087c478bd9Sstevel@tonic-gate phdr->p_paddr = 0; 28097c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 28107c478bd9Sstevel@tonic-gate continue; 28117c478bd9Sstevel@tonic-gate } 28127c478bd9Sstevel@tonic-gate #endif 28137c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_TLS) { 2814dd94ecefSrie Os_desc *tlsosp; 2815dd94ecefSrie Shdr *firstshdr = 0, *lastfilshdr, *lastmemshdr; 28167c478bd9Sstevel@tonic-gate 2817dd94ecefSrie if (ofl->ofl_ostlsseg.head == NULL) 28187c478bd9Sstevel@tonic-gate continue; 2819dd94ecefSrie 2820dd94ecefSrie for (LIST_TRAVERSE(&ofl->ofl_ostlsseg, lnp2, tlsosp)) { 2821dd94ecefSrie Shdr *tlsshdr = tlsosp->os_shdr; 2822dd94ecefSrie 2823dd94ecefSrie if (firstshdr == 0) { 2824dd94ecefSrie firstshdr = lastfilshdr = lastmemshdr = 2825dd94ecefSrie tlsosp->os_shdr; 2826dd94ecefSrie continue; 28277c478bd9Sstevel@tonic-gate } 2828dd94ecefSrie 2829dd94ecefSrie if (tlsshdr->sh_type == SHT_NOBITS) 2830dd94ecefSrie lastmemshdr = tlsshdr; 2831dd94ecefSrie else 2832dd94ecefSrie lastfilshdr = tlsshdr; 28337c478bd9Sstevel@tonic-gate } 2834dd94ecefSrie 2835dd94ecefSrie phdr->p_flags = PF_R | PF_W; 28367c478bd9Sstevel@tonic-gate phdr->p_vaddr = firstshdr->sh_addr; 28377c478bd9Sstevel@tonic-gate phdr->p_offset = firstshdr->sh_offset; 2838dd94ecefSrie phdr->p_align = firstshdr->sh_addralign; 2839dd94ecefSrie phdr->p_filesz = lastfilshdr->sh_offset + 2840dd94ecefSrie lastfilshdr->sh_size - phdr->p_offset; 2841dd94ecefSrie phdr->p_memsz = lastmemshdr->sh_offset + 2842dd94ecefSrie lastmemshdr->sh_size - phdr->p_offset; 2843dd94ecefSrie 28445aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 2845dd94ecefSrie 28467c478bd9Sstevel@tonic-gate ofl->ofl_tlsphdr = phdr; 28477c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 28487c478bd9Sstevel@tonic-gate continue; 28497c478bd9Sstevel@tonic-gate } 28507c478bd9Sstevel@tonic-gate 28517c478bd9Sstevel@tonic-gate /* 28527c478bd9Sstevel@tonic-gate * If this is an empty segment declaration, it will occur after 28537c478bd9Sstevel@tonic-gate * all other loadable segments, make sure the previous segment 28547c478bd9Sstevel@tonic-gate * doesn't overlap. We do not do the check if we are generating 28557c478bd9Sstevel@tonic-gate * a relocatable file. 28567c478bd9Sstevel@tonic-gate */ 28577c478bd9Sstevel@tonic-gate if (!(ofl->ofl_flags & FLG_OF_RELOBJ) && 28587c478bd9Sstevel@tonic-gate (sgp->sg_flags & FLG_SG_EMPTY)) { 28597c478bd9Sstevel@tonic-gate int i; 28607c478bd9Sstevel@tonic-gate Addr v_e; 28617c478bd9Sstevel@tonic-gate 28627c478bd9Sstevel@tonic-gate vaddr = phdr->p_vaddr; 28637c478bd9Sstevel@tonic-gate phdr->p_memsz = sgp->sg_length; 28645aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 28657c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 28667c478bd9Sstevel@tonic-gate 28677c478bd9Sstevel@tonic-gate if (phdr->p_type != PT_LOAD) 28687c478bd9Sstevel@tonic-gate continue; 28697c478bd9Sstevel@tonic-gate 28707c478bd9Sstevel@tonic-gate v_e = vaddr + phdr->p_memsz; 28717c478bd9Sstevel@tonic-gate /* 28727c478bd9Sstevel@tonic-gate * Check overlaps 28737c478bd9Sstevel@tonic-gate */ 28747c478bd9Sstevel@tonic-gate for (i = 0; i < phdrndx - 1; i++) { 28757c478bd9Sstevel@tonic-gate Addr p_s = (ofl->ofl_phdr[i]).p_vaddr; 28767c478bd9Sstevel@tonic-gate Addr p_e; 28777c478bd9Sstevel@tonic-gate 28787c478bd9Sstevel@tonic-gate if ((ofl->ofl_phdr[i]).p_type != PT_LOAD) 28797c478bd9Sstevel@tonic-gate continue; 28807c478bd9Sstevel@tonic-gate 28817c478bd9Sstevel@tonic-gate p_e = p_s + (ofl->ofl_phdr[i]).p_memsz; 28827c478bd9Sstevel@tonic-gate if (((p_s <= vaddr) && (p_e > vaddr)) || 28837c478bd9Sstevel@tonic-gate ((vaddr <= p_s) && (v_e > p_s))) 28845aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 28857c478bd9Sstevel@tonic-gate MSG_INTL(MSG_UPD_SEGOVERLAP), 28865aefb655Srie ofl->ofl_name, EC_ADDR(p_e), 28875aefb655Srie sgp->sg_name, EC_ADDR(vaddr)); 28887c478bd9Sstevel@tonic-gate } 28897c478bd9Sstevel@tonic-gate continue; 28907c478bd9Sstevel@tonic-gate } 28917c478bd9Sstevel@tonic-gate 28927c478bd9Sstevel@tonic-gate /* 28937c478bd9Sstevel@tonic-gate * Having processed any of the special program headers any 28947c478bd9Sstevel@tonic-gate * remaining headers will be built to express individual 28957c478bd9Sstevel@tonic-gate * segments. Segments are only built if they have output 28967c478bd9Sstevel@tonic-gate * section descriptors associated with them (ie. some form of 28977c478bd9Sstevel@tonic-gate * input section has been matched to this segment). 28987c478bd9Sstevel@tonic-gate */ 2899*0bc07c75Srie if (sgp->sg_osdescs == NULL) 29007c478bd9Sstevel@tonic-gate continue; 29017c478bd9Sstevel@tonic-gate 29027c478bd9Sstevel@tonic-gate /* 29037c478bd9Sstevel@tonic-gate * Determine the segments offset and size from the section 29047c478bd9Sstevel@tonic-gate * information provided from elf_update(). 29057c478bd9Sstevel@tonic-gate * Allow for multiple NOBITS sections. 29067c478bd9Sstevel@tonic-gate */ 2907*0bc07c75Srie osp = (Os_desc *)sgp->sg_osdescs->al_data[0]; 290854d82594Sseizo hshdr = osp->os_shdr; 29097c478bd9Sstevel@tonic-gate 29107c478bd9Sstevel@tonic-gate phdr->p_filesz = 0; 29117c478bd9Sstevel@tonic-gate phdr->p_memsz = 0; 29127c478bd9Sstevel@tonic-gate phdr->p_offset = offset = hshdr->sh_offset; 2913*0bc07c75Srie 291454d82594Sseizo nobits = ((hshdr->sh_type == SHT_NOBITS) && 2915*0bc07c75Srie ((sgp->sg_flags & FLG_SG_PHREQ) == 0)); 2916*0bc07c75Srie 2917*0bc07c75Srie for (ALIST_TRAVERSE(sgp->sg_osdescs, off, ospp)) { 2918*0bc07c75Srie Shdr *shdr; 2919*0bc07c75Srie 2920*0bc07c75Srie osp = *ospp; 2921*0bc07c75Srie shdr = osp->os_shdr; 29227c478bd9Sstevel@tonic-gate 29237c478bd9Sstevel@tonic-gate p_align = 0; 29247c478bd9Sstevel@tonic-gate if (shdr->sh_addralign > p_align) 29257c478bd9Sstevel@tonic-gate p_align = shdr->sh_addralign; 2926*0bc07c75Srie 29277c478bd9Sstevel@tonic-gate offset = (Off)S_ROUND(offset, shdr->sh_addralign); 29287c478bd9Sstevel@tonic-gate offset += shdr->sh_size; 2929*0bc07c75Srie 29307c478bd9Sstevel@tonic-gate if (shdr->sh_type != SHT_NOBITS) { 29317c478bd9Sstevel@tonic-gate if (nobits) { 29325aefb655Srie eprintf(ofl->ofl_lml, ERR_FATAL, 29337c478bd9Sstevel@tonic-gate MSG_INTL(MSG_UPD_NOBITS)); 29347c478bd9Sstevel@tonic-gate return (S_ERROR); 29357c478bd9Sstevel@tonic-gate } 29367c478bd9Sstevel@tonic-gate phdr->p_filesz = offset - phdr->p_offset; 293754d82594Sseizo } else if ((sgp->sg_flags & FLG_SG_PHREQ) == 0) 29387c478bd9Sstevel@tonic-gate nobits = TRUE; 29397c478bd9Sstevel@tonic-gate } 29407c478bd9Sstevel@tonic-gate phdr->p_memsz = offset - hshdr->sh_offset; 29417c478bd9Sstevel@tonic-gate 29427c478bd9Sstevel@tonic-gate /* 29437c478bd9Sstevel@tonic-gate * If this is PT_SUNWBSS, set alignment 29447c478bd9Sstevel@tonic-gate */ 29457c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_SUNWBSS) 29467c478bd9Sstevel@tonic-gate phdr->p_align = p_align; 29477c478bd9Sstevel@tonic-gate 29487c478bd9Sstevel@tonic-gate /* 29497c478bd9Sstevel@tonic-gate * If this is the first loadable segment of a dynamic object, 29507c478bd9Sstevel@tonic-gate * or an interpretor has been specified (a static object built 29517c478bd9Sstevel@tonic-gate * with an interpretor will still be given a PT_HDR entry), then 29527c478bd9Sstevel@tonic-gate * compensate for the elf header and program header array. Both 29537c478bd9Sstevel@tonic-gate * of these are actually part of the loadable segment as they 29547c478bd9Sstevel@tonic-gate * may be inspected by the interpretor. Adjust the segments 29557c478bd9Sstevel@tonic-gate * size and offset accordingly. 29567c478bd9Sstevel@tonic-gate */ 29577c478bd9Sstevel@tonic-gate if ((_phdr == 0) && (phdr->p_type == PT_LOAD) && 29587c478bd9Sstevel@tonic-gate ((ofl->ofl_osinterp) || (flags & FLG_OF_DYNAMIC)) && 29597c478bd9Sstevel@tonic-gate (!(ofl->ofl_flags1 & FLG_OF1_NOHDR))) { 29607c478bd9Sstevel@tonic-gate size = (Addr)S_ROUND((phdrsz + ehdrsz), 29617c478bd9Sstevel@tonic-gate hshdr->sh_addralign); 29627c478bd9Sstevel@tonic-gate phdr->p_offset -= size; 29637c478bd9Sstevel@tonic-gate phdr->p_filesz += size; 29647c478bd9Sstevel@tonic-gate phdr->p_memsz += size; 29657c478bd9Sstevel@tonic-gate } 29667c478bd9Sstevel@tonic-gate 29677c478bd9Sstevel@tonic-gate /* 29687c478bd9Sstevel@tonic-gate * If a segment size symbol is required (specified via a 29697c478bd9Sstevel@tonic-gate * mapfile) update its value. 29707c478bd9Sstevel@tonic-gate */ 29717c478bd9Sstevel@tonic-gate if (sgp->sg_sizesym != NULL) 29727c478bd9Sstevel@tonic-gate sgp->sg_sizesym->sd_sym->st_value = phdr->p_memsz; 29737c478bd9Sstevel@tonic-gate 29747c478bd9Sstevel@tonic-gate /* 29757c478bd9Sstevel@tonic-gate * If no file content has been assigned to this segment (it 29767c478bd9Sstevel@tonic-gate * only contains no-bits sections), then reset the offset for 29777c478bd9Sstevel@tonic-gate * consistency. 29787c478bd9Sstevel@tonic-gate */ 29797c478bd9Sstevel@tonic-gate if (phdr->p_filesz == 0) 29807c478bd9Sstevel@tonic-gate phdr->p_offset = 0; 29817c478bd9Sstevel@tonic-gate 29827c478bd9Sstevel@tonic-gate /* 29837c478bd9Sstevel@tonic-gate * If a virtual address has been specified for this segment 29847c478bd9Sstevel@tonic-gate * (presumably from a map file) use it and make sure the 29857c478bd9Sstevel@tonic-gate * previous segment does not run into this segment. 29867c478bd9Sstevel@tonic-gate */ 29877c478bd9Sstevel@tonic-gate if ((phdr->p_type == PT_LOAD) || 29887c478bd9Sstevel@tonic-gate (phdr->p_type == PT_SUNWBSS)) { 29897c478bd9Sstevel@tonic-gate if ((sgp->sg_flags & FLG_SG_VADDR)) { 29907c478bd9Sstevel@tonic-gate if (_phdr && (vaddr > phdr->p_vaddr) && 29917c478bd9Sstevel@tonic-gate (phdr->p_type == PT_LOAD)) 29925aefb655Srie eprintf(ofl->ofl_lml, ERR_WARNING, 29937c478bd9Sstevel@tonic-gate MSG_INTL(MSG_UPD_SEGOVERLAP), 29947c478bd9Sstevel@tonic-gate ofl->ofl_name, EC_ADDR(vaddr), 29957c478bd9Sstevel@tonic-gate sgp->sg_name, 29967c478bd9Sstevel@tonic-gate EC_ADDR(phdr->p_vaddr)); 29977c478bd9Sstevel@tonic-gate vaddr = phdr->p_vaddr; 29987c478bd9Sstevel@tonic-gate phdr->p_align = 0; 29997c478bd9Sstevel@tonic-gate } else { 30007c478bd9Sstevel@tonic-gate vaddr = phdr->p_vaddr = 30017c478bd9Sstevel@tonic-gate (Addr)S_ROUND(vaddr, phdr->p_align); 30027c478bd9Sstevel@tonic-gate } 30037c478bd9Sstevel@tonic-gate } 30047c478bd9Sstevel@tonic-gate 30057c478bd9Sstevel@tonic-gate /* 30067c478bd9Sstevel@tonic-gate * Adjust the address offset and p_align if needed. 30077c478bd9Sstevel@tonic-gate */ 30087c478bd9Sstevel@tonic-gate if (!(ofl->ofl_flags1 & (FLG_OF1_NOHDR | FLG_OF1_VADDR))) { 30097c478bd9Sstevel@tonic-gate if (phdr->p_align != 0) 30107c478bd9Sstevel@tonic-gate vaddr += phdr->p_offset % phdr->p_align; 30117c478bd9Sstevel@tonic-gate else 30127c478bd9Sstevel@tonic-gate vaddr += phdr->p_offset; 30137c478bd9Sstevel@tonic-gate phdr->p_vaddr = vaddr; 30147c478bd9Sstevel@tonic-gate } 30157c478bd9Sstevel@tonic-gate 30167c478bd9Sstevel@tonic-gate /* 30177c478bd9Sstevel@tonic-gate * If an interpreter is required set the virtual address of the 30187c478bd9Sstevel@tonic-gate * PT_PHDR program header now that we know the virtual address 30197c478bd9Sstevel@tonic-gate * of the loadable segment that contains it. Update the 30207c478bd9Sstevel@tonic-gate * PT_SUNWCAP header similarly. 30217c478bd9Sstevel@tonic-gate */ 30227c478bd9Sstevel@tonic-gate if ((_phdr == 0) && (phdr->p_type == PT_LOAD)) { 30237c478bd9Sstevel@tonic-gate _phdr = phdr; 30247c478bd9Sstevel@tonic-gate 30257c478bd9Sstevel@tonic-gate if (!(ofl->ofl_flags1 & FLG_OF1_NOHDR)) { 30267c478bd9Sstevel@tonic-gate if (ofl->ofl_osinterp) 30277c478bd9Sstevel@tonic-gate ofl->ofl_phdr[0].p_vaddr = 30287c478bd9Sstevel@tonic-gate vaddr + ehdrsz; 30297c478bd9Sstevel@tonic-gate 30307c478bd9Sstevel@tonic-gate if (ofl->ofl_oscap) 30317c478bd9Sstevel@tonic-gate ofl->ofl_phdr[capndx].p_vaddr = vaddr + 30327c478bd9Sstevel@tonic-gate ofl->ofl_phdr[capndx].p_offset; 30337c478bd9Sstevel@tonic-gate 30347c478bd9Sstevel@tonic-gate /* 30357c478bd9Sstevel@tonic-gate * Finally, if we're creating a dynamic object 30367c478bd9Sstevel@tonic-gate * (or a static object in which an interpretor 30377c478bd9Sstevel@tonic-gate * is specified) update the vaddr to reflect 30387c478bd9Sstevel@tonic-gate * the address of the first section within this 30397c478bd9Sstevel@tonic-gate * segment. 30407c478bd9Sstevel@tonic-gate */ 30417c478bd9Sstevel@tonic-gate if ((ofl->ofl_osinterp) || 30427c478bd9Sstevel@tonic-gate (flags & FLG_OF_DYNAMIC)) 30437c478bd9Sstevel@tonic-gate vaddr += size; 30447c478bd9Sstevel@tonic-gate } else { 30457c478bd9Sstevel@tonic-gate /* 30467c478bd9Sstevel@tonic-gate * If the FLG_OF1_NOHDR flag was set, PT_PHDR 30477c478bd9Sstevel@tonic-gate * will not be part of any loadable segment. 30487c478bd9Sstevel@tonic-gate */ 30497c478bd9Sstevel@tonic-gate ofl->ofl_phdr[0].p_vaddr = 0; 30507c478bd9Sstevel@tonic-gate ofl->ofl_phdr[0].p_memsz = 0; 30517c478bd9Sstevel@tonic-gate ofl->ofl_phdr[0].p_flags = 0; 30527c478bd9Sstevel@tonic-gate } 30537c478bd9Sstevel@tonic-gate } 30547c478bd9Sstevel@tonic-gate 30557c478bd9Sstevel@tonic-gate /* 30567c478bd9Sstevel@tonic-gate * Save the address of the first executable section for default 30577c478bd9Sstevel@tonic-gate * use as the execution entry point. This may get overridden in 30587c478bd9Sstevel@tonic-gate * update_oehdr(). 30597c478bd9Sstevel@tonic-gate */ 30607c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_RELOBJ) && !(ehdr->e_entry) && 30617c478bd9Sstevel@tonic-gate (phdr->p_flags & PF_X)) 30627c478bd9Sstevel@tonic-gate ehdr->e_entry = vaddr; 30637c478bd9Sstevel@tonic-gate 30645aefb655Srie DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp)); 30657c478bd9Sstevel@tonic-gate 30667c478bd9Sstevel@tonic-gate /* 30677c478bd9Sstevel@tonic-gate * Traverse the output section descriptors for this segment so 30687c478bd9Sstevel@tonic-gate * that we can update the section headers addresses. We've 30697c478bd9Sstevel@tonic-gate * calculated the virtual address of the initial section within 30707c478bd9Sstevel@tonic-gate * this segment, so each successive section can be calculated 30717c478bd9Sstevel@tonic-gate * based on their offsets from each other. 30727c478bd9Sstevel@tonic-gate */ 30737c478bd9Sstevel@tonic-gate secndx = 0; 30747c478bd9Sstevel@tonic-gate hshdr = 0; 3075*0bc07c75Srie for (ALIST_TRAVERSE(sgp->sg_osdescs, off, ospp)) { 3076*0bc07c75Srie Shdr *shdr; 3077*0bc07c75Srie 3078*0bc07c75Srie osp = *ospp; 3079*0bc07c75Srie shdr = osp->os_shdr; 30807c478bd9Sstevel@tonic-gate 30817c478bd9Sstevel@tonic-gate if (shdr->sh_link) 30827c478bd9Sstevel@tonic-gate shdr->sh_link = 30835aefb655Srie translate_link(ofl, osp, shdr->sh_link, 30847c478bd9Sstevel@tonic-gate MSG_INTL(MSG_FIL_INVSHLINK)); 30857c478bd9Sstevel@tonic-gate 30867c478bd9Sstevel@tonic-gate if (shdr->sh_info && (shdr->sh_flags & SHF_INFO_LINK)) 30877c478bd9Sstevel@tonic-gate shdr->sh_info = 30885aefb655Srie translate_link(ofl, osp, shdr->sh_info, 30897c478bd9Sstevel@tonic-gate MSG_INTL(MSG_FIL_INVSHINFO)); 30907c478bd9Sstevel@tonic-gate 30917c478bd9Sstevel@tonic-gate if (!(flags & FLG_OF_RELOBJ) && 30927c478bd9Sstevel@tonic-gate (phdr->p_type == PT_LOAD) || 30937c478bd9Sstevel@tonic-gate (phdr->p_type == PT_SUNWBSS)) { 30947c478bd9Sstevel@tonic-gate if (hshdr) 30957c478bd9Sstevel@tonic-gate vaddr += (shdr->sh_offset - 30967c478bd9Sstevel@tonic-gate hshdr->sh_offset); 30977c478bd9Sstevel@tonic-gate 30987c478bd9Sstevel@tonic-gate shdr->sh_addr = vaddr; 30997c478bd9Sstevel@tonic-gate hshdr = shdr; 31007c478bd9Sstevel@tonic-gate } 31017c478bd9Sstevel@tonic-gate 31027c478bd9Sstevel@tonic-gate DBG_CALL(Dbg_seg_os(ofl, osp, secndx)); 31037c478bd9Sstevel@tonic-gate secndx++; 31047c478bd9Sstevel@tonic-gate } 31057c478bd9Sstevel@tonic-gate 31067c478bd9Sstevel@tonic-gate /* 31077c478bd9Sstevel@tonic-gate * Establish the virtual address of the end of the last section 31087c478bd9Sstevel@tonic-gate * in this segment so that the next segments offset can be 31097c478bd9Sstevel@tonic-gate * calculated from this. 31107c478bd9Sstevel@tonic-gate */ 31117c478bd9Sstevel@tonic-gate if (hshdr) 31127c478bd9Sstevel@tonic-gate vaddr += hshdr->sh_size; 31137c478bd9Sstevel@tonic-gate 31147c478bd9Sstevel@tonic-gate /* 31157c478bd9Sstevel@tonic-gate * Output sections for this segment complete. Adjust the 31167c478bd9Sstevel@tonic-gate * virtual offset for the last sections size, and make sure we 31177c478bd9Sstevel@tonic-gate * haven't exceeded any maximum segment length specification. 31187c478bd9Sstevel@tonic-gate */ 31197c478bd9Sstevel@tonic-gate if ((sgp->sg_length != 0) && (sgp->sg_length < phdr->p_memsz)) { 31205aefb655Srie eprintf(ofl->ofl_lml, ERR_FATAL, 31215aefb655Srie MSG_INTL(MSG_UPD_LARGSIZE), ofl->ofl_name, 31225aefb655Srie sgp->sg_name, EC_XWORD(phdr->p_memsz), 31237c478bd9Sstevel@tonic-gate EC_XWORD(sgp->sg_length)); 31247c478bd9Sstevel@tonic-gate return (S_ERROR); 31257c478bd9Sstevel@tonic-gate } 31267c478bd9Sstevel@tonic-gate 31277c478bd9Sstevel@tonic-gate if (phdr->p_type == PT_NOTE) { 31287c478bd9Sstevel@tonic-gate phdr->p_vaddr = 0; 31297c478bd9Sstevel@tonic-gate phdr->p_paddr = 0; 31307c478bd9Sstevel@tonic-gate phdr->p_align = 0; 31317c478bd9Sstevel@tonic-gate phdr->p_memsz = 0; 31327c478bd9Sstevel@tonic-gate } 31337c478bd9Sstevel@tonic-gate if ((phdr->p_type != PT_NULL) && !(flags & FLG_OF_RELOBJ)) 31347c478bd9Sstevel@tonic-gate ofl->ofl_phdr[phdrndx++] = *phdr; 31357c478bd9Sstevel@tonic-gate } 31367c478bd9Sstevel@tonic-gate 31377c478bd9Sstevel@tonic-gate /* 31387c478bd9Sstevel@tonic-gate * Update any new output sections. When building the initial output 31397c478bd9Sstevel@tonic-gate * image, a number of sections were created but left uninitialized (eg. 31407c478bd9Sstevel@tonic-gate * .dynsym, .dynstr, .symtab, .symtab, etc.). Here we update these 31417c478bd9Sstevel@tonic-gate * sections with the appropriate data. Other sections may still be 31427c478bd9Sstevel@tonic-gate * modified via reloc_process(). 31437c478bd9Sstevel@tonic-gate * 31447c478bd9Sstevel@tonic-gate * Copy the interpretor name into the .interp section. 31457c478bd9Sstevel@tonic-gate */ 31467c478bd9Sstevel@tonic-gate if (ofl->ofl_interp) 31477c478bd9Sstevel@tonic-gate (void) strcpy((char *)ofl->ofl_osinterp->os_outdata->d_buf, 31487c478bd9Sstevel@tonic-gate ofl->ofl_interp); 31497c478bd9Sstevel@tonic-gate 31507c478bd9Sstevel@tonic-gate /* 31517c478bd9Sstevel@tonic-gate * Update the .shstrtab, .strtab and .dynstr sections. 31527c478bd9Sstevel@tonic-gate */ 31537c478bd9Sstevel@tonic-gate update_ostrtab(ofl->ofl_osshstrtab, ofl->ofl_shdrsttab); 31547c478bd9Sstevel@tonic-gate update_ostrtab(ofl->ofl_osstrtab, ofl->ofl_strtab); 31557c478bd9Sstevel@tonic-gate update_ostrtab(ofl->ofl_osdynstr, ofl->ofl_dynstrtab); 31567c478bd9Sstevel@tonic-gate 31577c478bd9Sstevel@tonic-gate /* 31587c478bd9Sstevel@tonic-gate * Build any output symbol tables, the symbols information is copied 31597c478bd9Sstevel@tonic-gate * and updated into the new output image. 31607c478bd9Sstevel@tonic-gate */ 31617c478bd9Sstevel@tonic-gate if ((etext = update_osym(ofl)) == (Addr)S_ERROR) 31627c478bd9Sstevel@tonic-gate return (S_ERROR); 31637c478bd9Sstevel@tonic-gate 31647c478bd9Sstevel@tonic-gate /* 31657c478bd9Sstevel@tonic-gate * If we have a PT_SUNWDTRACE phdr, update it now with the address of 31667c478bd9Sstevel@tonic-gate * the symbol. It's only now been updated via update_sym(). 31677c478bd9Sstevel@tonic-gate */ 31687c478bd9Sstevel@tonic-gate if (dtracephdr && ofl->ofl_dtracesym) { 31697c478bd9Sstevel@tonic-gate Phdr *pphdr; 31707c478bd9Sstevel@tonic-gate Sym_desc *sdp = ofl->ofl_dtracesym; 31717c478bd9Sstevel@tonic-gate 31727c478bd9Sstevel@tonic-gate dtracephdr->p_vaddr = sdp->sd_sym->st_value; 31737c478bd9Sstevel@tonic-gate dtracephdr->p_memsz = sdp->sd_sym->st_size; 31747c478bd9Sstevel@tonic-gate 31757c478bd9Sstevel@tonic-gate /* 31767c478bd9Sstevel@tonic-gate * Take permisions of the segment the symbol is associated with. 31777c478bd9Sstevel@tonic-gate */ 31787c478bd9Sstevel@tonic-gate pphdr = &sdp->sd_isc->is_osdesc->os_sgdesc->sg_phdr; 31797c478bd9Sstevel@tonic-gate assert(pphdr); 31807c478bd9Sstevel@tonic-gate dtracephdr->p_flags = pphdr->p_flags; 31817c478bd9Sstevel@tonic-gate } 31827c478bd9Sstevel@tonic-gate 31837c478bd9Sstevel@tonic-gate /* 31847c478bd9Sstevel@tonic-gate * Update the GROUP sections. 31857c478bd9Sstevel@tonic-gate */ 31867c478bd9Sstevel@tonic-gate if (update_ogroup(ofl) == S_ERROR) 31877c478bd9Sstevel@tonic-gate return (S_ERROR); 31887c478bd9Sstevel@tonic-gate 31897c478bd9Sstevel@tonic-gate /* 31907c478bd9Sstevel@tonic-gate * Update Move Table. 31917c478bd9Sstevel@tonic-gate */ 31927c478bd9Sstevel@tonic-gate if (ofl->ofl_osmove || ofl->ofl_issunwdata1) { 31937c478bd9Sstevel@tonic-gate if (update_move(ofl) == S_ERROR) 31947c478bd9Sstevel@tonic-gate return (S_ERROR); 31957c478bd9Sstevel@tonic-gate } 31967c478bd9Sstevel@tonic-gate 31977c478bd9Sstevel@tonic-gate /* 31987c478bd9Sstevel@tonic-gate * Build any output headers, version information, dynamic structure and 31997c478bd9Sstevel@tonic-gate * syminfo structure. 32007c478bd9Sstevel@tonic-gate */ 32017c478bd9Sstevel@tonic-gate if (update_oehdr(ofl) == S_ERROR) 32027c478bd9Sstevel@tonic-gate return (S_ERROR); 32037c478bd9Sstevel@tonic-gate if ((flags & (FLG_OF_VERDEF | FLG_OF_NOVERSEC)) == FLG_OF_VERDEF) 32047c478bd9Sstevel@tonic-gate if (update_overdef(ofl) == S_ERROR) 32057c478bd9Sstevel@tonic-gate return (S_ERROR); 32067c478bd9Sstevel@tonic-gate if ((flags & (FLG_OF_VERNEED | FLG_OF_NOVERSEC)) == FLG_OF_VERNEED) 32077c478bd9Sstevel@tonic-gate if (update_overneed(ofl) == S_ERROR) 32087c478bd9Sstevel@tonic-gate return (S_ERROR); 32097c478bd9Sstevel@tonic-gate if (flags & FLG_OF_DYNAMIC) { 32107c478bd9Sstevel@tonic-gate if (update_odynamic(ofl) == S_ERROR) 32117c478bd9Sstevel@tonic-gate return (S_ERROR); 32127c478bd9Sstevel@tonic-gate if (ofl->ofl_ossyminfo) 32137c478bd9Sstevel@tonic-gate if (update_osyminfo(ofl) == S_ERROR) 32147c478bd9Sstevel@tonic-gate return (S_ERROR); 32157c478bd9Sstevel@tonic-gate } 32167c478bd9Sstevel@tonic-gate 32177c478bd9Sstevel@tonic-gate /* 32187c478bd9Sstevel@tonic-gate * Emit Strtab diagnostics. 32197c478bd9Sstevel@tonic-gate */ 32205aefb655Srie DBG_CALL(Dbg_sec_strtab(ofl->ofl_lml, ofl->ofl_osshstrtab, 32215aefb655Srie ofl->ofl_shdrsttab)); 32225aefb655Srie DBG_CALL(Dbg_sec_strtab(ofl->ofl_lml, ofl->ofl_osstrtab, 32235aefb655Srie ofl->ofl_strtab)); 32245aefb655Srie DBG_CALL(Dbg_sec_strtab(ofl->ofl_lml, ofl->ofl_osdynstr, 32255aefb655Srie ofl->ofl_dynstrtab)); 32267c478bd9Sstevel@tonic-gate 32277c478bd9Sstevel@tonic-gate /* 32287c478bd9Sstevel@tonic-gate * Initialize the section headers string table index within the elf 32297c478bd9Sstevel@tonic-gate * header. 32307c478bd9Sstevel@tonic-gate */ 32317c478bd9Sstevel@tonic-gate /* LINTED */ 32327c478bd9Sstevel@tonic-gate if ((shscnndx = elf_ndxscn(ofl->ofl_osshstrtab->os_scn)) < 32337c478bd9Sstevel@tonic-gate SHN_LORESERVE) { 32345aefb655Srie ofl->ofl_nehdr->e_shstrndx = 32357c478bd9Sstevel@tonic-gate /* LINTED */ 32367c478bd9Sstevel@tonic-gate (Half)shscnndx; 32377c478bd9Sstevel@tonic-gate } else { 32387c478bd9Sstevel@tonic-gate /* 32397c478bd9Sstevel@tonic-gate * If the STRTAB section index doesn't fit into 32407c478bd9Sstevel@tonic-gate * e_shstrndx, then we store it in 'shdr[0].st_link'. 32417c478bd9Sstevel@tonic-gate */ 32427c478bd9Sstevel@tonic-gate Elf_Scn *scn; 32437c478bd9Sstevel@tonic-gate Shdr *shdr0; 32445aefb655Srie 32457c478bd9Sstevel@tonic-gate if ((scn = elf_getscn(ofl->ofl_elf, 0)) == NULL) { 32465aefb655Srie eprintf(ofl->ofl_lml, ERR_ELF, 32475aefb655Srie MSG_INTL(MSG_ELF_GETSCN), ofl->ofl_name); 32487c478bd9Sstevel@tonic-gate return (S_ERROR); 32497c478bd9Sstevel@tonic-gate } 32507c478bd9Sstevel@tonic-gate if ((shdr0 = elf_getshdr(scn)) == NULL) { 32515aefb655Srie eprintf(ofl->ofl_lml, ERR_ELF, 32525aefb655Srie MSG_INTL(MSG_ELF_GETSHDR), ofl->ofl_name); 32537c478bd9Sstevel@tonic-gate return (S_ERROR); 32547c478bd9Sstevel@tonic-gate } 32555aefb655Srie ofl->ofl_nehdr->e_shstrndx = SHN_XINDEX; 32567c478bd9Sstevel@tonic-gate shdr0->sh_link = shscnndx; 32577c478bd9Sstevel@tonic-gate } 32587c478bd9Sstevel@tonic-gate 32597c478bd9Sstevel@tonic-gate return ((uintptr_t)etext); 32607c478bd9Sstevel@tonic-gate } 3261