sections.c revision 2647:e440e3da2a6f
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 2006 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 */
35static 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
44void
45Dbg_sec_strtab(Lm_list *lml, Os_desc *osp, Str_tbl *stp)
46{
47	uint_t	i;
48
49	if (DBG_NOTCLASS(DBG_C_STRTAB))
50		return;
51
52	if (!osp)
53		return;
54
55	Dbg_util_nl(lml, DBG_NL_STD);
56	if (stp->st_flags & FLG_STTAB_COMPRESS)
57		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_COMP), osp->os_name,
58		    stp->st_fullstringsize, stp->st_stringsize);
59	else
60		dbg_print(lml, 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(lml, MSG_ORIG(MSG_STR_EMPTY));
68	dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_HD), osp->os_name,
69	    stp->st_hbckcnt);
70
71	for (i = 0; i < stp->st_hbckcnt; i++) {
72		Str_hash	*sthash;
73
74		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_BCKT), i);
75
76		for (sthash = stp->st_hashbcks[i]; sthash;
77		    sthash = sthash->hi_next) {
78			uint_t	stroff = sthash->hi_mstr->sm_stlen -
79			    sthash->hi_stlen;
80
81			if (stroff == 0) {
82				dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_MSTR),
83				    sthash->hi_refcnt, sthash->hi_mstr->sm_str);
84			} else {
85				dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_SUFSTR),
86				    sthash->hi_refcnt,
87				    &sthash->hi_mstr->sm_str[stroff],
88				    sthash->hi_mstr->sm_str);
89			}
90		}
91
92	}
93}
94
95void
96Dbg_sec_in(Lm_list *lml, Is_desc *isp)
97{
98	const char	*str;
99
100	if (DBG_NOTCLASS(DBG_C_SECTIONS))
101		return;
102
103	if (isp->is_file != NULL)
104		str = isp->is_file->ifl_name;
105	else
106		str = MSG_INTL(MSG_STR_NULL);
107
108	dbg_print(lml, MSG_INTL(MSG_SEC_INPUT), isp->is_name, str);
109}
110
111void
112Dbg_sec_added(Lm_list *lml, Os_desc *osp, Sg_desc *sgp)
113{
114	const char	*str;
115
116	if (DBG_NOTCLASS(DBG_C_SECTIONS))
117		return;
118
119	if (sgp->sg_name && *sgp->sg_name)
120		str = sgp->sg_name;
121	else
122		str = MSG_INTL(MSG_STR_NULL);
123
124	dbg_print(lml, MSG_INTL(MSG_SEC_ADDED), osp->os_name, str);
125}
126
127void
128Dbg_sec_created(Lm_list *lml, Os_desc *osp, Sg_desc *sgp)
129{
130	const char	*str;
131
132	if (DBG_NOTCLASS(DBG_C_SECTIONS))
133		return;
134
135	if (sgp->sg_name && *sgp->sg_name)
136		str = sgp->sg_name;
137	else
138		str = MSG_INTL(MSG_STR_NULL);
139
140	dbg_print(lml, MSG_INTL(MSG_SEC_CREATED), osp->os_name, str);
141}
142
143void
144Dbg_sec_discarded(Lm_list *lml, Is_desc *isp, Is_desc *disp)
145{
146	if (DBG_NOTCLASS(DBG_C_SECTIONS))
147		return;
148
149	dbg_print(lml, MSG_INTL(MSG_SEC_DISCARDED), isp->is_basename,
150	    isp->is_file->ifl_name, disp->is_basename,
151	    disp->is_file->ifl_name);
152}
153
154void
155Dbg_sec_group(Lm_list *lml, Is_desc *isp, Group_desc *gdp)
156{
157	const char	*fmt;
158
159	if (DBG_NOTCLASS(DBG_C_SECTIONS))
160		return;
161
162	if (gdp->gd_flags & GRP_FLG_DISCARD)
163		fmt = MSG_INTL(MSG_SEC_GRP_DISCARDED);
164	else
165		fmt = MSG_INTL(MSG_SEC_GRP_INPUT);
166
167	dbg_print(lml, fmt, isp->is_name, isp->is_file->ifl_name,
168	    gdp->gd_gsectname, gdp->gd_symname);
169}
170
171void
172Dbg_sec_order_list(Ofl_desc *ofl, int flag)
173{
174	Os_desc		*osp;
175	Is_desc		*isp1;
176	Listnode	*lnp1, *lnp2;
177	Lm_list		*lml = ofl->ofl_lml;
178	const char	*str;
179
180	if (DBG_NOTCLASS(DBG_C_SECTIONS))
181		return;
182	if (DBG_NOTDETAIL())
183		return;
184
185	Dbg_util_nl(lml, DBG_NL_STD);
186
187	/*
188	 * If the flag == 0, then the routine is called before sorting.
189	 */
190	if (flag == 0)
191		str = MSG_INTL(MSG_ORD_SORT_BEFORE);
192	else
193		str = MSG_INTL(MSG_ORD_SORT_AFTER);
194
195	for (LIST_TRAVERSE(&ofl->ofl_ordered, lnp1, osp)) {
196		Sort_desc	*sort = osp->os_sort;
197
198		dbg_print(lml, str, osp->os_name);
199		dbg_print(lml, MSG_INTL(MSG_ORD_HDR_1),
200		    EC_WORD(sort->st_beforecnt), EC_WORD(sort->st_aftercnt),
201		    EC_WORD(sort->st_ordercnt));
202
203		for (LIST_TRAVERSE(&osp->os_isdescs, lnp2, isp1)) {
204			Word		link;
205			Ifl_desc	*ifl = isp1->is_file;
206			Is_desc		*isp2;
207			const char	*msg;
208
209			if ((isp1->is_flags & FLG_IS_ORDERED) == 0) {
210				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_0),
211				    isp1->is_name, isp1->is_file->ifl_name);
212				continue;
213			}
214
215			if (isp1->is_shdr->sh_flags & SHF_ORDERED) {
216				link = isp1->is_shdr->sh_info;
217				msg = MSG_ORIG(MSG_SH_INFO);
218			} else {
219				/* SHF_LINK_ORDER */
220				link = isp1->is_shdr->sh_link;
221				msg = MSG_ORIG(MSG_SH_LINK);
222			}
223
224			if (link == SHN_BEFORE) {
225				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_1),
226				    isp1->is_name, isp1->is_file->ifl_name,
227				    msg);
228				continue;
229			}
230
231			if (link == SHN_AFTER) {
232				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_2),
233				    isp1->is_name, isp1->is_file->ifl_name,
234				    msg);
235				continue;
236			}
237
238			isp2 = ifl->ifl_isdesc[link];
239			dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_3),
240			    isp1->is_name, ifl->ifl_name, msg, isp2->is_name,
241			    isp2->is_key);
242		}
243	}
244	Dbg_util_nl(lml, DBG_NL_STD);
245}
246
247void
248Dbg_sec_order_error(Lm_list *lml, Ifl_desc *ifl, Word ndx, int error)
249{
250	if (DBG_NOTCLASS(DBG_C_SECTIONS))
251		return;
252	if (DBG_NOTDETAIL())
253		return;
254
255	if (error == 0)
256		return;
257
258	dbg_print(lml, MSG_INTL(MSG_ORD_ERR_TITLE),
259	    ifl->ifl_isdesc[ndx]->is_name, ifl->ifl_name);
260
261	if (error)
262		dbg_print(lml, MSG_INTL(order_errors[error - 1]));
263}
264