xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/sections.c (revision 49218d4f8e4d84d1c08aeb267bcf6e451f2056dc)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 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 
32 /*
33  * Error message string table.
34  */
35 static const Msg order_errors[] = {
36 	MSG_ORD_ERR_INFORANGE,		/* MSG_INTL(MSG_ORD_ERR_INFORANGE) */
37 	MSG_ORD_ERR_ORDER,		/* MSG_INTL(MSG_ORD_ERR_ORDER) */
38 	MSG_ORD_ERR_LINKRANGE,		/* MSG_INTL(MSG_ORD_ERR_LINKRANGE) */
39 	MSG_ORD_ERR_FLAGS,		/* MSG_INTL(MSG_ORD_ERR_FLAGS) */
40 	MSG_ORD_ERR_CYCLIC,		/* MSG_INTL(MSG_ORD_ERR_CYCLIC) */
41 	MSG_ORD_ERR_LINKINV		/* MSG_INTL(MSG_ORD_ERR_LINKINV) */
42 };
43 
44 void
45 Dbg_sec_strtab(Os_desc *osp, Str_tbl *stp)
46 {
47 	uint_t		i;
48 
49 	if (DBG_NOTCLASS(DBG_STRTAB))
50 		return;
51 
52 	if (!osp)
53 		return;
54 
55 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
56 	if (stp->st_flags & FLG_STTAB_COMPRESS)
57 		dbg_print(MSG_INTL(MSG_SEC_STRTAB_COMP), osp->os_name,
58 			stp->st_fullstringsize, stp->st_stringsize);
59 	else
60 		dbg_print(MSG_INTL(MSG_SEC_STRTAB_STND), osp->os_name,
61 			stp->st_fullstringsize);
62 
63 	if ((DBG_NOTDETAIL()) ||
64 	    ((stp->st_flags & FLG_STTAB_COMPRESS) == 0))
65 		return;
66 
67 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
68 	dbg_print(MSG_INTL(MSG_SEC_STRTAB_HD), osp->os_name,
69 		stp->st_hbckcnt);
70 	for (i = 0; i < stp->st_hbckcnt; i++) {
71 		Str_hash	*sthash;
72 		dbg_print(MSG_INTL(MSG_SEC_STRTAB_BCKT), i);
73 		for (sthash = stp->st_hashbcks[i]; sthash;
74 		    sthash = sthash->hi_next) {
75 			uint_t	stroff;
76 
77 			stroff = sthash->hi_mstr->sm_stlen - sthash->hi_stlen;
78 			if (stroff == 0) {
79 				dbg_print(MSG_INTL(MSG_SEC_STRTAB_MSTR),
80 					sthash->hi_refcnt,
81 					sthash->hi_mstr->sm_str);
82 			} else {
83 				const char	*str;
84 				str = &sthash->hi_mstr->sm_str[stroff];
85 				dbg_print(MSG_INTL(MSG_SEC_STRTAB_SUFSTR),
86 					sthash->hi_refcnt,
87 					str, sthash->hi_mstr->sm_str);
88 			}
89 		}
90 
91 	}
92 }
93 
94 void
95 Dbg_sec_in(Is_desc *isp)
96 {
97 	const char	*str;
98 
99 	if (DBG_NOTCLASS(DBG_SECTIONS))
100 		return;
101 
102 	if (isp->is_file != NULL)
103 		str = isp->is_file->ifl_name;
104 	else
105 		str = MSG_INTL(MSG_STR_NULL);
106 
107 	dbg_print(MSG_INTL(MSG_SEC_INPUT), isp->is_name, str);
108 }
109 
110 void
111 Dbg_sec_added(Os_desc *osp, Sg_desc *sgp)
112 {
113 	const char	*str;
114 
115 	if (DBG_NOTCLASS(DBG_SECTIONS))
116 		return;
117 
118 	if (sgp->sg_name && *sgp->sg_name)
119 		str = sgp->sg_name;
120 	else
121 		str = MSG_INTL(MSG_STR_NULL);
122 
123 	dbg_print(MSG_INTL(MSG_SEC_ADDED), osp->os_name, str);
124 }
125 
126 void
127 Dbg_sec_created(Os_desc *osp, Sg_desc *sgp)
128 {
129 	const char	*str;
130 
131 	if (DBG_NOTCLASS(DBG_SECTIONS))
132 		return;
133 
134 	if (sgp->sg_name && *sgp->sg_name)
135 		str = sgp->sg_name;
136 	else
137 		str = MSG_INTL(MSG_STR_NULL);
138 
139 	dbg_print(MSG_INTL(MSG_SEC_CREATED), osp->os_name, str);
140 }
141 
142 void
143 Dbg_sec_discarded(Is_desc *isp, Is_desc *disp)
144 {
145 	if (DBG_NOTCLASS(DBG_SECTIONS))
146 		return;
147 
148 	dbg_print(MSG_INTL(MSG_SEC_DISCARDED), isp->is_basename,
149 	    isp->is_file->ifl_name, disp->is_basename,
150 	    disp->is_file->ifl_name);
151 }
152 
153 void
154 Dbg_sec_group(Is_desc *isp, Group_desc *gdp)
155 {
156 	const char	*fmt;
157 
158 	if (DBG_NOTCLASS(DBG_SECTIONS))
159 		return;
160 
161 	if (gdp->gd_flags & GRP_FLG_DISCARD)
162 		fmt = MSG_INTL(MSG_SEC_GRP_DISCARDED);
163 	else
164 		fmt = MSG_INTL(MSG_SEC_GRP_INPUT);
165 
166 	dbg_print(fmt, isp->is_name, isp->is_file->ifl_name,
167 	    gdp->gd_gsectname, gdp->gd_symname);
168 }
169 
170 void
171 Dbg_sec_order_list(Ofl_desc *ofl, int flag)
172 {
173 	Os_desc		*osp;
174 	Is_desc		*isp1;
175 	Listnode	*lnp1, *lnp2;
176 	const char	*str;
177 
178 	if (DBG_NOTCLASS(DBG_SECTIONS))
179 		return;
180 	if (DBG_NOTDETAIL())
181 		return;
182 
183 	/*
184 	 * If the flag == 0, then the routine is called before sorting.
185 	 */
186 	if (flag == 0)
187 		str = MSG_INTL(MSG_ORD_SORT_BEFORE);
188 	else
189 		str = MSG_INTL(MSG_ORD_SORT_AFTER);
190 
191 	for (LIST_TRAVERSE(&ofl->ofl_ordered, lnp1, osp)) {
192 		Sort_desc	*sort = osp->os_sort;
193 
194 		dbg_print(str, osp->os_name);
195 		dbg_print(MSG_INTL(MSG_ORD_HDR_1),
196 		    EC_WORD(sort->st_beforecnt), EC_WORD(sort->st_aftercnt),
197 		    EC_WORD(sort->st_ordercnt));
198 
199 		for (LIST_TRAVERSE(&osp->os_isdescs, lnp2, isp1)) {
200 			Word			link;
201 			Ifl_desc		*ifl = isp1->is_file;
202 			Is_desc			*isp2;
203 			static const char	*msg;
204 
205 			if ((isp1->is_flags & FLG_IS_ORDERED) == 0) {
206 				dbg_print(MSG_INTL(MSG_ORD_TITLE_0),
207 				    isp1->is_name, isp1->is_file->ifl_name);
208 				continue;
209 			}
210 
211 			if (isp1->is_shdr->sh_flags & SHF_ORDERED) {
212 				link = isp1->is_shdr->sh_info;
213 				msg = MSG_INTL(MSG_ORD_TITLE_3);
214 			} else {
215 				/* SHF_LINK_ORDER */
216 				link = isp1->is_shdr->sh_link;
217 				msg = MSG_INTL(MSG_ORD_TITLE_4);
218 			}
219 
220 			if (link == SHN_BEFORE) {
221 				dbg_print(MSG_INTL(MSG_ORD_TITLE_1),
222 				    isp1->is_name, isp1->is_file->ifl_name);
223 				continue;
224 			}
225 
226 			if (link == SHN_AFTER) {
227 				dbg_print(MSG_INTL(MSG_ORD_TITLE_2),
228 				    isp1->is_name, isp1->is_file->ifl_name);
229 				continue;
230 			}
231 
232 			isp2 = ifl->ifl_isdesc[link];
233 			dbg_print(msg, isp1->is_name, ifl->ifl_name,
234 				isp2->is_name, isp2->is_key);
235 		}
236 	}
237 }
238 
239 void
240 Dbg_sec_order_error(Ifl_desc *ifl, Word ndx, int error)
241 {
242 	if (DBG_NOTCLASS(DBG_SECTIONS))
243 		return;
244 	if (DBG_NOTDETAIL())
245 		return;
246 
247 	if (error == 0)
248 		return;
249 
250 	dbg_print(MSG_INTL(MSG_ORD_ERR_TITLE),
251 		ifl->ifl_isdesc[ndx]->is_name, ifl->ifl_name);
252 
253 	if (error)
254 		dbg_print(MSG_INTL(order_errors[error - 1]));
255 }
256