17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
215aefb655Srie 
227c478bd9Sstevel@tonic-gate /*
23*69112eddSAli Bahrami  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24cc7efc4fSrie  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
26e23c41c9SAli Bahrami #include	<stdio.h>
277c478bd9Sstevel@tonic-gate #include	"msg.h"
287c478bd9Sstevel@tonic-gate #include	"_debug.h"
297c478bd9Sstevel@tonic-gate #include	"libld.h"
30a194faf8Srie #include	"_string_table.h"
317c478bd9Sstevel@tonic-gate 
32e23c41c9SAli Bahrami /*
33e23c41c9SAli Bahrami  * Format an input section descriptor name for output, in the format
34e23c41c9SAli Bahrami  *	[ndx]name
35e23c41c9SAli Bahrami  * If possible, a user supplied fixed size buffer is used. Failing that,
36e23c41c9SAli Bahrami  * dynamic memory is allocated, which must be freed by the caller.
37e23c41c9SAli Bahrami  *
38e23c41c9SAli Bahrami  * entry:
39e23c41c9SAli Bahrami  *	[dbg_fmt_isec_name2]: name, scnndx  - Name and section index
40e23c41c9SAli Bahrami  *	[dbg_fmt_isec_name]: isp - Input section descriptor giving name
41e23c41c9SAli Bahrami  *		and index.
42e23c41c9SAli Bahrami  *
43e23c41c9SAli Bahrami  *	buf - Caller supplied buffer
44e23c41c9SAli Bahrami  *	alloc_mem - Address of pointer to be set to address of allocated
45e23c41c9SAli Bahrami  *		memory, or NULL if no memory is allocated.
46e23c41c9SAli Bahrami  *
47e23c41c9SAli Bahrami  * exit:
48e23c41c9SAli Bahrami  *	A pointer to the formatted string is returned. If the supplied buffer
49e23c41c9SAli Bahrami  *	was sufficient, *alloc_mem is set to NULL. If memory was allocated,
50e23c41c9SAli Bahrami  *	*alloc_mem references it. The caller must free this memory after use.
51e23c41c9SAli Bahrami  */
52e23c41c9SAli Bahrami const char *
dbg_fmt_isec_name2(const char * name,Word scnndx,dbg_isec_name_buf_t buf,char ** alloc_mem)53e23c41c9SAli Bahrami dbg_fmt_isec_name2(const char *name, Word scnndx, dbg_isec_name_buf_t buf,
54e23c41c9SAli Bahrami     char **alloc_mem)
55e23c41c9SAli Bahrami {
56e23c41c9SAli Bahrami 	int	cnt;
57e23c41c9SAli Bahrami 
58e23c41c9SAli Bahrami 	/*
59e23c41c9SAli Bahrami 	 * If the section index is 0, it's not a real section.
60e23c41c9SAli Bahrami 	 * Just use the name as is.
61e23c41c9SAli Bahrami 	 */
62e23c41c9SAli Bahrami 	if (scnndx == 0) {
63e23c41c9SAli Bahrami 		*alloc_mem = NULL;
64e23c41c9SAli Bahrami 		return (name);
65e23c41c9SAli Bahrami 	}
66e23c41c9SAli Bahrami 
67e23c41c9SAli Bahrami 	/* Format into the fixed buffer */
68e23c41c9SAli Bahrami 	cnt = snprintf(buf, sizeof (dbg_isec_name_buf_t),
69e23c41c9SAli Bahrami 	    MSG_ORIG(MSG_FMT_ISEC_NAME), EC_WORD(scnndx), name);
70e23c41c9SAli Bahrami 
71e23c41c9SAli Bahrami 	/*
72e23c41c9SAli Bahrami 	 * If the name was too long, try to allocate a dynamic buffer.
73e23c41c9SAli Bahrami 	 * Failing that, fall through and use the clipped one already
74e23c41c9SAli Bahrami 	 * formatted into buf, as that's better than nothing.
75e23c41c9SAli Bahrami 	 */
76e23c41c9SAli Bahrami 	if ((cnt >= sizeof (dbg_isec_name_buf_t)) &&
77e23c41c9SAli Bahrami 	    ((*alloc_mem = malloc(cnt + 1)) != NULL)) {
78e23c41c9SAli Bahrami 		(void) snprintf(*alloc_mem, cnt + 1,
79e23c41c9SAli Bahrami 		    MSG_ORIG(MSG_FMT_ISEC_NAME), EC_WORD(scnndx), name);
80e23c41c9SAli Bahrami 		return (*alloc_mem);
81e23c41c9SAli Bahrami 	}
82e23c41c9SAli Bahrami 
83e23c41c9SAli Bahrami 	/* Return the caller supplied buffer */
84e23c41c9SAli Bahrami 	*alloc_mem = NULL;
85e23c41c9SAli Bahrami 	return (buf);
86e23c41c9SAli Bahrami }
87e23c41c9SAli Bahrami const char *
dbg_fmt_isec_name(Is_desc * isp,dbg_isec_name_buf_t buf,char ** alloc_mem)88e23c41c9SAli Bahrami dbg_fmt_isec_name(Is_desc *isp, dbg_isec_name_buf_t buf, char **alloc_mem)
89e23c41c9SAli Bahrami {
90e23c41c9SAli Bahrami 	return (dbg_fmt_isec_name2(isp->is_name, isp->is_scnndx, buf,
91e23c41c9SAli Bahrami 	    alloc_mem));
92e23c41c9SAli Bahrami }
93e23c41c9SAli Bahrami 
947c478bd9Sstevel@tonic-gate void
Dbg_sec_strtab(Lm_list * lml,Os_desc * osp,Str_tbl * stp)955aefb655Srie Dbg_sec_strtab(Lm_list *lml, Os_desc *osp, Str_tbl *stp)
967c478bd9Sstevel@tonic-gate {
97a194faf8Srie 	uint_t	cnt;
987c478bd9Sstevel@tonic-gate 
995aefb655Srie 	if (DBG_NOTCLASS(DBG_C_STRTAB))
1007c478bd9Sstevel@tonic-gate 		return;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	if (!osp)
1037c478bd9Sstevel@tonic-gate 		return;
1047c478bd9Sstevel@tonic-gate 
1057010c12aSrie 	Dbg_util_nl(lml, DBG_NL_STD);
1067c478bd9Sstevel@tonic-gate 	if (stp->st_flags & FLG_STTAB_COMPRESS)
1075aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_COMP), osp->os_name,
108cce0e03bSab 		    EC_XWORD(stp->st_fullstrsize), EC_XWORD(stp->st_strsize));
1097c478bd9Sstevel@tonic-gate 	else
1105aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_STND), osp->os_name,
111cce0e03bSab 		    EC_XWORD(stp->st_fullstrsize));
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	if ((DBG_NOTDETAIL()) ||
1147c478bd9Sstevel@tonic-gate 	    ((stp->st_flags & FLG_STTAB_COMPRESS) == 0))
1157c478bd9Sstevel@tonic-gate 		return;
1167c478bd9Sstevel@tonic-gate 
1175aefb655Srie 	dbg_print(lml, MSG_ORIG(MSG_STR_EMPTY));
1185aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_HD), osp->os_name,
1195aefb655Srie 	    stp->st_hbckcnt);
1205aefb655Srie 
121a194faf8Srie 	for (cnt = 0; cnt < stp->st_hbckcnt; cnt++) {
122a194faf8Srie 		Str_hash	*strhash = stp->st_hashbcks[cnt];
123a194faf8Srie 
124e23c41c9SAli Bahrami 		if (strhash == NULL)
125a194faf8Srie 			continue;
1265aefb655Srie 
127a194faf8Srie 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_BCKT), cnt);
1285aefb655Srie 
129a194faf8Srie 		while (strhash) {
130cce0e03bSab 			size_t	stroff = strhash->hi_mstr->sm_strlen -
131a194faf8Srie 			    strhash->hi_strlen;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 			if (stroff == 0) {
1345aefb655Srie 				dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_MSTR),
135cce0e03bSab 				    EC_XWORD(strhash->hi_refcnt),
136a194faf8Srie 				    strhash->hi_mstr->sm_str);
1377c478bd9Sstevel@tonic-gate 			} else {
1385aefb655Srie 				dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_SUFSTR),
139cce0e03bSab 				    EC_XWORD(strhash->hi_refcnt),
140a194faf8Srie 				    &strhash->hi_mstr->sm_str[stroff],
141a194faf8Srie 				    strhash->hi_mstr->sm_str);
1427c478bd9Sstevel@tonic-gate 			}
1437c478bd9Sstevel@tonic-gate 
144a194faf8Srie 			strhash = strhash->hi_next;
145a194faf8Srie 		}
1467c478bd9Sstevel@tonic-gate 	}
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate 
149cce0e03bSab void
Dbg_sec_genstr_compress(Lm_list * lml,const char * os_name,Xword raw_size,Xword merge_size)150cce0e03bSab Dbg_sec_genstr_compress(Lm_list *lml, const char *os_name,
151cce0e03bSab     Xword raw_size, Xword merge_size)
152cce0e03bSab {
153cce0e03bSab 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
154cce0e03bSab 		return;
155cce0e03bSab 
156cce0e03bSab 	dbg_print(lml, MSG_INTL(MSG_SEC_GENSTR_COMP), os_name,
157cce0e03bSab 	    EC_XWORD(raw_size), EC_XWORD(merge_size));
158cce0e03bSab }
159cce0e03bSab 
160cce0e03bSab void
Dbg_sec_unsup_strmerge(Lm_list * lml,Is_desc * isp)161cce0e03bSab Dbg_sec_unsup_strmerge(Lm_list *lml, Is_desc *isp)
162cce0e03bSab {
163e23c41c9SAli Bahrami 	dbg_isec_name_buf_t	buf;
164e23c41c9SAli Bahrami 	char			*alloc_mem;
165e23c41c9SAli Bahrami 	const char		*str;
166cce0e03bSab 
167cce0e03bSab 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
168cce0e03bSab 		return;
169cce0e03bSab 
170cce0e03bSab 	/*
171cce0e03bSab 	 * We can only merge string table sections with single byte
172cce0e03bSab 	 * (char) characters. For any other (wide) character types,
173cce0e03bSab 	 * issue a message so the user will understand why these
174cce0e03bSab 	 * sections are not being picked up.
175cce0e03bSab 	 */
176cce0e03bSab 	if ((isp->is_shdr->sh_entsize > 1) ||
177cce0e03bSab 	    (isp->is_shdr->sh_addralign > 1)) {
178cce0e03bSab 		str = (isp->is_file != NULL) ? isp->is_file->ifl_name :
179cce0e03bSab 		    MSG_INTL(MSG_STR_NULL);
180cce0e03bSab 		dbg_print(lml, MSG_INTL(MSG_SEC_STRMERGE_UNSUP),
181e23c41c9SAli Bahrami 		    dbg_fmt_isec_name(isp, buf, &alloc_mem), str,
182e23c41c9SAli Bahrami 		    EC_XWORD(isp->is_shdr->sh_addralign),
183cce0e03bSab 		    EC_XWORD(isp->is_shdr->sh_entsize));
184e23c41c9SAli Bahrami 		if (alloc_mem != NULL)
185e23c41c9SAli Bahrami 			free(alloc_mem);
186cce0e03bSab 	}
187cce0e03bSab }
188cce0e03bSab 
18957ef7aa9SRod Evans void
Dbg_sec_backing(Lm_list * lml)19057ef7aa9SRod Evans Dbg_sec_backing(Lm_list *lml)
19157ef7aa9SRod Evans {
19257ef7aa9SRod Evans 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
19357ef7aa9SRod Evans 		return;
19457ef7aa9SRod Evans 
19557ef7aa9SRod Evans 	Dbg_util_nl(lml, DBG_NL_STD);
19657ef7aa9SRod Evans 	dbg_print(lml, MSG_INTL(MSG_SEC_BACKING));
19757ef7aa9SRod Evans }
19857ef7aa9SRod Evans 
1997c478bd9Sstevel@tonic-gate void
Dbg_sec_in(Lm_list * lml,Is_desc * isp)2005aefb655Srie Dbg_sec_in(Lm_list *lml, Is_desc *isp)
2017c478bd9Sstevel@tonic-gate {
2025aefb655Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
2037c478bd9Sstevel@tonic-gate 		return;
2047c478bd9Sstevel@tonic-gate 
205cce0e03bSab 	if (isp->is_flags & FLG_IS_GNSTRMRG) {
206cce0e03bSab 		/*
207cce0e03bSab 		 * This section was generated because we have 1 or
208cce0e03bSab 		 * more SHF_MERGE|SHF_STRINGS input sections that we
209cce0e03bSab 		 * wish to merge. This new section will ultimately
210cce0e03bSab 		 * end up replacing those sections once it has been filled
211cce0e03bSab 		 * with their strings (merged and compressed) and relocations
212cce0e03bSab 		 * have been redirected.
213cce0e03bSab 		 */
214cce0e03bSab 		dbg_print(lml, MSG_INTL(MSG_SEC_INPUT_GENSTR), isp->is_name);
215e23c41c9SAli Bahrami 	} else if (isp->is_file == NULL) {
216e23c41c9SAli Bahrami 		/* Generated input section */
217e23c41c9SAli Bahrami 		dbg_print(lml, MSG_INTL(MSG_SEC_INPUT_GEN), isp->is_name);
218cce0e03bSab 	} else {
219cce0e03bSab 		/* Standard input section */
220e23c41c9SAli Bahrami 		dbg_isec_name_buf_t	buf;
221e23c41c9SAli Bahrami 		char			*alloc_mem;
222e23c41c9SAli Bahrami 
223e23c41c9SAli Bahrami 		dbg_print(lml, MSG_INTL(MSG_SEC_INPUT),
224e23c41c9SAli Bahrami 		    dbg_fmt_isec_name(isp, buf, &alloc_mem),
225e23c41c9SAli Bahrami 		    isp->is_file->ifl_name);
226e23c41c9SAli Bahrami 		if (alloc_mem != NULL)
227e23c41c9SAli Bahrami 			free(alloc_mem);
228cce0e03bSab 	}
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate void
Dbg_sec_added(Lm_list * lml,Os_desc * osp,Sg_desc * sgp)2325aefb655Srie Dbg_sec_added(Lm_list *lml, Os_desc *osp, Sg_desc *sgp)
2337c478bd9Sstevel@tonic-gate {
2345aefb655Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
2357c478bd9Sstevel@tonic-gate 		return;
2367c478bd9Sstevel@tonic-gate 
237*69112eddSAli Bahrami 	dbg_print(lml, MSG_INTL(MSG_SEC_ADDED), osp->os_name,
238*69112eddSAli Bahrami 	    (sgp->sg_name ? sgp->sg_name : MSG_INTL(MSG_STR_NULL)));
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate void
Dbg_sec_created(Lm_list * lml,Os_desc * osp,Sg_desc * sgp)2425aefb655Srie Dbg_sec_created(Lm_list *lml, Os_desc *osp, Sg_desc *sgp)
2437c478bd9Sstevel@tonic-gate {
2445aefb655Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
2457c478bd9Sstevel@tonic-gate 		return;
2467c478bd9Sstevel@tonic-gate 
247*69112eddSAli Bahrami 	dbg_print(lml, MSG_INTL(MSG_SEC_CREATED), osp->os_name,
248*69112eddSAli Bahrami 	    (sgp->sg_name ? sgp->sg_name : MSG_INTL(MSG_STR_NULL)));
2497c478bd9Sstevel@tonic-gate }
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate void
Dbg_sec_discarded(Lm_list * lml,Is_desc * isp,Is_desc * disp)2525aefb655Srie Dbg_sec_discarded(Lm_list *lml, Is_desc *isp, Is_desc *disp)
2537c478bd9Sstevel@tonic-gate {
254a194faf8Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS | DBG_C_UNUSED))
2557c478bd9Sstevel@tonic-gate 		return;
2567c478bd9Sstevel@tonic-gate 
257cce0e03bSab 	if ((isp->is_flags & FLG_IS_INSTRMRG) &&
258cce0e03bSab 	    (disp->is_flags & FLG_IS_GNSTRMRG)) {
259cce0e03bSab 		/*
260cce0e03bSab 		 * This SHF_MERGE|SHF_STRINGS input section is being
261cce0e03bSab 		 * discarded in favor of the generated merged string section.
262cce0e03bSab 		 */
263e23c41c9SAli Bahrami 		dbg_isec_name_buf_t	buf;
264e23c41c9SAli Bahrami 		char			*alloc_mem;
265e23c41c9SAli Bahrami 
266cce0e03bSab 		dbg_print(lml, MSG_INTL(MSG_SEC_STRMERGE_DISCARDED),
267e23c41c9SAli Bahrami 		    dbg_fmt_isec_name(isp, buf, &alloc_mem),
268e23c41c9SAli Bahrami 		    isp->is_file->ifl_name);
269e23c41c9SAli Bahrami 		if (alloc_mem != NULL)
270e23c41c9SAli Bahrami 			free(alloc_mem);
271cce0e03bSab 	} else {
272cce0e03bSab 		/* Generic section discard */
273e23c41c9SAli Bahrami 		dbg_isec_name_buf_t	buf1, buf2;
274e23c41c9SAli Bahrami 		char			*alloc_mem1, *alloc_mem2;
275e23c41c9SAli Bahrami 
276e23c41c9SAli Bahrami 		dbg_print(lml, MSG_INTL(MSG_SEC_DISCARDED),
277e23c41c9SAli Bahrami 		    dbg_fmt_isec_name(isp, buf1, &alloc_mem1),
278e23c41c9SAli Bahrami 		    isp->is_file->ifl_name,
279e23c41c9SAli Bahrami 		    dbg_fmt_isec_name(disp, buf2, &alloc_mem2),
280cce0e03bSab 		    disp->is_file->ifl_name);
281e23c41c9SAli Bahrami 		if (alloc_mem1 != NULL)
282e23c41c9SAli Bahrami 			free(alloc_mem1);
283e23c41c9SAli Bahrami 		if (alloc_mem2 != NULL)
284e23c41c9SAli Bahrami 			free(alloc_mem2);
285cce0e03bSab 	}
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate void
Dbg_sec_group(Lm_list * lml,Is_desc * isp,Group_desc * gdp)2895aefb655Srie Dbg_sec_group(Lm_list *lml, Is_desc *isp, Group_desc *gdp)
2907c478bd9Sstevel@tonic-gate {
291e23c41c9SAli Bahrami 	dbg_isec_name_buf_t	buf;
292e23c41c9SAli Bahrami 	char			*alloc_mem;
293e23c41c9SAli Bahrami 	const char		*comdat, *isp_str;
2947c478bd9Sstevel@tonic-gate 
2955aefb655Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
2967c478bd9Sstevel@tonic-gate 		return;
297cc7efc4fSrie 
2980e233487SRod Evans 	if (gdp->gd_data[0] & GRP_COMDAT)
2990e233487SRod Evans 		comdat = MSG_ORIG(MSG_STR_COMDAT);
300cc7efc4fSrie 	else
3010e233487SRod Evans 		comdat = MSG_ORIG(MSG_STR_EMPTY);
3020e233487SRod Evans 
303e23c41c9SAli Bahrami 	isp_str = dbg_fmt_isec_name(isp, buf, &alloc_mem);
304e23c41c9SAli Bahrami 
3050e233487SRod Evans 	if (isp->is_shdr->sh_type == SHT_GROUP) {
306e23c41c9SAli Bahrami 		dbg_print(lml, MSG_INTL(MSG_SEC_GRP_DEFINE), isp_str,
3070e233487SRod Evans 		    isp->is_file->ifl_name, comdat, gdp->gd_name);
3080e233487SRod Evans 	} else {
309e23c41c9SAli Bahrami 		dbg_print(lml, MSG_INTL(MSG_SEC_GRP_MEMBER), isp_str,
3100e233487SRod Evans 		    isp->is_file->ifl_name, comdat, gdp->gd_name);
3110e233487SRod Evans 	}
312cc7efc4fSrie 
3130e233487SRod Evans 	if (gdp->gd_oisc) {
314e23c41c9SAli Bahrami 		dbg_print(lml, MSG_INTL(MSG_SEC_GRP_DISCARDED), isp_str,
3150e233487SRod Evans 		    isp->is_file->ifl_name, gdp->gd_name,
3160e233487SRod Evans 		    gdp->gd_oisc->is_file->ifl_name);
3170e233487SRod Evans 	}
318e23c41c9SAli Bahrami 
319e23c41c9SAli Bahrami 	if (alloc_mem != NULL)
320e23c41c9SAli Bahrami 		free(alloc_mem);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate void
Dbg_sec_order_list(Ofl_desc * ofl,int flag)3247c478bd9Sstevel@tonic-gate Dbg_sec_order_list(Ofl_desc *ofl, int flag)
3257c478bd9Sstevel@tonic-gate {
3267c478bd9Sstevel@tonic-gate 	Os_desc		*osp;
3277c478bd9Sstevel@tonic-gate 	Is_desc		*isp1;
32857ef7aa9SRod Evans 	Aliste		idx1;
3295aefb655Srie 	Lm_list		*lml = ofl->ofl_lml;
3307c478bd9Sstevel@tonic-gate 	const char	*str;
3317c478bd9Sstevel@tonic-gate 
3325aefb655Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
3337c478bd9Sstevel@tonic-gate 		return;
3347c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
3357c478bd9Sstevel@tonic-gate 		return;
3367c478bd9Sstevel@tonic-gate 
3377010c12aSrie 	Dbg_util_nl(lml, DBG_NL_STD);
3387010c12aSrie 
3397c478bd9Sstevel@tonic-gate 	/*
3407c478bd9Sstevel@tonic-gate 	 * If the flag == 0, then the routine is called before sorting.
3417c478bd9Sstevel@tonic-gate 	 */
3427c478bd9Sstevel@tonic-gate 	if (flag == 0)
3437c478bd9Sstevel@tonic-gate 		str = MSG_INTL(MSG_ORD_SORT_BEFORE);
3447c478bd9Sstevel@tonic-gate 	else
3457c478bd9Sstevel@tonic-gate 		str = MSG_INTL(MSG_ORD_SORT_AFTER);
3467c478bd9Sstevel@tonic-gate 
34757ef7aa9SRod Evans 	for (APLIST_TRAVERSE(ofl->ofl_ordered, idx1, osp)) {
3481dd9d86fSAli Bahrami 		int		os_isdescs_idx;
34957ef7aa9SRod Evans 		Aliste		idx2;
3507c478bd9Sstevel@tonic-gate 
351e23c41c9SAli Bahrami 		Dbg_util_nl(lml, DBG_NL_STD);
3525aefb655Srie 		dbg_print(lml, str, osp->os_name);
3535aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_ORD_HDR_1),
3541dd9d86fSAli Bahrami 		    EC_WORD(aplist_nitems(osp->os_isdescs[OS_ISD_BEFORE])),
3551dd9d86fSAli Bahrami 		    EC_WORD(aplist_nitems(osp->os_isdescs[OS_ISD_ORDERED])),
3561dd9d86fSAli Bahrami 		    EC_WORD(aplist_nitems(osp->os_isdescs[OS_ISD_DEFAULT])),
3571dd9d86fSAli Bahrami 		    EC_WORD(aplist_nitems(osp->os_isdescs[OS_ISD_AFTER])));
3587c478bd9Sstevel@tonic-gate 
3591dd9d86fSAli Bahrami 		OS_ISDESCS_TRAVERSE(os_isdescs_idx, osp, idx2, isp1) {
360e23c41c9SAli Bahrami 			dbg_isec_name_buf_t	buf;
361e23c41c9SAli Bahrami 			char			*alloc_mem;
362e23c41c9SAli Bahrami 			const char		*isp1_str;
363e23c41c9SAli Bahrami 			Word			link;
364e23c41c9SAli Bahrami 			Ifl_desc		*ifl = isp1->is_file;
365e23c41c9SAli Bahrami 			Is_desc			*isp2;
366e23c41c9SAli Bahrami 			const char		*msg;
367e23c41c9SAli Bahrami 
368e23c41c9SAli Bahrami 			/*
369604635faSRod Evans 			 * An output segment that requires ordering might have
370604635faSRod Evans 			 * as little as two sorted input sections.  For example,
371604635faSRod Evans 			 * the crt's can provide a SHN_BEGIN and SHN_AFTER, and
372604635faSRod Evans 			 * only these two sections must be processed.  Thus, if
373604635faSRod Evans 			 * a input section is unordered, move on.  Diagnosing
374604635faSRod Evans 			 * any unsorted section can produce way too much noise.
375e23c41c9SAli Bahrami 			 */
376604635faSRod Evans 			if ((isp1->is_flags & FLG_IS_ORDERED) == 0)
3777c478bd9Sstevel@tonic-gate 				continue;
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 			if (isp1->is_shdr->sh_flags & SHF_ORDERED) {
3807c478bd9Sstevel@tonic-gate 				link = isp1->is_shdr->sh_info;
3817010c12aSrie 				msg = MSG_ORIG(MSG_SH_INFO);
382e23c41c9SAli Bahrami 			} else {	/* SHF_LINK_ORDER */
3837c478bd9Sstevel@tonic-gate 				link = isp1->is_shdr->sh_link;
3847010c12aSrie 				msg = MSG_ORIG(MSG_SH_LINK);
3857c478bd9Sstevel@tonic-gate 			}
3867c478bd9Sstevel@tonic-gate 
387e23c41c9SAli Bahrami 			isp1_str = dbg_fmt_isec_name(isp1, buf, &alloc_mem);
3887c478bd9Sstevel@tonic-gate 
389e23c41c9SAli Bahrami 			if (link == SHN_BEFORE) {
390e23c41c9SAli Bahrami 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_1), msg,
391e23c41c9SAli Bahrami 				    isp1_str, isp1->is_file->ifl_name);
392e23c41c9SAli Bahrami 			} else if (link == SHN_AFTER) {
393e23c41c9SAli Bahrami 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_2), msg,
394e23c41c9SAli Bahrami 				    isp1_str, isp1->is_file->ifl_name);
395e23c41c9SAli Bahrami 			} else {
396e23c41c9SAli Bahrami 				isp2 = ifl->ifl_isdesc[link];
397e23c41c9SAli Bahrami 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_3),
398e23c41c9SAli Bahrami 				    EC_WORD(isp2->is_keyident), isp1_str,
399e23c41c9SAli Bahrami 				    ifl->ifl_name, msg, isp2->is_name);
4007c478bd9Sstevel@tonic-gate 			}
401e23c41c9SAli Bahrami 			if (alloc_mem != NULL)
402e23c41c9SAli Bahrami 				free(alloc_mem);
4037c478bd9Sstevel@tonic-gate 		}
4047c478bd9Sstevel@tonic-gate 	}
4057010c12aSrie 	Dbg_util_nl(lml, DBG_NL_STD);
4067c478bd9Sstevel@tonic-gate }
4077c478bd9Sstevel@tonic-gate 
408a194faf8Srie /*
409a194faf8Srie  * Error message string table.
410a194faf8Srie  */
411a194faf8Srie static const Msg order_errors[] = {
412a194faf8Srie 	MSG_ORD_ERR_INFORANGE,		/* MSG_INTL(MSG_ORD_ERR_INFORANGE) */
413a194faf8Srie 	MSG_ORD_ERR_ORDER,		/* MSG_INTL(MSG_ORD_ERR_ORDER) */
414a194faf8Srie 	MSG_ORD_ERR_LINKRANGE,		/* MSG_INTL(MSG_ORD_ERR_LINKRANGE) */
415a194faf8Srie 	MSG_ORD_ERR_FLAGS,		/* MSG_INTL(MSG_ORD_ERR_FLAGS) */
416a194faf8Srie 	MSG_ORD_ERR_CYCLIC,		/* MSG_INTL(MSG_ORD_ERR_CYCLIC) */
417a194faf8Srie 	MSG_ORD_ERR_LINKINV		/* MSG_INTL(MSG_ORD_ERR_LINKINV) */
418a194faf8Srie };
419a194faf8Srie 
4207c478bd9Sstevel@tonic-gate void
Dbg_sec_order_error(Lm_list * lml,Ifl_desc * ifl,Word ndx,int error)4215aefb655Srie Dbg_sec_order_error(Lm_list *lml, Ifl_desc *ifl, Word ndx, int error)
4227c478bd9Sstevel@tonic-gate {
423e23c41c9SAli Bahrami 	dbg_isec_name_buf_t	buf;
424e23c41c9SAli Bahrami 	char			*alloc_mem;
425e23c41c9SAli Bahrami 
4265aefb655Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
4277c478bd9Sstevel@tonic-gate 		return;
4287c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
4297c478bd9Sstevel@tonic-gate 		return;
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	if (error == 0)
4327c478bd9Sstevel@tonic-gate 		return;
4337c478bd9Sstevel@tonic-gate 
4345aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_ORD_ERR_TITLE),
435e23c41c9SAli Bahrami 	    dbg_fmt_isec_name(ifl->ifl_isdesc[ndx], buf, &alloc_mem),
436e23c41c9SAli Bahrami 	    ifl->ifl_name);
437e23c41c9SAli Bahrami 	if (alloc_mem != NULL)
438e23c41c9SAli Bahrami 		free(alloc_mem);
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate 	if (error)
4415aefb655Srie 		dbg_print(lml, MSG_INTL(order_errors[error - 1]));
4427c478bd9Sstevel@tonic-gate }
4430e233487SRod Evans 
4440e233487SRod Evans void
Dbg_sec_redirected(Lm_list * lml,Is_desc * isp,const char * nname)445e23c41c9SAli Bahrami Dbg_sec_redirected(Lm_list *lml, Is_desc *isp, const char *nname)
4460e233487SRod Evans {
447e23c41c9SAli Bahrami 	dbg_isec_name_buf_t	buf;
448e23c41c9SAli Bahrami 	char			*alloc_mem;
449e23c41c9SAli Bahrami 
4500e233487SRod Evans 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
4510e233487SRod Evans 		return;
4520e233487SRod Evans 
453e23c41c9SAli Bahrami 	dbg_print(lml, MSG_INTL(MSG_SEC_REDIRECTED),
454e23c41c9SAli Bahrami 	    dbg_fmt_isec_name(isp, buf, &alloc_mem), nname);
455e23c41c9SAli Bahrami 	if (alloc_mem != NULL)
456e23c41c9SAli Bahrami 		free(alloc_mem);
4570e233487SRod Evans }
4580e233487SRod Evans 
4590e233487SRod Evans void
Dbg_sec_gnu_comdat(Lm_list * lml,Is_desc * isp,Boolean comdat,Boolean relax)460e64d0ff9SAli Bahrami Dbg_sec_gnu_comdat(Lm_list *lml, Is_desc *isp, Boolean comdat, Boolean relax)
4610e233487SRod Evans {
462e23c41c9SAli Bahrami 	dbg_isec_name_buf_t	buf;
463e23c41c9SAli Bahrami 	char			*alloc_mem;
464e23c41c9SAli Bahrami 	const char		*fmt;
4650e233487SRod Evans 
4660e233487SRod Evans 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
4670e233487SRod Evans 		return;
4680e233487SRod Evans 
4690e233487SRod Evans 	if (comdat && relax)
4700e233487SRod Evans 		fmt = MSG_INTL(MSG_SEC_GNU_COMDAT_1);
4710e233487SRod Evans 	else if (comdat)
4720e233487SRod Evans 		fmt = MSG_INTL(MSG_SEC_GNU_COMDAT_2);
4730e233487SRod Evans 	else
4740e233487SRod Evans 		fmt = MSG_INTL(MSG_SEC_GNU_COMDAT_3);
4750e233487SRod Evans 
476e23c41c9SAli Bahrami 	dbg_print(lml, fmt, dbg_fmt_isec_name(isp, buf, &alloc_mem));
477e23c41c9SAli Bahrami 	if (alloc_mem != NULL)
478e23c41c9SAli Bahrami 		free(alloc_mem);
4790e233487SRod Evans }
480