xref: /titanic_41/usr/src/cmd/sgs/liblddbg/common/sections.c (revision 22337b4b3c8a2b9db615e524e0e9e1fbd3dc71bf)
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 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include	"msg.h"
29 #include	"_debug.h"
30 #include	"libld.h"
31 #include	"_string_table.h"
32 
33 void
34 Dbg_sec_strtab(Lm_list *lml, Os_desc *osp, Str_tbl *stp)
35 {
36 	uint_t	cnt;
37 
38 	if (DBG_NOTCLASS(DBG_C_STRTAB))
39 		return;
40 
41 	if (!osp)
42 		return;
43 
44 	Dbg_util_nl(lml, DBG_NL_STD);
45 	if (stp->st_flags & FLG_STTAB_COMPRESS)
46 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_COMP), osp->os_name,
47 		    stp->st_fullstrsize, stp->st_strsize);
48 	else
49 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_STND), osp->os_name,
50 		    stp->st_fullstrsize);
51 
52 	if ((DBG_NOTDETAIL()) ||
53 	    ((stp->st_flags & FLG_STTAB_COMPRESS) == 0))
54 		return;
55 
56 	dbg_print(lml, MSG_ORIG(MSG_STR_EMPTY));
57 	dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_HD), osp->os_name,
58 	    stp->st_hbckcnt);
59 
60 	for (cnt = 0; cnt < stp->st_hbckcnt; cnt++) {
61 		Str_hash	*strhash = stp->st_hashbcks[cnt];
62 
63 		if (strhash == 0)
64 			continue;
65 
66 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_BCKT), cnt);
67 
68 		while (strhash) {
69 			uint_t	stroff = strhash->hi_mstr->sm_strlen -
70 			    strhash->hi_strlen;
71 
72 			if (stroff == 0) {
73 				dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_MSTR),
74 				    strhash->hi_refcnt,
75 				    strhash->hi_mstr->sm_str);
76 			} else {
77 				dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_SUFSTR),
78 				    strhash->hi_refcnt,
79 				    &strhash->hi_mstr->sm_str[stroff],
80 				    strhash->hi_mstr->sm_str);
81 			}
82 
83 			strhash = strhash->hi_next;
84 		}
85 	}
86 }
87 
88 void
89 Dbg_sec_in(Lm_list *lml, Is_desc *isp)
90 {
91 	const char	*str;
92 
93 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
94 		return;
95 
96 	if (isp->is_file != NULL)
97 		str = isp->is_file->ifl_name;
98 	else
99 		str = MSG_INTL(MSG_STR_NULL);
100 
101 	dbg_print(lml, MSG_INTL(MSG_SEC_INPUT), isp->is_name, str);
102 }
103 
104 void
105 Dbg_sec_added(Lm_list *lml, Os_desc *osp, Sg_desc *sgp)
106 {
107 	const char	*str;
108 
109 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
110 		return;
111 
112 	if (sgp->sg_name && *sgp->sg_name)
113 		str = sgp->sg_name;
114 	else
115 		str = MSG_INTL(MSG_STR_NULL);
116 
117 	dbg_print(lml, MSG_INTL(MSG_SEC_ADDED), osp->os_name, str);
118 }
119 
120 void
121 Dbg_sec_created(Lm_list *lml, Os_desc *osp, Sg_desc *sgp)
122 {
123 	const char	*str;
124 
125 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
126 		return;
127 
128 	if (sgp->sg_name && *sgp->sg_name)
129 		str = sgp->sg_name;
130 	else
131 		str = MSG_INTL(MSG_STR_NULL);
132 
133 	dbg_print(lml, MSG_INTL(MSG_SEC_CREATED), osp->os_name, str);
134 }
135 
136 void
137 Dbg_sec_discarded(Lm_list *lml, Is_desc *isp, Is_desc *disp)
138 {
139 	if (DBG_NOTCLASS(DBG_C_SECTIONS | DBG_C_UNUSED))
140 		return;
141 
142 	dbg_print(lml, MSG_INTL(MSG_SEC_DISCARDED), isp->is_basename,
143 	    isp->is_file->ifl_name, disp->is_basename,
144 	    disp->is_file->ifl_name);
145 }
146 
147 void
148 Dbg_sec_group(Lm_list *lml, Is_desc *isp, Group_desc *gdp)
149 {
150 	const char	*fmt;
151 
152 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
153 		return;
154 
155 	if (gdp->gd_flags & GRP_FLG_DISCARD)
156 		fmt = MSG_INTL(MSG_SEC_GRP_DISCARDED);
157 	else
158 		fmt = MSG_INTL(MSG_SEC_GRP_INPUT);
159 
160 	dbg_print(lml, fmt, isp->is_name, isp->is_file->ifl_name,
161 	    gdp->gd_gsectname, gdp->gd_symname);
162 }
163 
164 void
165 Dbg_sec_order_list(Ofl_desc *ofl, int flag)
166 {
167 	Os_desc		*osp;
168 	Is_desc		*isp1;
169 	Listnode	*lnp1, *lnp2;
170 	Lm_list		*lml = ofl->ofl_lml;
171 	const char	*str;
172 
173 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
174 		return;
175 	if (DBG_NOTDETAIL())
176 		return;
177 
178 	Dbg_util_nl(lml, DBG_NL_STD);
179 
180 	/*
181 	 * If the flag == 0, then the routine is called before sorting.
182 	 */
183 	if (flag == 0)
184 		str = MSG_INTL(MSG_ORD_SORT_BEFORE);
185 	else
186 		str = MSG_INTL(MSG_ORD_SORT_AFTER);
187 
188 	for (LIST_TRAVERSE(&ofl->ofl_ordered, lnp1, osp)) {
189 		Sort_desc	*sort = osp->os_sort;
190 
191 		dbg_print(lml, str, osp->os_name);
192 		dbg_print(lml, MSG_INTL(MSG_ORD_HDR_1),
193 		    EC_WORD(sort->st_beforecnt), EC_WORD(sort->st_aftercnt),
194 		    EC_WORD(sort->st_ordercnt));
195 
196 		for (LIST_TRAVERSE(&osp->os_isdescs, lnp2, isp1)) {
197 			Word		link;
198 			Ifl_desc	*ifl = isp1->is_file;
199 			Is_desc		*isp2;
200 			const char	*msg;
201 
202 			if ((isp1->is_flags & FLG_IS_ORDERED) == 0) {
203 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_0),
204 				    isp1->is_name, isp1->is_file->ifl_name);
205 				continue;
206 			}
207 
208 			if (isp1->is_shdr->sh_flags & SHF_ORDERED) {
209 				link = isp1->is_shdr->sh_info;
210 				msg = MSG_ORIG(MSG_SH_INFO);
211 			} else {
212 				/* SHF_LINK_ORDER */
213 				link = isp1->is_shdr->sh_link;
214 				msg = MSG_ORIG(MSG_SH_LINK);
215 			}
216 
217 			if (link == SHN_BEFORE) {
218 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_1),
219 				    isp1->is_name, isp1->is_file->ifl_name,
220 				    msg);
221 				continue;
222 			}
223 
224 			if (link == SHN_AFTER) {
225 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_2),
226 				    isp1->is_name, isp1->is_file->ifl_name,
227 				    msg);
228 				continue;
229 			}
230 
231 			isp2 = ifl->ifl_isdesc[link];
232 			dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_3),
233 			    isp1->is_name, ifl->ifl_name, msg, isp2->is_name,
234 			    isp2->is_key);
235 		}
236 	}
237 	Dbg_util_nl(lml, DBG_NL_STD);
238 }
239 
240 /*
241  * Error message string table.
242  */
243 static const Msg order_errors[] = {
244 	MSG_ORD_ERR_INFORANGE,		/* MSG_INTL(MSG_ORD_ERR_INFORANGE) */
245 	MSG_ORD_ERR_ORDER,		/* MSG_INTL(MSG_ORD_ERR_ORDER) */
246 	MSG_ORD_ERR_LINKRANGE,		/* MSG_INTL(MSG_ORD_ERR_LINKRANGE) */
247 	MSG_ORD_ERR_FLAGS,		/* MSG_INTL(MSG_ORD_ERR_FLAGS) */
248 	MSG_ORD_ERR_CYCLIC,		/* MSG_INTL(MSG_ORD_ERR_CYCLIC) */
249 	MSG_ORD_ERR_LINKINV		/* MSG_INTL(MSG_ORD_ERR_LINKINV) */
250 };
251 
252 void
253 Dbg_sec_order_error(Lm_list *lml, Ifl_desc *ifl, Word ndx, int error)
254 {
255 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
256 		return;
257 	if (DBG_NOTDETAIL())
258 		return;
259 
260 	if (error == 0)
261 		return;
262 
263 	dbg_print(lml, MSG_INTL(MSG_ORD_ERR_TITLE),
264 	    ifl->ifl_isdesc[ndx]->is_name, ifl->ifl_name);
265 
266 	if (error)
267 		dbg_print(lml, MSG_INTL(order_errors[error - 1]));
268 }
269