1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 1988 AT&T 24 * All Rights Reserved 25 * 26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 27 * Use is subject to license terms. 28 */ 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include <stdio.h> 32 #include <string.h> 33 #include "msg.h" 34 #include "_libld.h" 35 36 37 /* 38 * Print a virtual address map of input and output sections together with 39 * multiple symbol definitions (if they exist). 40 */ 41 static Boolean symbol_title = TRUE; 42 43 static void 44 sym_muldef_title() 45 { 46 (void) printf(MSG_INTL(MSG_ENT_MUL_FMT_TIL_0), 47 MSG_INTL(MSG_ENT_MUL_TIL_0)); 48 (void) printf(MSG_INTL(MSG_ENT_MUL_FMT_TIL_1), 49 MSG_INTL(MSG_ENT_MUL_ITM_SYM), 50 MSG_INTL(MSG_ENT_MUL_ITM_DEF_0), 51 MSG_INTL(MSG_ENT_MUL_ITM_DEF_1)); 52 symbol_title = FALSE; 53 } 54 55 void 56 ld_map_out(Ofl_desc * ofl) 57 { 58 Listnode * lnp1, * lnp2, * lnp3; 59 Os_desc * osp; 60 Sg_desc * sgp; 61 Is_desc * isp; 62 Sym_avlnode *sav; 63 64 (void) printf(MSG_INTL(MSG_ENT_MAP_FMT_TIL_1), 65 MSG_INTL(MSG_ENT_MAP_TITLE_1)); 66 if (ofl->ofl_flags & FLG_OF_RELOBJ) 67 (void) printf(MSG_INTL(MSG_ENT_MAP_FMT_TIL_2), 68 MSG_INTL(MSG_ENT_ITM_OUTPUT), 69 MSG_INTL(MSG_ENT_ITM_INPUT), 70 MSG_INTL(MSG_ENT_ITM_NEW), 71 MSG_INTL(MSG_ENT_ITM_SECTION), 72 MSG_INTL(MSG_ENT_ITM_SECTION), 73 MSG_INTL(MSG_ENT_ITM_DISPMNT), 74 MSG_INTL(MSG_ENT_ITM_SIZE)); 75 else 76 (void) printf(MSG_INTL(MSG_ENT_MAP_FMT_TIL_3), 77 MSG_INTL(MSG_ENT_ITM_OUTPUT), 78 MSG_INTL(MSG_ENT_ITM_INPUT), 79 MSG_INTL(MSG_ENT_ITM_VIRTUAL), 80 MSG_INTL(MSG_ENT_ITM_SECTION), 81 MSG_INTL(MSG_ENT_ITM_SECTION), 82 MSG_INTL(MSG_ENT_ITM_ADDRESS), 83 MSG_INTL(MSG_ENT_ITM_SIZE)); 84 85 for (LIST_TRAVERSE(&ofl->ofl_segs, lnp1, sgp)) { 86 if (sgp->sg_phdr.p_type != PT_LOAD) 87 continue; 88 89 for (LIST_TRAVERSE(&(sgp->sg_osdescs), lnp2, osp)) { 90 (void) printf(MSG_INTL(MSG_ENT_MAP_ENTRY_1), 91 osp->os_name, EC_ADDR(osp->os_shdr->sh_addr), 92 EC_XWORD(osp->os_shdr->sh_size)); 93 94 for (LIST_TRAVERSE(&(osp->os_isdescs), lnp3, isp)) { 95 Addr addr; 96 97 /* 98 * Although there seems little point in printing 99 * discarded (empty) sections, especially as 100 * diagnostics under -Dsegments,details are more 101 * informative, continue printing them. There 102 * are user scripts, fragile to say the least, 103 * that grep(1) through load-map output to 104 * discover object requirements. These scripts 105 * don't grep for all input sections types (ie. 106 * .picdata), and have become dependent on null 107 * sections (ie. .text) existing in the 108 * load-map output. 109 */ 110 if (isp->is_flags & FLG_IS_DISCARD) 111 addr = 0; 112 else { 113 addr = (Addr)_elf_getxoff(isp->is_indata); 114 if (!(ofl->ofl_flags & FLG_OF_RELOBJ)) 115 addr += 116 isp->is_osdesc->os_shdr->sh_addr; 117 } 118 119 (void) printf(MSG_INTL(MSG_ENT_MAP_ENTRY_2), 120 isp->is_name, EC_ADDR(addr), 121 EC_XWORD(isp->is_shdr->sh_size), 122 ((isp->is_file != NULL) ? 123 (char *)(isp->is_file->ifl_name) : 124 MSG_INTL(MSG_STR_NULL))); 125 } 126 } 127 } 128 129 if (ofl->ofl_flags & FLG_OF_RELOBJ) 130 return; 131 132 /* 133 * Check for any multiply referenced symbols (ie. symbols that have 134 * been overridden from a shared library). 135 */ 136 for (sav = avl_first(&ofl->ofl_symavl); sav; 137 sav = AVL_NEXT(&ofl->ofl_symavl, sav)) { 138 Sym_desc *sdp; 139 const char *name, *ducp, *adcp; 140 List *dfiles; 141 142 sdp = sav->sav_symdesc; 143 name = sdp->sd_name; 144 dfiles = &sdp->sd_aux->sa_dfiles; 145 146 /* 147 * Files that define a symbol are saved on the 148 * `sa_dfiles' list, if the head and tail of 149 * this list differ there must have been more 150 * than one symbol definition. Ignore symbols 151 * that aren't needed, and any special symbols 152 * that the link editor may produce (symbols of 153 * type ABS and COMMON are not recorded in the 154 * first place, however functions like _init() 155 * and _fini() commonly have multiple 156 * occurrances). 157 */ 158 if ((sdp->sd_ref == REF_DYN_SEEN) || 159 (dfiles->head == dfiles->tail) || 160 (sdp->sd_aux && sdp->sd_aux->sa_symspec) || 161 (strcmp(MSG_ORIG(MSG_SYM_FINI_U), name) == 0) || 162 (strcmp(MSG_ORIG(MSG_SYM_INIT_U), name) == 0) || 163 (strcmp(MSG_ORIG(MSG_SYM_LIBVER_U), name) == 0)) 164 continue; 165 166 if (symbol_title) 167 sym_muldef_title(); 168 169 ducp = sdp->sd_file->ifl_name; 170 (void) printf(MSG_INTL(MSG_ENT_MUL_ENTRY_1), demangle(name), 171 ducp); 172 for (LIST_TRAVERSE(dfiles, lnp2, adcp)) { 173 /* 174 * Ignore the referenced symbol. 175 */ 176 if (strcmp(adcp, ducp) != 0) 177 (void) printf(MSG_INTL(MSG_ENT_MUL_ENTRY_2), adcp); 178 } 179 } 180 } 181 182 /* 183 * Traverse the entrance criteria list searching for those sections that haven't 184 * been met and print error message. (only in the case of reordering) 185 */ 186 void 187 ld_ent_check(Ofl_desc * ofl) 188 { 189 Listnode * lnp; 190 Ent_desc * enp; 191 192 /* 193 * Try to give as much information to the user about the specific 194 * line in the mapfile. If the line contains a file name then 195 * output the filename too. Hence we have two warning lines - 196 * one for criterias where a filename is used and the other 197 * for those without a filename. 198 */ 199 for (LIST_TRAVERSE(&ofl->ofl_ents, lnp, enp)) { 200 if ((enp->ec_segment->sg_flags & FLG_SG_ORDER) && 201 !(enp->ec_flags & FLG_EC_USED) && enp->ec_ndx) { 202 Listnode * _lnp = enp->ec_files.head; 203 204 if ((_lnp != NULL) && (_lnp->data != NULL) && 205 (char *)(_lnp->data) != NULL) { 206 eprintf(ofl->ofl_lml, ERR_WARNING, 207 MSG_INTL(MSG_ENT_NOSEC_1), 208 enp->ec_segment->sg_name, enp->ec_name, 209 (const char *)(_lnp->data)); 210 } else { 211 eprintf(ofl->ofl_lml, ERR_WARNING, 212 MSG_INTL(MSG_ENT_NOSEC_2), 213 enp->ec_segment->sg_name, enp->ec_name); 214 } 215 } 216 } 217 } 218