10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211618Srie 
220Sstevel@tonic-gate /*
239131SRod.Evans@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2433Srie  * Use is subject to license terms.
250Sstevel@tonic-gate  */
26*9406SAli.Bahrami@Sun.COM #include	<stdio.h>
270Sstevel@tonic-gate #include	"msg.h"
280Sstevel@tonic-gate #include	"_debug.h"
290Sstevel@tonic-gate #include	"libld.h"
305549Srie #include	"_string_table.h"
310Sstevel@tonic-gate 
32*9406SAli.Bahrami@Sun.COM /*
33*9406SAli.Bahrami@Sun.COM  * Format an input section descriptor name for output, in the format
34*9406SAli.Bahrami@Sun.COM  *	[ndx]name
35*9406SAli.Bahrami@Sun.COM  * If possible, a user supplied fixed size buffer is used. Failing that,
36*9406SAli.Bahrami@Sun.COM  * dynamic memory is allocated, which must be freed by the caller.
37*9406SAli.Bahrami@Sun.COM  *
38*9406SAli.Bahrami@Sun.COM  * entry:
39*9406SAli.Bahrami@Sun.COM  *	[dbg_fmt_isec_name2]: name, scnndx  - Name and section index
40*9406SAli.Bahrami@Sun.COM  *	[dbg_fmt_isec_name]: isp - Input section descriptor giving name
41*9406SAli.Bahrami@Sun.COM  *		and index.
42*9406SAli.Bahrami@Sun.COM  *
43*9406SAli.Bahrami@Sun.COM  *	buf - Caller supplied buffer
44*9406SAli.Bahrami@Sun.COM  *	alloc_mem - Address of pointer to be set to address of allocated
45*9406SAli.Bahrami@Sun.COM  *		memory, or NULL if no memory is allocated.
46*9406SAli.Bahrami@Sun.COM  *
47*9406SAli.Bahrami@Sun.COM  * exit:
48*9406SAli.Bahrami@Sun.COM  *	A pointer to the formatted string is returned. If the supplied buffer
49*9406SAli.Bahrami@Sun.COM  *	was sufficient, *alloc_mem is set to NULL. If memory was allocated,
50*9406SAli.Bahrami@Sun.COM  *	*alloc_mem references it. The caller must free this memory after use.
51*9406SAli.Bahrami@Sun.COM  */
52*9406SAli.Bahrami@Sun.COM const char *
53*9406SAli.Bahrami@Sun.COM dbg_fmt_isec_name2(const char *name, Word scnndx, dbg_isec_name_buf_t buf,
54*9406SAli.Bahrami@Sun.COM     char **alloc_mem)
55*9406SAli.Bahrami@Sun.COM {
56*9406SAli.Bahrami@Sun.COM 	int	cnt;
57*9406SAli.Bahrami@Sun.COM 
58*9406SAli.Bahrami@Sun.COM 	/*
59*9406SAli.Bahrami@Sun.COM 	 * If the section index is 0, it's not a real section.
60*9406SAli.Bahrami@Sun.COM 	 * Just use the name as is.
61*9406SAli.Bahrami@Sun.COM 	 */
62*9406SAli.Bahrami@Sun.COM 	if (scnndx == 0) {
63*9406SAli.Bahrami@Sun.COM 		*alloc_mem = NULL;
64*9406SAli.Bahrami@Sun.COM 		return (name);
65*9406SAli.Bahrami@Sun.COM 	}
66*9406SAli.Bahrami@Sun.COM 
67*9406SAli.Bahrami@Sun.COM 	/* Format into the fixed buffer */
68*9406SAli.Bahrami@Sun.COM 	cnt = snprintf(buf, sizeof (dbg_isec_name_buf_t),
69*9406SAli.Bahrami@Sun.COM 	    MSG_ORIG(MSG_FMT_ISEC_NAME), EC_WORD(scnndx), name);
70*9406SAli.Bahrami@Sun.COM 
71*9406SAli.Bahrami@Sun.COM 	/*
72*9406SAli.Bahrami@Sun.COM 	 * If the name was too long, try to allocate a dynamic buffer.
73*9406SAli.Bahrami@Sun.COM 	 * Failing that, fall through and use the clipped one already
74*9406SAli.Bahrami@Sun.COM 	 * formatted into buf, as that's better than nothing.
75*9406SAli.Bahrami@Sun.COM 	 */
76*9406SAli.Bahrami@Sun.COM 	if ((cnt >= sizeof (dbg_isec_name_buf_t)) &&
77*9406SAli.Bahrami@Sun.COM 	    ((*alloc_mem = malloc(cnt + 1)) != NULL)) {
78*9406SAli.Bahrami@Sun.COM 		(void) snprintf(*alloc_mem, cnt + 1,
79*9406SAli.Bahrami@Sun.COM 		    MSG_ORIG(MSG_FMT_ISEC_NAME), EC_WORD(scnndx), name);
80*9406SAli.Bahrami@Sun.COM 		return (*alloc_mem);
81*9406SAli.Bahrami@Sun.COM 	}
82*9406SAli.Bahrami@Sun.COM 
83*9406SAli.Bahrami@Sun.COM 	/* Return the caller supplied buffer */
84*9406SAli.Bahrami@Sun.COM 	*alloc_mem = NULL;
85*9406SAli.Bahrami@Sun.COM 	return (buf);
86*9406SAli.Bahrami@Sun.COM }
87*9406SAli.Bahrami@Sun.COM const char *
88*9406SAli.Bahrami@Sun.COM dbg_fmt_isec_name(Is_desc *isp, dbg_isec_name_buf_t buf, char **alloc_mem)
89*9406SAli.Bahrami@Sun.COM {
90*9406SAli.Bahrami@Sun.COM 	return (dbg_fmt_isec_name2(isp->is_name, isp->is_scnndx, buf,
91*9406SAli.Bahrami@Sun.COM 	    alloc_mem));
92*9406SAli.Bahrami@Sun.COM }
93*9406SAli.Bahrami@Sun.COM 
940Sstevel@tonic-gate void
951618Srie Dbg_sec_strtab(Lm_list *lml, Os_desc *osp, Str_tbl *stp)
960Sstevel@tonic-gate {
975549Srie 	uint_t	cnt;
980Sstevel@tonic-gate 
991618Srie 	if (DBG_NOTCLASS(DBG_C_STRTAB))
1000Sstevel@tonic-gate 		return;
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	if (!osp)
1030Sstevel@tonic-gate 		return;
1040Sstevel@tonic-gate 
1052647Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1060Sstevel@tonic-gate 	if (stp->st_flags & FLG_STTAB_COMPRESS)
1071618Srie 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_COMP), osp->os_name,
1085892Sab196087 		    EC_XWORD(stp->st_fullstrsize), EC_XWORD(stp->st_strsize));
1090Sstevel@tonic-gate 	else
1101618Srie 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_STND), osp->os_name,
1115892Sab196087 		    EC_XWORD(stp->st_fullstrsize));
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	if ((DBG_NOTDETAIL()) ||
1140Sstevel@tonic-gate 	    ((stp->st_flags & FLG_STTAB_COMPRESS) == 0))
1150Sstevel@tonic-gate 		return;
1160Sstevel@tonic-gate 
1171618Srie 	dbg_print(lml, MSG_ORIG(MSG_STR_EMPTY));
1181618Srie 	dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_HD), osp->os_name,
1191618Srie 	    stp->st_hbckcnt);
1201618Srie 
1215549Srie 	for (cnt = 0; cnt < stp->st_hbckcnt; cnt++) {
1225549Srie 		Str_hash	*strhash = stp->st_hashbcks[cnt];
1231618Srie 
124*9406SAli.Bahrami@Sun.COM 		if (strhash == NULL)
1255549Srie 			continue;
1261618Srie 
1275549Srie 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_BCKT), cnt);
1285549Srie 
1295549Srie 		while (strhash) {
1305892Sab196087 			size_t	stroff = strhash->hi_mstr->sm_strlen -
1315549Srie 			    strhash->hi_strlen;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 			if (stroff == 0) {
1341618Srie 				dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_MSTR),
1355892Sab196087 				    EC_XWORD(strhash->hi_refcnt),
1365549Srie 				    strhash->hi_mstr->sm_str);
1370Sstevel@tonic-gate 			} else {
1381618Srie 				dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_SUFSTR),
1395892Sab196087 				    EC_XWORD(strhash->hi_refcnt),
1405549Srie 				    &strhash->hi_mstr->sm_str[stroff],
1415549Srie 				    strhash->hi_mstr->sm_str);
1420Sstevel@tonic-gate 			}
1435549Srie 
1445549Srie 			strhash = strhash->hi_next;
1450Sstevel@tonic-gate 		}
1460Sstevel@tonic-gate 	}
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate void
1505892Sab196087 Dbg_sec_genstr_compress(Lm_list *lml, const char *os_name,
1515892Sab196087     Xword raw_size, Xword merge_size)
1525892Sab196087 {
1535892Sab196087 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
1545892Sab196087 		return;
1555892Sab196087 
1565892Sab196087 	dbg_print(lml, MSG_INTL(MSG_SEC_GENSTR_COMP), os_name,
1575892Sab196087 	    EC_XWORD(raw_size), EC_XWORD(merge_size));
1585892Sab196087 }
1595892Sab196087 
1605892Sab196087 void
1615892Sab196087 Dbg_sec_unsup_strmerge(Lm_list *lml, Is_desc *isp)
1625892Sab196087 {
163*9406SAli.Bahrami@Sun.COM 	dbg_isec_name_buf_t	buf;
164*9406SAli.Bahrami@Sun.COM 	char			*alloc_mem;
165*9406SAli.Bahrami@Sun.COM 	const char		*str;
1665892Sab196087 
1675892Sab196087 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
1685892Sab196087 		return;
1695892Sab196087 
1705892Sab196087 	/*
1715892Sab196087 	 * We can only merge string table sections with single byte
1725892Sab196087 	 * (char) characters. For any other (wide) character types,
1735892Sab196087 	 * issue a message so the user will understand why these
1745892Sab196087 	 * sections are not being picked up.
1755892Sab196087 	 */
1765892Sab196087 	if ((isp->is_shdr->sh_entsize > 1) ||
1775892Sab196087 	    (isp->is_shdr->sh_addralign > 1)) {
1785892Sab196087 		str = (isp->is_file != NULL) ? isp->is_file->ifl_name :
1795892Sab196087 		    MSG_INTL(MSG_STR_NULL);
1805892Sab196087 		dbg_print(lml, MSG_INTL(MSG_SEC_STRMERGE_UNSUP),
181*9406SAli.Bahrami@Sun.COM 		    dbg_fmt_isec_name(isp, buf, &alloc_mem), str,
182*9406SAli.Bahrami@Sun.COM 		    EC_XWORD(isp->is_shdr->sh_addralign),
1835892Sab196087 		    EC_XWORD(isp->is_shdr->sh_entsize));
184*9406SAli.Bahrami@Sun.COM 		if (alloc_mem != NULL)
185*9406SAli.Bahrami@Sun.COM 			free(alloc_mem);
1865892Sab196087 	}
1875892Sab196087 }
1885892Sab196087 
1895892Sab196087 void
1909131SRod.Evans@Sun.COM Dbg_sec_backing(Lm_list *lml)
1919131SRod.Evans@Sun.COM {
1929131SRod.Evans@Sun.COM 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
1939131SRod.Evans@Sun.COM 		return;
1949131SRod.Evans@Sun.COM 
1959131SRod.Evans@Sun.COM 	Dbg_util_nl(lml, DBG_NL_STD);
1969131SRod.Evans@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_SEC_BACKING));
1979131SRod.Evans@Sun.COM }
1989131SRod.Evans@Sun.COM 
1999131SRod.Evans@Sun.COM void
2001618Srie Dbg_sec_in(Lm_list *lml, Is_desc *isp)
2010Sstevel@tonic-gate {
2021618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
2030Sstevel@tonic-gate 		return;
2040Sstevel@tonic-gate 
2055892Sab196087 	if (isp->is_flags & FLG_IS_GNSTRMRG) {
2065892Sab196087 		/*
2075892Sab196087 		 * This section was generated because we have 1 or
2085892Sab196087 		 * more SHF_MERGE|SHF_STRINGS input sections that we
2095892Sab196087 		 * wish to merge. This new section will ultimately
2105892Sab196087 		 * end up replacing those sections once it has been filled
2115892Sab196087 		 * with their strings (merged and compressed) and relocations
2125892Sab196087 		 * have been redirected.
2135892Sab196087 		 */
2145892Sab196087 		dbg_print(lml, MSG_INTL(MSG_SEC_INPUT_GENSTR), isp->is_name);
215*9406SAli.Bahrami@Sun.COM 	} else if (isp->is_file == NULL) {
216*9406SAli.Bahrami@Sun.COM 		/* Generated input section */
217*9406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_INPUT_GEN), isp->is_name);
2185892Sab196087 	} else {
2195892Sab196087 		/* Standard input section */
220*9406SAli.Bahrami@Sun.COM 		dbg_isec_name_buf_t	buf;
221*9406SAli.Bahrami@Sun.COM 		char			*alloc_mem;
222*9406SAli.Bahrami@Sun.COM 
223*9406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_INPUT),
224*9406SAli.Bahrami@Sun.COM 		    dbg_fmt_isec_name(isp, buf, &alloc_mem),
225*9406SAli.Bahrami@Sun.COM 		    isp->is_file->ifl_name);
226*9406SAli.Bahrami@Sun.COM 		if (alloc_mem != NULL)
227*9406SAli.Bahrami@Sun.COM 			free(alloc_mem);
2285892Sab196087 	}
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate void
2321618Srie Dbg_sec_added(Lm_list *lml, Os_desc *osp, Sg_desc *sgp)
2330Sstevel@tonic-gate {
2340Sstevel@tonic-gate 	const char	*str;
2350Sstevel@tonic-gate 
2361618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
2370Sstevel@tonic-gate 		return;
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate 	if (sgp->sg_name && *sgp->sg_name)
2400Sstevel@tonic-gate 		str = sgp->sg_name;
2410Sstevel@tonic-gate 	else
2420Sstevel@tonic-gate 		str = MSG_INTL(MSG_STR_NULL);
2430Sstevel@tonic-gate 
2441618Srie 	dbg_print(lml, MSG_INTL(MSG_SEC_ADDED), osp->os_name, str);
2450Sstevel@tonic-gate }
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate void
2481618Srie Dbg_sec_created(Lm_list *lml, Os_desc *osp, Sg_desc *sgp)
2490Sstevel@tonic-gate {
2500Sstevel@tonic-gate 	const char	*str;
2510Sstevel@tonic-gate 
2521618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
2530Sstevel@tonic-gate 		return;
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate 	if (sgp->sg_name && *sgp->sg_name)
2560Sstevel@tonic-gate 		str = sgp->sg_name;
2570Sstevel@tonic-gate 	else
2580Sstevel@tonic-gate 		str = MSG_INTL(MSG_STR_NULL);
2590Sstevel@tonic-gate 
2601618Srie 	dbg_print(lml, MSG_INTL(MSG_SEC_CREATED), osp->os_name, str);
2610Sstevel@tonic-gate }
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate void
2641618Srie Dbg_sec_discarded(Lm_list *lml, Is_desc *isp, Is_desc *disp)
2650Sstevel@tonic-gate {
2665549Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS | DBG_C_UNUSED))
2670Sstevel@tonic-gate 		return;
2680Sstevel@tonic-gate 
2695892Sab196087 	if ((isp->is_flags & FLG_IS_INSTRMRG) &&
2705892Sab196087 	    (disp->is_flags & FLG_IS_GNSTRMRG)) {
2715892Sab196087 		/*
2725892Sab196087 		 * This SHF_MERGE|SHF_STRINGS input section is being
2735892Sab196087 		 * discarded in favor of the generated merged string section.
2745892Sab196087 		 */
275*9406SAli.Bahrami@Sun.COM 		dbg_isec_name_buf_t	buf;
276*9406SAli.Bahrami@Sun.COM 		char			*alloc_mem;
277*9406SAli.Bahrami@Sun.COM 
2785892Sab196087 		dbg_print(lml, MSG_INTL(MSG_SEC_STRMERGE_DISCARDED),
279*9406SAli.Bahrami@Sun.COM 		    dbg_fmt_isec_name(isp, buf, &alloc_mem),
280*9406SAli.Bahrami@Sun.COM 		    isp->is_file->ifl_name);
281*9406SAli.Bahrami@Sun.COM 		if (alloc_mem != NULL)
282*9406SAli.Bahrami@Sun.COM 			free(alloc_mem);
2835892Sab196087 	} else {
2845892Sab196087 		/* Generic section discard */
285*9406SAli.Bahrami@Sun.COM 		dbg_isec_name_buf_t	buf1, buf2;
286*9406SAli.Bahrami@Sun.COM 		char			*alloc_mem1, *alloc_mem2;
287*9406SAli.Bahrami@Sun.COM 
288*9406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_DISCARDED),
289*9406SAli.Bahrami@Sun.COM 		    dbg_fmt_isec_name(isp, buf1, &alloc_mem1),
290*9406SAli.Bahrami@Sun.COM 		    isp->is_file->ifl_name,
291*9406SAli.Bahrami@Sun.COM 		    dbg_fmt_isec_name(disp, buf2, &alloc_mem2),
2925892Sab196087 		    disp->is_file->ifl_name);
293*9406SAli.Bahrami@Sun.COM 		if (alloc_mem1 != NULL)
294*9406SAli.Bahrami@Sun.COM 			free(alloc_mem1);
295*9406SAli.Bahrami@Sun.COM 		if (alloc_mem2 != NULL)
296*9406SAli.Bahrami@Sun.COM 			free(alloc_mem2);
2975892Sab196087 	}
2980Sstevel@tonic-gate }
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate void
3011618Srie Dbg_sec_group(Lm_list *lml, Is_desc *isp, Group_desc *gdp)
3020Sstevel@tonic-gate {
303*9406SAli.Bahrami@Sun.COM 	dbg_isec_name_buf_t	buf;
304*9406SAli.Bahrami@Sun.COM 	char			*alloc_mem;
305*9406SAli.Bahrami@Sun.COM 	const char		*comdat, *isp_str;
30633Srie 
3071618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
3080Sstevel@tonic-gate 		return;
3090Sstevel@tonic-gate 
3107463SRod.Evans@Sun.COM 	if (gdp->gd_data[0] & GRP_COMDAT)
3117463SRod.Evans@Sun.COM 		comdat = MSG_ORIG(MSG_STR_COMDAT);
31233Srie 	else
3137463SRod.Evans@Sun.COM 		comdat = MSG_ORIG(MSG_STR_EMPTY);
31433Srie 
315*9406SAli.Bahrami@Sun.COM 	isp_str = dbg_fmt_isec_name(isp, buf, &alloc_mem);
316*9406SAli.Bahrami@Sun.COM 
3177463SRod.Evans@Sun.COM 	if (isp->is_shdr->sh_type == SHT_GROUP) {
318*9406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_GRP_DEFINE), isp_str,
3197463SRod.Evans@Sun.COM 		    isp->is_file->ifl_name, comdat, gdp->gd_name);
3207463SRod.Evans@Sun.COM 	} else {
321*9406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_GRP_MEMBER), isp_str,
3227463SRod.Evans@Sun.COM 		    isp->is_file->ifl_name, comdat, gdp->gd_name);
3237463SRod.Evans@Sun.COM 	}
3247463SRod.Evans@Sun.COM 
3257463SRod.Evans@Sun.COM 	if (gdp->gd_oisc) {
326*9406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_GRP_DISCARDED), isp_str,
3277463SRod.Evans@Sun.COM 		    isp->is_file->ifl_name, gdp->gd_name,
3287463SRod.Evans@Sun.COM 		    gdp->gd_oisc->is_file->ifl_name);
3297463SRod.Evans@Sun.COM 	}
330*9406SAli.Bahrami@Sun.COM 
331*9406SAli.Bahrami@Sun.COM 	if (alloc_mem != NULL)
332*9406SAli.Bahrami@Sun.COM 		free(alloc_mem);
3330Sstevel@tonic-gate }
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate void
3360Sstevel@tonic-gate Dbg_sec_order_list(Ofl_desc *ofl, int flag)
3370Sstevel@tonic-gate {
3380Sstevel@tonic-gate 	Os_desc		*osp;
3390Sstevel@tonic-gate 	Is_desc		*isp1;
3409131SRod.Evans@Sun.COM 	Aliste		idx1;
3411618Srie 	Lm_list		*lml = ofl->ofl_lml;
3420Sstevel@tonic-gate 	const char	*str;
3430Sstevel@tonic-gate 
3441618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
3450Sstevel@tonic-gate 		return;
3460Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
3470Sstevel@tonic-gate 		return;
3480Sstevel@tonic-gate 
3492647Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3502647Srie 
3510Sstevel@tonic-gate 	/*
3520Sstevel@tonic-gate 	 * If the flag == 0, then the routine is called before sorting.
3530Sstevel@tonic-gate 	 */
3540Sstevel@tonic-gate 	if (flag == 0)
3550Sstevel@tonic-gate 		str = MSG_INTL(MSG_ORD_SORT_BEFORE);
3560Sstevel@tonic-gate 	else
3570Sstevel@tonic-gate 		str = MSG_INTL(MSG_ORD_SORT_AFTER);
3580Sstevel@tonic-gate 
3599131SRod.Evans@Sun.COM 	for (APLIST_TRAVERSE(ofl->ofl_ordered, idx1, osp)) {
3609131SRod.Evans@Sun.COM 		Aliste		idx2;
3610Sstevel@tonic-gate 		Sort_desc	*sort = osp->os_sort;
3620Sstevel@tonic-gate 
363*9406SAli.Bahrami@Sun.COM 		Dbg_util_nl(lml, DBG_NL_STD);
3641618Srie 		dbg_print(lml, str, osp->os_name);
3651618Srie 		dbg_print(lml, MSG_INTL(MSG_ORD_HDR_1),
3660Sstevel@tonic-gate 		    EC_WORD(sort->st_beforecnt), EC_WORD(sort->st_aftercnt),
3670Sstevel@tonic-gate 		    EC_WORD(sort->st_ordercnt));
3680Sstevel@tonic-gate 
3699131SRod.Evans@Sun.COM 		for (APLIST_TRAVERSE(osp->os_isdescs, idx2, isp1)) {
370*9406SAli.Bahrami@Sun.COM 			dbg_isec_name_buf_t	buf;
371*9406SAli.Bahrami@Sun.COM 			char			*alloc_mem;
372*9406SAli.Bahrami@Sun.COM 			const char		*isp1_str;
373*9406SAli.Bahrami@Sun.COM 			Word			link;
374*9406SAli.Bahrami@Sun.COM 			Ifl_desc		*ifl = isp1->is_file;
375*9406SAli.Bahrami@Sun.COM 			Is_desc			*isp2;
376*9406SAli.Bahrami@Sun.COM 			const char		*msg;
3770Sstevel@tonic-gate 
378*9406SAli.Bahrami@Sun.COM 			/*
379*9406SAli.Bahrami@Sun.COM 			 * An output section with sorted input sections
380*9406SAli.Bahrami@Sun.COM 			 * can also have a large number of unsorted sections.
381*9406SAli.Bahrami@Sun.COM 			 * Skip these without comment.
382*9406SAli.Bahrami@Sun.COM 			 */
3830Sstevel@tonic-gate 			if ((isp1->is_flags & FLG_IS_ORDERED) == 0) {
3840Sstevel@tonic-gate 				continue;
3850Sstevel@tonic-gate 			}
3860Sstevel@tonic-gate 
3870Sstevel@tonic-gate 			if (isp1->is_shdr->sh_flags & SHF_ORDERED) {
3880Sstevel@tonic-gate 				link = isp1->is_shdr->sh_info;
3892647Srie 				msg = MSG_ORIG(MSG_SH_INFO);
390*9406SAli.Bahrami@Sun.COM 			} else {	/* SHF_LINK_ORDER */
3910Sstevel@tonic-gate 				link = isp1->is_shdr->sh_link;
3922647Srie 				msg = MSG_ORIG(MSG_SH_LINK);
3930Sstevel@tonic-gate 			}
3940Sstevel@tonic-gate 
395*9406SAli.Bahrami@Sun.COM 			isp1_str = dbg_fmt_isec_name(isp1, buf, &alloc_mem);
3960Sstevel@tonic-gate 
397*9406SAli.Bahrami@Sun.COM 			if (link == SHN_BEFORE) {
398*9406SAli.Bahrami@Sun.COM 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_1), msg,
399*9406SAli.Bahrami@Sun.COM 				    isp1_str, isp1->is_file->ifl_name);
400*9406SAli.Bahrami@Sun.COM 			} else if (link == SHN_AFTER) {
401*9406SAli.Bahrami@Sun.COM 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_2), msg,
402*9406SAli.Bahrami@Sun.COM 				    isp1_str, isp1->is_file->ifl_name);
403*9406SAli.Bahrami@Sun.COM 			} else {
404*9406SAli.Bahrami@Sun.COM 				isp2 = ifl->ifl_isdesc[link];
405*9406SAli.Bahrami@Sun.COM 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_3),
406*9406SAli.Bahrami@Sun.COM 				    EC_WORD(isp2->is_keyident), isp1_str,
407*9406SAli.Bahrami@Sun.COM 				    ifl->ifl_name, msg, isp2->is_name);
4080Sstevel@tonic-gate 			}
409*9406SAli.Bahrami@Sun.COM 			if (alloc_mem != NULL)
410*9406SAli.Bahrami@Sun.COM 				free(alloc_mem);
4110Sstevel@tonic-gate 		}
4120Sstevel@tonic-gate 	}
4132647Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4140Sstevel@tonic-gate }
4150Sstevel@tonic-gate 
4165549Srie /*
4175549Srie  * Error message string table.
4185549Srie  */
4195549Srie static const Msg order_errors[] = {
4205549Srie 	MSG_ORD_ERR_INFORANGE,		/* MSG_INTL(MSG_ORD_ERR_INFORANGE) */
4215549Srie 	MSG_ORD_ERR_ORDER,		/* MSG_INTL(MSG_ORD_ERR_ORDER) */
4225549Srie 	MSG_ORD_ERR_LINKRANGE,		/* MSG_INTL(MSG_ORD_ERR_LINKRANGE) */
4235549Srie 	MSG_ORD_ERR_FLAGS,		/* MSG_INTL(MSG_ORD_ERR_FLAGS) */
4245549Srie 	MSG_ORD_ERR_CYCLIC,		/* MSG_INTL(MSG_ORD_ERR_CYCLIC) */
4255549Srie 	MSG_ORD_ERR_LINKINV		/* MSG_INTL(MSG_ORD_ERR_LINKINV) */
4265549Srie };
4275549Srie 
4280Sstevel@tonic-gate void
4291618Srie Dbg_sec_order_error(Lm_list *lml, Ifl_desc *ifl, Word ndx, int error)
4300Sstevel@tonic-gate {
431*9406SAli.Bahrami@Sun.COM 	dbg_isec_name_buf_t	buf;
432*9406SAli.Bahrami@Sun.COM 	char			*alloc_mem;
433*9406SAli.Bahrami@Sun.COM 
4341618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
4350Sstevel@tonic-gate 		return;
4360Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
4370Sstevel@tonic-gate 		return;
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate 	if (error == 0)
4400Sstevel@tonic-gate 		return;
4410Sstevel@tonic-gate 
4421618Srie 	dbg_print(lml, MSG_INTL(MSG_ORD_ERR_TITLE),
443*9406SAli.Bahrami@Sun.COM 	    dbg_fmt_isec_name(ifl->ifl_isdesc[ndx], buf, &alloc_mem),
444*9406SAli.Bahrami@Sun.COM 	    ifl->ifl_name);
445*9406SAli.Bahrami@Sun.COM 	if (alloc_mem != NULL)
446*9406SAli.Bahrami@Sun.COM 		free(alloc_mem);
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate 	if (error)
4491618Srie 		dbg_print(lml, MSG_INTL(order_errors[error - 1]));
4500Sstevel@tonic-gate }
4517463SRod.Evans@Sun.COM 
4527463SRod.Evans@Sun.COM void
453*9406SAli.Bahrami@Sun.COM Dbg_sec_redirected(Lm_list *lml, Is_desc *isp, const char *nname)
4547463SRod.Evans@Sun.COM {
455*9406SAli.Bahrami@Sun.COM 	dbg_isec_name_buf_t	buf;
456*9406SAli.Bahrami@Sun.COM 	char			*alloc_mem;
457*9406SAli.Bahrami@Sun.COM 
4587463SRod.Evans@Sun.COM 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
4597463SRod.Evans@Sun.COM 		return;
4607463SRod.Evans@Sun.COM 
461*9406SAli.Bahrami@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_SEC_REDIRECTED),
462*9406SAli.Bahrami@Sun.COM 	    dbg_fmt_isec_name(isp, buf, &alloc_mem), nname);
463*9406SAli.Bahrami@Sun.COM 	if (alloc_mem != NULL)
464*9406SAli.Bahrami@Sun.COM 		free(alloc_mem);
4657463SRod.Evans@Sun.COM }
4667463SRod.Evans@Sun.COM 
4677463SRod.Evans@Sun.COM void
468*9406SAli.Bahrami@Sun.COM Dbg_sec_gnu_comdat(Lm_list *lml, Is_desc *isp, uint_t comdat, uint_t relax)
4697463SRod.Evans@Sun.COM {
470*9406SAli.Bahrami@Sun.COM 	dbg_isec_name_buf_t	buf;
471*9406SAli.Bahrami@Sun.COM 	char			*alloc_mem;
472*9406SAli.Bahrami@Sun.COM 	const char		*fmt;
4737463SRod.Evans@Sun.COM 
4747463SRod.Evans@Sun.COM 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
4757463SRod.Evans@Sun.COM 		return;
4767463SRod.Evans@Sun.COM 
4777463SRod.Evans@Sun.COM 	if (comdat && relax)
4787463SRod.Evans@Sun.COM 		fmt = MSG_INTL(MSG_SEC_GNU_COMDAT_1);
4797463SRod.Evans@Sun.COM 	else if (comdat)
4807463SRod.Evans@Sun.COM 		fmt = MSG_INTL(MSG_SEC_GNU_COMDAT_2);
4817463SRod.Evans@Sun.COM 	else
4827463SRod.Evans@Sun.COM 		fmt = MSG_INTL(MSG_SEC_GNU_COMDAT_3);
4837463SRod.Evans@Sun.COM 
484*9406SAli.Bahrami@Sun.COM 	dbg_print(lml, fmt, dbg_fmt_isec_name(isp, buf, &alloc_mem));
485*9406SAli.Bahrami@Sun.COM 	if (alloc_mem != NULL)
486*9406SAli.Bahrami@Sun.COM 		free(alloc_mem);
4877463SRod.Evans@Sun.COM }
488