xref: /titanic_41/usr/src/cmd/sgs/libld/common/ldentry.c (revision dd51520e127b452179a2ce4ea3bd8dee949f9afe)
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 (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
27  */
28 
29 #include	<stdio.h>
30 #include	<string.h>
31 #include	"msg.h"
32 #include	"_libld.h"
33 
34 
35 /*
36  * Print a virtual address map of input and output sections together with
37  * multiple symbol definitions (if they exist).
38  */
39 static Boolean	symbol_title = TRUE;
40 
41 static void
42 sym_muldef_title()
43 {
44 	(void) printf(MSG_INTL(MSG_ENT_MUL_FMT_TIL_0),
45 	    MSG_INTL(MSG_ENT_MUL_TIL_0));
46 	(void) printf(MSG_INTL(MSG_ENT_MUL_FMT_TIL_1),
47 	    MSG_INTL(MSG_ENT_MUL_ITM_SYM),
48 	    MSG_INTL(MSG_ENT_MUL_ITM_DEF_0),
49 	    MSG_INTL(MSG_ENT_MUL_ITM_DEF_1));
50 	symbol_title = FALSE;
51 }
52 
53 void
54 ld_map_out(Ofl_desc *ofl)
55 {
56 	Sg_desc		*sgp;
57 	Is_desc		*isp;
58 	Sym_avlnode	*sav;
59 	Aliste		idx1;
60 
61 	(void) printf(MSG_INTL(MSG_ENT_MAP_FMT_TIL_1),
62 	    MSG_INTL(MSG_ENT_MAP_TITLE_1));
63 	if (ofl->ofl_flags & FLG_OF_RELOBJ)
64 		(void) printf(MSG_INTL(MSG_ENT_MAP_FMT_TIL_2),
65 		    MSG_INTL(MSG_ENT_ITM_OUTPUT),
66 		    MSG_INTL(MSG_ENT_ITM_INPUT),
67 		    MSG_INTL(MSG_ENT_ITM_NEW),
68 		    MSG_INTL(MSG_ENT_ITM_SECTION),
69 		    MSG_INTL(MSG_ENT_ITM_SECTION),
70 		    MSG_INTL(MSG_ENT_ITM_DISPMNT),
71 		    MSG_INTL(MSG_ENT_ITM_SIZE));
72 	else
73 		(void) printf(MSG_INTL(MSG_ENT_MAP_FMT_TIL_3),
74 		    MSG_INTL(MSG_ENT_ITM_OUTPUT),
75 		    MSG_INTL(MSG_ENT_ITM_INPUT),
76 		    MSG_INTL(MSG_ENT_ITM_VIRTUAL),
77 		    MSG_INTL(MSG_ENT_ITM_SECTION),
78 		    MSG_INTL(MSG_ENT_ITM_SECTION),
79 		    MSG_INTL(MSG_ENT_ITM_ADDRESS),
80 		    MSG_INTL(MSG_ENT_ITM_SIZE));
81 
82 	for (APLIST_TRAVERSE(ofl->ofl_segs, idx1, sgp)) {
83 		Os_desc	*osp;
84 		Aliste	idx2;
85 
86 		if (sgp->sg_phdr.p_type != PT_LOAD)
87 			continue;
88 
89 		for (APLIST_TRAVERSE(sgp->sg_osdescs, idx2, osp)) {
90 			int	os_isdescs_idx;
91 			Aliste	idx3;
92 
93 			(void) printf(MSG_INTL(MSG_ENT_MAP_ENTRY_1),
94 			    osp->os_name, EC_ADDR(osp->os_shdr->sh_addr),
95 			    EC_XWORD(osp->os_shdr->sh_size));
96 
97 			OS_ISDESCS_TRAVERSE(os_isdescs_idx, osp, idx3, isp) {
98 				Addr	addr;
99 
100 				/*
101 				 * Although there seems little point in printing
102 				 * discarded (empty) sections, especially as
103 				 * diagnostics under -Dsegments,details are more
104 				 * informative, continue printing them.  There
105 				 * are user scripts, fragile to say the least,
106 				 * that grep(1) through load-map output to
107 				 * discover object requirements.  These scripts
108 				 * don't grep for all input sections types (ie.
109 				 * .picdata), and have become dependent on null
110 				 * sections (ie. .text) existing in the
111 				 * load-map output.
112 				 */
113 				if (isp->is_flags & FLG_IS_DISCARD) {
114 					addr = 0;
115 				} else {
116 					addr = (Addr)
117 					    _elf_getxoff(isp->is_indata);
118 					if (!(ofl->ofl_flags & FLG_OF_RELOBJ))
119 						addr += isp->is_osdesc->
120 						    os_shdr->sh_addr;
121 				}
122 
123 				(void) printf(MSG_INTL(MSG_ENT_MAP_ENTRY_2),
124 				    isp->is_name, EC_ADDR(addr),
125 				    EC_XWORD(isp->is_shdr->sh_size),
126 				    ((isp->is_file != NULL) ?
127 				    (char *)(isp->is_file->ifl_name) :
128 				    MSG_INTL(MSG_STR_NULL)));
129 			}
130 		}
131 	}
132 
133 	if (ofl->ofl_flags & FLG_OF_RELOBJ)
134 		return;
135 
136 	/*
137 	 * Check for any multiply referenced symbols (ie. symbols that have
138 	 * been overridden from a shared library).
139 	 */
140 	for (sav = avl_first(&ofl->ofl_symavl); sav;
141 	    sav = AVL_NEXT(&ofl->ofl_symavl, sav)) {
142 		Sym_desc	*sdp = sav->sav_sdp;
143 		const char	*name = sdp->sd_name, *ducp, *adcp;
144 		APlist		*dfiles;
145 		Aliste		idx;
146 
147 		if (((dfiles = sdp->sd_aux->sa_dfiles) == NULL) ||
148 		    (aplist_nitems(dfiles) == 1))
149 			continue;
150 
151 		/*
152 		 * Files that define a symbol are saved on the `sa_dfiles' list.
153 		 * Ignore symbols that aren't needed, and any special symbols
154 		 * that the link editor may produce (symbols of type ABS and
155 		 * COMMON are not recorded in the first place, however functions
156 		 * like _init() and _fini() commonly have multiple occurrences).
157 		 */
158 		if ((sdp->sd_ref == REF_DYN_SEEN) ||
159 		    (sdp->sd_aux && sdp->sd_aux->sa_symspec) ||
160 		    (strcmp(MSG_ORIG(MSG_SYM_FINI_U), name) == 0) ||
161 		    (strcmp(MSG_ORIG(MSG_SYM_INIT_U), name) == 0) ||
162 		    (strcmp(MSG_ORIG(MSG_SYM_LIBVER_U), name) == 0))
163 			continue;
164 
165 		if (symbol_title)
166 			sym_muldef_title();
167 
168 		ducp = sdp->sd_file->ifl_name;
169 		(void) printf(MSG_INTL(MSG_ENT_MUL_ENTRY_1), demangle(name),
170 		    ducp);
171 		for (APLIST_TRAVERSE(dfiles, idx, adcp)) {
172 			/*
173 			 * Ignore the referenced symbol.
174 			 */
175 			if (strcmp(adcp, ducp) != 0)
176 				(void) printf(MSG_INTL(MSG_ENT_MUL_ENTRY_2),
177 				    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 	Ent_desc	*enp;
190 	Aliste		ndx;
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 (APLIST_TRAVERSE(ofl->ofl_ents, ndx, enp)) {
200 		/*
201 		 * No warning if any of the following hold:
202 		 * -	The segment has no entrance criteria requiring
203 		 *	input section sorting (FLG_SG_IS_ORDER not set).
204 		 * -	The entrance criteria was used to place a section.
205 		 * -	The specific entrance criteria does not require sorting
206 		 */
207 		if (((enp->ec_segment->sg_flags & FLG_SG_IS_ORDER) == 0) ||
208 		    (enp->ec_flags & FLG_EC_USED) || (enp->ec_ordndx == 0))
209 			continue;
210 
211 
212 		if (alist_nitems(enp->ec_files) > 0) {
213 			ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_ENT_NOSEC_1),
214 			    enp->ec_segment->sg_name, enp->ec_is_name);
215 		} else {
216 			ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_ENT_NOSEC_2),
217 			    enp->ec_segment->sg_name, enp->ec_is_name);
218 		}
219 	}
220 }
221