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