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 2003 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)
155 {
156 	Group_desc	*gdesc = isp->is_group;
157 	if (DBG_NOTCLASS(DBG_SECTIONS))
158 		return;
159 	dbg_print(MSG_INTL(MSG_SEC_GRP), isp->is_name,
160 		isp->is_file->ifl_name, gdesc->gd_gsectname,
161 		gdesc->gd_symname);
162 }
163 
164 void
165 Dbg_sec_group_discarded(Is_desc *isp)
166 {
167 	Group_desc	*gdesc = isp->is_group;
168 	if (DBG_NOTCLASS(DBG_SECTIONS))
169 		return;
170 	dbg_print(MSG_INTL(MSG_SEC_GRP_DISCARDED), isp->is_name,
171 		isp->is_file->ifl_name, gdesc->gd_gsectname,
172 		gdesc->gd_symname);
173 }
174 
175 void
176 Dbg_sec_order_list(Ofl_desc *ofl, int flag)
177 {
178 	Os_desc		*osp;
179 	Is_desc		*isp1;
180 	Listnode	*lnp1, *lnp2;
181 	const char	*str;
182 
183 	if (DBG_NOTCLASS(DBG_SECTIONS))
184 		return;
185 	if (DBG_NOTDETAIL())
186 		return;
187 
188 	/*
189 	 * If the flag == 0, then the routine is called before sorting.
190 	 */
191 	if (flag == 0)
192 		str = MSG_INTL(MSG_ORD_SORT_BEFORE);
193 	else
194 		str = MSG_INTL(MSG_ORD_SORT_AFTER);
195 
196 	for (LIST_TRAVERSE(&ofl->ofl_ordered, lnp1, osp)) {
197 		Sort_desc	*sort = osp->os_sort;
198 
199 		dbg_print(str, osp->os_name);
200 		dbg_print(MSG_INTL(MSG_ORD_HDR_1),
201 		    EC_WORD(sort->st_beforecnt), EC_WORD(sort->st_aftercnt),
202 		    EC_WORD(sort->st_ordercnt));
203 
204 		for (LIST_TRAVERSE(&osp->os_isdescs, lnp2, isp1)) {
205 			Word			link;
206 			Ifl_desc		*ifl = isp1->is_file;
207 			Is_desc			*isp2;
208 			static const char	*msg;
209 
210 			if ((isp1->is_flags & FLG_IS_ORDERED) == 0) {
211 				dbg_print(MSG_INTL(MSG_ORD_TITLE_0),
212 				    isp1->is_name, isp1->is_file->ifl_name);
213 				continue;
214 			}
215 
216 			if (isp1->is_shdr->sh_flags & SHF_ORDERED) {
217 				link = isp1->is_shdr->sh_info;
218 				msg = MSG_INTL(MSG_ORD_TITLE_3);
219 			} else {
220 				/* SHF_LINK_ORDER */
221 				link = isp1->is_shdr->sh_link;
222 				msg = MSG_INTL(MSG_ORD_TITLE_4);
223 			}
224 
225 			if (link == SHN_BEFORE) {
226 				dbg_print(MSG_INTL(MSG_ORD_TITLE_1),
227 				    isp1->is_name, isp1->is_file->ifl_name);
228 				continue;
229 			}
230 
231 			if (link == SHN_AFTER) {
232 				dbg_print(MSG_INTL(MSG_ORD_TITLE_2),
233 				    isp1->is_name, isp1->is_file->ifl_name);
234 				continue;
235 			}
236 
237 			isp2 = ifl->ifl_isdesc[link];
238 			dbg_print(msg, isp1->is_name, ifl->ifl_name,
239 				isp2->is_name, isp2->is_key);
240 		}
241 	}
242 }
243 
244 void
245 Dbg_sec_order_error(Ifl_desc *ifl, Word ndx, int error)
246 {
247 	if (DBG_NOTCLASS(DBG_SECTIONS))
248 		return;
249 	if (DBG_NOTDETAIL())
250 		return;
251 
252 	if (error == 0)
253 		return;
254 
255 	dbg_print(MSG_INTL(MSG_ORD_ERR_TITLE),
256 		ifl->ifl_isdesc[ndx]->is_name, ifl->ifl_name);
257 
258 	if (error)
259 		dbg_print(MSG_INTL(order_errors[error - 1]));
260 }
261